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