root / trunk / extensions / extArcims / src / es / prodevelop / cit / gvsig / arcims / gui / panels / utils / AvailableLayersTreeCellRenderer.java @ 8110
History | View | Annotate | Download (2.34 KB)
1 |
package es.prodevelop.cit.gvsig.arcims.gui.panels.utils; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Component; |
5 |
|
6 |
import javax.swing.JComponent; |
7 |
import javax.swing.JTree; |
8 |
import javax.swing.tree.DefaultMutableTreeNode; |
9 |
import javax.swing.tree.DefaultTreeCellRenderer; |
10 |
|
11 |
/**
|
12 |
* This class overrides the jtree cell renderer to allow
|
13 |
* a different tool tip for each node.
|
14 |
*
|
15 |
* @author jldominguez
|
16 |
*
|
17 |
*/
|
18 |
public class AvailableLayersTreeCellRenderer extends DefaultTreeCellRenderer { |
19 |
|
20 |
/**
|
21 |
* Colors used to indicate whether a node has been added or not.
|
22 |
* This has a sense in the FeatureServicePanel:
|
23 |
*
|
24 |
* @see es.prodevelop.cit.gvsig.arcims.gui.panels.FeatureServicePanel
|
25 |
*/
|
26 |
private Color addedLeafForeground = Color.LIGHT_GRAY; |
27 |
private Color notAddedLeafForeground = Color.BLACK; |
28 |
private static final long serialVersionUID = 0; |
29 |
|
30 |
|
31 |
/**
|
32 |
* This method sets the specific tool tip for each node
|
33 |
* and the root node
|
34 |
*/
|
35 |
public Component getTreeCellRendererComponent(JTree tree, Object value, |
36 |
boolean selected, boolean expanded, boolean leaf, int row, |
37 |
boolean hasFocus) {
|
38 |
|
39 |
Component c = super.getTreeCellRendererComponent(tree, value, selected, |
40 |
expanded, leaf, row, hasFocus); |
41 |
JComponent jc;
|
42 |
|
43 |
DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) value; |
44 |
Object innerObj = dmtn.getUserObject();
|
45 |
if (innerObj instanceof LayersListElement) { |
46 |
// tree nodes, with the LayersListElement's tool tip
|
47 |
LayersListElement lle = (LayersListElement) dmtn.getUserObject(); |
48 |
c.setForeground(this.getLeafForegroundColor(leaf, lle.isAdded(), selected));
|
49 |
jc = (JComponent) c;
|
50 |
jc.setToolTipText(lle.toolTipText()); |
51 |
} |
52 |
if (innerObj instanceof ServiceNamesObject) { |
53 |
// tree root node, with the ServiceNamesObject's tool tip
|
54 |
ServiceNamesObject sno = (ServiceNamesObject) dmtn.getUserObject(); |
55 |
jc = (JComponent) c;
|
56 |
jc.setToolTipText(sno.toolTipText()); |
57 |
} |
58 |
return c;
|
59 |
} |
60 |
|
61 |
/**
|
62 |
* Gets the tree node's font color.
|
63 |
*
|
64 |
* @param lf whether it is a leaf or not.
|
65 |
* @param added whether the node has been added or not.
|
66 |
* @param sel whether the node is selected or not.
|
67 |
* @return the node's font color.
|
68 |
*/
|
69 |
private Color getLeafForegroundColor(boolean lf, boolean added, boolean sel) { |
70 |
if (!lf) return Color.BLACK; |
71 |
if (sel) return Color.WHITE; |
72 |
if (added) {
|
73 |
return addedLeafForeground;
|
74 |
} else {
|
75 |
return notAddedLeafForeground;
|
76 |
} |
77 |
} |
78 |
|
79 |
} |