Revision 37138

View differences:

branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/gui/cad/CADTool.java
1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
1
/* gvSIG. Geographic Information System of the Valencian Government
2 2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
5 6
 * This program is free software; you can redistribute it and/or
6 7
 * modify it under the terms of the GNU General Public License
7 8
 * as published by the Free Software Foundation; either version 2
8 9
 * of the License, or (at your option) any later version.
9
 *
10
 * 
10 11
 * This program is distributed in the hope that it will be useful,
11 12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 14
 * GNU General Public License for more details.
14
 *
15
 * 
15 16
 * You should have received a copy of the GNU General Public License
16 17
 * 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
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
40 21
 */
41 22
package org.gvsig.editing.gui.cad;
42
import java.awt.Graphics;
23

  
43 24
import java.awt.event.InputEvent;
44 25
import java.awt.event.MouseEvent;
45 26

  
......
48 29
import org.gvsig.fmap.dal.exception.DataException;
49 30
import org.gvsig.fmap.mapcontrol.MapControlDrawer;
50 31

  
51

  
52

  
53 32
/**
54 33
 * DOCUMENT ME!
55
 *
34
 * 
56 35
 * @author $author$
57 36
 */
58 37
public interface CADTool {
59 38

  
39
    public static int TOPGEOMETRY = 2000;
60 40

  
61
	public static int TOPGEOMETRY = 2000;
41
    public void init();
62 42

  
63
	public void init();
64
	public void end();
65
	public void transition(double x, double y, InputEvent event);
66
	public void transition(double d);
67
	public void transition(String s) throws CommandException;
68
	public void addPoint(double x,double y,InputEvent event);
69
	public void addValue(double d);
70
	public void addOption(String s);
71
	public void setQuestion(String s);
43
    public void end();
72 44

  
73
	/**
74
	 * Recibe un graphics en el que se encuentra dibujada la
75
	 * EditableFeatureSource que se pasa como par�metro. En este m�todo, la
76
	 * herramienta ha de implementar el dibujado de la operaci�n que se est�
77
	 * realizando dependiendo del estado. Por ejemplo al dibujar un c�rculo
78
	 * mediante 3 puntos, cuando la herramienta se encuentre en el estado en
79
	 * el que s�lo falta un punto, se dibujar� el c�rculo teniendo en cuenta
80
	 * como tercer punto el puntero del rat�n (pasado en los par�metros x e
81
	 * y). Este m�todo es invocado tras cada transici�n y cada vez que se
82
	 * mueve el rat�n.
83
	 *
84
	 * @param g DOCUMENT ME!
85
	 * @param efs DOCUMENT ME!
86
	 * @param selectedGeometries DOCUMENT ME!
87
	 * @param x DOCUMENT ME!
88
	 * @param y DOCUMENT ME!
89
	 */
90
	void drawOperation(MapControlDrawer renderer,double x, double y);
45
    public void transition(double x, double y, InputEvent event);
91 46

  
92
	/**
93
	 * Obtiene la pregunta que saldr� en la consola relativa al estado en el
94
	 * que se encuentra la herramienta
95
	 *
96
	 * @return DOCUMENT ME!
97
	 */
98
	String getQuestion();
47
    public void transition(double d);
99 48

  
100
	/**
101
	 * DOCUMENT ME!
102
	 *
103
	 * @param cta DOCUMENT ME!
104
	 */
105
	public void setCadToolAdapter(CADToolAdapter cta);
49
    public void transition(String s) throws CommandException;
106 50

  
107
	/**
108
	 * DOCUMENT ME!
109
	 *
110
	 * @return DOCUMENT ME!
111
	 */
112
	public CADToolAdapter getCadToolAdapter();
113
	public String[] getDescriptions();
114
	public void setDescription(String[] descriptions);
115
	public String getName();
116
	public VectorialLayerEdited getVLE();
117
	void clearSelection() throws DataException;
118
	public boolean isApplicable(int shapeType);
119
	public void setPreviosTool(DefaultCADTool tool);
120
	public void restorePreviousTool();
121
	public void endTransition(double x, double y, MouseEvent e);
51
    public void addPoint(double x, double y, InputEvent event);
52

  
53
    public void addValue(double d);
54

  
55
    public void addOption(String s);
56

  
57
    public void setQuestion(String s);
58

  
59
    /**
60
     * Recibe un graphics en el que se encuentra dibujada la
61
     * EditableFeatureSource que se pasa como par�metro. En este m�todo, la
62
     * herramienta ha de implementar el dibujado de la operaci�n que se est�
63
     * realizando dependiendo del estado. Por ejemplo al dibujar un c�rculo
64
     * mediante 3 puntos, cuando la herramienta se encuentre en el estado en
65
     * el que s�lo falta un punto, se dibujar� el c�rculo teniendo en
66
     * cuenta
67
     * como tercer punto el puntero del rat�n (pasado en los par�metros x e
68
     * y). Este m�todo es invocado tras cada transici�n y cada vez que se
69
     * mueve el rat�n.
70
     * 
71
     * @param g
72
     *            DOCUMENT ME!
73
     * @param efs
74
     *            DOCUMENT ME!
75
     * @param selectedGeometries
76
     *            DOCUMENT ME!
77
     * @param x
78
     *            DOCUMENT ME!
79
     * @param y
80
     *            DOCUMENT ME!
81
     */
82
    void drawOperation(MapControlDrawer renderer, double x, double y);
83

  
84
    /**
85
     * Obtiene la pregunta que saldr� en la consola relativa al estado en el
86
     * que se encuentra la herramienta
87
     * 
88
     * @return DOCUMENT ME!
89
     */
90
    String getQuestion();
91

  
92
    /**
93
     * DOCUMENT ME!
94
     * 
95
     * @param cta
96
     *            DOCUMENT ME!
97
     */
98
    public void setCadToolAdapter(CADToolAdapter cta);
99

  
100
    /**
101
     * DOCUMENT ME!
102
     * 
103
     * @return DOCUMENT ME!
104
     */
105
    public CADToolAdapter getCadToolAdapter();
106

  
107
    public String[] getDescriptions();
108

  
109
    public void setDescription(String[] descriptions);
110

  
111
    public String getName();
112

  
113
    public VectorialLayerEdited getVLE();
114

  
115
    void clearSelection() throws DataException;
116

  
117
    public boolean isApplicable(int shapeType);
118

  
119
    public void setPreviosTool(DefaultCADTool tool);
120

  
121
    public void restorePreviousTool();
122

  
123
    public void endTransition(double x, double y, MouseEvent e);
122 124
}
branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/gui/cad/CADToolAdapter.java
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
 */
1 22
package org.gvsig.editing.gui.cad;
2 23

  
3 24
import java.awt.Color;
......
58 79
 * <p>
59 80
 * Allows user interact with different CAD tools, on a layer being edited.
60 81
 * </p>
61
 *
82
 * 
62 83
 * <p>
63 84
 * There are two ways of interacting:
64 85
 * <ul>
65 86
 * <li><b>With the mouse</b> : user selects any {@link CADTool CADTool} that
66 87
 * produces mouse events as consequence of the actions working with the layer
67
 * being edited. </li>
88
 * being edited.</li>
