ScopeZoom.java

Go to the documentation of this file.
00001 
00004 package edu.rice.cs.hpc.viewer.scope;
00005 
00006 import edu.rice.cs.hpc.data.experiment.scope.CallSiteScopeCallerView;
00007 import edu.rice.cs.hpc.data.experiment.scope.Scope;
00008 
00013 public class ScopeZoom {
00014     // --------------------------------------------------------------------
00015     //  ATTRIBUTES
00016     // --------------------------------------------------------------------
00017     private ScopeTreeViewer viewer;
00018     private ScopeViewActionsGUI objActionsGUI;
00019     
00020     private java.util.Stack<Scope> stackRootTree;
00021     private java.util.Stack<Object[]> stackTreeStates;
00022 
00023     // --------------------------------------------------------------------
00024     //  CONSTRUCTORS
00025     // --------------------------------------------------------------------
00031     public ScopeZoom ( ScopeTreeViewer treeViewer, ScopeViewActionsGUI objGUI ) {
00032         this.viewer = treeViewer;
00033         this.objActionsGUI = objGUI;
00034         stackRootTree = new java.util.Stack<Scope>();
00035         stackTreeStates = new java.util.Stack<Object[]>();
00036     }
00037     
00038     // --------------------------------------------------------------------
00039     //  METHODS
00040     // --------------------------------------------------------------------
00047     public void zoomIn (Scope current, Scope old) {
00048         // ---------------------- save the current view
00049         this.stackRootTree.push(old); // save the node for future zoom-out
00050         Object treeStates[] = viewer.getExpandedElements();
00051         this.stackTreeStates.push(treeStates);
00052         // ---------------------- 
00053 
00054         viewer.setInput(current);
00055         // we need to insert the selected node on the top of the table
00056         // FIXME: this approach is not elegant, but we don't have any choice
00057         //          at the moment
00058         this.objActionsGUI.insertParentNode(current);
00059     }
00060     
00064     public void zoomOut () {
00065         Scope parent; 
00066         if(this.stackRootTree.size()>0) {
00067             // the tree has been zoomed
00068             parent = this.stackRootTree.pop();
00069         } else {
00070             // case where the tree hasn't been zoomed
00071             // FIXME: there must be a bug if the code comes to here !
00072             parent = (Scope)viewer.getInput();
00073             throw( new java.lang.RuntimeException("ScopeViewActions - illegal zoomout"+parent));
00074         }
00075 
00076         viewer.setInput( parent );
00077         // Bug fix: we need to insert the parent on the top of the table
00078         this.objActionsGUI.insertParentNode(parent);
00079 
00080         // return the previous expanded tree items
00081         if(this.stackTreeStates.size()>0) {
00082             Object o[] = this.stackTreeStates.pop();
00083             viewer.setExpandedElements(o);
00084         }
00085     }
00086     
00091     public boolean canZoomOut () {
00092         boolean bRet = (this.stackRootTree != null);
00093         if (bRet) {
00094             bRet = ( this.stackRootTree.size()>0 );
00095         }
00096         return bRet;
00097     }
00098     
00104     public boolean canZoomIn ( Scope node ) {
00105         if (node == null)
00106             return false;
00107         if (node instanceof CallSiteScopeCallerView) {
00108             // in caller view, we don't know exactly how many children a scope has
00109             // the most reliable way is to retrieve the "mark" if the scope has a child or not
00110             return ((CallSiteScopeCallerView)node).hasScopeChildren();
00111         }
00112         return ( node.getChildCount()>0 );
00113     }
00114     
00115     public void setViewer ( ScopeTreeViewer treeViewer ) {
00116         viewer = treeViewer;
00117     }
00118 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1