KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > refactoring > query > views > ComplexTypeDerivationsView


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * ComplexTypeDerivationsView.java
22  *
23  * Created on October 25, 2005, 2:09 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.refactoring.query.views;
30
31
32 import java.awt.BorderLayout JavaDoc;
33 import java.awt.Color JavaDoc;
34 import java.awt.Dimension JavaDoc;
35 import java.beans.PropertyChangeEvent JavaDoc;
36 import java.beans.PropertyChangeListener JavaDoc;
37 import javax.swing.JPanel JavaDoc;
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 /**
78  *
79  * @author Jeri Lockhart
80  */

81 public class ComplexTypeDerivationsView implements View, PropertyChangeListener JavaDoc {
82     
83     private GlobalComplexType baseCT;
84     private Display display = null;
85     private JPanel JavaDoc displayPanel;
86     private Graph graph;
87     private boolean usePacer = true; // slow in slow out pacer for initial graph animation
88
private int resizeCounter = 0;
89     
90     /**
91      * Creates a new instance of ComplexTypeDerivationsView
92      * using a previously created Preview from
93      * FindUsageVisitor
94      */

95     public ComplexTypeDerivationsView(
96             SchemaComponent baseCT
97             ) {
98         this.baseCT = (GlobalComplexType)baseCT;
99     }
100     
101     /**
102      * Implement View
103      *
104      */

105     
106 // public JPanel getDisplayPanel() {
107
// return displayPanel;
108
// }
109

110     
111     public Object JavaDoc[] createModels( ) { // not cancellable
112
resizeCounter = 0;
113         usePacer = true;
114         graph = null;
115         ComplexTypeDerivationsReader reader = new ComplexTypeDerivationsReader();
116         // Load the prefuse graph
117

118         graph = reader.loadComplexTypeDerivationsGraph(baseCT);
119         return new Object JavaDoc[] {graph};
120     }
121      
122 // public DefaultTreeModel getTreeModel() {
123
// assert true:"This view only supports graph output. Use createGraph() instead.";
124
// throw new UnsupportedOperationException("This view only supports graph output. Use createGraph() instead.");//NOI18N
125
//
126
// }
127
//
128
// public Graph createGraphAndTreeModel(CancelSignal interruptProcess) {
129
// assert true:"This view only supports graph output. Use createGraph() instead."; //NOI18N
130
// throw new UnsupportedOperationException("This view only supports graph output. Use createGraph() instead.");//NOI18N
131
// }
132

133     public boolean showView(AnalysisViewer viewer) {
134         boolean wasShown = false;
135         viewer.setCurrentView(this);
136         // resizing will call showView() from AnalysisViewer
137
// prevent showing the view twice the first time
138
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             // initialize display
155
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             // size the AnalysisViewer to the available space in the main parent panel
162
Dimension JavaDoc dim = viewer.getPanel().getBounds().getSize();
163 // System.out.println("AnalysisView dimensions:" + dim.toString());
164
Dimension JavaDoc displayDim = display.getBounds().getSize();
165             if (!dim.equals(displayDim)) {
166                 display.setSize(dim.width, dim.height);
167             }
168             
169             this.displayPanel = new JPanel JavaDoc(new BorderLayout JavaDoc());
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)); // "tooltip"
178
display.addControlListener(new FocusControl());
179             display.addControlListener(new ActivatedNodesControlAdapter());
180             display.addControlListener(new NeighborHighlightControl(AnalysisConstants.ACTION_UPDATE)); //NOI18N
181
display.addControlListener(new PopupMouseControl());
182             display.addControlListener(new NodeExpansionMouseControl(viz,
183                     AnalysisConstants.ACTION_UPDATE));
184             
185             
186             // initialize renderers
187

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             // initialize action lists
197
// ActionList filter = new ActionList();
198
// System.out.println("layout.getLayoutBounds() " + layout.getLayoutBounds()); // null
199
// Rectangle2D rect = layout.getLayoutBounds(viz);
200
// layout.setLayoutBounds(new Rectangle(rect.getBounds().width-10, rect.getBounds().height-10));
201
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                 // animated transition
228
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 PolarLocationAnimator(AnalysisConstants.GRAPH_GROUP));
233
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 JavaDoc 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     /**
256      * Should the SchemaColumnView make the Column
257      * that the View is shown in as wide as possible?
258      * @return boolean true if View should be shown
259      * in a column as wide as the available horizontal space
260      * in the column view
261      */

262     public boolean getMaximizeWidth(){
263         return true;
264     }
265     
266     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
267     }
268 }
269
Popular Tags