68 89
 * <li><b>Writing commands in the edition console</b> : most of the
69 90
 * {@link CADTool CADTool} mouse actions can also be called writing a command or
70 91
 * a command's parameter in the associated edition console, and pressing the key
71
 * <code>Enter</code>. If the command isn't valid, will notify it. </li>
92
 * <code>Enter</code>. If the command isn't valid, will notify it.</li>
72 93
 * </ul>
73 94
 * </p>
74
 *
95
 * 
75 96
 * <p>
76 97
 * The edition has been implemented as a <i>finite machine</i>, with three kind
77 98
 * of transitions between states according the parameters introduced:
78 99
 * <ul>
79
 * <li><i>First transition type: <b>Point</i></b>: if <code>text</code>
80
 * matches with any pattern of parameters needed for any kind of point
81
 * coordinates.<br>
100
 * <li><i>First transition type: <b>Point</i></b>: if <code>text</code> matches
101
 * with any pattern of parameters needed for any kind of point coordinates.<br>
82 102
 * There are eight ways of introducing point 2D coordinates:
83 103
 * <ul>
84 104
 * <li><i>X,Y</i> : absolute cardinal 2D coordinate from the center <i>(0,0)</i>
85 105
 * of the CCS <i>Current Coordinate System</i>.</li>
86
 * <li><i>@X,Y</i> : relative cardinal 2D distances from the last point added
87
 * of the CCS. If it's the first point of the geometry, works like <i>X,Y</i>.</li>
106
 * <li><i>@X,Y</i> : relative cardinal 2D distances from the last point added of
107
 * the CCS. If it's the first point of the geometry, works like <i>X,Y</i>.</li>
88 108
 * <li><i>length< angle</i> : absolute polar 2D coordinate from the center
89 109
 * <i>(0,0)</i> of the CCS <i>Current Coordinate System</i>, using <i>angle</i>
90 110
 * from the <i>X</i> axis of CCS, and <i>length</i> far away.</li>
91
 * <li><i>@length< angle</i> : relative polar 2D coordinate from the last
92
 * point added of the CCS <i>Current Coordinate System</i>, using <i>angle</i>
93
 * from the <i>X</i> axis of CCS, and <i>length</i> far away. If it's the
94
 * first point of the geometry, works like <i>length< angle</i>.</li>
111
 * <li><i>@length< angle</i> : relative polar 2D coordinate from the last point
112
 * added of the CCS <i>Current Coordinate System</i>, using <i>angle</i> from
113
 * the <i>X</i> axis of CCS, and <i>length</i> far away. If it's the first point
114
 * of the geometry, works like <i>length< angle</i>.</li>
95 115
 * <li><i>*X,Y</i> : like <i>X,Y</i> but using UCS <i>Universal Coordinate
96 116
 * System</i> as reference.</li>
97 117
 * <li><i>@*X,Y</i> : like <i>@X,Y</i> but using UCS <i>Universal Coordinate
......
104 124
 * the geometry, works like <i>*length< angle</i>.</li>
105 125
 * </ul>
106 126
 * </li>
107
 * <li><i>Second transition type: <b>Value</i></b>: if recognizes it as a
108
 * single number.</li>
127
 * <li><i>Second transition type: <b>Value</i></b>: if recognizes it as a single
128
 * number.</li>
109 129
 * <li><i>Third transition type: <b>Option</i></b>: by default, if can't
110 130
 * classify the information as a single number neither as a point. This
111 131
 * information will be an <code>String</code> and dealt as an option of the
......
113 133
 * rewritten in the console notifying the user that isn't correct.</li>
114 134
 * </ul>
115 135
 * </p>
116
 *
136
 * 
117 137
 * @see Behavior
118 138
 * @see MapControl
119 139
 */
