svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / preferencespage / LayoutPage.java @ 28960
History | View | Annotate | Download (8.01 KB)
1 | 14821 | jmvivo | /* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|---|---|
2 | 7805 | jaume | *
|
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 | 14821 | jmvivo | * Av. Blasco Ib��ez, 50
|
24 | 7805 | jaume | * 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$
|
||
45 | * $Log$
|
||
46 | 9392 | caballero | * 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 | 8590 | jaume | * remove unecessary imports
|
51 | *
|
||
52 | * Revision 1.5 2006/10/18 07:57:47 jaume
|
||
53 | 7869 | jaume | * *** empty log message ***
|
54 | *
|
||
55 | 8142 | jaume | * Revision 1.4 2006/10/04 09:06:35 jaume
|
56 | * *** empty log message ***
|
||
57 | *
|
||
58 | 7869 | jaume | * Revision 1.3 2006/10/04 07:23:53 jaume
|
59 | 7855 | jaume | * 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 | 7811 | jaume | * initialize values
|
63 | *
|
||
64 | * Revision 1.1 2006/10/03 10:33:34 jaume
|
||
65 | 7805 | jaume | * *** 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 | 9392 | caballero | import com.iver.cit.gvsig.project.documents.layout.Attributes; |
80 | import com.iver.cit.gvsig.project.documents.layout.gui.Layout; |
||
81 | 7811 | jaume | import com.iver.utiles.XMLEntity; |
82 | 7869 | jaume | /**
|
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 | 7805 | jaume | public class LayoutPage extends AbstractPreferencePage{ |
95 | |||
96 | 7855 | jaume | private static final boolean FACTORY_DEFAULT_LAYOUT_ENABLE_RULES = true; |
97 | private static final boolean FACTORY_DEFAULT_LAYOUT_GRID_SHOW = true; |
||
98 | 9392 | caballero | private static final double FACTORY_DEFAULT_VERTICAL_GAP = 1; |
99 | private static final double FACTORY_DEFAULT_HORIZONTAL_GAP = 1; |
||
100 | 7811 | jaume | private static final boolean FACTORY_DEFAULT_LAYOUT_GRID_ENABLE = false; |
101 | 7855 | jaume | 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 | 8142 | jaume | static String id = LayoutPage.class.getName();; |
107 | 7805 | jaume | private ImageIcon icon; |
108 | private JCheckBox chkGridEnabled; |
||
109 | 7855 | jaume | private JCheckBox chkShowRules; |
110 | 7805 | jaume | private JCheckBox chkShowGrid; |
111 | private JTextField txtVGap; |
||
112 | private JTextField txtHGap; |
||
113 | |||
114 | 7869 | jaume | /**
|
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 | 7805 | jaume | public LayoutPage() {
|
125 | super();
|
||
126 | 8142 | jaume | |
127 | 14821 | jmvivo | icon = PluginServices.getIconTheme().get("mapa-icono");
|
128 | 23693 | vcaballero | |
129 | 7811 | jaume | // horizontal gap text field
|
130 | 7805 | jaume | addComponent(PluginServices.getText(this, "espaciado_horizontal"), txtHGap = new JTextField(5)); |
131 | 7855 | jaume | |
132 | 7811 | jaume | // vertical gap text field
|
133 | 7805 | jaume | addComponent(PluginServices.getText(this, "espaciado_vertical"), txtVGap = new JTextField(5)); |
134 | 7855 | jaume | |
135 | 7811 | jaume | // show/hide show check
|
136 | 7805 | jaume | addComponent(chkShowGrid = new JCheckBox(PluginServices.getText(this, "visualizar_cuadricula"))); |
137 | 7855 | jaume | |
138 | 7811 | jaume | // enable/disable grid
|
139 | 7805 | jaume | addComponent(chkGridEnabled = new JCheckBox(PluginServices.getText(this, "malla_activada"))); |
140 | |||
141 | 7855 | jaume | // show/hide rules
|
142 | addComponent(chkShowRules = new JCheckBox(PluginServices.getText(this, "activar_regla"))); |
||
143 | |||
144 | 8142 | jaume | |
145 | 7805 | jaume | } |
146 | 7855 | jaume | |
147 | 7805 | jaume | public void storeValues() throws StoreException { |
148 | 7855 | jaume | 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 | 7869 | jaume | Attributes.setDefaultGridGap(hGap, vGap);
|
163 | 7855 | jaume | 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 | 7805 | jaume | } |
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 | 7811 | jaume | PluginServices ps = PluginServices.getPluginServices(this);
|
186 | XMLEntity xml = ps.getPersistentXML(); |
||
187 | 23693 | vcaballero | double hGap=FACTORY_DEFAULT_HORIZONTAL_GAP;
|
188 | double vGap=FACTORY_DEFAULT_VERTICAL_GAP;
|
||
189 | boolean showGrid=FACTORY_DEFAULT_LAYOUT_GRID_SHOW;
|
||
190 | boolean gridEnabled=FACTORY_DEFAULT_LAYOUT_GRID_ENABLE;
|
||
191 | boolean showRules=FACTORY_DEFAULT_LAYOUT_ENABLE_RULES;
|
||
192 | 7811 | jaume | // horizontal gap
|
193 | if (xml.contains(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME)) {
|
||
194 | 23693 | vcaballero | hGap=xml.getDoubleProperty(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME); |
195 | 7811 | jaume | } |
196 | 23693 | vcaballero | txtHGap.setText(String.valueOf(hGap));
|
197 | 7811 | jaume | |
198 | // vertical gap
|
||
199 | if (xml.contains(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME)) {
|
||
200 | 23693 | vcaballero | vGap=xml.getDoubleProperty(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME); |
201 | 7811 | jaume | } |
202 | 23693 | vcaballero | txtVGap.setText(String.valueOf(vGap));
|
203 | 7855 | jaume | |
204 | 7811 | jaume | // show/hide grid check
|
205 | 7855 | jaume | if (xml.contains(DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME)) {
|
206 | 23693 | vcaballero | showGrid=xml.getBooleanProperty(DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME); |
207 | 7811 | jaume | } |
208 | 23693 | vcaballero | chkShowGrid.setSelected(showGrid); |
209 | 7855 | jaume | |
210 | 7811 | jaume | // enable/disable grid check
|
211 | 7855 | jaume | if (xml.contains(DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME)) {
|
212 | 23693 | vcaballero | gridEnabled=xml.getBooleanProperty(DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME); |
213 | 7811 | jaume | } |
214 | 23693 | vcaballero | chkGridEnabled.setSelected(gridEnabled); |
215 | 7811 | jaume | |
216 | // enable/disable rules
|
||
217 | 7855 | jaume | if (xml.contains(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME)) {
|
218 | 23693 | vcaballero | showRules=xml.getBooleanProperty(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME); |
219 | 7811 | jaume | } |
220 | 23693 | vcaballero | chkShowRules.setSelected(showRules); |
221 | 7811 | jaume | |
222 | 23693 | vcaballero | Layout.setDefaultShowGrid(showGrid); |
223 | Layout.setDefaultAdjustToGrid(gridEnabled); |
||
224 | Layout.setDefaultShowRulers(showRules); |
||
225 | Attributes.setDefaultGridGap(hGap, vGap);
|
||
226 | 7805 | jaume | } |
227 | |||
228 | public void initializeDefaults() { |
||
229 | 7855 | jaume | txtHGap.setText(String.valueOf(FACTORY_DEFAULT_HORIZONTAL_GAP));
|
230 | txtVGap.setText(String.valueOf(FACTORY_DEFAULT_VERTICAL_GAP));
|
||
231 | chkShowGrid.setSelected(FACTORY_DEFAULT_LAYOUT_GRID_SHOW); |
||
232 | chkGridEnabled.setSelected(FACTORY_DEFAULT_LAYOUT_GRID_ENABLE); |
||
233 | chkShowRules.setSelected(FACTORY_DEFAULT_LAYOUT_ENABLE_RULES); |
||
234 | 7805 | jaume | } |
235 | |||
236 | public ImageIcon getIcon() { |
||
237 | return icon;
|
||
238 | } |
||
239 | |||
240 | public boolean isValueChanged() { |
||
241 | return super.hasChanged(); |
||
242 | } |
||
243 | |||
244 | public void setChangesApplied() { |
||
245 | setChanged(false);
|
||
246 | } |
||
247 | } |