Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / preferencespage / ViewPage.java @ 7729

History | View | Annotate | Download (11.4 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 7729 2006-10-02 11:49:23Z jaume $
45
* $Log$
46
* Revision 1.12  2006-10-02 11:49:23  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.11  2006/09/28 12:04:21  jaume
50
* default selection color now configurable
51
*
52
* Revision 1.10  2006/09/25 10:17:15  caballero
53
* Projection
54
*
55
* Revision 1.9  2006/09/15 10:41:30  caballero
56
* extensibilidad de documentos
57
*
58
* Revision 1.8  2006/09/14 15:43:48  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.7  2006/09/14 15:42:38  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.6  2006/09/14 06:57:18  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.5  2006/09/12 15:56:50  jaume
68
* Default Projection now customizable
69
*
70
* Revision 1.4  2006/08/29 07:21:08  cesar
71
* Rename com.iver.cit.gvsig.fmap.Fmap class to com.iver.cit.gvsig.fmap.MapContext
72
*
73
* Revision 1.3  2006/08/22 12:30:59  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.2  2006/08/22 07:36:04  jaume
77
* *** empty log message ***
78
*
79
* Revision 1.1  2006/08/04 11:41:05  caballero
80
* poder especificar el zoom a aplicar en las vistas
81
*
82
* Revision 1.3  2006/07/31 10:02:31  jaume
83
* *** empty log message ***
84
*
85
* Revision 1.2  2006/06/13 07:43:08  fjp
86
* Ajustes sobre los cuadros de dialogos de preferencias
87
*
88
* Revision 1.1  2006/06/12 16:04:28  caballero
89
* Preferencias
90
*
91
* Revision 1.11  2006/06/06 10:26:31  jaume
92
* *** empty log message ***
93
*
94
* Revision 1.10  2006/06/05 17:07:17  jaume
95
* *** empty log message ***
96
*
97
* Revision 1.9  2006/06/05 17:00:44  jaume
98
* *** empty log message ***
99
*
100
* Revision 1.8  2006/06/05 16:57:59  jaume
101
* *** empty log message ***
102
*
103
* Revision 1.7  2006/06/05 14:45:06  jaume
104
* *** empty log message ***
105
*
106
* Revision 1.6  2006/06/05 11:00:09  jaume
107
* *** empty log message ***
108
*
109
* Revision 1.5  2006/06/05 10:39:02  jaume
110
* *** empty log message ***
111
*
112
* Revision 1.4  2006/06/05 10:13:40  jaume
113
* *** empty log message ***
114
*
115
* Revision 1.3  2006/06/05 10:06:08  jaume
116
* *** empty log message ***
117
*
118
* Revision 1.2  2006/06/05 09:51:56  jaume
119
* *** empty log message ***
120
*
121
* Revision 1.1  2006/06/02 10:50:18  jaume
122
* *** empty log message ***
123
*
124
*
125
*/
126
package com.iver.cit.gvsig.gui.preferencespage;
127

    
128
import java.awt.Color;
129
import java.awt.FlowLayout;
130
import java.awt.event.ActionEvent;
131
import java.awt.event.ActionListener;
132
import java.util.Enumeration;
133

    
134
import javax.swing.ImageIcon;
135
import javax.swing.JCheckBox;
136
import javax.swing.JLabel;
137
import javax.swing.JPanel;
138
import javax.swing.JTextField;
139
import javax.swing.SwingUtilities;
140
import javax.swing.UIManager;
141
import javax.swing.plaf.FontUIResource;
142

    
143
import org.cresques.cts.IProjection;
144
import org.gvsig.gui.beans.swing.JButton;
145

    
146
import com.iver.andami.PluginServices;
147
import com.iver.andami.preferences.AbstractPreferencePage;
148
import com.iver.andami.preferences.StoreException;
149
import com.iver.cit.gvsig.fmap.MapContext;
150
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
151
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
152
import com.iver.cit.gvsig.project.Project;
153
import com.iver.cit.gvsig.project.documents.view.info.gui.CSSelectionDialog;
154
import com.iver.utiles.StringUtilities;
155
import com.iver.utiles.XMLEntity;
156

    
157
public class ViewPage extends AbstractPreferencePage {
158
        private static final String DEFAULT_PROJECTION_KEY_NAME = "DefaultProjection";
159
        private static final String FACTORY_DEFAULT_PROJECTION = "EPSG:23030";
160
        private static final String ZOOM_IN_FACTOR_KEY_NAME = "ZoomInFactor";
161
        private static final String ZOOM_OUT_FACTOR_KEY_NAME = "ZoomOutFactor";
162
        private static final String ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME = "NewLayersInInvisibleMode";
163
        private static final String KEEP_SCALE_ON_RESIZING_KEY_NAME = "KeepScaleOnResizing";
164
        private static final String DEFAULT_SELECTION_COLOR_KEY_NAME = "DefaultSelectionColor";
165
        private static final double DEFAULT_ZOOM_IN_FACTOR = 2.0;
166
        private static final double DEFAULT_ZOOM_OUT_FACTOR = 0.5;
167
        private static final Color FACTORY_DEFAULT_SELECTION_COLOR = new Color(255, 255, 0);
168

    
169

    
170
        private JTextField txtZoomInFactor;
171
        private JTextField txtZoomOutFactor;
172
        protected String id;
173
        private ImageIcon icon;
174
        private JLabel lblDefaultProjection;
175
        private JButton btnChangeProjection;
176
        private String fontName;
177
        private JCheckBox chkInvisibleNewLayers;
178
        private JCheckBox chkKeepScaleOnResizing;
179
        private ColorChooserPanel jcp;
180

    
181
        {
182
                Enumeration keys = UIManager.getDefaults().keys();
183
                while (keys.hasMoreElements()) {
184
                        Object key = keys.nextElement();
185
                        Object value = UIManager.get (key);
186
                        if (value instanceof FontUIResource) {
187
                                FontUIResource fur = (FontUIResource) value;
188
                                fontName = fur.getFontName();
189

    
190
                        }
191
                }
192
        }
193

    
194
        public ViewPage() {
195
                super();
196
                id = this.getClass().getName();
197
                icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/Vista.png"));
198

    
199

    
200
                // default projection
201
                lblDefaultProjection = new JLabel();
202
                lblDefaultProjection.setFont(new java.awt.Font(
203
                        fontName, java.awt.Font.BOLD, 11));
204
                btnChangeProjection = new JButton(PluginServices.getText(this, "change"));
205
                btnChangeProjection.addActionListener(new ActionListener() {
206
                        public void actionPerformed(ActionEvent e) {
207
                                CSSelectionDialog csSelect = new CSSelectionDialog();
208
                                csSelect.setProjection( CRSFactory.getCRS(
209
                                                lblDefaultProjection.getText()));
210
                                PluginServices.getMDIManager().addWindow(csSelect);
211

    
212
                        if (csSelect.isOkPressed()) {
213
                                IProjection proj = csSelect.getProjection();
214
                                lblDefaultProjection.setText(proj.getAbrev());
215
                        }
216
                        }
217
                });
218

    
219
                addComponent(PluginServices.getText(this, "default_projection") + ":", lblDefaultProjection );
220
                JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
221
                aux.add(btnChangeProjection);
222
                addComponent("", aux);
223

    
224
                // just a separator
225
                addComponent(new JLabel(" "));
226

    
227
                // Adding Invisible New Layers
228
                chkInvisibleNewLayers = new JCheckBox(
229
                                PluginServices.getText(this, "options.view.invisible_new_layers"));
230

    
231
                addComponent("", chkInvisibleNewLayers);
232
                chkKeepScaleOnResizing = new JCheckBox(
233
                                PluginServices.getText(this, "options.view.keep_scale_on_resizing"));
234
                chkKeepScaleOnResizing.setEnabled(false);
235
                addComponent("", chkKeepScaleOnResizing);
236

    
237
                // just a separator
238
                addComponent(new JLabel(" "));
239

    
240
                // zoom in factor
241
                addComponent(PluginServices.getText(this, "zoom_in_factor") + ":",
242
                        txtZoomInFactor = new JTextField("", 15));
243
                // zoom out factor
244
                addComponent(PluginServices.getText(this, "zoom_out_factor") + ":",
245
                        txtZoomOutFactor = new JTextField("", 15));
246

    
247
                // just a separator
248
                addComponent(new JLabel(" "));
249

    
250
                // default selection color
251
                jcp = new ColorChooserPanel();
252
                addComponent(PluginServices.getText(this, "options.view.default_selection_color"), jcp);
253
                initializeValues();
254
        }
255

    
256
        public void initializeValues() {
257
                PluginServices ps = PluginServices.getPluginServices(this);
258
                XMLEntity xml = ps.getPersistentXML();
259

    
260
                // Default Projection
261
                if (xml.contains(DEFAULT_PROJECTION_KEY_NAME)) {
262
                        lblDefaultProjection.setText(
263
                                xml.getStringProperty(DEFAULT_PROJECTION_KEY_NAME));
264
                } else {
265
                        lblDefaultProjection.setText(FACTORY_DEFAULT_PROJECTION);
266
                }
267
                Project.setDefaultProjection( CRSFactory.getCRS(lblDefaultProjection.getText()));
268

    
269
                // Adding invisible new layers
270
                if (xml.contains(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME)) {
271
                        chkInvisibleNewLayers.setSelected(
272
                                xml.getBooleanProperty(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME));
273
                }
274

    
275
                // Keep scale on resizing
276
                if (xml.contains(KEEP_SCALE_ON_RESIZING_KEY_NAME)) {
277
                        chkKeepScaleOnResizing.setSelected(
278
                                xml.getBooleanProperty(KEEP_SCALE_ON_RESIZING_KEY_NAME));
279
                }
280

    
281
                // Zoom-in factor
282
                if (xml.contains(ZOOM_IN_FACTOR_KEY_NAME)) {
283
                        double zoomInFactor = xml.getDoubleProperty(ZOOM_IN_FACTOR_KEY_NAME);
284
                        txtZoomInFactor.setText(String.valueOf( zoomInFactor ));
285
                } else {
286
                        txtZoomInFactor.setText(
287
                                String.valueOf( MapContext.ZOOMINFACTOR ));
288
                }
289
                MapContext.ZOOMINFACTOR = Double.parseDouble(txtZoomInFactor.getText());
290

    
291
                // Zoom-out factor
292
                if (xml.contains(ZOOM_OUT_FACTOR_KEY_NAME)) {
293
                        double zoomOutFactor = xml.getDoubleProperty(ZOOM_OUT_FACTOR_KEY_NAME);
294
                        txtZoomOutFactor.setText(String.valueOf( zoomOutFactor ));
295
                } else {
296
                        txtZoomOutFactor.setText(
297
                                String.valueOf( MapContext.ZOOMOUTFACTOR ));
298
                }
299
                MapContext.ZOOMOUTFACTOR = Double.parseDouble(txtZoomOutFactor.getText());;
300

    
301
                // Default selection color
302
                jcp.setColor(Project.getDefaultColor());
303
                jcp.setAlpha(255);
304

    
305
        }
306

    
307
        public String getID() {
308
                return id;
309
        }
310

    
311
        public String getTitle() {
312
                return PluginServices.getText(this, "Vista");
313
        }
314

    
315
        public JPanel getPanel() {
316
                return this;
317
        }
318

    
319
        public void storeValues() throws StoreException {
320
                String projName = lblDefaultProjection.getText();
321
                double zif;
322
                double zof;
323
                boolean invisibleNewLayers, keepScaleOnResize;
324
                Color color;
325
                try {
326
                        zif=Double.parseDouble(txtZoomInFactor.getText());
327
                        zof=Double.parseDouble(txtZoomOutFactor.getText());
328
                        color = jcp.getColor();
329
                        Project.setDefaultProjection( CRSFactory.getCRS(projName));
330
                        Project.setDefaultSelectionColor( color );
331
                        invisibleNewLayers = chkInvisibleNewLayers.isSelected();
332
                        keepScaleOnResize = chkKeepScaleOnResizing.isSelected();
333
                } catch (Exception e) {
334
                        throw new StoreException(PluginServices.getText(this,"factor_zoom_incorrecto"));
335
                }
336
                MapContext.ZOOMINFACTOR=zif;
337
                MapContext.ZOOMOUTFACTOR=zof;
338
                // MapControl.setScalingOnResize(!keepScaleOnResize);
339

    
340
                PluginServices ps = PluginServices.getPluginServices(this);
341
                XMLEntity xml = ps.getPersistentXML();
342
                xml.putProperty(DEFAULT_PROJECTION_KEY_NAME, projName);
343
                xml.putProperty(ZOOM_IN_FACTOR_KEY_NAME, zif);
344
                xml.putProperty(ZOOM_OUT_FACTOR_KEY_NAME, zof);
345
                xml.putProperty(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME, invisibleNewLayers);
346
                xml.putProperty(KEEP_SCALE_ON_RESIZING_KEY_NAME, keepScaleOnResize);
347
                xml.putProperty(DEFAULT_SELECTION_COLOR_KEY_NAME, StringUtilities.color2String(color));
348
        }
349

    
350

    
351
        public void initializeDefaults() {
352
                lblDefaultProjection.setText(FACTORY_DEFAULT_PROJECTION);
353
                txtZoomInFactor.setText(String.valueOf(DEFAULT_ZOOM_IN_FACTOR));
354
                txtZoomOutFactor.setText(String.valueOf(DEFAULT_ZOOM_OUT_FACTOR));
355
                chkInvisibleNewLayers.setSelected(false);
356
                chkKeepScaleOnResizing.setSelected(false);
357
                jcp.setColor(FACTORY_DEFAULT_SELECTION_COLOR);
358

    
359
        }
360

    
361
        public ImageIcon getIcon() {
362
                return icon;
363
        }
364

    
365
        public boolean isValueChanged() {
366
                return super.hasChanged();
367
        }
368

    
369
        public void setChangesApplied() {
370
                setChanged(false);
371
        }
372
}