Revision 38116 branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/project/documents/view/toc/gui/TOCRenderer.java
TOCRenderer.java | ||
---|---|---|
25 | 25 |
import java.awt.Color; |
26 | 26 |
import java.awt.Component; |
27 | 27 |
import java.awt.Dimension; |
28 |
import java.awt.FlowLayout; |
|
29 | 28 |
import java.awt.Font; |
30 |
import java.awt.GridBagConstraints; |
|
31 |
import java.awt.GridBagLayout; |
|
32 | 29 |
import java.awt.Rectangle; |
33 | 30 |
|
34 |
import javax.swing.BorderFactory; |
|
35 | 31 |
import javax.swing.Icon; |
36 | 32 |
import javax.swing.JCheckBox; |
37 | 33 |
import javax.swing.JLabel; |
38 | 34 |
import javax.swing.JPanel; |
39 | 35 |
import javax.swing.JTree; |
40 | 36 |
import javax.swing.SpringLayout; |
41 |
import javax.swing.UIManager; |
|
42 |
import javax.swing.border.Border; |
|
43 | 37 |
import javax.swing.tree.DefaultMutableTreeNode; |
44 | 38 |
import javax.swing.tree.TreeCellRenderer; |
45 | 39 |
|
... | ... | |
54 | 48 |
*/ |
55 | 49 |
public class TOCRenderer extends JPanel implements TreeCellRenderer { |
56 | 50 |
|
57 |
public Border bordeSeleccionado = BorderFactory.createEtchedBorder(); |
|
58 |
|
|
59 |
/* |
|
60 |
* public Border bordeSeleccionado = |
|
61 |
* BorderFactory.createBevelBorder(BevelBorder.RAISED, |
|
62 |
* SystemColor.black, SystemColor.lightGray, SystemColor.gray, |
|
63 |
* SystemColor.lightGray); |
|
64 |
*/ |
|
65 |
private Border bordeNormal = BorderFactory.createEmptyBorder(); |
|
66 |
|
|
51 |
private static final long serialVersionUID = -6733445768959238193L; |
|
67 | 52 |
private JCheckBox check; |
68 | 53 |
private JLabel label; |
69 | 54 |
|
70 |
private static final Font BIGGER_FONT = |
|
71 |
new Font("SansSerif", Font.BOLD, 12); |
|
55 |
private final Color editingColor; |
|
72 | 56 |
|
73 |
GridBagLayout gridbag = new GridBagLayout(); |
|
74 |
GridBagConstraints c = new GridBagConstraints(); |
|
75 |
|
|
76 | 57 |
/** |
77 | 58 |
* Creates a new TOCRenderer object. |
78 | 59 |
*/ |
79 | 60 |
public TOCRenderer() { |
80 |
this.setBackground(Color.lightGray); |
|
81 |
// this.setLayout(new BorderLayout()); |
|
82 |
this.setLayout(new FlowLayout(FlowLayout.LEADING, 0, 0)); |
|
61 |
this(Color.RED); |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* Creates a new TOCRenderer object. |
|
66 |
*/ |
|
67 |
public TOCRenderer(Color editingColor) { |
|
68 |
this.editingColor = editingColor; |
|
69 |
|
|
83 | 70 |
check = new JCheckBox(); |
84 | 71 |
label = new JLabel(); |
85 | 72 |
|
86 |
/* |
|
87 |
* this.setLayout(gridbag); |
|
88 |
* |
|
89 |
* c.fill = GridBagConstraints.NONE; |
|
90 |
* c.weightx = 1.0; |
|
91 |
* c.anchor = GridBagConstraints.WEST; |
|
92 |
* // c.weightx = check.getWidth(); |
|
93 |
* gridbag.setConstraints(check,c); |
|
94 |
* this.add(check); |
|
95 |
* c.anchor = GridBagConstraints.WEST; |
|
96 |
* gridbag.setConstraints(colorPanel,c); |
|
97 |
* // c.weightx = colorPanel.getWidth(); |
|
98 |
* this.add(colorPanel); |
|
99 |
* c.gridwidth = GridBagConstraints.REMAINDER; //end row |
|
100 |
* c.fill = GridBagConstraints.HORIZONTAL; |
|
101 |
* gridbag.setConstraints(label,c); |
|
102 |
* this.add(label); |
|
103 |
*/ |
|
104 |
|
|
105 |
/* |
|
106 |
* this.setLayout(new FlowLayout(FlowLayout.LEFT)); |
|
107 |
* this.add(check); |
|
108 |
* this.add(colorPanel); |
|
109 |
* this.add(label); |
|
110 |
*/ |
|
111 |
|
|
112 |
/* |
|
113 |
* this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
|
114 |
* this.add(check); |
|
115 |
* this.add(colorPanel); |
|
116 |
* this.add(label); |
|
117 |
*/ |
|
118 |
|
|
119 | 73 |
SpringLayout theLayout = new SpringLayout(); |
120 | 74 |
this.setLayout(theLayout); |
121 | 75 |
|
122 |
// int rows = 1; |
|
123 |
// int cols = 2; |
|
124 |
|
|
125 |
/* |
|
126 |
* this.setLayout(new BorderLayout()); |
|
127 |
* |
|
128 |
* this.add(check, BorderLayout.WEST); |
|
129 |
* this.add(label, BorderLayout.CENTER); |
|
130 |
*/ |
|
131 |
/* |
|
132 |
* GridBagLayout gridbag = new GridBagLayout(); |
|
133 |
* GridBagConstraints c = new GridBagConstraints(); |
|
134 |
* |
|
135 |
* this.setLayout(gridbag); |
|
136 |
* this.add(check); |
|
137 |
* c.gridwidth = GridBagConstraints.REMAINDER; |
|
138 |
* c.fill = GridBagConstraints.HORIZONTAL; |
|
139 |
* this.add(label, c); |
|
140 |
*/ |
|
141 |
|
|
142 | 76 |
// Adjust constraints for the text field so it's at |
143 | 77 |
// (<label's right edge> + 5, 5). |
144 | 78 |
this.add(check); |
... | ... | |
146 | 80 |
|
147 | 81 |
theLayout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.EAST, |
148 | 82 |
check); |
149 |
|
|
150 |
this.setBorder(bordeSeleccionado); |
|
151 |
|
|
152 |
check.setBackground(UIManager.getColor("Button.background")); |
|
153 |
label.setForeground(UIManager.getColor("Tree.textForeground")); |
|
154 |
|
|
155 | 83 |
} |
156 | 84 |
|
157 | 85 |
/** |
... | ... | |
173 | 101 |
boolean hasFocus) { |
174 | 102 |
|
175 | 103 |
DefaultMutableTreeNode n = (DefaultMutableTreeNode) value; |
176 |
String stringValue = ""; |
|
177 |
this.setBackground(UIManager.getColor("Button.background")); |
|
104 |
Color foreground = tree.getForeground(); |
|
178 | 105 |
this.label.setFont(tree.getFont()); |
179 |
// System.out.println("ancho tree=" + tree.getWidth()); |
|
180 | 106 |
|
181 | 107 |
if (n.getUserObject() instanceof ITocItem) { |
182 | 108 |
|
183 | 109 |
ITocItem item = (ITocItem) n.getUserObject(); |
184 |
stringValue = item.getLabel(); |
|
110 |
label.setText(item.getLabel()); |
|
111 |
Icon icono = item.getIcon(); |
|
112 |
if (icono != null) { |
|
113 |
label.setIcon(icono); |
|
114 |
} |
|
185 | 115 |
|
116 |
this.validate(); |
|
186 | 117 |
Dimension sizeNode = item.getSize(); // Se fija en el resize del TOC |
187 |
|
|
188 | 118 |
this.setPreferredSize(sizeNode); |
189 | 119 |
|
190 | 120 |
if (item instanceof TocItemBranch) { |
... | ... | |
196 | 126 |
check.setEnabled(false); |
197 | 127 |
} else { |
198 | 128 |
check.setEnabled(true); |
199 |
if (!lyr.isWithinScale(lyr.getMapContext().getScaleView())) |
|
129 |
if (!lyr.isWithinScale(lyr.getMapContext().getScaleView())) {
|
|
200 | 130 |
check.setEnabled(false); |
131 |
} |
|
201 | 132 |
|
202 | 133 |
if (lyr.isEditing()) { |
203 |
this.label.setForeground(Color.RED); |
|
204 |
} else |
|
205 |
this.label.setForeground(Color.BLACK); |
|
134 |
this.label.setForeground(editingColor); |
|
135 |
} else { |
|
136 |
this.label.setForeground(foreground); |
|
137 |
} |
|
206 | 138 |
} |
207 | 139 |
if (lyr.isActive()) { |
208 |
this.setBorder(bordeSeleccionado); |
|
209 |
this.label.setFont(BIGGER_FONT); |
|
210 |
} else { |
|
211 |
this.setBorder(bordeNormal); |
|
140 |
this.label.setFont(label.getFont().deriveFont(Font.BOLD)); |
|
212 | 141 |
} |
213 | 142 |
} else { |
214 | 143 |
check.setVisible(false); |
215 |
this.setBorder(bordeNormal); |
|
216 |
|
|
217 | 144 |
} |
218 |
label.setText(stringValue); |
|
219 |
Icon icono = item.getIcon(); |
|
220 |
if (icono != null) { |
|
221 |
label.setIcon(icono); |
|
222 |
// System.out.println(">>>>>Pongo etiqueta " + stringValue + |
|
223 |
// " con icono " + item.getIcon().toString()); |
|
224 |
} |
|
225 |
this.setPreferredSize(sizeNode); |
|
226 | 145 |
} |
227 |
// this.setPreferredSize(new Dimension(tree.getWidth()-60,24)); // |
|
228 |
// sizeNode); |
|
229 | 146 |
|
230 | 147 |
if (leaf) { |
231 | 148 |
// label.setIcon(UIManager.getIcon("Tree.leafIcon")); |
149 |
} else if (expanded) { |
|
150 |
// label.setIcon(UIManager.getIcon("Tree.openIcon")); |
|
151 |
} else { |
|
152 |
// label.setIcon(UIManager.getIcon("Tree.closedIcon")); |
|
153 |
} |
|
232 | 154 |
|
233 |
} else |
|
234 |
if (expanded) { |
|
235 |
// label.setIcon(UIManager.getIcon("Tree.openIcon")); |
|
236 |
} else { |
|
237 |
// label.setIcon(UIManager.getIcon("Tree.closedIcon")); |
|
238 |
} |
|
239 |
|
|
240 | 155 |
return this; |
241 | 156 |
} |
242 | 157 |
|
Also available in: Unified diff