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 / GeneralLayerPropertiesPage.java @ 43557
History | View | Annotate | Download (10.3 KB)
1 |
package org.gvsig.app.project.documents.view.legend.gui; |
---|---|
2 |
|
3 |
import java.awt.event.ActionEvent; |
4 |
import java.awt.event.ActionListener; |
5 |
import java.text.NumberFormat; |
6 |
import java.text.ParseException; |
7 |
import javax.swing.JComponent; |
8 |
import org.apache.commons.lang3.StringUtils; |
9 |
import org.cresques.cts.ICoordTrans; |
10 |
import org.cresques.cts.IProjection; |
11 |
import org.gvsig.app.project.documents.view.ViewDocument; |
12 |
import org.gvsig.fmap.dal.DataStore; |
13 |
import org.gvsig.fmap.dal.DataStoreParameters; |
14 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
15 |
import org.gvsig.fmap.geom.primitive.Envelope; |
16 |
import org.gvsig.fmap.geom.type.GeometryType; |
17 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
18 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
19 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
20 |
import org.gvsig.propertypage.PropertiesPage; |
21 |
import org.gvsig.propertypage.PropertiesPageFactory; |
22 |
import org.gvsig.tools.ToolsLocator; |
23 |
import org.gvsig.tools.i18n.I18nManager; |
24 |
import org.slf4j.Logger; |
25 |
import org.slf4j.LoggerFactory; |
26 |
|
27 |
public class GeneralLayerPropertiesPage extends GeneralLayerPropertiesPageView implements PropertiesPage { |
28 |
|
29 |
private static final Logger logger = LoggerFactory.getLogger(GeneralLayerPropertiesPage.class); |
30 |
private FLayer layer = null; |
31 |
|
32 |
public static class GeneralLayerPropertiesPageFactory implements PropertiesPageFactory { |
33 |
|
34 |
@Override
|
35 |
public String getGroupID() { |
36 |
return ViewDocument.LAYER_PROPERTIES_PAGE_GROUP;
|
37 |
} |
38 |
|
39 |
@Override
|
40 |
public String getName() { |
41 |
return "General"; |
42 |
} |
43 |
|
44 |
@Override
|
45 |
public boolean isVisible(Object obj) { |
46 |
return obj instanceof FLayer; |
47 |
} |
48 |
|
49 |
@Override
|
50 |
public PropertiesPage create(Object obj) { |
51 |
return new GeneralLayerPropertiesPage((FLayer) obj); |
52 |
} |
53 |
|
54 |
} |
55 |
|
56 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
57 |
public GeneralLayerPropertiesPage(FLayer layer) {
|
58 |
this.initComponents();
|
59 |
this.setLayer(layer);
|
60 |
} |
61 |
|
62 |
private void initComponents() { |
63 |
this.rdoShowAlways.addActionListener(new ActionListener() { |
64 |
@Override
|
65 |
public void actionPerformed(ActionEvent ae) { |
66 |
txtIsGreaterThan.setEnabled(false);
|
67 |
txtIsLessThan.setEnabled(false);
|
68 |
} |
69 |
}); |
70 |
this.rdoShowConditionedToTheScale.addActionListener(new ActionListener() { |
71 |
@Override
|
72 |
public void actionPerformed(ActionEvent ae) { |
73 |
txtIsGreaterThan.setEnabled(true);
|
74 |
txtIsLessThan.setEnabled(true);
|
75 |
} |
76 |
}); |
77 |
this.translate();
|
78 |
} |
79 |
|
80 |
private void translate() { |
81 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
82 |
this.lblName.setText(i18nManager.getTranslation("Nombre") + ":"); |
83 |
this.lblRangeOfScales.setText(i18nManager.getTranslation("rango_de_escalas")); |
84 |
this.lblIsGreaterThan.setText(i18nManager.getTranslation("este_por_encima_de")); |
85 |
this.lblIsLessThan.setText(i18nManager.getTranslation("este_por_debajo_de_")); |
86 |
this.lblFullScale.setText(i18nManager.getTranslation("escala_maxima")); |
87 |
this.lblMinumunScale.setText(i18nManager.getTranslation("escala_minima")); |
88 |
this.lblProperties.setText(i18nManager.getTranslation("propiedades")); |
89 |
this.rdoShowAlways.setText(i18nManager.getTranslation("Mostrar_siempre")); |
90 |
this.rdoShowConditionedToTheScale.setText(i18nManager.getTranslation("No_mostrar_la_capa_cuando_la_escala") + ":"); |
91 |
|
92 |
} |
93 |
|
94 |
@Override
|
95 |
public String getTitle() { |
96 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
97 |
return i18nManager.getTranslation("General"); |
98 |
} |
99 |
|
100 |
@Override
|
101 |
public int getPriority() { |
102 |
return 1000; |
103 |
} |
104 |
|
105 |
@Override
|
106 |
public boolean whenAccept() { |
107 |
this.whenApply();
|
108 |
return true; |
109 |
} |
110 |
|
111 |
@Override
|
112 |
public boolean whenApply() { |
113 |
NumberFormat nf = NumberFormat.getInstance(); |
114 |
|
115 |
if (this.rdoShowConditionedToTheScale.isSelected()) { |
116 |
try {
|
117 |
String s = this.txtIsGreaterThan.getText(); |
118 |
if (StringUtils.isEmpty(s)) {
|
119 |
layer.setMinScale(-1);
|
120 |
} else {
|
121 |
layer.setMinScale((nf.parse(s)).doubleValue()); |
122 |
} |
123 |
} catch (ParseException ex) { |
124 |
this.txtIsGreaterThan.setText(""); |
125 |
} |
126 |
try {
|
127 |
String s = this.txtIsLessThan.getText(); |
128 |
if (StringUtils.isEmpty(s)) {
|
129 |
layer.setMaxScale(-1);
|
130 |
} else {
|
131 |
layer.setMaxScale((nf.parse(s)).doubleValue()); |
132 |
} |
133 |
} catch (ParseException ex) { |
134 |
this.txtIsLessThan.setText(""); |
135 |
} |
136 |
} else {
|
137 |
layer.setMinScale(-1);
|
138 |
layer.setMaxScale(-1);
|
139 |
} |
140 |
if (!this.txtName.getText().equals(layer.getName())) { |
141 |
layer.setName(this.txtName.getText());
|
142 |
} |
143 |
return true; |
144 |
} |
145 |
|
146 |
@Override
|
147 |
public boolean whenCancel() { |
148 |
// Do nothing
|
149 |
return true; |
150 |
} |
151 |
|
152 |
@Override
|
153 |
public JComponent asJComponent() { |
154 |
return this; |
155 |
} |
156 |
|
157 |
public void setLayer(FLayer layer) { |
158 |
NumberFormat nf = NumberFormat.getInstance(); |
159 |
|
160 |
this.layer = layer;
|
161 |
|
162 |
this.txtName.setText(this.layer.getName()); |
163 |
|
164 |
String info = this.getLayerInfo(); |
165 |
if( info.startsWith("<html>") ) { |
166 |
this.txtProperties.setContentType("text/html"); |
167 |
} |
168 |
this.txtProperties.setText(info);
|
169 |
this.txtProperties.setCaretPosition(0); |
170 |
|
171 |
if (layer.getMinScale() != -1) { |
172 |
this.txtIsGreaterThan.setText(nf.format(layer.getMinScale()));
|
173 |
} |
174 |
if (layer.getMaxScale() != -1) { |
175 |
this.txtIsLessThan.setText(nf.format(layer.getMaxScale()));
|
176 |
} |
177 |
if (layer.getMinScale() == -1 && layer.getMaxScale() == -1) { |
178 |
this.rdoShowConditionedToTheScale.setSelected(false); |
179 |
} else {
|
180 |
this.rdoShowConditionedToTheScale.setSelected(true); |
181 |
} |
182 |
} |
183 |
|
184 |
private String getLayerInfo() { |
185 |
String info;
|
186 |
StringBuilder buff = new StringBuilder(); |
187 |
try {
|
188 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
189 |
info = layer.getInfoString(); |
190 |
if (info == null) { |
191 |
Envelope fullExtentViewPort = layer.getFullEnvelope(); |
192 |
IProjection mapProjection = layer.getMapContext().getProjection(); |
193 |
buff.append(i18nManager.getTranslation("Extent"));
|
194 |
buff.append(" ");
|
195 |
buff.append(mapProjection.getAbrev()); |
196 |
buff.append(" (")
|
197 |
.append(i18nManager.getTranslation("view_projection"))
|
198 |
.append("):\n\t");
|
199 |
buff.append(i18nManager.getTranslation("Superior"))
|
200 |
.append(":\t")
|
201 |
.append(fullExtentViewPort.getMaximum(1))
|
202 |
.append("\n\t");
|
203 |
buff.append(i18nManager.getTranslation("Inferior"))
|
204 |
.append(":\t")
|
205 |
.append(fullExtentViewPort.getMinimum(1))
|
206 |
.append("\n\t");
|
207 |
buff.append(i18nManager.getTranslation("Izquierda"))
|
208 |
.append(":\t")
|
209 |
.append(fullExtentViewPort.getMinimum(0))
|
210 |
.append("\n\t");
|
211 |
buff.append(i18nManager.getTranslation("Derecha"))
|
212 |
.append(":\t")
|
213 |
.append(fullExtentViewPort.getMaximum(0))
|
214 |
.append("\n");
|
215 |
|
216 |
if (layer.getProjection() != null |
217 |
&& !layer.getProjection().getAbrev().equals( |
218 |
mapProjection.getAbrev())) { |
219 |
IProjection nativeLayerProj = layer.getProjection(); |
220 |
ICoordTrans ct = mapProjection.getCT(nativeLayerProj); |
221 |
Envelope nativeLayerExtent = fullExtentViewPort.convert(ct); |
222 |
buff.append(i18nManager.getTranslation("Extent"))
|
223 |
.append(" ");
|
224 |
buff.append(nativeLayerProj.getAbrev()); |
225 |
buff.append(" (")
|
226 |
.append(i18nManager.getTranslation("layer_native_projection"))
|
227 |
.append("):\n\t");
|
228 |
buff.append(i18nManager.getTranslation("Superior"))
|
229 |
.append(":\t")
|
230 |
.append(nativeLayerExtent.getMaximum(1))
|
231 |
.append("\n\t");
|
232 |
buff.append(i18nManager.getTranslation("Inferior"))
|
233 |
.append(":\t")
|
234 |
.append(nativeLayerExtent.getMinimum(1))
|
235 |
.append("\n\t");
|
236 |
buff.append(i18nManager.getTranslation("Izquierda"))
|
237 |
.append(":\t")
|
238 |
.append(nativeLayerExtent.getMinimum(0))
|
239 |
.append("\n\t");
|
240 |
buff.append(i18nManager.getTranslation("Derecha"))
|
241 |
.append(":\t")
|
242 |
.append(nativeLayerExtent.getMaximum(0))
|
243 |
.append("\n");
|
244 |
} |
245 |
|
246 |
if (layer instanceof FLyrVect) { |
247 |
try {
|
248 |
GeometryType geomType = ((FLyrVect) layer).getTypeVectorLayer(); |
249 |
buff.append("\n")
|
250 |
.append(i18nManager.getTranslation("type"))
|
251 |
.append(": ")
|
252 |
.append(geomType.getFullName()) |
253 |
.append("\n");
|
254 |
} catch (Exception e) { |
255 |
logger.warn("Can't get gemetry type for layer '" + layer.getName() + "'.", e); |
256 |
buff.append("\n")
|
257 |
.append(i18nManager.getTranslation("type"))
|
258 |
.append(": ")
|
259 |
.append("unknow")
|
260 |
.append("\n");
|
261 |
} |
262 |
|
263 |
} |
264 |
info = buff.toString(); |
265 |
} |
266 |
} catch (Exception e) { |
267 |
logger.warn("Can't get layer information.", e);
|
268 |
info = buff.toString(); |
269 |
} |
270 |
return info;
|
271 |
} |
272 |
|
273 |
} |