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 @ 43196
History | View | Annotate | Download (10.2 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 |
|
89 |
@Override
|
90 |
public String getTitle() { |
91 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
92 |
return i18nManager.getTranslation("General"); |
93 |
} |
94 |
|
95 |
@Override
|
96 |
public int getPriority() { |
97 |
return 1000; |
98 |
} |
99 |
|
100 |
@Override
|
101 |
public boolean whenAccept() { |
102 |
this.whenApply();
|
103 |
return true; |
104 |
} |
105 |
|
106 |
@Override
|
107 |
public boolean whenApply() { |
108 |
NumberFormat nf = NumberFormat.getInstance(); |
109 |
|
110 |
if (this.rdoShowConditionedToTheScale.isSelected()) { |
111 |
try {
|
112 |
String s = this.txtIsGreaterThan.getText(); |
113 |
if (StringUtils.isEmpty(s)) {
|
114 |
layer.setMinScale(-1);
|
115 |
} else {
|
116 |
layer.setMinScale((nf.parse(s)).doubleValue()); |
117 |
} |
118 |
} catch (ParseException ex) { |
119 |
this.txtIsGreaterThan.setText(""); |
120 |
} |
121 |
try {
|
122 |
String s = this.txtIsLessThan.getText(); |
123 |
if (StringUtils.isEmpty(s)) {
|
124 |
layer.setMaxScale(-1);
|
125 |
} else {
|
126 |
layer.setMaxScale((nf.parse(s)).doubleValue()); |
127 |
} |
128 |
} catch (ParseException ex) { |
129 |
this.txtIsLessThan.setText(""); |
130 |
} |
131 |
} else {
|
132 |
layer.setMinScale(-1);
|
133 |
layer.setMaxScale(-1);
|
134 |
} |
135 |
if (!this.txtName.getText().equals(layer.getName())) { |
136 |
layer.setName(this.txtName.getText());
|
137 |
} |
138 |
return true; |
139 |
} |
140 |
|
141 |
@Override
|
142 |
public boolean whenCancel() { |
143 |
// Do nothing
|
144 |
return true; |
145 |
} |
146 |
|
147 |
@Override
|
148 |
public JComponent asJComponent() { |
149 |
return this; |
150 |
} |
151 |
|
152 |
public void setLayer(FLayer layer) { |
153 |
NumberFormat nf = NumberFormat.getInstance(); |
154 |
|
155 |
this.layer = layer;
|
156 |
|
157 |
this.txtName.setText(this.layer.getName()); |
158 |
|
159 |
String info = this.getLayerInfo(); |
160 |
if( info.startsWith("<html>") ) { |
161 |
this.txtProperties.setContentType("text/html"); |
162 |
} |
163 |
this.txtProperties.setText(info);
|
164 |
this.txtProperties.setCaretPosition(0); |
165 |
|
166 |
if (layer.getMinScale() != -1) { |
167 |
this.txtIsGreaterThan.setText(nf.format(layer.getMinScale()));
|
168 |
} |
169 |
if (layer.getMaxScale() != -1) { |
170 |
this.txtIsLessThan.setText(nf.format(layer.getMaxScale()));
|
171 |
} |
172 |
if (layer.getMinScale() == -1 && layer.getMaxScale() == -1) { |
173 |
this.rdoShowConditionedToTheScale.setSelected(false); |
174 |
} else {
|
175 |
this.rdoShowConditionedToTheScale.setSelected(true); |
176 |
} |
177 |
} |
178 |
|
179 |
private String getLayerInfo() { |
180 |
String info;
|
181 |
StringBuilder buff = new StringBuilder(); |
182 |
try {
|
183 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
184 |
info = layer.getInfoString(); |
185 |
if (info == null) { |
186 |
Envelope fullExtentViewPort = layer.getFullEnvelope(); |
187 |
IProjection mapProjection = layer.getMapContext().getProjection(); |
188 |
buff.append(i18nManager.getTranslation("Extent"));
|
189 |
buff.append(" ");
|
190 |
buff.append(mapProjection.getAbrev()); |
191 |
buff.append(" (")
|
192 |
.append(i18nManager.getTranslation("view_projection"))
|
193 |
.append("):\n\t");
|
194 |
buff.append(i18nManager.getTranslation("Superior"))
|
195 |
.append(":\t")
|
196 |
.append(fullExtentViewPort.getMaximum(1))
|
197 |
.append("\n\t");
|
198 |
buff.append(i18nManager.getTranslation("Inferior"))
|
199 |
.append(":\t")
|
200 |
.append(fullExtentViewPort.getMinimum(1))
|
201 |
.append("\n\t");
|
202 |
buff.append(i18nManager.getTranslation("Izquierda"))
|
203 |
.append(":\t")
|
204 |
.append(fullExtentViewPort.getMinimum(0))
|
205 |
.append("\n\t");
|
206 |
buff.append(i18nManager.getTranslation("Derecha"))
|
207 |
.append(":\t")
|
208 |
.append(fullExtentViewPort.getMaximum(0))
|
209 |
.append("\n");
|
210 |
|
211 |
if (layer.getProjection() != null |
212 |
&& !layer.getProjection().getAbrev().equals( |
213 |
mapProjection.getAbrev())) { |
214 |
IProjection nativeLayerProj = layer.getProjection(); |
215 |
ICoordTrans ct = mapProjection.getCT(nativeLayerProj); |
216 |
Envelope nativeLayerExtent = fullExtentViewPort.convert(ct); |
217 |
buff.append(i18nManager.getTranslation("Extent"))
|
218 |
.append(" ");
|
219 |
buff.append(nativeLayerProj.getAbrev()); |
220 |
buff.append(" (")
|
221 |
.append(i18nManager.getTranslation("layer_native_projection"))
|
222 |
.append("):\n\t");
|
223 |
buff.append(i18nManager.getTranslation("Superior"))
|
224 |
.append(":\t")
|
225 |
.append(nativeLayerExtent.getMaximum(1))
|
226 |
.append("\n\t");
|
227 |
buff.append(i18nManager.getTranslation("Inferior"))
|
228 |
.append(":\t")
|
229 |
.append(nativeLayerExtent.getMinimum(1))
|
230 |
.append("\n\t");
|
231 |
buff.append(i18nManager.getTranslation("Izquierda"))
|
232 |
.append(":\t")
|
233 |
.append(nativeLayerExtent.getMinimum(0))
|
234 |
.append("\n\t");
|
235 |
buff.append(i18nManager.getTranslation("Derecha"))
|
236 |
.append(":\t")
|
237 |
.append(nativeLayerExtent.getMaximum(0))
|
238 |
.append("\n");
|
239 |
} |
240 |
|
241 |
if (layer instanceof FLyrVect) { |
242 |
try {
|
243 |
GeometryType geomType = ((FLyrVect) layer).getTypeVectorLayer(); |
244 |
buff.append("\n")
|
245 |
.append(i18nManager.getTranslation("type"))
|
246 |
.append(": ")
|
247 |
.append(geomType.getFullName()) |
248 |
.append("\n");
|
249 |
} catch (Exception e) { |
250 |
logger.warn("Can't get gemetry type for layer '" + layer.getName() + "'.", e); |
251 |
buff.append("\n")
|
252 |
.append(i18nManager.getTranslation("type"))
|
253 |
.append(": ")
|
254 |
.append("unknow")
|
255 |
.append("\n");
|
256 |
} |
257 |
|
258 |
} |
259 |
info = buff.toString(); |
260 |
} |
261 |
} catch (Exception e) { |
262 |
logger.warn("Can't get layer information.", e);
|
263 |
info = buff.toString(); |
264 |
} |
265 |
return info;
|
266 |
} |
267 |
|
268 |
} |