root / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toc / gui / TOCRenderer.java @ 10669
History | View | Annotate | Download (7.5 KB)
1 | 7304 | caballero | /*
|
---|---|---|---|
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 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
8 | *
|
||
9 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
10 | *
|
||
11 | * This program is free software; you can redistribute it and/or
|
||
12 | * modify it under the terms of the GNU General Public License
|
||
13 | * as published by the Free Software Foundation; either version 2
|
||
14 | * of the License, or (at your option) any later version.
|
||
15 | *
|
||
16 | * This program is distributed in the hope that it will be useful,
|
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
19 | * GNU General Public License for more details.
|
||
20 | *
|
||
21 | * You should have received a copy of the GNU General Public License
|
||
22 | * along with this program; if not, write to the Free Software
|
||
23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
24 | *
|
||
25 | * For more information, contact:
|
||
26 | *
|
||
27 | * Generalitat Valenciana
|
||
28 | * Conselleria d'Infraestructures i Transport
|
||
29 | * Av. Blasco Ib??ez, 50
|
||
30 | * 46010 VALENCIA
|
||
31 | * SPAIN
|
||
32 | *
|
||
33 | * +34 963862235
|
||
34 | * gvsig@gva.es
|
||
35 | * www.gvsig.gva.es
|
||
36 | *
|
||
37 | * or
|
||
38 | *
|
||
39 | * IVER T.I. S.A
|
||
40 | * Salamanca 50
|
||
41 | * 46005 Valencia
|
||
42 | * Spain
|
||
43 | *
|
||
44 | * +34 963163400
|
||
45 | * dac@iver.es
|
||
46 | */
|
||
47 | package com.iver.cit.gvsig.project.documents.view.toc.gui; |
||
48 | |||
49 | import java.awt.Color; |
||
50 | import java.awt.Component; |
||
51 | import java.awt.Dimension; |
||
52 | 7836 | ldiaz | import java.awt.FlowLayout; |
53 | 7304 | caballero | import java.awt.Font; |
54 | import java.awt.GridBagConstraints; |
||
55 | import java.awt.GridBagLayout; |
||
56 | import java.awt.Rectangle; |
||
57 | |||
58 | import javax.swing.BorderFactory; |
||
59 | import javax.swing.Icon; |
||
60 | import javax.swing.JCheckBox; |
||
61 | import javax.swing.JLabel; |
||
62 | import javax.swing.JPanel; |
||
63 | import javax.swing.JTree; |
||
64 | import javax.swing.SpringLayout; |
||
65 | import javax.swing.UIManager; |
||
66 | import javax.swing.border.Border; |
||
67 | import javax.swing.tree.DefaultMutableTreeNode; |
||
68 | import javax.swing.tree.TreeCellRenderer; |
||
69 | |||
70 | import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
||
71 | import com.iver.cit.gvsig.project.documents.view.toc.ITocItem; |
||
72 | import com.iver.cit.gvsig.project.documents.view.toc.TocItemBranch; |
||
73 | |||
74 | |||
75 | |||
76 | /**
|
||
77 | * Renderer que actua sobre el TOC.
|
||
78 | *
|
||
79 | * @author vcn
|
||
80 | */
|
||
81 | public class TOCRenderer extends JPanel implements TreeCellRenderer { |
||
82 | public Border bordeSeleccionado = BorderFactory.createEtchedBorder(); |
||
83 | |||
84 | /*public Border bordeSeleccionado = BorderFactory.createBevelBorder(BevelBorder.RAISED,
|
||
85 | SystemColor.black, SystemColor.lightGray, SystemColor.gray,
|
||
86 | SystemColor.lightGray);
|
||
87 | */
|
||
88 | private Border bordeNormal = BorderFactory.createEmptyBorder(); |
||
89 | |||
90 | private JCheckBox check; |
||
91 | private JLabel label; |
||
92 | |||
93 | private static final Font BIGGER_FONT = |
||
94 | new Font("SansSerif", Font.BOLD, 12); |
||
95 | |||
96 | GridBagLayout gridbag = new GridBagLayout(); |
||
97 | GridBagConstraints c = new GridBagConstraints(); |
||
98 | /**
|
||
99 | * Creates a new TOCRenderer object.
|
||
100 | */
|
||
101 | public TOCRenderer() {
|
||
102 | this.setBackground(Color.lightGray); |
||
103 | // this.setLayout(new BorderLayout());
|
||
104 | 7836 | ldiaz | this.setLayout(new FlowLayout(FlowLayout.LEADING, 0,0)); |
105 | 7304 | caballero | check = new JCheckBox(); |
106 | label = new JLabel(); |
||
107 | |||
108 | |||
109 | |||
110 | /* this.setLayout(gridbag);
|
||
111 | |||
112 | c.fill = GridBagConstraints.NONE;
|
||
113 | c.weightx = 1.0;
|
||
114 | c.anchor = GridBagConstraints.WEST;
|
||
115 | // c.weightx = check.getWidth();
|
||
116 | gridbag.setConstraints(check,c);
|
||
117 | this.add(check);
|
||
118 | c.anchor = GridBagConstraints.WEST;
|
||
119 | gridbag.setConstraints(colorPanel,c);
|
||
120 | // c.weightx = colorPanel.getWidth();
|
||
121 | this.add(colorPanel);
|
||
122 | c.gridwidth = GridBagConstraints.REMAINDER; //end row
|
||
123 | c.fill = GridBagConstraints.HORIZONTAL;
|
||
124 | gridbag.setConstraints(label,c);
|
||
125 | this.add(label); */
|
||
126 | |||
127 | |||
128 | |||
129 | /* this.setLayout(new FlowLayout(FlowLayout.LEFT));
|
||
130 | this.add(check);
|
||
131 | this.add(colorPanel);
|
||
132 | this.add(label); */
|
||
133 | |||
134 | /* this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
|
||
135 | this.add(check);
|
||
136 | this.add(colorPanel);
|
||
137 | this.add(label); */
|
||
138 | |||
139 | SpringLayout theLayout = new SpringLayout(); |
||
140 | this.setLayout(theLayout);
|
||
141 | |||
142 | //int rows = 1;
|
||
143 | //int cols = 2;
|
||
144 | |||
145 | /* this.setLayout(new BorderLayout());
|
||
146 | |||
147 | this.add(check, BorderLayout.WEST);
|
||
148 | this.add(label, BorderLayout.CENTER);
|
||
149 | */
|
||
150 | /*
|
||
151 | GridBagLayout gridbag = new GridBagLayout();
|
||
152 | GridBagConstraints c = new GridBagConstraints();
|
||
153 | |||
154 | this.setLayout(gridbag);
|
||
155 | this.add(check);
|
||
156 | c.gridwidth = GridBagConstraints.REMAINDER;
|
||
157 | c.fill = GridBagConstraints.HORIZONTAL;
|
||
158 | this.add(label, c);
|
||
159 | */
|
||
160 | |||
161 | // Adjust constraints for the text field so it's at
|
||
162 | // (<label's right edge> + 5, 5).
|
||
163 | this.add(check);
|
||
164 | this.add(label);
|
||
165 | |||
166 | theLayout.putConstraint(SpringLayout.WEST, label,
|
||
167 | 5,
|
||
168 | SpringLayout.EAST, check);
|
||
169 | |||
170 | this.setBorder(bordeSeleccionado);
|
||
171 | |||
172 | check.setBackground(UIManager.getColor("Button.background")); |
||
173 | label.setForeground(UIManager.getColor("Tree.textForeground")); |
||
174 | |||
175 | |||
176 | } |
||
177 | |||
178 | /**
|
||
179 | * M?todo llamado una vez por cada nodo, y todas las veces que se redibuja
|
||
180 | * en pantalla el TOC.
|
||
181 | *
|
||
182 | * @param tree
|
||
183 | * @param value
|
||
184 | * @param isSelected
|
||
185 | * @param expanded
|
||
186 | * @param leaf
|
||
187 | * @param row
|
||
188 | * @param hasFocus
|
||
189 | *
|
||
190 | * @return
|
||
191 | */
|
||
192 | public Component getTreeCellRendererComponent(JTree tree, Object value, |
||
193 | boolean isSelected, boolean expanded, boolean leaf, int row, |
||
194 | boolean hasFocus) {
|
||
195 | |||
196 | DefaultMutableTreeNode n = (DefaultMutableTreeNode) value; |
||
197 | String stringValue = ""; |
||
198 | this.setBackground(UIManager.getColor("Button.background")); |
||
199 | this.label.setFont(tree.getFont());
|
||
200 | // System.out.println("ancho tree=" + tree.getWidth());
|
||
201 | |||
202 | if (n.getUserObject() instanceof ITocItem) |
||
203 | { |
||
204 | |||
205 | ITocItem item = (ITocItem) n.getUserObject(); |
||
206 | stringValue = item.getLabel(); |
||
207 | |||
208 | Dimension sizeNode = item.getSize(); // Se fija en el resize del TOC |
||
209 | |||
210 | this.setPreferredSize(sizeNode);
|
||
211 | |||
212 | if (item instanceof TocItemBranch) |
||
213 | { |
||
214 | TocItemBranch branch = (TocItemBranch) item; |
||
215 | FLyrDefault lyr = (FLyrDefault)branch.getLayer(); |
||
216 | check.setVisible(true);
|
||
217 | check.setSelected(lyr.visibleRequired()); |
||
218 | if (!lyr.isAvailable()) {
|
||
219 | check.setEnabled(false);
|
||
220 | } else {
|
||
221 | check.setEnabled(true);
|
||
222 | if (!lyr.isWithinScale(lyr.getMapContext().getScaleView()))
|
||
223 | check.setEnabled(false);
|
||
224 | |||
225 | |||
226 | if (lyr.isEditing())
|
||
227 | { |
||
228 | this.label.setForeground(Color.RED); |
||
229 | } |
||
230 | else this.label.setForeground(Color.BLACK); |
||
231 | } |
||
232 | if (lyr.isActive())
|
||
233 | { |
||
234 | this.setBorder(bordeSeleccionado);
|
||
235 | this.label.setFont(BIGGER_FONT);
|
||
236 | } |
||
237 | else
|
||
238 | { |
||
239 | this.setBorder(bordeNormal);
|
||
240 | } |
||
241 | } |
||
242 | else
|
||
243 | { |
||
244 | check.setVisible(false);
|
||
245 | this.setBorder(bordeNormal);
|
||
246 | |||
247 | } |
||
248 | label.setText(stringValue); |
||
249 | Icon icono = item.getIcon();
|
||
250 | if (icono != null) |
||
251 | { |
||
252 | label.setIcon(icono); |
||
253 | //System.out.println(">>>>>Pongo etiqueta " + stringValue + " con icono " + item.getIcon().toString());
|
||
254 | } |
||
255 | this.setPreferredSize(sizeNode);
|
||
256 | } |
||
257 | // this.setPreferredSize(new Dimension(tree.getWidth()-60,24)); // sizeNode);
|
||
258 | |||
259 | if (leaf) {
|
||
260 | // label.setIcon(UIManager.getIcon("Tree.leafIcon"));
|
||
261 | |||
262 | } else if (expanded) { |
||
263 | //label.setIcon(UIManager.getIcon("Tree.openIcon"));
|
||
264 | } else {
|
||
265 | //label.setIcon(UIManager.getIcon("Tree.closedIcon"));
|
||
266 | } |
||
267 | |||
268 | return this; |
||
269 | } |
||
270 | |||
271 | public Rectangle getCheckBoxBounds() { |
||
272 | return check.getBounds();
|
||
273 | } |
||
274 | |||
275 | } |