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
00036
00037
00038 import java.io.*;
00039 import javax.swing.*;
00040 import java.util.Vector;
00041 import java.util.Iterator;
00042 import javax.swing.event.*;
00043 import java.util.Hashtable;
00044 import ca.mcgill.sable.soot.*;
00045 import edu.ksu.cis.bandera.bui.*;
00046 import javax.swing.tree.TreeNode;
00047 import edu.ksu.cis.bandera.abstraction.*;
00048 import javax.swing.filechooser.FileFilter;
00049 import edu.ksu.cis.bandera.abstraction.options.*;
00050 import edu.ksu.cis.bandera.abstraction.typeinference.*;
00051 public class TypeGUI extends JFrame {
00052 static TypeGUI typeGUI;
00053 private JScrollPane ivjJScrollPane1 = null;
00054 protected java.util.Vector classes;
00055 private JToolBar ivjJToolBar1 = null;
00056 private JPanel ivjJFrameContentPane = null;
00057 protected TypeTree tree;
00058 protected JTreeTable treeTable;
00059 protected java.util.Vector methods;
00060 IvjEventHandler ivjEventHandler = new IvjEventHandler();
00061 protected java.io.File file;
00062 private JButton ivjTypeCheckButton = null;
00063 private JButton ivjSaveOptionsButton = null;
00064
00065 class IvjEventHandler implements java.awt.event.ActionListener {
00066 public void actionPerformed(java.awt.event.ActionEvent e) {
00067 if (e.getSource() == TypeGUI.this.getTypeCheckButton())
00068 connEtoC1(e);
00069 if (e.getSource() == TypeGUI.this.getSaveOptionsButton())
00070 connEtoC2(e);
00071 };
00072 };
00073
00074
00075
00076 public TypeGUI() {
00077 super();
00078 initialize();
00079 }
00080
00081
00082
00083 public TypeGUI(Vector v) {
00084 super();
00085 this.classes = v;
00086 initialize();
00087 }
00088
00089
00090
00091
00092
00093 private void connEtoC1(java.awt.event.ActionEvent arg1) {
00094 try {
00095
00096
00097 this.typeCheck();
00098
00099
00100 } catch (java.lang.Throwable ivjExc) {
00101
00102
00103 handleException(ivjExc);
00104 ivjExc.printStackTrace();
00105 }
00106 }
00107
00108
00109
00110
00111
00112 private void connEtoC2(java.awt.event.ActionEvent arg1) {
00113 try {
00114
00115
00116 this.saveOptions();
00117
00118
00119 } catch (java.lang.Throwable ivjExc) {
00120
00121
00122 handleException(ivjExc);
00123 }
00124 }
00125
00126
00127
00128 public void expandTree() {
00129 JTree tree = treeTable.getTree();
00130 for (int i = 0; i < tree.getRowCount(); i++) {
00131 tree.expandRow(i);
00132 }
00133 }
00134
00135
00136
00137
00138
00139 public java.io.File getFile() {
00140 return file;
00141 }
00142
00143
00144
00145
00146
00147 private javax.swing.JPanel getJFrameContentPane() {
00148 if (ivjJFrameContentPane == null) {
00149 try {
00150 ivjJFrameContentPane = new javax.swing.JPanel();
00151 ivjJFrameContentPane.setName("JFrameContentPane");
00152 ivjJFrameContentPane.setLayout(new java.awt.GridBagLayout());
00153 ivjJFrameContentPane.setBackground(new java.awt.Color(255,255,255));
00154 ivjJFrameContentPane.setMaximumSize(new java.awt.Dimension(2147483647, 2147483647));
00155 ivjJFrameContentPane.setMinimumSize(new java.awt.Dimension(277, 145));
00156 ivjJFrameContentPane.setBounds(0, 0, 0, 0);
00157
00158 java.awt.GridBagConstraints constraintsJToolBar1 = new java.awt.GridBagConstraints();
00159 constraintsJToolBar1.gridx = 0; constraintsJToolBar1.gridy = 0;
00160 constraintsJToolBar1.fill = java.awt.GridBagConstraints.HORIZONTAL;
00161 constraintsJToolBar1.weightx = 1.0;
00162 constraintsJToolBar1.ipadx = 227;
00163 getJFrameContentPane().add(getJToolBar1(), constraintsJToolBar1);
00164
00165 java.awt.GridBagConstraints constraintsJScrollPane1 = new java.awt.GridBagConstraints();
00166 constraintsJScrollPane1.gridx = 0; constraintsJScrollPane1.gridy = 1;
00167 constraintsJScrollPane1.fill = java.awt.GridBagConstraints.BOTH;
00168 constraintsJScrollPane1.weightx = 1.0;
00169 constraintsJScrollPane1.weighty = 1.0;
00170 constraintsJScrollPane1.ipadx = 138;
00171 constraintsJScrollPane1.ipady = 98;
00172 getJFrameContentPane().add(getJScrollPane1(), constraintsJScrollPane1);
00173
00174
00175 } catch (java.lang.Throwable ivjExc) {
00176
00177
00178 handleException(ivjExc);
00179 }
00180 }
00181 return ivjJFrameContentPane;
00182 }
00183
00184
00185
00186
00187
00188 private javax.swing.JScrollPane getJScrollPane1() {
00189 if (ivjJScrollPane1 == null) {
00190 try {
00191 ivjJScrollPane1 = new javax.swing.JScrollPane();
00192 ivjJScrollPane1.setName("JScrollPane1");
00193 ivjJScrollPane1.setOpaque(true);
00194
00195 getJScrollPane1().setViewportView(treeTable = new JTreeTable(tree = new TypeTree()));
00196
00197
00198 } catch (java.lang.Throwable ivjExc) {
00199
00200 ivjExc.printStackTrace();
00201
00202 handleException(ivjExc);
00203 }
00204 }
00205 return ivjJScrollPane1;
00206 }
00207
00208
00209
00210
00211
00212 private javax.swing.JToolBar getJToolBar1() {
00213 if (ivjJToolBar1 == null) {
00214 try {
00215 ivjJToolBar1 = new javax.swing.JToolBar();
00216 ivjJToolBar1.setName("JToolBar1");
00217 ivjJToolBar1.setFloatable(false);
00218 ivjJToolBar1.setAlignmentY(0.5F);
00219 ivjJToolBar1.setMaximumSize(new java.awt.Dimension(1000, 30));
00220 ivjJToolBar1.setMinimumSize(new java.awt.Dimension(50, 30));
00221 ivjJToolBar1.add(getTypeCheckButton());
00222 ivjJToolBar1.add(getSaveOptionsButton());
00223
00224
00225 } catch (java.lang.Throwable ivjExc) {
00226
00227
00228 handleException(ivjExc);
00229 }
00230 }
00231 return ivjJToolBar1;
00232 }
00233
00234
00235
00236
00237
00238 public Hashtable getOptions() {
00239 return tree.getOptions();
00240 }
00241
00242
00243
00244
00245
00246 private javax.swing.JButton getSaveOptionsButton() {
00247 if (ivjSaveOptionsButton == null) {
00248 try {
00249 ivjSaveOptionsButton = new javax.swing.JButton();
00250 ivjSaveOptionsButton.setName("SaveOptionsButton");
00251 ivjSaveOptionsButton.setToolTipText("Saves the typing options.");
00252 ivjSaveOptionsButton.setAlignmentY(0.5F);
00253 ivjSaveOptionsButton.setText("");
00254 ivjSaveOptionsButton.setMaximumSize(new java.awt.Dimension(30, 30));
00255 ivjSaveOptionsButton.setHorizontalTextPosition(0);
00256 ivjSaveOptionsButton.setActionCommand("SaveOptionsButton");
00257 ivjSaveOptionsButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/ksu/cis/bandera/bui/images/SaveAs24.gif")));
00258 ivjSaveOptionsButton.setAlignmentX(0.5F);
00259 ivjSaveOptionsButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
00260 ivjSaveOptionsButton.setMinimumSize(new java.awt.Dimension(20, 20));
00261 ivjSaveOptionsButton.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/ksu/cis/bandera/bui/images/SaveAs24.gif")));
00262 ivjSaveOptionsButton.setBorder(new javax.swing.border.CompoundBorder());
00263
00264
00265 } catch (java.lang.Throwable ivjExc) {
00266
00267
00268 handleException(ivjExc);
00269 }
00270 }
00271 return ivjSaveOptionsButton;
00272 }
00273
00274
00275
00276
00277
00278 private javax.swing.JButton getTypeCheckButton() {
00279 if (ivjTypeCheckButton == null) {
00280 try {
00281 ivjTypeCheckButton = new javax.swing.JButton();
00282 ivjTypeCheckButton.setName("TypeCheckButton");
00283 ivjTypeCheckButton.setToolTipText("Type check.");
00284 ivjTypeCheckButton.setAlignmentY(0.5F);
00285 ivjTypeCheckButton.setText("");
00286 ivjTypeCheckButton.setMaximumSize(new java.awt.Dimension(30, 30));
00287 ivjTypeCheckButton.setHorizontalTextPosition(0);
00288 ivjTypeCheckButton.setActionCommand("JToolBarButton1");
00289 ivjTypeCheckButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/ksu/cis/bandera/bui/images/Run24.gif")));
00290 ivjTypeCheckButton.setAlignmentX(0.5F);
00291 ivjTypeCheckButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
00292 ivjTypeCheckButton.setMinimumSize(new java.awt.Dimension(20, 20));
00293 ivjTypeCheckButton.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/ksu/cis/bandera/bui/images/Run24.gif")));
00294 ivjTypeCheckButton.setBorder(new javax.swing.border.CompoundBorder());
00295
00296
00297 } catch (java.lang.Throwable ivjExc) {
00298
00299
00300 handleException(ivjExc);
00301 }
00302 }
00303 return ivjTypeCheckButton;
00304 }
00305
00306
00307
00308
00309 private void handleException(java.lang.Throwable exception) {
00310
00311
00312
00313
00314 }
00315
00316
00317
00318
00319
00320 private void initConnections() throws java.lang.Exception {
00321
00322
00323 getTypeCheckButton().addActionListener(ivjEventHandler);
00324 getSaveOptionsButton().addActionListener(ivjEventHandler);
00325 }
00326
00327
00328
00329
00330 private void initialize() {
00331 try {
00332
00333 typeGUI = this;
00334
00335 setName("TypeGUI");
00336 setSize(426, 240);
00337 setContentPane(getJFrameContentPane());
00338 initConnections();
00339 } catch (java.lang.Throwable ivjExc) {
00340 handleException(ivjExc);
00341 }
00342
00343 setTitle("Abstract Type Inference<Untitled>");
00344
00345 }
00346
00347
00348
00349 public void reset() {
00350 setTitle("Abstract Type Inference<Untitled>");
00351 if (classes != null) {
00352 tree.setRoot(TypeTree.createTree(classes));
00353 tree.nodeStructureChanged((TreeNode) tree.getRoot());
00354 }
00355 }
00356
00357
00358
00359 public void saveOptions() {
00360 boolean write = true;
00361 JFileChooser chooser = new JFileChooser();
00362
00363 chooser.setFileFilter(FileChooser.ABSTRACTION);
00364 int returnVal = chooser.showSaveDialog(getParent());
00365 if (returnVal == JFileChooser.APPROVE_OPTION) {
00366
00367 try {
00368 if (chooser.getSelectedFile().exists()) {
00369 String filename = chooser.getSelectedFile().getCanonicalPath();
00370 if (JOptionPane.showConfirmDialog(this, "Overwrite " + filename + "?", "Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
00371 System.out.println("You chose not to overwrite " + filename);
00372 write = false;
00373 }
00374 }
00375 } catch (Exception e) {
00376 e.printStackTrace();
00377 }
00378 if (write) {
00379 try {
00380 file = chooser.getSelectedFile();
00381 FileWriter fout;
00382 PrintWriter out = new PrintWriter(fout = new FileWriter(file));
00383 OptionsSaverLoader.save(out, tree.getOptions());
00384 out.close();
00385 fout.close();
00386 BUI.sessions.getActiveSession().setAbsFilename(file.getAbsolutePath());
00387 BUI.manager.updateProperty();
00388 setTitle("Abstract Type Inference<" + file.getName() + ">");
00389 } catch (Exception e) {
00390 e.printStackTrace();
00391 }
00392 }
00393 }
00394 return;
00395 }
00396
00397
00398
00399
00400
00401 public void setClasses(Vector v) {
00402
00403 this.classes = v;
00404 reset();
00405 }
00406
00407
00408
00409
00410
00411 public void setFile(java.io.File newFile) {
00412 file = newFile;
00413 }
00414
00415
00416
00417
00418 public void setInferredTypes(TypeTable typeTable) {
00419 expandTree();
00420 tree.setInferedTypes(typeTable);
00421 }
00422
00423
00424
00425
00426 public void setSelectedTypes(Hashtable options, String filename) {
00427 setTitle("Abstract Type Inference<" + new File(filename).getName() + ">");
00428 expandTree();
00429 tree.setSelectedTypes(options);
00430 }
00431
00432
00433
00434 public void typeCheck() {
00435 try {
00436 TypeTable table;
00437
00438
00439 TypeInference ti = new TypeInference();
00440 table = ti.type(((SootClass) classes.get(0)).getManager(), getOptions());
00441 tree.setInferedTypes(table);
00442 if (ti.getErrors().size() != 0) {
00443 Hashtable errorTable = ti.getErrors();
00444 Iterator i = errorTable.keySet().iterator();
00445 while (i.hasNext()) {
00446 Object o = i.next();
00447 JOptionPane.showMessageDialog(this, errorTable.get(o), o.toString(), JOptionPane.ERROR_MESSAGE);
00448 System.err.println(o + ": " + errorTable.get(o));
00449 }
00450 } else {
00451 JOptionPane.showMessageDialog(this, "OK", "Typing", JOptionPane.INFORMATION_MESSAGE);
00452 }
00453
00454
00455 } catch (Exception e) {
00456 e.printStackTrace();
00457 }
00458 return;
00459 }
00460 }