00001 package edu.ksu.cis.bandera.abstraction.gui;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 import Bandera;
00036 import java.io.*;
00037 import java.util.*;
00038 import javax.swing.*;
00039 import javax.swing.table.*;
00040 import edu.ksu.cis.bandera.bui.*;
00041 import edu.ksu.cis.bandera.abstraction.*;
00042 import edu.ksu.cis.bandera.abstraction.pvs.*;
00043 import edu.ksu.cis.bandera.abstraction.util.*;
00044 import edu.ksu.cis.bandera.abstraction.lib.integral.*;
00045 import edu.ksu.cis.bandera.abstraction.specification.*;
00046 import edu.ksu.cis.bandera.util.*;
00047 public class AbstractionLibraryManager extends JDialog {
00048 private static final Object[] columnNames = new String[] {"Name", "Tokens", "Type"};
00049 private static TreeSet abstractions = new TreeSet();
00050 public static String abstractionPackage;
00051 public static String abstractionPath;
00052 private static String abstractionListPath;
00053 static {
00054 init();
00055 }
00056 private JPanel ivjJDialogContentPane = null;
00057 private JButton ivjAddToLibraryButton = null;
00058 private JScrollPane ivjBASLCodeScrollPane = null;
00059 private JTextArea ivjBASLCodeTextArea = null;
00060 private JLabel ivjBASLLabel = null;
00061 private JScrollPane ivjLibraryScrollPane = null;
00062 private JButton ivjNewButton = null;
00063 private JButton ivjOpenButton = null;
00064 private JButton ivjPVSButton = null;
00065 private JLabel ivjPVSLogoLabel = null;
00066 private JButton ivjRemoveButton = null;
00067 private JButton ivjSaveAsButton = null;
00068 private JTable ivjScrollPaneTable = null;
00069 private JButton ivjShowButton = null;
00070 private JLabel ivjAbstractionsLabel = null;
00071 IvjEventHandler ivjEventHandler = new IvjEventHandler();
00072 class IvjEventHandler implements java.awt.event.ActionListener {
00073 public void actionPerformed(java.awt.event.ActionEvent e) {
00074 if (e.getSource() == AbstractionLibraryManager.this.getNewButton())
00075 connEtoM1(e);
00076 if (e.getSource() == AbstractionLibraryManager.this.getAddToLibraryButton())
00077 connEtoC1();
00078 if (e.getSource() == AbstractionLibraryManager.this.getPVSButton())
00079 connEtoC2();
00080 if (e.getSource() == AbstractionLibraryManager.this.getSaveAsButton())
00081 connEtoC3();
00082 if (e.getSource() == AbstractionLibraryManager.this.getOpenButton())
00083 connEtoC4();
00084 if (e.getSource() == AbstractionLibraryManager.this.getShowButton())
00085 connEtoC5();
00086 if (e.getSource() == AbstractionLibraryManager.this.getRemoveButton())
00087 connEtoC6();
00088 };
00089 };
00090
00091
00092
00093 public AbstractionLibraryManager() {
00094 super();
00095 initialize();
00096 }
00097
00098
00099
00100
00101 public AbstractionLibraryManager(java.awt.Dialog owner) {
00102 super(owner);
00103 }
00104
00105
00106
00107
00108
00109 public AbstractionLibraryManager(java.awt.Dialog owner, String title) {
00110 super(owner, title);
00111 }
00112
00113
00114
00115
00116
00117
00118 public AbstractionLibraryManager(java.awt.Dialog owner, String title, boolean modal) {
00119 super(owner, title, modal);
00120 }
00121
00122
00123
00124
00125
00126 public AbstractionLibraryManager(java.awt.Dialog owner, boolean modal) {
00127 super(owner, modal);
00128 }
00129
00130
00131
00132
00133 public AbstractionLibraryManager(java.awt.Frame owner) {
00134 super(owner);
00135 }
00136
00137
00138
00139
00140
00141 public AbstractionLibraryManager(java.awt.Frame owner, String title) {
00142 super(owner, title);
00143 }
00144
00145
00146
00147
00148
00149
00150 public AbstractionLibraryManager(java.awt.Frame owner, String title, boolean modal) {
00151 super(owner, title, modal);
00152 }
00153
00154
00155
00156
00157
00158 public AbstractionLibraryManager(java.awt.Frame owner, boolean modal) {
00159 super(owner, modal);
00160 }
00161
00162
00163
00164 public void addToLibraryButton_ActionEvents() {
00165 try {
00166 AbstractionGenerator ag = new AbstractionGenerator(new StringReader(getBASLCodeTextArea().getText()));
00167 String result = ag.generate(abstractionPackage);
00168 if (ag.getErrors().size() > 0) {
00169 StringBuffer buffer = new StringBuffer("Errors:\n");
00170 for (Iterator i = ag.getErrors().iterator(); i.hasNext();) {
00171 buffer.append("- " + i.next() + "\n");
00172 }
00173 if (ag.getWarnings().size() > 0) {
00174 buffer.append("Warnings:\n");
00175 for (Iterator i = ag.getWarnings().iterator(); i.hasNext();) {
00176 buffer.append("- " + i.next() + "\n");
00177 }
00178 }
00179 JOptionPane.showMessageDialog(this, buffer.toString(), "Cannnot generate abstraction", JOptionPane.ERROR_MESSAGE);
00180 } else {
00181 if (ag.getWarnings().size() > 0) {
00182 StringBuffer buffer = new StringBuffer();
00183 for (Iterator i = ag.getWarnings().iterator(); i.hasNext();) {
00184 buffer.append(i.next() + "\n");
00185 }
00186 JOptionPane.showMessageDialog(this, buffer.toString(), "Warnings", JOptionPane.INFORMATION_MESSAGE);
00187 }
00188 String filename = abstractionPath + File.separator + ag.getAbstractionType() + File.separator + ag.getAbstractionName();
00189 new File(filename + ".java").delete();
00190 new File(filename + ".class").delete();
00191 filename += ".java";
00192 PrintWriter pw = new PrintWriter(new FileWriter(filename));
00193 pw.write(result);
00194 pw.flush();
00195 pw.close();
00196 runJavac(System.getProperty("java.class.path"), filename);
00197 try {
00198 abstractions.add(AbstractionClassLoader.getClass(ag.getAbstractionFullyQualifiedName()).getName());
00199 updateAbstractionList();
00200 } catch (Exception e2) {
00201 e2.printStackTrace();
00202 JOptionPane.showMessageDialog(this, e2.getMessage(), "Abstraction installation failed", JOptionPane.ERROR_MESSAGE);
00203 }
00204 }
00205 } catch (Exception e) {
00206 e.printStackTrace();
00207 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
00208 }
00209 }
00210
00211
00212
00213
00214 private void connEtoC1() {
00215 try {
00216
00217
00218 this.addToLibraryButton_ActionEvents();
00219
00220
00221 } catch (java.lang.Throwable ivjExc) {
00222
00223
00224 handleException(ivjExc);
00225 }
00226 }
00227
00228
00229
00230
00231 private void connEtoC2() {
00232 try {
00233
00234
00235 this.pVSButton_ActionEvents();
00236
00237
00238 } catch (java.lang.Throwable ivjExc) {
00239
00240
00241 handleException(ivjExc);
00242 }
00243 }
00244
00245
00246
00247
00248 private void connEtoC3() {
00249 try {
00250
00251
00252 this.saveAsButton_ActionEvents();
00253
00254
00255 } catch (java.lang.Throwable ivjExc) {
00256
00257
00258 handleException(ivjExc);
00259 }
00260 }
00261
00262
00263
00264
00265 private void connEtoC4() {
00266 try {
00267
00268
00269 this.openButton_ActionEvents();
00270
00271
00272 } catch (java.lang.Throwable ivjExc) {
00273
00274
00275 handleException(ivjExc);
00276 }
00277 }
00278
00279
00280
00281
00282 private void connEtoC5() {
00283 try {
00284
00285
00286 this.showButton_ActionEvents();
00287
00288
00289 } catch (java.lang.Throwable ivjExc) {
00290
00291
00292 handleException(ivjExc);
00293 }
00294 }
00295
00296
00297
00298
00299 private void connEtoC6() {
00300 try {
00301
00302
00303 this.removeButton_ActionEvents();
00304
00305
00306 } catch (java.lang.Throwable ivjExc) {
00307
00308
00309 handleException(ivjExc);
00310 }
00311 }
00312
00313
00314
00315
00316
00317 private void connEtoM1(java.awt.event.ActionEvent arg1) {
00318 try {
00319
00320
00321 getBASLCodeTextArea().setText(new java.lang.String());
00322
00323
00324 } catch (java.lang.Throwable ivjExc) {
00325
00326
00327 handleException(ivjExc);
00328 }
00329 }
00330
00331
00332
00333
00334 public static java.util.Set getAbstractions() {
00335 Set set = new HashSet(abstractions);
00336 set.add(Signs.class.getName());
00337 set.add(Point.class.getName());
00338 set.add(Set0.class.getName());
00339 set.add(Range01.class.getName());
00340 set.add(Range02.class.getName());
00341 set.add(Range03.class.getName());
00342 set.add(Range04.class.getName());
00343 set.add(edu.ksu.cis.bandera.abstraction.lib.real.Signs.class.getName());
00344 set.add(edu.ksu.cis.bandera.abstraction.lib.real.Point.class.getName());
00345 return set;
00346 }
00347
00348
00349
00350
00351
00352 private javax.swing.JLabel getAbstractionsLabel() {
00353 if (ivjAbstractionsLabel == null) {
00354 try {
00355 ivjAbstractionsLabel = new javax.swing.JLabel();
00356 ivjAbstractionsLabel.setName("AbstractionsLabel");
00357 ivjAbstractionsLabel.setText("Abstractions:");
00358 ivjAbstractionsLabel.setForeground(java.awt.Color.black);
00359
00360
00361 } catch (java.lang.Throwable ivjExc) {
00362
00363
00364 handleException(ivjExc);
00365 }
00366 }
00367 return ivjAbstractionsLabel;
00368 }
00369
00370
00371
00372
00373
00374 private javax.swing.JButton getAddToLibraryButton() {
00375 if (ivjAddToLibraryButton == null) {
00376 try {
00377 ivjAddToLibraryButton = new javax.swing.JButton();
00378 ivjAddToLibraryButton.setName("AddToLibraryButton");
00379 ivjAddToLibraryButton.setMnemonic('a');
00380 ivjAddToLibraryButton.setText("Add");
00381 ivjAddToLibraryButton.setBackground(new java.awt.Color(204,204,255));
00382
00383
00384 } catch (java.lang.Throwable ivjExc) {
00385
00386
00387 handleException(ivjExc);
00388 }
00389 }
00390 return ivjAddToLibraryButton;
00391 }
00392
00393
00394
00395
00396
00397 private javax.swing.JScrollPane getBASLCodeScrollPane() {
00398 if (ivjBASLCodeScrollPane == null) {
00399 try {
00400 ivjBASLCodeScrollPane = new javax.swing.JScrollPane();
00401 ivjBASLCodeScrollPane.setName("BASLCodeScrollPane");
00402 ivjBASLCodeScrollPane.setBorder(BorderFactory.createLoweredBevelBorder());
00403 getBASLCodeScrollPane().setViewportView(getBASLCodeTextArea());
00404
00405
00406 } catch (java.lang.Throwable ivjExc) {
00407
00408
00409 handleException(ivjExc);
00410 }
00411 }
00412 return ivjBASLCodeScrollPane;
00413 }
00414
00415
00416
00417
00418
00419 private javax.swing.JTextArea getBASLCodeTextArea() {
00420 if (ivjBASLCodeTextArea == null) {
00421 try {
00422 ivjBASLCodeTextArea = new javax.swing.JTextArea();
00423 ivjBASLCodeTextArea.setName("BASLCodeTextArea");
00424 ivjBASLCodeTextArea.setFont(new java.awt.Font("monospaced", 0, 12));
00425 ivjBASLCodeTextArea.setBounds(0, 0, 157, 117);
00426 ivjBASLCodeTextArea.setFocusAccelerator('b');
00427
00428
00429 } catch (java.lang.Throwable ivjExc) {
00430
00431
00432 handleException(ivjExc);
00433 }
00434 }
00435 return ivjBASLCodeTextArea;
00436 }
00437
00438
00439
00440
00441
00442 private javax.swing.JLabel getBASLLabel() {
00443 if (ivjBASLLabel == null) {
00444 try {
00445 ivjBASLLabel = new javax.swing.JLabel();
00446 ivjBASLLabel.setName("BASLLabel");
00447 ivjBASLLabel.setDisplayedMnemonic('b');
00448 ivjBASLLabel.setText("BASL Code:");
00449 ivjBASLLabel.setForeground(java.awt.Color.black);
00450
00451
00452 } catch (java.lang.Throwable ivjExc) {
00453
00454
00455 handleException(ivjExc);
00456 }
00457 }
00458 return ivjBASLLabel;
00459 }
00460
00461
00462
00463
00464 private static void getBuilderData() {
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516 }
00517
00518
00519
00520
00521
00522 private javax.swing.JPanel getJDialogContentPane() {
00523 if (ivjJDialogContentPane == null) {
00524 try {
00525 ivjJDialogContentPane = new javax.swing.JPanel();
00526 ivjJDialogContentPane.setName("JDialogContentPane");
00527 ivjJDialogContentPane.setBorder(new javax.swing.border.EtchedBorder());
00528 ivjJDialogContentPane.setLayout(new java.awt.GridBagLayout());
00529 ivjJDialogContentPane.setBackground(new java.awt.Color(204,204,255));
00530
00531 java.awt.GridBagConstraints constraintsPVSButton = new java.awt.GridBagConstraints();
00532 constraintsPVSButton.gridx = 1; constraintsPVSButton.gridy = 4;
00533 constraintsPVSButton.fill = java.awt.GridBagConstraints.HORIZONTAL;
00534 constraintsPVSButton.insets = new java.awt.Insets(5, 10, 0, 10);
00535 getJDialogContentPane().add(getPVSButton(), constraintsPVSButton);
00536
00537 java.awt.GridBagConstraints constraintsAddToLibraryButton = new java.awt.GridBagConstraints();
00538 constraintsAddToLibraryButton.gridx = 1; constraintsAddToLibraryButton.gridy = 7;
00539 constraintsAddToLibraryButton.fill = java.awt.GridBagConstraints.HORIZONTAL;
00540 constraintsAddToLibraryButton.anchor = java.awt.GridBagConstraints.SOUTH;
00541 constraintsAddToLibraryButton.insets = new java.awt.Insets(10, 10, 0, 10);
00542 getJDialogContentPane().add(getAddToLibraryButton(), constraintsAddToLibraryButton);
00543
00544 java.awt.GridBagConstraints constraintsBASLCodeScrollPane = new java.awt.GridBagConstraints();
00545 constraintsBASLCodeScrollPane.gridx = 0; constraintsBASLCodeScrollPane.gridy = 1;
00546 constraintsBASLCodeScrollPane.gridheight = 7;
00547 constraintsBASLCodeScrollPane.fill = java.awt.GridBagConstraints.BOTH;
00548 constraintsBASLCodeScrollPane.weightx = 1.0;
00549 constraintsBASLCodeScrollPane.weighty = 1.0;
00550 constraintsBASLCodeScrollPane.insets = new java.awt.Insets(5, 10, 0, 0);
00551 getJDialogContentPane().add(getBASLCodeScrollPane(), constraintsBASLCodeScrollPane);
00552
00553 java.awt.GridBagConstraints constraintsBASLLabel = new java.awt.GridBagConstraints();
00554 constraintsBASLLabel.gridx = 0; constraintsBASLLabel.gridy = 0;
00555 constraintsBASLLabel.gridwidth = 2;
00556 constraintsBASLLabel.fill = java.awt.GridBagConstraints.BOTH;
00557 constraintsBASLLabel.weightx = 1.0;
00558 constraintsBASLLabel.insets = new java.awt.Insets(10, 10, 0, 10);
00559 getJDialogContentPane().add(getBASLLabel(), constraintsBASLLabel);
00560
00561 java.awt.GridBagConstraints constraintsSaveAsButton = new java.awt.GridBagConstraints();
00562 constraintsSaveAsButton.gridx = 1; constraintsSaveAsButton.gridy = 3;
00563 constraintsSaveAsButton.fill = java.awt.GridBagConstraints.HORIZONTAL;
00564 constraintsSaveAsButton.insets = new java.awt.Insets(5, 10, 0, 10);
00565 getJDialogContentPane().add(getSaveAsButton(), constraintsSaveAsButton);
00566
00567 java.awt.GridBagConstraints constraintsRemoveButton = new java.awt.GridBagConstraints();
00568 constraintsRemoveButton.gridx = 1; constraintsRemoveButton.gridy = 11;
00569 constraintsRemoveButton.fill = java.awt.GridBagConstraints.HORIZONTAL;
00570 constraintsRemoveButton.insets = new java.awt.Insets(5, 10, 10, 10);
00571 getJDialogContentPane().add(getRemoveButton(), constraintsRemoveButton);
00572
00573 java.awt.GridBagConstraints constraintsOpenButton = new java.awt.GridBagConstraints();
00574 constraintsOpenButton.gridx = 1; constraintsOpenButton.gridy = 2;
00575 constraintsOpenButton.fill = java.awt.GridBagConstraints.HORIZONTAL;
00576 constraintsOpenButton.insets = new java.awt.Insets(5, 10, 0, 10);
00577 getJDialogContentPane().add(getOpenButton(), constraintsOpenButton);
00578
00579 java.awt.GridBagConstraints constraintsNewButton = new java.awt.GridBagConstraints();
00580 constraintsNewButton.gridx = 1; constraintsNewButton.gridy = 1;
00581 constraintsNewButton.fill = java.awt.GridBagConstraints.HORIZONTAL;
00582 constraintsNewButton.insets = new java.awt.Insets(5, 10, 0, 10);
00583 getJDialogContentPane().add(getNewButton(), constraintsNewButton);
00584
00585 java.awt.GridBagConstraints constraintsPVSLogoLabel = new java.awt.GridBagConstraints();
00586 constraintsPVSLogoLabel.gridx = 1; constraintsPVSLogoLabel.gridy = 5;
00587 constraintsPVSLogoLabel.anchor = java.awt.GridBagConstraints.SOUTH;
00588 constraintsPVSLogoLabel.insets = new java.awt.Insets(15, 0, 0, 0);
00589 getJDialogContentPane().add(getPVSLogoLabel(), constraintsPVSLogoLabel);
00590
00591 java.awt.GridBagConstraints constraintsShowButton = new java.awt.GridBagConstraints();
00592 constraintsShowButton.gridx = 1; constraintsShowButton.gridy = 9;
00593 constraintsShowButton.fill = java.awt.GridBagConstraints.HORIZONTAL;
00594 constraintsShowButton.insets = new java.awt.Insets(5, 10, 0, 10);
00595 getJDialogContentPane().add(getShowButton(), constraintsShowButton);
00596
00597 java.awt.GridBagConstraints constraintsLibraryScrollPane = new java.awt.GridBagConstraints();
00598 constraintsLibraryScrollPane.gridx = 0; constraintsLibraryScrollPane.gridy = 9;
00599 constraintsLibraryScrollPane.gridheight = 4;
00600 constraintsLibraryScrollPane.fill = java.awt.GridBagConstraints.BOTH;
00601 constraintsLibraryScrollPane.weightx = 1.0;
00602 constraintsLibraryScrollPane.weighty = 1.0;
00603 constraintsLibraryScrollPane.insets = new java.awt.Insets(5, 10, 10, 0);
00604 getJDialogContentPane().add(getLibraryScrollPane(), constraintsLibraryScrollPane);
00605
00606 java.awt.GridBagConstraints constraintsAbstractionsLabel = new java.awt.GridBagConstraints();
00607 constraintsAbstractionsLabel.gridx = 0; constraintsAbstractionsLabel.gridy = 8;
00608 constraintsAbstractionsLabel.gridwidth = 2;
00609 constraintsAbstractionsLabel.fill = java.awt.GridBagConstraints.HORIZONTAL;
00610 constraintsAbstractionsLabel.weightx = 1.0;
00611 constraintsAbstractionsLabel.insets = new java.awt.Insets(10, 10, 0, 10);
00612 getJDialogContentPane().add(getAbstractionsLabel(), constraintsAbstractionsLabel);
00613
00614
00615 } catch (java.lang.Throwable ivjExc) {
00616
00617
00618 handleException(ivjExc);
00619 }
00620 }
00621 return ivjJDialogContentPane;
00622 }
00623
00624
00625
00626
00627
00628 private javax.swing.JScrollPane getLibraryScrollPane() {
00629 if (ivjLibraryScrollPane == null) {
00630 try {
00631 ivjLibraryScrollPane = new javax.swing.JScrollPane();
00632 ivjLibraryScrollPane.setName("LibraryScrollPane");
00633 ivjLibraryScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
00634 ivjLibraryScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
00635 getLibraryScrollPane().setViewportView(getScrollPaneTable());
00636
00637
00638 } catch (java.lang.Throwable ivjExc) {
00639
00640
00641 handleException(ivjExc);
00642 }
00643 }
00644 return ivjLibraryScrollPane;
00645 }
00646
00647
00648
00649
00650
00651 private javax.swing.JButton getNewButton() {
00652 if (ivjNewButton == null) {
00653 try {
00654 ivjNewButton = new javax.swing.JButton();
00655 ivjNewButton.setName("NewButton");
00656 ivjNewButton.setMnemonic('n');
00657 ivjNewButton.setText("New");
00658 ivjNewButton.setBackground(new java.awt.Color(204,204,255));
00659
00660
00661 } catch (java.lang.Throwable ivjExc) {
00662
00663
00664 handleException(ivjExc);
00665 }
00666 }
00667 return ivjNewButton;
00668 }
00669
00670
00671
00672
00673
00674 private javax.swing.JButton getOpenButton() {
00675 if (ivjOpenButton == null) {
00676 try {
00677 ivjOpenButton = new javax.swing.JButton();
00678 ivjOpenButton.setName("OpenButton");
00679 ivjOpenButton.setMnemonic('o');
00680 ivjOpenButton.setText("Open");
00681 ivjOpenButton.setBackground(new java.awt.Color(204,204,255));
00682
00683
00684 } catch (java.lang.Throwable ivjExc) {
00685
00686
00687 handleException(ivjExc);
00688 }
00689 }
00690 return ivjOpenButton;
00691 }
00692
00693
00694
00695
00696
00697 private javax.swing.JButton getPVSButton() {
00698 if (ivjPVSButton == null) {
00699 try {
00700 ivjPVSButton = new javax.swing.JButton();
00701 ivjPVSButton.setName("PVSButton");
00702 ivjPVSButton.setMnemonic('r');
00703 ivjPVSButton.setText("Run PVS");
00704 ivjPVSButton.setBackground(new java.awt.Color(204,204,255));
00705
00706 if (System.getProperty("os.name").indexOf("Windows") >= 0) {
00707 ivjPVSButton.setEnabled(false);
00708 ivjPVSButton.setToolTipText("PVS is not available for Windows-based system");
00709 }
00710
00711 } catch (java.lang.Throwable ivjExc) {
00712
00713
00714 handleException(ivjExc);
00715 }
00716 }
00717 return ivjPVSButton;
00718 }
00719
00720
00721
00722
00723
00724 private javax.swing.JLabel getPVSLogoLabel() {
00725 if (ivjPVSLogoLabel == null) {
00726 try {
00727 ivjPVSLogoLabel = new javax.swing.JLabel();
00728 ivjPVSLogoLabel.setName("PVSLogoLabel");
00729 ivjPVSLogoLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/ksu/cis/bandera/bui/images/PVS.gif")));
00730 ivjPVSLogoLabel.setBorder(BorderFactory.createRaisedBevelBorder());
00731 ivjPVSLogoLabel.setText("");
00732
00733
00734 } catch (java.lang.Throwable ivjExc) {
00735
00736
00737 handleException(ivjExc);
00738 }
00739 }
00740 return ivjPVSLogoLabel;
00741 }
00742
00743
00744
00745
00746
00747 private javax.swing.JButton getRemoveButton() {
00748 if (ivjRemoveButton == null) {
00749 try {
00750 ivjRemoveButton = new javax.swing.JButton();
00751 ivjRemoveButton.setName("RemoveButton");
00752 ivjRemoveButton.setMnemonic('m');
00753 ivjRemoveButton.setText("Remove");
00754 ivjRemoveButton.setBackground(new java.awt.Color(204,204,255));
00755
00756
00757 } catch (java.lang.Throwable ivjExc) {
00758
00759
00760 handleException(ivjExc);
00761 }
00762 }
00763 return ivjRemoveButton;
00764 }
00765
00766
00767
00768
00769
00770 private javax.swing.JButton getSaveAsButton() {
00771 if (ivjSaveAsButton == null) {
00772 try {
00773 ivjSaveAsButton = new javax.swing.JButton();
00774 ivjSaveAsButton.setName("SaveAsButton");
00775 ivjSaveAsButton.setMnemonic('s');
00776 ivjSaveAsButton.setText("Save as...");
00777 ivjSaveAsButton.setBackground(new java.awt.Color(204,204,255));
00778
00779
00780 } catch (java.lang.Throwable ivjExc) {
00781
00782
00783 handleException(ivjExc);
00784 }
00785 }
00786 return ivjSaveAsButton;
00787 }
00788
00789
00790
00791
00792
00793 private javax.swing.JTable getScrollPaneTable() {
00794 if (ivjScrollPaneTable == null) {
00795 try {
00796 ivjScrollPaneTable = new javax.swing.JTable();
00797 ivjScrollPaneTable.setName("ScrollPaneTable");
00798 getLibraryScrollPane().setColumnHeaderView(ivjScrollPaneTable.getTableHeader());
00799 getLibraryScrollPane().getViewport().setBackingStoreEnabled(true);
00800 ivjScrollPaneTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
00801 ivjScrollPaneTable.setBounds(0, 0, 200, 200);
00802 ivjScrollPaneTable.setAutoCreateColumnsFromModel(true);
00803
00804
00805 } catch (java.lang.Throwable ivjExc) {
00806
00807
00808 handleException(ivjExc);
00809 }
00810 }
00811 return ivjScrollPaneTable;
00812 }
00813
00814
00815
00816
00817
00818 private javax.swing.JButton getShowButton() {
00819 if (ivjShowButton == null) {
00820 try {
00821 ivjShowButton = new javax.swing.JButton();
00822 ivjShowButton.setName("ShowButton");
00823 ivjShowButton.setMnemonic('h');
00824 ivjShowButton.setText("Show");
00825 ivjShowButton.setBackground(new java.awt.Color(204,204,255));
00826
00827
00828 } catch (java.lang.Throwable ivjExc) {
00829
00830
00831 handleException(ivjExc);
00832 }
00833 }
00834 return ivjShowButton;
00835 }
00836
00837
00838
00839
00840 private void handleException(java.lang.Throwable exception) {
00841
00842
00843
00844
00845 }
00846
00847
00848
00849 private static void init() {
00850 try {
00851 abstractionPackage = Preferences.getAbstractionPackage();
00852 abstractionPath = Preferences.getAbstractionPath();
00853 abstractionListPath = abstractionPath + File.separator + "Abstractions";
00854 LineNumberReader r = new LineNumberReader(new FileReader(abstractionListPath));
00855 String abstraction;
00856 while ((abstraction = r.readLine()) != null) {
00857 abstraction = abstraction.trim();
00858 if (!"".equals(abstraction))
00859 abstractions.add(abstraction);
00860 }
00861 r.close();
00862 } catch (Throwable e) {
00863 System.out.println("Cannot load abstractions...");
00864 e.printStackTrace();
00865 }
00866 }
00867
00868
00869
00870
00871
00872 private void initConnections() throws java.lang.Exception {
00873
00874
00875 getNewButton().addActionListener(ivjEventHandler);
00876 getAddToLibraryButton().addActionListener(ivjEventHandler);
00877 getPVSButton().addActionListener(ivjEventHandler);
00878 getSaveAsButton().addActionListener(ivjEventHandler);
00879 getOpenButton().addActionListener(ivjEventHandler);
00880 getShowButton().addActionListener(ivjEventHandler);
00881 getRemoveButton().addActionListener(ivjEventHandler);
00882 }
00883
00884
00885
00886
00887 private void initialize() {
00888 try {
00889
00890
00891 setName("AbtractionLibraryManager");
00892 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
00893 setSize(546, 474);
00894 setModal(true);
00895 setTitle("Abstraction Library Manager");
00896 setContentPane(getJDialogContentPane());
00897 initConnections();
00898 } catch (java.lang.Throwable ivjExc) {
00899 handleException(ivjExc);
00900 }
00901
00902 updateAbstractionTable();
00903
00904 }
00905
00906
00907
00908
00909 public static void main(java.lang.String[] args) {
00910 try {
00911 AbstractionLibraryManager aAbstractionLibraryManager;
00912 aAbstractionLibraryManager = new AbstractionLibraryManager();
00913 aAbstractionLibraryManager.setModal(true);
00914 aAbstractionLibraryManager.addWindowListener(new java.awt.event.WindowAdapter() {
00915 public void windowClosing(java.awt.event.WindowEvent e) {
00916 System.exit(0);
00917 };
00918 });
00919 aAbstractionLibraryManager.setVisible(true);
00920 } catch (Throwable exception) {
00921 System.err.println("Exception occurred in main() of javax.swing.JDialog");
00922 exception.printStackTrace(System.out);
00923 }
00924 }
00925
00926
00927
00928 public void newButton_ActionEvents() {
00929 return;
00930 }
00931
00932
00933
00934 public void openButton_ActionEvents() {
00935 FileChooser.chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
00936 FileChooser.chooser.setFileFilter(FileChooser.BASL);
00937 FileChooser.chooser.setSelectedFile(new File(""));
00938 FileChooser.chooser.setFileSelectionMode(FileChooser.FILES_ONLY);
00939 if (FileChooser.chooser.showOpenDialog(this) == FileChooser.APPROVE_OPTION) {
00940 File file = FileChooser.chooser.getSelectedFile();
00941 if (!file.exists()) {
00942 JOptionPane.showMessageDialog(this, "File is not exist", "Open Error", JOptionPane.ERROR_MESSAGE);
00943 return;
00944 }
00945 try {
00946 FileReader r = new FileReader(file);
00947 AbstractionGenerator ag = new AbstractionGenerator(new PushbackReader(r));
00948 getBASLCodeTextArea().setText(AbstractionPrinter.print(ag.getNode(), true));
00949 r.close();
00950 } catch (Exception e) {
00951 JOptionPane.showMessageDialog(this, e.getMessage(), "Open Error", JOptionPane.ERROR_MESSAGE);
00952 }
00953 }
00954 }
00955
00956
00957
00958 public void pVSButton_ActionEvents() {
00959 try {
00960 AbstractionGenerator ag = new AbstractionGenerator(new StringReader(getBASLCodeTextArea().getText()));
00961 String s = ag.generate(abstractionPackage);
00962 ag.getErrors().remove("Default token is undefined");
00963 if (ag.getErrors().size() > 0) {
00964 StringBuffer buffer = new StringBuffer("Errors:\n");
00965 for (Iterator i = ag.getErrors().iterator(); i.hasNext();) {
00966 buffer.append("- " + i.next() + "\n");
00967 }
00968 if (ag.getWarnings().size() > 0) {
00969 buffer.append("Warnings:\n");
00970 for (Iterator i = ag.getWarnings().iterator(); i.hasNext();) {
00971 buffer.append("- " + i.next() + "\n");
00972 }
00973 }
00974 JOptionPane.showMessageDialog(this, buffer.toString(), "Cannnot run PVS", JOptionPane.ERROR_MESSAGE);
00975 return;
00976 }
00977 Reader r = new StringReader(AbstractionPrinter.print(ag.getNode(), false));
00978 parser parserObj = new parser(new Yylex(r));
00979 parserObj.parse();
00980 r.close();
00981 if (parserObj.npredicates != parserObj.tokens.size()) {
00982 JOptionPane.showMessageDialog(this, "Wrong token set", "Cannnot run PVS", JOptionPane.ERROR_MESSAGE);
00983 return;
00984 }
00985 new File("abstraction.pvs").delete();
00986 new File("abstraction.prf").delete();
00987 new File("abstraction.el").delete();
00988 PrintWriter pwPVS = new PrintWriter(new FileWriter("abstraction.pvs"));
00989 PrintWriter pwPRF = new PrintWriter(new FileWriter("abstraction.prf"));
00990 PrintWriter pwEL = new PrintWriter(new FileWriter("abstraction.el"));
00991 if (pwPVS == null || pwPRF == null || pwEL == null) {
00992 JOptionPane.showMessageDialog(this, "Unable to create temporary files", "Cannnot run PVS", JOptionPane.ERROR_MESSAGE);
00993 return;
00994 }
00995 if (parserObj.basic_type == sym.INT)
00996 PVS.begin_int(pwPVS);
00997 else
00998 PVS.begin_float(pwPVS);
00999 parserObj.tree.print_PVS(pwPVS);
01000 PVS.check(pwPVS, parserObj.npredicates);
01001 PVS.rest(pwPVS, parserObj.npredicates, parserObj.basic_type);
01002 PVS.prf(pwPRF, parserObj.npredicates, parserObj.basic_type);
01003 pwEL.println("(prove-pvs-file \"abstraction\")");
01004 pwPRF.close();
01005 pwPVS.close();
01006 pwEL.close();
01007 PVS.execAndWait("pvs -batch -q -l abstraction.el -v 1");
01008 StringWriter sw = new StringWriter();
01009 PrintWriter pwSpec = new PrintWriter(sw);
01010 if (parserObj.basic_type == sym.INT)
01011 pwSpec.print("abstraction " + parserObj.name + " extends integral\n begin\n");
01012 else
01013 pwSpec.print("abstraction " + parserObj.name + " extends real\n begin\n");
01014 pwSpec.print(" TOKENS = { ");
01015 for (int i = 0; i < parserObj.npredicates - 1; i++)
01016 pwSpec.print(parserObj.tokens.elementAt(i) + " , ");
01017 pwSpec.print(parserObj.tokens.elementAt(parserObj.npredicates - 1) + " }; ");
01018 PVS.check_BASL(pwSpec, parserObj.npredicates, parserObj.tokens);
01019 pwSpec.print("\n\n abstract(" + parserObj.variable + ")\n begin\n");
01020 parserObj.tree.print_BASL(pwSpec);
01021 pwSpec.print(" end\n\n");
01022 PVS.rest_BASL(pwSpec, parserObj.npredicates, parserObj.basic_type, parserObj.tokens);
01023 getBASLCodeTextArea().setText(sw.toString());
01024 pwSpec.close();
01025 } catch (Throwable e) {
01026 JOptionPane.showMessageDialog(this, e.getMessage(), "Cannnot run PVS", JOptionPane.ERROR_MESSAGE);
01027 e.printStackTrace();
01028 }
01029 new File("abstraction.pvs").delete();
01030 new File("abstraction.prf").delete();
01031 new File("abstraction.el").delete();
01032 }
01033
01034
01035
01036 public void removeButton_ActionEvents() {
01037 int index = getScrollPaneTable().getSelectedRow();
01038 if (index >= 0) {
01039 String name = (String) abstractions.toArray()[index];
01040 boolean t = "".equals(abstractionPackage) ? name.startsWith(abstractionPackage + "integral.") : name.startsWith(abstractionPackage + ".");
01041 if (t) {
01042 if (JOptionPane.showConfirmDialog(this, "Do you want to delete the Java source and class files also?", "Question", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
01043 AbstractionClassLoader.removeClass(name);
01044
01045 String filename = "".equals(abstractionPackage) ? abstractionPath + File.separator + name.replace('.', File.separatorChar) : abstractionPath + File.separator + name.substring(name.indexOf(abstractionPackage) + 1).replace('.', File.separatorChar);
01046 new File(filename + ".java").delete();
01047 new File(filename + ".class").delete();
01048 }
01049 }
01050 abstractions.remove(name);
01051 try {
01052 updateAbstractionList();
01053 } catch (Exception e) {
01054 }
01055 }
01056 }
01057 private void runJavac(String classpath, String filename) {
01058 String cmdLine = "javac -g -classpath " + classpath + " " + filename;
01059 System.out.println(cmdLine);
01060 sun.tools.javac.Main javac = new sun.tools.javac.Main(System.out, "Bandera");
01061 if (!javac.compile(new String[] { "-g", "-classpath", classpath, filename })) {
01062 System.out.println("Error while compiling the abstraction definition");
01063 }
01064 }
01065
01066
01067
01068 public void saveAsButton_ActionEvents() {
01069 FileChooser.chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
01070 FileChooser.chooser.setFileFilter(FileChooser.BASL);
01071 FileChooser.chooser.setSelectedFile(new File(""));
01072 FileChooser.chooser.setFileSelectionMode(FileChooser.FILES_ONLY);
01073 if (FileChooser.chooser.showSaveDialog(this) == FileChooser.APPROVE_OPTION) {
01074 File file = FileChooser.chooser.getSelectedFile();
01075 if (file.exists()) {
01076 if (JOptionPane.showConfirmDialog(this, "Do you want to overwrite the file?", "Confirm", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
01077 file.delete();
01078 } else {
01079 return;
01080 }
01081 }
01082 try {
01083 PrintWriter pw = new PrintWriter(new FileWriter(file));
01084 pw.print(getBASLCodeTextArea().getText());
01085 pw.flush();
01086 pw.close();
01087 } catch (Exception e) {
01088 JOptionPane.showMessageDialog(this, e.getMessage(), "Saving Error", JOptionPane.ERROR_MESSAGE);
01089 }
01090 }
01091 }
01092
01093
01094
01095 public void showButton_ActionEvents() {
01096 int index = getScrollPaneTable().getSelectedRow();
01097 if (index >= 0) {
01098 getBASLCodeTextArea().setText((String) AbstractionClassLoader.invokeMethod((String) abstractions.toArray()[index], "getBASLRepresentation", new Class[0], null, new Object[0]));
01099 }
01100 }
01101
01102
01103
01104 private synchronized void updateAbstractionList() throws Exception {
01105 File f = new File(abstractionListPath);
01106 if (f.exists()) f.delete();
01107 PrintWriter pw = new PrintWriter(new FileWriter(abstractionListPath));
01108 for (Iterator i = abstractions.iterator(); i.hasNext();) {
01109 pw.println(i.next().toString());
01110 }
01111 pw.flush();
01112 pw.close();
01113 updateAbstractionTable();
01114 }
01115
01116
01117
01118 private void updateAbstractionTable() {
01119 JTreeTable.processAbstractions(getAbstractions());
01120 if (TypeGUI.typeGUI != null) TypeGUI.typeGUI.reset();
01121 Object[][] data = new Object[abstractions.size()][3];
01122 String[] abstractions = new String[data.length];
01123 System.arraycopy(this.abstractions.toArray(), 0, abstractions, 0, data.length);
01124 for (int i = 0; i < data.length; i++) {
01125 data[i][0] = AbstractionClassLoader.invokeMethod(abstractions[i], "getName", new Class[0], null, new Object[0]);
01126 int numTokens = ((Integer) AbstractionClassLoader.invokeMethod(abstractions[i], "getNumOfTokens", new Class[0], null, new Object[0])).intValue();
01127 HashSet tokens = new HashSet();
01128 for (int j = 0; j < numTokens; j++) {
01129 String token = (String) AbstractionClassLoader.invokeMethod(abstractions[i], "getToken", new Class[] {int.class}, null, new Object[] {new Integer(j)});
01130 tokens.add(token.substring(token.indexOf(".") + 1));
01131 }
01132 data[i][1] = tokens.toString().replace('[', '{').replace(']', '}');
01133 data[i][2] = "integral";
01134 }
01135 getScrollPaneTable().setModel(new DefaultTableModel(data, columnNames));
01136 getScrollPaneTable().sizeColumnsToFit(0);
01137 }
01138 }