Statistics
| Revision:

svn-gvsig-desktop / tags / v10_RC2c / applications / appgvSIG / src / com / iver / cit / gvsig / gui / preferencespage / ViewPage.java @ 8745

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

    
122
import java.awt.FlowLayout;
123
import java.awt.event.ActionEvent;
124
import java.awt.event.ActionListener;
125
import java.util.Enumeration;
126

    
127
import javax.swing.ImageIcon;
128
import javax.swing.JCheckBox;
129
import javax.swing.JLabel;
130
import javax.swing.JPanel;
131
import javax.swing.JTextField;
132
import javax.swing.UIManager;
133
import javax.swing.plaf.FontUIResource;
134

    
135
import org.cresques.cts.IProjection;
136
import org.cresques.cts.ProjectionPool;
137
import org.gvsig.gui.beans.swing.JButton;
138

    
139
import com.iver.andami.PluginServices;
140
import com.iver.andami.preferences.AbstractPreferencePage;
141
import com.iver.andami.preferences.StoreException;
142
import com.iver.cit.gvsig.fmap.MapContext;
143
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
144
import com.iver.cit.gvsig.gui.dialogs.CSSelectionDialog;
145
import com.iver.cit.gvsig.gui.panels.CRSSelectPanel;
146
import com.iver.cit.gvsig.project.Project;
147
import com.iver.utiles.XMLEntity;
148

    
149
public class ViewPage extends AbstractPreferencePage {
150
        private static final String DEFAULT_PROJECTION_KEY_NAME = "DefaultProjection";
151
        private static final String FACTORY_DEFAULT_PROJECTION = "EPSG:23030";
152
        private static final String ZOOM_IN_FACTOR_KEY_NAME = "ZoomInFactor";
153
        private static final String ZOOM_OUT_FACTOR_KEY_NAME = "ZoomOutFactor";
154
        private static final String ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME = "NewLayersInInvisibleMode";
155
        private static final String KEEP_SCALE_ON_RESIZING_KEY_NAME = "KeepScaleOnResizing";
156

    
157
        private JTextField txtZoomInFactor;
158
        private JTextField txtZoomOutFactor;
159
        protected String id;
160
        private ImageIcon icon;
161
        //private boolean changed = false;
162
        //private JLabel lblDefaultProjection;
163
        //private JButton btnChangeProjection;
164
        private String fontName;
165
        private JCheckBox chkInvisibleNewLayers;
166
        private JCheckBox chkKeepScaleOnResizing;
167
        private boolean panelStarted = false;
168
        private boolean panelInitialized = false;
169
        
170
        private CRSSelectPanel jPanelProj = null;
171
        {
172
                Enumeration keys = UIManager.getDefaults().keys();
173
                while (keys.hasMoreElements()) {
174
                        Object key = keys.nextElement();
175
                        Object value = UIManager.get (key);
176
                        if (value instanceof FontUIResource) {
177
                                FontUIResource fur = (FontUIResource) value;
178
                                fontName = fur.getFontName();
179

    
180
                        }
181
                }
182
        }
183

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

    
190
        /**
191
         * This method initializes jPanel4
192
         *
193
         * @return javax.swing.JPanel
194
         */
195
        private CRSSelectPanel getJPanelProj() {
196
                if (jPanelProj == null) {
197
                        jPanelProj = CRSSelectPanel.getPanel(Project.getDefaultProjection());
198
                        jPanelProj.setPreferredSize(new java.awt.Dimension(330,35));
199
                        jPanelProj.addActionListener(new java.awt.event.ActionListener() {
200
                                public void actionPerformed(java.awt.event.ActionEvent e) {
201
                                        if (jPanelProj.isOkPressed()) {
202
                                                Project.setDefaultProjection(jPanelProj.getCurProj());
203
                                        }
204
                                }
205
                        });
206

    
207
//                        jPanelProj.add(jLblProjName, null);
208
//                        jPanelProj.add(jLblProj, null);
209
//                        jPanelProj.add(getJBtnChangeProj(), null);
210
                }
211
                return jPanelProj;
212
        }
213

    
214
        public void initializeValues() {
215
                if (!panelStarted) getPanel();
216
                
217
                PluginServices ps = PluginServices.getPluginServices(this);
218
                XMLEntity xml = ps.getPersistentXML();
219

    
220
                // Default Projection
221
                String projCode = null; 
222
                if (xml.contains(DEFAULT_PROJECTION_KEY_NAME)) {
223
                        projCode = xml.getStringProperty(DEFAULT_PROJECTION_KEY_NAME);
224
                } else {
225
                        projCode = FACTORY_DEFAULT_PROJECTION;
226
                }
227
                Project.setDefaultProjection(CRSFactory.getCRS(projCode));
228

    
229
                // Adding invisible new layers
230
                if (xml.contains(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME)) {
231
                        chkInvisibleNewLayers.setSelected(
232
                                xml.getBooleanProperty(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME));
233
                }
234

    
235
                // Keep scale on resizing
236
                if (xml.contains(KEEP_SCALE_ON_RESIZING_KEY_NAME)) {
237
                        chkKeepScaleOnResizing.setSelected(
238
                                xml.getBooleanProperty(KEEP_SCALE_ON_RESIZING_KEY_NAME));
239
                }
240

    
241
                // Zoom-in factor
242
                if (xml.contains(ZOOM_IN_FACTOR_KEY_NAME)) {
243
                        double zoomInFactor = xml.getDoubleProperty(ZOOM_IN_FACTOR_KEY_NAME);
244
                        txtZoomInFactor.setText(String.valueOf( zoomInFactor ));
245
                } else {
246
                        txtZoomInFactor.setText(
247
                                String.valueOf( MapContext.ZOOMINFACTOR ));
248
                }
249
                MapContext.ZOOMINFACTOR = Double.parseDouble(txtZoomInFactor.getText());
250

    
251
                // Zoom-out factor
252
                if (xml.contains(ZOOM_OUT_FACTOR_KEY_NAME)) {
253
                        double zoomOutFactor = xml.getDoubleProperty(ZOOM_OUT_FACTOR_KEY_NAME);
254
                        txtZoomOutFactor.setText(String.valueOf( zoomOutFactor ));
255
                } else {
256
                        txtZoomOutFactor.setText(
257
                                String.valueOf( MapContext.ZOOMOUTFACTOR ));
258
                }
259
                MapContext.ZOOMOUTFACTOR = Double.parseDouble(txtZoomOutFactor.getText());;
260
        }
261

    
262
        public String getID() {
263
                return id;
264
        }
265

    
266
        public String getTitle() {
267
                return PluginServices.getText(this, "Vista");
268
        }
269

    
270
        public JPanel getPanel() {
271
                if (panelStarted) return this;
272
                panelStarted = true;
273
                // default projection
274
                addComponent(getJPanelProj());
275
/*                lblDefaultProjection = new JLabel();
276
                lblDefaultProjection.setFont(new java.awt.Font(
277
                        fontName, java.awt.Font.BOLD, 11));
278
                btnChangeProjection = new JButton(PluginServices.getText(this, "change"));
279
                btnChangeProjection.addActionListener(new ActionListener() {
280
                        public void actionPerformed(ActionEvent e) {
281
                                CSSelectionDialog csSelect = new CSSelectionDialog();
282
                                csSelect.setProjection(        CRSFactory.getCRS(
283
                                                lblDefaultProjection.getText()));
284
                                PluginServices.getMDIManager().addWindow(csSelect);
285

286
                        if (csSelect.isOkPressed()) {
287
                                IProjection proj = csSelect.getProjection();
288
                                lblDefaultProjection.setText(proj.getAbrev());
289
                        }
290
                        }
291
                });
292
                addComponent(PluginServices.getText(this, "default_projection") + ":", lblDefaultProjection );
293
                JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
294
                aux.add(btnChangeProjection);
295
                addComponent("", aux);*/
296

    
297
                // just a separator
298
                addComponent(new JLabel(" "));
299

    
300
                // Adding Invisible New Layers
301
                chkInvisibleNewLayers = new JCheckBox(
302
                                PluginServices.getText(this, "options.view.invisible_new_layers"));
303

    
304
                addComponent("", chkInvisibleNewLayers);
305
                chkKeepScaleOnResizing = new JCheckBox(
306
                                PluginServices.getText(this, "options.view.keep_scale_on_resizing"));
307
                chkKeepScaleOnResizing.setEnabled(false);
308
                addComponent("", chkKeepScaleOnResizing);
309

    
310
                // just a separator
311
                addComponent(new JLabel(" "));
312

    
313
                // zoom in factor
314
                addComponent(PluginServices.getText(this, "zoom_in_factor") + ":",
315
                        txtZoomInFactor = new JTextField("", 15));
316
                // zoom out factor
317
                addComponent(PluginServices.getText(this, "zoom_out_factor") + ":",
318
                        txtZoomOutFactor = new JTextField("", 15));
319

    
320
                initializeValues();
321
                return this;
322
        }
323

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

    
341
                PluginServices ps = PluginServices.getPluginServices(this);
342
                XMLEntity xml = ps.getPersistentXML();
343
                xml.putProperty(DEFAULT_PROJECTION_KEY_NAME,
344
                        Project.getDefaultProjection().getAbrev());
345
                xml.putProperty(ZOOM_IN_FACTOR_KEY_NAME, zif);
346
                xml.putProperty(ZOOM_OUT_FACTOR_KEY_NAME, zof);
347
                xml.putProperty(ADD_NEW_LAYERS_IN_INVISIBLE_MODE_KEY_NAME, invisibleNewLayers);
348
                xml.putProperty(KEEP_SCALE_ON_RESIZING_KEY_NAME, keepScaleOnResize);
349
        }
350

    
351
        public void initializeDefaults() {
352
                //projCode = FACTORY_DEFAULT_PROJECTION;
353
                txtZoomInFactor.setText(String.valueOf(MapContext.ZOOMINFACTOR));
354
                txtZoomOutFactor.setText(String.valueOf(MapContext.ZOOMOUTFACTOR));
355
                chkInvisibleNewLayers.setSelected(false);
356
                chkKeepScaleOnResizing.setSelected(false);
357
        }
358

    
359
        public ImageIcon getIcon() {
360
                return icon;
361
        }
362

    
363
        public boolean isValueChanged() {
364
                return super.hasChanged();
365
        }
366

    
367
        public void setChangesApplied() {
368
                setChanged(false);
369
        }
370
}