svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / preferencespage / LayoutPage.java @ 7869
History | View | Annotate | Download (7.68 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 7869 2006-10-04 09:06:35Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.4 2006-10-04 09:06:35 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.3 2006/10/04 07:23:53 jaume
|
50 |
* refactored ambiguous methods and field names and added some more features for preference pages
|
51 |
*
|
52 |
* Revision 1.2 2006/10/03 11:12:41 jaume
|
53 |
* initialize values
|
54 |
*
|
55 |
* Revision 1.1 2006/10/03 10:33:34 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
*
|
59 |
*/
|
60 |
package com.iver.cit.gvsig.gui.preferencespage; |
61 |
|
62 |
import javax.swing.ImageIcon; |
63 |
import javax.swing.JCheckBox; |
64 |
import javax.swing.JPanel; |
65 |
import javax.swing.JTextField; |
66 |
|
67 |
import com.iver.andami.PluginServices; |
68 |
import com.iver.andami.preferences.AbstractPreferencePage; |
69 |
import com.iver.andami.preferences.StoreException; |
70 |
import com.iver.cit.gvsig.gui.layout.Attributes; |
71 |
import com.iver.cit.gvsig.gui.layout.Layout; |
72 |
import com.iver.utiles.XMLEntity; |
73 |
/**
|
74 |
* Layout preference page where the user can establish default values for
|
75 |
* <ol>
|
76 |
* <li><b>grid horizontal gap</b></li>
|
77 |
* <li><b>grid vertical gap</b></li>
|
78 |
* <li><b>show or hide grid</b></li>
|
79 |
* <li><b>adjust elements to grid</b></li>
|
80 |
* <li><b>show or hide rules</b></li>
|
81 |
* </ol>
|
82 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
83 |
*
|
84 |
*/
|
85 |
public class LayoutPage extends AbstractPreferencePage{ |
86 |
|
87 |
private static final boolean FACTORY_DEFAULT_LAYOUT_ENABLE_RULES = true; |
88 |
private static final boolean FACTORY_DEFAULT_LAYOUT_GRID_SHOW = true; |
89 |
private static final double FACTORY_DEFAULT_VERTICAL_GAP = 0.25; |
90 |
private static final double FACTORY_DEFAULT_HORIZONTAL_GAP = 0.25; |
91 |
private static final boolean FACTORY_DEFAULT_LAYOUT_GRID_ENABLE = false; |
92 |
private static final String DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME = "DefaultShowLayoutGrid"; |
93 |
private static final String DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME = "DefaultEnableLayoutGrid"; |
94 |
private static final String DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME = "DefaultShowLayoutRules"; |
95 |
private static final String DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME = "DefaultGridVerticalGap"; |
96 |
private static final String DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME = "DefaultGridHorizontalGap"; |
97 |
private String id; |
98 |
private ImageIcon icon; |
99 |
private JCheckBox chkGridEnabled; |
100 |
private JCheckBox chkShowRules; |
101 |
private JCheckBox chkShowGrid; |
102 |
private JTextField txtVGap; |
103 |
private JTextField txtHGap; |
104 |
|
105 |
/**
|
106 |
* Builds preference page where the user can establish default values for
|
107 |
* <ol>
|
108 |
* <li><b>grid horizontal gap</b></li>
|
109 |
* <li><b>grid vertical gap</b></li>
|
110 |
* <li><b>show or hide grid</b></li>
|
111 |
* <li><b>adjust elements to grid</b></li>
|
112 |
* <li><b>show or hide rules</b></li>
|
113 |
* </ol>
|
114 |
*/
|
115 |
public LayoutPage() {
|
116 |
super();
|
117 |
id = this.getClass().getName();
|
118 |
icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/mapas.png")); |
119 |
|
120 |
// horizontal gap text field
|
121 |
addComponent(PluginServices.getText(this, "espaciado_horizontal"), txtHGap = new JTextField(5)); |
122 |
|
123 |
// vertical gap text field
|
124 |
addComponent(PluginServices.getText(this, "espaciado_vertical"), txtVGap = new JTextField(5)); |
125 |
|
126 |
// show/hide show check
|
127 |
addComponent(chkShowGrid = new JCheckBox(PluginServices.getText(this, "visualizar_cuadricula"))); |
128 |
|
129 |
// enable/disable grid
|
130 |
addComponent(chkGridEnabled = new JCheckBox(PluginServices.getText(this, "malla_activada"))); |
131 |
|
132 |
// show/hide rules
|
133 |
addComponent(chkShowRules = new JCheckBox(PluginServices.getText(this, "activar_regla"))); |
134 |
|
135 |
} |
136 |
|
137 |
public void storeValues() throws StoreException { |
138 |
double hGap, vGap;
|
139 |
boolean gridEnabled, showRules, showGrid;
|
140 |
try {
|
141 |
hGap = Double.parseDouble(txtHGap.getText());
|
142 |
vGap = Double.parseDouble(txtVGap.getText());
|
143 |
gridEnabled = chkGridEnabled.isSelected(); |
144 |
showGrid = chkShowGrid.isSelected(); |
145 |
showRules = chkShowRules.isSelected(); |
146 |
} catch (Exception e) { |
147 |
throw new StoreException(PluginServices.getText(this, "invalid_value_for_gap")); |
148 |
} |
149 |
Layout.setDefaultShowGrid(showGrid); |
150 |
Layout.setDefaultAdjustToGrid(gridEnabled); |
151 |
Layout.setDefaultShowRulers(showRules); |
152 |
Attributes.setDefaultGridGap(hGap, vGap);
|
153 |
PluginServices ps = PluginServices.getPluginServices(this);
|
154 |
XMLEntity xml = ps.getPersistentXML(); |
155 |
xml.putProperty(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME, hGap); |
156 |
xml.putProperty(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME, vGap); |
157 |
xml.putProperty(DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME, showGrid); |
158 |
xml.putProperty(DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME, gridEnabled); |
159 |
xml.putProperty(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME, showRules); |
160 |
} |
161 |
|
162 |
public String getID() { |
163 |
return id;
|
164 |
} |
165 |
|
166 |
public String getTitle() { |
167 |
return PluginServices.getText(this, "Mapa"); |
168 |
} |
169 |
|
170 |
public JPanel getPanel() { |
171 |
return this; |
172 |
} |
173 |
|
174 |
public void initializeValues() { |
175 |
PluginServices ps = PluginServices.getPluginServices(this);
|
176 |
XMLEntity xml = ps.getPersistentXML(); |
177 |
|
178 |
// horizontal gap
|
179 |
if (xml.contains(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME)) {
|
180 |
txtHGap.setText(String.valueOf(
|
181 |
xml.getDoubleProperty(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME))); |
182 |
} else {
|
183 |
txtHGap.setText(String.valueOf(FACTORY_DEFAULT_HORIZONTAL_GAP));
|
184 |
} |
185 |
|
186 |
// vertical gap
|
187 |
if (xml.contains(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME)) {
|
188 |
txtVGap.setText(String.valueOf(
|
189 |
xml.getDoubleProperty(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME))); |
190 |
} else {
|
191 |
txtVGap.setText(String.valueOf(FACTORY_DEFAULT_VERTICAL_GAP));
|
192 |
} |
193 |
|
194 |
// show/hide grid check
|
195 |
if (xml.contains(DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME)) {
|
196 |
chkShowGrid.setSelected( |
197 |
xml.getBooleanProperty(DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME)); |
198 |
} else {
|
199 |
chkShowGrid.setSelected(FACTORY_DEFAULT_LAYOUT_GRID_SHOW); |
200 |
} |
201 |
|
202 |
// enable/disable grid check
|
203 |
if (xml.contains(DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME)) {
|
204 |
chkGridEnabled.setSelected( |
205 |
xml.getBooleanProperty(DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME)); |
206 |
} else {
|
207 |
chkGridEnabled.setSelected(FACTORY_DEFAULT_LAYOUT_GRID_ENABLE); |
208 |
} |
209 |
|
210 |
// enable/disable rules
|
211 |
if (xml.contains(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME)) {
|
212 |
chkShowRules.setSelected( |
213 |
xml.getBooleanProperty(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME)); |
214 |
} else {
|
215 |
chkShowRules.setSelected(FACTORY_DEFAULT_LAYOUT_ENABLE_RULES); |
216 |
} |
217 |
|
218 |
} |
219 |
|
220 |
public void initializeDefaults() { |
221 |
txtHGap.setText(String.valueOf(FACTORY_DEFAULT_HORIZONTAL_GAP));
|
222 |
txtVGap.setText(String.valueOf(FACTORY_DEFAULT_VERTICAL_GAP));
|
223 |
chkShowGrid.setSelected(FACTORY_DEFAULT_LAYOUT_GRID_SHOW); |
224 |
chkGridEnabled.setSelected(FACTORY_DEFAULT_LAYOUT_GRID_ENABLE); |
225 |
chkShowRules.setSelected(FACTORY_DEFAULT_LAYOUT_ENABLE_RULES); |
226 |
} |
227 |
|
228 |
public ImageIcon getIcon() { |
229 |
return icon;
|
230 |
} |
231 |
|
232 |
public boolean isValueChanged() { |
233 |
return super.hasChanged(); |
234 |
} |
235 |
|
236 |
public void setChangesApplied() { |
237 |
setChanged(false);
|
238 |
} |
239 |
} |