Statistics
| Revision:

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

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

    
137
import java.awt.Color;
138
import java.awt.FlowLayout;
139
import java.awt.event.ActionEvent;
140
import java.awt.event.ActionListener;
141
import java.util.Enumeration;
142

    
143
import javax.swing.ImageIcon;
144
import javax.swing.JCheckBox;
145
import javax.swing.JLabel;
146
import javax.swing.JPanel;
147
import javax.swing.JTextField;
148
import javax.swing.UIManager;
149
import javax.swing.plaf.FontUIResource;
150

    
151
import org.cresques.cts.IProjection;
152
import org.gvsig.gui.beans.swing.JButton;
153

    
154
import com.iver.andami.PluginServices;
155
import com.iver.andami.preferences.AbstractPreferencePage;
156
import com.iver.andami.preferences.StoreException;
157
import com.iver.cit.gvsig.fmap.MapContext;
158
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
159
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
160
import com.iver.cit.gvsig.project.Project;
161
import com.iver.cit.gvsig.project.documents.view.info.gui.CSSelectionDialog;
162
import com.iver.utiles.StringUtilities;
163
import com.iver.utiles.XMLEntity;
164

    
165
public class ViewPage extends AbstractPreferencePage {
166
        private static final String DEFAULT_PROJECTION_KEY_NAME = "DefaultProjection";
167
        private static final String FACTORY_DEFAULT_PROJECTION = "EPSG:23030";
168
        private static final String ZOOM_IN_FACTOR_KEY_NAME = "ZoomInFactor";
169
        private static final String ZOOM_OUT_FACTOR_KEY_NAME = "ZoomOutFactor";
170
        private static final String ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME = "NewLayersInInvisibleMode";
171
        private static final String KEEP_SCALE_ON_RESIZING_KEY_NAME = "KeepScaleOnResizing";
172
        private static final String DEFAULT_SELECTION_COLOR_KEY_NAME = "DefaultSelectionColor";
173
        private static final String DEFAULT_VIEW_BACK_COLOR_KEY_NAME = "DefaultViewBackColor";
174
        /*
175
         * Locator's background color, for when we let it be possible
176
         * private static final String DEFAULT_MAP_OVERVIEW_BACK_COLOR_KEY_NAME = "DefaultMapOverViewBackColor";
177
         */
178
        private static final double DEFAULT_ZOOM_IN_FACTOR = 2.0;
179
        private static final double DEFAULT_ZOOM_OUT_FACTOR = 0.5;
180
        private static final Color FACTORY_DEFAULT_SELECTION_COLOR = Color.YELLOW;
181
        private static final Color FACTORY_DEFAULT_VIEW_BACK_COLOR = Color.WHITE;
182
        /*
183
         * Locator's background color, for when we let it be possible
184
         * private static final Color FACTORY_DEFAULT_MAP_OVERVIEW_BACK_COLOR = Color.WHITE;
185
         */
186

    
187
        private JTextField txtZoomInFactor;
188
        private JTextField txtZoomOutFactor;
189
        protected String id;
190
        private ImageIcon icon;
191
        private JLabel lblDefaultProjection;
192
        private JButton btnChangeProjection;
193
        private String fontName;
194
        private JCheckBox chkInvisibleNewLayers;
195
        private JCheckBox chkKeepScaleOnResizing;
196
        private ColorChooserPanel jccDefaultSelectionColor;
197
        private ColorChooserPanel jccDefaultViewBackColor;
198
        private ColorChooserPanel jccDefaultMapOverViewBackColor;
199

    
200
        {
201
                Enumeration keys = UIManager.getDefaults().keys();
202
                while (keys.hasMoreElements()) {
203
                        Object key = keys.nextElement();
204
                        Object value = UIManager.get (key);
205
                        if (value instanceof FontUIResource) {
206
                                FontUIResource fur = (FontUIResource) value;
207
                                fontName = fur.getFontName();
208

    
209
                        }
210
                }
211
        }
212

    
213
        public ViewPage() {
214
                super();
215
                id = this.getClass().getName();
216
                icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/Vista.png"));
217

    
218

    
219
                // default projection
220
                lblDefaultProjection = new JLabel();
221
                lblDefaultProjection.setFont(new java.awt.Font(
222
                        fontName, java.awt.Font.BOLD, 11));
223
                btnChangeProjection = new JButton(PluginServices.getText(this, "change"));
224
                btnChangeProjection.addActionListener(new ActionListener() {
225
                        public void actionPerformed(ActionEvent e) {
226
                                CSSelectionDialog csSelect = new CSSelectionDialog();
227
                                csSelect.setProjection( CRSFactory.getCRS(
228
                                                lblDefaultProjection.getText()));
229
                                PluginServices.getMDIManager().addWindow(csSelect);
230

    
231
                        if (csSelect.isOkPressed()) {
232
                                IProjection proj = csSelect.getProjection();
233
                                lblDefaultProjection.setText(proj.getAbrev());
234
                        }
235
                        }
236
                });
237

    
238
                addComponent(PluginServices.getText(this, "default_projection") + ":", lblDefaultProjection );
239
                JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
240
                aux.add(btnChangeProjection);
241
                addComponent("", aux);
242

    
243
                // just a separator
244
                addComponent(new JLabel(" "));
245

    
246
                // Adding Invisible New Layers
247
                chkInvisibleNewLayers = new JCheckBox(
248
                                PluginServices.getText(this, "options.view.invisible_new_layers"));
249

    
250
                addComponent("", chkInvisibleNewLayers);
251
                chkKeepScaleOnResizing = new JCheckBox(
252
                                PluginServices.getText(this, "options.view.keep_scale_on_resizing"));
253
                chkKeepScaleOnResizing.setEnabled(false);
254
                addComponent("", chkKeepScaleOnResizing);
255

    
256
                // just a separator
257
                addComponent(new JLabel(" "));
258

    
259
                // zoom in factor
260
                addComponent(PluginServices.getText(this, "zoom_in_factor") + ":",
261
                        txtZoomInFactor = new JTextField("", 15));
262
                // zoom out factor
263
                addComponent(PluginServices.getText(this, "zoom_out_factor") + ":",
264
                        txtZoomOutFactor = new JTextField("", 15));
265

    
266
                // just a separator
267
                addComponent(new JLabel(" "));
268

    
269
                // default back color chooser
270
                jccDefaultViewBackColor = new ColorChooserPanel();
271
                addComponent(PluginServices.getText(this, "options.view.default_view_back_color"), jccDefaultViewBackColor);
272

    
273
                /*
274
                 * Locator's background color, for when we let it be possible
275
                 * // default back color chooser
276
                 * jccDefaultMapOverViewBackColor = new ColorChooserPanel();
277
                 * addComponent(PluginServices.getText(this, "options.view.default_map_overview_back_color"), jccDefaultMapOverViewBackColor);
278
                 */
279

    
280
                // default selection color chooser
281
                jccDefaultSelectionColor = new ColorChooserPanel();
282
                addComponent(PluginServices.getText(this, "options.view.default_selection_color"), jccDefaultSelectionColor);
283

    
284
                initializeValues();
285
        }
286

    
287
        public void initializeValues() {
288
                PluginServices ps = PluginServices.getPluginServices(this);
289
                XMLEntity xml = ps.getPersistentXML();
290

    
291
                // Default Projection
292
                if (xml.contains(DEFAULT_PROJECTION_KEY_NAME)) {
293
                        lblDefaultProjection.setText(
294
                                xml.getStringProperty(DEFAULT_PROJECTION_KEY_NAME));
295
                } else {
296
                        lblDefaultProjection.setText(FACTORY_DEFAULT_PROJECTION);
297
                }
298
                Project.setDefaultProjection( CRSFactory.getCRS(lblDefaultProjection.getText()));
299

    
300
                // Adding invisible new layers
301
                if (xml.contains(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME)) {
302
                        chkInvisibleNewLayers.setSelected(
303
                                xml.getBooleanProperty(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME));
304
                }
305

    
306
                // Keep scale on resizing
307
                if (xml.contains(KEEP_SCALE_ON_RESIZING_KEY_NAME)) {
308
                        chkKeepScaleOnResizing.setSelected(
309
                                xml.getBooleanProperty(KEEP_SCALE_ON_RESIZING_KEY_NAME));
310
                }
311

    
312
                // Zoom-in factor
313
                if (xml.contains(ZOOM_IN_FACTOR_KEY_NAME)) {
314
                        double zoomInFactor = xml.getDoubleProperty(ZOOM_IN_FACTOR_KEY_NAME);
315
                        txtZoomInFactor.setText(String.valueOf( zoomInFactor ));
316
                } else {
317
                        txtZoomInFactor.setText(
318
                                String.valueOf( MapContext.ZOOMINFACTOR ));
319
                }
320
                MapContext.ZOOMINFACTOR = Double.parseDouble(txtZoomInFactor.getText());
321

    
322
                // Zoom-out factor
323
                if (xml.contains(ZOOM_OUT_FACTOR_KEY_NAME)) {
324
                        double zoomOutFactor = xml.getDoubleProperty(ZOOM_OUT_FACTOR_KEY_NAME);
325
                        txtZoomOutFactor.setText(String.valueOf( zoomOutFactor ));
326
                } else {
327
                        txtZoomOutFactor.setText(
328
                                String.valueOf( MapContext.ZOOMOUTFACTOR ));
329
                }
330
                MapContext.ZOOMOUTFACTOR = Double.parseDouble(txtZoomOutFactor.getText());;
331

    
332
                // Default back color
333
                jccDefaultViewBackColor.setColor(Project.getDefaultViewBackColor());
334
                jccDefaultViewBackColor.setAlpha(255);
335
                /*
336
                 * Locator's background color, for when we let it be possible
337
                 * // Default map overview back color
338
                 * jccDefaultMapOverViewBackColor.setColor(Project.getDefaultMapOverViewBackColor());
339
                 * jccDefaultMapOverViewBackColor.setAlpha(255);
340
                 */
341

    
342
                // Default selection color
343
                jccDefaultSelectionColor.setColor(Project.getDefaultSelectionColor());
344
                jccDefaultSelectionColor.setAlpha(255);
345

    
346
        }
347

    
348
        public String getID() {
349
                return id;
350
        }
351

    
352
        public String getTitle() {
353
                return PluginServices.getText(this, "Vista");
354
        }
355

    
356
        public JPanel getPanel() {
357
                return this;
358
        }
359

    
360
        public void storeValues() throws StoreException {
361
                String projName = lblDefaultProjection.getText();
362
                double zif;
363
                double zof;
364
                boolean invisibleNewLayers, keepScaleOnResize;
365
                Color selectionColor, viewBackColor;
366
                /*
367
                 * Locator's background color, for when we let it be possible
368
                 * Color mapOverViewBackColor;
369
                 */
370

    
371
                try {
372
                        zif=Double.parseDouble(txtZoomInFactor.getText());
373
                        zof=Double.parseDouble(txtZoomOutFactor.getText());
374

    
375
                        Project.setDefaultProjection( CRSFactory.getCRS(projName));
376

    
377
                        selectionColor = jccDefaultSelectionColor.getColor();
378
                        Project.setDefaultSelectionColor( selectionColor );
379

    
380
                        viewBackColor = jccDefaultViewBackColor.getColor();
381
                        Project.setDefaultViewBackColor( viewBackColor );
382
                        /*
383
                         * Locator's background color, for when we let it be possible
384
                         * mapOverViewBackColor = jccDefaultMapOverViewBackColor.getColor();
385
                         * Project.setDefaultMapOverViewBackColor( mapOverViewBackColor );
386
                         */
387

    
388
                        invisibleNewLayers = chkInvisibleNewLayers.isSelected();
389
                        keepScaleOnResize = chkKeepScaleOnResizing.isSelected();
390
                } catch (Exception e) {
391
                        throw new StoreException(PluginServices.getText(this,"factor_zoom_incorrecto"));
392
                }
393
                MapContext.ZOOMINFACTOR=zif;
394
                MapContext.ZOOMOUTFACTOR=zof;
395
                // MapControl.setScalingOnResize(!keepScaleOnResize);
396

    
397
                PluginServices ps = PluginServices.getPluginServices(this);
398
                XMLEntity xml = ps.getPersistentXML();
399
                xml.putProperty(DEFAULT_PROJECTION_KEY_NAME, projName);
400
                xml.putProperty(ZOOM_IN_FACTOR_KEY_NAME, zif);
401
                xml.putProperty(ZOOM_OUT_FACTOR_KEY_NAME, zof);
402
                xml.putProperty(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME, invisibleNewLayers);
403
                xml.putProperty(KEEP_SCALE_ON_RESIZING_KEY_NAME, keepScaleOnResize);
404
                xml.putProperty(DEFAULT_VIEW_BACK_COLOR_KEY_NAME, StringUtilities.color2String(viewBackColor));
405
                /*
406
                 * Locator's background color, for when we let it be possible
407
                 * xml.putProperty(DEFAULT_MAP_OVERVIEW_BACK_COLOR_KEY_NAME, StringUtilities.color2String(mapOverViewBackColor));
408
                 */
409
                xml.putProperty(DEFAULT_SELECTION_COLOR_KEY_NAME, StringUtilities.color2String(selectionColor));
410
        }
411

    
412

    
413
        public void initializeDefaults() {
414
                lblDefaultProjection.setText(FACTORY_DEFAULT_PROJECTION);
415
                txtZoomInFactor.setText(String.valueOf(DEFAULT_ZOOM_IN_FACTOR));
416
                txtZoomOutFactor.setText(String.valueOf(DEFAULT_ZOOM_OUT_FACTOR));
417
                chkInvisibleNewLayers.setSelected(false);
418
                chkKeepScaleOnResizing.setSelected(false);
419
                jccDefaultSelectionColor.setColor(FACTORY_DEFAULT_SELECTION_COLOR);
420
                /*
421
                 * Locator's background color, for when we let it be possible
422
                 * jccDefaultViewBackColor.setColor(FACTORY_DEFAULT_VIEW_BACK_COLOR);
423
                 */
424
        }
425

    
426
        public ImageIcon getIcon() {
427
                return icon;
428
        }
429

    
430
        public boolean isValueChanged() {
431
                return super.hasChanged();
432
        }
433

    
434
        public void setChangesApplied() {
435
                setChanged(false);
436
        }
437
}