00001 package edu.ksu.cis.bandera.pdgslicer.dependency;
00002
00003 import javax.swing.*;
00004 import javax.swing.tree.*;
00005 import edu.ksu.cis.bandera.annotation.*;
00006 import edu.ksu.cis.bandera.jjjc.CompilationManager;
00007 import ca.mcgill.sable.soot.*;
00008 import edu.ksu.cis.bandera.util.Preferences;
00009 import edu.ksu.cis.bandera.pdgslicer.SliceTraceNode;
00010
00011
00012
00013
00014
00015 public class DependencyValueViewer extends JFrame implements java.awt.event.MouseListener, java.awt.event.WindowListener, javax.swing.event.TreeSelectionListener {
00016 private boolean isSetSelectedByProgram = false;
00017 DefaultMutableTreeNode currentValueTreeRoot = null;
00018 DefaultMutableTreeNode currentDependTreeRoot = null;
00019 private Dependencies dependFrame;
00020 private final int EMPTY = 0;
00021 private final int DEPEND = 1;
00022 private final int VALUE = 2;
00023 private final int DEPENDVALUE = 3;
00024 private final int VALUEDEPEND = 4;
00025 private boolean doDepend = false;
00026 private boolean doValue = false;
00027 private boolean doDependValue = false;
00028 private boolean doValueDepend = false;
00029 private JPanel ivjJFrameContentPane = null;
00030 private JPanel ivjDependencyPanel = null;
00031 private JSplitPane ivjDependValueSplitPane = null;
00032 private JPanel ivjValuesPanel = null;
00033 private JLabel ivjDependencyLabel = null;
00034 private JTree ivjDependencyTree = null;
00035 private JScrollPane ivjDependScrollPane = null;
00036 private JLabel ivjValueLabel = null;
00037 private JScrollPane ivjValueScrollPane = null;
00038 private JTree ivjValueTree = null;
00039
00040 class IvjEventHandler implements java.awt.event.MouseListener, java.awt.event.WindowListener, javax.swing.event.TreeSelectionListener {
00041 public void mouseClicked(java.awt.event.MouseEvent e) {
00042 if (e.getSource() == DependencyValueViewer.this.getDependencyTree())
00043 connEtoC2(e);
00044 if (e.getSource() == DependencyValueViewer.this.getValueTree())
00045 connEtoC3(e);
00046 };
00047 public void mouseEntered(java.awt.event.MouseEvent e) {};
00048 public void mouseExited(java.awt.event.MouseEvent e) {};
00049 public void mousePressed(java.awt.event.MouseEvent e) {};
00050 public void mouseReleased(java.awt.event.MouseEvent e) {};
00051 public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
00052 if (e.getSource() == DependencyValueViewer.this.getDependencyTree())
00053 connEtoC1();
00054 if (e.getSource() == DependencyValueViewer.this.getValueTree())
00055 connEtoC4();
00056 };
00057 public void windowActivated(java.awt.event.WindowEvent e) {};
00058 public void windowClosed(java.awt.event.WindowEvent e) {
00059 if (e.getSource() == DependencyValueViewer.this)
00060 connEtoM1(e);
00061 };
00062 public void windowClosing(java.awt.event.WindowEvent e) {};
00063 public void windowDeactivated(java.awt.event.WindowEvent e) {};
00064 public void windowDeiconified(java.awt.event.WindowEvent e) {};
00065 public void windowIconified(java.awt.event.WindowEvent e) {};
00066 public void windowOpened(java.awt.event.WindowEvent e) {};
00067 };
00068 IvjEventHandler ivjEventHandler = new IvjEventHandler();
00069
00070
00071
00072 public DependencyValueViewer() {
00073 super();
00074 initialize();
00075 }
00076
00077
00078
00079
00080 public DependencyValueViewer(String title) {
00081 super(title);
00082 }
00083
00084
00085
00086
00087 private void changeStateFromDepend() {
00088 if (!dependFrame.doDepends() && !dependFrame.doValues())
00089 this.setToEmptyState();
00090 if (dependFrame.doDepends() && dependFrame.doValues()) {
00091
00092 doDependValue = true;
00093 doDepend = true;
00094 doValue = true;
00095 doValueDepend = false;
00096
00097 resizeViewer(true);
00098 getJFrameContentPane().removeAll();
00099 getDependValueSplitPane().add(getDependencyPanel(), "top");
00100 getDependValueSplitPane().add(getValuesPanel(), "bottom");
00101 getJFrameContentPane().add(getDependValueSplitPane(), "Center");
00102 validate();
00103 repaint();
00104 getDependValueSplitPane().setDividerLocation((double) 0.5);
00105 }
00106 else if (dependFrame.doDepends() && !dependFrame.doValues()){
00107
00108 }
00109 }
00110
00111
00112
00113
00114 private void changeStateFromDependValue() {
00115 if (dependFrame.doDepends() && dependFrame.doValues()) {
00116
00117 } else
00118 if (dependFrame.doDepends() && !dependFrame.doValues()) {
00119
00120 doDepend = true;
00121 doValue = false;
00122 doDependValue = false;
00123 doValueDepend = false;
00124
00125 int componentCount = getJFrameContentPane().getComponentCount();
00126 if (componentCount == 1) {
00127 java.awt.Component component = getJFrameContentPane().getComponent(0);
00128 if (component.getName().equals("DependValueSplitPane"))
00129 resizeViewer(false);
00130 }
00131 getJFrameContentPane().removeAll();
00132 getJFrameContentPane().add(getDependencyPanel(), "Center");
00133 } else
00134 if (!dependFrame.doDepends() && dependFrame.doValues()) {
00135
00136 doValue = true;
00137 doDepend = false;
00138 doDependValue = false;
00139 doValueDepend = false;
00140 int componentCount = getJFrameContentPane().getComponentCount();
00141 if (componentCount == 1) {
00142 java.awt.Component component = getJFrameContentPane().getComponent(0);
00143 if (component.getName().equals("DependValueSplitPane"))
00144 resizeViewer(false);
00145 }
00146 getJFrameContentPane().removeAll();
00147 getJFrameContentPane().add(getValuesPanel(), "Center");
00148 }
00149 }
00150
00151
00152
00153
00154 private void changeStateFromEmpty() {
00155 getJFrameContentPane().removeAll();
00156 if (dependFrame.doDepends()) {
00157
00158 doDepend = true;
00159 doValue = false;
00160 doDependValue = false;
00161 doValueDepend = false;
00162
00163
00164 getJFrameContentPane().add(getDependencyPanel(), "Center");
00165 } else
00166 if (dependFrame.doValues()) {
00167
00168 doValue = true;
00169 doDepend = false;
00170 doDependValue = false;
00171 doValueDepend = false;
00172
00173
00174 getJFrameContentPane().add(getValuesPanel(), "Center");
00175 }
00176 else {
00177
00178
00179 }
00180 }
00181
00182
00183
00184
00185 void changeStateFromEmptyTo(int newState) {
00186 int currentState = getViewersCurrentState();
00187 setToEmptyState();
00188 getJFrameContentPane().removeAll();
00189 switch (newState) {
00190 case EMPTY :
00191
00192 break;
00193 case DEPEND :
00194 doDepend = true;
00195 doValue = false;
00196 doDependValue = false;
00197 doValueDepend = false;
00198
00199 switch (currentState) {
00200 case EMPTY :
00201 case DEPEND :
00202 case VALUE :
00203 break;
00204 case DEPENDVALUE :
00205 case VALUEDEPEND :
00206 resizeViewer(false);
00207 break;
00208 }
00209 getJFrameContentPane().add(getDependencyPanel(), "Center");
00210 break;
00211 case VALUE :
00212
00213 doValue = true;
00214 doDepend = false;
00215 doDependValue = false;
00216 doValueDepend = false;
00217
00218 switch (currentState) {
00219 case EMPTY :
00220 case DEPEND :
00221 case VALUE :
00222 break;
00223 case DEPENDVALUE :
00224 case VALUEDEPEND :
00225 resizeViewer(false);
00226 break;
00227 }
00228 getJFrameContentPane().add(getValuesPanel(), "Center");
00229 break;
00230 case DEPENDVALUE :
00231 {
00232
00233 doDependValue = true;
00234 doDepend = true;
00235 doValue = true;
00236 doValueDepend = false;
00237
00238 switch (currentState) {
00239 case EMPTY :
00240 case DEPEND :
00241 case VALUE :
00242 resizeViewer(true);
00243 break;
00244 case DEPENDVALUE :
00245 case VALUEDEPEND :
00246 break;
00247 }
00248 getDependValueSplitPane().add(getDependencyPanel(), "top");
00249 getDependValueSplitPane().add(getValuesPanel(), "bottom");
00250 getJFrameContentPane().add(getDependValueSplitPane(), "Center");
00251 validate();
00252 repaint();
00253 getDependValueSplitPane().setDividerLocation((double) 0.5);
00254 }
00255 break;
00256 case VALUEDEPEND :
00257
00258 doDependValue = false;
00259 doDepend = true;
00260 doValue = true;
00261 doValueDepend = true;
00262
00263 switch (currentState) {
00264 case EMPTY :
00265 case DEPEND :
00266 case VALUE :
00267 resizeViewer(true);
00268 break;
00269 case DEPENDVALUE :
00270 case VALUEDEPEND :
00271 break;
00272 }
00273 getDependValueSplitPane().add(getValuesPanel(), "top");
00274 getDependValueSplitPane().add(getDependencyPanel(), "bottom");
00275 getJFrameContentPane().add(getDependValueSplitPane(), "Center");
00276 validate();
00277 repaint();
00278 getDependValueSplitPane().setDividerLocation((double) 0.5);
00279 break;
00280 }
00281 currentState = getViewersCurrentState();
00282 if (currentState != EMPTY) {
00283 this.validate();
00284 this.repaint();
00285 if (!this.isVisible())
00286 this.setVisible(true);
00287 }
00288 }
00289
00290
00291
00292
00293 private void changeStateFromValue() {
00294 if (!dependFrame.doDepends() && !dependFrame.doValues())
00295 this.setToEmptyState();
00296 if (dependFrame.doDepends() && dependFrame.doValues()) {
00297
00298 doDependValue = false;
00299 doDepend = true;
00300 doValue = true;
00301 doValueDepend = true;
00302
00303
00304 resizeViewer(true);
00305 getJFrameContentPane().removeAll();
00306 getDependValueSplitPane().add(getValuesPanel(), "top");
00307 getDependValueSplitPane().add(getDependencyPanel(), "bottom");
00308 getJFrameContentPane().add(getDependValueSplitPane(), "Center");
00309 validate();
00310 repaint();
00311 getDependValueSplitPane().setDividerLocation((double) 0.5);
00312 } else
00313 if (dependFrame.doValues() && !dependFrame.doDepends()) {
00314
00315 }
00316 }
00317
00318
00319
00320
00321 private void changeStateFromValueDepend() {
00322 changeStateFromDependValue();
00323 }
00324
00325
00326
00327
00328 void changeViewerState() {
00329 int currentState = getViewersCurrentState();
00330 switch (currentState) {
00331 case EMPTY :
00332 changeStateFromEmpty();
00333 break;
00334 case DEPEND :
00335 changeStateFromDepend();
00336 break;
00337 case VALUE :
00338 changeStateFromValue();
00339 break;
00340 case DEPENDVALUE :
00341 changeStateFromDependValue();
00342 break;
00343 case VALUEDEPEND :
00344 changeStateFromValueDepend();
00345 break;
00346 }
00347 currentState = getViewersCurrentState();
00348 if (currentState != EMPTY) {
00349 this.validate();
00350 this.repaint();
00351 if (!this.isVisible())
00352 this.setVisible(true);
00353 }
00354 }
00355
00356
00357
00358
00359 private void connEtoC1() {
00360 try {
00361
00362 if (!isSetSelectedByProgram)
00363
00364 this.dependencyTree_TreeSelectionEvents();
00365
00366
00367 } catch (java.lang.Throwable ivjExc) {
00368
00369
00370 handleException(ivjExc);
00371 }
00372 }
00373
00374
00375
00376
00377
00378 private void connEtoC2(java.awt.event.MouseEvent arg1) {
00379 try {
00380
00381
00382 this.dependencyTree_MouseClicked(arg1);
00383
00384
00385 } catch (java.lang.Throwable ivjExc) {
00386
00387
00388 handleException(ivjExc);
00389 }
00390 }
00391
00392
00393
00394
00395
00396 private void connEtoC3(java.awt.event.MouseEvent arg1) {
00397 try {
00398
00399
00400 this.valueTree_MouseClicked(arg1);
00401
00402
00403 } catch (java.lang.Throwable ivjExc) {
00404
00405
00406 handleException(ivjExc);
00407 }
00408 }
00409
00410
00411
00412
00413 private void connEtoC4() {
00414 try {
00415
00416
00417 this.valueTree_TreeSelectionEvents();
00418
00419
00420 } catch (java.lang.Throwable ivjExc) {
00421
00422
00423 handleException(ivjExc);
00424 }
00425 }
00426
00427
00428
00429
00430
00431 private void connEtoM1(java.awt.event.WindowEvent arg1) {
00432 try {
00433
00434
00435 this.setVisible(false);
00436
00437
00438 } catch (java.lang.Throwable ivjExc) {
00439
00440
00441 handleException(ivjExc);
00442 }
00443 }
00444
00445
00446
00447 public boolean connEtoM1_ABoolean() {
00448 return false;
00449 }
00450
00451
00452
00453 public void dependencyTree_MouseClicked(java.awt.event.MouseEvent mouseEvent) {
00454 int selRow = getDependencyTree().getRowForLocation(mouseEvent.getX(), mouseEvent.getY());
00455
00456 if (selRow != -1) {
00457 if (mouseEvent.getClickCount() == 1) {
00458
00459
00460 } else
00461 if (mouseEvent.getClickCount() == 2) {
00462
00463
00464 DefaultMutableTreeNode dependTreeSelected = (DefaultMutableTreeNode) getDependencyTree().getLastSelectedPathComponent();
00465 if (dependTreeSelected == null)
00466 return;
00467 Object userObject = dependTreeSelected.getUserObject();
00468 if (userObject instanceof MethodDeclarationAnnotation)
00469 return;
00470 StmtTreeNode selectedNode = getSelectedStmtTreeNode(userObject);
00471 dependFrame.addSelectedNodeToDependFrame(selectedNode);
00472
00473 }
00474 }
00475 return;
00476 }
00477
00478
00479
00480 public void dependencyTree_TreeSelectionEvents() {
00481 DefaultMutableTreeNode lastSelectedNode = (DefaultMutableTreeNode) getDependencyTree().getLastSelectedPathComponent();
00482 if (lastSelectedNode == null)
00483 return;
00484 if (lastSelectedNode.isRoot()) {
00485 dependFrame.getCodeBrowserPane().setCurrentNodeSelected(dependFrame.currentNode);
00486 return;
00487 }
00488 Object userObject = lastSelectedNode.getUserObject();
00489 if (userObject.equals(dependFrame.currentNode) || (userObject instanceof String))
00490 return;
00491 StmtTreeNode selectedNode = getSelectedStmtTreeNode(userObject);
00492 dependFrame.getCodeBrowserPane().setCurrentNodeSelected(selectedNode);
00493 return;
00494 }
00495
00496
00497
00498
00499
00500 void expandAndCollapseFrom(DefaultMutableTreeNode rootNode, boolean isDependency) {
00501 isSetSelectedByProgram = true;
00502 int rootRow = -1;
00503
00504 if (isDependency) {
00505 for (int i = 0; i < getDependencyTree().getRowCount(); i++) {
00506 getDependencyTree().setSelectionRow(i);
00507 DefaultMutableTreeNode node = (DefaultMutableTreeNode) getDependencyTree().getLastSelectedPathComponent();
00508
00509
00510 if (node.equals(rootNode)) {
00511 getDependencyTree().expandRow(i);
00512 rootRow = i;
00513 break;
00514 }
00515 }
00516 getDependencyTree().setSelectionRow(0);
00517 isSetSelectedByProgram = false;
00518 if (rootRow >= 0) {
00519 for (int i = 1; i <= rootNode.getChildCount(); i++)
00520 getDependencyTree().collapseRow(rootRow + i);
00521 }
00522 } else {
00523 for (int i = 0; i < getValueTree().getRowCount(); i++) {
00524 getValueTree().setSelectionRow(i);
00525 DefaultMutableTreeNode node = (DefaultMutableTreeNode) getValueTree().getLastSelectedPathComponent();
00526
00527
00528
00529 {
00530 getValueTree().expandRow(i);
00531
00532
00533 }
00534 }
00535 getValueTree().setSelectionRow(0);
00536 isSetSelectedByProgram = false;
00537
00538
00539
00540
00541
00542
00543 }
00544 }
00545 void expandDependTreeToOneLevel(boolean isDependency) {
00546 if (isDependency) {
00547 for (int i = 0; i < currentDependTreeRoot.getChildCount(); i++) {
00548 DefaultMutableTreeNode child = (DefaultMutableTreeNode) currentDependTreeRoot.getChildAt(i);
00549 expandAndCollapseFrom(child, isDependency);
00550 for (int j = 0; j < child.getChildCount(); j++) {
00551 DefaultMutableTreeNode dependChild = (DefaultMutableTreeNode) child.getChildAt(j);
00552 expandAndCollapseFrom(dependChild, isDependency);
00553 }
00554 }
00555 } else {
00556 for (int i = 0; i < currentValueTreeRoot.getChildCount(); i++) {
00557 DefaultMutableTreeNode child = (DefaultMutableTreeNode) currentValueTreeRoot.getChildAt(i);
00558 expandAndCollapseFrom(child, isDependency);
00559 for (int j = 0; j < child.getChildCount(); j++) {
00560 DefaultMutableTreeNode valueChild = (DefaultMutableTreeNode) child.getChildAt(j);
00561 expandAndCollapseFrom(valueChild, isDependency);
00562 }
00563 }
00564 }
00565 }
00566
00567
00568
00569
00570 private static void getBuilderData() {
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610 }
00611
00612
00613
00614
00615
00616 private javax.swing.JLabel getDependencyLabel() {
00617 if (ivjDependencyLabel == null) {
00618 try {
00619 ivjDependencyLabel = new javax.swing.JLabel();
00620 ivjDependencyLabel.setName("DependencyLabel");
00621 ivjDependencyLabel.setFont(new java.awt.Font("dialog.plain", 0, 12));
00622 ivjDependencyLabel.setText("Dependencies");
00623 ivjDependencyLabel.setForeground(java.awt.Color.black);
00624
00625
00626 } catch (java.lang.Throwable ivjExc) {
00627
00628
00629 handleException(ivjExc);
00630 }
00631 }
00632 return ivjDependencyLabel;
00633 }
00634
00635
00636
00637
00638
00639 public javax.swing.JPanel getDependencyPanel() {
00640 if (ivjDependencyPanel == null) {
00641 try {
00642 ivjDependencyPanel = new javax.swing.JPanel();
00643 ivjDependencyPanel.setName("DependencyPanel");
00644 ivjDependencyPanel.setLayout(new java.awt.BorderLayout());
00645 ivjDependencyPanel.setBounds(632, 76, 160, 120);
00646 getDependencyPanel().add(getDependencyLabel(), "North");
00647 getDependencyPanel().add(getDependScrollPane(), "Center");
00648
00649
00650 } catch (java.lang.Throwable ivjExc) {
00651
00652
00653 handleException(ivjExc);
00654 }
00655 }
00656 return ivjDependencyPanel;
00657 }
00658
00659
00660
00661
00662
00663 public javax.swing.JTree getDependencyTree() {
00664 if (ivjDependencyTree == null) {
00665 try {
00666 ivjDependencyTree = new javax.swing.JTree();
00667 ivjDependencyTree.setName("DependencyTree");
00668 ivjDependencyTree.setBackground(new java.awt.Color(204,204,204));
00669 ivjDependencyTree.setBounds(0, 0, 78, 72);
00670
00671 getDependencyTree().setModel(new DefaultTreeModel(new DefaultMutableTreeNode("")));
00672 getDependScrollPane().validate();
00673 getDependScrollPane().repaint();
00674 ivjDependencyTree.setUI(new javax.swing.plaf.metal.MetalTreeUI() {
00675 public javax.swing.plaf.metal.MetalTreeUI setAngledColor() {
00676 setHashColor(java.awt.Color.black);
00677 return this;
00678 }
00679 }
00680 .setAngledColor());
00681 ivjDependencyTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
00682 ivjDependencyTree.setCellRenderer(new DefaultTreeCellRenderer() {
00683 public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
00684 super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
00685 Object o = ((DefaultMutableTreeNode) value).getUserObject();
00686 setForeground(java.awt.Color.black);
00687 setIcon(null);
00688 return this;
00689 }
00690 });
00691 ((DefaultTreeCellRenderer) ivjDependencyTree.getCellRenderer()).setBackgroundNonSelectionColor(new java.awt.Color(204, 204, 204));
00692 ivjDependencyTree.putClientProperty("JTree.lineStyle", "Angled");
00693
00694
00695 } catch (java.lang.Throwable ivjExc) {
00696
00697
00698 handleException(ivjExc);
00699 }
00700 }
00701 return ivjDependencyTree;
00702 }
00703
00704
00705
00706
00707
00708 public javax.swing.JScrollPane getDependScrollPane() {
00709 if (ivjDependScrollPane == null) {
00710 try {
00711 ivjDependScrollPane = new javax.swing.JScrollPane();
00712 ivjDependScrollPane.setName("DependScrollPane");
00713 getDependScrollPane().setViewportView(getDependencyTree());
00714
00715
00716 } catch (java.lang.Throwable ivjExc) {
00717
00718
00719 handleException(ivjExc);
00720 }
00721 }
00722 return ivjDependScrollPane;
00723 }
00724
00725
00726
00727
00728
00729 public javax.swing.JSplitPane getDependValueSplitPane() {
00730 if (ivjDependValueSplitPane == null) {
00731 try {
00732 ivjDependValueSplitPane = new javax.swing.JSplitPane(javax.swing.JSplitPane.VERTICAL_SPLIT);
00733 ivjDependValueSplitPane.setName("DependValueSplitPane");
00734 ivjDependValueSplitPane.setDividerLocation(50);
00735 ivjDependValueSplitPane.setBackground(new java.awt.Color(204,204,204));
00736 ivjDependValueSplitPane.setBounds(642, 243, 160, 120);
00737
00738
00739 } catch (java.lang.Throwable ivjExc) {
00740
00741
00742 handleException(ivjExc);
00743 }
00744 }
00745 return ivjDependValueSplitPane;
00746 }
00747
00748
00749
00750
00751
00752
00753 int getInsertIndexOf(String dependValueKind, boolean isDependency) {
00754 if (isDependency) {
00755 int kind = dependFrame.dependencyKindsList.indexOf(dependValueKind);
00756 for (int i = 0; i < currentDependTreeRoot.getChildCount(); i++) {
00757 DefaultMutableTreeNode oneChild = (DefaultMutableTreeNode) currentDependTreeRoot.getChildAt(i);
00758 int childIndex = dependFrame.dependencyKindsList.indexOf(oneChild.toString());
00759 if (kind < childIndex)
00760 return i;
00761 }
00762 return currentDependTreeRoot.getChildCount();
00763 } else {
00764 int kind = dependFrame.valueKindsList.indexOf(dependValueKind);
00765 for (int i = 0; i < currentValueTreeRoot.getChildCount(); i++) {
00766 DefaultMutableTreeNode oneChild = (DefaultMutableTreeNode) currentValueTreeRoot.getChildAt(i);
00767 int childIndex = dependFrame.valueKindsList.indexOf(oneChild.toString());
00768 if (kind < childIndex)
00769 return i;
00770 }
00771 return currentValueTreeRoot.getChildCount();
00772 }
00773 }
00774
00775
00776
00777
00778
00779 public javax.swing.JPanel getJFrameContentPane() {
00780 if (ivjJFrameContentPane == null) {
00781 try {
00782 ivjJFrameContentPane = new javax.swing.JPanel();
00783 ivjJFrameContentPane.setName("JFrameContentPane");
00784 ivjJFrameContentPane.setLayout(new java.awt.BorderLayout());
00785
00786
00787
00788 } catch (java.lang.Throwable ivjExc) {
00789
00790
00791 handleException(ivjExc);
00792 }
00793 }
00794 return ivjJFrameContentPane;
00795 }
00796
00797
00798
00799
00800
00801
00802 StmtTreeNode getSelectedStmtTreeNode(Object userObject) {
00803 StmtTreeNode selectedNode = null;
00804 if (userObject instanceof StmtTreeNode) {
00805 selectedNode = (StmtTreeNode) userObject;
00806 } else
00807 if (userObject instanceof ParameterNode) {
00808 ParameterNode pn = (ParameterNode) userObject;
00809 selectedNode = new StmtTreeNode(pn.sootClass, pn.mda, pn.mda);
00810 } else
00811 if (userObject instanceof Annotation) {
00812 Annotation ma = null;
00813 if ((userObject instanceof MethodDeclarationAnnotation) || (userObject instanceof ConstructorDeclarationAnnotation))
00814 ma = (Annotation) userObject;
00815 else
00816 ma = CompilationManager.getAnnotationManager().getMethodAnnotationContainingAnnotation((Annotation) userObject);
00817 if (ma instanceof MethodDeclarationAnnotation) {
00818 SootClass sc = ((MethodDeclarationAnnotation) ma).getSootMethod().getDeclaringClass();
00819 selectedNode = new StmtTreeNode(sc, ma, (Annotation) userObject);
00820 } else
00821 if (ma instanceof ConstructorDeclarationAnnotation) {
00822 SootClass sc = ((ConstructorDeclarationAnnotation) ma).getSootMethod().getDeclaringClass();
00823 selectedNode = new StmtTreeNode(sc, ma, (Annotation) userObject);
00824 } else
00825 throw new edu.ksu.cis.bandera.pdgslicer.exceptions.SlicerException("Annotation containing userObject should be method declaration or constructor declaration.");
00826 } else
00827 if (userObject instanceof SliceTraceNode) {
00828 SliceTraceNode stn = (SliceTraceNode) userObject;
00829 Annotation mdAnnotation = edu.ksu.cis.bandera.jjjc.CompilationManager.getAnnotationManager().getAnnotation(stn.methodInfo.sootClass, stn.methodInfo.sootMethod);
00830 selectedNode = new StmtTreeNode(stn.methodInfo.sootClass, mdAnnotation, stn.stmtAnnotation);
00831 } else
00832 throw new edu.ksu.cis.bandera.pdgslicer.exceptions.SlicerException("The object of nodes in dependency tree should be StmtTreeNode, ParameterNode or Annotation.");
00833 return selectedNode;
00834 }
00835
00836
00837
00838
00839
00840 private javax.swing.JLabel getValueLabel() {
00841 if (ivjValueLabel == null) {
00842 try {
00843 ivjValueLabel = new javax.swing.JLabel();
00844 ivjValueLabel.setName("ValueLabel");
00845 ivjValueLabel.setFont(new java.awt.Font("dialog.plain", 0, 12));
00846 ivjValueLabel.setText("Values");
00847 ivjValueLabel.setForeground(java.awt.Color.black);
00848
00849
00850 } catch (java.lang.Throwable ivjExc) {
00851
00852
00853 handleException(ivjExc);
00854 }
00855 }
00856 return ivjValueLabel;
00857 }
00858
00859
00860
00861
00862
00863 private javax.swing.JScrollPane getValueScrollPane() {
00864 if (ivjValueScrollPane == null) {
00865 try {
00866 ivjValueScrollPane = new javax.swing.JScrollPane();
00867 ivjValueScrollPane.setName("ValueScrollPane");
00868 getValueScrollPane().setViewportView(getValueTree());
00869
00870
00871 } catch (java.lang.Throwable ivjExc) {
00872
00873
00874 handleException(ivjExc);
00875 }
00876 }
00877 return ivjValueScrollPane;
00878 }
00879
00880
00881
00882
00883
00884 public javax.swing.JPanel getValuesPanel() {
00885 if (ivjValuesPanel == null) {
00886 try {
00887 ivjValuesPanel = new javax.swing.JPanel();
00888 ivjValuesPanel.setName("ValuesPanel");
00889 ivjValuesPanel.setLayout(new java.awt.BorderLayout());
00890 ivjValuesPanel.setBounds(633, 404, 160, 120);
00891 getValuesPanel().add(getValueLabel(), "North");
00892 getValuesPanel().add(getValueScrollPane(), "Center");
00893
00894
00895 } catch (java.lang.Throwable ivjExc) {
00896
00897
00898 handleException(ivjExc);
00899 }
00900 }
00901 return ivjValuesPanel;
00902 }
00903
00904
00905
00906
00907
00908 public javax.swing.JTree getValueTree() {
00909 if (ivjValueTree == null) {
00910 try {
00911 ivjValueTree = new javax.swing.JTree();
00912 ivjValueTree.setName("ValueTree");
00913 ivjValueTree.setBackground(new java.awt.Color(204,204,204));
00914 ivjValueTree.setBounds(0, 0, 78, 72);
00915
00916 getValueTree().setModel(new DefaultTreeModel(new DefaultMutableTreeNode("")));
00917 getValueScrollPane().validate();
00918 getValueScrollPane().repaint();
00919 ivjValueTree.setUI(new javax.swing.plaf.metal.MetalTreeUI() {
00920 public javax.swing.plaf.metal.MetalTreeUI setAngledColor() {
00921 setHashColor(java.awt.Color.black);
00922 return this;
00923 }
00924 }
00925 .setAngledColor());
00926 ivjValueTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
00927 ivjValueTree.setCellRenderer(new DefaultTreeCellRenderer() {
00928 public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
00929 super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
00930 Object o = ((DefaultMutableTreeNode) value).getUserObject();
00931 setForeground(java.awt.Color.black);
00932 setIcon(null);
00933 return this;
00934 }
00935 });
00936 ((DefaultTreeCellRenderer) ivjValueTree.getCellRenderer()).setBackgroundNonSelectionColor(new java.awt.Color(204, 204, 204));
00937 ivjValueTree.putClientProperty("JTree.lineStyle", "Angled");
00938
00939
00940 } catch (java.lang.Throwable ivjExc) {
00941
00942
00943 handleException(ivjExc);
00944 }
00945 }
00946 return ivjValueTree;
00947 }
00948
00949
00950
00951
00952
00953 int getViewersCurrentState() {
00954 if (!doDepend && !doValue)
00955 return EMPTY;
00956 if (doDepend && !(doValue || doDependValue || doValueDepend))
00957 return DEPEND;
00958 if (doValue && !(doDepend || doDependValue || doValueDepend))
00959 return VALUE;
00960 if (doDependValue && doDepend && doValue && !doValueDepend)
00961 return DEPENDVALUE;
00962 if (doValueDepend && doDepend && doValue && !doDependValue)
00963 return VALUEDEPEND;
00964 else
00965 throw new edu.ksu.cis.bandera.pdgslicer.exceptions.SlicerException("The dependency/value viewer should be one of the following states: empty, depend, value, dependvalue and valuedepend");
00966 }
00967
00968
00969
00970
00971 private void handleException(java.lang.Throwable exception) {
00972
00973
00974
00975
00976 }
00977
00978
00979
00980
00981
00982 private void initConnections() throws java.lang.Exception {
00983
00984
00985 this.addWindowListener(ivjEventHandler);
00986 getDependencyTree().addTreeSelectionListener(ivjEventHandler);
00987 getDependencyTree().addMouseListener(ivjEventHandler);
00988 getValueTree().addMouseListener(ivjEventHandler);
00989 getValueTree().addTreeSelectionListener(ivjEventHandler);
00990 }
00991
00992
00993
00994
00995 private void initialize() {
00996 try {
00997
00998
00999 setName("DependencyValueViewer");
01000 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
01001 setSize(401, 308);
01002 setTitle("Dependencies and Vaule Flow Viewer");
01003 setContentPane(getJFrameContentPane());
01004 initConnections();
01005 } catch (java.lang.Throwable ivjExc) {
01006 handleException(ivjExc);
01007 }
01008
01009
01010 }
01011
01012
01013
01014
01015 public static void main(java.lang.String[] args) {
01016 try {
01017 DependencyValueViewer aDependencyValueViewer;
01018 aDependencyValueViewer = new DependencyValueViewer();
01019 aDependencyValueViewer.addWindowListener(new java.awt.event.WindowAdapter() {
01020 public void windowClosing(java.awt.event.WindowEvent e) {
01021 System.exit(0);
01022 };
01023 });
01024 aDependencyValueViewer.setVisible(true);
01025 } catch (Throwable exception) {
01026 System.err.println("Exception occurred in main() of javax.swing.JFrame");
01027 exception.printStackTrace(System.out);
01028 }
01029 }
01030
01031
01032
01033
01034
01035 public void mouseClicked(java.awt.event.MouseEvent e) {
01036
01037
01038 if (e.getSource() == getDependencyTree())
01039 connEtoC2(e);
01040
01041
01042 }
01043
01044
01045
01046
01047
01048 public void mouseEntered(java.awt.event.MouseEvent e) {
01049
01050
01051
01052
01053 }
01054
01055
01056
01057
01058
01059 public void mouseExited(java.awt.event.MouseEvent e) {
01060
01061
01062
01063
01064 }
01065
01066
01067
01068
01069
01070 public void mousePressed(java.awt.event.MouseEvent e) {
01071
01072
01073
01074
01075 }
01076
01077
01078
01079
01080
01081 public void mouseReleased(java.awt.event.MouseEvent e) {
01082
01083
01084
01085
01086 }
01087
01088
01089
01090
01091
01092 private void resizeViewer(boolean enlarge) {
01093 if (enlarge) {
01094 java.awt.Dimension contentPaneSize = getJFrameContentPane().getSize();
01095 int newWidth = (int) contentPaneSize.getWidth() + 5;
01096 double oldHeight = contentPaneSize.getHeight();
01097 int newHeight = (int) oldHeight * 2 + 30;
01098 contentPaneSize = new java.awt.Dimension(newWidth, newHeight);
01099 setSize(contentPaneSize);
01100 } else {
01101 java.awt.Dimension contentPaneSize = getJFrameContentPane().getSize();
01102 int newWidth = (int) contentPaneSize.getWidth() + 10;
01103 double oldHeight = contentPaneSize.getHeight();
01104 int newHeight = (int) oldHeight / 2 + 40;
01105 contentPaneSize = new java.awt.Dimension(newWidth, newHeight);
01106 this.setSize(contentPaneSize);
01107 }
01108 }
01109
01110
01111
01112
01113
01114 void setDependFrame(Dependencies dpnd) {
01115 dependFrame = dpnd;
01116 }
01117
01118
01119
01120
01121 void setToEmptyState() {
01122 doDepend = false;
01123 doValue = false;
01124 doDependValue = false;
01125 doValueDepend = false;
01126 this.setVisible(false);
01127
01128 }
01129
01130
01131
01132
01133
01134 public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
01135
01136
01137 if (e.getSource() == getDependencyTree())
01138 connEtoC1();
01139
01140
01141 }
01142
01143
01144
01145 public void valueTree_MouseClicked(java.awt.event.MouseEvent mouseEvent) {
01146 int selRow = getValueTree().getRowForLocation(mouseEvent.getX(), mouseEvent.getY());
01147
01148 if (selRow != -1) {
01149 if (mouseEvent.getClickCount() == 1) {
01150
01151
01152 } else
01153 if (mouseEvent.getClickCount() == 2) {
01154
01155
01156 DefaultMutableTreeNode valueTreeSelected = (DefaultMutableTreeNode) getValueTree().getLastSelectedPathComponent();
01157 if (valueTreeSelected == null)
01158 return;
01159 Object userObject = valueTreeSelected.getUserObject();
01160 if (userObject instanceof MethodDeclarationAnnotation)
01161 return;
01162 StmtTreeNode selectedNode = getSelectedStmtTreeNode(userObject);
01163 dependFrame.addSelectedNodeToDependFrame(selectedNode);
01164
01165 }
01166 }
01167
01168 return;
01169 }
01170
01171
01172
01173 public void valueTree_TreeSelectionEvents() {
01174 DefaultMutableTreeNode lastSelectedNode = (DefaultMutableTreeNode) getValueTree().getLastSelectedPathComponent();
01175 if (lastSelectedNode == null)
01176 return;
01177 if (lastSelectedNode.isRoot()) {
01178 dependFrame.getCodeBrowserPane().setCurrentNodeSelected(dependFrame.currentNode);
01179 return;
01180 }
01181 Object userObject = lastSelectedNode.getUserObject();
01182 if (userObject.equals(dependFrame.currentNode) || (userObject instanceof String))
01183 return;
01184 StmtTreeNode selectedNode = getSelectedStmtTreeNode(userObject);
01185 dependFrame.getCodeBrowserPane().setCurrentNodeSelected(selectedNode);
01186 return;
01187 }
01188
01189
01190
01191
01192
01193 public void windowActivated(java.awt.event.WindowEvent e) {
01194
01195
01196
01197
01198 }
01199
01200
01201
01202
01203
01204 public void windowClosed(java.awt.event.WindowEvent e) {
01205
01206
01207 if (e.getSource() == this)
01208 connEtoM1(e);
01209
01210
01211 }
01212
01213
01214
01215
01216
01217 public void windowClosing(java.awt.event.WindowEvent e) {
01218
01219
01220
01221
01222 }
01223
01224
01225
01226
01227
01228 public void windowDeactivated(java.awt.event.WindowEvent e) {
01229
01230
01231
01232
01233 }
01234
01235
01236
01237
01238
01239 public void windowDeiconified(java.awt.event.WindowEvent e) {
01240
01241
01242
01243
01244 }
01245
01246
01247
01248
01249
01250 public void windowIconified(java.awt.event.WindowEvent e) {
01251
01252
01253
01254
01255 }
01256
01257
01258
01259
01260
01261 public void windowOpened(java.awt.event.WindowEvent e) {
01262
01263
01264
01265
01266 }
01267 }