Revision 20098 trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/CADToolAdapter.java

View differences:

CADToolAdapter.java
59 59
import com.iver.utiles.console.JConsole;
60 60
import com.vividsolutions.jts.geom.Envelope;
61 61

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

  
121
	/**
122
	 * Reference to the object used to manage the edition of the layers of the associated <code>MapControl</code>.
123
	 * 
124
	 * @see EditionManager
125
	 * @see #getEditionManager()
126
	 */
65 127
	private EditionManager editionManager = new EditionManager();
66 128

  
129
	/**
130
	 * Identifies that the data are absolute coordinates of the new point from the (0, 0) position.
131
	 */
67 132
	public static final int ABSOLUTE = 0;
68 133

  
134
	/**
135
	 * Equivalent to {@link CADToolAdapter#ABSOLUTE CADToolAdapter#ABSOLUTE}.
136
	 */
69 137
	public static final int RELATIVE_SCP = 1;
70 138

  
139
	/**
140
	 * Identifies that the data are relative distances of the new point from the previous introduced.
141
	 */
71 142
	public static final int RELATIVE_SCU = 2;
72 143

  
144
	/**
145
	 * Identifies that the data are relative polar distances (longitude of the line and angle given in degrees)
146
	 *  of the new point from the previous introduced.
147
	 */
73 148
	public static final int POLAR_SCP = 3;
74 149

  
150
	/**
151
	 * Identifies that the data are relative polar distances (longitude of the line and angle given in radians)
152
	 *  of the new point from the previous introduced.
153
	 */
75 154
	public static final int POLAR_SCU = 4;
76 155

  
156
	/**
157
	 * Stores the 2D map coordinates of the last point added.
158
	 */
77 159
	private double[] previousPoint = null;
78 160

  
161
	/**
162
	 * <i>Stack with CAD tools.</i>
163
	 * 
164
	 * <i>For each CAD tool we use, the last item added in this stack will
165
	 *  display a different icon according to the current operation and its status.</i> 
166
	 */
79 167
	private Stack cadToolStack = new Stack();
80 168

  
81
	// Para pasarle las coordenadas cuando se produce un evento textEntered
169
	/**
170
	 * X coordinate of the last dragging or moving mouse event.
171
	 */
82 172
	private int lastX;
83 173

  
174
	/**
175
	 * Y coordinate of the last dragging or moving mouse event.
176
	 */
84 177
	private int lastY;
85 178

  
179
	/**
180
	 * Unused attribute.
181
	 */
86 182
	private ISymbol symbol = SymbologyFactory.createDefaultSymbolByShapeType(FConstant.SYMBOL_TYPE_POINT, Color.RED);
87 183

  
184
	/**
185
	 * Represents the cursor's point selected in <i>map coordinates</i>.
186
	 * 
187
	 * @see MapControl#toMapPoint
188
	 */
88 189
	private Point2D mapAdjustedPoint;
89 190

  
191
	/**
192
	 * Kind of geometry drawn to identify the kind of control point selected by the cursor's mouse.
193
	 */
90 194
	private ISnapper usedSnap = null;
91 195

  
196
	/**
197
	 * Determines if has displayed at the edition console, the question for the operations that can do
198
	 *  the user with the current CAD tool, in its current state.
199
	 */
92 200
	private boolean questionAsked = false;
93 201

  
202
	/**
203
	 * Represents the cursor's point selected in <i>screen coordinates</i>.
204
	 *
205
	 * @see ViewPort#fromMapPoint(Point2D)
206
	 */
94 207
	private Point2D adjustedPoint;
95 208

  
209
	/**
210
	 * Determines if the snap tools are enabled or disabled.
211
	 * 
212
	 * @see #isRefentEnabled()
213
	 * @see #setRefentEnabled(boolean)
214
	 */
96 215
	private boolean bRefent = true;
97 216

  
217
	/**
218
	 * <p>Determines if the position of the snap of the mouse's cursor on the <code>MapControl</code>
219
	 * is within the area around a control point of a geometry.</p>
220
	 * 
221
	 * <p>The area is calculated as a circle centered at the control point and with radius the pixels tolerance
222
	 *  defined in the preferences.</p>
223
	 */
98 224
	private boolean bForceCoord = false;
99 225

  
226
	/**
227
	 * Optional grid that could be applied on the <code>MapControl</code>'s view port.
228
	 * 
229
	 * @see #getGrid()
230
	 * @see #setAdjustGrid(boolean)
231
	 */
