svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.snapping.app / org.gvsig.snapping.app.mainplugin / src / main / java / org / gvsig / app / gui / preferencespage / GridPage.java @ 42508
History | View | Annotate | Download (5.41 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.gui.preferencespage; |
25 |
|
26 |
import javax.swing.ImageIcon; |
27 |
import javax.swing.JCheckBox; |
28 |
import javax.swing.JLabel; |
29 |
import javax.swing.JPanel; |
30 |
import javax.swing.JTextField; |
31 |
|
32 |
import org.gvsig.andami.IconThemeHelper; |
33 |
import org.gvsig.andami.PluginServices; |
34 |
import org.gvsig.andami.PluginsLocator; |
35 |
import org.gvsig.andami.PluginsManager; |
36 |
import org.gvsig.andami.preferences.AbstractPreferencePage; |
37 |
import org.gvsig.andami.preferences.StoreException; |
38 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
39 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
40 |
import org.gvsig.fmap.mapcontrol.MapControl; |
41 |
import org.gvsig.fmap.mapcontrol.tools.grid.Grid; |
42 |
import org.gvsig.tools.dynobject.DynObject; |
43 |
|
44 |
|
45 |
public class GridPage extends AbstractPreferencePage { |
46 |
public static final String ID = GridPage.class.getName(); |
47 |
|
48 |
private org.gvsig.fmap.mapcontrol.MapControl mapControl;
|
49 |
private JCheckBox chkShowGrid; |
50 |
private JCheckBox chkAdjustGrid; |
51 |
private JTextField txtDistanceX; |
52 |
private JTextField txtDistanceY; |
53 |
private JLabel lblUnits=new JLabel(); |
54 |
private ImageIcon icon; |
55 |
|
56 |
private DynObject pluginProperties;
|
57 |
private PluginServices plugin;
|
58 |
|
59 |
|
60 |
|
61 |
public GridPage() {
|
62 |
super();
|
63 |
PluginsManager pluginManager = PluginsLocator.getManager(); |
64 |
this.plugin = pluginManager.getPlugin(this); |
65 |
this.pluginProperties = this.plugin.getPluginProperties(); |
66 |
|
67 |
icon = IconThemeHelper.getImageIcon("grid-preferences");
|
68 |
|
69 |
chkShowGrid=new JCheckBox(PluginServices.getText(this,"mostrar_rejilla")); |
70 |
addComponent(chkShowGrid); |
71 |
chkAdjustGrid=new JCheckBox(PluginServices.getText(this,"ajustar_rejilla")); |
72 |
addComponent(chkAdjustGrid); |
73 |
addComponent(lblUnits); |
74 |
|
75 |
// distance x
|
76 |
addComponent(PluginServices.getText(this, "distance_x") + ":", |
77 |
txtDistanceX = new JTextField("", 15)); |
78 |
// distance y
|
79 |
addComponent(PluginServices.getText(this, "distance_y") + ":", |
80 |
txtDistanceY = new JTextField("", 15)); |
81 |
// setParentID(ViewPage.id);
|
82 |
|
83 |
} |
84 |
|
85 |
public void initializeValues() { |
86 |
boolean showGrid = ((Boolean)pluginProperties.getDynValue("showgrid")).booleanValue(); |
87 |
boolean adjustGrid = ((Boolean)pluginProperties.getDynValue("adjustgrid")).booleanValue(); |
88 |
|
89 |
double dx = ((Double)pluginProperties.getDynValue("griddistancex")).doubleValue(); |
90 |
double dy = ((Double)pluginProperties.getDynValue("griddistancey")).doubleValue(); |
91 |
|
92 |
Grid.SHOWGRID=showGrid; |
93 |
Grid.ADJUSTGRID=adjustGrid; |
94 |
Grid.GRIDSIZEX=dx; |
95 |
Grid.GRIDSIZEY=dy; |
96 |
|
97 |
chkShowGrid.setSelected(showGrid); |
98 |
chkAdjustGrid.setSelected(adjustGrid); |
99 |
txtDistanceX.setText(String.valueOf(dx));
|
100 |
txtDistanceY.setText(String.valueOf(dy));
|
101 |
} |
102 |
|
103 |
public String getID() { |
104 |
return ID;
|
105 |
} |
106 |
|
107 |
public String getTitle() { |
108 |
return PluginServices.getText(this, "Grid"); |
109 |
} |
110 |
|
111 |
public JPanel getPanel() { |
112 |
return this; |
113 |
} |
114 |
|
115 |
public void storeValues() throws StoreException { |
116 |
boolean showGrid;
|
117 |
boolean adjustGrid;
|
118 |
double dx;
|
119 |
double dy;
|
120 |
|
121 |
showGrid=chkShowGrid.isSelected(); |
122 |
adjustGrid=chkAdjustGrid.isSelected(); |
123 |
try{
|
124 |
dx=Double.parseDouble(txtDistanceX.getText());
|
125 |
dy=Double.parseDouble(txtDistanceY.getText());
|
126 |
}catch (Exception e) { |
127 |
throw new StoreException(PluginServices.getText(this,"distancia_malla_incorrecta")); |
128 |
} |
129 |
|
130 |
this.pluginProperties.setDynValue("showgrid", showGrid); |
131 |
this.pluginProperties.setDynValue("adjustgrid", adjustGrid); |
132 |
this.pluginProperties.setDynValue("griddistancex", dx); |
133 |
this.pluginProperties.setDynValue("griddistancey", dy); |
134 |
|
135 |
|
136 |
Grid.SHOWGRID=showGrid; |
137 |
Grid.ADJUSTGRID=adjustGrid; |
138 |
Grid.GRIDSIZEX=dx; |
139 |
Grid.GRIDSIZEY=dy; |
140 |
|
141 |
IWindow window=PluginServices.getMDIManager().getActiveWindow(); |
142 |
if (window instanceof DefaultViewPanel){ |
143 |
MapControl mc=((DefaultViewPanel)window).getMapControl(); |
144 |
Grid cadGrid=mc.getGrid(); |
145 |
cadGrid.setShowGrid(showGrid); |
146 |
cadGrid.setAdjustGrid(adjustGrid); |
147 |
cadGrid.setGridSizeX(dx); |
148 |
cadGrid.setGridSizeY(dy); |
149 |
} |
150 |
|
151 |
} |
152 |
|
153 |
public void initializeDefaults() { |
154 |
chkShowGrid.setSelected(Grid.DefaultShowGrid); |
155 |
chkAdjustGrid.setSelected(Grid.DefaultAdjustGrid); |
156 |
txtDistanceX.setText(String.valueOf(Grid.DefaultGridSizeX));
|
157 |
txtDistanceY.setText(String.valueOf(Grid.DefaultGridSizeY));
|
158 |
} |
159 |
|
160 |
public ImageIcon getIcon() { |
161 |
return icon;
|
162 |
} |
163 |
|
164 |
public boolean isValueChanged() { |
165 |
return super.hasChanged(); |
166 |
} |
167 |
|
168 |
public void setChangesApplied() { |
169 |
setChanged(false);
|
170 |
} |
171 |
} |