svn-gvsig-desktop / branches / v10 / extensions / extCoords / src / org / gvsig / iver / extensions / coords / CoordsExtension.java @ 11098
History | View | Annotate | Download (6.11 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 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 |
package org.gvsig.iver.extensions.coords; |
42 |
|
43 |
import java.awt.Dimension; |
44 |
import java.awt.event.MouseAdapter; |
45 |
|
46 |
import javax.swing.BorderFactory; |
47 |
import javax.swing.border.BevelBorder; |
48 |
|
49 |
import com.iver.andami.PluginServices; |
50 |
import com.iver.andami.plugins.Extension; |
51 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
52 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
53 |
|
54 |
/**
|
55 |
* @author Cesar Martinez Izquierdo <cesar.martinez@iver.es>
|
56 |
*
|
57 |
* This extension replaces the labels which contain the coordinates with
|
58 |
* new labels which show a window and allow to change the View coordinates.
|
59 |
*/
|
60 |
public class CoordsExtension extends Extension { |
61 |
//private Logger logger = PluginServices.getLogger();
|
62 |
private Label xLabel = null; |
63 |
private Label yLabel = null; |
64 |
private Label unitsLabel = null; |
65 |
private Label projectionLabel = null; |
66 |
private int numLabel=0; |
67 |
|
68 |
/* (non-Javadoc)
|
69 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
70 |
*/
|
71 |
public void execute(String actionCommand) { |
72 |
com.iver.andami.ui.mdiManager.IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow(); |
73 |
if (!(activeWindow instanceof View)) |
74 |
return;
|
75 |
|
76 |
if (actionCommand.startsWith("CHANGE_UNITS")){ |
77 |
View view = (View)activeWindow; |
78 |
IProjectView model = view.getModel(); |
79 |
DistanceUnitsConfig duc=new DistanceUnitsConfig(model);
|
80 |
PluginServices.getMDIManager().addWindow(duc); |
81 |
} |
82 |
} |
83 |
|
84 |
/* (non-Javadoc)
|
85 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
86 |
*/
|
87 |
public void initialize() { |
88 |
// remove the previous existing labels
|
89 |
PluginServices.getMainFrame().removeStatusBarLabels(View.class);
|
90 |
|
91 |
// create a new label set
|
92 |
com.iver.andami.plugins.config.generate.Label label4 = new com.iver.andami.plugins.config.generate.Label();
|
93 |
label4.setSize(110);
|
94 |
label4.setId("4");
|
95 |
com.iver.andami.plugins.config.generate.Label label5 = new com.iver.andami.plugins.config.generate.Label();
|
96 |
label5.setSize(140);
|
97 |
label5.setId("5");
|
98 |
com.iver.andami.plugins.config.generate.Label[] labelArray = {label4, label5};
|
99 |
PluginServices.getMainFrame().setStatusBarLabels(View.class, labelArray);
|
100 |
|
101 |
// add new Label controls
|
102 |
PluginServices.getMainFrame().addStatusBarControl(CoordsExtension.class, getXLabel()); |
103 |
getXLabel().setText("X =");
|
104 |
PluginServices.getMainFrame().addStatusBarControl(CoordsExtension.class, getYLabel()); |
105 |
getYLabel().setText("Y =");
|
106 |
PluginServices.getMainFrame().addStatusBarControl(CoordsExtension.class, getUnitsLabel()); |
107 |
PluginServices.getMainFrame().addStatusBarControl(CoordsExtension.class, getProjectionLabel()); |
108 |
|
109 |
// add listeners
|
110 |
getXLabel().addMouseListener(new MouseListener()); |
111 |
getYLabel().addMouseListener(new MouseListener()); |
112 |
getUnitsLabel().addMouseListener(new MouseListener()); |
113 |
} |
114 |
|
115 |
private void doubleClick(java.awt.event.MouseEvent e) { |
116 |
com.iver.andami.ui.mdiManager.IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow(); |
117 |
if (!(activeWindow instanceof View)) |
118 |
return;
|
119 |
View view= (View) activeWindow; |
120 |
IProjectView model = view.getModel(); |
121 |
DistanceUnitsConfig duc=new DistanceUnitsConfig(model);
|
122 |
PluginServices.getMDIManager().addWindow(duc); |
123 |
} |
124 |
|
125 |
/* (non-Javadoc)
|
126 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
127 |
*/
|
128 |
public boolean isEnabled() { |
129 |
com.iver.andami.ui.mdiManager.IWindow activeWindow = |
130 |
PluginServices.getMDIManager().getActiveWindow(); |
131 |
|
132 |
if (activeWindow!=null && activeWindow instanceof View) { |
133 |
return true; |
134 |
} |
135 |
return false; |
136 |
} |
137 |
|
138 |
/* (non-Javadoc)
|
139 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
140 |
*/
|
141 |
public boolean isVisible() { |
142 |
com.iver.andami.ui.mdiManager.IWindow activeWindow = |
143 |
PluginServices.getMDIManager().getActiveWindow(); |
144 |
|
145 |
if (activeWindow !=null && activeWindow instanceof View) { |
146 |
return true; |
147 |
} |
148 |
return false; |
149 |
} |
150 |
|
151 |
private Label getLabel(int width) { |
152 |
Label lbl = new Label(); |
153 |
lbl.setPreferredSize(new Dimension(width, PluginServices.getMainFrame().getStatusBar().getHeight()-2)); |
154 |
lbl.setSize(new Dimension(width, PluginServices.getMainFrame().getStatusBar().getHeight()-2)); |
155 |
lbl.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); |
156 |
lbl.setName("Label"+numLabel++);
|
157 |
return lbl;
|
158 |
} |
159 |
|
160 |
public Label getXLabel() { |
161 |
if (xLabel!=null) |
162 |
return xLabel;
|
163 |
xLabel = getLabel(126);
|
164 |
xLabel.setName("x");
|
165 |
return xLabel;
|
166 |
} |
167 |
|
168 |
public Label getYLabel() { |
169 |
if (yLabel!=null) |
170 |
return yLabel;
|
171 |
yLabel = getLabel(126);
|
172 |
yLabel.setName("y");
|
173 |
return yLabel;
|
174 |
} |
175 |
|
176 |
public Label getUnitsLabel() { |
177 |
if (unitsLabel!=null) |
178 |
return unitsLabel;
|
179 |
unitsLabel = getLabel(85);
|
180 |
unitsLabel.setName("units");
|
181 |
return unitsLabel;
|
182 |
} |
183 |
|
184 |
public Label getProjectionLabel() { |
185 |
if (projectionLabel!=null) |
186 |
return projectionLabel;
|
187 |
projectionLabel = getLabel(85);
|
188 |
projectionLabel.setName("projection");
|
189 |
return projectionLabel;
|
190 |
} |
191 |
|
192 |
private class MouseListener extends MouseAdapter { |
193 |
public void mouseClicked(java.awt.event.MouseEvent e) { |
194 |
//simpleClick(e);
|
195 |
if (e.getClickCount()==2) { |
196 |
doubleClick(e); |
197 |
} |
198 |
} |
199 |
} |
200 |
} |