00001 package edu.ksu.cis.bandera.bui;
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 edu.ksu.cis.bandera.pdgslicer.datastructure.*;
00036 import ca.mcgill.sable.soot.*;
00037 import ca.mcgill.sable.soot.jimple.*;
00038 import edu.ksu.cis.bandera.annotation.*;
00039 import edu.ksu.cis.bandera.specification.assertion.datastructure.*;
00040 import edu.ksu.cis.bandera.jjjc.*;
00041 import edu.ksu.cis.bandera.jjjc.symboltable.*;
00042 import edu.ksu.cis.bandera.jjjc.symboltable.Package;
00043 import edu.ksu.cis.bandera.specification.predicate.datastructure.*;
00044 import edu.ksu.cis.bandera.util.*;
00045 import java.awt.*;
00046 import java.awt.event.*;
00047 import java.util.*;
00048 import javax.swing.*;
00049 import javax.swing.tree.*;
00050
00051
00052 public class BUISessionPane extends JPanel {
00053 private boolean showIconRightTree;
00054 private JSplitPane ivjBUISplitPane = null;
00055 private JScrollPane ivjLeftScrollPane = null;
00056 private JTree ivjLeftTree = null;
00057 private JScrollPane ivjRightScrollPane = null;
00058 private JTree ivjRightTree = null;
00059 IvjEventHandler ivjEventHandler = new IvjEventHandler();
00060
00061 class IvjEventHandler implements java.awt.event.MouseListener, javax.swing.event.TreeSelectionListener {
00062 public void mouseClicked(java.awt.event.MouseEvent e) {};
00063 public void mouseEntered(java.awt.event.MouseEvent e) {};
00064 public void mouseExited(java.awt.event.MouseEvent e) {};
00065 public void mousePressed(java.awt.event.MouseEvent e) {};
00066 public void mouseReleased(java.awt.event.MouseEvent e) {
00067 if (e.getSource() == BUISessionPane.this.getLeftTree())
00068 connEtoC2(e);
00069 };
00070 public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
00071 if (e.getSource() == BUISessionPane.this.getLeftTree())
00072 connEtoC1();
00073 };
00074 };
00075
00076
00077
00078 public BUISessionPane() {
00079 super();
00080 initialize();
00081 }
00082
00083
00084
00085
00086 public BUISessionPane(LayoutManager layout) {
00087 super(layout);
00088 }
00089
00090
00091
00092
00093
00094 public BUISessionPane(LayoutManager layout, boolean isDoubleBuffered) {
00095 super(layout, isDoubleBuffered);
00096 }
00097
00098
00099
00100
00101 public BUISessionPane(boolean isDoubleBuffered) {
00102 super(isDoubleBuffered);
00103 }
00104
00105
00106
00107
00108
00109 private static void addBlock(DefaultMutableTreeNode node, BlockStmtAnnotation ann) {
00110 if (ann == null) return;
00111
00112 Vector anns = ann.getContainedAnnotations();
00113 for (Enumeration e = anns.elements(); e.hasMoreElements();) {
00114 for (Enumeration e2 = buildTree((Annotation) e.nextElement()).elements(); e2.hasMoreElements();) {
00115 DefaultMutableTreeNode n = (DefaultMutableTreeNode) e2.nextElement();
00116 Object o = n.getUserObject();
00117 if (!"".equals(o.toString().trim())) node.add(n);
00118 }
00119 }
00120 }
00121
00122
00123
00124
00125
00126 private DefaultMutableTreeNode buildClassNode(SootClass sc) {
00127 AnnotationManager am = CompilationManager.getAnnotationManager();
00128
00129 TreeSet ts = new TreeSet();
00130 for (ca.mcgill.sable.util.Iterator i = sc.getFields().iterator(); i.hasNext();) {
00131 Annotation a = am.getAnnotation(sc, i.next());
00132 if (a != null)
00133 ts.add(a);
00134 }
00135 for (ca.mcgill.sable.util.Iterator i = sc.getMethods().iterator(); i.hasNext();) {
00136 Annotation a = am.getAnnotation(sc, i.next());
00137 if (a != null)
00138 ts.add(a);
00139 }
00140
00141 DefaultMutableTreeNode node = new DefaultMutableTreeNode(sc);
00142
00143 for (Iterator i = ts.iterator(); i.hasNext();) {
00144 node.add(new DefaultMutableTreeNode(i.next()));
00145 }
00146
00147 return node;
00148 }
00149
00150
00151
00152
00153
00154 private DefaultMutableTreeNode buildPackageNode(Package p) {
00155 DefaultMutableTreeNode pNode = new DefaultMutableTreeNode(p);
00156 Hashtable compiledClasses = CompilationManager.getCompiledClasses();
00157
00158 TreeSet cNames = new TreeSet();
00159 for (Enumeration e = compiledClasses.elements(); e.hasMoreElements();) {
00160 Name cName = new Name(((SootClass) e.nextElement()).getName());
00161 if (cName.getSuperName().equals(p.getName()))
00162 cNames.add(cName);
00163 }
00164
00165 for (Iterator j = cNames.iterator(); j.hasNext();) {
00166 Name cName = (Name) j.next();
00167 SootClass sc = (SootClass) compiledClasses.get(cName.toString());
00168 pNode.add(buildClassNode(sc));
00169 }
00170 return pNode;
00171 }
00172
00173
00174
00175
00176
00177 public static Vector buildTree(Annotation annotation) {
00178 Vector result = new Vector();
00179
00180 if (annotation == null) return result;
00181
00182 DefaultMutableTreeNode node = new DefaultMutableTreeNode(annotation);
00183
00184 result.addElement(node);
00185
00186 if (annotation instanceof BlockStmtAnnotation) {
00187 addBlock(node, (BlockStmtAnnotation) annotation);
00188 } else if (annotation instanceof BreakStmtAnnotation) {
00189 } else if (annotation instanceof ContinueStmtAnnotation) {
00190 } else if (annotation instanceof DoWhileStmtAnnotation) {
00191 Annotation ann = ((DoWhileStmtAnnotation) annotation).getBlockAnnotation();
00192 if (ann instanceof BlockStmtAnnotation) {
00193 addBlock(node, (BlockStmtAnnotation) ann);
00194 } else {
00195 for (Enumeration e = buildTree(ann).elements(); e.hasMoreElements();) {
00196 node.add((DefaultMutableTreeNode) e.nextElement());
00197 }
00198 }
00199 } else if (annotation instanceof EmptyStmtAnnotation) {
00200 } else if (annotation instanceof ExpStmtAnnotation) {
00201 } else if (annotation instanceof FieldDeclarationAnnotation) {
00202 } else if (annotation instanceof ForStmtAnnotation) {
00203 Annotation ann = ((ForStmtAnnotation) annotation).getBlockAnnotation();
00204 if (ann instanceof BlockStmtAnnotation) {
00205 addBlock(node, (BlockStmtAnnotation) ann);
00206 } else {
00207 for (Enumeration e = buildTree(ann).elements(); e.hasMoreElements();) {
00208 node.add((DefaultMutableTreeNode) e.nextElement());
00209 }
00210 }
00211 } else if (annotation instanceof IfStmtAnnotation) {
00212 Annotation tann = ((IfStmtAnnotation) annotation).getThenAnnotation();
00213 Annotation eann = ((IfStmtAnnotation) annotation).getElseAnnotation();
00214 for (Enumeration e = buildTree(tann).elements(); e.hasMoreElements();) {
00215 node.add((DefaultMutableTreeNode) e.nextElement());
00216 }
00217
00218 if (!(eann instanceof EmptyStmtAnnotation)) {
00219 DefaultMutableTreeNode elseNode = new DefaultMutableTreeNode("else");
00220 for (Enumeration e = buildTree(eann).elements(); e.hasMoreElements();) {
00221 elseNode.add((DefaultMutableTreeNode) e.nextElement());
00222 }
00223 result.addElement(elseNode);
00224 }
00225 } else if (annotation instanceof InstanceInitializerAnnotation) {
00226 } else if (annotation instanceof LabeledStmtAnnotation) {
00227 for (Enumeration e = buildTree(((LabeledStmtAnnotation) annotation).getAnnotation()).elements();
00228 e.hasMoreElements();) {
00229 node.add((DefaultMutableTreeNode) e.nextElement());
00230 }
00231 } else if (annotation instanceof EmptyStmtAnnotation) {
00232 } else if (annotation instanceof LocalDeclarationStmtAnnotation) {
00233 } else if (annotation instanceof ReturnStmtAnnotation) {
00234 } else if (annotation instanceof StaticInitializerAnnotation) {
00235 } else if (annotation instanceof SwitchStmtAnnotation) {
00236 Hashtable cases = ((SwitchStmtAnnotation) annotation).getSwitchCases();
00237 for (Enumeration e = ((SwitchStmtAnnotation) annotation).getSwitchCases().elements(); e.hasMoreElements();) {
00238 BlockStmtAnnotation a = (BlockStmtAnnotation) e.nextElement();
00239 DefaultMutableTreeNode caseNode = new DefaultMutableTreeNode(a.getNode());
00240 if (a.getNode() instanceof edu.ksu.cis.bandera.jjjc.node.ACaseSwitchLabel) {
00241 edu.ksu.cis.bandera.jjjc.node.ACaseSwitchLabel caseLabel = (edu.ksu.cis.bandera.jjjc.node.ACaseSwitchLabel) a.getNode();
00242 caseNode.setUserObject("case " + caseLabel.getExp().toString().trim() + ":");
00243 } else if (a.getNode() instanceof edu.ksu.cis.bandera.jjjc.node.ASwitchBlockStmtGroup) {
00244 edu.ksu.cis.bandera.jjjc.node.ASwitchBlockStmtGroup caseLabel = (edu.ksu.cis.bandera.jjjc.node.ASwitchBlockStmtGroup) a.getNode();
00245 String label = "";
00246 for (ca.mcgill.sable.util.Iterator i = caseLabel.getSwitchLabel().iterator(); i.hasNext();) {
00247 label += i.next();
00248 }
00249
00250 caseNode.setUserObject(label);
00251 }
00252 addBlock(caseNode, a);
00253 node.add(caseNode);
00254 }
00255 Annotation da = ((SwitchStmtAnnotation) annotation).getDefaultAnnotation();
00256 if (da != null) {
00257 DefaultMutableTreeNode defaultNode = new DefaultMutableTreeNode("default:");
00258 addBlock(defaultNode, (BlockStmtAnnotation) da);
00259 node.add(defaultNode);
00260 }
00261 } else if (annotation instanceof SynchronizedStmtAnnotation) {
00262 addBlock(node, (BlockStmtAnnotation) ((SynchronizedStmtAnnotation) annotation).getBlockAnnotation());
00263 } else if (annotation instanceof ThrowStmtAnnotation) {
00264 } else if (annotation instanceof TryFinallyStmtAnnotation) {
00265 addBlock(node, (BlockStmtAnnotation) ((TryStmtAnnotation) annotation).getBlockAnnotation());
00266 for (Enumeration e = ((TryStmtAnnotation) annotation).getCatchClauses().elements();
00267 e.hasMoreElements();) {
00268 Annotation a = (Annotation) e.nextElement();
00269 edu.ksu.cis.bandera.jjjc.node.ACatchClause catchClause = (edu.ksu.cis.bandera.jjjc.node.ACatchClause) a.getNode();
00270
00271 DefaultMutableTreeNode catchNode = new DefaultMutableTreeNode(a);
00272 addBlock(catchNode, (BlockStmtAnnotation) a);
00273 result.addElement(catchNode);
00274 }
00275 Annotation a = ((TryFinallyStmtAnnotation) annotation).getFinallyAnnotation();
00276 DefaultMutableTreeNode finallyNode = new DefaultMutableTreeNode(a);
00277 finallyNode.setUserObject("finally");
00278 addBlock(finallyNode, (BlockStmtAnnotation) a);
00279 result.addElement(finallyNode);
00280 } else if (annotation instanceof TryStmtAnnotation) {
00281 addBlock(node, (BlockStmtAnnotation) ((TryStmtAnnotation) annotation).getBlockAnnotation());
00282 for (Enumeration e = ((TryStmtAnnotation) annotation).getCatchClauses().elements();
00283 e.hasMoreElements();) {
00284 Annotation a = (Annotation) e.nextElement();
00285 edu.ksu.cis.bandera.jjjc.node.ACatchClause catchClause = (edu.ksu.cis.bandera.jjjc.node.ACatchClause) a.getNode();
00286
00287 DefaultMutableTreeNode catchNode = new DefaultMutableTreeNode(a);
00288 addBlock(catchNode, (BlockStmtAnnotation) a);
00289 result.addElement(catchNode);
00290 }
00291 } else if (annotation instanceof WhileStmtAnnotation) {
00292 Annotation ann = ((WhileStmtAnnotation) annotation).getBlockAnnotation();
00293 if (ann instanceof BlockStmtAnnotation) {
00294 addBlock(node, (BlockStmtAnnotation) ann);
00295 } else {
00296 for (Enumeration e = buildTree(ann).elements(); e.hasMoreElements();) {
00297 node.add((DefaultMutableTreeNode) e.nextElement());
00298 }
00299 }
00300 } else if (annotation instanceof ConstructorInvocationStmtAnnotation) {
00301 } else if (annotation instanceof SequentialAnnotation) {
00302 node.setUserObject("");
00303 }
00304
00305 Vector discard = new Vector();
00306
00307 for (Enumeration e = node.children(); e.hasMoreElements();) {
00308 DefaultMutableTreeNode child = (DefaultMutableTreeNode) e.nextElement();
00309 Object o = child.getUserObject();
00310 if ("".equals(o.toString().trim())) discard.addElement(child);
00311 }
00312
00313 for (Enumeration e = discard.elements(); e.hasMoreElements();) {
00314 node.remove((MutableTreeNode) e.nextElement());
00315 }
00316
00317 return result;
00318 }
00319
00320
00321
00322
00323 private void connEtoC1() {
00324 try {
00325
00326
00327 this.leftTree_TreeSelectionEvents();
00328
00329
00330 } catch (java.lang.Throwable ivjExc) {
00331
00332
00333 handleException(ivjExc);
00334 }
00335 }
00336
00337
00338
00339
00340
00341 private void connEtoC2(java.awt.event.MouseEvent arg1) {
00342 try {
00343
00344
00345 this.leftTree_MouseReleased(arg1);
00346
00347
00348 } catch (java.lang.Throwable ivjExc) {
00349
00350
00351 handleException(ivjExc);
00352 }
00353 }
00354
00355
00356
00357
00358 private static void getBuilderData() {
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389 }
00390
00391
00392
00393
00394
00395 private javax.swing.JSplitPane getBUISplitPane() {
00396 if (ivjBUISplitPane == null) {
00397 try {
00398 ivjBUISplitPane = new javax.swing.JSplitPane(javax.swing.JSplitPane.HORIZONTAL_SPLIT);
00399 ivjBUISplitPane.setName("BUISplitPane");
00400 ivjBUISplitPane.setPreferredSize(new java.awt.Dimension(600, 320));
00401 getBUISplitPane().add(getLeftScrollPane(), "left");
00402 getBUISplitPane().add(getRightScrollPane(), "right");
00403
00404
00405 } catch (java.lang.Throwable ivjExc) {
00406
00407
00408 handleException(ivjExc);
00409 }
00410 }
00411 return ivjBUISplitPane;
00412 }
00413
00414
00415
00416
00417
00418 private javax.swing.JScrollPane getLeftScrollPane() {
00419 if (ivjLeftScrollPane == null) {
00420 try {
00421 ivjLeftScrollPane = new javax.swing.JScrollPane();
00422 ivjLeftScrollPane.setName("LeftScrollPane");
00423 ivjLeftScrollPane.setBorder(BorderFactory.createLoweredBevelBorder());
00424 getLeftScrollPane().setViewportView(getLeftTree());
00425
00426
00427 } catch (java.lang.Throwable ivjExc) {
00428
00429
00430 handleException(ivjExc);
00431 }
00432 }
00433 return ivjLeftScrollPane;
00434 }
00435
00436
00437
00438
00439
00440 public javax.swing.JTree getLeftTree() {
00441 if (ivjLeftTree == null) {
00442 try {
00443 ivjLeftTree = new javax.swing.JTree();
00444 ivjLeftTree.setName("LeftTree");
00445 ivjLeftTree.setBackground(new java.awt.Color(204,204,204));
00446 ivjLeftTree.setBounds(0, 0, 78, 72);
00447
00448 ivjLeftTree.setUI(new javax.swing.plaf.metal.MetalTreeUI() {
00449 public javax.swing.plaf.metal.MetalTreeUI setAngledColor() {
00450 setHashColor(Color.black);
00451 return this;
00452 }
00453 }.setAngledColor());
00454 ivjLeftTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
00455 ivjLeftTree.setCellRenderer(new DefaultTreeCellRenderer() {
00456 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
00457 super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
00458 setIcon(null);
00459 Object o = ((DefaultMutableTreeNode) value).getUserObject();
00460 if (o instanceof Package) {
00461 String name = ((Package) o).getName().toString().trim();
00462 name = "".equals(name) ? "<default package>" : name;
00463 setText(name);
00464 setIcon(IconLibrary.packageIcon);
00465 } else
00466 if (o instanceof SootClass) {
00467 SootClass sc = (SootClass) o;
00468 Name cName = new Name(sc.getName());
00469 setText(cName.getLastIdentifier());
00470 setIcon(IconLibrary.classIcon);
00471 try {
00472 if (Package.getClassOrInterfaceType(cName).isInterface()) {
00473 setIcon(IconLibrary.interfaceIcon);
00474 }
00475 } catch (Exception e) {
00476 }
00477 } else
00478 if (o instanceof FieldDeclarationAnnotation) {
00479 FieldDeclarationAnnotation fda = (FieldDeclarationAnnotation) o;
00480 setText(fda.getField().getType() + " " + fda.getField().getName());
00481 setIcon(IconLibrary.fieldIcon);
00482 } else
00483 if (o instanceof ConstructorDeclarationAnnotation) {
00484 ConstructorDeclarationAnnotation cda = (ConstructorDeclarationAnnotation) o;
00485 try {
00486 SootMethod sm = cda.getSootMethod();
00487 Method m = cda.getConstructor();
00488 boolean isAbstractNative = Modifier.isAbstract(sm.getModifiers()) || Modifier.isNative(sm.getModifiers());
00489 String result = m.getDeclaringClassOrInterface().getName().getLastIdentifier().trim() + "(";
00490 JimpleBody body = (JimpleBody) sm.getBody(Jimple.v());
00491 String parm = "";
00492 for (Enumeration e = m.getParameters().elements(); e.hasMoreElements();) {
00493 Variable v = (Variable) e.nextElement();
00494 if (body.declaresLocal(v.getName().toString().trim()) || isAbstractNative) {
00495 parm += (v.toString() + ", ");
00496 }
00497 }
00498 if (parm.length() > 1)
00499 parm = parm.substring(0, parm.length() - 2);
00500 result += (parm + ")");
00501 setText(result);
00502 } catch (Exception e) {
00503 }
00504 setIcon(IconLibrary.methodIcon);
00505 } else
00506 if (o instanceof MethodDeclarationAnnotation) {
00507 MethodDeclarationAnnotation mda = (MethodDeclarationAnnotation) o;
00508 SootMethod sm = mda.getSootMethod();
00509 boolean isAbstractNative = Modifier.isAbstract(sm.getModifiers()) || Modifier.isNative(sm.getModifiers());
00510 Method m = mda.getMethod();
00511 String result = sm.getReturnType().toString().trim() + " " + sm.getName().trim() + "(";
00512 JimpleBody body = (JimpleBody) sm.getBody(Jimple.v());
00513 String parm = "";
00514 for (Enumeration e = m.getParameters().elements(); e.hasMoreElements();) {
00515 Variable v = (Variable) e.nextElement();
00516 if (body.declaresLocal(v.getName().toString().trim()) || isAbstractNative) {
00517 parm += (v.toString() + ", ");
00518 }
00519 }
00520 if (parm.length() > 1)
00521 parm = parm.substring(0, parm.length() - 2);
00522 result += (parm + ")");
00523 setText(result);
00524 setIcon(IconLibrary.methodIcon);
00525 }
00526 return this;
00527 }
00528 });
00529 ((DefaultTreeCellRenderer) ivjLeftTree.getCellRenderer()).setBackgroundNonSelectionColor(new Color(204, 204, 204));
00530 ((DefaultTreeCellRenderer) ivjLeftTree.getCellRenderer()).setBackgroundSelectionColor(Preferences.getHighlightColor());
00531 ivjLeftTree.putClientProperty("JTree.lineStyle", "Angled");
00532
00533 } catch (java.lang.Throwable ivjExc) {
00534
00535
00536 handleException(ivjExc);
00537 }
00538 }
00539 return ivjLeftTree;
00540 }
00541
00542
00543
00544
00545
00546 private javax.swing.JScrollPane getRightScrollPane() {
00547 if (ivjRightScrollPane == null) {
00548 try {
00549 ivjRightScrollPane = new javax.swing.JScrollPane();
00550 ivjRightScrollPane.setName("RightScrollPane");
00551 ivjRightScrollPane.setBorder(BorderFactory.createLoweredBevelBorder());
00552 getRightScrollPane().setViewportView(getRightTree());
00553
00554
00555 } catch (java.lang.Throwable ivjExc) {
00556
00557
00558 handleException(ivjExc);
00559 }
00560 }
00561 return ivjRightScrollPane;
00562 }
00563
00564
00565
00566
00567
00568 public javax.swing.JTree getRightTree() {
00569 if (ivjRightTree == null) {
00570 try {
00571 ivjRightTree = new javax.swing.JTree();
00572 ivjRightTree.setName("RightTree");
00573 ivjRightTree.setBackground(new java.awt.Color(204,204,204));
00574 ivjRightTree.setBounds(0, 0, 78, 72);
00575
00576 ivjRightTree.setUI(new javax.swing.plaf.metal.MetalTreeUI() {
00577 public javax.swing.plaf.metal.MetalTreeUI setAngledColor() {
00578 setHashColor(Color.black);
00579 return this;
00580 }
00581 }
00582 .setAngledColor());
00583 ivjRightTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
00584 ivjRightTree.setCellRenderer(new DefaultTreeCellRenderer() {
00585 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
00586 super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
00587 setIcon(null);
00588 Object o = ((DefaultMutableTreeNode) value).getUserObject();
00589 if (o instanceof Predicate) {
00590 setForeground(Preferences.getPredicateColor());
00591 if (!((Predicate) o).isValid())
00592 setIcon(IconLibrary.errorIcon);
00593 } else
00594 if (o instanceof Assertion) {
00595 setForeground(Preferences.getAssertionColor());
00596 if (!((Assertion) o).isValid())
00597 setIcon(IconLibrary.errorIcon);
00598 } else {
00599 setForeground(Color.black);
00600 }
00601 if (o instanceof Package) {
00602 String name = ((Package) o).getName().toString().trim();
00603 name = "".equals(name) ? "<default package>" : name;
00604 setText(name);
00605 if (showIconRightTree)
00606 setIcon(IconLibrary.packageIcon);
00607 } else
00608 if (o instanceof SootClass) {
00609 SootClass sc = (SootClass) o;
00610 Name cName = new Name(sc.getName());
00611 String text = null;
00612 if (Modifier.isInterface(sc.getModifiers())) {
00613 text = Modifier.toString(sc.getModifiers()) + cName;
00614 } else {
00615 text = Modifier.toString(sc.getModifiers()) + " class " + cName;
00616 }
00617 if (sc.hasSuperClass()) {
00618 String superClassName = sc.getSuperClass().getName().trim();
00619
00620 text += " extends " + superClassName;
00621 }
00622 if (sc.getInterfaceCount() > 0) {
00623 text += " implements ";
00624 for (ca.mcgill.sable.util.Iterator i = sc.getInterfaces().iterator(); i.hasNext();) {
00625 text += ((SootClass) i.next()).getName().trim() + ", ";
00626 }
00627 text.substring(0, text.length() - 2);
00628 }
00629 setText(text.trim());
00630 if (showIconRightTree) {
00631 setIcon(IconLibrary.classIcon);
00632 try {
00633 if (Package.getClassOrInterfaceType(cName).isInterface()) {
00634 setIcon(IconLibrary.interfaceIcon);
00635 }
00636 } catch (Exception e) {
00637 }
00638 }
00639 } else
00640 if (showIconRightTree && (o instanceof FieldDeclarationAnnotation)) {
00641 setIcon(IconLibrary.fieldIcon);
00642 } else
00643 if (showIconRightTree && (o instanceof ConstructorDeclarationAnnotation)) {
00644 setIcon(IconLibrary.methodIcon);
00645 } else
00646 if (showIconRightTree && (o instanceof MethodDeclarationAnnotation)) {
00647 setIcon(IconLibrary.methodIcon);
00648 }
00649 if (o instanceof Annotation) {
00650 Annotation a = (Annotation) o;
00651 if (!(a instanceof MethodDeclarationAnnotation) && !(a instanceof ConstructorDeclarationAnnotation) && !((DefaultMutableTreeNode) value).isRoot() && !(a instanceof LocalDeclarationStmtAnnotation) && (a.getStatements().length == 0)) {
00652 setForeground(Preferences.getSlicedColor());
00653 } else
00654 if ((a instanceof LocalDeclarationStmtAnnotation) && (((LocalDeclarationStmtAnnotation) a).getDeclaredLocals().size() == 0)) {
00655 setForeground(Preferences.getSlicedColor());
00656 }
00657 }
00658 return this;
00659 }
00660 });
00661 ((DefaultTreeCellRenderer) ivjRightTree.getCellRenderer()).setBackgroundNonSelectionColor(new Color(204, 204, 204));
00662 ((DefaultTreeCellRenderer) ivjRightTree.getCellRenderer()).setBackgroundSelectionColor(Preferences.getHighlightColor());
00663 ivjRightTree.putClientProperty("JTree.lineStyle", "Angled");
00664
00665 } catch (java.lang.Throwable ivjExc) {
00666
00667
00668 handleException(ivjExc);
00669 }
00670 }
00671 return ivjRightTree;
00672 }
00673
00674
00675
00676
00677 private void handleException(java.lang.Throwable exception) {
00678
00679
00680
00681
00682 }
00683
00684
00685
00686
00687
00688 private void initConnections() throws java.lang.Exception {
00689
00690
00691 getLeftTree().addTreeSelectionListener(ivjEventHandler);
00692 getLeftTree().addMouseListener(ivjEventHandler);
00693 }
00694
00695
00696
00697
00698 private void initialize() {
00699 try {
00700
00701
00702 setName("BUISessionPane");
00703 setPreferredSize(new java.awt.Dimension(600, 320));
00704 setBorder(new javax.swing.border.EtchedBorder());
00705 setLayout(new java.awt.BorderLayout());
00706 setBackground(new java.awt.Color(204,204,255));
00707 setSize(522, 244);
00708 add(getBUISplitPane(), "Center");
00709 initConnections();
00710 } catch (java.lang.Throwable ivjExc) {
00711 handleException(ivjExc);
00712 }
00713
00714 updateLeftTree();
00715
00716 }
00717
00718
00719
00720 public void leftTree_MouseReleased(java.awt.event.MouseEvent mouseEvent) {
00721 }
00722
00723
00724
00725 public void leftTree_TreeSelectionEvents() {
00726 updateRightTree(((DefaultMutableTreeNode) getLeftTree().getLastSelectedPathComponent()).getUserObject());
00727 }
00728
00729
00730
00731
00732 public static void main(java.lang.String[] args) {
00733 try {
00734 JFrame frame = new javax.swing.JFrame();
00735 BUISessionPane aBUISessionPane;
00736 aBUISessionPane = new BUISessionPane();
00737 frame.setContentPane(aBUISessionPane);
00738 frame.setSize(aBUISessionPane.getSize());
00739 frame.addWindowListener(new java.awt.event.WindowAdapter() {
00740 public void windowClosing(java.awt.event.WindowEvent e) {
00741 System.exit(0);
00742 };
00743 });
00744 frame.setVisible(true);
00745 } catch (Throwable exception) {
00746 System.err.println("Exception occurred in main() of javax.swing.JPanel");
00747 exception.printStackTrace(System.out);
00748 }
00749 }
00750
00751
00752
00753
00754
00755 public void select(Object leftObject, Object rightObject) {
00756 select(getLeftTree(), leftObject, true);
00757 updateRightTree(leftObject);
00758 select(getRightTree(), rightObject, false);
00759 }
00760
00761
00762
00763
00764
00765 public static void select(JTree tree, Object object, boolean collapseAbove) {
00766 for (int i = 0; i < tree.getRowCount(); i++) {
00767 tree.setSelectionRow(i);
00768 DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
00769 Object o = node.getUserObject();
00770 if (o == object) {
00771 TreePath path = tree.getSelectionPath();
00772 if (collapseAbove) {
00773 Object[] objects = path.getPath();
00774 for (int j = 0, k = 0; j < tree.getRowCount(); j++) {
00775 tree.setSelectionRow(j);
00776 if (objects[k] == tree.getLastSelectedPathComponent()) {
00777 k++;
00778 if (k == objects.length) break;
00779 } else {
00780 tree.collapseRow(j);
00781 }
00782 }
00783 }
00784 tree.scrollPathToVisible(path);
00785 return;
00786 } else {
00787 tree.expandRow(i);
00788 }
00789 }
00790 }
00791
00792
00793
00794 public void updateLeftTree() {
00795 if (CompilationManager.getExceptions().size() > 0) {
00796 DefaultMutableTreeNode root = new DefaultMutableTreeNode(BUI.sessions.getActiveSession().getName() + " -- Exception");
00797 Hashtable table = CompilationManager.getExceptions();
00798 for (Enumeration e = table.keys(); e.hasMoreElements();) {
00799 Object key = e.nextElement();
00800 DefaultMutableTreeNode node = new DefaultMutableTreeNode(key);
00801 root.add(node);
00802 Vector v = (Vector) table.get(key);
00803 for (Enumeration e2 = v.elements(); e2.hasMoreElements();) {
00804 Exception ex = (Exception) e2.nextElement();
00805 node.add(new DefaultMutableTreeNode(ex.getMessage()));
00806 }
00807 }
00808 getLeftTree().setRootVisible(true);
00809 getLeftTree().setModel(new DefaultTreeModel(root));
00810 getLeftScrollPane().validate();
00811 getLeftScrollPane().repaint();
00812 return;
00813 }
00814
00815 String rootName = "root";
00816
00817 if (BUI.sessions.getActiveSession() != null) {
00818 rootName = BUI.sessions.getActiveSession().getName();
00819 getLeftTree().setRootVisible(true);
00820 } else {
00821 getLeftTree().setRootVisible(false);
00822 }
00823
00824 DefaultMutableTreeNode root = new DefaultMutableTreeNode(rootName);
00825
00826 Hashtable compiledClasses = CompilationManager.getCompiledClasses();
00827
00828 TreeSet pNames = new TreeSet();
00829 for (Enumeration e = compiledClasses.elements(); e.hasMoreElements();) {
00830 pNames.add(new Name(((SootClass) e.nextElement()).getName()).getSuperName());
00831 }
00832
00833 for (Iterator i = pNames.iterator(); i.hasNext();) {
00834 try {
00835 Package p = Package.getPackage((Name) i.next());
00836 DefaultMutableTreeNode pNode = buildPackageNode(p);
00837 root.add(pNode);
00838 } catch (Exception e) {
00839 }
00840 }
00841 getLeftTree().setModel(new DefaultTreeModel(root));
00842 getLeftScrollPane().validate();
00843 getLeftScrollPane().repaint();
00844 updateRightTree((Object) null);
00845 getBUISplitPane().resetToPreferredSizes();
00846 }
00847
00848
00849
00850
00851 private void updateRightTree(SootClass sc) {
00852 DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
00853
00854 for (Iterator i = PredicateSet.getDefinedPredicates(sc).iterator(); i.hasNext();) {
00855 root.add(new DefaultMutableTreeNode(i.next()));
00856 }
00857
00858 root.add(buildClassNode(sc));
00859 showIconRightTree = true;
00860 getRightTree().setRootVisible(false);
00861 getRightTree().setModel(new DefaultTreeModel(root));
00862 getRightScrollPane().validate();
00863 getRightScrollPane().repaint();
00864 }
00865
00866
00867
00868
00869 private void updateRightTree(ConstructorDeclarationAnnotation cda) {
00870 if (cda.getNode() == null) {
00871 updateRightTree("nocode");
00872 return;
00873 }
00874
00875 DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
00876
00877 for (Iterator i = PredicateSet.getDefinedPredicates(cda).iterator(); i.hasNext();) {
00878 root.add(new DefaultMutableTreeNode(i.next()));
00879 }
00880 for (Iterator i = AssertionSet.getDefinedAssertions(cda).iterator(); i.hasNext();) {
00881 root.add(new DefaultMutableTreeNode(i.next()));
00882 }
00883
00884 root.add((DefaultMutableTreeNode) buildTree(cda).elementAt(0));
00885
00886 JTree rightTree = getRightTree();
00887 rightTree.setRootVisible(false);
00888 rightTree.setModel(new DefaultTreeModel(root));
00889 for (int i = 0; i < rightTree.getRowCount(); i++) {
00890 rightTree.expandPath(rightTree.getPathForRow(i));
00891 }
00892 getRightScrollPane().validate();
00893 getRightScrollPane().repaint();
00894 }
00895
00896
00897
00898
00899 private void updateRightTree(FieldDeclarationAnnotation fda) {
00900 showIconRightTree = false;
00901 getRightTree().setRootVisible(true);
00902 getRightTree().setModel(new DefaultTreeModel(new DefaultMutableTreeNode(fda)));
00903 getRightScrollPane().validate();
00904 getRightScrollPane().repaint();
00905 }
00906
00907
00908
00909
00910 private void updateRightTree(MethodDeclarationAnnotation mda) {
00911 DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
00912
00913 for (Iterator i = PredicateSet.getDefinedPredicates(mda).iterator(); i.hasNext();) {
00914 root.add(new DefaultMutableTreeNode(i.next()));
00915 }
00916 for (Iterator i = AssertionSet.getDefinedAssertions(mda).iterator(); i.hasNext();) {
00917 root.add(new DefaultMutableTreeNode(i.next()));
00918 }
00919
00920 root.add((DefaultMutableTreeNode) buildTree(mda).elementAt(0));
00921
00922 JTree rightTree = getRightTree();
00923 rightTree.setRootVisible(false);
00924 rightTree.setModel(new DefaultTreeModel(root));
00925 for (int i = 0; i < rightTree.getRowCount(); i++) {
00926 rightTree.expandPath(rightTree.getPathForRow(i));
00927 }
00928 getRightScrollPane().validate();
00929 getRightScrollPane().repaint();
00930 }
00931
00932
00933
00934
00935 private void updateRightTree(Package p) {
00936 showIconRightTree = true;
00937 getRightTree().setRootVisible(true);
00938 getRightTree().setModel(new DefaultTreeModel(buildPackageNode(p)));
00939 getRightScrollPane().validate();
00940 getRightScrollPane().repaint();
00941 }
00942
00943
00944
00945
00946 public void updateRightTree(Object object) {
00947 showIconRightTree = false;
00948 if (object instanceof Package) {
00949 updateRightTree((Package) object);
00950 } else if (object instanceof SootClass) {
00951 updateRightTree((SootClass) object);
00952 } else if (object instanceof FieldDeclarationAnnotation) {
00953 updateRightTree((FieldDeclarationAnnotation) object);
00954 } else if (object instanceof ConstructorDeclarationAnnotation) {
00955 updateRightTree((ConstructorDeclarationAnnotation) object);
00956 } else if (object instanceof MethodDeclarationAnnotation) {
00957 updateRightTree((MethodDeclarationAnnotation) object);
00958 } else if ("nocode".equals(object)) {
00959 getRightTree().setRootVisible(true);
00960 getRightTree().setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Source code unavailable")));
00961 getRightScrollPane().validate();
00962 getRightScrollPane().repaint();
00963 } else {
00964 getRightTree().setRootVisible(false);
00965 getRightTree().setModel(new DefaultTreeModel(new DefaultMutableTreeNode("")));
00966 getRightScrollPane().validate();
00967 getRightScrollPane().repaint();
00968 }
00969 }
00970 }