Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

TypeGUI.java

00001 package edu.ksu.cis.bandera.abstraction.gui;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1998, 1999, 2000   Shawn Laubach (laubach@acm.org)  *
00006  * All rights reserved.                                              *
00007  *                                                                   *
00008  * Modifications by Robby (robby@cis.ksu.edu) are                    *
00009  * Copyright (C) 2000 Robby.  All rights reserved.                   *
00010  *                                                                   *
00011  * This work was done as a project in the SAnToS Laboratory,         *
00012  * Department of Computing and Information Sciences, Kansas State    *
00013  * University, USA (http://www.cis.ksu.edu/santos).                  *
00014  * It is understood that any modification not identified as such is  *
00015  * not covered by the preceding statement.                           *
00016  *                                                                   *
00017  * This work is free software; you can redistribute it and/or        *
00018  * modify it under the terms of the GNU Library General Public       *
00019  * License as published by the Free Software Foundation; either      *
00020  * version 2 of the License, or (at your option) any later version.  *
00021  *                                                                   *
00022  * This work is distributed in the hope that it will be useful,      *
00023  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00025  * Library General Public License for more details.                  *
00026  *                                                                   *
00027  * You should have received a copy of the GNU Library General Public *
00028  * License along with this toolkit; if not, write to the             *
00029  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00030  * Boston, MA  02111-1307, USA.                                      *
00031  *                                                                   *
00032  * Java is a trademark of Sun Microsystems, Inc.                     *
00033  *                                                                   *
00034  * To submit a bug report, send a comment, or get the latest news on *
00035  * this project and other SAnToS projects, please visit the web-site *
00036  *                http://www.cis.ksu.edu/santos                      *
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  * TypeGUI constructor comment.
00075  */
00076 public TypeGUI() {
00077     super();
00078     initialize();
00079 }
00080 /**
00081  * TypeGUI constructor comment.
00082  */
00083 public TypeGUI(Vector v) {
00084     super();
00085     this.classes = v;
00086     initialize();
00087 }
00088 /**
00089  * connEtoC1:  (JToolBarButton1.action.actionPerformed(java.awt.event.ActionEvent) --> TypeGUI.typeCheck()V)
00090  * @param arg1 java.awt.event.ActionEvent
00091  */
00092 /* WARNING: THIS METHOD WILL BE REGENERATED. */
00093 private void connEtoC1(java.awt.event.ActionEvent arg1) {
00094     try {
00095         // user code begin {1}
00096         // user code end
00097         this.typeCheck();
00098         // user code begin {2}
00099         // user code end
00100     } catch (java.lang.Throwable ivjExc) {
00101         // user code begin {3}
00102         // user code end
00103         handleException(ivjExc);
00104         ivjExc.printStackTrace();
00105     }
00106 }
00107 /**
00108  * connEtoC2:  (JToolBarButton2.action.actionPerformed(java.awt.event.ActionEvent) --> TypeGUI.jToolBarButton2_ActionPerformed()V)
00109  * @param arg1 java.awt.event.ActionEvent
00110  */
00111 /* WARNING: THIS METHOD WILL BE REGENERATED. */
00112 private void connEtoC2(java.awt.event.ActionEvent arg1) {
00113     try {
00114         // user code begin {1}
00115         // user code end
00116         this.saveOptions();
00117         // user code begin {2}
00118         // user code end
00119     } catch (java.lang.Throwable ivjExc) {
00120         // user code begin {3}
00121         // user code end
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  * Insert the method's description here.
00136  * Creation date: (5/25/00 3:10:49 PM)
00137  * @return java.io.File
00138  */
00139 public java.io.File getFile() {
00140     return file;
00141 }
00142 /**
00143  * Return the JFrameContentPane property value.
00144  * @return javax.swing.JPanel
00145  */
00146 /* WARNING: THIS METHOD WILL BE REGENERATED. */
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             // user code begin {1}
00174             // user code end
00175         } catch (java.lang.Throwable ivjExc) {
00176             // user code begin {2}
00177             // user code end
00178             handleException(ivjExc);
00179         }
00180     }
00181     return ivjJFrameContentPane;
00182 }
00183 /**
00184  * Return the JScrollPane1 property value.
00185  * @return javax.swing.JScrollPane
00186  */
00187 /* WARNING: THIS METHOD WILL BE REGENERATED. */
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             // user code begin {1}
00195             getJScrollPane1().setViewportView(treeTable = new JTreeTable(tree = new TypeTree()));
00196             //t.setBackground(getJPanel1().getBackground());
00197             // user code end
00198         } catch (java.lang.Throwable ivjExc) {
00199             // user code begin {2}
00200             ivjExc.printStackTrace();
00201             // user code end
00202             handleException(ivjExc);
00203         }
00204     }
00205     return ivjJScrollPane1;
00206 }
00207 /**
00208  * Return the JToolBar1 property value.
00209  * @return javax.swing.JToolBar
00210  */
00211 /* WARNING: THIS METHOD WILL BE REGENERATED. */
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             // user code begin {1}
00224             // user code end
00225         } catch (java.lang.Throwable ivjExc) {
00226             // user code begin {2}
00227             // user code end
00228             handleException(ivjExc);
00229         }
00230     }
00231     return ivjJToolBar1;
00232 }
00233 /**
00234  * Insert the method's description here.
00235  * Creation date: (5/3/00 4:35:18 PM)
00236  * @return java.util.Hashtable
00237  */
00238 public Hashtable getOptions() {
00239     return tree.getOptions();
00240 }
00241 /**
00242  * Return the JToolBarButton2 property value.
00243  * @return javax.swing.JButton
00244  */
00245 /* WARNING: THIS METHOD WILL BE REGENERATED. */
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             // user code begin {1}
00264             // user code end
00265         } catch (java.lang.Throwable ivjExc) {
00266             // user code begin {2}
00267             // user code end
00268             handleException(ivjExc);
00269         }
00270     }
00271     return ivjSaveOptionsButton;
00272 }
00273 /**
00274  * Return the JToolBarButton1 property value.
00275  * @return javax.swing.JButton
00276  */
00277 /* WARNING: THIS METHOD WILL BE REGENERATED. */
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             // user code begin {1}
00296             // user code end
00297         } catch (java.lang.Throwable ivjExc) {
00298             // user code begin {2}
00299             // user code end
00300             handleException(ivjExc);
00301         }
00302     }
00303     return ivjTypeCheckButton;
00304 }
00305 /**
00306  * Called whenever the part throws an exception.
00307  * @param exception java.lang.Throwable
00308  */
00309 private void handleException(java.lang.Throwable exception) {
00310 
00311     /* Uncomment the following lines to print uncaught exceptions to stdout */
00312     // System.out.println("--------- UNCAUGHT EXCEPTION ---------");
00313     // exception.printStackTrace(System.out);
00314 }
00315 /**
00316  * Initializes connections
00317  * @exception java.lang.Exception The exception description.
00318  */
00319 /* WARNING: THIS METHOD WILL BE REGENERATED. */
00320 private void initConnections() throws java.lang.Exception {
00321     // user code begin {1}
00322     // user code end
00323     getTypeCheckButton().addActionListener(ivjEventHandler);
00324     getSaveOptionsButton().addActionListener(ivjEventHandler);
00325 }
00326 /**
00327  * Initialize the class.
00328  */
00329 /* WARNING: THIS METHOD WILL BE REGENERATED. */
00330 private void initialize() {
00331     try {
00332         // user code begin {1}
00333         typeGUI = this;
00334         // user code end
00335         setName("TypeGUI");
00336         setSize(426, 240);
00337         setContentPane(getJFrameContentPane());
00338         initConnections();
00339     } catch (java.lang.Throwable ivjExc) {
00340         handleException(ivjExc);
00341     }
00342     // user code begin {2}
00343     setTitle("Abstract Type Inference<Untitled>");
00344     // user code end
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  * Comment
00358  */
00359 public void saveOptions() {
00360     boolean write = true;
00361     JFileChooser chooser = new JFileChooser();
00362     // Note: source for ExtensionFileFilter can be found in the SwingSet demo 
00363     chooser.setFileFilter(FileChooser.ABSTRACTION);
00364     int returnVal = chooser.showSaveDialog(getParent());
00365     if (returnVal == JFileChooser.APPROVE_OPTION) {
00366         //System.out.println("You chose to open this file: " + chooser.getSelectedFile().getName());
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  * Insert the method's description here.
00398  * Creation date: (5/3/00 4:29:31 PM)
00399  * @param v java.util.Vector
00400  */
00401 public void setClasses(Vector v) {
00402     //Vector c;
00403     this.classes = v;
00404     reset();
00405 }
00406 /**
00407  * Insert the method's description here.
00408  * Creation date: (5/25/00 3:10:49 PM)
00409  * @param newFile java.io.File
00410  */
00411 public void setFile(java.io.File newFile) {
00412     file = newFile;
00413 }
00414 /**
00415  * 
00416  * @param typeTable edu.ksu.cis.bandera.abstraction.typeinference.TypeTable
00417  */
00418 public void setInferredTypes(TypeTable typeTable) {
00419     expandTree();
00420     tree.setInferedTypes(typeTable);
00421 }
00422 /**
00423  * 
00424  * @param options java.util.Hashtable
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  * Comment
00433  */
00434 public void typeCheck() {
00435     try {
00436         TypeTable table;
00437         //System.out.println(tree.getOptions());
00438         //System.out.println("Pretty:\n" + tree.getOptions().prettyPrint());
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         //System.out.println(TypeInference.getErrors());
00455     } catch (Exception e) {
00456         e.printStackTrace();
00457     }
00458     return;
00459 }
00460 }

Generated at Thu Feb 7 06:58:46 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001