Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / gui / preferencespage / LayoutPage.java @ 36443

History | View | Annotate | Download (8.27 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 36443 2011-09-19 08:36:54Z cordinyana $
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 org.gvsig.app.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 org.gvsig.andami.PluginServices;
77
import org.gvsig.andami.preferences.AbstractPreferencePage;
78
import org.gvsig.andami.preferences.StoreException;
79
import org.gvsig.app.project.ProjectManager;
80
import org.gvsig.app.project.documents.layout.Attributes;
81
import org.gvsig.app.project.documents.layout.DefaultLayoutManager;
82
import org.gvsig.utils.XMLEntity;
83

    
84
/**
85
 * Layout preference page where the user can establish default values for
86
 * <ol>
87
 *  <li><b>grid horizontal gap</b></li>
88
 *  <li><b>grid vertical gap</b></li>
89
 *  <li><b>show or hide grid</b></li>
90
 *  <li><b>adjust elements to grid</b></li>
91
 *  <li><b>show or hide rules</b></li>
92
 * </ol>
93
 * @author jaume dominguez faus - jaume.dominguez@iver.es
94
 *
95
 */
96
public class LayoutPage extends AbstractPreferencePage{
97

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

    
116
        private static DefaultLayoutManager layoutManager = null;
117
        
118
        /**
119
         * Builds preference page where the user can establish default values for
120
         * <ol>
121
         *  <li><b>grid horizontal gap</b></li>
122
         *  <li><b>grid vertical gap</b></li>
123
         *  <li><b>show or hide grid</b></li>
124
         *  <li><b>adjust elements to grid</b></li>
125
         *  <li><b>show or hide rules</b></li>
126
         * </ol>
127
         */
128
        public LayoutPage() {
129
                super();
130
                 layoutManager = (DefaultLayoutManager)ProjectManager.getInstance().getDocumentManager(DefaultLayoutManager.TYPENAME);
131

    
132
                icon = PluginServices.getIconTheme().get("mapa-icono");
133

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

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

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

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

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

    
149

    
150
        }
151

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

    
177
        public String getID() {
178
                return id;
179
        }
180

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

    
185
        public JPanel getPanel() {
186
                return this;
187
        }
188

    
189
        public void initializeValues() {
190
                PluginServices ps = PluginServices.getPluginServices(this);
191
                XMLEntity xml = ps.getPersistentXML();
192
                double hGap=FACTORY_DEFAULT_HORIZONTAL_GAP;
193
                double vGap=FACTORY_DEFAULT_VERTICAL_GAP;
194
                boolean showGrid=FACTORY_DEFAULT_LAYOUT_GRID_SHOW;
195
                boolean gridEnabled=FACTORY_DEFAULT_LAYOUT_GRID_ENABLE;
196
                boolean showRules=FACTORY_DEFAULT_LAYOUT_ENABLE_RULES;
197
                // horizontal gap
198
                if (xml.contains(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME)) {
199
                        hGap=xml.getDoubleProperty(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME);
200
                }
201
                txtHGap.setText(String.valueOf(hGap));
202

    
203
                // vertical gap
204
                if (xml.contains(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME)) {
205
                        vGap=xml.getDoubleProperty(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME);
206
                }
207
                txtVGap.setText(String.valueOf(vGap));
208

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

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

    
221
                // enable/disable rules
222
                if (xml.contains(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME)) {
223
                        showRules=xml.getBooleanProperty(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME);
224
                }
225
                chkShowRules.setSelected(showRules);
226

    
227
                layoutManager.setDefaultShowGrid(showGrid);
228
                layoutManager.setDefaultAdjustToGrid(gridEnabled);
229
                layoutManager.setDefaultShowRulers(showRules);
230
                Attributes.setDefaultGridGap(hGap, vGap);
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
}