svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / legend / gui / General.java @ 42506
History | View | Annotate | Download (17.8 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
9 |
* version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14 |
* details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License along with
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.app.project.documents.view.legend.gui; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.ComponentOrientation; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.FlowLayout; |
29 |
import java.awt.GridLayout; |
30 |
import java.awt.SystemColor; |
31 |
import java.awt.event.ActionEvent; |
32 |
import java.awt.event.ActionListener; |
33 |
import java.text.NumberFormat; |
34 |
import java.text.ParseException; |
35 |
|
36 |
import javax.swing.BorderFactory; |
37 |
import javax.swing.ButtonGroup; |
38 |
import javax.swing.JCheckBox; |
39 |
import javax.swing.JLabel; |
40 |
import javax.swing.JPanel; |
41 |
import javax.swing.JRadioButton; |
42 |
import javax.swing.JScrollPane; |
43 |
import javax.swing.JTextArea; |
44 |
import javax.swing.JTextField; |
45 |
import javax.swing.border.BevelBorder; |
46 |
import javax.swing.border.EtchedBorder; |
47 |
import javax.swing.border.TitledBorder; |
48 |
|
49 |
import org.cresques.cts.ICoordTrans; |
50 |
import org.cresques.cts.IProjection; |
51 |
import org.gvsig.andami.PluginServices; |
52 |
import org.gvsig.andami.messages.NotificationManager; |
53 |
import org.gvsig.fmap.dal.DataStoreParameters; |
54 |
import org.gvsig.fmap.dal.exception.DataException; |
55 |
import org.gvsig.fmap.dal.exception.ReadException; |
56 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
57 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
58 |
import org.gvsig.fmap.geom.primitive.Envelope; |
59 |
import org.gvsig.fmap.geom.type.GeometryType; |
60 |
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException; |
61 |
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException; |
62 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
63 |
import org.gvsig.fmap.mapcontext.layers.FLyrDefault; |
64 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
65 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
66 |
import org.gvsig.gui.beans.swing.JBlank; |
67 |
import org.gvsig.tools.locator.LocatorException; |
68 |
|
69 |
/**
|
70 |
* @deprecated This tab is outdated and not used. It has been replaced by "GeneralLayerPropertiesPage"
|
71 |
* @see GeneralLayerPropertiesPage
|
72 |
|
73 |
*/
|
74 |
public class General extends AbstractThemeManagerPage { |
75 |
|
76 |
private static final long serialVersionUID = 1L; |
77 |
private FLayer layer;
|
78 |
private NumberFormat nf = NumberFormat.getInstance(); |
79 |
private JPanel pnlLayerName = null; |
80 |
private GridBagLayoutPanel pnlScale = null; |
81 |
private JPanel pnlProperties = null; |
82 |
private JLabel lblLayerName = null; |
83 |
private JTextField txtLayerName = null; |
84 |
private JTextField txtMaxScale = null; |
85 |
private JTextArea propertiesTextArea = null; |
86 |
private JRadioButton rdBtnShowAlways = null; |
87 |
private JRadioButton rdBtnDoNotShow = null; |
88 |
private JTextField txtMinScale = null; |
89 |
private JScrollPane scrlProperties; |
90 |
|
91 |
/**
|
92 |
* This is the default constructor.
|
93 |
*/
|
94 |
public General() {
|
95 |
super();
|
96 |
initialize(); |
97 |
} |
98 |
|
99 |
/**
|
100 |
* This method initializes this
|
101 |
*
|
102 |
* @return void
|
103 |
*/
|
104 |
private void initialize() { |
105 |
this.setLayout(new BorderLayout()); |
106 |
GridBagLayoutPanel aux = new GridBagLayoutPanel();
|
107 |
aux.addComponent(getPnlLayerName()); |
108 |
aux.addComponent(new JBlank(10, 10)); |
109 |
aux.addComponent("", getPnlScale());
|
110 |
JPanel aux2 = new JPanel(new GridLayout(1, 2)); |
111 |
aux2.add(getPnlProperties()); |
112 |
aux.addComponent(aux2); |
113 |
|
114 |
aux.setPreferredSize(getPreferredSize()); |
115 |
this.add(aux, BorderLayout.CENTER); |
116 |
this.add(new JBlank(5, 10), BorderLayout.WEST); |
117 |
this.add(new JBlank(5, 10), BorderLayout.EAST); |
118 |
|
119 |
} |
120 |
|
121 |
@Override
|
122 |
public int getPriority() { |
123 |
return 1000; |
124 |
} |
125 |
|
126 |
/**
|
127 |
* Sets the necessary properties in the panel. This properties are extracted
|
128 |
* from the layer. With this properties fills the TextFields, ComboBoxes and
|
129 |
* the rest of GUI components.
|
130 |
*
|
131 |
* @param FLayer layer,
|
132 |
*/
|
133 |
public void setModel(FLayer layer) { |
134 |
this.layer = layer;
|
135 |
|
136 |
if (layer.getMinScale() != -1) { |
137 |
getTxtMaxScale().setText(nf.format(layer.getMinScale())); |
138 |
} |
139 |
if (layer.getMaxScale() != -1) { |
140 |
getTxtMinScale().setText(nf.format(layer.getMaxScale())); |
141 |
} |
142 |
if (layer.getMinScale() == -1 && layer.getMaxScale() == -1) { |
143 |
getRdBtnShowAlways().setSelected(true);
|
144 |
txtMaxScale.setEnabled(false);
|
145 |
txtMinScale.setEnabled(false);
|
146 |
|
147 |
} else {
|
148 |
getRdBtnDoNotShowWhen().setSelected(true);
|
149 |
txtMaxScale.setEnabled(true);
|
150 |
txtMinScale.setEnabled(true);
|
151 |
} |
152 |
txtLayerName.setText(layer.getName()); |
153 |
showLayerInfo(); |
154 |
|
155 |
} |
156 |
|
157 |
/**
|
158 |
* This method initializes jPanel
|
159 |
*
|
160 |
* @return javax.swing.JPanel
|
161 |
*/
|
162 |
private JPanel getPnlLayerName() { |
163 |
if (pnlLayerName == null) { |
164 |
lblLayerName = new JLabel(); |
165 |
pnlLayerName = new JPanel(); |
166 |
lblLayerName.setText(PluginServices.getText(this, "Nombre") + ":"); |
167 |
lblLayerName.setComponentOrientation(ComponentOrientation.UNKNOWN);
|
168 |
pnlLayerName.setComponentOrientation(ComponentOrientation.UNKNOWN);
|
169 |
pnlLayerName.add(lblLayerName, null);
|
170 |
pnlLayerName.add(getTxtLayerName(), null);
|
171 |
} |
172 |
return pnlLayerName;
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* This method initializes jPanel1
|
177 |
*
|
178 |
* @return javax.swing.JPanel
|
179 |
*/
|
180 |
private GridBagLayoutPanel getPnlScale() {
|
181 |
if (pnlScale == null) { |
182 |
pnlScale = new GridBagLayoutPanel();
|
183 |
pnlScale.setBorder(BorderFactory.createTitledBorder(
|
184 |
BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), |
185 |
PluginServices.getText(this, "rango_de_escalas"), |
186 |
TitledBorder.DEFAULT_JUSTIFICATION,
|
187 |
TitledBorder.DEFAULT_POSITION, null, null) |
188 |
); |
189 |
ButtonGroup buttonGroup = new ButtonGroup(); |
190 |
buttonGroup.add(getRdBtnShowAlways()); |
191 |
buttonGroup.add(getRdBtnDoNotShowWhen()); |
192 |
pnlScale.addComponent(getRdBtnShowAlways()); |
193 |
pnlScale.addComponent(getRdBtnDoNotShowWhen()); |
194 |
JPanel aux;
|
195 |
|
196 |
aux = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
197 |
aux.add(getTxtMaxScale()); |
198 |
aux.add(new JLabel("(" + PluginServices.getText(this, "escala_maxima") + ")")); |
199 |
|
200 |
GridBagLayoutPanel aux2; |
201 |
aux2 = new GridBagLayoutPanel();
|
202 |
aux2.addComponent(PluginServices.getText( |
203 |
this, "este_por_encima_de") + " 1:", |
204 |
aux); |
205 |
aux = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
206 |
aux.add(getTxtMinScale()); |
207 |
aux.add(new JLabel("(" + PluginServices.getText(this, "escala_minima") + ")")); |
208 |
|
209 |
aux2.addComponent(PluginServices.getText( |
210 |
this, "este_por_debajo_de_") + " 1:", |
211 |
aux); |
212 |
|
213 |
pnlScale.addComponent(new JBlank(20, 1), aux2); |
214 |
|
215 |
pnlScale.addComponent(new JBlank(20, 1), aux2); |
216 |
|
217 |
} |
218 |
return pnlScale;
|
219 |
} |
220 |
|
221 |
/**
|
222 |
* This method initializes jPanel2, this contains the ScrollPane with the
|
223 |
* properies.
|
224 |
*
|
225 |
* @return javax.swing.JPanel
|
226 |
*/
|
227 |
private JPanel getPnlProperties() { |
228 |
if (pnlProperties == null) { |
229 |
pnlProperties = new JPanel(); |
230 |
pnlProperties.setBorder(BorderFactory.createTitledBorder(
|
231 |
BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), |
232 |
PluginServices.getText(this, "propiedades"), |
233 |
TitledBorder.DEFAULT_JUSTIFICATION,
|
234 |
TitledBorder.DEFAULT_POSITION, null, null) |
235 |
); |
236 |
pnlProperties.add(getScrlProperties(), null);
|
237 |
} |
238 |
return pnlProperties;
|
239 |
} |
240 |
|
241 |
/**
|
242 |
* This method initializes jTextField
|
243 |
*
|
244 |
* @return javax.swing.JTextField
|
245 |
*/
|
246 |
private JTextField getTxtLayerName() { |
247 |
if (txtLayerName == null) { |
248 |
txtLayerName = new JTextField(25); |
249 |
txtLayerName.setEditable(false);
|
250 |
} |
251 |
return txtLayerName;
|
252 |
} |
253 |
|
254 |
/**
|
255 |
* This method initializes TxtMaxScale
|
256 |
*
|
257 |
* @return jTextField1
|
258 |
*/
|
259 |
private JTextField getTxtMaxScale() { |
260 |
if (txtMaxScale == null) { |
261 |
txtMaxScale = new JTextField(15); |
262 |
txtMaxScale.setEnabled(false);
|
263 |
} |
264 |
return txtMaxScale;
|
265 |
} |
266 |
|
267 |
/**
|
268 |
* This method initilizes TxtArea, in this TextArea sets the text with the
|
269 |
* properties of the layer
|
270 |
*
|
271 |
* @return
|
272 |
*/
|
273 |
private JTextArea getPropertiesTextArea() { |
274 |
if (propertiesTextArea == null) { |
275 |
propertiesTextArea = new JTextArea(); |
276 |
propertiesTextArea.setEditable(false);
|
277 |
propertiesTextArea.setBackground(SystemColor.control);
|
278 |
|
279 |
} |
280 |
return propertiesTextArea;
|
281 |
} |
282 |
|
283 |
/**
|
284 |
* This method initializes jScrollPane
|
285 |
*
|
286 |
* @return javax.swing.JScrollPane
|
287 |
*/
|
288 |
private JScrollPane getScrlProperties() { |
289 |
if (scrlProperties == null) { |
290 |
scrlProperties = new JScrollPane(); |
291 |
scrlProperties.setViewportView(getPropertiesTextArea()); |
292 |
scrlProperties.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); |
293 |
scrlProperties.setPreferredSize(new Dimension(350, 180)); |
294 |
} |
295 |
return scrlProperties;
|
296 |
} |
297 |
|
298 |
/**
|
299 |
* This method initializes jRadioButton
|
300 |
*
|
301 |
* @return javax.swing.JRadioButton
|
302 |
*/
|
303 |
private JRadioButton getRdBtnShowAlways() { |
304 |
if (rdBtnShowAlways == null) { |
305 |
rdBtnShowAlways = new JRadioButton(); |
306 |
rdBtnShowAlways.setText(PluginServices.getText(this, "Mostrar_siempre")); |
307 |
rdBtnShowAlways.setSelected(true);
|
308 |
rdBtnShowAlways.addActionListener(new ActionListener() { |
309 |
public void actionPerformed(ActionEvent e) { |
310 |
txtMaxScale.setEnabled(false);
|
311 |
txtMinScale.setEnabled(false);
|
312 |
} |
313 |
}); |
314 |
} |
315 |
return rdBtnShowAlways;
|
316 |
} |
317 |
|
318 |
/**
|
319 |
* This method initializes jRadioButton1
|
320 |
*
|
321 |
* @return javax.swing.JRadioButton
|
322 |
*/
|
323 |
private JRadioButton getRdBtnDoNotShowWhen() { |
324 |
if (rdBtnDoNotShow == null) { |
325 |
rdBtnDoNotShow = new JRadioButton(); |
326 |
rdBtnDoNotShow.setText(PluginServices.getText(this, "No_mostrar_la_capa_cuando_la_escala")); |
327 |
rdBtnDoNotShow.addActionListener(new ActionListener() { |
328 |
public void actionPerformed(ActionEvent e) { |
329 |
txtMaxScale.setEnabled(true);
|
330 |
txtMinScale.setEnabled(true);
|
331 |
} |
332 |
}); |
333 |
} |
334 |
return rdBtnDoNotShow;
|
335 |
} |
336 |
|
337 |
/**
|
338 |
* This method initializes jTextField2
|
339 |
*
|
340 |
* @return javax.swing.JTextField
|
341 |
*/
|
342 |
private JTextField getTxtMinScale() { |
343 |
if (txtMinScale == null) { |
344 |
txtMinScale = new JTextField(15); |
345 |
txtMinScale.setEnabled(false);
|
346 |
} |
347 |
return txtMinScale;
|
348 |
} |
349 |
|
350 |
private String getLayerName() { |
351 |
return txtLayerName.getText().toString();
|
352 |
} |
353 |
|
354 |
/**
|
355 |
* Add the information of the layer to the textArea
|
356 |
*/
|
357 |
private void showLayerInfo() { |
358 |
try {
|
359 |
String info = ((FLyrDefault) layer).getInfoString();
|
360 |
if (info == null) { |
361 |
StringBuffer buff = new StringBuffer(); |
362 |
Envelope fullExtentViewPort = layer.getFullEnvelope(); |
363 |
IProjection viewPortProj = layer.getMapContext().getProjection(); |
364 |
buff.append(PluginServices.getText(this, "Extent")); |
365 |
buff.append(" ");
|
366 |
buff.append(viewPortProj.getAbrev()); |
367 |
buff.append(" (" + PluginServices.getText(this, "view_projection") + "):\n\t"); |
368 |
buff.append(PluginServices.getText(this, "Superior") + ":\t" + fullExtentViewPort.getMaximum(1) + "\n\t"); |
369 |
buff.append(PluginServices.getText(this, "Inferior") + ":\t" + fullExtentViewPort.getMinimum(1) + "\n\t"); |
370 |
buff.append(PluginServices.getText(this, "Izquierda") + ":\t" + fullExtentViewPort.getMinimum(0) + "\n\t"); |
371 |
buff.append(PluginServices.getText(this, "Derecha") + ":\t" + fullExtentViewPort.getMaximum(0) + "\n"); |
372 |
// show layer native projection
|
373 |
if (layer.getProjection() != null |
374 |
&& !layer.getProjection().getAbrev().equals( |
375 |
viewPortProj.getAbrev())) { |
376 |
IProjection nativeLayerProj = layer.getProjection(); |
377 |
ICoordTrans ct = viewPortProj.getCT(nativeLayerProj); |
378 |
Envelope nativeLayerExtent = fullExtentViewPort.convert(ct); |
379 |
buff.append(PluginServices.getText(this, "Extent") + " "); |
380 |
buff.append(nativeLayerProj.getAbrev()); |
381 |
buff.append(" (" + PluginServices.getText(this, "layer_native_projection") + "):\n\t"); |
382 |
buff.append(PluginServices.getText(this, "Superior") |
383 |
+ ":\t" + nativeLayerExtent.getMaximum(1) + "\n\t"); |
384 |
buff.append(PluginServices.getText(this, "Inferior") |
385 |
+ ":\t" + nativeLayerExtent.getMinimum(1) + "\n\t"); |
386 |
buff.append(PluginServices.getText(this, "Izquierda") |
387 |
+ ":\t" + nativeLayerExtent.getMinimum(0) + "\n\t"); |
388 |
buff.append(PluginServices.getText(this, "Derecha") + ":\t" |
389 |
+ nativeLayerExtent.getMaximum(0) + "\n"); |
390 |
|
391 |
} |
392 |
if (layer instanceof FLyrVect) { |
393 |
FeatureStore fStore = ((FLyrVect) layer).getFeatureStore(); |
394 |
|
395 |
buff.append(PluginServices.getText(this, "Origen_de_datos") + ": "); |
396 |
buff.append(fStore.getName()); |
397 |
info = buff.toString(); |
398 |
|
399 |
DataStoreParameters parameters = fStore.getParameters(); |
400 |
if (parameters instanceof FilesystemStoreParameters) { |
401 |
info = info + "\n"
|
402 |
+ PluginServices.getText(this, "fichero") |
403 |
+ ": "
|
404 |
+ ((FilesystemStoreParameters) parameters) |
405 |
.getFile(); |
406 |
} else {
|
407 |
info = info + "\n" + fStore.getName() + "\n"; |
408 |
} |
409 |
String sGeomType = "Unknow"; |
410 |
|
411 |
try {
|
412 |
GeometryType geomType = ((FLyrVect) layer).getTypeVectorLayer(); |
413 |
sGeomType = geomType.getName(); |
414 |
} catch (LocatorException e) {
|
415 |
NotificationManager.addError(e); |
416 |
} catch (GeometryTypeNotSupportedException e) {
|
417 |
NotificationManager.showMessageWarning("Not supported GeometryType", e);
|
418 |
} catch (GeometryTypeNotValidException e) {
|
419 |
NotificationManager.showMessageWarning("Not valid GeometryType", e);
|
420 |
} |
421 |
|
422 |
info += "\n" + PluginServices.getText(this, "type") + ": " + sGeomType + "\n"; |
423 |
|
424 |
} else {
|
425 |
info = buff.toString(); |
426 |
info = info + PluginServices.getText(this, "Origen_de_datos") + ": " + layer.getName(); |
427 |
} |
428 |
|
429 |
} |
430 |
getPropertiesTextArea().setText(info); |
431 |
|
432 |
} catch (ReadException e) {
|
433 |
NotificationManager.addError(e.getMessage(), e); |
434 |
} catch (DataException e) {
|
435 |
NotificationManager.addError(e.getMessage(), e); |
436 |
} |
437 |
|
438 |
} |
439 |
|
440 |
/**
|
441 |
* Returns true or false if the scale is activa
|
442 |
*/
|
443 |
private boolean isScaleActive() { |
444 |
return getRdBtnDoNotShowWhen().isSelected();
|
445 |
} |
446 |
|
447 |
public void acceptAction() { |
448 |
|
449 |
} |
450 |
|
451 |
public void cancelAction() { |
452 |
// does nothing
|
453 |
} |
454 |
|
455 |
/**
|
456 |
* When we press the apply button, sets the new properties of the layer thar
|
457 |
* the user modified using the UI components
|
458 |
*/
|
459 |
public void applyAction() { |
460 |
if (isScaleActive()) {
|
461 |
try {
|
462 |
layer.setMinScale((nf.parse(getTxtMaxScale().getText())).doubleValue()); |
463 |
} catch (ParseException ex) { |
464 |
if (getTxtMaxScale().getText().compareTo("") == 0) { |
465 |
layer.setMinScale(-1);
|
466 |
} else {
|
467 |
System.err.print(ex.getLocalizedMessage());
|
468 |
} |
469 |
} |
470 |
|
471 |
try {
|
472 |
layer.setMaxScale((nf.parse(getTxtMinScale().getText())).doubleValue()); |
473 |
} catch (ParseException ex) { |
474 |
if (getTxtMinScale().getText().compareTo("") == 0) { |
475 |
layer.setMaxScale(-1);
|
476 |
} else {
|
477 |
System.err.print(ex.getLocalizedMessage());
|
478 |
} |
479 |
} |
480 |
|
481 |
} else {
|
482 |
layer.setMinScale(-1);
|
483 |
layer.setMaxScale(-1);
|
484 |
} |
485 |
|
486 |
if (!getLayerName().equals(layer.getName())) {
|
487 |
layer.setName(getLayerName()); |
488 |
} |
489 |
|
490 |
} |
491 |
|
492 |
/*
|
493 |
* (non-Javadoc)
|
494 |
* @see java.awt.Component#getName()
|
495 |
*/
|
496 |
public String getName() { |
497 |
return PluginServices.getText(this, "General"); |
498 |
} |
499 |
} |