100 232
	private CADGrid cadgrid = new CADGrid();
101 233

  
234
	/**
235
	 * Determines is is enabled or not the <i>Orto</i> mode.
236
	 */
102 237
	private boolean bOrtoMode;
103 238

  
239
	/**
240
	 * A light yellow color for the tool tip text box associated to the point indicated by the mouse's cursor.
241
	 */
104 242
	private Color theTipColor = new Color(255, 255, 155);
105 243

  
244
	/**
245
	 * Last question asked to the user in the CAD console.
246
	 */
106 247
	private Object lastQuestion;
107 248

  
249
	/**
250
	 * Maximum tolerance in the approximation of a curved line by a polyline.
251
	 * 
252
	 * @see #initializeFlatness()
253
	 */
108 254
	private static boolean flatnessInitialized=false;
255

  
256
	/**
257
	 * Edition preferences.
258
	 */
109 259
	private static Preferences prefs = Preferences.userRoot().node( "cadtooladapter" );
260
	
261
	/**
262
	 * Listener to display the coordinates in the current application's status bar.
263
	 */
110 264
	private StatusBarListener sbl=null;
111
	/* (non-Javadoc)
112
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.IBehavior#setMapControl(com.iver.cit.gvsig.fmap.MapControl)
265

  
266
	/*
267
	 * (non-Javadoc)
268
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setMapControl(com.iver.cit.gvsig.fmap.MapControl)
113 269
	 */
114 270
	public void setMapControl(MapControl mc) {
115 271
		super.setMapControl(mc);
116 272
		sbl=new StatusBarListener(getMapControl());
117 273
	}
274

  
118 275
	/**
119
	 * Pinta de alguna manera especial las geometrias seleccionadas para la
120
	 * edici?n. En caso de que el snapping est? activado, pintar? el efecto del
121
	 * mismo.
276
	 * <p>Draws the selected geometries to edit. And, if the <i>snapping</i> is enabled,
277
	 *  draws also its effect over them.</p>
122 278
	 *
123 279
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
124 280
	 */
......
143 299
	}
144 300

  
145 301
	/**
146
	 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
302
	 * <p>Responds two kind of mouse click events:
303
	 *  <ul>
304
	 *   <li><b><i>One click of the third mouse's button</i></b>: displays a popup with edition options.</li>
305
	 *   <li><b><i>Two clicks of the first mouse's button</i></b>: ends the last cad tool setting as end transition
306
	 *    point the event's one.</li>
307
	 *  </ul>
308
	 * </p>
309
	 * 
310
	 * 
311
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseClicked(java.awt.event.MouseEvent)
312
	 * @see CADExtension#showPopup(MouseEvent)
147 313
	 */
148 314
	public void mouseClicked(MouseEvent e) throws BehaviorException {
149 315
		if (e.getButton() == MouseEvent.BUTTON3) {
......
166 332
		}
167 333
	}
168 334

  
169
	/**
170
	 * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
335
	/*
336
	 * (non-Javadoc)
337
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseEntered(java.awt.event.MouseEvent)
171 338
	 */
172 339
	public void mouseEntered(MouseEvent e) throws BehaviorException {
173 340
		clearMouseImage();
174 341
	}
175 342

  
176
	/**
177
	 * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
343
	/*
344
	 * (non-Javadoc)
345
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseExited(java.awt.event.MouseEvent)
178 346
	 */
179 347
	public void mouseExited(MouseEvent e) throws BehaviorException {
180 348
	}
181 349

  
182 350
	/**
183
	 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
351
	 * Selects the vertex of a geometry at the point selected on the <code>MapControl</code> 
352
	 * by pressing the first mouse's button.
353
	 * 
354
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mousePressed(java.awt.event.MouseEvent)
184 355
	 */
