View Javadoc

1   /*$Id: VizualizationController.java,v 1.2 2008/11/04 14:35:48 nw Exp $
2    * Created on 27-Jan-2006
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid 
7    * Software License version 1.2, a copy of which has been included 
8    * with this distribution in the LICENSE.txt file.  
9    *
10  **/
11  package org.astrogrid.desktop.modules.ui.scope;
12  
13  
14  import java.util.ArrayList;
15  import java.util.Iterator;
16  
17  import org.apache.commons.collections.iterators.UnmodifiableIterator;
18  
19  import edu.berkeley.guir.prefuse.ItemRegistry;
20  import edu.berkeley.guir.prefuse.focus.FocusSet;
21  import edu.berkeley.guir.prefuse.graph.Entity;
22  import edu.berkeley.guir.prefuse.graph.TreeNode;
23  import edu.berkeley.guir.prefuse.render.ImageFactory;
24  /***
25   * Aggregates a set of prefuse vizualizations together. - enables them to be worked
26   * with as a whole, attached to a single vizualization model.
27   * 
28   *<p>
29   *also contains resources, helper objects, etc that are shared between vizualizations.
30   * @author Noel Winstanley noel.winstanley@manchester.ac.uk 27-Jan-2006
31   *
32   */
33  public class VizualizationController {
34      public VizualizationController(final VizModel model) {            
35          this.model = model;
36          imageFactory = new ImageFactory(24,24); // small thumbnails.        
37      
38      }
39      private final ImageFactory imageFactory;    
40      private final ArrayList l = new ArrayList();
41      private final VizModel model;
42      
43      public void add(final Vizualization v) {
44          l.add(v);
45          model.getTree().addGraphEventListener(v);
46      }
47      
48      /*** access the common image factory.*/
49      public ImageFactory getImageFactory() {
50          return imageFactory;
51      }
52      
53      public VizModel getVizModel() {
54          return model;
55      }
56      
57      public Iterator iterator() {
58          return UnmodifiableIterator.decorate(l.iterator());
59      }
60      
61      /***
62       * method: refocusMainNodes()
63       * description: Refocuses the graph on the main root node.  Typically called right before a query or user
64       * hits a particular button.  Seems to focus better if it focuses on cone and sia tree nodes first before root.
65       *
66       */
67      public void refocusMainNodes() {
68          for (final Iterator i = this.iterator(); i.hasNext(); ) {
69              final Vizualization vis = (Vizualization)i.next();
70              final ItemRegistry itemReg = vis.getItemRegistry();
71              final FocusSet defaultFocusSet = itemReg.getFocusManager().getDefaultFocusSet();
72              for (final Iterator j = model.getProtocols().iterator(); j.hasNext(); ) {
73                  final DalProtocol p = (DalProtocol)j.next();
74                  defaultFocusSet.set(p.getPrimaryNode());
75              }  
76              defaultFocusSet.set(model.getTree().getRoot());
77              gc(itemReg);
78          }    
79      }
80  
81      /***
82      force a garbage collection too - will remove any old visual nodes lurking after the real nodes have been removed.
83       * @param itemReg
84       */
85      private void gc(final ItemRegistry itemReg) {
86          itemReg.garbageCollectAggregates();
87          itemReg.garbageCollectEdges();
88          itemReg.garbageCollectNodes();
89      }
90      
91      public void moveUp() {
92          for (final Iterator i = this.iterator(); i.hasNext(); ) {
93              final Vizualization v = (Vizualization)i.next();
94              final ItemRegistry itemReg = v.getItemRegistry();
95              final FocusSet focusSet = itemReg.getFocusManager().getDefaultFocusSet();
96              final Iterator j = focusSet.iterator();
97              if (j.hasNext()) {
98                  final Entity e = (Entity)j.next();
99                  if (e instanceof TreeNode) {
100                     final TreeNode parent = ((TreeNode)e).getParent();
101                     if (parent != null) {
102                         focusSet.set(parent);
103                     }
104                 }
105             }
106             gc(itemReg);
107         }
108     }
109     
110     /***
111      * method: reDrawGraphs
112      * description: Calls Redraw on all the displays/visualizations typically called after a refocus and needs to
113      * draw the new focus on the graph.  
114      * Note: clearTree does not call it because nodes are typically added from a query causing the graph to be 
115      * redrawn anyways.
116      *
117      */
118     public void reDrawGraphs() {
119         for (final Iterator i = this.iterator(); i.hasNext(); ) {
120             final Vizualization vis = (Vizualization)i.next();
121             vis.reDraw();
122         }
123     }        
124 }
125 
126 /* 
127 $Log: VizualizationController.java,v $
128 Revision 1.2  2008/11/04 14:35:48  nw
129 javadoc polishing
130 
131 Revision 1.1  2007/12/12 13:54:12  nw
132 astroscope upgrade, and minor changes for first beta release
133 
134 Revision 1.5  2007/01/29 10:43:49  nw
135 documentation fixes.
136 
137 Revision 1.4  2006/09/15 14:37:20  nw
138 reduced size of thumbnails.
139 
140 Revision 1.3  2006/04/18 23:25:44  nw
141 merged asr development.
142 
143 Revision 1.2.6.1  2006/04/14 02:45:00  nw
144 finished code.
145 extruded plastic hub.
146 
147 Revision 1.2  2006/02/09 15:40:01  nw
148 finished refactoring of astroscope.
149 added vospec viewer
150 
151 Revision 1.1  2006/02/02 14:51:11  nw
152 components of astroscope, plus new ssap component.
153  
154 */