Statistics
| Revision:

root / branches / piloto3d / applications / appgvSIG / src / com / iver / cit / gvsig / gui / preferencespage / LayoutPage.java @ 9529

History | View | Annotate | Download (7.97 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: LayoutPage.java 9529 2007-01-03 17:07:31Z sbayarri $
45
* $Log$
46
* Revision 1.7.2.1  2007-01-03 17:07:29  sbayarri
47
* Fix wrong files
48
*
49
* Revision 1.6.2.1  2006/11/15 04:10:43  jjdelcerro
50
* *** empty log message ***
51
*
52
* Revision 1.6  2006/11/08 10:57:55  jaume
53
* remove unecessary imports
54
*
55
* Revision 1.5  2006/10/18 07:57:47  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.4  2006/10/04 09:06:35  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.3  2006/10/04 07:23:53  jaume
62
* refactored ambiguous methods and field names and added some more features for preference pages
63
*
64
* Revision 1.2  2006/10/03 11:12:41  jaume
65
* initialize values
66
*
67
* Revision 1.1  2006/10/03 10:33:34  jaume
68
* *** empty log message ***
69
*
70
*
71
*/
72
package com.iver.cit.gvsig.gui.preferencespage;
73

    
74
import javax.swing.ImageIcon;
75
import javax.swing.JCheckBox;
76
import javax.swing.JPanel;
77
import javax.swing.JTextField;
78

    
79
import com.iver.andami.PluginServices;
80
import com.iver.andami.preferences.AbstractPreferencePage;
81
import com.iver.andami.preferences.StoreException;
82
import com.iver.cit.gvsig.gui.layout.Attributes;
83
import com.iver.cit.gvsig.gui.layout.Layout;
84
import com.iver.utiles.XMLEntity;
85
/**
86
 * Layout preference page where the user can establish default values for
87
 * <ol>
88
 *  <li><b>grid horizontal gap</b></li>
89
 *  <li><b>grid vertical gap</b></li>
90
 *  <li><b>show or hide grid</b></li>
91
 *  <li><b>adjust elements to grid</b></li>
92
 *  <li><b>show or hide rules</b></li>
93
 * </ol>
94
 * @author jaume dominguez faus - jaume.dominguez@iver.es
95
 *
96
 */
97
public class LayoutPage extends AbstractPreferencePage{
98

    
99
        private static final boolean FACTORY_DEFAULT_LAYOUT_ENABLE_RULES = true;
100
        private static final boolean FACTORY_DEFAULT_LAYOUT_GRID_SHOW = true;
101
        private static final double FACTORY_DEFAULT_VERTICAL_GAP = 0.25;
102
        private static final double FACTORY_DEFAULT_HORIZONTAL_GAP = 0.25;
103
        private static final boolean FACTORY_DEFAULT_LAYOUT_GRID_ENABLE = false;
104
        private static final String DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME = "DefaultShowLayoutGrid";
105
        private static final String DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME = "DefaultEnableLayoutGrid";
106
        private static final String DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME = "DefaultShowLayoutRules";
107
        private static final String DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME = "DefaultGridVerticalGap";
108
        private static final String DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME = "DefaultGridHorizontalGap";
109
        static String id = LayoutPage.class.getName();;
110
        private ImageIcon icon;
111
        private JCheckBox chkGridEnabled;
112
        private JCheckBox chkShowRules;
113
        private JCheckBox chkShowGrid;
114
        private JTextField txtVGap;
115
        private JTextField txtHGap;
116

    
117
        /**
118
         * Builds preference page where the user can establish default values for
119
         * <ol>
120
         *  <li><b>grid horizontal gap</b></li>
121
         *  <li><b>grid vertical gap</b></li>
122
         *  <li><b>show or hide grid</b></li>
123
         *  <li><b>adjust elements to grid</b></li>
124
         *  <li><b>show or hide rules</b></li>
125
         * </ol>
126
         */
127
        public LayoutPage() {
128
                super();
129

    
130
                icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/mapas.png"));
131

    
132
                // horizontal gap text field
133
                addComponent(PluginServices.getText(this, "espaciado_horizontal"), txtHGap = new JTextField(5));
134

    
135
                // vertical gap text field
136
                addComponent(PluginServices.getText(this, "espaciado_vertical"), txtVGap = new JTextField(5));
137

    
138
                // show/hide show check
139
                addComponent(chkShowGrid = new JCheckBox(PluginServices.getText(this, "visualizar_cuadricula")));
140

    
141
                // enable/disable grid
142
                addComponent(chkGridEnabled = new JCheckBox(PluginServices.getText(this, "malla_activada")));
143

    
144
                // show/hide rules
145
                addComponent(chkShowRules = new JCheckBox(PluginServices.getText(this, "activar_regla")));
146

    
147

    
148
        }
149

    
150
        public void storeValues() throws StoreException {
151
                double hGap, vGap;
152
                boolean gridEnabled, showRules, showGrid;
153
                try {
154
                        hGap = Double.parseDouble(txtHGap.getText());
155
                        vGap = Double.parseDouble(txtVGap.getText());
156
                        gridEnabled = chkGridEnabled.isSelected();
157
                        showGrid = chkShowGrid.isSelected();
158
                        showRules = chkShowRules.isSelected();
159
                } catch (Exception e) {
160
                        throw new StoreException(PluginServices.getText(this, "invalid_value_for_gap"));
161
                }
162
                Layout.setDefaultShowGrid(showGrid);
163
                Layout.setDefaultAdjustToGrid(gridEnabled);
164
                Layout.setDefaultShowRulers(showRules);
165
                Attributes.setDefaultGridGap(hGap, vGap);
166
                PluginServices ps = PluginServices.getPluginServices(this);
167
                XMLEntity xml = ps.getPersistentXML();
168
                xml.putProperty(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME, hGap);
169
                xml.putProperty(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME, vGap);
170
                xml.putProperty(DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME, showGrid);
171
                xml.putProperty(DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME, gridEnabled);
172
                xml.putProperty(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME, showRules);
173
        }
174

    
175
        public String getID() {
176
                return id;
177
        }
178

    
179
        public String getTitle() {
180
                return PluginServices.getText(this, "Mapa");
181
        }
182

    
183
        public JPanel getPanel() {
184
                return this;
185
        }
186

    
187
        public void initializeValues() {
188
                PluginServices ps = PluginServices.getPluginServices(this);
189
                XMLEntity xml = ps.getPersistentXML();
190

    
191
                // horizontal gap
192
                if (xml.contains(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME)) {
193
                        txtHGap.setText(String.valueOf(
194
                                xml.getDoubleProperty(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME)));
195
                } else {
196
                        txtHGap.setText(String.valueOf(FACTORY_DEFAULT_HORIZONTAL_GAP));
197
                }
198

    
199
                // vertical gap
200
                if (xml.contains(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME)) {
201
                        txtVGap.setText(String.valueOf(
202
                                xml.getDoubleProperty(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME)));
203
                } else {
204
                        txtVGap.setText(String.valueOf(FACTORY_DEFAULT_VERTICAL_GAP));
205
                }
206

    
207
                // show/hide grid check
208
                if (xml.contains(DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME)) {
209
                        chkShowGrid.setSelected(
210
                                xml.getBooleanProperty(DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME));
211
                } else {
212
                        chkShowGrid.setSelected(FACTORY_DEFAULT_LAYOUT_GRID_SHOW);
213
                }
214

    
215
                // enable/disable grid check
216
                if (xml.contains(DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME)) {
217
                        chkGridEnabled.setSelected(
218
                                xml.getBooleanProperty(DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME));
219
                } else {
220
                        chkGridEnabled.setSelected(FACTORY_DEFAULT_LAYOUT_GRID_ENABLE);
221
                }
222

    
223
                // enable/disable rules
224
                if (xml.contains(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME)) {
225
                        chkShowRules.setSelected(
226
                                xml.getBooleanProperty(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME));
227
                } else {
228
                        chkShowRules.setSelected(FACTORY_DEFAULT_LAYOUT_ENABLE_RULES);
229
                }
230

    
231
        }
232

    
233
        public void initializeDefaults() {
234
                txtHGap.setText(String.valueOf(FACTORY_DEFAULT_HORIZONTAL_GAP));
235
                txtVGap.setText(String.valueOf(FACTORY_DEFAULT_VERTICAL_GAP));
236
                chkShowGrid.setSelected(FACTORY_DEFAULT_LAYOUT_GRID_SHOW);
237
                chkGridEnabled.setSelected(FACTORY_DEFAULT_LAYOUT_GRID_ENABLE);
238
                chkShowRules.setSelected(FACTORY_DEFAULT_LAYOUT_ENABLE_RULES);
239
        }
240

    
241
        public ImageIcon getIcon() {
242
                return icon;
243
        }
244

    
245
        public boolean isValueChanged() {
246
                return super.hasChanged();
247
        }
248

    
249
        public void setChangesApplied() {
250
                setChanged(false);
251
        }
252
}