120 140
public class CADToolAdapter extends Behavior {
121 141

  
122
	private static Logger logger = LoggerFactory
123
			.getLogger(CADToolAdapter.class);
142
    private static Logger logger = LoggerFactory
143
        .getLogger(CADToolAdapter.class);
124 144

  
125
	/**
126
	 * Stores the CAD tools to edit the layers of the associated
127
	 * <code>MapControl</code>.
128
	 *
129
	 * @see #addCADTool(String, CADTool)
130
	 * @see #getCadTool()
131
	 * @see #getCADTool(String)
132
	 */
133
	private static HashMap namesCadTools = new HashMap();
145
    /**
146
     * Stores the CAD tools to edit the layers of the associated
147
     * <code>MapControl</code>.
148
     * 
149
     * @see #addCADTool(String, CADTool)
150
     * @see #getCadTool()
151
     * @see #getCADTool(String)
152
     */
153
    private static HashMap namesCadTools = new HashMap();
134 154

  
135
	/**
136
	 * Reference to the object used to manage the edition of the layers of the
137
	 * associated <code>MapControl</code>.
138
	 *
139
	 * @see EditionManager
140
	 * @see #getEditionManager()
141
	 */
142
	private EditionManager editionManager = new EditionManager();
143
	
144
	/**
145
	 * Reference to the MapContext library manager, used to create symbols
146
	 * and legends.
147
	 */
148
	private MapContextManager mapContextManager = MapContextLocator
149
			.getMapContextManager();
155
    /**
156
     * Reference to the object used to manage the edition of the layers of the
157
     * associated <code>MapControl</code>.
158
     * 
159
     * @see EditionManager
160
     * @see #getEditionManager()
161
     */
162
    private EditionManager editionManager = new EditionManager();
150 163

  
151
	/**
152
	 * Identifies that the data are absolute coordinates of the new point from
153
	 * the (0, 0) position.
154
	 */
155
	public static final int ABSOLUTE = 0;
164
    /**
165
     * Reference to the MapContext library manager, used to create symbols
166
     * and legends.
167
     */
168
    private MapContextManager mapContextManager = MapContextLocator
169
        .getMapContextManager();
156 170

  
157
	/**
158
	 * Equivalent to {@link CADToolAdapter#ABSOLUTE CADToolAdapter#ABSOLUTE}.
159
	 */
160
	public static final int RELATIVE_SCP = 1;
171
    /**
172
     * Identifies that the data are absolute coordinates of the new point from
173
     * the (0, 0) position.
174
     */
175
    public static final int ABSOLUTE = 0;
161 176

  
162
	/**
163
	 * Identifies that the data are relative distances of the new point from the
164
	 * previous introduced.
165
	 */
166
	public static final int RELATIVE_SCU = 2;
177
    /**
178
     * Equivalent to {@link CADToolAdapter#ABSOLUTE CADToolAdapter#ABSOLUTE}.
179
     */
180
    public static final int RELATIVE_SCP = 1;
167 181

  
168
	/**
169
	 * Identifies that the data are relative polar distances (longitude of the
170
	 * line and angle given in degrees) of the new point from the previous
171
	 * introduced.
172
	 */
173
	public static final int POLAR_SCP = 3;
182
    /**
183
     * Identifies that the data are relative distances of the new point from the
184
     * previous introduced.
185
     */
186
    public static final int RELATIVE_SCU = 2;
174 187

  
175
	/**
176
	 * Identifies that the data are relative polar distances (longitude of the
177
	 * line and angle given in radians) of the new point from the previous
178
	 * introduced.
179
	 */
180
	public static final int POLAR_SCU = 4;
188
    /**
189
     * Identifies that the data are relative polar distances (longitude of the
190
     * line and angle given in degrees) of the new point from the previous
191
     * introduced.
192
     */
193
    public static final int POLAR_SCP = 3;
181 194

  
182
	/**
183
	 * Stores the 2D map coordinates of the last point added.
184
	 */
185
	private double[] previousPoint = null;
195
    /**
196
     * Identifies that the data are relative polar distances (longitude of the
197
     * line and angle given in radians) of the new point from the previous
198
     * introduced.
199
     */
200
    public static final int POLAR_SCU = 4;
186 201

  
187
	/**
188
	 * <i>Stack with CAD tools.</i>
189
	 *
190
	 * <i>For each CAD tool we use, the last item added in this stack will
191
	 * display a different icon according to the current operation and its
192
	 * status.</i>
193
	 */
194
	private Stack cadToolStack = new Stack();
202
    /**
203
     * Stores the 2D map coordinates of the last point added.
204
     */
205
    private double[] previousPoint = null;
195 206

  
196
	/**
197
	 * X coordinate of the last dragging or moving mouse event.
198
	 */
199
	private int lastX;
207
    /**
208
     * <i>Stack with CAD tools.</i>
209
     * 
210
     * <i>For each CAD tool we use, the last item added in this stack will
211
     * display a different icon according to the current operation and its
212
     * status.</i>
213
     */
214
    private Stack cadToolStack = new Stack();
200 215

  
201
	/**
202
	 * Y coordinate of the last dragging or moving mouse event.
203
	 */
204
	private int lastY;
216
    /**
217
     * X coordinate of the last dragging or moving mouse event.
218
     */
219
    private int lastX;
205 220

  
206
	/**
207
	 * Unused attribute.
208
	 */
209
	private ISymbol symbol =
210
			mapContextManager.getSymbolManager().createSymbol(
211
			Geometry.TYPES.POINT, Color.RED);
221
    /**
222
     * Y coordinate of the last dragging or moving mouse event.
223
     */
224
    private int lastY;
212 225

  
213
	/**
214
	 * Represents the cursor's point selected in <i>map coordinates</i>.
215
	 *
216
	 * @see MapControl#toMapPoint
217
	 */
218
	private Point2D mapAdjustedPoint;
226
    /**
227
     * Unused attribute.
228
     */
229
    private ISymbol symbol = mapContextManager.getSymbolManager().createSymbol(
230
        Geometry.TYPES.POINT, Color.RED);
219 231

  
220
	/**
221
	 * Kind of geometry drawn to identify the kind of control point selected by
222
	 * the cursor's mouse.
223
	 */
224
	// private ISnapper usedSnap = null;
225
	/**
226
	 * Determines if has displayed at the edition console, the question for the
227
	 * operations that can do the user with the current CAD tool, in its current
228
	 * state.
229
	 */
230
	private boolean questionAsked = false;
232
    /**
233
     * Represents the cursor's point selected in <i>map coordinates</i>.
234
     * 
235
     * @see MapControl#toMapPoint
236
     */
237
    private Point2D mapAdjustedPoint;
231 238

  
232
	/**
233
	 * Represents the cursor's point selected in <i>screen coordinates</i>.
234
	 *
235
	 * @see ViewPort#fromMapPoint(Point2D)
236
	 */
237
	private Point2D adjustedPoint;
239
    /**
240
     * Kind of geometry drawn to identify the kind of control point selected by
241
     * the cursor's mouse.
242
     */
243
    // private ISnapper usedSnap = null;
244
    /**
245
     * Determines if has displayed at the edition console, the question for the
246
     * operations that can do the user with the current CAD tool, in its current
247
     * state.
248
     */
249
    private boolean questionAsked = false;
238 250

  
239
	/**
240
	 * Determines if the snap tools are enabled or disabled.
241
	 *
242
	 * @see #isRefentEnabled()
243
	 * @see #setRefentEnabled(boolean)
244
	 */
245
	// private boolean bRefent = true;
246
	/**
247
	 * <p>
248
	 * Determines if the position of the snap of the mouse's cursor on the
249
	 * <code>MapControl</code> is within the area around a control point of a
250
	 * geometry.
251
	 * </p>
252
	 *
253
	 * <p>
254
	 * The area is calculated as a circle centered at the control point and with
255
	 * radius the pixels tolerance defined in the preferences.
256
	 * </p>
257
	 */
258
	// private boolean bForceCoord = false;
259
	/**
260
	 * Optional grid that could be applied on the <code>MapControl</code>'s
261
	 * view port.
262
	 *
263
	 * @see #getGrid()
264
	 * @see #setAdjustGrid(boolean)
265
	 */
266
	// private CADGrid cadgrid = new CADGrid();
267
	/**
268
	 * Determines is is enabled or not the <i>Orto</i> mode.
269
	 */
270
	private boolean bOrtoMode;
251
    /**
252
     * Represents the cursor's point selected in <i>screen coordinates</i>.
253
     * 
254
     * @see ViewPort#fromMapPoint(Point2D)
255
     */
256
    private Point2D adjustedPoint;
271 257

  
272
	/**
273
	 * A light yellow color for the tool tip text box associated to the point
274
	 * indicated by the mouse's cursor.
275
	 */
276
	private Color theTipColor = new Color(255, 255, 155);
258
    /**
259
     * Determines if the snap tools are enabled or disabled.
260
     * 
261
     * @see #isRefentEnabled()
262
     * @see #setRefentEnabled(boolean)
263
     */
264
    // private boolean bRefent = true;
265
    /**
266
     * <p>
267
     * Determines if the position of the snap of the mouse's cursor on the
268
     * <code>MapControl</code> is within the area around a control point of a
269
     * geometry.
270
     * </p>
271
     * 
272
     * <p>
273
     * The area is calculated as a circle centered at the control point and with
274
     * radius the pixels tolerance defined in the preferences.
275
     * </p>
276
     */
277
    // private boolean bForceCoord = false;
278
    /**
279
     * Optional grid that could be applied on the <code>MapControl</code>'s
280
     * view port.
281
     * 
282
     * @see #getGrid()
283
     * @see #setAdjustGrid(boolean)
284
     */
285
    // private CADGrid cadgrid = new CADGrid();
286
    /**
287
     * Determines is is enabled or not the <i>Orto</i> mode.
288
     */
289
    private boolean bOrtoMode;
277 290

  
278
	/**
279
	 * Last question asked to the user in the CAD console.
280
	 */
281
	private Object lastQuestion;
291
    /**
292
     * A light yellow color for the tool tip text box associated to the point
293
     * indicated by the mouse's cursor.
294
     */
295
    private Color theTipColor = new Color(255, 255, 155);
282 296

  
283
	/**
284
	 * Maximum tolerance in the approximation of a curved line by a polyline.
285
	 *
286
	 * @see #initializeFlatness()
287
	 */
288
	private static boolean flatnessInitialized = false;
297
    /**
298
     * Last question asked to the user in the CAD console.
299
     */
300
    private Object lastQuestion;
289 301

  
290
	/**
291
	 * Listener to display the coordinates in the current application's status
292
	 * bar.
293
	 */
294
	private StatusBarListener sbl = null;
302
    /**
303
     * Maximum tolerance in the approximation of a curved line by a polyline.
304
     * 
305
     * @see #initializeFlatness()
306
     */
307
    private static boolean flatnessInitialized = false;
295 308

  
296
	/*
297
	 * (non-Javadoc)
298
	 *
299
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setMapControl(com.iver.cit.gvsig.fmap.MapControl)
300
	 */
301
	public void setMapControl(MapControl mc) {
302
		super.setMapControl(mc);
303
		sbl = new StatusBarListener(getMapControl());
304
	}
309
    /**
310
     * Listener to display the coordinates in the current application's status
311
     * bar.
312
     */
313
    private StatusBarListener sbl = null;
305 314

  
306
	private static final Image imageCursor = new BufferedImage(32, 32,
307
			BufferedImage.TYPE_INT_ARGB);
308
	static {
309
		Graphics g = imageCursor.getGraphics();
310
		int size1 = 15;
311
		int size2 = 3;
312
		int x = 16;
313
		int y = 16;
314
		g.setColor(Color.MAGENTA);
315
		g.drawLine((x - size1), (y), (x + size1), (y));
316
		g.drawLine((x), (y - size1), (x), (y + size1));
317
		// g.setColor(Color.MAGENTA);
318
		g.drawRect((x - 6), (y - 6), 12, 12);
319
		g.drawRect((x - 3), (y - 3), 6, 6);
315
    /*
316
     * (non-Javadoc)
317
     * 
318
     * @see
319
     * com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setMapControl(com.iver
320
     * .cit.gvsig.fmap.MapControl)
321
     */
322
    public void setMapControl(MapControl mc) {
323
        super.setMapControl(mc);
324
        sbl = new StatusBarListener(getMapControl());
325
    }
320 326

  
321
		// // getMapControl().setToolTipText(null);
322
		// if (adjustedPoint != null) {
323
		// if (bForceCoord) {
324
		// /* g.setColor(Color.ORANGE);
325
		// g.drawRect((int) (adjustedPoint.getX() - 6),
326
		// (int) (adjustedPoint.getY() - 6), 12, 12);
327
		// g.drawRect((int) (adjustedPoint.getX() - 3),
328
		// (int) (adjustedPoint.getY() - 3), 6, 6);
329
		// g.setColor(Color.MAGENTA);
330
		// g.drawRect((int) (adjustedPoint.getX() - 4),
331
		// (int) (adjustedPoint.getY() - 4), 8, 8); */
332
		// if (usedSnap != null)
333
		// {
334
		// usedSnap.draw(g, adjustedPoint);
335
		//
336
		// Graphics2D g2 = (Graphics2D) g;
337
		// FontMetrics metrics = g2.getFontMetrics();
338
		// int w = metrics.stringWidth(usedSnap.getToolTipText()) + 5;
339
		// int h = metrics.getMaxAscent() + 5;
340
		// int x = (int)p.getX()+9;
341
		// int y = (int)p.getY()- 7;
342
		//
343
		// g2.setColor(theTipColor );
344
		// g2.fillRect(x, y-h, w, h);
345
		// g2.setColor(Color.BLACK);
346
		// g2.drawRect(x, y-h, w, h);
347
		// g2.drawString(usedSnap.getToolTipText(), x+3, y-3);
348
		//
349
		//
350
		// // getMapControl().setToolTipText(usedSnap.getToolTipText());
351
		// }
352
		//
353
		// bForceCoord = false;
354
		// } else {
355
		// g.drawRect((int) (p.getX() - size2), (int) (p.getY() - size2),
356
		// (int) (size2 * 2), (int) (size2 * 2));
357
		// }
358
		// }
327
    private static final Image imageCursor = new BufferedImage(32, 32,
328
        BufferedImage.TYPE_INT_ARGB);
329
    static {
330
        Graphics g = imageCursor.getGraphics();
331
        int size1 = 15;
332
        int size2 = 3;
333
        int x = 16;
334
        int y = 16;
335
        g.setColor(Color.MAGENTA);
336
        g.drawLine((x - size1), (y), (x + size1), (y));
337
        g.drawLine((x), (y - size1), (x), (y + size1));
338
        // g.setColor(Color.MAGENTA);
339
        g.drawRect((x - 6), (y - 6), 12, 12);
340
        g.drawRect((x - 3), (y - 3), 6, 6);
359 341

  
360
	}
342
        // // getMapControl().setToolTipText(null);
343
        // if (adjustedPoint != null) {
344
        // if (bForceCoord) {
345
        // /* g.setColor(Color.ORANGE);
346
        // g.drawRect((int) (adjustedPoint.getX() - 6),
347
        // (int) (adjustedPoint.getY() - 6), 12, 12);
348
        // g.drawRect((int) (adjustedPoint.getX() - 3),
349
        // (int) (adjustedPoint.getY() - 3), 6, 6);
350
        // g.setColor(Color.MAGENTA);
351
        // g.drawRect((int) (adjustedPoint.getX() - 4),
352
        // (int) (adjustedPoint.getY() - 4), 8, 8); */
353
        // if (usedSnap != null)
354
        // {
355
        // usedSnap.draw(g, adjustedPoint);
356
        //
357
        // Graphics2D g2 = (Graphics2D) g;
358
        // FontMetrics metrics = g2.getFontMetrics();
359
        // int w = metrics.stringWidth(usedSnap.getToolTipText()) + 5;
360
        // int h = metrics.getMaxAscent() + 5;
361
        // int x = (int)p.getX()+9;
362
        // int y = (int)p.getY()- 7;
363
        //
364
        // g2.setColor(theTipColor );
365
        // g2.fillRect(x, y-h, w, h);
366
        // g2.setColor(Color.BLACK);
367
        // g2.drawRect(x, y-h, w, h);
368
        // g2.drawString(usedSnap.getToolTipText(), x+3, y-3);
369
        //
370
        //
371
        // // getMapControl().setToolTipText(usedSnap.getToolTipText());
372
        // }
373
        //
374
        // bForceCoord = false;
375
        // } else {
376
        // g.drawRect((int) (p.getX() - size2), (int) (p.getY() - size2),
377
        // (int) (size2 * 2), (int) (size2 * 2));
378
        // }
379
        // }
361 380

  
362
	/**
363
	 * <p>
364
	 * Draws the selected geometries to edit. And, if the <i>snapping</i> is
365
	 * enabled, draws also its effect over them.
366
	 * </p>
367
	 *
368
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
369
	 */
370
	public void paintComponent(MapControlDrawer mapControlDrawer) {
371
		super.paintComponent(mapControlDrawer);
372
		if (CADExtension.getCADToolAdapter() != this) {
373
			return;
374
		}
381
    }
375 382

  
376
		if (adjustedPoint != null) {
377
			Point2D p = null;
378
			if (mapAdjustedPoint != null) {
379
				p = mapAdjustedPoint;
380
			} else {
381
				p = getMapControl().getViewPort().toMapPoint(adjustedPoint);
382
			}
383
    /**
384
     * <p>
385
     * Draws the selected geometries to edit. And, if the <i>snapping</i> is
386
     * enabled, draws also its effect over them.
387
     * </p>
388
     * 
389
     * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
390
     */
391
    public void paintComponent(MapControlDrawer mapControlDrawer) {
392
        super.paintComponent(mapControlDrawer);
393
        if (CADExtension.getCADToolAdapter() != this) {
394
            return;
395
        }
383 396

  
384
			//If the stack is empty, return
385
			if (cadToolStack.isEmpty()){
386
			    return;
387
			}
388
			
389
			if (((CADTool) cadToolStack.peek()).getVLE() == null){
390
				return;
391
			}
392
			
393
			((CADTool) cadToolStack.peek())
394
					.drawOperation(mapControlDrawer, p.getX(), p.getY());
395
		}
396
	}
397
        if (adjustedPoint != null) {
398
            Point2D p = null;
399
            if (mapAdjustedPoint != null) {
400
                p = mapAdjustedPoint;
401
            } else {
402
                p = getMapControl().getViewPort().toMapPoint(adjustedPoint);
403
            }
397 404

  
398
	/**
399
	 * <p>
400
	 * Responds two kind of mouse click events:
401
	 * <ul>
402
	 * <li><b><i>One click of the third mouse's button</i></b>: displays a
403
	 * popup with edition options.</li>
404
	 * <li><b><i>Two clicks of the first mouse's button</i></b>: ends the
405
	 * last cad tool setting as end transition point the event's one.</li>
406
	 * </ul>
407
	 * </p>
408
	 *
409
	 *
410
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseClicked(java.awt.event.MouseEvent)
411
	 * @see CADExtension#showPopup(MouseEvent)
412
	 */
413
	public void mouseClicked(MouseEvent e) throws BehaviorException {
414
		if (e.getButton() == MouseEvent.BUTTON3) {
415
			CADExtension.showPopup(e);
416
		} else if (e.getButton() == MouseEvent.BUTTON1
417
				&& e.getClickCount() == 2) {
418
			questionAsked = true;
419
			if (!cadToolStack.isEmpty()) {
420
				CADTool ct = (CADTool) cadToolStack.peek();
421
				ViewPort vp = getMapControl().getMapContext().getViewPort();
422
				Point2D p;
405
            // If the stack is empty, return
406
            if (cadToolStack.isEmpty()) {
407
                return;
408
            }
423 409

  
424
				if (mapAdjustedPoint != null) {
425
					p = mapAdjustedPoint;
426
				} else {
427
					p = vp.toMapPoint(adjustedPoint);
428
				}
429
				ct.endTransition(p.getX(), p.getY(), e);
430
				previousPoint = new double[] { p.getX(), p.getY() };
431
			}
432
		}
433
	}
410
            if (((CADTool) cadToolStack.peek()).getVLE() == null) {
411
                return;
412
            }
434 413

  
435
	/*
436
	 * (non-Javadoc)
437
	 *
438
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseEntered(java.awt.event.MouseEvent)
439
	 */
440
	public void mouseEntered(MouseEvent e) throws BehaviorException {
441
		clearMouseImage();
442
	}
414
            ((CADTool) cadToolStack.peek()).drawOperation(mapControlDrawer,
415
                p.getX(), p.getY());
416
        }
417
    }
443 418

  
444
	/*
445
	 * (non-Javadoc)
446
	 *
447
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseExited(java.awt.event.MouseEvent)
448
	 */
449
	public void mouseExited(MouseEvent e) throws BehaviorException {
450
	}
419
    /**
420
     * <p>
421
     * Responds two kind of mouse click events:
422
     * <ul>
423
     * <li><b><i>One click of the third mouse's button</i></b>: displays a popup
424
     * with edition options.</li>
425
     * <li><b><i>Two clicks of the first mouse's button</i></b>: ends the last
426
     * cad tool setting as end transition point the event's one.</li>
427
     * </ul>
428
     * </p>
429
     * 
430
     * 
431
     * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseClicked(java.awt.event.MouseEvent)
432
     * @see CADExtension#showPopup(MouseEvent)
433
     */
434
    public void mouseClicked(MouseEvent e) throws BehaviorException {
435
        if (e.getButton() == MouseEvent.BUTTON3) {
436
            CADExtension.showPopup(e);
437
        } else
438
            if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
439
                questionAsked = true;
440
                if (!cadToolStack.isEmpty()) {
441
                    CADTool ct = (CADTool) cadToolStack.peek();
442
                    ViewPort vp = getMapControl().getMapContext().getViewPort();
443
                    Point2D p;
451 444

  
452
	/**
453
	 * Selects the vertex of a geometry at the point selected on the
454
	 * <code>MapControl</code> by pressing the first mouse's button.
455
	 *
456
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mousePressed(java.awt.event.MouseEvent)
457
	 */
458
	public void mousePressed(MouseEvent e) throws BehaviorException {
459
		if (e.getButton() == MouseEvent.BUTTON1) {
460
			ViewPort vp = getMapControl().getMapContext().getViewPort();
461
			Point2D p;
462
			mapAdjustedPoint = getMapControl().getMapAdjustedPoint();
463
			if (mapAdjustedPoint != null) {
464
				p = mapAdjustedPoint;
465
			} else {
466
				p = vp.toMapPoint(adjustedPoint);
467
			}
468
			transition(new double[] { p.getX(), p.getY() }, e, ABSOLUTE);
469
		}
470
	}
445
                    if (mapAdjustedPoint != null) {
446
                        p = mapAdjustedPoint;
447
                    } else {
448
                        p = vp.toMapPoint(adjustedPoint);
449
                    }
450
                    ct.endTransition(p.getX(), p.getY(), e);
451
                    previousPoint = new double[] { p.getX(), p.getY() };
452
                }
453
            }
454
    }
