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