KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jsf > navigation > vwmodel > GraphUtilities


1 /*
2  * GraphUtilities.java
3  *
4  * Created on December 7, 2006, 10:39 AM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.modules.web.jsf.navigation.vwmodel;
11
12 import org.netbeans.modules.web.jsf.navigation.vwmodel.Page;
13 import java.awt.Dimension JavaDoc;
14 import java.awt.FontMetrics JavaDoc;
15 import java.awt.Image JavaDoc;
16 import java.awt.Rectangle JavaDoc;
17
18 /**
19  *
20  * @author Joelle Lam
21  */

22 public class GraphUtilities {
23     private static final String JavaDoc LAYOUT_TYPE = "layoutType"; //NOI18N
24
private static final String JavaDoc LINK_TYPE = "linkType"; //NOI18N
25

26     private static final String JavaDoc LAYOUT_TYPE_DRAGGABLE = "draggable"; //NOI18N
27
private static final String JavaDoc LAYOUT_TYPE_FLAT = "flat"; //NOI18N
28

29     private static final String JavaDoc LINK_TYPE_LINE = "line"; //NOI18N
30
private static final String JavaDoc LINK_TYPE_ARC = "arc"; //NOI18N
31

32     public static final int STRAIGHT_LINE = 0;
33     public static final int ARC_LINE = 1;
34     public static int linkType = STRAIGHT_LINE;
35     
36     public static final int LEFT = 0;
37     public static final int RIGHT = 1;
38     public static final int UP = 2;
39     public static final int DOWN = 3;
40     
41     private static final int MOVE_STEP = 5;
42     
43     static final int LINK_THRESHOLD = 10; // mouse distance from an arc considered a match
44
static final int PAGEWIDTH = 80; // width of a page
45
static final int ZOOMEDPAGEWIDTH = 2*PAGEWIDTH;
46     static final int PAGEHEIGHT = PAGEWIDTH*11/8; // height of a page. 8/11 proportions.
47
static final int ZOOMEDPAGEHEIGHT = 2*PAGEHEIGHT;
48     static final int EARSIZE = PAGEWIDTH/5; // size of a paper "ear"/"thumb"
49
static final int ARROWSIZE = 8; // size of arrowhead segment
50
static final int ICONSIZE = 16; // size of icons
51
static final int ICONSPACING = 3; // size of icons
52
static final int ARROWSIZEROT = (int)(((float)ARROWSIZE)*0.707); // cos 45
53
static final int PORTWIDTH = 50; // width of the port label text TODO make dynamic
54
static final int PORTHEIGHT = 12; // Height of each port row: should use fontheight!!! XXX OBSOLETE
55
static final int PORTNIBWIDTH = 8; // width of the nib for the port
56
static final int PORTNIBHEIGHT = 6; // height of the nib for the port
57
static final int YSPACING = 40;
58     static final int XSPACING= 100;
59     static final int LEFT_OFFSET= 3*ARROWSIZE; // margins around graph
60
static final int TOP_OFFSET= LEFT_OFFSET;
61     
62     /**
63      * Size of rectangle around a point (such as a mouse pointer) that we should ensure visible when
64      * the user clicks, drags, etc.
65      */

66     static final int SCROLLZONE = PAGEWIDTH; // width of a page
67

68     
69     // --------------------------------------------------------------------
70
// Painting
71
// --------------------------------------------------------------------
72

73     /** Icon shown whenever there's an error */
74     private static Image JavaDoc getErrorIcon() {
75         if (errorIcon == null) {
76             errorIcon = org.openide.util.Utilities.loadImage("org/netbeans/modules/web/jsf/navigation/vwmodel/error.gif"); // NOI18N
77
}
78         return errorIcon;
79     }
80     
81     private static Image JavaDoc errorIcon;
82     
83     /** Icon shown next to dynamic navigation cases */
84     private static Image JavaDoc getDynamicIcon() {
85         if (dynamicIcon == null) {
86             dynamicIcon = org.openide.util.Utilities.loadImage("org/netbeans/modules/web/jsf/navigation/vwmodel/dynamic.gif"); // NOI18N
87
}
88         return dynamicIcon;
89     }
90     
91     private static Image JavaDoc dynamicIcon;
92     
93     /**
94      * Icon shown for UICommands when there is no bean info or no icon in the bean info.
95      */

96     static Image JavaDoc getCommandIcon() {
97         if (commandIcon == null) {
98             commandIcon = org.openide.util.Utilities.loadImage("org/netbeans/modules/web/jsf/navigation/vwmodel/command.gif"); // NOI18N
99
}
100         return commandIcon;
101     }
102     
103     private static Image JavaDoc commandIcon;
104     
105     /**
106      * Icon shown next to hint labels
107      */

108     static Image JavaDoc getIdeaIcon() {
109         if (ideaIcon == null) {
110             ideaIcon = org.openide.util.Utilities.loadImage("org/netbeans/modules/web/jsf/navigation/vwmodel/lightbulb.gif"); // NOI18N
111
}
112         return ideaIcon;
113     }
114     
115     private static Image JavaDoc ideaIcon;
116     
117     /** Return the width of the given string */
118     static int getStringWidth(FontMetrics JavaDoc metrics, String JavaDoc s) {
119         int w = 0;
120         if (s == null) {
121             return 0;
122         }
123         int n = s.length();
124         for (int j = 0; j < n; j++) {
125             w += metrics.charWidth(s.charAt(j));
126         }
127         return w;
128     }
129     
130     /** Interface implemented by layout providers */
131     public interface Layout {
132         /**
133          * Compute a layout for the given document. Will set the various layout-related fields for
134          * the Page and Link objects in the Document.
135          *
136          * @param document The document for which to compute a layout
137          * @param alloc The size of the current viewport.
138          * @param selected If non null, treat the given page as "selected" meaning it should be
139          * assigned a larger size etc.
140          * @param metrics The font metrics for the font to use for labelling
141          * @param keepPages If true, don't reposition the pages
142          * @param keepLinks If true, don't reposition the links
143          * @return the size of the resulting layout.
144          */

145         public Dimension JavaDoc computeLayout(NavigationModel document, Rectangle JavaDoc alloc,
146                 FontMetrics JavaDoc metrics, Page selected,
147                 boolean keepPages, boolean keepLinks);
148         
149         /**
150          * Compute an internal layout for the given page. This is used to lay out a "focused" page
151          * containing beans and ports, showing the relationships between the beans and the ports, or
152          * unassigned ports as well as beans pointing to nonexistent or "actionRef" (method call)
153          * cases. The page is assumed to already have its dimensions set.
154          *
155          * @param document The document for which to compute a layout
156          * @param page The page to be laid out
157          * @param metrics The font metrices for the font to use for labelling
158          * @return true iff the layout is okay, false if the page dimensions had to change (and as a
159          * result, the page positions and links should be adjusted).
160          */

161         public boolean computePageLayout(NavigationModel document, Page page, FontMetrics JavaDoc metrics);
162     }
163 }
164
Popular Tags