svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / preferencespage / ViewPage.java @ 7253
History | View | Annotate | Download (9.99 KB)
1 | 6663 | caballero | /* 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$
|
||
45 | * $Log$
|
||
46 | 7253 | jaume | * Revision 1.6 2006-09-14 06:57:18 jaume
|
47 | * *** empty log message ***
|
||
48 | *
|
||
49 | * Revision 1.5 2006/09/12 15:56:50 jaume
|
||
50 | 7222 | jaume | * Default Projection now customizable
|
51 | *
|
||
52 | * Revision 1.4 2006/08/29 07:21:08 cesar
|
||
53 | 6878 | cesar | * Rename com.iver.cit.gvsig.fmap.Fmap class to com.iver.cit.gvsig.fmap.MapContext
|
54 | *
|
||
55 | * Revision 1.3 2006/08/22 12:30:59 jaume
|
||
56 | 6805 | jaume | * *** empty log message ***
|
57 | *
|
||
58 | 6812 | jaume | * Revision 1.2 2006/08/22 07:36:04 jaume
|
59 | * *** empty log message ***
|
||
60 | *
|
||
61 | 6805 | jaume | * Revision 1.1 2006/08/04 11:41:05 caballero
|
62 | 6663 | caballero | * poder especificar el zoom a aplicar en las vistas
|
63 | *
|
||
64 | * Revision 1.3 2006/07/31 10:02:31 jaume
|
||
65 | * *** empty log message ***
|
||
66 | *
|
||
67 | * Revision 1.2 2006/06/13 07:43:08 fjp
|
||
68 | * Ajustes sobre los cuadros de dialogos de preferencias
|
||
69 | *
|
||
70 | * Revision 1.1 2006/06/12 16:04:28 caballero
|
||
71 | * Preferencias
|
||
72 | *
|
||
73 | * Revision 1.11 2006/06/06 10:26:31 jaume
|
||
74 | * *** empty log message ***
|
||
75 | *
|
||
76 | * Revision 1.10 2006/06/05 17:07:17 jaume
|
||
77 | * *** empty log message ***
|
||
78 | *
|
||
79 | * Revision 1.9 2006/06/05 17:00:44 jaume
|
||
80 | * *** empty log message ***
|
||
81 | *
|
||
82 | * Revision 1.8 2006/06/05 16:57:59 jaume
|
||
83 | * *** empty log message ***
|
||
84 | *
|
||
85 | * Revision 1.7 2006/06/05 14:45:06 jaume
|
||
86 | * *** empty log message ***
|
||
87 | *
|
||
88 | * Revision 1.6 2006/06/05 11:00:09 jaume
|
||
89 | * *** empty log message ***
|
||
90 | *
|
||
91 | * Revision 1.5 2006/06/05 10:39:02 jaume
|
||
92 | * *** empty log message ***
|
||
93 | *
|
||
94 | * Revision 1.4 2006/06/05 10:13:40 jaume
|
||
95 | * *** empty log message ***
|
||
96 | *
|
||
97 | * Revision 1.3 2006/06/05 10:06:08 jaume
|
||
98 | * *** empty log message ***
|
||
99 | *
|
||
100 | * Revision 1.2 2006/06/05 09:51:56 jaume
|
||
101 | * *** empty log message ***
|
||
102 | *
|
||
103 | * Revision 1.1 2006/06/02 10:50:18 jaume
|
||
104 | * *** empty log message ***
|
||
105 | *
|
||
106 | *
|
||
107 | */
|
||
108 | package com.iver.cit.gvsig.gui.preferencespage; |
||
109 | |||
110 | 7222 | jaume | import java.awt.FlowLayout; |
111 | import java.awt.event.ActionEvent; |
||
112 | import java.awt.event.ActionListener; |
||
113 | import java.util.Enumeration; |
||
114 | 6663 | caballero | |
115 | import javax.swing.ImageIcon; |
||
116 | 7253 | jaume | import javax.swing.JCheckBox; |
117 | 7222 | jaume | import javax.swing.JLabel; |
118 | 6663 | caballero | import javax.swing.JPanel; |
119 | import javax.swing.JTextField; |
||
120 | 7222 | jaume | import javax.swing.UIManager; |
121 | import javax.swing.plaf.FontUIResource; |
||
122 | 6663 | caballero | |
123 | 7222 | jaume | import org.cresques.cts.IProjection; |
124 | import org.cresques.cts.ProjectionPool; |
||
125 | import org.gvsig.gui.beans.swing.JButton; |
||
126 | |||
127 | 6663 | caballero | import com.iver.andami.PluginServices; |
128 | import com.iver.andami.preferences.AbstractPreferencePage; |
||
129 | import com.iver.andami.preferences.StoreException; |
||
130 | 6878 | cesar | import com.iver.cit.gvsig.fmap.MapContext; |
131 | 7253 | jaume | import com.iver.cit.gvsig.fmap.MapControl; |
132 | 7222 | jaume | import com.iver.cit.gvsig.gui.dialogs.CSSelectionDialog; |
133 | import com.iver.cit.gvsig.project.Project; |
||
134 | import com.iver.utiles.XMLEntity; |
||
135 | 6663 | caballero | |
136 | public class ViewPage extends AbstractPreferencePage { |
||
137 | 7222 | jaume | private static final String DEFAULT_PROJECTION_KEY_NAME = "DefaultProjection"; |
138 | private static final String FACTORY_DEFAULT_PROJECTION = "EPSG:23030"; |
||
139 | private static final String ZOOM_IN_FACTOR_KEY_NAME = "ZoomInFactor"; |
||
140 | private static final String ZOOM_OUT_FACTOR_KEY_NAME = "ZoomOutFactor"; |
||
141 | 7253 | jaume | private static final String ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME = "NewLayersInInvisibleMode"; |
142 | private static final String KEEP_SCALE_ON_RESIZING_KEY_NAME = "KeepScaleOnResizing"; |
||
143 | |||
144 | 6663 | caballero | private JTextField txtZoomInFactor; |
145 | private JTextField txtZoomOutFactor; |
||
146 | protected String id; |
||
147 | private ImageIcon icon; |
||
148 | 6805 | jaume | private boolean changed = false; |
149 | 7222 | jaume | private JLabel lblDefaultProjection; |
150 | private JButton btnChangeProjection; |
||
151 | private String fontName; |
||
152 | 7253 | jaume | private JCheckBox chkInvisibleNewLayers; |
153 | private JCheckBox chkKeepScaleOnResizing; |
||
154 | 6663 | caballero | |
155 | 7222 | jaume | { |
156 | Enumeration keys = UIManager.getDefaults().keys(); |
||
157 | while (keys.hasMoreElements()) {
|
||
158 | Object key = keys.nextElement();
|
||
159 | Object value = UIManager.get (key); |
||
160 | if (value instanceof FontUIResource) { |
||
161 | FontUIResource fur = (FontUIResource) value; |
||
162 | fontName = fur.getFontName(); |
||
163 | |||
164 | } |
||
165 | } |
||
166 | } |
||
167 | |||
168 | 6663 | caballero | public ViewPage() {
|
169 | super();
|
||
170 | id = this.getClass().getName();
|
||
171 | icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/Vista.png")); |
||
172 | 7222 | jaume | |
173 | |||
174 | // default projection
|
||
175 | lblDefaultProjection = new JLabel(); |
||
176 | lblDefaultProjection.setFont(new java.awt.Font(
|
||
177 | fontName, java.awt.Font.BOLD, 11));
|
||
178 | btnChangeProjection = new JButton(PluginServices.getText(this, "change")); |
||
179 | btnChangeProjection.addActionListener(new ActionListener() { |
||
180 | public void actionPerformed(ActionEvent e) { |
||
181 | CSSelectionDialog csSelect = new CSSelectionDialog();
|
||
182 | csSelect.setProjection( ProjectionPool.get( |
||
183 | lblDefaultProjection.getText())); |
||
184 | PluginServices.getMDIManager().addWindow(csSelect); |
||
185 | |||
186 | if (csSelect.isOkPressed()) {
|
||
187 | IProjection proj = csSelect.getProjection(); |
||
188 | lblDefaultProjection.setText(proj.getAbrev()); |
||
189 | } |
||
190 | } |
||
191 | }); |
||
192 | addComponent(PluginServices.getText(this, "default_projection") + ":", lblDefaultProjection ); |
||
193 | JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
||
194 | aux.add(btnChangeProjection); |
||
195 | addComponent("", aux);
|
||
196 | |||
197 | // just a separator
|
||
198 | addComponent(new JLabel(" ")); |
||
199 | |||
200 | 7253 | jaume | // Adding Invisible New Layers
|
201 | chkInvisibleNewLayers = new JCheckBox( |
||
202 | PluginServices.getText(this, "options.view.invisible_new_layers")); |
||
203 | |||
204 | addComponent("", chkInvisibleNewLayers);
|
||
205 | chkKeepScaleOnResizing = new JCheckBox( |
||
206 | PluginServices.getText(this, "options.view.keep_scale_on_resizing")); |
||
207 | chkKeepScaleOnResizing.setEnabled(false);
|
||
208 | addComponent("", chkKeepScaleOnResizing);
|
||
209 | |||
210 | // just a separator
|
||
211 | addComponent(new JLabel(" ")); |
||
212 | |||
213 | 6663 | caballero | // zoom in factor
|
214 | addComponent(PluginServices.getText(this, "zoom_in_factor") + ":", |
||
215 | txtZoomInFactor = new JTextField("", 15)); |
||
216 | // zoom out factor
|
||
217 | addComponent(PluginServices.getText(this, "zoom_out_factor") + ":", |
||
218 | txtZoomOutFactor = new JTextField("", 15)); |
||
219 | 7222 | jaume | |
220 | initializeValues(); |
||
221 | 6663 | caballero | } |
222 | |||
223 | public void initializeValues() { |
||
224 | 7222 | jaume | PluginServices ps = PluginServices.getPluginServices(this);
|
225 | XMLEntity xml = ps.getPersistentXML(); |
||
226 | |||
227 | // Default Projection
|
||
228 | if (xml.contains(DEFAULT_PROJECTION_KEY_NAME)) {
|
||
229 | 7253 | jaume | lblDefaultProjection.setText( |
230 | xml.getStringProperty(DEFAULT_PROJECTION_KEY_NAME)); |
||
231 | 7222 | jaume | } else {
|
232 | lblDefaultProjection.setText(FACTORY_DEFAULT_PROJECTION); |
||
233 | } |
||
234 | Project.setDefaultProjection(ProjectionPool.get(lblDefaultProjection.getText())); |
||
235 | |||
236 | 7253 | jaume | // Adding invisible new layers
|
237 | if (xml.contains(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME)) {
|
||
238 | chkInvisibleNewLayers.setSelected( |
||
239 | xml.getBooleanProperty(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME)); |
||
240 | } |
||
241 | |||
242 | // Keep scale on resizing
|
||
243 | if (xml.contains(KEEP_SCALE_ON_RESIZING_KEY_NAME)) {
|
||
244 | chkKeepScaleOnResizing.setSelected( |
||
245 | xml.getBooleanProperty(KEEP_SCALE_ON_RESIZING_KEY_NAME)); |
||
246 | } |
||
247 | |||
248 | 7222 | jaume | // Zoom-in factor
|
249 | if (xml.contains(ZOOM_IN_FACTOR_KEY_NAME)) {
|
||
250 | double zoomInFactor = xml.getDoubleProperty(ZOOM_IN_FACTOR_KEY_NAME);
|
||
251 | txtZoomInFactor.setText(String.valueOf( zoomInFactor ));
|
||
252 | } else {
|
||
253 | txtZoomInFactor.setText( |
||
254 | String.valueOf( MapContext.ZOOMINFACTOR ));
|
||
255 | } |
||
256 | MapContext.ZOOMINFACTOR = Double.parseDouble(txtZoomInFactor.getText());
|
||
257 | |||
258 | // Zoom-out factor
|
||
259 | if (xml.contains(ZOOM_OUT_FACTOR_KEY_NAME)) {
|
||
260 | double zoomOutFactor = xml.getDoubleProperty(ZOOM_OUT_FACTOR_KEY_NAME);
|
||
261 | txtZoomOutFactor.setText(String.valueOf( zoomOutFactor ));
|
||
262 | } else {
|
||
263 | txtZoomOutFactor.setText( |
||
264 | String.valueOf( MapContext.ZOOMOUTFACTOR ));
|
||
265 | } |
||
266 | MapContext.ZOOMOUTFACTOR = Double.parseDouble(txtZoomOutFactor.getText());;
|
||
267 | |||
268 | 6663 | caballero | } |
269 | |||
270 | public String getID() { |
||
271 | return id;
|
||
272 | } |
||
273 | |||
274 | public String getTitle() { |
||
275 | return PluginServices.getText(this, "Vista"); |
||
276 | } |
||
277 | |||
278 | public JPanel getPanel() { |
||
279 | return this; |
||
280 | } |
||
281 | |||
282 | public void storeValues() throws StoreException { |
||
283 | 7222 | jaume | String projName = lblDefaultProjection.getText();
|
284 | 6663 | caballero | double zif;
|
285 | double zof;
|
||
286 | 7253 | jaume | boolean invisibleNewLayers, keepScaleOnResize;
|
287 | 7222 | jaume | try {
|
288 | 6663 | caballero | zif=Double.parseDouble(txtZoomInFactor.getText());
|
289 | zof=Double.parseDouble(txtZoomOutFactor.getText());
|
||
290 | 7222 | jaume | Project.setDefaultProjection(ProjectionPool.get(projName)); |
291 | 7253 | jaume | invisibleNewLayers = chkInvisibleNewLayers.isSelected(); |
292 | keepScaleOnResize = chkKeepScaleOnResizing.isSelected(); |
||
293 | 7222 | jaume | } catch (Exception e) { |
294 | 6663 | caballero | throw new StoreException(PluginServices.getText(this,"factor_zoom_incorrecto")); |
295 | } |
||
296 | 6878 | cesar | MapContext.ZOOMINFACTOR=zif; |
297 | MapContext.ZOOMOUTFACTOR=zof; |
||
298 | 7253 | jaume | // MapControl.setScalingOnResize(!keepScaleOnResize);
|
299 | 6812 | jaume | |
300 | 7222 | jaume | PluginServices ps = PluginServices.getPluginServices(this);
|
301 | XMLEntity xml = ps.getPersistentXML(); |
||
302 | xml.putProperty(DEFAULT_PROJECTION_KEY_NAME, projName); |
||
303 | xml.putProperty(ZOOM_IN_FACTOR_KEY_NAME, zif); |
||
304 | xml.putProperty(ZOOM_OUT_FACTOR_KEY_NAME, zof); |
||
305 | 7253 | jaume | xml.putProperty(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME, invisibleNewLayers); |
306 | xml.putProperty(KEEP_SCALE_ON_RESIZING_KEY_NAME, keepScaleOnResize); |
||
307 | |||
308 | 6663 | caballero | } |
309 | |||
310 | |||
311 | public void initializeDefaults() { |
||
312 | 7222 | jaume | lblDefaultProjection.setText(FACTORY_DEFAULT_PROJECTION); |
313 | 6878 | cesar | txtZoomInFactor.setText(String.valueOf(MapContext.ZOOMINFACTOR));
|
314 | txtZoomOutFactor.setText(String.valueOf(MapContext.ZOOMOUTFACTOR));
|
||
315 | 7253 | jaume | chkInvisibleNewLayers.setSelected(false);
|
316 | chkKeepScaleOnResizing.setSelected(false);
|
||
317 | 6663 | caballero | } |
318 | |||
319 | public ImageIcon getIcon() { |
||
320 | return icon;
|
||
321 | } |
||
322 | 6805 | jaume | |
323 | public boolean isValueChanged() { |
||
324 | return super.hasChanged(); |
||
325 | } |
||
326 | 6812 | jaume | |
327 | public void setChangesApplied() { |
||
328 | setChanged(false);
|
||
329 | } |
||
330 | 6663 | caballero | } |