# Coverage details for edu.uci.ics.jung.visualization.DefaultGraphLabelRenderer

Line | Hits | Source
--- | --- | ---
1 |  | `/*`
2 |  | `* Copyright (c) 2005, the JUNG Project and the Regents of the University of`
3 |  | `* California All rights reserved.`
4 |  | `*`
5 |  | `* This software is open-source under the BSD license; see either "license.txt"`
6 |  | `* or http://jung.sourceforge.net/license.txt for a description.`
7 |  | `*`
8 |  | `* Created on Apr 14, 2005`
9 |  | `*/`
10 |  | ``
11 |  | `package edu.uci.ics.jung.visualization;`
12 |  | ``
13 |  | `import java.awt.Color;`
14 |  | `import java.awt.Component;`
15 |  | `import java.awt.Font;`
16 |  | `import java.awt.Rectangle;`
17 |  | `import java.io.Serializable;`
18 |  | ``
19 |  | `import javax.swing.JComponent;`
20 |  | `import javax.swing.JLabel;`
21 |  | `import javax.swing.border.Border;`
22 |  | `import javax.swing.border.EmptyBorder;`
23 |  | ``
24 |  | `import edu.uci.ics.jung.graph.Edge;`
25 |  | `import edu.uci.ics.jung.graph.Vertex;`
26 |  | ``
27 |  | `/**`
28 |  | `* DefaultGraphLabelRenderer is similar to the cell renderers`
29 |  | `* used by the JTable and JTree jfc classes.`
30 |  | `*`
31 |  | `* @author Tom Nelson - RABA Technologies`
32 |  | `*`
33 |  | `*`
34 |  | `*/`
35 |  | `public class DefaultGraphLabelRenderer extends JLabel implements`
36 |  | `GraphLabelRenderer, Serializable {`
37 |  | ``
38 | 0 | `protected static Border noFocusBorder = new EmptyBorder(0,0,0,0);`
39 |  | ``
40 | 0 | `protected Color pickedVertexLabelColor = Color.black;`
41 | 0 | `protected Color pickedEdgeLabelColor = Color.black;`
42 |  | `protected boolean rotateEdgeLabels;`
43 |  | ``
44 |  | ``
45 |  | `public DefaultGraphLabelRenderer(Color pickedVertexLabelColor,`
46 |  | `Color pickedEdgeLabelColor) {`
47 | 0 | `this(pickedVertexLabelColor, pickedEdgeLabelColor, true);`
48 | 0 | `}`
49 |  | `/**`
50 |  | `* Creates a default table cell renderer.`
51 |  | `*/`
52 |  | `public DefaultGraphLabelRenderer(Color pickedVertexLabelColor,`
53 |  | `Color pickedEdgeLabelColor, boolean rotateEdgeLabels) {`
54 | 0 | `super();`
55 | 0 | `this.pickedVertexLabelColor = pickedVertexLabelColor;`
56 | 0 | `this.pickedEdgeLabelColor = pickedEdgeLabelColor;`
57 | 0 | `this.rotateEdgeLabels = rotateEdgeLabels;`
58 | 0 | `setOpaque(true);`
59 | 0 | `setBorder(noFocusBorder);`
60 | 0 | `}`
61 |  | ``
62 |  | `/**`
63 |  | `* @return Returns the rotateEdgeLabels.`
64 |  | `*/`
65 |  | `public boolean isRotateEdgeLabels() {`
66 | 0 | `return rotateEdgeLabels;`
67 |  | `}`
68 |  | `/**`
69 |  | `* @param rotateEdgeLabels The rotateEdgeLabels to set.`
70 |  | `*/`
71 |  | `public void setRotateEdgeLabels(boolean rotateEdgeLabels) {`
72 | 0 | `this.rotateEdgeLabels = rotateEdgeLabels;`
73 | 0 | `}`
74 |  | `/**`
75 |  | `* Overrides <code>JComponent.setForeground</code> to assign`
76 |  | `* the unselected-foreground color to the specified color.`
77 |  | `*`
78 |  | `* @param c set the foreground color to this value`
79 |  | `*/`
80 |  | `public void setForeground(Color c) {`
81 | 0 | `super.setForeground(c);`
82 | 0 | `}`
83 |  | ``
84 |  | `/**`
85 |  | `* Overrides <code>JComponent.setBackground</code> to assign`
86 |  | `* the unselected-background color to the specified color.`
87 |  | `*`
88 |  | `* @param c set the background color to this value`
89 |  | `*/`
90 |  | `public void setBackground(Color c) {`
91 | 0 | `super.setBackground(c);`
92 | 0 | `}`
93 |  | ``
94 |  | `/**`
95 |  | `* Notification from the <code>UIManager</code> that the look and feel`
96 |  | `* [L&F] has changed.`
97 |  | `* Replaces the current UI object with the latest version from the`
98 |  | `* <code>UIManager</code>.`
99 |  | `*`
100 |  | `* @see JComponent#updateUI`
101 |  | `*/`
102 |  | `public void updateUI() {`
103 | 0 | `super.updateUI();`
104 | 0 | `setForeground(null);`
105 | 0 | `setBackground(null);`
106 | 0 | `}`
107 |  | ``
108 |  | `/**`
109 |  | `*`
110 |  | `* Returns the default label renderer for a Vertex`
111 |  | `*`
112 |  | `* @param vv the <code>VisualizationViewer</code> to render on`
113 |  | `* @param value the value to assign to the label for`
114 |  | `* <code>Vertex</code>`
115 |  | `* @param vertex the <code>Vertex</code>`
116 |  | `* @return the default label renderer`
117 |  | `*/`
118 |  | `public Component getGraphLabelRendererComponent(JComponent vv, Object value,`
119 |  | `Font font, boolean isSelected, Vertex vertex) {`
120 |  | ``
121 | 0 | `super.setForeground(vv.getForeground());`
122 | 0 | `if(isSelected) setForeground(pickedVertexLabelColor);`
123 | 0 | `super.setBackground(vv.getBackground());`
124 | 0 | `if(font != null) {`
125 |  | `// setFont(vv.getFont());`
126 | 0 | `setFont(font);`
127 |  | `} else {`
128 | 0 | `setFont(vv.getFont());`
129 |  | `}`
130 | 0 | `setIcon(null);`
131 | 0 | `setBorder(noFocusBorder);`
132 | 0 | `setValue(value);`
133 | 0 | `return this;`
134 |  | `}`
135 |  | ``
136 |  | `/**`
137 |  | `*`
138 |  | `* Returns the default label renderer for an Edge`
139 |  | `*`
140 |  | `* @param vv the <code>VisualizationViewer</code> to render on`
141 |  | `* @param value the value to assign to the label for`
142 |  | `* <code>Edge</code>`
143 |  | `* @param edge the <code>Edge</code>`
144 |  | `* @return the default label renderer`
145 |  | `*/`
146 |  | `public Component getGraphLabelRendererComponent(JComponent vv, Object value,`
147 |  | `Font font, boolean isSelected, Edge edge) {`
148 |  | ``
149 | 0 | `super.setForeground(vv.getForeground());`
150 | 0 | `if(isSelected) setForeground(pickedEdgeLabelColor);`
151 | 0 | `super.setBackground(vv.getBackground());`
152 |  | ``
153 | 0 | `if(font != null) {`
154 |  | `// setFont(vv.getFont());`
155 | 0 | `setFont(font);`
156 |  | `} else {`
157 | 0 | `setFont(vv.getFont());`
158 |  | `}`
159 | 0 | `setIcon(null);`
160 | 0 | `setBorder(noFocusBorder);`
161 | 0 | `setValue(value);`
162 | 0 | `return this;`
163 |  | `}`
164 |  | ``
165 |  | `/*`
166 |  | `* The following methods are overridden as a performance measure to`
167 |  | `* to prune code-paths are often called in the case of renders`
168 |  | `* but which we know are unnecessary. Great care should be taken`
169 |  | `* when writing your own renderer to weigh the benefits and`
170 |  | `* drawbacks of overriding methods like these.`
171 |  | `*/`
172 |  | ``
173 |  | `/**`
174 |  | `* Overridden for performance reasons.`
175 |  | `* See the <a href="#override">Implementation Note</a>`
176 |  | `* for more information.`
177 |  | `*/`
178 |  | `public boolean isOpaque() {`
179 | 0 | `Color back = getBackground();`
180 | 0 | `Component p = getParent();`
181 | 0 | `if (p != null) {`
182 | 0 | `p = p.getParent();`
183 |  | `}`
184 | 0 | `boolean colorMatch = (back != null) && (p != null) &&`
185 |  | `back.equals(p.getBackground()) &&`
186 |  | `p.isOpaque();`
187 | 0 | `return !colorMatch && super.isOpaque();`
188 |  | `}`
189 |  | ``
190 |  | `/**`
191 |  | `* Overridden for performance reasons.`
192 |  | `* See the <a href="#override">Implementation Note</a>`
193 |  | `* for more information.`
194 |  | `*/`
195 | 0 | `public void validate() {}`
196 |  | ``
197 |  | `/**`
198 |  | `* Overridden for performance reasons.`
199 |  | `* See the <a href="#override">Implementation Note</a>`
200 |  | `* for more information.`
201 |  | `*/`
202 | 0 | `public void revalidate() {}`
203 |  | ``
204 |  | `/**`
205 |  | `* Overridden for performance reasons.`
206 |  | `* See the <a href="#override">Implementation Note</a>`
207 |  | `* for more information.`
208 |  | `*/`
209 | 0 | `public void repaint(long tm, int x, int y, int width, int height) {}`
210 |  | ``
211 |  | `/**`
212 |  | `* Overridden for performance reasons.`
213 |  | `* See the <a href="#override">Implementation Note</a>`
214 |  | `* for more information.`
215 |  | `*/`
216 | 0 | `public void repaint(Rectangle r) { }`
217 |  | ``
218 |  | `/**`
219 |  | `* Overridden for performance reasons.`
220 |  | `* See the <a href="#override">Implementation Note</a>`
221 |  | `* for more information.`
222 |  | `*/`
223 |  | `protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {`
224 |  | `// Strings get interned...`
225 | 0 | `if (propertyName=="text") {`
226 | 0 | `super.firePropertyChange(propertyName, oldValue, newValue);`
227 |  | `}`
228 | 0 | `}`
229 |  | ``
230 |  | `/**`
231 |  | `* Overridden for performance reasons.`
232 |  | `* See the <a href="#override">Implementation Note</a>`
233 |  | `* for more information.`
234 |  | `*/`
235 | 0 | `public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) { }`
236 |  | ``
237 |  | ``
238 |  | `/**`
239 |  | `* Sets the <code>String</code> object for the cell being rendered to`
240 |  | `* <code>value</code>.`
241 |  | `*`
242 |  | `* @param value the string value for this cell; if value is`
243 |  | `* <code>null</code> it sets the text value to an empty string`
244 |  | `* @see JLabel#setText`
245 |  | `*`
246 |  | `*/`
247 |  | `protected void setValue(Object value) {`
248 | 0 | `setText((value == null) ? "" : value.toString());`
249 | 0 | `}`
250 |  | `}`

this report was generated by version 1.0.5 of jcoverage. visit www.jcoverage.com for updates. | copyright © 2003, jcoverage ltd. all rights reserved. Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.