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.GlobalComplexType; 48 import org.netbeans.modules.xml.schema.model.SchemaComponent; 49 import org.netbeans.modules.xml.nbprefuse.View; 50 import org.netbeans.modules.xml.nbprefuse.layout.NbFruchtermanReingoldLayout; 51 import org.netbeans.modules.xml.nbprefuse.render.CompositionEdgeRenderer; 52 import org.netbeans.modules.xml.nbprefuse.render.FindUsagesRendererFactory; 53 import org.netbeans.modules.xml.nbprefuse.render.GeneralizationEdgeRenderer; 54 import org.netbeans.modules.xml.nbprefuse.render.NbLabelRenderer; 55 import org.netbeans.modules.xml.nbprefuse.render.ReferenceEdgeRenderer; 56 import org.netbeans.modules.xml.schema.refactoring.query.readers.ComplexTypeDerivationsReader; 57 import org.openide.ErrorManager; 58 import org.openide.util.NbBundle; 59 import prefuse.Display; 60 import prefuse.Visualization; 61 import prefuse.action.ActionList; 62 import prefuse.action.RepaintAction; 63 import prefuse.action.animate.ColorAnimator; 64 import prefuse.action.animate.QualityControlAnimator; 65 import prefuse.action.animate.VisibilityAnimator; 66 import prefuse.activity.SlowInSlowOutPacer; 67 import prefuse.controls.FocusControl; 68 import prefuse.controls.NeighborHighlightControl; 69 import prefuse.controls.PanControl; 70 import prefuse.controls.SubtreeDragControl; 71 import prefuse.controls.ToolTipControl; 72 import prefuse.controls.WheelZoomControl; 73 import prefuse.controls.ZoomControl; 74 import prefuse.data.Graph; 75 import prefuse.render.EdgeRenderer; 76 77 81 public class ComplexTypeDerivationsView implements View, PropertyChangeListener { 82 83 private GlobalComplexType baseCT; 84 private Display display = null; 85 private JPanel displayPanel; 86 private Graph graph; 87 private boolean usePacer = true; private int resizeCounter = 0; 89 90 95 public ComplexTypeDerivationsView( 96 SchemaComponent baseCT 97 ) { 98 this.baseCT = (GlobalComplexType)baseCT; 99 } 100 101 105 106 110 111 public Object [] createModels( ) { resizeCounter = 0; 113 usePacer = true; 114 graph = null; 115 ComplexTypeDerivationsReader reader = new ComplexTypeDerivationsReader(); 116 118 graph = reader.loadComplexTypeDerivationsGraph(baseCT); 119 return new Object [] {graph}; 120 } 121 122 133 public boolean showView(AnalysisViewer viewer) { 134 boolean wasShown = false; 135 viewer.setCurrentView(this); 136 if (resizeCounter == 0){ 139 resizeCounter++; 140 } else if (resizeCounter == 1 || resizeCounter == 2){ 141 resizeCounter++; 142 return wasShown; 143 } 144 145 Visualization viz = null; 146 if (graph == null){ 147 ErrorManager.getDefault().log(ErrorManager.ERROR, 148 NbBundle.getMessage(WhereUsedView.class, 149 "LBL_Graph_Not_Created_Error")); 150 return false; 151 } 152 153 try { 154 this.display = new Display(); 156 display.setBackground(Color.WHITE); 157 viz = new Visualization(); 158 viz.addGraph(AnalysisConstants.GRAPH_GROUP, graph); 159 display.setVisualization(viz); 160 161 Dimension dim = viewer.getPanel().getBounds().getSize(); 163 Dimension displayDim = display.getBounds().getSize(); 165 if (!dim.equals(displayDim)) { 166 display.setSize(dim.width, dim.height); 167 } 168 169 this.displayPanel = new JPanel (new BorderLayout ()); 170 displayPanel.add(display, BorderLayout.CENTER); 171 viewer.addDisplayPanel(displayPanel); 172 173 display.addControlListener(new SubtreeDragControl()); 174 display.addControlListener(new PanControl()); 175 display.addControlListener(new ZoomControl()); 176 display.addControlListener(new WheelZoomControl()); 177 display.addControlListener(new ToolTipControl(AnalysisConstants.TOOLTIP)); display.addControlListener(new FocusControl()); 179 display.addControlListener(new ActivatedNodesControlAdapter()); 180 display.addControlListener(new NeighborHighlightControl(AnalysisConstants.ACTION_UPDATE)); display.addControlListener(new PopupMouseControl()); 182 display.addControlListener(new NodeExpansionMouseControl(viz, 183 AnalysisConstants.ACTION_UPDATE)); 184 185 186 188 viz.setRendererFactory(new FindUsagesRendererFactory( 189 new NbLabelRenderer(), 190 new NbLabelRenderer(), 191 new GeneralizationEdgeRenderer(), 192 new CompositionEdgeRenderer(), 193 new ReferenceEdgeRenderer(), 194 new EdgeRenderer() 195 )); 196 ActionList update = new ActionList(viz); 202 update.add(new NodeFillColorAction()); 203 update.add(new NodeTextColorAction()); 204 update.add(new NodeStrokeColorAction()); 205 update.add(new EdgeStrokeColorAction()); 206 update.add(new EdgeFillColorAction()); 207 update.add(new RepaintAction()); 208 viz.putAction(AnalysisConstants.ACTION_UPDATE, update); 209 210 ActionList draw = new ActionList(); 211 draw.add(new NodeFillColorAction()); 212 draw.add(new NodeTextColorAction()); 213 draw.add(new NodeStrokeColorAction()); 214 draw.add(new EdgeStrokeColorAction()); 215 draw.add(new EdgeFillColorAction()); 216 viz.putAction(AnalysisConstants.ACTION_DRAW, draw); 217 218 ActionList layout = new ActionList(); 219 layout.add(new NbFruchtermanReingoldLayout(AnalysisConstants.GRAPH_GROUP)); 220 layout.add(new RepaintAction()); 221 viz.putAction(AnalysisConstants.ACTION_LAYOUT, layout); 222 223 224 viz.runAfter(AnalysisConstants.ACTION_DRAW, AnalysisConstants.ACTION_LAYOUT); 225 226 if (usePacer) { 227 ActionList animate = new ActionList(1500, 20); 229 animate.setPacingFunction(new SlowInSlowOutPacer()); 230 animate.add(new QualityControlAnimator()); 231 animate.add(new VisibilityAnimator()); 232 animate.add(new ColorAnimator()); 234 animate.add(new RepaintAction()); 235 viz.putAction(AnalysisConstants.ACTION_ANIMATE, animate); 236 viz.alwaysRunAfter(AnalysisConstants.ACTION_LAYOUT, AnalysisConstants.ACTION_ANIMATE); 237 } 238 239 viz.run(AnalysisConstants.ACTION_DRAW); 240 wasShown = true; 241 242 243 } catch ( Exception e ) { 244 ErrorManager.getDefault().notify(e); 245 } 246 return wasShown; 247 } 248 249 250 public void usePacer(boolean use) { 251 this.usePacer = use; 252 } 253 254 255 262 public boolean getMaximizeWidth(){ 263 return true; 264 } 265 266 public void propertyChange(PropertyChangeEvent evt) { 267 } 268 } 269 | Popular Tags |