471 455

  
472
	// /**
473
	// * <p>Adjusts the <code>point</code> to the grid if its enabled, and
474
	// * sets <code>mapHandlerAdjustedPoint</code> with that new value.</p>
475
	// *
476
	// * <p>The value returned is the distance between those points: the
477
	// original and
478
	// * the adjusted one.</p>
479
	// *
480
	// * @param point point to adjust
481
	// * @param mapHandlerAdjustedPoint <code>point</code> adjusted
482
	// *
483
	// * @return distance from <code>point</code> to the adjusted one. If there
484
	// is no
485
	// * adjustment, returns <code>Double.MAX_VALUE</code>.
486
	// */
487
	// private double adjustToHandler(Point2D point,
488
	// Point2D mapHandlerAdjustedPoint) {
489
	//
490
	// if (!isRefentEnabled())
491
	// return Double.MAX_VALUE;
492
	//
493
	// ILayerEdited aux =
494
	// CADExtension.getEditionManager().getActiveLayerEdited();
495
	// if (!(aux instanceof VectorialLayerEdited))
496
	// return Double.MAX_VALUE;
497
	// VectorialLayerEdited vle = (VectorialLayerEdited) aux;
498
	//
499
	// ArrayList snappers = vle.getSnappers();
500
	// ArrayList layersToSnap = vle.getLayersToSnap();
