svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / gui / preferencespage / LayoutPage.java @ 36648
History | View | Annotate | Download (8.32 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.app.gui.preferencespage; |
23 |
|
24 |
import javax.swing.ImageIcon; |
25 |
import javax.swing.JCheckBox; |
26 |
import javax.swing.JPanel; |
27 |
import javax.swing.JTextField; |
28 |
|
29 |
import org.gvsig.andami.PluginServices; |
30 |
import org.gvsig.andami.preferences.AbstractPreferencePage; |
31 |
import org.gvsig.andami.preferences.StoreException; |
32 |
import org.gvsig.app.project.ProjectManager; |
33 |
import org.gvsig.app.project.documents.layout.Attributes; |
34 |
import org.gvsig.app.project.documents.layout.DefaultLayoutManager; |
35 |
import org.gvsig.utils.XMLEntity; |
36 |
|
37 |
/**
|
38 |
* Layout preference page where the user can establish default values for
|
39 |
* <ol>
|
40 |
* <li><b>grid horizontal gap</b></li>
|
41 |
* <li><b>grid vertical gap</b></li>
|
42 |
* <li><b>show or hide grid</b></li>
|
43 |
* <li><b>adjust elements to grid</b></li>
|
44 |
* <li><b>show or hide rules</b></li>
|
45 |
* </ol>
|
46 |
*
|
47 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
48 |
*
|
49 |
*/
|
50 |
public class LayoutPage extends AbstractPreferencePage { |
51 |
|
52 |
private static final long serialVersionUID = -8225970409668105935L; |
53 |
private static final boolean FACTORY_DEFAULT_LAYOUT_ENABLE_RULES = true; |
54 |
private static final boolean FACTORY_DEFAULT_LAYOUT_GRID_SHOW = true; |
55 |
private static final double FACTORY_DEFAULT_VERTICAL_GAP = 1; |
56 |
private static final double FACTORY_DEFAULT_HORIZONTAL_GAP = 1; |
57 |
private static final boolean FACTORY_DEFAULT_LAYOUT_GRID_ENABLE = false; |
58 |
private static final String DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME = |
59 |
"DefaultShowLayoutGrid";
|
60 |
private static final String DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME = |
61 |
"DefaultEnableLayoutGrid";
|
62 |
private static final String DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME = |
63 |
"DefaultShowLayoutRules";
|
64 |
private static final String DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME = |
65 |
"DefaultGridVerticalGap";
|
66 |
private static final String DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME = |
67 |
"DefaultGridHorizontalGap";
|
68 |
static String id = LayoutPage.class.getName();; |
69 |
private ImageIcon icon; |
70 |
private JCheckBox chkGridEnabled; |
71 |
private JCheckBox chkShowRules; |
72 |
private JCheckBox chkShowGrid; |
73 |
private JTextField txtVGap; |
74 |
private JTextField txtHGap; |
75 |
|
76 |
private static DefaultLayoutManager layoutManager = null; |
77 |
|
78 |
/**
|
79 |
* Builds preference page where the user can establish default values for
|
80 |
* <ol>
|
81 |
* <li><b>grid horizontal gap</b></li>
|
82 |
* <li><b>grid vertical gap</b></li>
|
83 |
* <li><b>show or hide grid</b></li>
|
84 |
* <li><b>adjust elements to grid</b></li>
|
85 |
* <li><b>show or hide rules</b></li>
|
86 |
* </ol>
|
87 |
*/
|
88 |
public LayoutPage() {
|
89 |
super();
|
90 |
layoutManager = |
91 |
(DefaultLayoutManager) ProjectManager.getInstance() |
92 |
.getDocumentManager(DefaultLayoutManager.TYPENAME); |
93 |
|
94 |
icon = PluginServices.getIconTheme().get("mapa-icono");
|
95 |
|
96 |
// horizontal gap text field
|
97 |
addComponent(PluginServices.getText(this, "espaciado_horizontal"), |
98 |
txtHGap = new JTextField(5)); |
99 |
|
100 |
// vertical gap text field
|
101 |
addComponent(PluginServices.getText(this, "espaciado_vertical"), |
102 |
txtVGap = new JTextField(5)); |
103 |
|
104 |
// show/hide show check
|
105 |
addComponent(chkShowGrid = |
106 |
new JCheckBox(PluginServices.getText(this, "visualizar_cuadricula"))); |
107 |
|
108 |
// enable/disable grid
|
109 |
addComponent(chkGridEnabled = |
110 |
new JCheckBox(PluginServices.getText(this, "malla_activada"))); |
111 |
|
112 |
// show/hide rules
|
113 |
addComponent(chkShowRules = |
114 |
new JCheckBox(PluginServices.getText(this, "activar_regla"))); |
115 |
|
116 |
} |
117 |
|
118 |
public void storeValues() throws StoreException { |
119 |
double hGap, vGap;
|
120 |
boolean gridEnabled, showRules, showGrid;
|
121 |
try {
|
122 |
hGap = Double.parseDouble(txtHGap.getText());
|
123 |
vGap = Double.parseDouble(txtVGap.getText());
|
124 |
gridEnabled = chkGridEnabled.isSelected(); |
125 |
showGrid = chkShowGrid.isSelected(); |
126 |
showRules = chkShowRules.isSelected(); |
127 |
} catch (Exception e) { |
128 |
throw new StoreException(PluginServices.getText(this, |
129 |
"invalid_value_for_gap"));
|
130 |
} |
131 |
layoutManager.setDefaultShowGrid(showGrid); |
132 |
layoutManager.setDefaultAdjustToGrid(gridEnabled); |
133 |
layoutManager.setDefaultShowRulers(showRules); |
134 |
Attributes.setDefaultGridGap(hGap, vGap);
|
135 |
PluginServices ps = PluginServices.getPluginServices(this);
|
136 |
XMLEntity xml = ps.getPersistentXML(); |
137 |
xml.putProperty(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME, hGap); |
138 |
xml.putProperty(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME, vGap); |
139 |
xml.putProperty(DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME, showGrid); |
140 |
xml.putProperty(DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME, gridEnabled); |
141 |
xml.putProperty(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME, showRules); |
142 |
} |
143 |
|
144 |
public String getID() { |
145 |
return id;
|
146 |
} |
147 |
|
148 |
public String getTitle() { |
149 |
return PluginServices.getText(this, "Mapa"); |
150 |
} |
151 |
|
152 |
public JPanel getPanel() { |
153 |
return this; |
154 |
} |
155 |
|
156 |
public void initializeValues() { |
157 |
PluginServices ps = PluginServices.getPluginServices(this);
|
158 |
XMLEntity xml = ps.getPersistentXML(); |
159 |
double hGap = FACTORY_DEFAULT_HORIZONTAL_GAP;
|
160 |
double vGap = FACTORY_DEFAULT_VERTICAL_GAP;
|
161 |
boolean showGrid = FACTORY_DEFAULT_LAYOUT_GRID_SHOW;
|
162 |
boolean gridEnabled = FACTORY_DEFAULT_LAYOUT_GRID_ENABLE;
|
163 |
boolean showRules = FACTORY_DEFAULT_LAYOUT_ENABLE_RULES;
|
164 |
// horizontal gap
|
165 |
if (xml.contains(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME)) {
|
166 |
hGap = |
167 |
xml.getDoubleProperty(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME); |
168 |
} |
169 |
txtHGap.setText(String.valueOf(hGap));
|
170 |
|
171 |
// vertical gap
|
172 |
if (xml.contains(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME)) {
|
173 |
vGap = |
174 |
xml.getDoubleProperty(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME); |
175 |
} |
176 |
txtVGap.setText(String.valueOf(vGap));
|
177 |
|
178 |
// show/hide grid check
|
179 |
if (xml.contains(DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME)) {
|
180 |
showGrid = |
181 |
xml.getBooleanProperty(DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME); |
182 |
} |
183 |
chkShowGrid.setSelected(showGrid); |
184 |
|
185 |
// enable/disable grid check
|
186 |
if (xml.contains(DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME)) {
|
187 |
gridEnabled = |
188 |
xml.getBooleanProperty(DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME); |
189 |
} |
190 |
chkGridEnabled.setSelected(gridEnabled); |
191 |
|
192 |
// enable/disable rules
|
193 |
if (xml.contains(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME)) {
|
194 |
showRules = |
195 |
xml.getBooleanProperty(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME); |
196 |
} |
197 |
chkShowRules.setSelected(showRules); |
198 |
|
199 |
layoutManager.setDefaultShowGrid(showGrid); |
200 |
layoutManager.setDefaultAdjustToGrid(gridEnabled); |
201 |
layoutManager.setDefaultShowRulers(showRules); |
202 |
Attributes.setDefaultGridGap(hGap, vGap);
|
203 |
} |
204 |
|
205 |
public void initializeDefaults() { |
206 |
txtHGap.setText(String.valueOf(FACTORY_DEFAULT_HORIZONTAL_GAP));
|
207 |
txtVGap.setText(String.valueOf(FACTORY_DEFAULT_VERTICAL_GAP));
|
208 |
chkShowGrid.setSelected(FACTORY_DEFAULT_LAYOUT_GRID_SHOW); |
209 |
chkGridEnabled.setSelected(FACTORY_DEFAULT_LAYOUT_GRID_ENABLE); |
210 |
chkShowRules.setSelected(FACTORY_DEFAULT_LAYOUT_ENABLE_RULES); |
211 |
} |
212 |
|
213 |
public ImageIcon getIcon() { |
214 |
return icon;
|
215 |
} |
216 |
|
217 |
public boolean isValueChanged() { |
218 |
return super.hasChanged(); |
219 |
} |
220 |
|
221 |
public void setChangesApplied() { |
222 |
setChanged(false);
|
223 |
} |
224 |
} |