Statistics
| Revision:

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

History | View | Annotate | Download (17 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 9392 2006-12-20 14:50:10Z caballero $
45
* $Log$
46
* Revision 1.22  2006-12-20 14:41:12  caballero
47
* Remodelado Layout
48
*
49
* Revision 1.21  2006/11/08 10:57:55  jaume
50
* remove unecessary imports
51
*
52
* Revision 1.20  2006/10/25 08:34:06  jmvivo
53
* LLamado al PluginServices.getText para las unidades de medida del los combo
54
*
55
* Revision 1.19  2006/10/04 07:23:31  jaume
56
* refactored ambiguous methods and field names and added some more features for preference pages
57
*
58
* Revision 1.18  2006/10/03 09:52:38  jaume
59
* restores to meters
60
*
61
* Revision 1.17  2006/10/03 09:19:12  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.16  2006/10/03 07:26:08  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.15  2006/10/02 15:30:29  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.14  2006/10/02 13:52:34  jaume
71
* organize impots
72
*
73
* Revision 1.13  2006/10/02 13:38:23  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.12  2006/10/02 11:49:23  jaume
77
* *** empty log message ***
78
*
79
* Revision 1.11  2006/09/28 12:04:21  jaume
80
* default selection color now configurable
81
*
82
* Revision 1.10  2006/09/25 10:17:15  caballero
83
* Projection
84
*
85
* Revision 1.9  2006/09/15 10:41:30  caballero
86
* extensibilidad de documentos
87
*
88
* Revision 1.8  2006/09/14 15:43:48  jaume
89
* *** empty log message ***
90
*
91
* Revision 1.7  2006/09/14 15:42:38  jaume
92
* *** empty log message ***
93
*
94
* Revision 1.6  2006/09/14 06:57:18  jaume
95
* *** empty log message ***
96
*
97
* Revision 1.5  2006/09/12 15:56:50  jaume
98
* Default Projection now customizable
99
*
100
* Revision 1.4  2006/08/29 07:21:08  cesar
101
* Rename com.iver.cit.gvsig.fmap.Fmap class to com.iver.cit.gvsig.fmap.MapContext
102
*
103
* Revision 1.3  2006/08/22 12:30:59  jaume
104
* *** empty log message ***
105
*
106
* Revision 1.2  2006/08/22 07:36:04  jaume
107
* *** empty log message ***
108
*
109
* Revision 1.1  2006/08/04 11:41:05  caballero
110
* poder especificar el zoom a aplicar en las vistas
111
*
112
* Revision 1.3  2006/07/31 10:02:31  jaume
113
* *** empty log message ***
114
*
115
* Revision 1.2  2006/06/13 07:43:08  fjp
116
* Ajustes sobre los cuadros de dialogos de preferencias
117
*
118
* Revision 1.1  2006/06/12 16:04:28  caballero
119
* Preferencias
120
*
121
* Revision 1.11  2006/06/06 10:26:31  jaume
122
* *** empty log message ***
123
*
124
* Revision 1.10  2006/06/05 17:07:17  jaume
125
* *** empty log message ***
126
*
127
* Revision 1.9  2006/06/05 17:00:44  jaume
128
* *** empty log message ***
129
*
130
* Revision 1.8  2006/06/05 16:57:59  jaume
131
* *** empty log message ***
132
*
133
* Revision 1.7  2006/06/05 14:45:06  jaume
134
* *** empty log message ***
135
*
136
* Revision 1.6  2006/06/05 11:00:09  jaume
137
* *** empty log message ***
138
*
139
* Revision 1.5  2006/06/05 10:39:02  jaume
140
* *** empty log message ***
141
*
142
* Revision 1.4  2006/06/05 10:13:40  jaume
143
* *** empty log message ***
144
*
145
* Revision 1.3  2006/06/05 10:06:08  jaume
146
* *** empty log message ***
147
*
148
* Revision 1.2  2006/06/05 09:51:56  jaume
149
* *** empty log message ***
150
*
151
* Revision 1.1  2006/06/02 10:50:18  jaume
152
* *** empty log message ***
153
*
154
*
155
*/
156
package com.iver.cit.gvsig.gui.preferencespage;
157

    
158
import java.awt.Color;
159
import java.awt.FlowLayout;
160
import java.awt.event.ActionEvent;
161
import java.awt.event.ActionListener;
162
import java.util.Enumeration;
163

    
164
import javax.swing.ImageIcon;
165
import javax.swing.JCheckBox;
166
import javax.swing.JLabel;
167
import javax.swing.JPanel;
168
import javax.swing.JTextField;
169
import javax.swing.UIManager;
170
import javax.swing.plaf.FontUIResource;
171

    
172
import org.cresques.cts.IProjection;
173
import org.gvsig.gui.beans.swing.JButton;
174

    
175
import com.iver.andami.PluginServices;
176
import com.iver.andami.preferences.AbstractPreferencePage;
177
import com.iver.andami.preferences.StoreException;
178
import com.iver.cit.gvsig.fmap.MapContext;
179
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
180
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
181
import com.iver.cit.gvsig.project.Project;
182
import com.iver.cit.gvsig.project.documents.layout.Attributes;
183
import com.iver.cit.gvsig.project.documents.view.gui.View;
184
import com.iver.cit.gvsig.project.documents.view.info.gui.CSSelectionDialog;
185
import com.iver.utiles.StringUtilities;
186
import com.iver.utiles.XMLEntity;
187
import com.iver.utiles.swing.JComboBox;
188
/**
189
 *  View document configuration page.
190
 *  <b><b>
191
 *  Here the user can establish what settings wants to use by default regarding to
192
 *  the document View.
193
 *
194
 *
195
 * @author jaume dominguez faus - jaume.dominguez@iver.es
196
 */
197
public class ViewPage extends AbstractPreferencePage {
198

    
199
        private static final String DEFAULT_PROJECTION_KEY_NAME = "DefaultProjection";
200
        private static final String FACTORY_DEFAULT_PROJECTION = "EPSG:23030";
201
        private static final String ZOOM_IN_FACTOR_KEY_NAME = "ZoomInFactor";
202
        private static final String ZOOM_OUT_FACTOR_KEY_NAME = "ZoomOutFactor";
203
        private static final String ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME = "NewLayersInInvisibleMode";
204
        private static final String KEEP_SCALE_ON_RESIZING_KEY_NAME = "KeepScaleOnResizing";
205
        private static final String DEFAULT_SELECTION_COLOR_KEY_NAME = "DefaultSelectionColor";
206
        private static final String DEFAULT_VIEW_BACK_COLOR_KEY_NAME = "DefaultViewBackColor";
207
        private static final String DEFAULT_DISTANCE_UNITS_KEY_NAME = "DefaultDistanceUnits";
208
        private static final String DEFAULT_MAP_UNITS_KEY_NAME = "DefaultMapUnits";
209
        /*
210
         * Locator's background color, for when we let it be possible
211
         * private static final String DEFAULT_MAP_OVERVIEW_BACK_COLOR_KEY_NAME = "DefaultMapOverViewBackColor";
212
         */
213
        private static final double DEFAULT_ZOOM_IN_FACTOR = 2.0;
214
        private static final double DEFAULT_ZOOM_OUT_FACTOR = 0.5;
215
        private static final Color FACTORY_DEFAULT_SELECTION_COLOR = Color.YELLOW;
216
        private static final Color FACTORY_DEFAULT_VIEW_BACK_COLOR = Color.WHITE;
217
        /*
218
         * Locator's background color, for when we let it be possible
219
         * private static final Color FACTORY_DEFAULT_MAP_OVERVIEW_BACK_COLOR = Color.WHITE;
220
         */
221
        
222
        private static String[] unitsNames = null;
223
        
224
        private static int FACTORY_DEFAULT_MAP_UNITS;
225
        private static int FACTORY_DEFAULT_DISTANCE_UNITS;
226

    
227
        private JTextField txtZoomInFactor;
228
        private JTextField txtZoomOutFactor;
229
        protected String id;
230
        private ImageIcon icon;
231
        private JLabel lblDefaultProjection;
232
        private JButton btnChangeProjection;
233
        private String fontName;
234
        private JCheckBox chkInvisibleNewLayers;
235
        private JCheckBox chkKeepScaleOnResizing;
236
        private ColorChooserPanel jccDefaultSelectionColor;
237
        private ColorChooserPanel jccDefaultViewBackColor;
238
        private JComboBox jCmbMapUnits;
239
        private JComboBox jCmbDistanceUnits;
240
        /*
241
         * Locator's background color, for when we let it be possible
242
         * private ColorChooserPanel jccDefaultMapOverViewBackColor;
243
         */
244

    
245
        {
246
                Enumeration keys = UIManager.getDefaults().keys();
247
                while (keys.hasMoreElements()) {
248
                        Object key = keys.nextElement();
249
                        Object value = UIManager.get (key);
250
                        if (value instanceof FontUIResource) {
251
                                FontUIResource fur = (FontUIResource) value;
252
                                fontName = fur.getFontName();
253

    
254
                        }
255
                }
256

    
257
                String[] unitNames = Attributes.NAMES;
258
                for (int i = 0; i < unitNames.length; i++) {
259
                        if (unitNames[i].equals(PluginServices.getText(this, "Metros"))) {
260
                                FACTORY_DEFAULT_DISTANCE_UNITS = i;
261
                                FACTORY_DEFAULT_MAP_UNITS = i;
262
                                break;
263
                        }
264
                }
265

    
266
        }
267

    
268
        /**
269
         * Creates a new panel containing View preferences settings.
270
         *
271
         */
272
        public ViewPage() {
273
                super();
274
                id = this.getClass().getName();
275
                icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/Vista.png"));
276

    
277

    
278
                // default projection
279
                lblDefaultProjection = new JLabel();
280
                lblDefaultProjection.setFont(new java.awt.Font(
281
                        fontName, java.awt.Font.BOLD, 11));
282
                btnChangeProjection = new JButton(PluginServices.getText(this, "change"));
283
                btnChangeProjection.addActionListener(new ActionListener() {
284
                        public void actionPerformed(ActionEvent e) {
285
                                CSSelectionDialog csSelect = new CSSelectionDialog();
286
                                csSelect.setProjection( CRSFactory.getCRS(
287
                                                lblDefaultProjection.getText()));
288
                                PluginServices.getMDIManager().addWindow(csSelect);
289

    
290
                        if (csSelect.isOkPressed()) {
291
                                IProjection proj = csSelect.getProjection();
292
                                lblDefaultProjection.setText(proj.getAbrev());
293
                        }
294
                        }
295
                });
296

    
297
                addComponent(PluginServices.getText(this, "default_projection") + ":", lblDefaultProjection );
298
                JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
299
                aux.add(btnChangeProjection);
300
                addComponent("", aux);
301

    
302
                // just a separator
303
                addComponent(new JLabel(" "));
304

    
305
                // Adding Invisible New Layers
306
                chkInvisibleNewLayers = new JCheckBox(
307
                                PluginServices.getText(this, "options.view.invisible_new_layers"));
308

    
309
                addComponent("", chkInvisibleNewLayers);
310
                chkKeepScaleOnResizing = new JCheckBox(
311
                                PluginServices.getText(this, "options.view.keep_scale_on_resizing"));
312
                chkKeepScaleOnResizing.setEnabled(false);
313
                addComponent("", chkKeepScaleOnResizing);
314

    
315
                // just a separator
316
                addComponent(new JLabel(" "));
317

    
318
                // zoom in factor
319
                addComponent(PluginServices.getText(this, "zoom_in_factor") + ":",
320
                        txtZoomInFactor = new JTextField("", 15));
321
                // zoom out factor
322
                addComponent(PluginServices.getText(this, "zoom_out_factor") + ":",
323
                        txtZoomOutFactor = new JTextField("", 15));
324

    
325
                // just a separator
326
                addComponent(new JLabel(" "));
327

    
328
                // default back color chooser
329
                addComponent(PluginServices.getText(this, "options.view.default_view_back_color"),
330
                                jccDefaultViewBackColor = new ColorChooserPanel());
331

    
332
                /*
333
                 * Locator's background color, for when we let it be possible
334
                 * // default back color chooser
335
                 * addComponent(PluginServices.getText(this, "options.view.default_map_overview_back_color"), jccDefaultMapOverViewBackColor = new ColorChooserPanel());
336
                 */
337

    
338
                // default selection color chooser
339
                addComponent(PluginServices.getText(this, "options.view.default_selection_color"),
340
                                jccDefaultSelectionColor = new ColorChooserPanel());
341

    
342
                // just a separator
343
                addComponent(new JLabel(" "));
344

    
345
                // default map units
346
                addComponent(PluginServices.getText(this, "map_units"),
347
                                jCmbMapUnits = new JComboBox(getUnitsNames()));
348

    
349
                // default distance units
350
                addComponent(PluginServices.getText(this, "distance_units"),
351
                                jCmbDistanceUnits = new JComboBox(getUnitsNames()));
352

    
353
                initializeValues();
354
        }
355

    
356
        public void initializeValues() {
357
                PluginServices ps = PluginServices.getPluginServices(this);
358
                XMLEntity xml = ps.getPersistentXML();
359

    
360
                // Default Projection
361
                if (xml.contains(DEFAULT_PROJECTION_KEY_NAME)) {
362
                        lblDefaultProjection.setText(
363
                                xml.getStringProperty(DEFAULT_PROJECTION_KEY_NAME));
364
                } else {
365
                        lblDefaultProjection.setText(FACTORY_DEFAULT_PROJECTION);
366
                }
367
                Project.setDefaultProjection( CRSFactory.getCRS(lblDefaultProjection.getText()));
368

    
369
                // Adding invisible new layers
370
                if (xml.contains(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME)) {
371
                        chkInvisibleNewLayers.setSelected(
372
                                xml.getBooleanProperty(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME));
373
                }
374

    
375
                // Keep scale on resizing
376
                if (xml.contains(KEEP_SCALE_ON_RESIZING_KEY_NAME)) {
377
                        chkKeepScaleOnResizing.setSelected(
378
                                xml.getBooleanProperty(KEEP_SCALE_ON_RESIZING_KEY_NAME));
379
                }
380

    
381
                // Zoom-in factor
382
                if (xml.contains(ZOOM_IN_FACTOR_KEY_NAME)) {
383
                        double zoomInFactor = xml.getDoubleProperty(ZOOM_IN_FACTOR_KEY_NAME);
384
                        txtZoomInFactor.setText(String.valueOf( zoomInFactor ));
385
                } else {
386
                        txtZoomInFactor.setText(
387
                                String.valueOf( MapContext.ZOOMINFACTOR ));
388
                }
389
                MapContext.ZOOMINFACTOR = Double.parseDouble(txtZoomInFactor.getText());
390

    
391
                // Zoom-out factor
392
                if (xml.contains(ZOOM_OUT_FACTOR_KEY_NAME)) {
393
                        double zoomOutFactor = xml.getDoubleProperty(ZOOM_OUT_FACTOR_KEY_NAME);
394
                        txtZoomOutFactor.setText(String.valueOf( zoomOutFactor ));
395
                } else {
396
                        txtZoomOutFactor.setText(
397
                                String.valueOf( MapContext.ZOOMOUTFACTOR ));
398
                }
399
                MapContext.ZOOMOUTFACTOR = Double.parseDouble(txtZoomOutFactor.getText());;
400

    
401
                // Default back color
402
                jccDefaultViewBackColor.setColor(View.getDefaultBackColor());
403
                jccDefaultViewBackColor.setAlpha(255);
404
                /*
405
                 * Locator's background color, for when we let it be possible
406
                 * // Default map overview back color
407
                 * jccDefaultMapOverViewBackColor.setColor(Project.getDefaultMapOverViewBackColor());
408
                 * jccDefaultMapOverViewBackColor.setAlpha(255);
409
                 */
410

    
411
                // Default selection color
412
                jccDefaultSelectionColor.setColor(Project.getDefaultSelectionColor());
413
                jccDefaultSelectionColor.setAlpha(255);
414

    
415
                // Map units
416
                jCmbMapUnits.setSelectedIndex(Project.getDefaultMapUnits());
417

    
418
                // Distance units
419
                jCmbDistanceUnits.setSelectedIndex(Project.getDefaultDistanceUnits());
420

    
421
        }
422

    
423
        public String getID() {
424
                return id;
425
        }
426

    
427
        public String getTitle() {
428
                return PluginServices.getText(this, "Vista");
429
        }
430

    
431
        public JPanel getPanel() {
432
                return this;
433
        }
434

    
435
        public void storeValues() throws StoreException {
436
                String projName = lblDefaultProjection.getText();
437
                double zif;
438
                double zof;
439
                boolean invisibleNewLayers, keepScaleOnResize;
440
                Color selectionColor, viewBackColor;
441
                /*
442
                 * Locator's background color, for when we let it be possible
443
                 * Color mapOverViewBackColor;
444
                 */
445

    
446
                try {
447
                        zif=Double.parseDouble(txtZoomInFactor.getText());
448
                        zof=Double.parseDouble(txtZoomOutFactor.getText());
449

    
450
                        Project.setDefaultProjection( CRSFactory.getCRS(projName));
451

    
452
                        selectionColor = jccDefaultSelectionColor.getColor();
453
                        Project.setDefaultSelectionColor( selectionColor );
454

    
455
                        viewBackColor = jccDefaultViewBackColor.getColor();
456
                        View.setDefaultBackColor( viewBackColor );
457
                        /*
458
                         * Locator's background color, for when we let it be possible
459
                         * mapOverViewBackColor = jccDefaultMapOverViewBackColor.getColor();
460
                         * View.setDefaultMapOverViewBackColor( mapOverViewBackColor );
461
                         */
462

    
463
                        Project.setDefaultMapUnits(jCmbMapUnits.getSelectedIndex());
464
                        Project.setDefaultDistanceUnits(jCmbDistanceUnits.getSelectedIndex());
465
                        invisibleNewLayers = chkInvisibleNewLayers.isSelected();
466
                        keepScaleOnResize = chkKeepScaleOnResizing.isSelected();
467
                } catch (Exception e) {
468
                        throw new StoreException(PluginServices.getText(this,"factor_zoom_incorrecto"));
469
                }
470
                MapContext.ZOOMINFACTOR=zif;
471
                MapContext.ZOOMOUTFACTOR=zof;
472
                // MapControl.setScalingOnResize(!keepScaleOnResize);
473

    
474
                PluginServices ps = PluginServices.getPluginServices(this);
475
                XMLEntity xml = ps.getPersistentXML();
476
                xml.putProperty(DEFAULT_PROJECTION_KEY_NAME, projName);
477
                xml.putProperty(ZOOM_IN_FACTOR_KEY_NAME, zif);
478
                xml.putProperty(ZOOM_OUT_FACTOR_KEY_NAME, zof);
479
                xml.putProperty(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME, invisibleNewLayers);
480
                xml.putProperty(KEEP_SCALE_ON_RESIZING_KEY_NAME, keepScaleOnResize);
481
                xml.putProperty(DEFAULT_VIEW_BACK_COLOR_KEY_NAME, StringUtilities.color2String(viewBackColor));
482
                /*
483
                 * Locator's background color, for when we let it be possible
484
                 * xml.putProperty(DEFAULT_MAP_OVERVIEW_BACK_COLOR_KEY_NAME, StringUtilities.color2String(mapOverViewBackColor));
485
                 */
486
                xml.putProperty(DEFAULT_SELECTION_COLOR_KEY_NAME, StringUtilities.color2String(selectionColor));
487
                xml.putProperty(DEFAULT_MAP_UNITS_KEY_NAME, jCmbMapUnits.getSelectedIndex());
488
                xml.putProperty(DEFAULT_DISTANCE_UNITS_KEY_NAME, jCmbDistanceUnits.getSelectedIndex());
489
        }
490

    
491

    
492
        public void initializeDefaults() {
493
                lblDefaultProjection.setText(FACTORY_DEFAULT_PROJECTION);
494
                txtZoomInFactor.setText(String.valueOf(DEFAULT_ZOOM_IN_FACTOR));
495
                txtZoomOutFactor.setText(String.valueOf(DEFAULT_ZOOM_OUT_FACTOR));
496
                chkInvisibleNewLayers.setSelected(false);
497
                chkKeepScaleOnResizing.setSelected(false);
498
                jccDefaultViewBackColor.setColor(FACTORY_DEFAULT_VIEW_BACK_COLOR);
499
                /*
500
                 * Locator's background color, for when we let it be possible
501
                 * jccDefaultMapOverViewBackColor.setColor(FACTORY_DEFAULT_VIEW_BACK_COLOR);
502
                 */
503
                jccDefaultSelectionColor.setColor(FACTORY_DEFAULT_SELECTION_COLOR);
504
                jCmbMapUnits.setSelectedIndex(FACTORY_DEFAULT_MAP_UNITS);
505
                jCmbDistanceUnits.setSelectedIndex(FACTORY_DEFAULT_DISTANCE_UNITS);
506

    
507
        }
508

    
509
        public ImageIcon getIcon() {
510
                return icon;
511
        }
512

    
513
        public boolean isValueChanged() {
514
                return super.hasChanged();
515
        }
516

    
517
        public void setChangesApplied() {
518
                setChanged(false);
519
        }
520
        
521
        
522
        private String[] getUnitsNames() {
523
                if (unitsNames == null) {
524
                        unitsNames = new String[Attributes.NAMES.length];
525
                        for (int i=0;i<Attributes.NAMES.length;i++) {
526
                                unitsNames[i]=PluginServices.getText(this, Attributes.NAMES[i]);
527
                        }
528
                }
529
                return unitsNames;
530
        }
531
}