Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / gui / preferencespage / GridPage.java @ 23642

History | View | Annotate | Download (7.85 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: GridPage.java 21668 2008-06-19 09:05:14Z vcaballero $
45
* $Log$
46
* Revision 1.4  2006-08-22 12:27:53  jaume
47
* improved performances when saving
48
*
49
* Revision 1.3  2006/08/22 07:37:32  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.2  2006/08/10 11:13:02  caballero
53
* mostrar unidades
54
*
55
* Revision 1.1  2006/08/10 08:18:35  caballero
56
* configurar grid
57
*
58
* Revision 1.1  2006/08/04 11:41:05  caballero
59
* poder especificar el zoom a aplicar en las vistas
60
*
61
* Revision 1.3  2006/07/31 10:02:31  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.2  2006/06/13 07:43:08  fjp
65
* Ajustes sobre los cuadros de dialogos de preferencias
66
*
67
* Revision 1.1  2006/06/12 16:04:28  caballero
68
* Preferencias
69
*
70
* Revision 1.11  2006/06/06 10:26:31  jaume
71
* *** empty log message ***
72
*
73
* Revision 1.10  2006/06/05 17:07:17  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.9  2006/06/05 17:00:44  jaume
77
* *** empty log message ***
78
*
79
* Revision 1.8  2006/06/05 16:57:59  jaume
80
* *** empty log message ***
81
*
82
* Revision 1.7  2006/06/05 14:45:06  jaume
83
* *** empty log message ***
84
*
85
* Revision 1.6  2006/06/05 11:00:09  jaume
86
* *** empty log message ***
87
*
88
* Revision 1.5  2006/06/05 10:39:02  jaume
89
* *** empty log message ***
90
*
91
* Revision 1.4  2006/06/05 10:13:40  jaume
92
* *** empty log message ***
93
*
94
* Revision 1.3  2006/06/05 10:06:08  jaume
95
* *** empty log message ***
96
*
97
* Revision 1.2  2006/06/05 09:51:56  jaume
98
* *** empty log message ***
99
*
100
* Revision 1.1  2006/06/02 10:50:18  jaume
101
* *** empty log message ***
102
*
103
*
104
*/
105
package com.iver.cit.gvsig.gui.preferencespage;
106

    
107
import java.util.prefs.Preferences;
108

    
109
import javax.swing.ImageIcon;
110
import javax.swing.JCheckBox;
111
import javax.swing.JLabel;
112
import javax.swing.JPanel;
113
import javax.swing.JTextField;
114

    
115
import org.gvsig.fmap.mapcontrol.MapControl;
116
import org.gvsig.fmap.mapcontrol.tools.grid.CADGrid;
117

    
118
import com.iver.andami.PluginServices;
119
import com.iver.andami.preferences.AbstractPreferencePage;
120
import com.iver.andami.preferences.StoreException;
121
import com.iver.andami.ui.mdiManager.IWindow;
122
import com.iver.cit.gvsig.project.documents.view.gui.View;
123

    
124
public class GridPage extends AbstractPreferencePage {
125
        private static Preferences prefs = Preferences.userRoot().node( "cadtooladapter" );
126
        private org.gvsig.fmap.mapcontrol.MapControl mapControl;
127
        private JCheckBox chkShowGrid;
128
        private JCheckBox chkAdjustGrid;
129
        private JTextField txtDistanceX;
130
        private JTextField txtDistanceY;
131
        private JLabel lblUnits=new JLabel();
132
        private ImageIcon icon;
133

    
134
        public GridPage() {
135
                super();
136
                icon = PluginServices.getIconTheme().get("grid-icon");
137
                chkShowGrid=new JCheckBox(PluginServices.getText(this,"mostrar_rejilla"));
138
                addComponent(chkShowGrid);
139
                chkAdjustGrid=new JCheckBox(PluginServices.getText(this,"ajustar_rejilla"));
140
                addComponent(chkAdjustGrid);
141
                addComponent(lblUnits);
142

    
143
                // distance x
144
                addComponent(PluginServices.getText(this, "distance_x") + ":",
145
                        txtDistanceX = new JTextField("", 15));
146
                // distance y
147
                addComponent(PluginServices.getText(this, "distance_y") + ":",
148
                        txtDistanceY = new JTextField("", 15));
149
                setParentID(ViewPage.id);
150

    
151
        }
152

    
153
        public void initializeValues() {
154
                boolean showGrid = prefs.getBoolean("grid.showgrid",CADGrid.DefaultShowGrid);
155
                boolean adjustGrid = prefs.getBoolean("grid.adjustgrid",CADGrid.DefaultAdjustGrid);
156

    
157
                double dx = prefs.getDouble("grid.distancex",CADGrid.DefaultGridSizeX);
158
                double dy = prefs.getDouble("grid.distancey",CADGrid.DefaultGridSizeY);
159

    
160
                CADGrid.SHOWGRID=showGrid;
161
                CADGrid.ADJUSTGRID=adjustGrid;
162
                CADGrid.GRIDSIZEX=dx;
163
                CADGrid.GRIDSIZEY=dy;
164

    
165
//                setGridVisibility(showGrid);
166
//                setAdjustGrid(adjustGrid);
167
//                cadgrid.setGridSizeX(dx);
168
//                cadgrid.setGridSizeY(dy);
169
//                cta=CADExtension.getCADToolAdapter();
170
//                cta.initializeGrid();
171
//                ViewPort vp=cta.getMapControl().getViewPort();
172
//                boolean showGrid = prefs.getBoolean("grid.showgrid",cta.getGrid().isShowGrid());
173
//                boolean adjustGrid = prefs.getBoolean("grid.adjustgrid",cta.getGrid().isAdjustGrid());
174
//
175
//                double dx = prefs.getDouble("grid.distancex",cta.getGrid().getGridSizeX());
176
//                double dy = prefs.getDouble("grid.distancey",cta.getGrid().getGridSizeY());
177
//                CADGrid cg=cta.getGrid();
178
                chkShowGrid.setSelected(showGrid);
179
                chkAdjustGrid.setSelected(adjustGrid);
180
                txtDistanceX.setText(String.valueOf(dx));
181
                txtDistanceY.setText(String.valueOf(dy));
182
//                lblUnits.setText(PluginServices.getText(this,"Unidades")+ "           "+PluginServices.getText(this,MapContext.getDistanceNames()[vp.getDistanceUnits()]));
183

    
184
//                cta.setGridVisibility(showGrid);
185
//                cta.setAdjustGrid(adjustGrid);
186
//                cta.getGrid().setGridSizeX(dx);
187
//                cta.getGrid().setGridSizeY(dy);
188

    
189
        }
190

    
191
        public String getID() {
192
                return this.getClass().getName();
193
        }
194

    
195
        public String getTitle() {
196
                return PluginServices.getText(this, "Grid");
197
        }
198

    
199
        public JPanel getPanel() {
200
                return this;
201
        }
202

    
203
        public void storeValues() throws StoreException {
204
                boolean showGrid;
205
                boolean adjustGrid;
206
                double dx;
207
                double dy;
208

    
209
                        showGrid=chkShowGrid.isSelected();
210
                        adjustGrid=chkAdjustGrid.isSelected();
211
                try{
212
                        dx=Double.parseDouble(txtDistanceX.getText());
213
                        dy=Double.parseDouble(txtDistanceY.getText());
214
                }catch (Exception e) {
215
                        throw new StoreException(PluginServices.getText(this,"distancia_malla_incorrecta"));
216
                }
217
                prefs.putBoolean("grid.showgrid",showGrid);
218
                prefs.putBoolean("grid.adjustgrid",adjustGrid);
219
                prefs.putDouble("grid.distancex", dx);
220
                prefs.putDouble("grid.distancey", dy);
221

    
222
                CADGrid.SHOWGRID=showGrid;
223
                CADGrid.ADJUSTGRID=adjustGrid;
224
                CADGrid.GRIDSIZEX=dx;
225
                CADGrid.GRIDSIZEY=dy;
226

    
227
                IWindow window=PluginServices.getMDIManager().getActiveWindow();
228
                if (window instanceof View){
229
                        MapControl mc=((View)window).getMapControl();
230
                        CADGrid cadGrid=mc.getGrid();
231
                        cadGrid.setShowGrid(showGrid);
232
                        cadGrid.setAdjustGrid(adjustGrid);
233
                        cadGrid.setGridSizeX(dx);
234
                        cadGrid.setGridSizeY(dy);
235
                }
236

    
237
        }
238

    
239
        public void initializeDefaults() {
240
                chkShowGrid.setSelected(CADGrid.DefaultShowGrid);
241
                chkAdjustGrid.setSelected(CADGrid.DefaultAdjustGrid);
242
//                ViewPort vp=cta.getMapControl().getViewPort();
243
//                lblUnits.setText(PluginServices.getText(this,"Unidades")+ "           "+PluginServices.getText(this,MapContext.getDistanceNames()[vp.getDistanceUnits()]));
244
                txtDistanceX.setText(String.valueOf(CADGrid.DefaultGridSizeX));
245
                txtDistanceY.setText(String.valueOf(CADGrid.DefaultGridSizeY));
246
        }
247

    
248
        public ImageIcon getIcon() {
249
                return icon;
250
        }
251

    
252
        public boolean isValueChanged() {
253
                return super.hasChanged();
254
        }
255

    
256
        public void setChangesApplied() {
257
                setChanged(false);
258
        }
259
}