Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / preferencespage / LayoutPage.java @ 14821

History | View | Annotate | Download (7.89 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 14821 2007-10-22 12:15:26Z jmvivo $
45
* $Log$
46
* Revision 1.7  2006-12-20 14:41:12  caballero
47
* Remodelado Layout
48
*
49
* Revision 1.6  2006/11/08 10:57:55  jaume
50
* remove unecessary imports
51
*
52
* Revision 1.5  2006/10/18 07:57:47  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.4  2006/10/04 09:06:35  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.3  2006/10/04 07:23:53  jaume
59
* refactored ambiguous methods and field names and added some more features for preference pages
60
*
61
* Revision 1.2  2006/10/03 11:12:41  jaume
62
* initialize values
63
*
64
* Revision 1.1  2006/10/03 10:33:34  jaume
65
* *** empty log message ***
66
*
67
*
68
*/
69
package com.iver.cit.gvsig.gui.preferencespage;
70

    
71
import javax.swing.ImageIcon;
72
import javax.swing.JCheckBox;
73
import javax.swing.JPanel;
74
import javax.swing.JTextField;
75

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

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

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

    
127
                icon = PluginServices.getIconTheme().get("mapa-icono");
128
                
129
                // horizontal gap text field
130
                addComponent(PluginServices.getText(this, "espaciado_horizontal"), txtHGap = new JTextField(5));
131

    
132
                // vertical gap text field
133
                addComponent(PluginServices.getText(this, "espaciado_vertical"), txtVGap = new JTextField(5));
134

    
135
                // show/hide show check
136
                addComponent(chkShowGrid = new JCheckBox(PluginServices.getText(this, "visualizar_cuadricula")));
137

    
138
                // enable/disable grid
139
                addComponent(chkGridEnabled = new JCheckBox(PluginServices.getText(this, "malla_activada")));
140

    
141
                // show/hide rules
142
                addComponent(chkShowRules = new JCheckBox(PluginServices.getText(this, "activar_regla")));
143

    
144

    
145
        }
146

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

    
172
        public String getID() {
173
                return id;
174
        }
175

    
176
        public String getTitle() {
177
                return PluginServices.getText(this, "Mapa");
178
        }
179

    
180
        public JPanel getPanel() {
181
                return this;
182
        }
183

    
184
        public void initializeValues() {
185
                PluginServices ps = PluginServices.getPluginServices(this);
186
                XMLEntity xml = ps.getPersistentXML();
187

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

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

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

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

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

    
228
        }
229

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

    
238
        public ImageIcon getIcon() {
239
                return icon;
240
        }
241

    
242
        public boolean isValueChanged() {
243
                return super.hasChanged();
244
        }
245

    
246
        public void setChangesApplied() {
247
                setChanged(false);
248
        }
249
}