svn-gvsig-desktop / branches / gvSIG_GisPlanet / applications / appgvSIG / src / com / iver / cit / gvsig / gui / legendmanager / panels / FPanelLegendLabels.java @ 2165
History | View | Annotate | Download (12.9 KB)
1 | 445 | fjp | /*
|
---|---|---|---|
2 | * Created on 01-jun-2004
|
||
3 | *
|
||
4 | */
|
||
5 | 1103 | fjp | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
6 | *
|
||
7 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
8 | *
|
||
9 | * This program is free software; you can redistribute it and/or
|
||
10 | * modify it under the terms of the GNU General Public License
|
||
11 | * as published by the Free Software Foundation; either version 2
|
||
12 | * of the License, or (at your option) any later version.
|
||
13 | *
|
||
14 | * This program is distributed in the hope that it will be useful,
|
||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
17 | * GNU General Public License for more details.
|
||
18 | *
|
||
19 | * You should have received a copy of the GNU General Public License
|
||
20 | * along with this program; if not, write to the Free Software
|
||
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
22 | *
|
||
23 | * For more information, contact:
|
||
24 | *
|
||
25 | * Generalitat Valenciana
|
||
26 | * Conselleria d'Infraestructures i Transport
|
||
27 | * Av. Blasco Ib??ez, 50
|
||
28 | * 46010 VALENCIA
|
||
29 | * SPAIN
|
||
30 | *
|
||
31 | * +34 963862235
|
||
32 | * gvsig@gva.es
|
||
33 | * www.gvsig.gva.es
|
||
34 | *
|
||
35 | * or
|
||
36 | *
|
||
37 | * IVER T.I. S.A
|
||
38 | * Salamanca 50
|
||
39 | * 46005 Valencia
|
||
40 | * Spain
|
||
41 | *
|
||
42 | * +34 963163400
|
||
43 | * dac@iver.es
|
||
44 | */
|
||
45 | 445 | fjp | package com.iver.cit.gvsig.gui.legendmanager.panels; |
46 | |||
47 | import java.awt.Font; |
||
48 | import java.awt.event.ActionEvent; |
||
49 | |||
50 | import javax.swing.ButtonGroup; |
||
51 | import javax.swing.DefaultComboBoxModel; |
||
52 | import javax.swing.JButton; |
||
53 | import javax.swing.JPanel; |
||
54 | |||
55 | 1830 | fernando | import com.hardcode.gdbms.engine.data.driver.DriverException; |
56 | 606 | fernando | import com.iver.andami.PluginServices; |
57 | 813 | fjp | import com.iver.cit.gvsig.fmap.core.FShape; |
58 | 458 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
59 | 594 | vcaballero | import com.iver.cit.gvsig.fmap.layers.FLayer; |
60 | 589 | vcaballero | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
61 | 594 | vcaballero | import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
62 | import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
||
63 | 458 | fjp | import com.iver.cit.gvsig.fmap.rendering.Legend; |
64 | 589 | vcaballero | import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
65 | 445 | fjp | import com.iver.cit.gvsig.gui.Dialogs.FontChooser; |
66 | import com.iver.cit.gvsig.gui.Panels.ColorChooserPanel; |
||
67 | |||
68 | /**
|
||
69 | * @author fjp
|
||
70 | *
|
||
71 | */
|
||
72 | 704 | fjp | public class FPanelLegendLabels extends JPanel implements ILegendPanel { |
73 | 445 | fjp | private static final Font DEFAULT_FONT = |
74 | new Font("SansSerif", Font.PLAIN, 9); |
||
75 | |||
76 | |||
77 | // private TOC m_TOC;
|
||
78 | 589 | vcaballero | private VectorialLegend m_Renderer;
|
79 | 594 | vcaballero | private ClassifiableVectorial m_lyr;
|
80 | 788 | fjp | private FSymbol m_FSymbol;
|
81 | 445 | fjp | |
82 | private ColorChooserPanel m_colorChooser = new ColorChooserPanel(); |
||
83 | |||
84 | |||
85 | private javax.swing.JLabel jLabel = null; |
||
86 | private javax.swing.JCheckBox jCheckBox = null; |
||
87 | private javax.swing.JLabel jLabel1 = null; |
||
88 | private javax.swing.JComboBox jComboBox = null; |
||
89 | private javax.swing.JLabel jLabel2 = null; |
||
90 | private javax.swing.JComboBox jComboBox1 = null; |
||
91 | private javax.swing.JPanel jPanel = null; |
||
92 | private javax.swing.JTextField jTextField = null; |
||
93 | private javax.swing.JRadioButton jRadioButton = null; |
||
94 | private javax.swing.JRadioButton jRadioButton1 = null; |
||
95 | 589 | vcaballero | private FPreviewSymbol fPreviewSymbol = null; |
96 | 445 | fjp | private javax.swing.JLabel jLabel3 = null; |
97 | private javax.swing.JButton jButton = null; |
||
98 | |||
99 | private Font labelFont = DEFAULT_FONT; |
||
100 | private JPanel parent; |
||
101 | private javax.swing.JLabel jLabel4 = null; |
||
102 | /**
|
||
103 | * This is the default constructor
|
||
104 | */
|
||
105 | public FPanelLegendLabels(JPanel parent) { |
||
106 | super();
|
||
107 | this.parent = parent;
|
||
108 | initialize(); |
||
109 | } |
||
110 | /**
|
||
111 | * This method initializes this
|
||
112 | *
|
||
113 | * @return void
|
||
114 | */
|
||
115 | private void initialize() { |
||
116 | this.setLayout(null); |
||
117 | this.setSize(454, 230); |
||
118 | this.add(getJCheckBox(), null); |
||
119 | this.add(getJLabel1(), null); |
||
120 | this.add(getJComboBox(), null); |
||
121 | this.add(getJLabel2(), null); |
||
122 | this.add(getJComboBox1(), null); |
||
123 | this.add(getJPanel(), null); |
||
124 | this.add(getFPreviewSymbol(), null); |
||
125 | this.add(getJLabel3(), null); |
||
126 | this.add(getJButton(), null); |
||
127 | |||
128 | // m_colorChooser = new ColorChooserPanel();
|
||
129 | // m_colorChooser.setColor(Color.RED);
|
||
130 | m_colorChooser.setAlpha(255);
|
||
131 | m_colorChooser.setBounds(190, 103, 99, 34); |
||
132 | m_colorChooser.addActionListener(new java.awt.event.ActionListener() {
|
||
133 | public void actionPerformed(ActionEvent e) { |
||
134 | updateControls(); |
||
135 | } |
||
136 | }); |
||
137 | this.add(getJLabel4(), null); |
||
138 | this.add(m_colorChooser);
|
||
139 | |||
140 | } |
||
141 | 594 | vcaballero | public void setLayer(FLayer lyr, Legend r) |
142 | 445 | fjp | { |
143 | 594 | vcaballero | m_lyr = (ClassifiableVectorial) lyr; |
144 | 589 | vcaballero | m_Renderer = (VectorialLegend)r; |
145 | 445 | fjp | |
146 | fillFieldNames(); |
||
147 | getJComboBox().getModel().setSelectedItem(m_Renderer.getLabelField()); |
||
148 | 801 | fjp | setFSymbol(r.getDefaultSymbol()); |
149 | |||
150 | 445 | fjp | if (m_Renderer.getLabelField() != null) |
151 | getJCheckBox().setSelected(true);
|
||
152 | else
|
||
153 | getJCheckBox().setSelected(false);
|
||
154 | 788 | fjp | |
155 | 787 | fjp | |
156 | 788 | fjp | |
157 | 801 | fjp | |
158 | 788 | fjp | } |
159 | public void setFSymbol(FSymbol sym) |
||
160 | { |
||
161 | if (sym == null) |
||
162 | { |
||
163 | 813 | fjp | m_FSymbol = new FSymbol(FShape.MULTI);
|
164 | 788 | fjp | } |
165 | else
|
||
166 | m_FSymbol = sym; |
||
167 | |||
168 | if (m_FSymbol.getFontColor()!=null){ |
||
169 | m_colorChooser.setColor(m_FSymbol.getFontColor()); |
||
170 | } |
||
171 | fPreviewSymbol.setSymbol(m_FSymbol); |
||
172 | |||
173 | 806 | fjp | getJRadioButton1().setSelected(!m_FSymbol.isFontSizeInPixels()); |
174 | 787 | fjp | getJTextField().setText("" +
|
175 | 788 | fjp | m_FSymbol.getFontSize()); |
176 | 445 | fjp | |
177 | |||
178 | } |
||
179 | |||
180 | private void updateControls() { |
||
181 | getJComboBox().setEnabled(getJCheckBox().isSelected()); |
||
182 | getJComboBox1().setEnabled(getJCheckBox().isSelected()); |
||
183 | getJRadioButton().setEnabled(getJCheckBox().isSelected()); |
||
184 | getJRadioButton1().setEnabled(getJCheckBox().isSelected()); |
||
185 | getJTextField().setEnabled(getJCheckBox().isSelected()); |
||
186 | if (getJCheckBox().isSelected())
|
||
187 | { |
||
188 | 788 | fjp | FSymbol sym = m_FSymbol; |
189 | 608 | fjp | sym.setFont(labelFont); |
190 | sym.setFontColor(m_colorChooser.getColor()); |
||
191 | 445 | fjp | fPreviewSymbol.setSymbol(sym); |
192 | } |
||
193 | } |
||
194 | 704 | fjp | private void updateValuesFromControls() { |
195 | 445 | fjp | if (getJCheckBox().isSelected())
|
196 | { |
||
197 | m_Renderer.setLabelField((String) getJComboBox().getSelectedItem());
|
||
198 | 589 | vcaballero | ///m_Renderer.setLabelHeightField((String) getJComboBox1().getSelectedItem());
|
199 | 788 | fjp | m_FSymbol.setFontColor(m_colorChooser.getColor()); |
200 | 806 | fjp | if (!getJRadioButton().isSelected())
|
201 | 445 | fjp | { |
202 | 772 | fjp | float sizeUnits = Float.parseFloat(getJTextField().getText()); |
203 | 788 | fjp | m_FSymbol.setFontSize(sizeUnits); // Para que se pueda crear correctamente al recuperar del proyecto
|
204 | m_FSymbol.setFontSizeInPixels(false);
|
||
205 | 445 | fjp | } |
206 | else
|
||
207 | 772 | fjp | { |
208 | float sizePoints = Float.parseFloat(getJTextField().getText()); |
||
209 | 788 | fjp | m_FSymbol.setFont(labelFont); |
210 | m_FSymbol.setFont(labelFont.deriveFont(sizePoints)); |
||
211 | m_FSymbol.setFontSize(sizePoints); |
||
212 | m_FSymbol.setFontSizeInPixels(true);
|
||
213 | 801 | fjp | } |
214 | m_Renderer.setDefaultSymbol(m_FSymbol); |
||
215 | 445 | fjp | } |
216 | else
|
||
217 | { |
||
218 | // Para que no se dibujen las etiquetas, el campo labelField del Renderer
|
||
219 | // ha de ser null
|
||
220 | m_Renderer.setLabelField(null);
|
||
221 | } |
||
222 | } |
||
223 | |||
224 | |||
225 | |||
226 | |||
227 | private void fillFieldNames() { |
||
228 | |||
229 | 589 | vcaballero | SelectableDataSource rs; |
230 | try {
|
||
231 | 594 | vcaballero | rs = ((AlphanumericData) m_lyr).getRecordset(); |
232 | 589 | vcaballero | String[] nomFields; |
233 | nomFields = new String[rs.getFieldCount()]; |
||
234 | for (int i = 0; i < rs.getFieldCount(); i++) { |
||
235 | 445 | fjp | nomFields[i] = rs.getFieldName(i).trim(); |
236 | } |
||
237 | |||
238 | DefaultComboBoxModel cM_labelField = new DefaultComboBoxModel(nomFields); |
||
239 | getJComboBox().setModel(cM_labelField); |
||
240 | DefaultComboBoxModel cM_heightField = new DefaultComboBoxModel(nomFields); |
||
241 | getJComboBox1().setModel(cM_heightField); |
||
242 | 654 | fernando | } catch (DriverException e) {
|
243 | 589 | vcaballero | e.printStackTrace(); |
244 | 1830 | fernando | } catch (com.iver.cit.gvsig.fmap.DriverException e) {
|
245 | e.printStackTrace(); |
||
246 | 445 | fjp | } |
247 | 589 | vcaballero | |
248 | } |
||
249 | 445 | fjp | |
250 | |||
251 | /**
|
||
252 | |||
253 | * This method initializes jCheckBox
|
||
254 | |||
255 | *
|
||
256 | |||
257 | * @return javax.swing.JCheckBox
|
||
258 | |||
259 | */
|
||
260 | private javax.swing.JCheckBox getJCheckBox() {
|
||
261 | if (jCheckBox == null) { |
||
262 | jCheckBox = new javax.swing.JCheckBox();
|
||
263 | 606 | fernando | jCheckBox.setText(PluginServices.getText(this,"Habilitar_etiquetado")); |
264 | 445 | fjp | jCheckBox.setBounds(28, 22, 117, 23); |
265 | jCheckBox.addItemListener(new java.awt.event.ItemListener() {
|
||
266 | |||
267 | public void itemStateChanged(java.awt.event.ItemEvent e) { |
||
268 | updateControls(); |
||
269 | |||
270 | } |
||
271 | }); |
||
272 | |||
273 | } |
||
274 | return jCheckBox;
|
||
275 | } |
||
276 | |||
277 | /**
|
||
278 | |||
279 | * This method initializes jLabel1
|
||
280 | |||
281 | *
|
||
282 | |||
283 | * @return javax.swing.JLabel
|
||
284 | |||
285 | */
|
||
286 | private javax.swing.JLabel getJLabel1() {
|
||
287 | if (jLabel1 == null) { |
||
288 | jLabel1 = new javax.swing.JLabel();
|
||
289 | 606 | fernando | jLabel1.setText(PluginServices.getText(this,"Campo_de_etiquetado")); |
290 | 445 | fjp | jLabel1.setBounds(29, 53, 116, 21); |
291 | } |
||
292 | return jLabel1;
|
||
293 | } |
||
294 | |||
295 | /**
|
||
296 | |||
297 | * This method initializes jComboBox
|
||
298 | |||
299 | *
|
||
300 | |||
301 | * @return javax.swing.JComboBox
|
||
302 | |||
303 | */
|
||
304 | private javax.swing.JComboBox getJComboBox() {
|
||
305 | if (jComboBox == null) { |
||
306 | jComboBox = new javax.swing.JComboBox();
|
||
307 | jComboBox.setBounds(175, 52, 110, 19); |
||
308 | jComboBox.setEnabled(false);
|
||
309 | } |
||
310 | return jComboBox;
|
||
311 | } |
||
312 | |||
313 | /**
|
||
314 | |||
315 | * This method initializes jLabel2
|
||
316 | |||
317 | *
|
||
318 | |||
319 | * @return javax.swing.JLabel
|
||
320 | |||
321 | */
|
||
322 | private javax.swing.JLabel getJLabel2() {
|
||
323 | if (jLabel2 == null) { |
||
324 | jLabel2 = new javax.swing.JLabel();
|
||
325 | jLabel2.setBounds(29, 83, 137, 21); |
||
326 | 606 | fernando | jLabel2.setText(PluginServices.getText(this,"campo_altura_texto")); |
327 | 445 | fjp | jLabel2.setVisible(false);
|
328 | } |
||
329 | return jLabel2;
|
||
330 | } |
||
331 | |||
332 | /**
|
||
333 | |||
334 | * This method initializes jComboBox1
|
||
335 | |||
336 | *
|
||
337 | |||
338 | * @return javax.swing.JComboBox
|
||
339 | |||
340 | */
|
||
341 | private javax.swing.JComboBox getJComboBox1() {
|
||
342 | if (jComboBox1 == null) { |
||
343 | jComboBox1 = new javax.swing.JComboBox();
|
||
344 | jComboBox1.setBounds(175, 82, 110, 18); |
||
345 | jComboBox1.setEnabled(false);
|
||
346 | jComboBox1.setVisible(false);
|
||
347 | } |
||
348 | return jComboBox1;
|
||
349 | } |
||
350 | |||
351 | /**
|
||
352 | |||
353 | * This method initializes jPanel
|
||
354 | |||
355 | *
|
||
356 | |||
357 | * @return javax.swing.JPanel
|
||
358 | |||
359 | */
|
||
360 | private javax.swing.JPanel getJPanel() {
|
||
361 | if (jPanel == null) { |
||
362 | jPanel = new javax.swing.JPanel();
|
||
363 | jPanel.setLayout(null);
|
||
364 | jPanel.setBounds(29, 136, 258, 84); |
||
365 | 606 | fernando | jPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this,"Altura_fija_de_texto"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
366 | 445 | fjp | ButtonGroup jButtonGroup = new ButtonGroup(); |
367 | jButtonGroup.add(getJRadioButton1()); |
||
368 | jButtonGroup.add(getJRadioButton()); |
||
369 | jPanel.add(getJRadioButton1(), null);
|
||
370 | jPanel.add(getJRadioButton(), null);
|
||
371 | jPanel.add(getJTextField(), null);
|
||
372 | } |
||
373 | return jPanel;
|
||
374 | } |
||
375 | |||
376 | /**
|
||
377 | |||
378 | * This method initializes jTextField
|
||
379 | |||
380 | *
|
||
381 | |||
382 | * @return javax.swing.JTextField
|
||
383 | |||
384 | */
|
||
385 | private javax.swing.JTextField getJTextField() {
|
||
386 | if (jTextField == null) { |
||
387 | jTextField = new javax.swing.JTextField();
|
||
388 | jTextField.setBounds(26, 32, 76, 21); |
||
389 | jTextField.setEnabled(false);
|
||
390 | jTextField.setText("10");
|
||
391 | } |
||
392 | return jTextField;
|
||
393 | } |
||
394 | |||
395 | /**
|
||
396 | |||
397 | * This method initializes jRadioButton
|
||
398 | |||
399 | *
|
||
400 | |||
401 | * @return javax.swing.JRadioButton
|
||
402 | |||
403 | */
|
||
404 | private javax.swing.JRadioButton getJRadioButton() {
|
||
405 | if (jRadioButton == null) { |
||
406 | jRadioButton = new javax.swing.JRadioButton();
|
||
407 | 606 | fernando | jRadioButton.setText(PluginServices.getText(this,"En_pixels")); |
408 | 445 | fjp | jRadioButton.setBounds(145, 44, 100, 23); |
409 | jRadioButton.setEnabled(false);
|
||
410 | jRadioButton.setSelected(true);
|
||
411 | } |
||
412 | return jRadioButton;
|
||
413 | } |
||
414 | |||
415 | /**
|
||
416 | |||
417 | * This method initializes jRadioButton1
|
||
418 | |||
419 | *
|
||
420 | |||
421 | * @return javax.swing.JRadioButton
|
||
422 | |||
423 | */
|
||
424 | private javax.swing.JRadioButton getJRadioButton1() {
|
||
425 | if (jRadioButton1 == null) { |
||
426 | jRadioButton1 = new javax.swing.JRadioButton();
|
||
427 | 606 | fernando | jRadioButton1.setText(PluginServices.getText(this,"En_metros")); |
428 | 445 | fjp | jRadioButton1.setBounds(145, 16, 100, 23); |
429 | jRadioButton1.setEnabled(false);
|
||
430 | } |
||
431 | return jRadioButton1;
|
||
432 | } |
||
433 | |||
434 | /**
|
||
435 | |||
436 | * This method initializes fPreviewSymbol
|
||
437 | |||
438 | *
|
||
439 | |||
440 | * @return com.iver.cit.opensig.gui.Panels.FPreviewSymbol
|
||
441 | |||
442 | */
|
||
443 | 589 | vcaballero | private FPreviewSymbol getFPreviewSymbol() {
|
444 | 445 | fjp | if (fPreviewSymbol == null) { |
445 | 589 | vcaballero | fPreviewSymbol = new FPreviewSymbol();
|
446 | 445 | fjp | fPreviewSymbol.setBounds(311, 53, 134, 77); |
447 | } |
||
448 | return fPreviewSymbol;
|
||
449 | } |
||
450 | |||
451 | /**
|
||
452 | |||
453 | * This method initializes jLabel3
|
||
454 | |||
455 | *
|
||
456 | |||
457 | * @return javax.swing.JLabel
|
||
458 | |||
459 | */
|
||
460 | private javax.swing.JLabel getJLabel3() {
|
||
461 | if (jLabel3 == null) { |
||
462 | jLabel3 = new javax.swing.JLabel();
|
||
463 | jLabel3.setBounds(312, 28, 100, 18); |
||
464 | 606 | fernando | jLabel3.setText(PluginServices.getText(this,"Previsualizacion")); |
465 | 445 | fjp | } |
466 | return jLabel3;
|
||
467 | } |
||
468 | |||
469 | /**
|
||
470 | |||
471 | * This method initializes jButton
|
||
472 | |||
473 | *
|
||
474 | |||
475 | * @return javax.swing.JButton
|
||
476 | |||
477 | */
|
||
478 | private javax.swing.JButton getJButton() {
|
||
479 | if (jButton == null) { |
||
480 | jButton = new javax.swing.JButton();
|
||
481 | jButton.setBounds(315, 139, 111, 29); |
||
482 | 606 | fernando | jButton.setText(PluginServices.getText(this,"fuente")+"..."); |
483 | 445 | fjp | jButton.addActionListener(new java.awt.event.ActionListener() {
|
484 | |||
485 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
486 | JButton origen = (JButton) e.getSource(); |
||
487 | Font newFont;
|
||
488 | |||
489 | newFont = FontChooser.showDialog("Choose Font", labelFont);
|
||
490 | |||
491 | if (newFont == null) { |
||
492 | return;
|
||
493 | } |
||
494 | |||
495 | labelFont = newFont; |
||
496 | updateControls(); |
||
497 | |||
498 | |||
499 | } |
||
500 | }); |
||
501 | |||
502 | } |
||
503 | return jButton;
|
||
504 | } |
||
505 | |||
506 | /**
|
||
507 | |||
508 | * This method initializes jLabel4
|
||
509 | |||
510 | *
|
||
511 | |||
512 | * @return javax.swing.JLabel
|
||
513 | |||
514 | */
|
||
515 | private javax.swing.JLabel getJLabel4() {
|
||
516 | if (jLabel4 == null) { |
||
517 | jLabel4 = new javax.swing.JLabel();
|
||
518 | jLabel4.setBounds(29, 109, 133, 23); |
||
519 | 606 | fernando | jLabel4.setText(PluginServices.getText(this,"color_texto")); |
520 | 445 | fjp | } |
521 | return jLabel4;
|
||
522 | } |
||
523 | 704 | fjp | /* (non-Javadoc)
|
524 | * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
|
||
525 | */
|
||
526 | public Legend getLegend() {
|
||
527 | updateValuesFromControls(); |
||
528 | return m_Renderer;
|
||
529 | } |
||
530 | 445 | fjp | |
531 | } // @jve:visual-info decl-index=0 visual-constraint="10,10" |