185 356
	public void mousePressed(MouseEvent e) throws BehaviorException {
186 357
		if (e.getButton() == MouseEvent.BUTTON1) {
......
197 368
	}
198 369

  
199 370
	/**
200
	 * Ajusta un punto de la imagen que se pasa como par?metro al grid si ?ste
201
	 * est? activo y devuelve la distancia de un punto al punto ajustado
371
	 * <p>Adjusts the <code>point</code> to the grid if its enabled, and 
372
	 *  sets <code>mapHandlerAdjustedPoint</code> with that new value.</p>
373
	 * 
374
	 * <p>The value returned is the distance between those points: the original and
375
	 *  the adjusted one.</p>
202 376
	 *
203
	 * @param point
204
	 * @param mapHandlerAdjustedPoint
205
	 *            DOCUMENT ME!
377
	 * @param point point to adjust
378
	 * @param mapHandlerAdjustedPoint <code>point</code> adjusted
206 379
	 *
207
	 * @return Distancia del punto que se pasa como
208
	 *  par?metro al punto ajustado. Si no hay ajuste,
209
	 *  devuelve Double.MAX_VALUE
380
	 * @return distance from <code>point</code> to the adjusted one. If there is no
381
	 *  adjustment, returns <code>Double.MAX_VALUE</code>.
210 382
	 */
211 383
	private double adjustToHandler(Point2D point,
212 384
			Point2D mapHandlerAdjustedPoint) {
......
300 472

  
301 473
	}
302 474

  
303
	/**
304
	 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
475
	/*
476
	 * (non-Javadoc)
477
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseReleased(java.awt.event.MouseEvent)
305 478
	 */
306 479
	public void mouseReleased(MouseEvent e) throws BehaviorException {
307 480
		getMapControl().repaint();
308 481
	}
309 482

  
310
	/**
311
	 * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
483
	/*
484
	 * (non-Javadoc)
485
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseDragged(java.awt.event.MouseEvent)
312 486
	 */
313 487
	public void mouseDragged(MouseEvent e) throws BehaviorException {
314 488
		lastX = e.getX();
......
317 491
		calculateSnapPoint(e.getPoint());
318 492
	}
319 493

  
320
	/**
321
	 * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
494
	/*
495
	 * (non-Javadoc)
496
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseMoved(java.awt.event.MouseEvent)
322 497
	 */
323 498
	public void mouseMoved(MouseEvent e) throws BehaviorException {
324 499

  
......
332 507
		getMapControl().repaint();
333 508
	}
334 509

  
510
	/**
511
	 * Displays the current coordinates of the mouse's cursor on the associated <code>MapControl</code>
512
	 *  object, at the status bar of the application's main frame.
513
	 * 
514
	 * @param pPix current 2D mouse's cursor coordinates on the <code>MapControl</code>
515
	 */
335 516
	private void showCoords(Point2D pPix)
336 517
	{
337 518
		String[] axisText = new String[2];
......
379 560
		}
380 561
	}
381 562

  
563
	/**
564
	 * Hides the mouse's cursor.
565
	 */