501
	//
502
	//
503
	// ViewPort vp = getMapControl().getViewPort();
504
	//
505
	// snappers=SnapConfigPage.getActivesSnappers();
506
	//
507
	// double mapTolerance = vp.toMapDistance(SelectionCADTool.tolerance);
508
	// double minDist = mapTolerance;
509
	// // double rw = getMapControl().getViewPort().toMapDistance(5);
510
	// Point2D mapPoint = point;
511
	// double middleTol=mapTolerance * 0.5;
512
	// org.gvsig.fmap.geom.primitive.Envelope r = new
513
	// DefaultEnvelope(mapPoint.getX() - middleTol,
514
	// mapPoint.getY() - middleTol,
515
	// mapPoint.getX() + middleTol,
516
	// mapPoint.getY() + middleTol);
517
	//
518
	// Envelope e = Converter.convertEnvelopeToJTS(r);
519
	//
520
	// usedSnap = null;
521
	// Point2D lastPoint = null;
522
	// if (previousPoint != null)
523
	// {
524
	// lastPoint = new Point2D.Double(previousPoint[0], previousPoint[1]);
525
	// }
526
	// for (int j = 0; j < layersToSnap.size(); j++)
527
	// {
528
	// FLyrVect lyrVect = (FLyrVect) layersToSnap.get(j);
