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 @ 42507
History | View | Annotate | Download (10.7 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 boolean isVisible(Object obj) { |
41 |
return obj instanceof FLayer; |
42 |
} |
43 |
|
44 |
@Override
|
45 |
public PropertiesPage create(Object obj) { |
46 |
return new GeneralLayerPropertiesPage((FLayer) obj); |
47 |
} |
48 |
|
49 |
} |
50 |
|
51 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
52 |
public GeneralLayerPropertiesPage(FLayer layer) {
|
53 |
this.initComponents();
|
54 |
this.setLayer(layer);
|
55 |
} |
56 |
|
57 |
private void initComponents() { |
58 |
this.rdoShowAlways.addActionListener(new ActionListener() { |
59 |
@Override
|
60 |
public void actionPerformed(ActionEvent ae) { |
61 |
txtIsGreaterThan.setEnabled(false);
|
62 |
txtIsLessThan.setEnabled(false);
|
63 |
} |
64 |
}); |
65 |
this.rdoShowConditionedToTheScale.addActionListener(new ActionListener() { |
66 |
@Override
|
67 |
public void actionPerformed(ActionEvent ae) { |
68 |
txtIsGreaterThan.setEnabled(true);
|
69 |
txtIsLessThan.setEnabled(true);
|
70 |
} |
71 |
}); |
72 |
this.translate();
|
73 |
} |
74 |
|
75 |
private void translate() { |
76 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
77 |
this.lblName.setText(i18nManager.getTranslation("Nombre") + ":"); |
78 |
this.lblRangeOfScales.setText(i18nManager.getTranslation("rango_de_escalas")); |
79 |
this.lblIsGreaterThan.setText(i18nManager.getTranslation("este_por_encima_de")); |
80 |
this.lblIsLessThan.setText(i18nManager.getTranslation("este_por_debajo_de_")); |
81 |
this.lblFullScale.setText(i18nManager.getTranslation("escala_maxima")); |
82 |
this.lblMinumunScale.setText(i18nManager.getTranslation("escala_minima")); |
83 |
this.lblProperties.setText(i18nManager.getTranslation("propiedades")); |
84 |
this.rdoShowAlways.setText(i18nManager.getTranslation("Mostrar_siempre")); |
85 |
this.rdoShowConditionedToTheScale.setText(i18nManager.getTranslation("No_mostrar_la_capa_cuando_la_escala") + ":"); |
86 |
} |
87 |
|
88 |
@Override
|
89 |
public String getTitle() { |
90 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
91 |
return i18nManager.getTranslation("General"); |
92 |
} |
93 |
|
94 |
@Override
|
95 |
public int getPriority() { |
96 |
return 1000; |
97 |
} |
98 |
|
99 |
@Override
|
100 |
public boolean whenAccept() { |
101 |
this.whenApply();
|
102 |
return true; |
103 |
} |
104 |
|
105 |
@Override
|
106 |
public boolean whenApply() { |
107 |
NumberFormat nf = NumberFormat.getInstance(); |
108 |
|
109 |
if (this.rdoShowConditionedToTheScale.isSelected()) { |
110 |
try {
|
111 |
String s = this.txtIsGreaterThan.getText(); |
112 |
if (StringUtils.isEmpty(s)) {
|
113 |
layer.setMinScale(-1);
|
114 |
} else {
|
115 |
layer.setMinScale((nf.parse(s)).doubleValue()); |
116 |
} |
117 |
} catch (ParseException ex) { |
118 |
this.txtIsGreaterThan.setText(""); |
119 |
} |
120 |
try {
|
121 |
String s = this.txtIsLessThan.getText(); |
122 |
if (StringUtils.isEmpty(s)) {
|
123 |
layer.setMaxScale(-1);
|
124 |
} else {
|
125 |
layer.setMaxScale((nf.parse(s)).doubleValue()); |
126 |
} |
127 |
} catch (ParseException ex) { |
128 |
this.txtIsLessThan.setText(""); |
129 |
} |
130 |
} else {
|
131 |
layer.setMinScale(-1);
|
132 |
layer.setMaxScale(-1);
|
133 |
} |
134 |
if (!this.txtName.getText().equals(layer.getName())) { |
135 |
layer.setName(this.txtName.getText());
|
136 |
} |
137 |
return true; |
138 |
} |
139 |
|
140 |
@Override
|
141 |
public boolean whenCancel() { |
142 |
// Do nothing
|
143 |
return true; |
144 |
} |
145 |
|
146 |
@Override
|
147 |
public JComponent asJComponent() { |
148 |
return this; |
149 |
} |
150 |
|
151 |
public void setLayer(FLayer layer) { |
152 |
NumberFormat nf = NumberFormat.getInstance(); |
153 |
|
154 |
this.layer = layer;
|
155 |
|
156 |
this.txtName.setText(this.layer.getName()); |
157 |
this.txtProperties.setText(this.getLayerInfo()); |
158 |
|
159 |
if (layer.getMinScale() != -1) { |
160 |
this.txtIsGreaterThan.setText(nf.format(layer.getMinScale()));
|
161 |
} |
162 |
if (layer.getMaxScale() != -1) { |
163 |
this.txtIsLessThan.setText(nf.format(layer.getMaxScale()));
|
164 |
} |
165 |
if (layer.getMinScale() == -1 && layer.getMaxScale() == -1) { |
166 |
this.rdoShowConditionedToTheScale.setSelected(false); |
167 |
} else {
|
168 |
this.rdoShowConditionedToTheScale.setSelected(true); |
169 |
} |
170 |
if (layer instanceof SingleLayer) { |
171 |
DataStore store = ((SingleLayer) layer).getDataStore(); |
172 |
this.txtSourceType.setText(store.getProviderName());
|
173 |
DataStoreParameters parameters = store.getParameters(); |
174 |
if (parameters instanceof FilesystemStoreParameters) { |
175 |
this.txtSource.setText(
|
176 |
((FilesystemStoreParameters) parameters).getFile().getAbsolutePath() |
177 |
); |
178 |
} else {
|
179 |
this.txtSource.setText(store.getFullName());
|
180 |
} |
181 |
} else {
|
182 |
this.txtSourceType.setText(""); |
183 |
this.txtSource.setText(""); |
184 |
} |
185 |
} |
186 |
|
187 |
private String getLayerInfo() { |
188 |
String info;
|
189 |
StringBuilder buff = new StringBuilder(); |
190 |
try {
|
191 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
192 |
info = layer.getInfoString(); |
193 |
if (info == null) { |
194 |
Envelope fullExtentViewPort = layer.getFullEnvelope(); |
195 |
IProjection mapProjection = layer.getMapContext().getProjection(); |
196 |
buff.append(i18nManager.getTranslation("Extent"));
|
197 |
buff.append(" ");
|
198 |
buff.append(mapProjection.getAbrev()); |
199 |
buff.append(" (")
|
200 |
.append(i18nManager.getTranslation("view_projection"))
|
201 |
.append("):\n\t");
|
202 |
buff.append(i18nManager.getTranslation("Superior"))
|
203 |
.append(":\t")
|
204 |
.append(fullExtentViewPort.getMaximum(1))
|
205 |
.append("\n\t");
|
206 |
buff.append(i18nManager.getTranslation("Inferior"))
|
207 |
.append(":\t")
|
208 |
.append(fullExtentViewPort.getMinimum(1))
|
209 |
.append("\n\t");
|
210 |
buff.append(i18nManager.getTranslation("Izquierda"))
|
211 |
.append(":\t")
|
212 |
.append(fullExtentViewPort.getMinimum(0))
|
213 |
.append("\n\t");
|
214 |
buff.append(i18nManager.getTranslation("Derecha"))
|
215 |
.append(":\t")
|
216 |
.append(fullExtentViewPort.getMaximum(0))
|
217 |
.append("\n");
|
218 |
|
219 |
if (layer.getProjection() != null |
220 |
&& !layer.getProjection().getAbrev().equals( |
221 |
mapProjection.getAbrev())) { |
222 |
IProjection nativeLayerProj = layer.getProjection(); |
223 |
ICoordTrans ct = mapProjection.getCT(nativeLayerProj); |
224 |
Envelope nativeLayerExtent = fullExtentViewPort.convert(ct); |
225 |
buff.append(i18nManager.getTranslation("Extent"))
|
226 |
.append(" ");
|
227 |
buff.append(nativeLayerProj.getAbrev()); |
228 |
buff.append(" (")
|
229 |
.append(i18nManager.getTranslation("layer_native_projection"))
|
230 |
.append("):\n\t");
|
231 |
buff.append(i18nManager.getTranslation("Superior"))
|
232 |
.append(":\t")
|
233 |
.append(nativeLayerExtent.getMaximum(1))
|
234 |
.append("\n\t");
|
235 |
buff.append(i18nManager.getTranslation("Inferior"))
|
236 |
.append(":\t")
|
237 |
.append(nativeLayerExtent.getMinimum(1))
|
238 |
.append("\n\t");
|
239 |
buff.append(i18nManager.getTranslation("Izquierda"))
|
240 |
.append(":\t")
|
241 |
.append(nativeLayerExtent.getMinimum(0))
|
242 |
.append("\n\t");
|
243 |
buff.append(i18nManager.getTranslation("Derecha"))
|
244 |
.append(":\t")
|
245 |
.append(nativeLayerExtent.getMaximum(0))
|
246 |
.append("\n");
|
247 |
} |
248 |
|
249 |
if (layer instanceof FLyrVect) { |
250 |
try {
|
251 |
GeometryType geomType = ((FLyrVect) layer).getTypeVectorLayer(); |
252 |
buff.append("\n")
|
253 |
.append(i18nManager.getTranslation("type"))
|
254 |
.append(": ")
|
255 |
.append(geomType.getName()) |
256 |
.append("\n");
|
257 |
} catch (Exception e) { |
258 |
logger.warn("Can't get gemetry type for layer '" + layer.getName() + "'.", e); |
259 |
buff.append("\n")
|
260 |
.append(i18nManager.getTranslation("type"))
|
261 |
.append(": ")
|
262 |
.append("unknow")
|
263 |
.append("\n");
|
264 |
} |
265 |
|
266 |
} |
267 |
info = buff.toString(); |
268 |
} |
269 |
} catch (Exception e) { |
270 |
logger.warn("Can't get layer information.", e);
|
271 |
info = buff.toString(); |
272 |
} |
273 |
return info;
|
274 |
} |
275 |
|
276 |
} |