382 566
	private void clearMouseImage() {
383 567
		int[] pixels = new int[16 * 16];
384 568
		Image image = Toolkit.getDefaultToolkit().createImage(
......
390 574
	}
391 575

  
392 576
	/**
393
	 * DOCUMENT ME!
577
	 * <p>Draws a 31x31 pixels cross round the mouse's cursor with an small geometry centered:
578
	 *  <ul>
579
	 *   <li><i>an square centered</i>: if isn't over a <i>control point</i>.
580
	 *   <li><i>an small geometry centered according to the kind of control point</i>: if it's over a control
581
	 *    point. In this case, the small geometry is drawn by a {@link ISnapper ISnapper} type object.<br>
582
	 *    On the other hand, a light-yellowed background tool tip text with the type of <i>control point</i> will
583
	 *     be displayed.</li>
584
	 * </p> 
394 585
	 *
395
	 * @param g
396
	 *            DOCUMENT ME!
586
	 * @param g <code>MapControl</code>'s graphics where the data will be drawn
397 587
	 */
398 588
	private void drawCursor(Graphics g) {
399 589
		g.setColor(Color.black);
......
453 643
	}
454 644

  
455 645
	/**
456
	 * DOCUMENT ME!
646
	 * <p>Tries to find the nearest geometry or grid control point by the position of the current snap tool.</p>
647
	 * 
648
	 * <p>Prioritizes the grid control points than the geometries ones.</p>
649
	 * 
650
	 * <p>If finds any near, stores the <i>map</i> and <i>pixel</i> coordinates for the snap, and enables
651
	 *  the <code>bForceCoord</code> attribute for the next draw of the mouse's cursor.</p>
457 652
	 *
458
	 * @param point
653
	 * @param point current mouse 2D position
459 654
	 */
460 655
	private void calculateSnapPoint(Point point) {
461 656
		// Se comprueba el ajuste a rejilla
......
508 703

  
509 704
	}
510 705

  
511
	/**
512
	 * @see java.awt.event.MouseWheelListener#mouseWheelMoved(java.awt.event.MouseWheelEvent)
706
	/*
707
	 * (non-Javadoc)
708
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseWheelMoved(java.awt.event.MouseWheelEvent)
513 709
	 */
514 710
	public void mouseWheelMoved(MouseWheelEvent e) throws BehaviorException {
515 711
	}
516 712

  
517 713
	/**
518
	 * M?todo que realiza las transiciones en las herramientas en funci?n de un
519
	 * texto introducido en la consola
714
	 * <p>Process the information written by the user about the next point coordinate, determining
715
	 *  the kind of <i>transition</i> according the parameters written.</p>
716
	 * 
717
	 * <p>After, invokes one of the three possible <i>transition</i> methods of the <i>finite machine</i> of
718
	 *  edition:
719
	 *  <ul>
720
	 *   <li><i>First transition type: <b>Point</i></b>: if <code>text</code> matches with any pattern of
721
	 *    parameters needed for any kind of point coordinates.<br>
722
	 *    There are eight ways of introducing point 2D coordinates:
723
	 *    <ul>
724
	 *    <li><i>X,Y</i> : absolute cardinal 2D coordinate from the center <i>(0,0)</i> of the CCS <i>Current Coordinate System</i>.</li>
725
	 *    <li><i>@X,Y</i> : relative cardinal 2D distances from the last point added of the CCS. If it's the first point of the geometry,
726
	 *     works like <i>X,Y</i>.</li>
727
	 *    <li><i>length< angle</i> : absolute polar 2D coordinate from the center <i>(0,0)</i> of the CCS <i>Current Coordinate System</i>, using
728
	 *     <i>angle</i> from the <i>X</i> axis of CCS, and <i>length</i> far away.</li>
729
	 *    <li><i>@length< angle</i> : relative polar 2D coordinate from the last point added of the CCS <i>Current Coordinate System</i>, using
730
	 *     <i>angle</i> from the <i>X</i> axis of CCS, and <i>length</i> far away. If it's the first point of the geometry,
731
	 *     works like <i>length< angle</i>.</li>
732
	 *    <li><i>*X,Y</i> : like <i>X,Y</i> but using UCS <i>Universal Coordinate System</i> as reference.</li>
733
	 *    <li><i>@*X,Y</i> : like <i>@X,Y</i> but using UCS <i>Universal Coordinate System</i> as reference.
734
	 *      If it's the first point of the geometry, works like <i>*X,Y</i>.</li>
735
	 *    <li><i>*length< angle</i> : like <i>length< angle</i> but using UCS <i>Universal Coordinate System</i> as reference.</li>
736
	 *    <li><i>@*length< angle</i> : like <i>@length< angle</i> but using UCS <i>Universal Coordinate System</i> as reference.
737
	 *      If it's the first point of the geometry, works like <i>*length< angle</i>.</li>
738
	 *    </ul>
739
	 *   </li>
740
	 *   <li><i>Second transition type: <b>Value</i></b>: if recognizes it as a single number.</li>
741
	 *   <li><i>Third transition type: <b>Option</i></b>: by default, if can't classify the information as a single number
742
	 *    neither as a point. This information will be an <code>String</code> and dealt as an option of the current
743
	 *    tool state. Ultimately, if isn't valid, <code>text</code> will be rewritten in the console notifying the user
744
	 *    that isn't correct.</li>
745
	 *  </ul>
746
	 * </p>
520 747
	 *
521
	 * @param text
522
	 *            DOCUMENT ME!
748
	 * @param text command written by user in the edition's console
523 749
	 */
524 750
	public void textEntered(String text) {
525 751
		if (text == null) {
......
582 808
	}
583 809

  
584 810
	/**
585
	 * DOCUMENT ME!
811
	 * If there are options related with the <code>CADTool</code> at the peek of the CAD tool stack,
812
	 *  displays them as a popup.
586 813
	 */
587 814
	public void configureMenu() {
588 815
		String[] desc = ((CADTool) cadToolStack.peek()).getDescriptions();
......
601 828
	}
602 829

  
603 830
	/**
604
	 * Recibe los valores de la transici?n (normalmente un punto) y el evento
605
	 * con el que se gener? (si fue de rat?n ser? MouseEvent, el que viene en el
606
	 * pressed) y si es de teclado, ser? un KeyEvent. Del evento se puede sacar
607
	 * informaci?n acerca de si estaba pulsada la tecla CTRL, o Alt, etc.
831
	 * <p>One of the three kind of transaction methods of the <i>finite machine</i> of
832
	 *  edition.</p>
833
	 * 
834
	 * <p>This one deals <code>values</code> as two numbers that, according <code>type</code>
835
	 *  calculate a new point 2D in the current layer edited in the associated <code>MapControl</code>.</p>
608 836
	 *
609
	 * @param values
610
	 * @param event
837
	 * <p>There are different ways of calculating the new point 2D coordinates, according the value of <code>type</code>, see 
838
	 *  {@link #textEntered(String) #textEntered(String)}.</p>
839
	 *    
840
	 * <p>After applying the changes, updates the controls available for managing the current data.</p>
841
	 * 
842
	 * @param values numbers needed to calculate the new point coordinates according <code>type</code>
843
	 * @param event event which generated this invocation (a <code>MouseEvent</code> or a <code>KeyEvent</code>)
844
	 * @param type kind of information that is <code>values</code>. According this parameter, will calculate the
845
	 *  new point in a different way
846
	 * 
847
	 * @see CADTool#transition(double, double, InputEvent)
848
	 * @see #transition(double)
849
	 * @see #transition(String)
611 850
	 */
612 851
	private void transition(double[] values, InputEvent event, int type) {
613 852
		questionAsked = true;
......
684 923
	}
685 924

  
686 925
	/**
687
	 * DOCUMENT ME!
688
	 *
689
	 * @param text
690
	 *            DOCUMENT ME!
691
	 * @param source
692
	 *            DOCUMENT ME!
693
	 * @param sel
694
	 *            DOCUMENT ME!
695
	 * @param values
696
	 *            DOCUMENT ME!
926
	 * <p>One of the three kind of transaction methods of the <i>finite machine</i> of
927
	 *  edition.</p>
928
	 * 
929
	 * <p>This one deals <code>value</code> as a single number used as a parameter for the current
930
	 *    tool state. Ultimately, if isn't valid, <code>number</code> will be rewritten in the
931
	 *    console notifying the user that isn't correct.</p>
932
	 *    
933
	 * <p>After applying the changes, updates the controls available for managing the current data.</p>
934
	 * 
935
	 * @param value value for the current tool state
936
	 * 
937
	 * @see CADTool#transition(double)
938
	 * @see #transition(double[], InputEvent, int)
939
	 * @see #transition(String)
697 940
	 */
698 941
	private void transition(double value) {
699 942
		questionAsked = true;
......
706 949
		PluginServices.getMainFrame().enableControls();
707 950
	}
708 951

  
952
	/**
953
	 * <p>One of the three kind of transaction methods of the <i>finite machine</i> of
954
	 *  edition.</p>
955
	 * 
956
	 * <p>This one deals <code>option</code> as an option of the current
957
	 *    tool state. Ultimately, if isn't valid, <code>option</code> will be rewritten in the
958
	 *    console notifying the user that isn't correct.</p>
959
	 * 
960
	 * @param option option for the current tool state
961
	 * 
962
	 * @see CADTool#transition(String)
963
	 * @see #transition(double[], InputEvent, int)
964
	 * @see #transition(double)
965
	 */
709 966
	public void transition(String option) {
710 967
		questionAsked = true;
711 968
		if (!cadToolStack.isEmpty()) {
......
728 985
	}
729 986

  
730 987
	/**
731
	 * DOCUMENT ME!
988
	 * Shows or hides a grid on the <code>ViewPort</code> of the associated <code>MapControl</code>.
732 989
	 *
733
	 * @param value
734
	 *            DOCUMENT ME!
990
	 * @param value <code>true</code> to make the grid visible; <code>false</code> to make it invisible
735 991
	 */
736 992
	public void setGridVisibility(boolean value) {
737 993
		getGrid().setShowGrid(value);
......
739 995
		getMapControl().repaint();
740 996
	}
741 997

  
998
	/**
999
	 * Sets the snap tools enabled or disabled.
1000
	 * 
1001
	 * @param activated <code>true</code> to enable the snap tools; <code>false</code> to disable them
1002
	 * 
1003
	 * @see #isRefentEnabled()
1004
	 */
742 1005
	public void setRefentEnabled(boolean activated) {
743 1006
		bRefent = activated;
744 1007
	}
745 1008

  
1009
	/**
1010
	 * Determines if snap tools are enabled or disabled.
1011
	 * 
1012
	 * @return <code>true</code> to enable the snap tools; <code>false</code> to disable them
1013
	 * 
1014
	 * @see #setRefentEnabled(boolean)
1015
	 */
746 1016
	public boolean isRefentEnabled()
747 1017
	{
748 1018
		return bRefent;
749 1019
	}
750 1020

  
751
	/**
1021
	/*
1022
	 * (non-Javadoc)
752 1023
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
753 1024
	 */
754 1025
	public ToolListener getListener() {
......
770 1041
	}
771 1042

  
772 1043
	/**
773
	 * DOCUMENT ME!
774
	 *
775
	 * @return DOCUMENT ME!
1044
	 * Returns the {@link CADTool CADTool} at the top of the stack without removing it from the CAD tool stack.
1045
	 * 
1046
	 * @return the {@link CADTool CADTool} at the top of the stack
1047
	 * 
1048
	 * @see #pushCadTool(CADTool)
1049
	 * @see #popCadTool()
1050
	 * @see #setCadTool(CADTool)
776 1051
	 */
777 1052
	public CADTool getCadTool() {
778 1053
		return (CADTool) cadToolStack.peek();
779 1054
	}
780 1055

  
781 1056
	/**
782
	 * DOCUMENT ME!
783
	 *
784
	 * @param cadTool
785
	 *            DOCUMENT ME!
1057
	 * <p>Pushes a {@link CADTool CADTool} onto the top of the CAD tool stack, and sets it as current.</p>
1058
	 * 
1059
	 * @param cadTool CAD tool to enable as current
1060
	 *            
1061
	 * @see #getCadTool()
1062
	 * @see #popCadTool()
1063
	 * @see #setCadTool(CADTool)
786 1064
	 */
787 1065
	public void pushCadTool(CADTool cadTool) {
788 1066
		cadToolStack.push(cadTool);
......
808 1086
	}
809 1087

  
810 1088
	/**
811
	 * DOCUMENT ME!
1089
	 * Removes the peek of the CAD tool stack.
1090
	 * 
1091
	 * @see #pushCadTool(CADTool)
1092
	 * @see #getCadTool()
1093
	 * @see #setCadTool(CADTool)
812 1094
	 */
813 1095
	public void popCadTool() {
814 1096
		cadToolStack.pop();
815 1097
	}
816 1098

  
817 1099
	/**
818
	 * DOCUMENT ME!
1100
	 * <p>Displays at the console associated to the current active view that's being edited, the question of the following
1101
	 *  operation that user can do with the current <code>CADTool</code>, only if it hasn't just answered.</p>
1102
	 * 
1103
	 * <p>The format of the question will be according the following pattern:<br>
1104
	 *   "\n#"<i>{cadtool at CAD tool stack peek}</i>.getQuestion()">"
1105
	 * </p>
819 1106
	 */
820 1107
	public void askQuestion() {
821 1108
		CADTool cadtool = (CADTool) cadToolStack.peek();
......
841 1128
	}
842 1129

  
843 1130
	/**
844
	 * DOCUMENT ME!
845
	 *
846
	 * @param cadTool
847
	 *            DOCUMENT ME!
1131
	 * Empties the CAD tools stack and pushes <code>cadTool</code> in it.
1132
	 * 
1133
	 * @param cadTool CAD tool to set at the peek of the stack
1134
	 * 
1135
	 * @see #pushCadTool(CADTool)
1136
	 * @see #popCadTool()
1137
	 * @see #getCadTool()
848 1138
	 */
849 1139
	public void setCadTool(CADTool cadTool) {
850 1140
		cadToolStack.clear();
......
852 1142
		// askQuestion();
853 1143
	}
854 1144

  
855

  
856 1145
	/**
857
	 * Elimina las geometr?as seleccionadas actualmente
1146
	 * <p>Removes all geometries selected in the associated <code>MapControl</code>.
858 1147
	 */
859 1148
	public void delete() {
860 1149
		ILayerEdited aux = CADExtension.getEditionManager().getActiveLayerEdited();
......
905 1194
	}
906 1195

  
907 1196
	/**
908
	 * DOCUMENT ME!
909
	 *
910
	 * @param b
1197
	 * @see CADGrid#setAdjustGrid(boolean)
911 1198
	 */
912 1199
	public void setAdjustGrid(boolean b) {
913 1200
		getGrid().setAdjustGrid(b);
914 1201
	}
915 1202

  
916 1203
	/**
917
	 * DOCUMENT ME!
1204
	 * <p>Responds to actions of writing common key commands for all kind of CAD operations, enabling/disabling after
1205
	 *  the controls to manage the available information according the tool selected:
1206
	 *  <ul>
1207
	 *   <li><i>eliminar</i>: removes the geometries that are now selected.</li>
1208
	 *   <li><i>escape</i>: executes different actions according to the current CAD tool of the associated <code>MapControl</code>:
1209
	 *    <ul>
1210
	 *     <li>If the tool enabled is identified by <i>cadtooladapter</i>: empties the CAD tools stack, changing the current tool by
1211
	 *      a {@link SelectionCADTool SelectionCADTool}, which is identified by <i>_selection</i> and allows select features of the
1212
	 *      active vector layer of the associated <code>MapControl</code> instance. </li>
1213
	 *     <li>Otherwise, that means current associated <code>MapControl</code> instance isn't identified by "<i>cadtooladapter</i>",
1214
	 *      changes the enabled tool by the previous.</li>
1215
	 *    </ul>
1216
	 *   </li>
1217
	 *  </ul>
1218
	 * </p>
918 1219
	 *
919
	 * @param actionCommand
1220
	 * @param actionCommand identifier of the key action command executed by the user
1221
	 * 
1222
	 * @see SelectionCADTool
1223
	 * @see MapControl#setPrevTool()
920 1224
	 */
921 1225
	public void keyPressed(String actionCommand) {
922 1226
		if (CADExtension.getEditionManager().getActiveLayerEdited()== null) {
......
957 1261
	}
958 1262

  
959 1263
	/**
960
	 * Provoca un repintado "soft" de la capa activa en edici?n.
961
	 * Las capas por debajo de ella no se dibujan de verdad, solo
962
	 * se dibuja la que est? en edici?n y las que est?n por encima
963
	 * de ella en el TOC.
1264
	 * <p>Applies a lightweight repaint of the active layer being edited.</p>
1265
	 * 
1266
	 * <p>All layers under it won't be drawn, only the upper one and whose are over that layer in the TOC.</p>
1267
	 * 
1268
	 * @see MapControl#rePaintDirtyLayers()
964 1269
	 */
965 1270
	public void refreshEditedLayer()
966 1271
	{
......
973 1278

  
974 1279
	}
975 1280

  
1281
	/**
1282
	 * Gets the {@link CADGrid CADGrid} that can be drawn on the <code>ViewPort</code> of the associated <code>MapControl</code>.
1283
	 * 
1284
	 * @return reference to the <i>grid</i> that can be applied on the <code>ViewPort</code>
1285
	 * 
1286
	 * @see #setGridVisibility(boolean)
1287
	 */
976 1288
	public CADGrid getGrid() {
977 1289
		return cadgrid;
978 1290
	}
979 1291

  
1292
	/**
1293
	 * Determines if is enabled or not the <i>orto</i> mode.
1294
	 * 
1295
	 * @return <code>true</code> if is enabled the <i>orto</i> mode; otherwise <code>false</code> 
1296
	 * 
1297
	 * @see #setOrtoMode(boolean)
1298
	 */
980 1299
	public boolean isOrtoMode() {
981 1300
		return bOrtoMode;
982 1301
	}
983 1302

  
1303
	/**
1304
	 * Enables / disables the <i>orto</i> mode.
1305
	 * 
1306
	 * @param b the desired value
1307
	 * 
1308
	 * @see #isOrtoMode()
1309
	 */
984 1310
	public void setOrtoMode(boolean b) {
985 1311
		bOrtoMode = b;
986 1312
	}
987 1313

  
1314
	/**
1315
	 * Associates and stores the specified name with the specified {@link CADTool CADTool}.
1316
	 * 
1317
	 * @param name name of the tool
1318
	 * @param c CAD tool to interactuate editing the layers
1319
	 * 
1320
	 * @see #getCADTools()
1321
	 * @see #getCADTool(String)
1322
	 */
988 1323
	public static void addCADTool(String name, CADTool c) {
989 1324
		namesCadTools.put(name, c);
990 1325

  
991 1326
	}
1327

  
1328
	/**
1329
	 * Gets all CAD tools available to edit layers with this tool listener.
1330
	 * 
1331
	 * @return CAD tools available to edit layers with this tool listener
1332
	 *
1333
	 * @see #addCADTool(String, CADTool)
1334
	 * @see #getCADTool(String)
1335
	 */
992 1336
	public static CADTool[] getCADTools() {
993 1337
		return (CADTool[]) CADToolAdapter.namesCadTools.values().toArray(new CADTool[0]);
994 1338
	}
1339

  
1340
	/**
1341
	 * Returns the {@link CADTool CADTool} to which the specified name is mapped.
1342
	 * 
1343
	 * @param text name of the tool
1344
	 * @return the CAD tool whose associated name is to be returned
1345
	 * 
1346
	 * @see #addCADTool(String, CADTool)
1347
	 * @see #getCADTools()
1348
	 */
995 1349
	public CADTool getCADTool(String text) {
996 1350
		CADTool ct = (CADTool) namesCadTools.get(text);
997 1351
		return ct;
998 1352
	}
999 1353

  
1354
	/**
1355
	 * Gets the object used to manage the edition of the layers of the associated <code>MapControl</code>.
1356
	 * 
1357
	 * @see EditionManager
1358
	 * 
1359
	 * @return object used to manage the edition of the layers
1360
	 */
1000 1361
	public EditionManager getEditionManager() {
1001 1362
		return editionManager;
1002 1363
	}
1003 1364

  
1365
	/**
1366
	 * <p>Initializes the <i>flatness</i> with the defined in preferences.</p>
1367
	 *
1368
	 * <p>The <i>flatness</i> is the maximum tolerance used to approximate curved lines in a <i>shape</i> by polylines.</p>
1369
	 * <p>The shapes doesn't support primitive like arcs neither other curved lines to draw their geometries, then for drawing any
1370
	 *  kind of this geometries the curved lines are drawn approximately by a polyline. And for doing more realistic that curves,
1371
	 *  is used the <i>flatness</i> parameter, that indicates that the difference between each arc and the straight segment that
1372
	 *  approximates it must be in the worse case, like the <i>flatness</i>.</p>
1373
	 *  
1374
	 * @see FConverter#FLATNESS
1375
	 */
1004 1376
	public void initializeFlatness() {
1005 1377
		if (!flatnessInitialized){
1006 1378
			flatnessInitialized=true;
......
1009 1381
			FConverter.FLATNESS=flatness;
1010 1382
		}
1011 1383
	}
1384

  
1385
	/**
1386
	 * <p>Updates the grid on the <code>ViewPort</code> of the associated <code>MapControl</code>
1387
	 *  object according the values in the {@link com.iver.cit.gvsig.gui.cad.CADToolAdapter.prefs.Preferences com.iver.cit.gvsig.gui.cad.CADToolAdapter.prefs.Preferences}.</p>
1388
	 * 
1389
	 * <p>The preferences are:
1390
	 *  <ul>
1391
	 *   <li>Show/hide the grid.</li>
1392
	 *   <li>Adjust or not the grid.</li>
1393
	 *   <li>Horizontal ( X ) line separation.</li>
1394
	 *   <li>Vertical ( Y ) line separation.</li>
1395
	 *  </ul>
1396
	 * </p>
1397
	 */
1012 1398
	public void initializeGrid(){
1013 1399
		boolean showGrid = prefs.getBoolean("grid.showgrid",getGrid().isShowGrid());
1014 1400
		boolean adjustGrid = prefs.getBoolean("grid.adjustgrid",getGrid().isAdjustGrid());
......
1021 1407
		getGrid().setGridSizeX(dx);
1022 1408
		getGrid().setGridSizeY(dy);
1023 1409
	}
1410

  
1024 1411
	/**
1025
	* Returns the type of active layer.
1026
	**/
1412
	 * <p>Returns the type of the shape that's the current active and vector layer being edited.</p>
1413
	 * 
1414
	 * @see FLyrVect#getShapeType()
1415
	 * 
1416
	 * @return type of the shape that's the current active and vector layer being edited
1417
	 */
1027 1418
	public int getActiveLayerType() {
1028 1419
		int type=FShape.MULTI;
1029 1420
		try {

Also available in: Unified diff