529
	// SpatialCache cache = lyrVect.getSpatialCache();
530
	// if (lyrVect.isVisible())
531
	// {
532
	// // La lista de snappers est� siempre ordenada por prioridad. Los de mayor
533
	// // prioridad est�n primero.
534
	// for (int i = 0; i < snappers.size(); i++)
535
	// {
536
	// ISnapper theSnapper = (ISnapper) snappers.get(i);
537
	//
538
	// if (usedSnap != null)
539
	// {
540
	// // Si ya tenemos un snap y es de alta prioridad, cogemos ese. (A no ser
541
	// que en otra capa encontremos un snapper mejor)
542
	// if (theSnapper.getPriority() < usedSnap.getPriority())
543
	// break;
544
	// }
545
	// SnappingVisitor snapVisitor = null;
546
	// Point2D theSnappedPoint = null;
547
	//
548
	// if (theSnapper instanceof ISnapperVectorial)
549
	// {
550
	// if (theSnapper instanceof ISnapperGeometriesVectorial) {
551
	// snapVisitor=new GeometriesSnappingVisitor((ISnapperGeometriesVectorial)
552
	// theSnapper,point,mapTolerance,lastPoint);
553
	// }else {
554
	// snapVisitor = new SnappingVisitor((ISnapperVectorial) theSnapper, point,
555
	// mapTolerance, lastPoint);
556
	// }
557
	// // System.out.println("Cache size = " + cache.size());
558
	// cache.query(e, snapVisitor);
559
	// theSnappedPoint = snapVisitor.getSnapPoint();
560
	//
561
	// }
562
	// if (theSnapper instanceof ISnapperRaster)
563
	// {
564
	// ISnapperRaster snapRaster = (ISnapperRaster) theSnapper;
565
	// theSnappedPoint = snapRaster.getSnapPoint(getMapControl(), point,
566
	// mapTolerance, lastPoint);
567
	// }
568
	//
569
	//
570
	// if (theSnappedPoint != null) {
571
	// double distAux = theSnappedPoint.distance(point);
572
	// if (minDist > distAux)
573
	// {
574
	// minDist = distAux;
575
	// usedSnap = theSnapper;
576
	// mapHandlerAdjustedPoint.setLocation(theSnappedPoint);
577
	// }
578
	// }
579
	// }
580
	// } // visible
581
	// }
582
	// if (usedSnap != null)
583
	// return minDist;
584
	// return Double.MAX_VALUE;
585
	//
586
	// }
456
    /*
457
     * (non-Javadoc)
458
     * 
459
     * @see
460
     * com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseEntered(java.awt
461
     * .event.MouseEvent)
462
     */
463
    public void mouseEntered(MouseEvent e) throws BehaviorException {
464
        clearMouseImage();
465
    }
587 466

  
588
	/*
589
	 * (non-Javadoc)
590
	 *
591
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseReleased(java.awt.event.MouseEvent)
592
	 */
593
	public void mouseReleased(MouseEvent e) throws BehaviorException {
594
		getMapControl().repaint();
595
	}
467
    /*
468
     * (non-Javadoc)
469
     * 
470
     * @see
471
     * com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseExited(java.awt.
472
     * event.MouseEvent)
473
     */
474
    public void mouseExited(MouseEvent e) throws BehaviorException {
475
    }
596 476

  
597
	/*
598
	 * (non-Javadoc)
599
	 *
600
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseDragged(java.awt.event.MouseEvent)
601
	 */
602
	public void mouseDragged(MouseEvent e) throws BehaviorException {
603
		lastX = e.getX();
604
		lastY = e.getY();
605
		adjustedPoint = e.getPoint();
606
		// calculateSnapPoint(e.getPoint());
607
	}
477
    /**
478
     * Selects the vertex of a geometry at the point selected on the
479
     * <code>MapControl</code> by pressing the first mouse's button.
480
     * 
481
     * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mousePressed(java.awt.event.MouseEvent)
482
     */
483
    public void mousePressed(MouseEvent e) throws BehaviorException {
484
        if (e.getButton() == MouseEvent.BUTTON1) {
485
            ViewPort vp = getMapControl().getMapContext().getViewPort();
486
            Point2D p;
487
            mapAdjustedPoint = getMapControl().getMapAdjustedPoint();
488
            if (mapAdjustedPoint != null) {
489
                p = mapAdjustedPoint;
490
            } else {
491
                p = vp.toMapPoint(adjustedPoint);
492
            }
493
            transition(new double[] { p.getX(), p.getY() }, e, ABSOLUTE);
494
        }
495
    }
608 496

  
609
	/*
610
	 * (non-Javadoc)
611
	 *
612
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseMoved(java.awt.event.MouseEvent)
613
	 */
