svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toc / TOCRenderer.java @ 312
History | View | Annotate | Download (7.28 KB)
1 | 312 | fernando | /*
|
---|---|---|---|
2 | * Created on 23-feb-2004
|
||
3 | *
|
||
4 | * To change the template for this generated file go to
|
||
5 | * Window>Preferences>Java>Code Generation>Code and Comments
|
||
6 | */
|
||
7 | package com.iver.cit.gvsig.gui.toc; |
||
8 | |||
9 | import java.awt.Color; |
||
10 | import java.awt.Component; |
||
11 | import java.awt.Dimension; |
||
12 | import java.awt.Font; |
||
13 | import java.awt.GridBagConstraints; |
||
14 | import java.awt.GridBagLayout; |
||
15 | import java.awt.Rectangle; |
||
16 | |||
17 | import javax.swing.BorderFactory; |
||
18 | import javax.swing.JCheckBox; |
||
19 | import javax.swing.JLabel; |
||
20 | import javax.swing.JPanel; |
||
21 | import javax.swing.JTree; |
||
22 | import javax.swing.SpringLayout; |
||
23 | import javax.swing.UIManager; |
||
24 | import javax.swing.border.Border; |
||
25 | import javax.swing.tree.DefaultMutableTreeNode; |
||
26 | import javax.swing.tree.TreeCellRenderer; |
||
27 | |||
28 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
29 | import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
||
30 | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
||
31 | import com.iver.cit.gvsig.gui.Panels.FPreviewSymbol; |
||
32 | |||
33 | |||
34 | /**
|
||
35 | * Renderer que actua sobre el TOC.
|
||
36 | *
|
||
37 | * @author vcn
|
||
38 | */
|
||
39 | public class TOCRenderer extends JPanel implements TreeCellRenderer { |
||
40 | public Border bordeSeleccionado = BorderFactory.createEtchedBorder(); |
||
41 | |||
42 | /*public Border bordeSeleccionado = BorderFactory.createBevelBorder(BevelBorder.RAISED,
|
||
43 | SystemColor.black, SystemColor.lightGray, SystemColor.gray,
|
||
44 | SystemColor.lightGray);
|
||
45 | */
|
||
46 | private Border bordeNormal = BorderFactory.createEmptyBorder(); |
||
47 | |||
48 | // public Color m_color;
|
||
49 | private JCheckBox check; |
||
50 | private JLabel label; |
||
51 | // GridBagLayout gridBagLayout = new GridBagLayout();
|
||
52 | private FPreviewSymbol colorPanel; // = new PanelColor(); |
||
53 | |||
54 | private static final Font BIGGER_FONT = |
||
55 | new Font("SansSerif", Font.BOLD, 12); |
||
56 | |||
57 | GridBagLayout gridbag = new GridBagLayout(); |
||
58 | GridBagConstraints c = new GridBagConstraints(); |
||
59 | /**
|
||
60 | * Creates a new TOCRenderer object.
|
||
61 | */
|
||
62 | public TOCRenderer() {
|
||
63 | this.setBackground(Color.lightGray); |
||
64 | // this.setLayout(new BorderLayout());
|
||
65 | |||
66 | check = new JCheckBox(); |
||
67 | colorPanel = new FPreviewSymbol();
|
||
68 | colorPanel.setMinimumSize(new Dimension(25,20)); |
||
69 | label = new JLabel(); |
||
70 | |||
71 | |||
72 | |||
73 | /* this.setLayout(gridbag);
|
||
74 | |||
75 | c.fill = GridBagConstraints.NONE;
|
||
76 | c.weightx = 1.0;
|
||
77 | c.anchor = GridBagConstraints.WEST;
|
||
78 | // c.weightx = check.getWidth();
|
||
79 | gridbag.setConstraints(check,c);
|
||
80 | this.add(check);
|
||
81 | c.anchor = GridBagConstraints.WEST;
|
||
82 | gridbag.setConstraints(colorPanel,c);
|
||
83 | // c.weightx = colorPanel.getWidth();
|
||
84 | this.add(colorPanel);
|
||
85 | c.gridwidth = GridBagConstraints.REMAINDER; //end row
|
||
86 | c.fill = GridBagConstraints.HORIZONTAL;
|
||
87 | gridbag.setConstraints(label,c);
|
||
88 | this.add(label); */
|
||
89 | |||
90 | |||
91 | |||
92 | /* this.setLayout(new FlowLayout(FlowLayout.LEFT));
|
||
93 | this.add(check);
|
||
94 | this.add(colorPanel);
|
||
95 | this.add(label); */
|
||
96 | |||
97 | /* this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
|
||
98 | this.add(check);
|
||
99 | this.add(colorPanel);
|
||
100 | this.add(label); */
|
||
101 | |||
102 | SpringLayout theLayout = new SpringLayout(); |
||
103 | this.setLayout(theLayout);
|
||
104 | |||
105 | int rows = 1; |
||
106 | int cols = 3; |
||
107 | |||
108 | |||
109 | |||
110 | this.add(check);
|
||
111 | this.add(colorPanel);
|
||
112 | this.add(label);
|
||
113 | // Adjust constraints for the text field so it's at
|
||
114 | // (<label's right edge> + 5, 5).
|
||
115 | theLayout.putConstraint(SpringLayout.WEST, colorPanel,
|
||
116 | 5,
|
||
117 | SpringLayout.EAST, check);
|
||
118 | theLayout.putConstraint(SpringLayout.WEST, label,
|
||
119 | 5,
|
||
120 | SpringLayout.EAST, colorPanel);
|
||
121 | |||
122 | /* theLayout.putConstraint(SpringLayout.NORTH, textField,
|
||
123 | 5,
|
||
124 | SpringLayout.NORTH, contentPane); */
|
||
125 | |||
126 | |||
127 | /* // Lay out the panel.
|
||
128 | SpringUtilities.makeCompactGrid(this, //parent
|
||
129 | rows, cols,
|
||
130 | 3, 3, //initX, initY
|
||
131 | 3, 3); //xPad, yPad */
|
||
132 | |||
133 | |||
134 | this.setBorder(bordeSeleccionado);
|
||
135 | |||
136 | check.setBackground(UIManager.getColor("Button.background")); |
||
137 | label.setForeground(UIManager.getColor("Tree.textForeground")); |
||
138 | |||
139 | |||
140 | colorPanel.setPreferredSize(new Dimension(25,20)); |
||
141 | /*
|
||
142 | * TODO implementar bien
|
||
143 | FSymbol sym = new FSymbol(FConstant.SYMBOL_TYPE_FILL, Color.WHITE);
|
||
144 | colorPanel.setSymbol(sym);
|
||
145 | */
|
||
146 | // this.setMinimumSize(new Dimension(55,70));
|
||
147 | // this.setMinimumSize(new Dimension(55,70));
|
||
148 | // add(m_panelContenedor);
|
||
149 | |||
150 | } |
||
151 | |||
152 | /**
|
||
153 | * M?todo llamado una vez por cada nodo, y todas las veces que se redibuja
|
||
154 | * en pantalla el TOC.
|
||
155 | *
|
||
156 | * @param tree
|
||
157 | * @param value
|
||
158 | * @param isSelected
|
||
159 | * @param expanded
|
||
160 | * @param leaf
|
||
161 | * @param row
|
||
162 | * @param hasFocus
|
||
163 | *
|
||
164 | * @return
|
||
165 | */
|
||
166 | public Component getTreeCellRendererComponent(JTree tree, Object value, |
||
167 | boolean isSelected, boolean expanded, boolean leaf, int row, |
||
168 | boolean hasFocus) {
|
||
169 | |||
170 | // super.getTreeCellRendererComponent(tree,value,isSelected,expanded, leaf, row, hasFocus);
|
||
171 | |||
172 | int widthTree = tree.getWidth()-24; |
||
173 | Dimension sizeNode;
|
||
174 | if (widthTree < 100) widthTree = 100; |
||
175 | |||
176 | DefaultMutableTreeNode n = (DefaultMutableTreeNode) value; |
||
177 | String stringValue = ""; |
||
178 | this.setBackground(UIManager.getColor("Button.background")); |
||
179 | this.label.setFont(tree.getFont());
|
||
180 | |||
181 | // this.setPreferredSize(new Dimension(widthTree,20));
|
||
182 | sizeNode = new Dimension(widthTree,18); |
||
183 | |||
184 | if (n.getUserObject() instanceof FTheme) |
||
185 | { |
||
186 | FTheme elTema = (FTheme) n.getUserObject(); |
||
187 | FLayer lyr = elTema.getLayer(); |
||
188 | |||
189 | sizeNode = new Dimension(widthTree,25); |
||
190 | stringValue = lyr.getName(); |
||
191 | colorPanel.setVisible(true);
|
||
192 | colorPanel.setBackground(UIManager.getColor("Button.background")); |
||
193 | check.setVisible(true);
|
||
194 | check.setSelected(lyr.isVisible()); |
||
195 | if (lyr.isActive())
|
||
196 | { |
||
197 | this.setBorder(bordeSeleccionado);
|
||
198 | this.label.setFont(BIGGER_FONT);
|
||
199 | } |
||
200 | else
|
||
201 | { |
||
202 | this.setBorder(bordeNormal);
|
||
203 | } |
||
204 | |||
205 | if (lyr instanceof FLyrRaster) |
||
206 | { |
||
207 | colorPanel.setTextDescrip("raster");
|
||
208 | } |
||
209 | /*
|
||
210 | * //TODO implementar bien
|
||
211 | *
|
||
212 | if (lyr instanceof FLyrDgnG)
|
||
213 | {
|
||
214 | colorPanel.setTextDescrip("dgn");
|
||
215 | }
|
||
216 | if (lyr instanceof FLyrDxfG)
|
||
217 | {
|
||
218 | colorPanel.setTextDescrip("dxf");
|
||
219 | }
|
||
220 | if (lyr instanceof FLyrWMS)
|
||
221 | {
|
||
222 | colorPanel.setTextDescrip("wms");
|
||
223 | }
|
||
224 | |||
225 | |||
226 | if (lyr instanceof FLyrVect)
|
||
227 | {
|
||
228 | FLyrVect lyrVect = (FLyrVect) lyr;
|
||
229 | FRenderer r = lyrVect.getRenderer();
|
||
230 | if (r.getLegendType() == FConstant.LEGEND_TYPE_DEFAULT)
|
||
231 | {
|
||
232 | FSymbol sym = lyrVect.getRenderer().getDefaultSymbol();
|
||
233 | colorPanel.setVisible(true);
|
||
234 | colorPanel.setSymbol(sym);
|
||
235 | |||
236 | }
|
||
237 | else
|
||
238 | {
|
||
239 | colorPanel.setVisible(false);
|
||
240 | }
|
||
241 | }
|
||
242 | */
|
||
243 | } |
||
244 | /*
|
||
245 | *
|
||
246 | //TODO implementar bien
|
||
247 | if (n.getUserObject() instanceof FSymbol)
|
||
248 | {
|
||
249 | FSymbol sym = (FSymbol) n.getUserObject();
|
||
250 | stringValue = sym.m_Descrip;
|
||
251 | colorPanel.setVisible(true);
|
||
252 | check.setVisible(false);
|
||
253 | colorPanel.setSymbol(sym);
|
||
254 | this.setBorder(bordeNormal);
|
||
255 | |||
256 | }
|
||
257 | */
|
||
258 | this.setPreferredSize(sizeNode);
|
||
259 | label.setText(stringValue); |
||
260 | |||
261 | if (leaf) {
|
||
262 | // label.setIcon(UIManager.getIcon("Tree.leafIcon"));
|
||
263 | |||
264 | } else if (expanded) { |
||
265 | //label.setIcon(UIManager.getIcon("Tree.openIcon"));
|
||
266 | } else {
|
||
267 | //label.setIcon(UIManager.getIcon("Tree.closedIcon"));
|
||
268 | } |
||
269 | |||
270 | return this; |
||
271 | } |
||
272 | |||
273 | public Rectangle getCheckBoxBounds() { |
||
274 | return check.getBounds();
|
||
275 | } |
||
276 | |||
277 | } |