KickJava   Java API By Example, From Geeks To Geeks.

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


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  * QuerySubstitutionGroupsView.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.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 /**
77  *
78  * @author Jeri Lockhart
79  */

80 public class QuerySubstitutionGroupsView implements View, PropertyChangeListener JavaDoc {
81     
82     private SchemaModel model;
83     private Display display = null;
84     private JPanel JavaDoc displayPanel;
85     private Graph graph;
86     private boolean usePacer = false; // slow in slow out pacer for initial graph animation
87
private int resizeCounter = 0; // counter to control first invocation of the view
88

89     
90     /**
91      * Creates a new instance of QuerySubstitutionGroupsView
92      * taking a SchemaComponent argument
93      */

94     public QuerySubstitutionGroupsView(SchemaModel model ) {
95         this.model = model;
96         this.display = new Display();
97     }
98     
99     
100 // public JPanel getDisplayPanel() {
101
// return displayPanel;
102
// }
103

104     public Object JavaDoc[] createModels( ) { // not cancellable
105
usePacer = true;
106         resizeCounter = 0;
107         graph = null;
108         QuerySubstitutionGroupsReader reader = new QuerySubstitutionGroupsReader(model);
109         graph = reader.loadGraph();
110         return new Object JavaDoc[] {graph};
111     }
112     
113 // public DefaultTreeModel getTreeModel() {
114
// assert true:"This view only supports graph output. Use createGraph() instead.";
115
// throw new UnsupportedOperationException("This view only supports graph output. Use createGraph() instead.");//NOI18N
116
//
117
// }
118

119 // public Graph createGraphAndTreeModel(CancelSignal interruptProcess) {
120
// assert true:"This view only supports graph output. Use createGraph() instead.";
121
// throw new UnsupportedOperationException("This view only supports graph output. Use createGraph() instead.");//NOI18N
122
// }
123

124     public boolean showView(AnalysisViewer viewer) {
125         boolean wasShown = false;
126         viewer.setCurrentView(this);
127         // resizing will call showView() from AnalysisViewer
128
// prevent showing the view twice the first time
129
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         // Load the prefuse graph
144
try {
145             
146             this.display = new Display();
147             display.setBackground(Color.WHITE);
148             // initialize display
149
viz = new Visualization();
150             display.setVisualization(viz);
151             
152             // size the AnalysisViewer to the available space in the main parent panel
153
Dimension JavaDoc dim = viewer.getPanel().getBounds().getSize();
154 // System.out.println("AnalysisView dimensions:" + dim.toString());
155
Dimension JavaDoc displayDim = display.getBounds().getSize();
156             if (!dim.equals(displayDim)) {
157                 display.setSize(dim.width, dim.height);
158             }
159             
160             this.displayPanel = new JPanel JavaDoc(new BorderLayout JavaDoc());
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)); // "tooltip"
169
display.addControlListener(new FocusControl());
170             display.addControlListener(new ActivatedNodesControlAdapter());
171             display.addControlListener(new NeighborHighlightControl(AnalysisConstants.ACTION_UPDATE)); //NOI18N
172
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                 // animated transition
220

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 PolarLocationAnimator(AnalysisConstants.GRAPH_GROUP));
226
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 JavaDoc 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     /**
250      * Should the SchemaColumnView make the Column
251      * that the View is shown in as wide as possible?
252      * @return boolean true if View should be shown
253      * in a column as wide as the available horizontal space
254      * in the column view
255      */

256     public boolean getMaximizeWidth(){
257         return true;
258     }
259
260
261     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
262     }
263
264     
265 }
266
Popular Tags