Statistics
| Revision:

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

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

    
125
import java.awt.Color;
126
import java.awt.FlowLayout;
127
import java.awt.event.ActionEvent;
128
import java.awt.event.ActionListener;
129
import java.util.Enumeration;
130

    
131
import javax.swing.ImageIcon;
132
import javax.swing.JCheckBox;
133
import javax.swing.JLabel;
134
import javax.swing.JPanel;
135
import javax.swing.JTextField;
136
import javax.swing.SwingUtilities;
137
import javax.swing.UIManager;
138
import javax.swing.plaf.FontUIResource;
139

    
140
import org.cresques.cts.IProjection;
141
import org.gvsig.gui.beans.swing.JButton;
142

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

    
154
public class ViewPage extends AbstractPreferencePage {
155
        private static final String DEFAULT_PROJECTION_KEY_NAME = "DefaultProjection";
156
        private static final String FACTORY_DEFAULT_PROJECTION = "EPSG:23030";
157
        private static final String ZOOM_IN_FACTOR_KEY_NAME = "ZoomInFactor";
158
        private static final String ZOOM_OUT_FACTOR_KEY_NAME = "ZoomOutFactor";
159
        private static final String ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME = "NewLayersInInvisibleMode";
160
        private static final String KEEP_SCALE_ON_RESIZING_KEY_NAME = "KeepScaleOnResizing";
161
        private static final String DEFAULT_SELECTION_COLOR_KEY_NAME = "DefaultSelectionColor";
162

    
163
        private JTextField txtZoomInFactor;
164
        private JTextField txtZoomOutFactor;
165
        protected String id;
166
        private ImageIcon icon;
167
        private JLabel lblDefaultProjection;
168
        private JButton btnChangeProjection;
169
        private String fontName;
170
        private JCheckBox chkInvisibleNewLayers;
171
        private JCheckBox chkKeepScaleOnResizing;
172
        private ColorChooserPanel jcp;
173

    
174
        {
175
                Enumeration keys = UIManager.getDefaults().keys();
176
                while (keys.hasMoreElements()) {
177
                        Object key = keys.nextElement();
178
                        Object value = UIManager.get (key);
179
                        if (value instanceof FontUIResource) {
180
                                FontUIResource fur = (FontUIResource) value;
181
                                fontName = fur.getFontName();
182

    
183
                        }
184
                }
185
        }
186

    
187
        public ViewPage() {
188
                super();
189
                id = this.getClass().getName();
190
                icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/Vista.png"));
191

    
192

    
193
                // default projection
194
                lblDefaultProjection = new JLabel();
195
                lblDefaultProjection.setFont(new java.awt.Font(
196
                        fontName, java.awt.Font.BOLD, 11));
197
                btnChangeProjection = new JButton(PluginServices.getText(this, "change"));
198
                btnChangeProjection.addActionListener(new ActionListener() {
199
                        public void actionPerformed(ActionEvent e) {
200
                                CSSelectionDialog csSelect = new CSSelectionDialog();
201
                                csSelect.setProjection( CRSFactory.getCRS(
202
                                                lblDefaultProjection.getText()));
203
                                PluginServices.getMDIManager().addWindow(csSelect);
204

    
205
                        if (csSelect.isOkPressed()) {
206
                                IProjection proj = csSelect.getProjection();
207
                                lblDefaultProjection.setText(proj.getAbrev());
208
                        }
209
                        }
210
                });
211

    
212
                addComponent(PluginServices.getText(this, "default_projection") + ":", lblDefaultProjection );
213
                JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
214
                aux.add(btnChangeProjection);
215
                addComponent("", aux);
216

    
217
                // just a separator
218
                addComponent(new JLabel(" "));
219

    
220
                // Adding Invisible New Layers
221
                chkInvisibleNewLayers = new JCheckBox(
222
                                PluginServices.getText(this, "options.view.invisible_new_layers"));
223

    
224
                addComponent("", chkInvisibleNewLayers);
225
                chkKeepScaleOnResizing = new JCheckBox(
226
                                PluginServices.getText(this, "options.view.keep_scale_on_resizing"));
227
                chkKeepScaleOnResizing.setEnabled(false);
228
                addComponent("", chkKeepScaleOnResizing);
229

    
230
                // just a separator
231
                addComponent(new JLabel(" "));
232

    
233
                // zoom in factor
234
                addComponent(PluginServices.getText(this, "zoom_in_factor") + ":",
235
                        txtZoomInFactor = new JTextField("", 15));
236
                // zoom out factor
237
                addComponent(PluginServices.getText(this, "zoom_out_factor") + ":",
238
                        txtZoomOutFactor = new JTextField("", 15));
239

    
240
                // just a separator
241
                addComponent(new JLabel(" "));
242

    
243
                // default selection color
244
                jcp = new ColorChooserPanel();
245
                jcp.setColor(Project.getDefaultColor());
246
                jcp.setAlpha(255);
247
                addComponent(PluginServices.getText(this, "options.view.default_selection_color"), jcp);
248
                initializeValues();
249
        }
250

    
251
        public void initializeValues() {
252
                PluginServices ps = PluginServices.getPluginServices(this);
253
                XMLEntity xml = ps.getPersistentXML();
254

    
255
                // Default Projection
256
                if (xml.contains(DEFAULT_PROJECTION_KEY_NAME)) {
257
                        lblDefaultProjection.setText(
258
                                xml.getStringProperty(DEFAULT_PROJECTION_KEY_NAME));
259
                } else {
260
                        lblDefaultProjection.setText(FACTORY_DEFAULT_PROJECTION);
261
                }
262
                Project.setDefaultProjection( CRSFactory.getCRS(lblDefaultProjection.getText()));
263

    
264
                // Adding invisible new layers
265
                if (xml.contains(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME)) {
266
                        chkInvisibleNewLayers.setSelected(
267
                                xml.getBooleanProperty(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME));
268
                }
269

    
270
                // Keep scale on resizing
271
                if (xml.contains(KEEP_SCALE_ON_RESIZING_KEY_NAME)) {
272
                        chkKeepScaleOnResizing.setSelected(
273
                                xml.getBooleanProperty(KEEP_SCALE_ON_RESIZING_KEY_NAME));
274
                }
275

    
276
                // Zoom-in factor
277
                if (xml.contains(ZOOM_IN_FACTOR_KEY_NAME)) {
278
                        double zoomInFactor = xml.getDoubleProperty(ZOOM_IN_FACTOR_KEY_NAME);
279
                        txtZoomInFactor.setText(String.valueOf( zoomInFactor ));
280
                } else {
281
                        txtZoomInFactor.setText(
282
                                String.valueOf( MapContext.ZOOMINFACTOR ));
283
                }
284
                MapContext.ZOOMINFACTOR = Double.parseDouble(txtZoomInFactor.getText());
285

    
286
                // Zoom-out factor
287
                if (xml.contains(ZOOM_OUT_FACTOR_KEY_NAME)) {
288
                        double zoomOutFactor = xml.getDoubleProperty(ZOOM_OUT_FACTOR_KEY_NAME);
289
                        txtZoomOutFactor.setText(String.valueOf( zoomOutFactor ));
290
                } else {
291
                        txtZoomOutFactor.setText(
292
                                String.valueOf( MapContext.ZOOMOUTFACTOR ));
293
                }
294
                MapContext.ZOOMOUTFACTOR = Double.parseDouble(txtZoomOutFactor.getText());;
295

    
296
        }
297

    
298
        public String getID() {
299
                return id;
300
        }
301

    
302
        public String getTitle() {
303
                return PluginServices.getText(this, "Vista");
304
        }
305

    
306
        public JPanel getPanel() {
307
                return this;
308
        }
309

    
310
        public void storeValues() throws StoreException {
311
                String projName = lblDefaultProjection.getText();
312
                double zif;
313
                double zof;
314
                boolean invisibleNewLayers, keepScaleOnResize;
315
                Color color;
316
                try {
317
                        zif=Double.parseDouble(txtZoomInFactor.getText());
318
                        zof=Double.parseDouble(txtZoomOutFactor.getText());
319
                        color = jcp.getColor();
320
                        Project.setDefaultProjection( CRSFactory.getCRS(projName));
321
                        Project.setDefaultSelectionColor( color );
322
                        invisibleNewLayers = chkInvisibleNewLayers.isSelected();
323
                        keepScaleOnResize = chkKeepScaleOnResizing.isSelected();
324
                } catch (Exception e) {
325
                        throw new StoreException(PluginServices.getText(this,"factor_zoom_incorrecto"));
326
                }
327
                MapContext.ZOOMINFACTOR=zif;
328
                MapContext.ZOOMOUTFACTOR=zof;
329
                // MapControl.setScalingOnResize(!keepScaleOnResize);
330

    
331
                PluginServices ps = PluginServices.getPluginServices(this);
332
                XMLEntity xml = ps.getPersistentXML();
333
                xml.putProperty(DEFAULT_PROJECTION_KEY_NAME, projName);
334
                xml.putProperty(ZOOM_IN_FACTOR_KEY_NAME, zif);
335
                xml.putProperty(ZOOM_OUT_FACTOR_KEY_NAME, zof);
336
                xml.putProperty(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME, invisibleNewLayers);
337
                xml.putProperty(KEEP_SCALE_ON_RESIZING_KEY_NAME, keepScaleOnResize);
338
                xml.putProperty(DEFAULT_SELECTION_COLOR_KEY_NAME, StringUtilities.color2String(color));
339
        }
340

    
341

    
342
        public void initializeDefaults() {
343
                lblDefaultProjection.setText(FACTORY_DEFAULT_PROJECTION);
344
                txtZoomInFactor.setText(String.valueOf(MapContext.ZOOMINFACTOR));
345
                txtZoomOutFactor.setText(String.valueOf(MapContext.ZOOMOUTFACTOR));
346
                chkInvisibleNewLayers.setSelected(false);
347
                chkKeepScaleOnResizing.setSelected(false);
348
        }
349

    
350
        public ImageIcon getIcon() {
351
                return icon;
352
        }
353

    
354
        public boolean isValueChanged() {
355
                return super.hasChanged();
356
        }
357

    
358
        public void setChangesApplied() {
359
                setChanged(false);
360
        }
361
}