svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / thememanager / legendmanager / panels / FPanelLegendLabels.java @ 2796
History | View | Annotate | Download (13.2 KB)
1 |
/*
|
---|---|
2 |
* Created on 01-jun-2004
|
3 |
*
|
4 |
*/
|
5 |
/* 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 |
package com.iver.cit.gvsig.gui.thememanager.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.JPanel; |
53 |
|
54 |
import com.iver.andami.PluginServices; |
55 |
import com.iver.cit.gvsig.ProjectExtension; |
56 |
import com.iver.cit.gvsig.fmap.DriverException; |
57 |
import com.iver.cit.gvsig.fmap.core.FShape; |
58 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
59 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
60 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
61 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
62 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
63 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
64 |
import com.iver.cit.gvsig.gui.Dialogs.FontChooser; |
65 |
import com.iver.cit.gvsig.gui.Panels.ColorChooserPanel; |
66 |
|
67 |
/**
|
68 |
* @author fjp
|
69 |
*
|
70 |
*/
|
71 |
public class FPanelLegendLabels extends JPanel implements ILegendPanel { |
72 |
private static final Font DEFAULT_FONT = |
73 |
new Font("SansSerif", Font.PLAIN, 9); |
74 |
|
75 |
|
76 |
// private TOC m_TOC;
|
77 |
private VectorialLegend m_Renderer;
|
78 |
private ClassifiableVectorial m_lyr;
|
79 |
private FSymbol m_FSymbol;
|
80 |
|
81 |
private ColorChooserPanel m_colorChooser = new ColorChooserPanel(); |
82 |
|
83 |
|
84 |
//private javax.swing.JLabel jLabel = null;
|
85 |
private javax.swing.JCheckBox jCheckBox = null; |
86 |
private javax.swing.JLabel jLabel1 = null; |
87 |
private javax.swing.JComboBox jComboBox = null; |
88 |
private javax.swing.JLabel jLabel2 = null; |
89 |
private javax.swing.JComboBox jComboBox1 = null; |
90 |
private javax.swing.JPanel jPanel = null; |
91 |
private javax.swing.JTextField jTextField = null; |
92 |
private javax.swing.JRadioButton jRadioButton = null; |
93 |
private javax.swing.JRadioButton jRadioButton1 = null; |
94 |
private FPreviewSymbol fPreviewSymbol = null; |
95 |
private javax.swing.JLabel jLabel3 = null; |
96 |
private javax.swing.JButton jButton = null; |
97 |
|
98 |
private Font labelFont = DEFAULT_FONT; |
99 |
//private JPanel parent;
|
100 |
private javax.swing.JLabel jLabel4 = null; |
101 |
/**
|
102 |
* This is the default constructor
|
103 |
*/
|
104 |
public FPanelLegendLabels(JPanel parent) { |
105 |
super();
|
106 |
//this.parent = parent;
|
107 |
initialize(); |
108 |
} |
109 |
/**
|
110 |
* This method initializes this
|
111 |
*
|
112 |
* @return void
|
113 |
*/
|
114 |
private void initialize() { |
115 |
this.setLayout(null); |
116 |
this.setSize(454, 230); |
117 |
this.add(getJCheckBox(), null); |
118 |
this.add(getJLabel1(), null); |
119 |
this.add(getJComboBox(), null); |
120 |
this.add(getJLabel2(), null); |
121 |
this.add(getJComboBox1(), null); |
122 |
this.add(getJPanel(), null); |
123 |
this.add(getFPreviewSymbol(), null); |
124 |
this.add(getJLabel3(), null); |
125 |
this.add(getJButton(), null); |
126 |
|
127 |
// m_colorChooser = new ColorChooserPanel();
|
128 |
// m_colorChooser.setColor(Color.RED);
|
129 |
m_colorChooser.setAlpha(255);
|
130 |
m_colorChooser.setBounds(190, 103, 99, 34); |
131 |
m_colorChooser.addActionListener(new java.awt.event.ActionListener() {
|
132 |
public void actionPerformed(ActionEvent e) { |
133 |
updateControls(); |
134 |
} |
135 |
}); |
136 |
this.add(getJLabel4(), null); |
137 |
this.add(m_colorChooser);
|
138 |
|
139 |
} |
140 |
public void setLayer(FLayer lyr, Legend r) |
141 |
{ |
142 |
m_lyr = (ClassifiableVectorial) lyr; |
143 |
m_Renderer = (VectorialLegend)r; |
144 |
|
145 |
fillFieldNames(); |
146 |
getJComboBox().getModel().setSelectedItem(m_Renderer.getLabelField()); |
147 |
setFSymbol(r.getDefaultSymbol()); |
148 |
|
149 |
if (m_Renderer.getLabelField() != null) |
150 |
getJCheckBox().setSelected(true);
|
151 |
else
|
152 |
getJCheckBox().setSelected(false);
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
} |
158 |
public void setFSymbol(FSymbol sym) |
159 |
{ |
160 |
if (sym == null) |
161 |
{ |
162 |
m_FSymbol = new FSymbol(FShape.MULTI);
|
163 |
} |
164 |
else
|
165 |
m_FSymbol = sym; |
166 |
|
167 |
if (m_FSymbol.getFontColor()!=null){ |
168 |
m_colorChooser.setColor(m_FSymbol.getFontColor()); |
169 |
} |
170 |
fPreviewSymbol.setSymbol(m_FSymbol); |
171 |
|
172 |
getJRadioButton1().setSelected(!m_FSymbol.isFontSizeInPixels()); |
173 |
getJTextField().setText("" +
|
174 |
m_FSymbol.getFontSize()); |
175 |
|
176 |
|
177 |
} |
178 |
|
179 |
private void updateControls() { |
180 |
getJComboBox().setEnabled(getJCheckBox().isSelected()); |
181 |
getJComboBox1().setEnabled(getJCheckBox().isSelected()); |
182 |
getJRadioButton().setEnabled(getJCheckBox().isSelected()); |
183 |
getJRadioButton1().setEnabled(getJCheckBox().isSelected()); |
184 |
getJTextField().setEnabled(getJCheckBox().isSelected()); |
185 |
if (getJCheckBox().isSelected())
|
186 |
{ |
187 |
FSymbol sym = m_FSymbol; |
188 |
sym.setFont(labelFont); |
189 |
sym.setFontColor(m_colorChooser.getColor()); |
190 |
fPreviewSymbol.setSymbol(sym); |
191 |
} |
192 |
} |
193 |
public void updateValuesFromControls(VectorialLegend l) { |
194 |
if (getJCheckBox().isSelected())
|
195 |
{ |
196 |
m_FSymbol = l.getDefaultSymbol(); |
197 |
m_FSymbol.setFont(labelFont); |
198 |
l.setLabelField((String) getJComboBox().getSelectedItem());
|
199 |
///m_Renderer.setLabelHeightField((String) getJComboBox1().getSelectedItem());
|
200 |
m_FSymbol.setFontColor(m_colorChooser.getColor()); |
201 |
//m_FSymbol.setSymbolType(m_Renderer.getShapeType());
|
202 |
if (!getJRadioButton().isSelected())
|
203 |
{ |
204 |
float sizeUnits = Float.parseFloat(getJTextField().getText()); |
205 |
m_FSymbol.setFontSize(sizeUnits); // Para que se pueda crear correctamente al recuperar del proyecto
|
206 |
m_FSymbol.setFontSizeInPixels(false);
|
207 |
} |
208 |
else
|
209 |
{ |
210 |
float sizePoints = Float.parseFloat(getJTextField().getText()); |
211 |
m_FSymbol.setFont(labelFont); |
212 |
m_FSymbol.setFont(labelFont.deriveFont(sizePoints)); |
213 |
m_FSymbol.setFontSize(sizePoints); |
214 |
m_FSymbol.setFontSizeInPixels(true);
|
215 |
} |
216 |
l.setDefaultSymbol(m_FSymbol); |
217 |
// System.out.println("Color punto 3 " + m_FSymbol.getColor().toString());
|
218 |
} |
219 |
else
|
220 |
{ |
221 |
// Para que no se dibujen las etiquetas, el campo labelField del Renderer
|
222 |
// ha de ser null
|
223 |
l.setLabelField(null);
|
224 |
} |
225 |
} |
226 |
|
227 |
|
228 |
|
229 |
|
230 |
private void fillFieldNames() { |
231 |
|
232 |
SelectableDataSource rs; |
233 |
try {
|
234 |
rs = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject().getDataSourceByLayer((FLayer) m_lyr); |
235 |
String[] nomFields; |
236 |
nomFields = new String[rs.getFieldCount()]; |
237 |
for (int i = 0; i < rs.getFieldCount(); i++) { |
238 |
nomFields[i] = rs.getFieldName(i).trim(); |
239 |
} |
240 |
|
241 |
DefaultComboBoxModel cM_labelField = new DefaultComboBoxModel(nomFields); |
242 |
getJComboBox().setModel(cM_labelField); |
243 |
DefaultComboBoxModel cM_heightField = new DefaultComboBoxModel(nomFields); |
244 |
getJComboBox1().setModel(cM_heightField); |
245 |
|
246 |
} catch (DriverException e) {
|
247 |
e.printStackTrace(); |
248 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
249 |
e.printStackTrace(); |
250 |
} |
251 |
} |
252 |
|
253 |
|
254 |
/**
|
255 |
|
256 |
* This method initializes jCheckBox
|
257 |
|
258 |
*
|
259 |
|
260 |
* @return javax.swing.JCheckBox
|
261 |
|
262 |
*/
|
263 |
private javax.swing.JCheckBox getJCheckBox() {
|
264 |
if (jCheckBox == null) { |
265 |
jCheckBox = new javax.swing.JCheckBox();
|
266 |
jCheckBox.setText(PluginServices.getText(this,"Habilitar_etiquetado")); |
267 |
jCheckBox.setBounds(28, 22, 152, 23); |
268 |
jCheckBox.addItemListener(new java.awt.event.ItemListener() {
|
269 |
|
270 |
public void itemStateChanged(java.awt.event.ItemEvent e) { |
271 |
updateControls(); |
272 |
|
273 |
} |
274 |
}); |
275 |
|
276 |
} |
277 |
return jCheckBox;
|
278 |
} |
279 |
|
280 |
/**
|
281 |
|
282 |
* This method initializes jLabel1
|
283 |
|
284 |
*
|
285 |
|
286 |
* @return javax.swing.JLabel
|
287 |
|
288 |
*/
|
289 |
private javax.swing.JLabel getJLabel1() {
|
290 |
if (jLabel1 == null) { |
291 |
jLabel1 = new javax.swing.JLabel();
|
292 |
jLabel1.setText(PluginServices.getText(this,"Campo_de_etiquetado")); |
293 |
jLabel1.setBounds(29, 53, 139, 21); |
294 |
} |
295 |
return jLabel1;
|
296 |
} |
297 |
|
298 |
/**
|
299 |
|
300 |
* This method initializes jComboBox
|
301 |
|
302 |
*
|
303 |
|
304 |
* @return javax.swing.JComboBox
|
305 |
|
306 |
*/
|
307 |
private javax.swing.JComboBox getJComboBox() {
|
308 |
if (jComboBox == null) { |
309 |
jComboBox = new javax.swing.JComboBox();
|
310 |
jComboBox.setBounds(175, 52, 110, 19); |
311 |
jComboBox.setEnabled(false);
|
312 |
} |
313 |
return jComboBox;
|
314 |
} |
315 |
|
316 |
/**
|
317 |
|
318 |
* This method initializes jLabel2
|
319 |
|
320 |
*
|
321 |
|
322 |
* @return javax.swing.JLabel
|
323 |
|
324 |
*/
|
325 |
private javax.swing.JLabel getJLabel2() {
|
326 |
if (jLabel2 == null) { |
327 |
jLabel2 = new javax.swing.JLabel();
|
328 |
jLabel2.setBounds(298, 190, 137, 21); |
329 |
jLabel2.setText(PluginServices.getText(this,"campo_altura_texto")); |
330 |
jLabel2.setVisible(false);
|
331 |
} |
332 |
return jLabel2;
|
333 |
} |
334 |
|
335 |
/**
|
336 |
|
337 |
* This method initializes jComboBox1
|
338 |
|
339 |
*
|
340 |
|
341 |
* @return javax.swing.JComboBox
|
342 |
|
343 |
*/
|
344 |
private javax.swing.JComboBox getJComboBox1() {
|
345 |
if (jComboBox1 == null) { |
346 |
jComboBox1 = new javax.swing.JComboBox();
|
347 |
jComboBox1.setBounds(175, 82, 110, 18); |
348 |
jComboBox1.setEnabled(false);
|
349 |
jComboBox1.setVisible(false);
|
350 |
} |
351 |
return jComboBox1;
|
352 |
} |
353 |
|
354 |
/**
|
355 |
|
356 |
* This method initializes jPanel
|
357 |
|
358 |
*
|
359 |
|
360 |
* @return javax.swing.JPanel
|
361 |
|
362 |
*/
|
363 |
private javax.swing.JPanel getJPanel() {
|
364 |
if (jPanel == null) { |
365 |
jPanel = new javax.swing.JPanel();
|
366 |
jPanel.setLayout(null);
|
367 |
jPanel.setBounds(29, 136, 258, 84); |
368 |
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)); |
369 |
ButtonGroup jButtonGroup = new ButtonGroup(); |
370 |
jButtonGroup.add(getJRadioButton1()); |
371 |
jButtonGroup.add(getJRadioButton()); |
372 |
jPanel.add(getJRadioButton1(), null);
|
373 |
jPanel.add(getJRadioButton(), null);
|
374 |
jPanel.add(getJTextField(), null);
|
375 |
} |
376 |
return jPanel;
|
377 |
} |
378 |
|
379 |
/**
|
380 |
|
381 |
* This method initializes jTextField
|
382 |
|
383 |
*
|
384 |
|
385 |
* @return javax.swing.JTextField
|
386 |
|
387 |
*/
|
388 |
private javax.swing.JTextField getJTextField() {
|
389 |
if (jTextField == null) { |
390 |
jTextField = new javax.swing.JTextField();
|
391 |
jTextField.setBounds(26, 32, 76, 21); |
392 |
jTextField.setEnabled(false);
|
393 |
jTextField.setText("10");
|
394 |
} |
395 |
return jTextField;
|
396 |
} |
397 |
|
398 |
/**
|
399 |
|
400 |
* This method initializes jRadioButton
|
401 |
|
402 |
*
|
403 |
|
404 |
* @return javax.swing.JRadioButton
|
405 |
|
406 |
*/
|
407 |
private javax.swing.JRadioButton getJRadioButton() {
|
408 |
if (jRadioButton == null) { |
409 |
jRadioButton = new javax.swing.JRadioButton();
|
410 |
jRadioButton.setText(PluginServices.getText(this,"En_pixels")); |
411 |
jRadioButton.setBounds(145, 44, 100, 23); |
412 |
jRadioButton.setEnabled(false);
|
413 |
jRadioButton.setSelected(true);
|
414 |
} |
415 |
return jRadioButton;
|
416 |
} |
417 |
|
418 |
/**
|
419 |
|
420 |
* This method initializes jRadioButton1
|
421 |
|
422 |
*
|
423 |
|
424 |
* @return javax.swing.JRadioButton
|
425 |
|
426 |
*/
|
427 |
private javax.swing.JRadioButton getJRadioButton1() {
|
428 |
if (jRadioButton1 == null) { |
429 |
jRadioButton1 = new javax.swing.JRadioButton();
|
430 |
jRadioButton1.setText(PluginServices.getText(this,"En_metros")); |
431 |
jRadioButton1.setBounds(145, 16, 100, 23); |
432 |
jRadioButton1.setEnabled(false);
|
433 |
} |
434 |
return jRadioButton1;
|
435 |
} |
436 |
|
437 |
/**
|
438 |
|
439 |
* This method initializes fPreviewSymbol
|
440 |
|
441 |
*
|
442 |
|
443 |
* @return com.iver.cit.opensig.gui.Panels.FPreviewSymbol
|
444 |
|
445 |
*/
|
446 |
public FPreviewSymbol getFPreviewSymbol() {
|
447 |
if (fPreviewSymbol == null) { |
448 |
fPreviewSymbol = new FPreviewSymbol();
|
449 |
fPreviewSymbol.setBounds(311, 53, 134, 77); |
450 |
} |
451 |
return fPreviewSymbol;
|
452 |
} |
453 |
|
454 |
/**
|
455 |
|
456 |
* This method initializes jLabel3
|
457 |
|
458 |
*
|
459 |
|
460 |
* @return javax.swing.JLabel
|
461 |
|
462 |
*/
|
463 |
private javax.swing.JLabel getJLabel3() {
|
464 |
if (jLabel3 == null) { |
465 |
jLabel3 = new javax.swing.JLabel();
|
466 |
jLabel3.setBounds(312, 28, 100, 18); |
467 |
jLabel3.setText(PluginServices.getText(this,"Previsualizacion")); |
468 |
jLabel3.setVisible(false);
|
469 |
} |
470 |
return jLabel3;
|
471 |
} |
472 |
|
473 |
/**
|
474 |
|
475 |
* This method initializes jButton
|
476 |
|
477 |
*
|
478 |
|
479 |
* @return javax.swing.JButton
|
480 |
|
481 |
*/
|
482 |
private javax.swing.JButton getJButton() {
|
483 |
if (jButton == null) { |
484 |
jButton = new javax.swing.JButton();
|
485 |
jButton.setBounds(29, 77, 111, 29); |
486 |
jButton.setText(PluginServices.getText(this,"fuente")+"..."); |
487 |
jButton.addActionListener(new java.awt.event.ActionListener() {
|
488 |
|
489 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
490 |
//JButton origen = (JButton) e.getSource();
|
491 |
Font newFont;
|
492 |
|
493 |
newFont = FontChooser.showDialog("Choose Font", labelFont);
|
494 |
|
495 |
if (newFont == null) { |
496 |
return;
|
497 |
} |
498 |
|
499 |
labelFont = newFont; |
500 |
updateControls(); |
501 |
|
502 |
|
503 |
} |
504 |
}); |
505 |
|
506 |
} |
507 |
return jButton;
|
508 |
} |
509 |
|
510 |
/**
|
511 |
|
512 |
* This method initializes jLabel4
|
513 |
|
514 |
*
|
515 |
|
516 |
* @return javax.swing.JLabel
|
517 |
|
518 |
*/
|
519 |
private javax.swing.JLabel getJLabel4() {
|
520 |
if (jLabel4 == null) { |
521 |
jLabel4 = new javax.swing.JLabel();
|
522 |
jLabel4.setBounds(29, 109, 133, 23); |
523 |
jLabel4.setText(PluginServices.getText(this,"color_texto")); |
524 |
} |
525 |
return jLabel4;
|
526 |
} |
527 |
/* (non-Javadoc)
|
528 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
|
529 |
*/
|
530 |
public Legend getLegend() {
|
531 |
updateValuesFromControls(m_Renderer); |
532 |
return m_Renderer;
|
533 |
} |
534 |
|
535 |
} // @jve:visual-info decl-index=0 visual-constraint="10,10"
|