614
	public void mouseMoved(MouseEvent e) throws BehaviorException {
497
    // /**
498
    // * <p>Adjusts the <code>point</code> to the grid if its enabled, and
499
    // * sets <code>mapHandlerAdjustedPoint</code> with that new value.</p>
500
    // *
501
    // * <p>The value returned is the distance between those points: the
502
    // original and
503
    // * the adjusted one.</p>
504
    // *
505
    // * @param point point to adjust
506
    // * @param mapHandlerAdjustedPoint <code>point</code> adjusted
507
    // *
508
    // * @return distance from <code>point</code> to the adjusted one. If there
509
    // is no
510
    // * adjustment, returns <code>Double.MAX_VALUE</code>.
511
    // */
512
    // private double adjustToHandler(Point2D point,
513
    // Point2D mapHandlerAdjustedPoint) {
514
    //
515
    // if (!isRefentEnabled())
516
    // return Double.MAX_VALUE;
517
    //
518
    // ILayerEdited aux =
519
    // CADExtension.getEditionManager().getActiveLayerEdited();
520
    // if (!(aux instanceof VectorialLayerEdited))
521
    // return Double.MAX_VALUE;
522
    // VectorialLayerEdited vle = (VectorialLayerEdited) aux;
523
    //
524
    // ArrayList snappers = vle.getSnappers();
525
    // ArrayList layersToSnap = vle.getLayersToSnap();
526
    //
527
    //
528
    // ViewPort vp = getMapControl().getViewPort();
529
    //
530
    // snappers=SnapConfigPage.getActivesSnappers();
531
    //
532
    // double mapTolerance = vp.toMapDistance(SelectionCADTool.tolerance);
533
    // double minDist = mapTolerance;
534
    // // double rw = getMapControl().getViewPort().toMapDistance(5);
535
    // Point2D mapPoint = point;
536
    // double middleTol=mapTolerance * 0.5;
537
    // org.gvsig.fmap.geom.primitive.Envelope r = new
538
    // DefaultEnvelope(mapPoint.getX() - middleTol,
539
    // mapPoint.getY() - middleTol,
540
    // mapPoint.getX() + middleTol,
541
    // mapPoint.getY() + middleTol);
542
    //
543
    // Envelope e = Converter.convertEnvelopeToJTS(r);
544
    //
545
    // usedSnap = null;
546
    // Point2D lastPoint = null;
547
    // if (previousPoint != null)
548
    // {
549
    // lastPoint = new Point2D.Double(previousPoint[0], previousPoint[1]);
550
    // }
551
    // for (int j = 0; j < layersToSnap.size(); j++)
552
    // {
553
    // FLyrVect lyrVect = (FLyrVect) layersToSnap.get(j);
554
    // SpatialCache cache = lyrVect.getSpatialCache();
555
    // if (lyrVect.isVisible())
556
    // {
557
    // // La lista de snappers est� siempre ordenada por prioridad. Los de
558
    // mayor
559
    // // prioridad est�n primero.
560
    // for (int i = 0; i < snappers.size(); i++)
561
    // {
562
    // ISnapper theSnapper = (ISnapper) snappers.get(i);
563
    //
564
    // if (usedSnap != null)
565
    // {
566
    // // Si ya tenemos un snap y es de alta prioridad, cogemos ese. (A no ser
567
    // que en otra capa encontremos un snapper mejor)
568
    // if (theSnapper.getPriority() < usedSnap.getPriority())
569
    // break;
570
    // }
571
    // SnappingVisitor snapVisitor = null;
572
    // Point2D theSnappedPoint = null;
573
    //
574
    // if (theSnapper instanceof ISnapperVectorial)
575
    // {
576
    // if (theSnapper instanceof ISnapperGeometriesVectorial) {
577
    // snapVisitor=new GeometriesSnappingVisitor((ISnapperGeometriesVectorial)
578
    // theSnapper,point,mapTolerance,lastPoint);
579
    // }else {
580
    // snapVisitor = new SnappingVisitor((ISnapperVectorial) theSnapper, point,
581
    // mapTolerance, lastPoint);
582
    // }
583
    // // System.out.println("Cache size = " + cache.size());
584
    // cache.query(e, snapVisitor);
585
    // theSnappedPoint = snapVisitor.getSnapPoint();
586
    //
587
    // }
588
    // if (theSnapper instanceof ISnapperRaster)
589
    // {
590
    // ISnapperRaster snapRaster = (ISnapperRaster) theSnapper;
591
    // theSnappedPoint = snapRaster.getSnapPoint(getMapControl(), point,
592
    // mapTolerance, lastPoint);
593
    // }
594
    //
595
    //
596
    // if (theSnappedPoint != null) {
597
    // double distAux = theSnappedPoint.distance(point);
598
    // if (minDist > distAux)
599
    // {
600
    // minDist = distAux;
601
    // usedSnap = theSnapper;
602
    // mapHandlerAdjustedPoint.setLocation(theSnappedPoint);
603
    // }
604
    // }
605
    // }
606
    // } // visible
607
    // }
608
    // if (usedSnap != null)
609
    // return minDist;
610
    // return Double.MAX_VALUE;
611
    //
612
    // }
615 613

  
616
		lastX = e.getX();
617
		lastY = e.getY();
618
		adjustedPoint = e.getPoint();
619
//		 calculateSnapPoint(e.getPoint());
614
    /*
615
     * (non-Javadoc)
616
     * 
617
     * @see
618
     * com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseReleased(java.awt
619
     * .event.MouseEvent)
620
     */
621
    public void mouseReleased(MouseEvent e) throws BehaviorException {
622
        getMapControl().repaint();
623
    }
620 624

  
621
		showCoords(e.getPoint());
625
    /*
626
     * (non-Javadoc)
627
     * 
628
     * @see
629
     * com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseDragged(java.awt
630
     * .event.MouseEvent)
631
     */
632
    public void mouseDragged(MouseEvent e) throws BehaviorException {
633
        lastX = e.getX();
634
        lastY = e.getY();
635
        adjustedPoint = e.getPoint();
636
        // calculateSnapPoint(e.getPoint());
637
    }
622 638

  
623
		getMapControl().repaint();
624
	}
639
    /*
640
     * (non-Javadoc)
641
     * 
642
     * @see
643
     * com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseMoved(java.awt.event
644
     * .MouseEvent)
645
     */
646
    public void mouseMoved(MouseEvent e) throws BehaviorException {
625 647

  
626
	/**
627
	 * Displays the current coordinates of the mouse's cursor on the associated
628
	 * <code>MapControl</code> object, at the status bar of the application's
629
	 * main frame.
630
	 *
631
	 * @param pPix
632
	 *            current 2D mouse's cursor coordinates on the
633
	 *            <code>MapControl</code>
634
	 */
635
	private void showCoords(Point2D pPix) {
636
		String[] axisText = new String[2];
637
		axisText[0] = "X = ";
638
		axisText[1] = "Y = ";
639
		// NumberFormat nf = NumberFormat.getInstance();
640
		MapControl mapControl = getMapControl();
641
		ViewPort vp = mapControl.getMapContext().getViewPort();
642
		IProjection iProj = vp.getProjection();
648
        lastX = e.getX();
649
        lastY = e.getY();
650
        adjustedPoint = e.getPoint();
651
        // calculateSnapPoint(e.getPoint());
643 652

  
644
		// if (iProj.getAbrev().equals("EPSG:4326") ||
645
		// iProj.getAbrev().equals("EPSG:4230")) {
646
		// axisText[0] = "Lon = ";
647
		// axisText[1] = "Lat = ";
648
		// nf.setMaximumFractionDigits(8);
649
		// } else {
650
		// axisText[0] = "X = ";
651
		// axisText[1] = "Y = ";
652
		// nf.setMaximumFractionDigits(2);
653
		// }
654
		Point2D p;
655
		if (mapAdjustedPoint == null) {
656
			p = vp.toMapPoint(pPix);
657
		} else {
658
			p = mapAdjustedPoint;
659
		}
660
		sbl.setFractionDigits(p);
661
		axisText = sbl.setCoorDisplayText(axisText);
662
		MainFrame mF = PluginServices.getMainFrame();
653
        showCoords(e.getPoint());
663 654

  
664
		if (mF != null) {
665
			mF.getStatusBar().setMessage(
666
					"units",
667
					PluginServices
668
							.getText(this, MapContext.getDistanceNames()[vp
669
									.getDistanceUnits()]));
670
			mF.getStatusBar().setControlValue("scale",
671
					String.valueOf(mapControl.getMapContext().getScaleView()));
672
			mF.getStatusBar().setMessage("projection", iProj.getAbrev());
655
        getMapControl().repaint();
656
    }
673 657

  
674
			String[] coords = sbl.getCoords(p);
675
			mF.getStatusBar().setMessage("x", axisText[0] + coords[0]);
676
			mF.getStatusBar().setMessage("y", axisText[1] + coords[1]);
677
		}
678
	}
