9 |
9 |
import java.awt.Color;
|
10 |
10 |
import java.awt.Graphics;
|
11 |
11 |
import java.awt.Image;
|
|
12 |
import java.awt.Point;
|
12 |
13 |
import java.awt.event.MouseEvent;
|
13 |
14 |
import java.awt.geom.Point2D;
|
14 |
15 |
import java.awt.image.BufferedImage;
|
15 |
16 |
|
|
17 |
import org.cresques.cts.IProjection;
|
16 |
18 |
import org.gvsig.andami.PluginServices;
|
|
19 |
import org.gvsig.andami.ui.mdiFrame.MainFrame;
|
17 |
20 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
|
|
21 |
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener;
|
18 |
22 |
import org.gvsig.fmap.mapcontext.MapContext;
|
19 |
23 |
import org.gvsig.fmap.mapcontext.ViewPort;
|
20 |
24 |
import org.gvsig.fmap.mapcontext.layers.CancelationException;
|
... | ... | |
48 |
52 |
|
49 |
53 |
private EditingServiceParameter currentParam;
|
50 |
54 |
|
|
55 |
private StatusBarListener sbl = null;
|
|
56 |
|
51 |
57 |
private static final Image imageCursor = new BufferedImage(32, 32,
|
52 |
58 |
BufferedImage.TYPE_INT_ARGB);
|
53 |
59 |
static {
|
... | ... | |
58 |
64 |
g.setColor(Color.MAGENTA);
|
59 |
65 |
g.drawLine((x - size1), (y), (x + size1), (y));
|
60 |
66 |
g.drawLine((x), (y - size1), (x), (y + size1));
|
61 |
|
// g.setColor(Color.MAGENTA);
|
62 |
67 |
g.drawRect((x - 6), (y - 6), 12, 12);
|
63 |
68 |
g.drawRect((x - 3), (y - 3), 6, 6);
|
64 |
69 |
}
|
... | ... | |
67 |
72 |
// TODO Auto-generated constructor stub
|
68 |
73 |
if (mapControl != null) {
|
69 |
74 |
this.mapControl = mapControl;
|
|
75 |
sbl = new StatusBarListener(mapControl);
|
70 |
76 |
initMapControlListeners(mapControl);
|
71 |
77 |
FLayers layers = mapControl.getMapContext().getLayers();
|
72 |
78 |
for (int i = 0; i < layers.getLayersCount(); i++) {
|
... | ... | |
97 |
103 |
|
98 |
104 |
private void initMapControlListeners(MapControl mapControl) {
|
99 |
105 |
DefaultViewPanel view = getActiveView();
|
|
106 |
|
100 |
107 |
view.addConsoleListener("VectorEditingConsole", new ResponseListener() {
|
101 |
108 |
|
102 |
109 |
public void acceptResponse(String response) {
|
103 |
|
textEntered(response);
|
|
110 |
try {
|
|
111 |
textEntered(response);
|
|
112 |
}
|
|
113 |
catch (RuntimeException e) {
|
|
114 |
showErrorConsole(e);
|
|
115 |
getNextParameter();
|
|
116 |
}
|
104 |
117 |
}
|
|
118 |
|
|
119 |
private void showErrorConsole(RuntimeException e) {
|
|
120 |
DefaultViewPanel view = getActiveView();
|
|
121 |
view.getConsolePanel().addText(e.getMessage(), JConsole.ERROR);
|
|
122 |
|
|
123 |
}
|
105 |
124 |
});
|
|
125 |
|
106 |
126 |
MapContext context = mapControl.getMapContext();
|
107 |
127 |
FLayers layers = context.getLayers();
|
108 |
128 |
layers.addLayerListener(layerListener);
|
... | ... | |
116 |
136 |
throws CancelationException {}
|
117 |
137 |
|
118 |
138 |
public void layerRemoved(LayerCollectionEvent e) {
|
119 |
|
// TODO Auto-generated method stub
|
120 |
|
// layer.removeLayerListener(layerListener)
|
121 |
139 |
FLayers layers2 = e.getLayers();
|
122 |
140 |
for (int i = 0; i < layers2.getLayersCount(); i++) {
|
123 |
141 |
FLayer layer = layers2.getLayer(i);
|
... | ... | |
148 |
166 |
|
149 |
167 |
private void textEntered(String response) {
|
150 |
168 |
int type = currentParam.getType();
|
151 |
|
DefaultViewPanel view = getActiveView();
|
152 |
|
switch (type) {
|
153 |
|
case EditingServiceParameter.TYPE_POINT:
|
154 |
|
try {
|
|
169 |
try {
|
|
170 |
switch (type) {
|
|
171 |
case EditingServiceParameter.TYPE_POINT:
|
155 |
172 |
String[] numbers = new String[1];
|
156 |
173 |
numbers[0] = response;
|
157 |
174 |
numbers = response.split(",");
|
158 |
175 |
if (numbers.length == 2) {
|
159 |
|
if(numbers[0].startsWith("(") && numbers[1].endsWith(")\n")){ //CCS format
|
|
176 |
if (numbers[0].startsWith("(") && numbers[1].endsWith(")\n")) { // CCS
|
160 |
177 |
numbers[0] = numbers[0].replace("(", "");
|
161 |
178 |
numbers[1] = numbers[1].replace(")\n", "");
|
162 |
179 |
}
|
... | ... | |
167 |
184 |
|
168 |
185 |
}
|
169 |
186 |
else {
|
170 |
|
view.getConsolePanel().addText("?Datos inv?lidos!", JConsole.ERROR);
|
|
187 |
throw new RuntimeException("Datos inv?lidos: " + response);
|
171 |
188 |
}
|
172 |
|
}
|
173 |
|
catch (Exception e) {
|
174 |
|
view.getConsolePanel().addText("?Datos inv?lidos!", JConsole.ERROR);
|
175 |
|
}
|
176 |
|
|
177 |
|
case EditingServiceParameter.TYPE_LIST_POINTS:
|
178 |
|
case EditingServiceParameter.TYPE_OPTION:
|
179 |
|
case EditingServiceParameter.TYPE_SELECTION:
|
180 |
|
case EditingServiceParameter.TYPE_GEOMETRY:
|
181 |
|
case EditingServiceParameter.TYPE_VALUE:
|
|
189 |
case EditingServiceParameter.TYPE_LIST_POINTS:
|
|
190 |
case EditingServiceParameter.TYPE_OPTION:
|
|
191 |
case EditingServiceParameter.TYPE_SELECTION:
|
|
192 |
case EditingServiceParameter.TYPE_GEOMETRY:
|
|
193 |
case EditingServiceParameter.TYPE_VALUE:
|
|
194 |
}
|
|
195 |
getNextParameter();
|
182 |
196 |
}
|
183 |
|
getNextParameter();
|
|
197 |
catch (Exception e) {
|
|
198 |
throw new RuntimeException("Datos inv?lidos: " + response);
|
|
199 |
}
|
184 |
200 |
}
|
185 |
201 |
|
186 |
202 |
public void setCurrentLayer(FLyrVect layer) {
|
... | ... | |
188 |
204 |
}
|
189 |
205 |
|
190 |
206 |
public void activateTool(String name) {
|
191 |
|
// TODO Auto-generated method stub
|
192 |
207 |
|
193 |
208 |
EditingManager manager = EditingLocator.getManager();
|
194 |
209 |
|
... | ... | |
260 |
275 |
// TODO Auto-generated method stub
|
261 |
276 |
if (activatedTool != null) {
|
262 |
277 |
if (currentParam != null) {
|
263 |
|
if (currentParam.getType() == EditingServiceParameter.TYPE_POINT) {
|
264 |
|
ViewPort vp = mapControl.getViewPort();
|
265 |
|
Point2D point;
|
266 |
|
point = vp.toMapPoint(e.getX(), e.getY());
|
267 |
|
this.activatedTool.setValueParameter(currentParam, point);
|
|
278 |
switch (currentParam.getType()) {
|
|
279 |
case EditingServiceParameter.TYPE_POINT:
|
|
280 |
ViewPort vp = mapControl.getViewPort();
|
|
281 |
Point2D point;
|
|
282 |
point = vp.toMapPoint(e.getX(), e.getY());
|
|
283 |
this.activatedTool.setValueParameter(currentParam, point);
|
|
284 |
|
|
285 |
case EditingServiceParameter.TYPE_LIST_POINTS:
|
|
286 |
case EditingServiceParameter.TYPE_OPTION:
|
|
287 |
case EditingServiceParameter.TYPE_SELECTION:
|
|
288 |
case EditingServiceParameter.TYPE_GEOMETRY:
|
|
289 |
case EditingServiceParameter.TYPE_VALUE:
|
268 |
290 |
}
|
|
291 |
getNextParameter();
|
269 |
292 |
}
|
270 |
|
getNextParameter();
|
|
293 |
|
271 |
294 |
}
|
272 |
295 |
}
|
273 |
296 |
|
... | ... | |
276 |
299 |
}
|
277 |
300 |
|
278 |
301 |
public void mouseMoved(MouseEvent e) throws BehaviorException {
|
279 |
|
// TODO Auto-generated method stub
|
|
302 |
showCoords(e.getPoint());
|
|
303 |
|
|
304 |
getMapControl().repaint();
|
280 |
305 |
}
|
281 |
306 |
|
|
307 |
private void showCoords(Point point) {
|
|
308 |
String[] axisText = new String[2];
|
|
309 |
axisText[0] = "X = ";
|
|
310 |
axisText[1] = "Y = ";
|
|
311 |
|
|
312 |
ViewPort vp = mapControl.getMapContext().getViewPort();
|
|
313 |
IProjection iProj = vp.getProjection();
|
|
314 |
Point2D p = vp.toMapPoint((int) point.getX(), (int) point.getY());
|
|
315 |
;
|
|
316 |
// if (mapAdjustedPoint == null) {
|
|
317 |
// p = vp.toMapPoint(point);
|
|
318 |
// } else {
|
|
319 |
// p = mapAdjustedPoint;
|
|
320 |
// }
|
|
321 |
sbl.setFractionDigits(p);
|
|
322 |
axisText = sbl.setCoorDisplayText(axisText);
|
|
323 |
MainFrame mF = PluginServices.getMainFrame();
|
|
324 |
|
|
325 |
if (mF != null) {
|
|
326 |
mF.getStatusBar().setMessage(
|
|
327 |
"units",
|
|
328 |
PluginServices.getText(this,
|
|
329 |
MapContext.getDistanceNames()[vp.getDistanceUnits()]));
|
|
330 |
mF.getStatusBar().setControlValue("scale",
|
|
331 |
String.valueOf(mapControl.getMapContext().getScaleView()));
|
|
332 |
mF.getStatusBar().setMessage("projection", iProj.getAbrev());
|
|
333 |
|
|
334 |
String[] coords = sbl.getCoords(p);
|
|
335 |
mF.getStatusBar().setMessage("x", axisText[0] + coords[0]);
|
|
336 |
mF.getStatusBar().setMessage("y", axisText[1] + coords[1]);
|
|
337 |
}
|
|
338 |
|
|
339 |
}
|
|
340 |
|
282 |
341 |
public void mousePressed(MouseEvent e) throws BehaviorException {
|
283 |
342 |
// TODO Auto-generated method stub
|
284 |
343 |
}
|