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

LineHitsSource
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  
380     protected static Border noFocusBorder = new EmptyBorder(0,0,0,0);
39     
400     protected Color pickedVertexLabelColor = Color.black;
410     protected Color pickedEdgeLabelColor = Color.black;
42      protected boolean rotateEdgeLabels;
43  
44      
45      public DefaultGraphLabelRenderer(Color pickedVertexLabelColor,
46              Color pickedEdgeLabelColor) {
470         this(pickedVertexLabelColor, pickedEdgeLabelColor, true);
480     }
49     /**
50      * Creates a default table cell renderer.
51      */
52     public DefaultGraphLabelRenderer(Color pickedVertexLabelColor,
53             Color pickedEdgeLabelColor, boolean rotateEdgeLabels) {
540        super();
550        this.pickedVertexLabelColor = pickedVertexLabelColor;
560        this.pickedEdgeLabelColor = pickedEdgeLabelColor;
570        this.rotateEdgeLabels = rotateEdgeLabels;
580        setOpaque(true);
590        setBorder(noFocusBorder);
600    }
61  
62     /**
63      * @return Returns the rotateEdgeLabels.
64      */
65     public boolean isRotateEdgeLabels() {
660        return rotateEdgeLabels;
67     }
68     /**
69      * @param rotateEdgeLabels The rotateEdgeLabels to set.
70      */
71     public void setRotateEdgeLabels(boolean rotateEdgeLabels) {
720        this.rotateEdgeLabels = rotateEdgeLabels;
730    }
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) {
810        super.setForeground(c);
820    }
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) {
910        super.setBackground(c);
920    }
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() {
1030        super.updateUI();
1040    setForeground(null);
1050    setBackground(null);
1060    }
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         
1210        super.setForeground(vv.getForeground());
1220        if(isSelected) setForeground(pickedVertexLabelColor);
1230        super.setBackground(vv.getBackground());
1240        if(font != null) {
125 // setFont(vv.getFont());
1260            setFont(font);
127         } else {
1280            setFont(vv.getFont());
129         }
1300        setIcon(null);
1310        setBorder(noFocusBorder);
1320        setValue(value);
1330        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         
1490        super.setForeground(vv.getForeground());
1500        if(isSelected) setForeground(pickedEdgeLabelColor);
1510        super.setBackground(vv.getBackground());
152         
1530        if(font != null) {
154 // setFont(vv.getFont());
1550            setFont(font);
156         } else {
1570            setFont(vv.getFont());
158         }
1590        setIcon(null);
1600        setBorder(noFocusBorder);
1610        setValue(value);
1620        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() {
1790        Color back = getBackground();
1800        Component p = getParent();
1810        if (p != null) {
1820            p = p.getParent();
183         }
1840        boolean colorMatch = (back != null) && (p != null) &&
185         back.equals(p.getBackground()) &&
186         p.isOpaque();
1870        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      */
1950    public void validate() {}
196  
197     /**
198      * Overridden for performance reasons.
199      * See the <a href="#override">Implementation Note</a>
200      * for more information.
201      */
2020    public void revalidate() {}
203  
204     /**
205      * Overridden for performance reasons.
206      * See the <a href="#override">Implementation Note</a>
207      * for more information.
208      */
2090    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      */
2160    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...
2250        if (propertyName=="text") {
2260            super.firePropertyChange(propertyName, oldValue, newValue);
227         }
2280    }
229  
230     /**
231      * Overridden for performance reasons.
232      * See the <a href="#override">Implementation Note</a>
233      * for more information.
234      */
2350    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) {
2480        setText((value == null) ? "" : value.toString());
2490    }
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.