root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / preferencespage / ViewPage.java @ 7737
History | View | Annotate | Download (11.5 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: ViewPage.java 7737 2006-10-02 13:38:23Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.13 2006-10-02 13:38:23 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.12 2006/10/02 11:49:23 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.11 2006/09/28 12:04:21 jaume
|
53 |
* default selection color now configurable
|
54 |
*
|
55 |
* Revision 1.10 2006/09/25 10:17:15 caballero
|
56 |
* Projection
|
57 |
*
|
58 |
* Revision 1.9 2006/09/15 10:41:30 caballero
|
59 |
* extensibilidad de documentos
|
60 |
*
|
61 |
* Revision 1.8 2006/09/14 15:43:48 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.7 2006/09/14 15:42:38 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.6 2006/09/14 06:57:18 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.5 2006/09/12 15:56:50 jaume
|
71 |
* Default Projection now customizable
|
72 |
*
|
73 |
* Revision 1.4 2006/08/29 07:21:08 cesar
|
74 |
* Rename com.iver.cit.gvsig.fmap.Fmap class to com.iver.cit.gvsig.fmap.MapContext
|
75 |
*
|
76 |
* Revision 1.3 2006/08/22 12:30:59 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.2 2006/08/22 07:36:04 jaume
|
80 |
* *** empty log message ***
|
81 |
*
|
82 |
* Revision 1.1 2006/08/04 11:41:05 caballero
|
83 |
* poder especificar el zoom a aplicar en las vistas
|
84 |
*
|
85 |
* Revision 1.3 2006/07/31 10:02:31 jaume
|
86 |
* *** empty log message ***
|
87 |
*
|
88 |
* Revision 1.2 2006/06/13 07:43:08 fjp
|
89 |
* Ajustes sobre los cuadros de dialogos de preferencias
|
90 |
*
|
91 |
* Revision 1.1 2006/06/12 16:04:28 caballero
|
92 |
* Preferencias
|
93 |
*
|
94 |
* Revision 1.11 2006/06/06 10:26:31 jaume
|
95 |
* *** empty log message ***
|
96 |
*
|
97 |
* Revision 1.10 2006/06/05 17:07:17 jaume
|
98 |
* *** empty log message ***
|
99 |
*
|
100 |
* Revision 1.9 2006/06/05 17:00:44 jaume
|
101 |
* *** empty log message ***
|
102 |
*
|
103 |
* Revision 1.8 2006/06/05 16:57:59 jaume
|
104 |
* *** empty log message ***
|
105 |
*
|
106 |
* Revision 1.7 2006/06/05 14:45:06 jaume
|
107 |
* *** empty log message ***
|
108 |
*
|
109 |
* Revision 1.6 2006/06/05 11:00:09 jaume
|
110 |
* *** empty log message ***
|
111 |
*
|
112 |
* Revision 1.5 2006/06/05 10:39:02 jaume
|
113 |
* *** empty log message ***
|
114 |
*
|
115 |
* Revision 1.4 2006/06/05 10:13:40 jaume
|
116 |
* *** empty log message ***
|
117 |
*
|
118 |
* Revision 1.3 2006/06/05 10:06:08 jaume
|
119 |
* *** empty log message ***
|
120 |
*
|
121 |
* Revision 1.2 2006/06/05 09:51:56 jaume
|
122 |
* *** empty log message ***
|
123 |
*
|
124 |
* Revision 1.1 2006/06/02 10:50:18 jaume
|
125 |
* *** empty log message ***
|
126 |
*
|
127 |
*
|
128 |
*/
|
129 |
package com.iver.cit.gvsig.gui.preferencespage; |
130 |
|
131 |
import java.awt.Color; |
132 |
import java.awt.FlowLayout; |
133 |
import java.awt.event.ActionEvent; |
134 |
import java.awt.event.ActionListener; |
135 |
import java.util.Enumeration; |
136 |
|
137 |
import javax.swing.ImageIcon; |
138 |
import javax.swing.JCheckBox; |
139 |
import javax.swing.JLabel; |
140 |
import javax.swing.JPanel; |
141 |
import javax.swing.JTextField; |
142 |
import javax.swing.SwingUtilities; |
143 |
import javax.swing.UIManager; |
144 |
import javax.swing.plaf.FontUIResource; |
145 |
|
146 |
import org.cresques.cts.IProjection; |
147 |
import org.gvsig.gui.beans.swing.JButton; |
148 |
|
149 |
import com.iver.andami.PluginServices; |
150 |
import com.iver.andami.preferences.AbstractPreferencePage; |
151 |
import com.iver.andami.preferences.StoreException; |
152 |
import com.iver.cit.gvsig.fmap.MapContext; |
153 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
154 |
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
155 |
import com.iver.cit.gvsig.project.Project; |
156 |
import com.iver.cit.gvsig.project.documents.view.info.gui.CSSelectionDialog; |
157 |
import com.iver.utiles.StringUtilities; |
158 |
import com.iver.utiles.XMLEntity; |
159 |
|
160 |
public class ViewPage extends AbstractPreferencePage { |
161 |
private static final String DEFAULT_PROJECTION_KEY_NAME = "DefaultProjection"; |
162 |
private static final String FACTORY_DEFAULT_PROJECTION = "EPSG:23030"; |
163 |
private static final String ZOOM_IN_FACTOR_KEY_NAME = "ZoomInFactor"; |
164 |
private static final String ZOOM_OUT_FACTOR_KEY_NAME = "ZoomOutFactor"; |
165 |
private static final String ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME = "NewLayersInInvisibleMode"; |
166 |
private static final String KEEP_SCALE_ON_RESIZING_KEY_NAME = "KeepScaleOnResizing"; |
167 |
private static final String DEFAULT_SELECTION_COLOR_KEY_NAME = "DefaultSelectionColor"; |
168 |
private static final double DEFAULT_ZOOM_IN_FACTOR = 2.0; |
169 |
private static final double DEFAULT_ZOOM_OUT_FACTOR = 0.5; |
170 |
private static final Color FACTORY_DEFAULT_SELECTION_COLOR = new Color(255, 255, 0); |
171 |
|
172 |
|
173 |
private JTextField txtZoomInFactor; |
174 |
private JTextField txtZoomOutFactor; |
175 |
protected String id; |
176 |
private ImageIcon icon; |
177 |
private JLabel lblDefaultProjection; |
178 |
private JButton btnChangeProjection; |
179 |
private String fontName; |
180 |
private JCheckBox chkInvisibleNewLayers; |
181 |
private JCheckBox chkKeepScaleOnResizing; |
182 |
private ColorChooserPanel jcp;
|
183 |
|
184 |
{ |
185 |
Enumeration keys = UIManager.getDefaults().keys(); |
186 |
while (keys.hasMoreElements()) {
|
187 |
Object key = keys.nextElement();
|
188 |
Object value = UIManager.get (key); |
189 |
if (value instanceof FontUIResource) { |
190 |
FontUIResource fur = (FontUIResource) value; |
191 |
fontName = fur.getFontName(); |
192 |
|
193 |
} |
194 |
} |
195 |
} |
196 |
|
197 |
public ViewPage() {
|
198 |
super();
|
199 |
id = this.getClass().getName();
|
200 |
icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/Vista.png")); |
201 |
|
202 |
|
203 |
// default projection
|
204 |
lblDefaultProjection = new JLabel(); |
205 |
lblDefaultProjection.setFont(new java.awt.Font(
|
206 |
fontName, java.awt.Font.BOLD, 11));
|
207 |
btnChangeProjection = new JButton(PluginServices.getText(this, "change")); |
208 |
btnChangeProjection.addActionListener(new ActionListener() { |
209 |
public void actionPerformed(ActionEvent e) { |
210 |
CSSelectionDialog csSelect = new CSSelectionDialog();
|
211 |
csSelect.setProjection( CRSFactory.getCRS( |
212 |
lblDefaultProjection.getText())); |
213 |
PluginServices.getMDIManager().addWindow(csSelect); |
214 |
|
215 |
if (csSelect.isOkPressed()) {
|
216 |
IProjection proj = csSelect.getProjection(); |
217 |
lblDefaultProjection.setText(proj.getAbrev()); |
218 |
} |
219 |
} |
220 |
}); |
221 |
|
222 |
addComponent(PluginServices.getText(this, "default_projection") + ":", lblDefaultProjection ); |
223 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
224 |
aux.add(btnChangeProjection); |
225 |
addComponent("", aux);
|
226 |
|
227 |
// just a separator
|
228 |
addComponent(new JLabel(" ")); |
229 |
|
230 |
// Adding Invisible New Layers
|
231 |
chkInvisibleNewLayers = new JCheckBox( |
232 |
PluginServices.getText(this, "options.view.invisible_new_layers")); |
233 |
|
234 |
addComponent("", chkInvisibleNewLayers);
|
235 |
chkKeepScaleOnResizing = new JCheckBox( |
236 |
PluginServices.getText(this, "options.view.keep_scale_on_resizing")); |
237 |
chkKeepScaleOnResizing.setEnabled(false);
|
238 |
addComponent("", chkKeepScaleOnResizing);
|
239 |
|
240 |
// just a separator
|
241 |
addComponent(new JLabel(" ")); |
242 |
|
243 |
// zoom in factor
|
244 |
addComponent(PluginServices.getText(this, "zoom_in_factor") + ":", |
245 |
txtZoomInFactor = new JTextField("", 15)); |
246 |
// zoom out factor
|
247 |
addComponent(PluginServices.getText(this, "zoom_out_factor") + ":", |
248 |
txtZoomOutFactor = new JTextField("", 15)); |
249 |
|
250 |
// just a separator
|
251 |
addComponent(new JLabel(" ")); |
252 |
|
253 |
// default selection color chooser
|
254 |
jcp = new ColorChooserPanel();
|
255 |
addComponent(PluginServices.getText(this, "options.view.default_selection_color"), jcp); |
256 |
initializeValues(); |
257 |
} |
258 |
|
259 |
public void initializeValues() { |
260 |
PluginServices ps = PluginServices.getPluginServices(this);
|
261 |
XMLEntity xml = ps.getPersistentXML(); |
262 |
|
263 |
// Default Projection
|
264 |
if (xml.contains(DEFAULT_PROJECTION_KEY_NAME)) {
|
265 |
lblDefaultProjection.setText( |
266 |
xml.getStringProperty(DEFAULT_PROJECTION_KEY_NAME)); |
267 |
} else {
|
268 |
lblDefaultProjection.setText(FACTORY_DEFAULT_PROJECTION); |
269 |
} |
270 |
Project.setDefaultProjection( CRSFactory.getCRS(lblDefaultProjection.getText())); |
271 |
|
272 |
// Adding invisible new layers
|
273 |
if (xml.contains(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME)) {
|
274 |
chkInvisibleNewLayers.setSelected( |
275 |
xml.getBooleanProperty(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME)); |
276 |
} |
277 |
|
278 |
// Keep scale on resizing
|
279 |
if (xml.contains(KEEP_SCALE_ON_RESIZING_KEY_NAME)) {
|
280 |
chkKeepScaleOnResizing.setSelected( |
281 |
xml.getBooleanProperty(KEEP_SCALE_ON_RESIZING_KEY_NAME)); |
282 |
} |
283 |
|
284 |
// Zoom-in factor
|
285 |
if (xml.contains(ZOOM_IN_FACTOR_KEY_NAME)) {
|
286 |
double zoomInFactor = xml.getDoubleProperty(ZOOM_IN_FACTOR_KEY_NAME);
|
287 |
txtZoomInFactor.setText(String.valueOf( zoomInFactor ));
|
288 |
} else {
|
289 |
txtZoomInFactor.setText( |
290 |
String.valueOf( MapContext.ZOOMINFACTOR ));
|
291 |
} |
292 |
MapContext.ZOOMINFACTOR = Double.parseDouble(txtZoomInFactor.getText());
|
293 |
|
294 |
// Zoom-out factor
|
295 |
if (xml.contains(ZOOM_OUT_FACTOR_KEY_NAME)) {
|
296 |
double zoomOutFactor = xml.getDoubleProperty(ZOOM_OUT_FACTOR_KEY_NAME);
|
297 |
txtZoomOutFactor.setText(String.valueOf( zoomOutFactor ));
|
298 |
} else {
|
299 |
txtZoomOutFactor.setText( |
300 |
String.valueOf( MapContext.ZOOMOUTFACTOR ));
|
301 |
} |
302 |
MapContext.ZOOMOUTFACTOR = Double.parseDouble(txtZoomOutFactor.getText());;
|
303 |
|
304 |
// Default selection color
|
305 |
jcp.setColor(Project.getDefaultColor()); |
306 |
jcp.setAlpha(255);
|
307 |
|
308 |
} |
309 |
|
310 |
public String getID() { |
311 |
return id;
|
312 |
} |
313 |
|
314 |
public String getTitle() { |
315 |
return PluginServices.getText(this, "Vista"); |
316 |
} |
317 |
|
318 |
public JPanel getPanel() { |
319 |
return this; |
320 |
} |
321 |
|
322 |
public void storeValues() throws StoreException { |
323 |
String projName = lblDefaultProjection.getText();
|
324 |
double zif;
|
325 |
double zof;
|
326 |
boolean invisibleNewLayers, keepScaleOnResize;
|
327 |
Color color;
|
328 |
try {
|
329 |
zif=Double.parseDouble(txtZoomInFactor.getText());
|
330 |
zof=Double.parseDouble(txtZoomOutFactor.getText());
|
331 |
color = jcp.getColor(); |
332 |
Project.setDefaultProjection( CRSFactory.getCRS(projName)); |
333 |
Project.setDefaultSelectionColor( color ); |
334 |
invisibleNewLayers = chkInvisibleNewLayers.isSelected(); |
335 |
keepScaleOnResize = chkKeepScaleOnResizing.isSelected(); |
336 |
} catch (Exception e) { |
337 |
throw new StoreException(PluginServices.getText(this,"factor_zoom_incorrecto")); |
338 |
} |
339 |
MapContext.ZOOMINFACTOR=zif; |
340 |
MapContext.ZOOMOUTFACTOR=zof; |
341 |
// MapControl.setScalingOnResize(!keepScaleOnResize);
|
342 |
|
343 |
PluginServices ps = PluginServices.getPluginServices(this);
|
344 |
XMLEntity xml = ps.getPersistentXML(); |
345 |
xml.putProperty(DEFAULT_PROJECTION_KEY_NAME, projName); |
346 |
xml.putProperty(ZOOM_IN_FACTOR_KEY_NAME, zif); |
347 |
xml.putProperty(ZOOM_OUT_FACTOR_KEY_NAME, zof); |
348 |
xml.putProperty(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME, invisibleNewLayers); |
349 |
xml.putProperty(KEEP_SCALE_ON_RESIZING_KEY_NAME, keepScaleOnResize); |
350 |
xml.putProperty(DEFAULT_SELECTION_COLOR_KEY_NAME, StringUtilities.color2String(color)); |
351 |
} |
352 |
|
353 |
|
354 |
public void initializeDefaults() { |
355 |
lblDefaultProjection.setText(FACTORY_DEFAULT_PROJECTION); |
356 |
txtZoomInFactor.setText(String.valueOf(DEFAULT_ZOOM_IN_FACTOR));
|
357 |
txtZoomOutFactor.setText(String.valueOf(DEFAULT_ZOOM_OUT_FACTOR));
|
358 |
chkInvisibleNewLayers.setSelected(false);
|
359 |
chkKeepScaleOnResizing.setSelected(false);
|
360 |
jcp.setColor(FACTORY_DEFAULT_SELECTION_COLOR); |
361 |
|
362 |
} |
363 |
|
364 |
public ImageIcon getIcon() { |
365 |
return icon;
|
366 |
} |
367 |
|
368 |
public boolean isValueChanged() { |
369 |
return super.hasChanged(); |
370 |
} |
371 |
|
372 |
public void setChangesApplied() { |
373 |
setChanged(false);
|
374 |
} |
375 |
} |