658
    /**
659
     * Displays the current coordinates of the mouse's cursor on the associated
660
     * <code>MapControl</code> object, at the status bar of the application's
661
     * main frame.
662
     * 
663
     * @param pPix
664
     *            current 2D mouse's cursor coordinates on the
665
     *            <code>MapControl</code>
666
     */
667
    private void showCoords(Point2D pPix) {
668
        String[] axisText = new String[2];
669
        axisText[0] = "X = ";
670
        axisText[1] = "Y = ";
671
        // NumberFormat nf = NumberFormat.getInstance();
672
        MapControl mapControl = getMapControl();
673
        ViewPort vp = mapControl.getMapContext().getViewPort();
674
        IProjection iProj = vp.getProjection();
679 675

  
680
	/**
681
	 * Hides the mouse's cursor.
682
	 */
683
	private void clearMouseImage() {
684
		int[] pixels = new int[16 * 16];
685
		Image image = Toolkit.getDefaultToolkit().createImage(
686
				new MemoryImageSource(16, 16, pixels, 0, 16));
687
		Cursor transparentCursor = Toolkit.getDefaultToolkit()
688
				.createCustomCursor(image, new Point(0, 0), "invisiblecursor");
676
        // if (iProj.getAbrev().equals("EPSG:4326") ||
677
        // iProj.getAbrev().equals("EPSG:4230")) {
678
        // axisText[0] = "Lon = ";
679
        // axisText[1] = "Lat = ";
680
        // nf.setMaximumFractionDigits(8);
681
        // } else {
682
        // axisText[0] = "X = ";
683
        // axisText[1] = "Y = ";
684
        // nf.setMaximumFractionDigits(2);
685
        // }
686
        Point2D p;
687
        if (mapAdjustedPoint == null) {
688
            p = vp.toMapPoint(pPix);
689
        } else {
690
            p = mapAdjustedPoint;
691
        }
692
        sbl.setFractionDigits(p);
693
        axisText = sbl.setCoorDisplayText(axisText);
694
        MainFrame mF = PluginServices.getMainFrame();
689 695

  
690
		getMapControl().setCursor(transparentCursor);
691
	}
696
        if (mF != null) {
697
            mF.getStatusBar().setMessage(
698
                "units",
699
                PluginServices.getText(this,
700
                    MapContext.getDistanceNames()[vp.getDistanceUnits()]));
701
            mF.getStatusBar().setControlValue("scale",
702
                String.valueOf(mapControl.getMapContext().getScaleView()));
703
            mF.getStatusBar().setMessage("projection", iProj.getAbrev());
692 704

  
693
	/**
694
	 * <p>
695
	 * Draws a 31x31 pixels cross round the mouse's cursor with an small
696
	 * geometry centered:
697
	 * <ul>
698
	 * <li><i>an square centered</i>: if isn't over a <i>control point</i>.
699
	 * <li><i>an small geometry centered according to the kind of control point</i>:
700
	 * if it's over a control point. In this case, the small geometry is drawn
701
	 * by a {@link ISnapper ISnapper} type object.<br>
702
	 * On the other hand, a light-yellowed background tool tip text with the
703
	 * type of <i>control point</i> will be displayed.</li>
704
	 * </p>
705
	 *
706
	 * @param g
707
	 *            <code>MapControl</code>'s graphics where the data will be
708
	 *            drawn
709
	 */
710
	// private void drawCursor(Graphics g) {
711
	// g.setColor(Color.black);
712
	// Point2D p = adjustedPoint;
713
	//
714
	// if (p == null) {
715
	// getGrid().setViewPort(getMapControl().getViewPort());
716
	//
717
	// return;
718
	// }
719
	//
720
	// int size1 = 15;
721
	// int size2 = 3;
722
	// g.drawLine((int) (p.getX() - size1), (int) (p.getY()),
723
	// (int) (p.getX() + size1), (int) (p.getY()));
724
	// g.drawLine((int) (p.getX()), (int) (p.getY() - size1),
725
	// (int) (p.getX()), (int) (p.getY() + size1));
726
	//
727
	// // getMapControl().setToolTipText(null);
728
	// if (adjustedPoint != null) {
729
	// if (bForceCoord) {
730
	// /* g.setColor(Color.ORANGE);
731
	// g.drawRect((int) (adjustedPoint.getX() - 6),
732
	// (int) (adjustedPoint.getY() - 6), 12, 12);
733
	// g.drawRect((int) (adjustedPoint.getX() - 3),
734
	// (int) (adjustedPoint.getY() - 3), 6, 6);
735
	// g.setColor(Color.MAGENTA);
736
	// g.drawRect((int) (adjustedPoint.getX() - 4),
737
	// (int) (adjustedPoint.getY() - 4), 8, 8); */
738
	// if (usedSnap != null)
739
	// {
740
	// usedSnap.draw(g, adjustedPoint);
741
	//
742
	// Graphics2D g2 = (Graphics2D) g;
743
	// FontMetrics metrics = g2.getFontMetrics();
744
	// int w = metrics.stringWidth(usedSnap.getToolTipText()) + 5;
745
	// int h = metrics.getMaxAscent() + 5;
746
	// int x = (int)p.getX()+9;
747
	// int y = (int)p.getY()- 7;
748
	//
749
	// g2.setColor(theTipColor );
750
	// g2.fillRect(x, y-h, w, h);
751
	// g2.setColor(Color.BLACK);
752
	// g2.drawRect(x, y-h, w, h);
753
	// g2.drawString(usedSnap.getToolTipText(), x+3, y-3);
754
	//
755
	//
756
	// // getMapControl().setToolTipText(usedSnap.getToolTipText());
757
	// }
758
	//
759
	// bForceCoord = false;
760
	// } else {
761
	// g.drawRect((int) (p.getX() - size2), (int) (p.getY() - size2),
762
	// (int) (size2 * 2), (int) (size2 * 2));
763
	// }
764
	// }
765
	// }
766
	/**
767
	 * <p>
768
	 * Tries to find the nearest geometry or grid control point by the position
769
	 * of the current snap tool.
770
	 * </p>
771
	 *
772
	 * <p>
773
	 * Prioritizes the grid control points than the geometries ones.
774
	 * </p>
775
	 *
776
	 * <p>
777
	 * If finds any near, stores the <i>map</i> and <i>pixel</i> coordinates
778
	 * for the snap, and enables the <code>bForceCoord</code> attribute for
779
	 * the next draw of the mouse's cursor.
780
	 * </p>
781
	 *
782
	 * @param point
783
	 *            current mouse 2D position
784
	 */
785
	// private void calculateSnapPoint(Point point) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff