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