1 19 20 28 29 package org.netbeans.modules.xml.schema.refactoring.query.views; 30 31 32 import java.awt.BorderLayout ; 33 import java.awt.Color ; 34 import java.awt.Dimension ; 35 import java.beans.PropertyChangeEvent ; 36 import java.beans.PropertyChangeListener ; 37 import javax.swing.JPanel ; 38 import org.netbeans.modules.xml.nbprefuse.AnalysisConstants; 39 import org.netbeans.modules.xml.nbprefuse.AnalysisViewer; 40 import org.netbeans.modules.xml.nbprefuse.EdgeFillColorAction; 41 import org.netbeans.modules.xml.nbprefuse.EdgeStrokeColorAction; 42 import org.netbeans.modules.xml.nbprefuse.NodeExpansionMouseControl; 43 import org.netbeans.modules.xml.nbprefuse.NodeFillColorAction; 44 import org.netbeans.modules.xml.nbprefuse.NodeStrokeColorAction; 45 import org.netbeans.modules.xml.nbprefuse.NodeTextColorAction; 46 import org.netbeans.modules.xml.nbprefuse.PopupMouseControl; 47 import org.netbeans.modules.xml.schema.model.SchemaModel; 48 import org.netbeans.modules.xml.nbprefuse.View; 49 import org.netbeans.modules.xml.nbprefuse.layout.NbFruchtermanReingoldLayout; 50 import org.netbeans.modules.xml.nbprefuse.render.CompositionEdgeRenderer; 51 import org.netbeans.modules.xml.nbprefuse.render.FindUsagesRendererFactory; 52 import org.netbeans.modules.xml.nbprefuse.render.GeneralizationEdgeRenderer; 53 import org.netbeans.modules.xml.nbprefuse.render.NbLabelRenderer; 54 import org.netbeans.modules.xml.nbprefuse.render.ReferenceEdgeRenderer; 55 import org.netbeans.modules.xml.schema.refactoring.query.readers.QuerySubstitutionGroupsReader; 56 import org.openide.ErrorManager; 57 import org.openide.util.NbBundle; 58 import prefuse.Display; 59 import prefuse.Visualization; 60 import prefuse.action.ActionList; 61 import prefuse.action.RepaintAction; 62 import prefuse.action.animate.ColorAnimator; 63 import prefuse.action.animate.QualityControlAnimator; 64 import prefuse.action.animate.VisibilityAnimator; 65 import prefuse.activity.SlowInSlowOutPacer; 66 import prefuse.controls.FocusControl; 67 import prefuse.controls.NeighborHighlightControl; 68 import prefuse.controls.PanControl; 69 import prefuse.controls.SubtreeDragControl; 70 import prefuse.controls.ToolTipControl; 71 import prefuse.controls.WheelZoomControl; 72 import prefuse.controls.ZoomControl; 73 import prefuse.data.Graph; 74 import prefuse.render.EdgeRenderer; 75 76 80 public class QuerySubstitutionGroupsView implements View, PropertyChangeListener { 81 82 private SchemaModel model; 83 private Display display = null; 84 private JPanel displayPanel; 85 private Graph graph; 86 private boolean usePacer = false; private int resizeCounter = 0; 89 90 94 public QuerySubstitutionGroupsView(SchemaModel model ) { 95 this.model = model; 96 this.display = new Display(); 97 } 98 99 100 104 public Object [] createModels( ) { usePacer = true; 106 resizeCounter = 0; 107 graph = null; 108 QuerySubstitutionGroupsReader reader = new QuerySubstitutionGroupsReader(model); 109 graph = reader.loadGraph(); 110 return new Object [] {graph}; 111 } 112 113 119 124 public boolean showView(AnalysisViewer viewer) { 125 boolean wasShown = false; 126 viewer.setCurrentView(this); 127 if (resizeCounter == 0){ 130 resizeCounter++; 131 } else if (resizeCounter == 1 || resizeCounter == 2){ 132 resizeCounter++; 133 return wasShown; 134 } 135 Visualization viz = null; 136 if (graph == null){ 137 ErrorManager.getDefault().log(ErrorManager.ERROR, 138 NbBundle.getMessage(WhereUsedView.class, 139 "LBL_Graph_Not_Created_Error")); 140 return wasShown; 141 } 142 143 try { 145 146 this.display = new Display(); 147 display.setBackground(Color.WHITE); 148 viz = new Visualization(); 150 display.setVisualization(viz); 151 152 Dimension dim = viewer.getPanel().getBounds().getSize(); 154 Dimension displayDim = display.getBounds().getSize(); 156 if (!dim.equals(displayDim)) { 157 display.setSize(dim.width, dim.height); 158 } 159 160 this.displayPanel = new JPanel (new BorderLayout ()); 161 displayPanel.add(display, BorderLayout.CENTER); 162 viewer.addDisplayPanel(displayPanel); 163 164 display.addControlListener(new SubtreeDragControl()); 165 display.addControlListener(new PanControl()); 166 display.addControlListener(new ZoomControl()); 167 display.addControlListener(new WheelZoomControl()); 168 display.addControlListener(new ToolTipControl(AnalysisConstants.TOOLTIP)); display.addControlListener(new FocusControl()); 170 display.addControlListener(new ActivatedNodesControlAdapter()); 171 display.addControlListener(new NeighborHighlightControl(AnalysisConstants.ACTION_UPDATE)); display.addControlListener(new PopupMouseControl()); 173 display.addControlListener(new NodeExpansionMouseControl(viz, 174 AnalysisConstants.ACTION_UPDATE)); 175 176 viz.addGraph(AnalysisConstants.GRAPH_GROUP, graph); 177 178 if (graph.getNodeCount() < 1){ 179 return false; 180 } 181 182 viz.setRendererFactory(new FindUsagesRendererFactory( 183 new NbLabelRenderer(), 184 new NbLabelRenderer(), 185 new GeneralizationEdgeRenderer(), 186 new CompositionEdgeRenderer(), 187 new ReferenceEdgeRenderer(), 188 new EdgeRenderer() 189 )); 190 191 192 ActionList update = new ActionList(viz); 193 update.add(new NodeFillColorAction()); 194 update.add(new NodeTextColorAction()); 195 update.add(new NodeStrokeColorAction()); 196 update.add(new EdgeStrokeColorAction()); 197 update.add(new EdgeFillColorAction()); 198 update.add(new RepaintAction()); 199 viz.putAction(AnalysisConstants.ACTION_UPDATE, update); 200 201 202 203 ActionList draw = new ActionList(); 204 draw.add(new NodeFillColorAction()); 205 draw.add(new NodeTextColorAction()); 206 draw.add(new NodeStrokeColorAction()); 207 draw.add(new EdgeStrokeColorAction()); 208 draw.add(new EdgeFillColorAction()); 209 viz.putAction(AnalysisConstants.ACTION_DRAW, draw); 210 211 ActionList layout = new ActionList(); 212 layout.add(new NbFruchtermanReingoldLayout(AnalysisConstants.GRAPH_GROUP)); 213 layout.add(new RepaintAction()); 214 viz.putAction(AnalysisConstants.ACTION_LAYOUT, layout); 215 216 viz.runAfter(AnalysisConstants.ACTION_DRAW, AnalysisConstants.ACTION_LAYOUT); 217 218 if (usePacer) { 219 221 ActionList animate = new ActionList(1500, 20); 222 animate.setPacingFunction(new SlowInSlowOutPacer()); 223 animate.add(new QualityControlAnimator()); 224 animate.add(new VisibilityAnimator()); 225 animate.add(new ColorAnimator()); 227 animate.add(new RepaintAction()); 228 viz.putAction(AnalysisConstants.ACTION_ANIMATE, animate); 229 viz.alwaysRunAfter(AnalysisConstants.ACTION_LAYOUT, AnalysisConstants.ACTION_ANIMATE); 230 } 231 232 viz.run(AnalysisConstants.ACTION_DRAW); 233 wasShown = true; 234 235 236 } catch ( Exception e ) { 237 ErrorManager.getDefault().notify(e); 238 } 239 return wasShown; 240 241 } 242 243 244 245 public void usePacer(boolean use) { 246 usePacer = use; 247 } 248 249 256 public boolean getMaximizeWidth(){ 257 return true; 258 } 259 260 261 public void propertyChange(PropertyChangeEvent evt) { 262 } 263 264 265 } 266 | Popular Tags |