KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > nbprefuse > render > FindUsagesRendererFactory


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  * FindUsagesRendererFactory.java
22  *
23  * Created on March 3, 2006, 7:47 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.nbprefuse.render;
30
31 import org.netbeans.modules.xml.nbprefuse.AnalysisConstants;
32 import prefuse.render.Renderer;
33 import prefuse.render.RendererFactory;
34 import prefuse.visual.AggregateItem;
35 import prefuse.visual.EdgeItem;
36 import prefuse.visual.NodeItem;
37 import prefuse.visual.VisualItem;
38
39 /**
40  *
41  * @author Jeri Lockhart
42  */

43 public class FindUsagesRendererFactory implements RendererFactory {
44     private NbLabelRenderer nodeRenderer;
45     private NbLabelRenderer fileNodeRenderer;
46     private NbLabelRenderer queryNodeRenderer;
47     private Renderer generalizationRenderer;
48     private Renderer compositionRenderer;
49     private Renderer referenceRenderer;
50     private Renderer fileEdgeRenderer;
51     private Renderer aggregateRenderer;
52      
53     
54     /**
55      * Construcotr for Graph that doesn't use aggregate items
56      *
57      */

58     public FindUsagesRendererFactory(
59             NbLabelRenderer nodeRenderer,
60             NbLabelRenderer fileNodeRenderer,
61             Renderer generalizationRenderer,
62             Renderer compositionRenderer,
63             Renderer referenceRenderer,
64             Renderer fileEdgeRenderer
65             ){
66         this(nodeRenderer, fileNodeRenderer, generalizationRenderer,
67                compositionRenderer, referenceRenderer,fileEdgeRenderer, null );
68     
69     }
70     
71     /**
72      * Construcotr for Graph that uses aggregate items
73      *
74      */

75     public FindUsagesRendererFactory(
76             NbLabelRenderer nodeRenderer,
77             NbLabelRenderer fileNodeRenderer,
78             Renderer generalizationRenderer,
79             Renderer compositionRenderer,
80             Renderer referenceRenderer,
81             Renderer fileEdgeRenderer,
82             Renderer aggregateRenderer
83             ) {
84         this.nodeRenderer = nodeRenderer;
85         nodeRenderer.setVerticalPadding(5);
86         nodeRenderer.setHorizontalPadding(5);
87         this.fileNodeRenderer = fileNodeRenderer;
88         this.aggregateRenderer = aggregateRenderer;
89         fileNodeRenderer.setRoundedCorner(10,10); // arc width, arc height
90
fileNodeRenderer.setVerticalPadding(5);
91         fileNodeRenderer.setHorizontalPadding(5);
92         this.queryNodeRenderer = new NbLabelRenderer();
93         queryNodeRenderer.setRoundedCorner(20,20);
94         queryNodeRenderer.setVerticalPadding(10);
95         queryNodeRenderer.setHorizontalPadding(10);
96         this.generalizationRenderer = generalizationRenderer;
97         this.compositionRenderer = compositionRenderer;
98         this.referenceRenderer = referenceRenderer;
99         this.fileEdgeRenderer = fileEdgeRenderer;
100     } //
101

102     public Renderer getRenderer(VisualItem visualItem) {
103         if (visualItem instanceof AggregateItem){
104             return aggregateRenderer;
105         }
106         if ( visualItem instanceof NodeItem ) {
107             if (visualItem.canGetBoolean(AnalysisConstants.IS_FILE_NODE) &&
108                     visualItem.getBoolean(AnalysisConstants.IS_FILE_NODE)){
109                 return fileNodeRenderer;
110             }
111             else if (visualItem.canGetBoolean(AnalysisConstants.IS_QUERY_NODE) &&
112                     visualItem.getBoolean(AnalysisConstants.IS_QUERY_NODE)){
113                 return queryNodeRenderer;
114             }
115             else {
116                 return nodeRenderer;
117             }
118         }else if ( visualItem instanceof EdgeItem ) {
119             String JavaDoc type = visualItem.getString(AnalysisConstants.EDGE_TYPE);
120             if (type != null && type.equals(AnalysisConstants.GENERALIZATION)){
121                 return generalizationRenderer;
122             }else if (type != null && type.equals(AnalysisConstants.COMPOSITION)){
123                 return compositionRenderer;
124             }else if (type != null && type.equals(AnalysisConstants.REFERENCE)){
125                 return referenceRenderer;
126             }
127             if (visualItem.getString(AnalysisConstants.EDGE_TYPE) != null &&
128                     visualItem.getString(AnalysisConstants.EDGE_TYPE).equals(AnalysisConstants.FILE_EDGE_TYPE) ){
129                 return fileEdgeRenderer;
130             }
131         }
132         return fileEdgeRenderer;
133     } //
134
} // end of inner class FindUsagesRendererFactory
135
Popular Tags