Revision 20098 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/MapControl.java

View differences:

MapControl.java
78 78

  
79 79

  
80 80
/**
81
 * MapControl.
81
 * <p>A component that includes a {@link MapContext MapContext} with support for use it as a particular {@link Behavior Behavior}.</p>
82 82
 *
83
 * <p>A developer can register a set of <code>Behavior</code>, but only one (that can be a composition of several) of them can be active. The active one
84
 *  defines the way to work and access with its <code>MapContext</code>'s layers. The active behavior, in combination with the appropriate
85
 *  {@link ToolListener ToolListener} will allow user work with a particular <i>tool</i>.</p>
86
 *
87
 * <p>All mouse events produced on this component will be delegated to the current active behavior, the <i>currentMapTool</i>.</p>
88
 * 
89
 * <p><b>Drawing process:</b></p>
90
 * 
91
 * <p>Uses a double buffer for the drawing process of <code>MapContext</code>'s information.</p>
92
 * 
93
 * <p>If the double buffer wasn't created, creates a new one.</p>
94
 * 
95
 * <p>Paints the component according the following algorithm:
96
 * <br>
97
 *  &nbsp If <i>status</i> is <i>UPDATED</i>:<br>
98
 *  &nbsp &nbsp If there is a <i>double buffer</i>:<br>
99
 *  &nbsp &nbsp &nbsp If there is a <i>behavior</i> for managing the <code>MapControl</code> instance, delegates
100
 *   the drawing process to that behavior, calling: <code><i>behavior_instance</i>.paintComponent(g)</code>.<br>
101
 *  &nbsp &nbsp &nbsp Else, repaints the current graphical information quickly calling: <code>g.drawImage(image,0,0,null)</code>.<br>
102
 *  &nbsp Else, (<i>status</i> is <i>OUTDATED</i>, or <i>ONLY_GRAPHICS</i>): executes a quickly repaint of the previous information calling <code>g.drawImage(image,0,0,null)</code>, and creates
103
 *   a <i>painting request</i> to delegate the heavy drawing process to the {@link Drawer2 Drawer2}'s worker thread, according the <i>SingleWorketThread</i> pattern, starting a timer to update
104
 *   (invoking <code>repaint()</code>) the view every delay of <code>1000 / drawFrameRate</code> ms. during that heavy drawing process, and if its enabled <code>drawAnimationEnabled</code>. The <i>painting request</i> once is being attended, invokes <code>MapContext</code> to
105
 *   draw the layers: <code>mapContext.draw(image, g, cancel,mapContext.getScaleView());</code> 
106
 * <br>
107
 * <p>Some notes:
108
 *  <ul>
109
 *   <li>The painting process can be cancelled calling {@link #cancelDrawing() #cancelDrawing()}.</li>
110
 *   <li>At last resort, the particular implementation of each layer in a <code>MapControl</code>'s <code>MapContrext</code>
111
 *    will be that one which will draw the graphical information, and, if supports, which could cancel its drawing subprocess.</li>
112
 *   <li>It's possible to force repaint all layers, calling {@link #drawMap(boolean doClear) #drawMap(boolean)}.</li>
113
 *   <li>It's possible repaint only the dirty layers, calling {@link #rePaintDirtyLayers() #rePaintDirtyLayers()}.</li>
114
 *   <li>It's possible repaint only the {@link GraphicLayer GraphicLayer}, calling {@link #drawGraphics() #drawGraphics()}.</li>
115
 *  </ul> 
116
 * </p>
117
 * 
118
 * <p><b>Tools:</b></p>
119
 * 
120
 * <p>A developer can:
121
 *   <ul>
122
 *    <li>Register each tool as:
123
 *     <ul>
124
 *      <li>A single behavior: {@link #addMapTool(String, Behavior) #addMapTool(String, Behavior)}.</li>
125
 *      <li>Or, a compound behavior: {@link #addMapTool(String, Behavior) #addMapTool(String, Behavior)}.</li>
126
 *     </ul>
127
 *    </li>
128
 *    <li>Get the current active tool: {@link #getCurrentMapTool() #getCurrentMapTool()}.</li>
129
 *    <li>Get the current active tool name: {@link #getCurrentTool() #getCurrentTool()}.</li>
130
 *    <li>Get a registered tool: {@link #getMapTool(String) #getMapTool(String)}.</li>
131
 *    <li>Get the name of all tools registered: {@link #getMapToolsKeySet() #getMapToolsKeySet()}.</li>
132
 *    <li>Get all tools registered, including the name they were registered: {@link #getNamesMapTools() #getNamesMapTools()}.</li>
133
 *    <li>Determine if has a tool registered: {@link #hasTool(String) #hasTool(String)}.</li>
134
 *    <li>Set as an active tool, one of the registered: {@link #setTool(String) #setTool(String)}.</li>
135
 *    <li>Set as active tool, the previous used: {@link #setPrevTool() #setPrevTool()}.</li>
136
 *    <li>Set the current tool: {@link #setCurrentMapTool(Behavior) #setCurrentMapTool(Behavior)}.</li>
137
 *    <li>Change the draw frame rate: {@link #setDrawFrameRate(int) #setDrawFrameRate(int)} and {@link #applyFrameRate() #applyFrameRate()}.</li>
138
 *    <li>Get the draw frame rate: {@link #getDrawFrameRate() #getDrawFrameRate()}.</li>
139
 *    <li>Determine if will repaint this component each time timer finishes: {@link #isDrawAnimationEnabled() #isDrawAnimationEnabled()}.</li>
140
 *    <li>Change if will repaint this component each time timer finishes: {@link #setDrawAnimationEnabled(boolean) #setDrawAnimationEnabled(boolean)}.</li>
141
 *    <li>Get the shared object that determines if a drawing process must be cancelled or can continue: {@link #getCanceldraw() #getCanceldraw()}.</li>
142
 *   </ul>
143
 * </p>
144
 *
145
 * <p><b>Exception listener:</b></p>
146
 * 
147
 * <p> Adding an <code>ExceptionListener</code>, can get notification about any exception produced: 
148
 *  <ul>
149
 *   <li>Attending a <i>painting request</i>.</li>
150
 *   <li>Working with the active tool.</li>
151
 *   <li>Applying a <i>zoom in</i> or <i>zoom out</i> operation.</li>
152
 *  </ul>
153
 * </p>
154
 * 
155
 * <p><b>Other:</b></p>
156
 * 
157
 * <p>Other useful capabilities of <code>MapControl</code>:
158
 *   <ul>
159
 *    <li>Cancel the current drawing process (notifying it also to the inner
160
 *     <code>MapContext</code> instance and its layers): {@link #cancelDrawing() #cancelDrawing()}.</li>
161
 *    <li>Applying a <i>zoom in</i> operation centered at mouse position (without a <code>ToolListener</code>): {@link #zoomIn() #zoomIn()}.</li>
162
 *    <li>Applying a <i>zoom out</i> operation centered at mouse position (without a <code>ToolListener</code>): {@link #zoomOut() #zoomOut()}.</li>
163
 *   </ul>
164
 * </p>
165
 * 
166
 * @see CancelDraw
167
 * @see Drawer2
168
 * @see MapContextListener
169
 * @see MapToolListener
170
 * 
83 171
 * @author Fernando Gonz?lez Cort?s
84 172
 */
85
public class MapControl extends JComponent implements ComponentListener,
86
			CommandListener {
87
	/** Cuando la vista est? actualizada. */
173
public class MapControl extends JComponent implements ComponentListener, CommandListener {
174
	/**
175
	 * <p>One of the possible status of <code>MapControl</code>. Determines that all visible information has been
176
	 * drawn and its updated.</p> 
177
	 */
88 178
	public static final int ACTUALIZADO = 0;
89 179

  
90
	/** Cuando la vista est? desactualizada. */
180
	/**
181
	 * <p>One of the possible status of <code>MapControl</code>. Determines that not all visible information has been
182
	 * drawn or isn't updated.</p> 
183
	 */
91 184
	public static final int DESACTUALIZADO = 1;
92
    public static final int ONLY_GRAPHICS = 2;
185
	
186
	/**
187
	 * <p>One of the possible status of <code>MapControl</code>. Determines that only the graphical layer must
188
	 * be drawn / updated.</p> 
189
	 */
190
	public static final int ONLY_GRAPHICS = 2;
191

  
192
	/**
193
	 * <p>Determines the number of frames.</p>
194
	 *
195
	 * <p>Number of updates per second that the timer will invoke repaint this component.</p>
196
	 */
93 197
    private static int drawFrameRate = 3;
198

  
199
    /**
200
     * <p>Determines if the drawer can update this <code>MapControl</code> instance when the timer launches an event.</p>
201
     */
94 202
    private static boolean drawAnimationEnabled = true;
95 203

  
96 204
    // public static final int FAST_PAINT = 3;
97 205
	//private static Logger logger = Logger.getLogger(MapControl.class.getName());
98
	private MapContext mapContext = null;
206

  
207
    /**
208
     * <p>Inner model with the layers, event support for drawing them, and the <code>ViewPort</code>
209
     *  with information to adapt to the bounds available in <i>image coordinates</i>.</p>
210
     *  
211
     * @see #getMapContext()
212
     * @see #setMapContext(MapContext) 
213
     */
214
    private MapContext mapContext = null;
215

  
99 216
    //private boolean drawerAlive = false;
100
	protected HashMap namesMapTools = new HashMap();
101
	protected Behavior currentMapTool = null;
102
	private int status = DESACTUALIZADO;
103
	private BufferedImage image = null;
104
	protected String currentTool;
105
	private CancelDraw canceldraw;
106
	//private boolean isCancelled = true;
107
	private Timer timer;
108
	protected ViewPort vp;
109
	//private Drawer drawer;
217

  
218

  
219
	/**
220
	 * <p>All registered <code>Behavior</code> that can define a way to work with this <code>MapControl</code>.</p>
221
	 * 
222
	 * <p>Only one of them can be active at a given moment.</p>
223
	 * 
224
	 * @see #addMapTool(String, Behavior)
225
	 * @see #addMapTool(String, Behavior[])
226
	 * @see #getMapTool(String)
227
	 * @see #getMapToolsKeySet() 
228
	 * @see #getNamesMapTools()
229
	 */
230
    protected HashMap namesMapTools = new HashMap();
231

  
232
	/**
233
	 * <p>Active {@link Behavior Behavior} that will generate events according a criterion, and then, with a {@link ToolListener ToolListener}
234
	 *  associated, will simulate to user that works with this component as a particular tool.</p>
235
	 *  
236
	 * @see #getCurrentMapTool()
237
	 * @see #getCurrentTool()
238
	 * @see #setTool(String) 
239
	 */
240
    protected Behavior currentMapTool = null;
241

  
242
	/**
243
	 * <p>Determines which's the current drawn status of this component:
244
	 * <ul>
245
	 *  <li><b>OUTDATED</b>: all visible information has been drawn or isn't updated.</li>
246
	 *  <li><b>UTDATED</b>: all visible information has been drawn and its updated.</li>
247
	 *  <li><b>ONLY_GRAPHICS</b>: only the graphical layer must be drawn / updated.</li>
248
	 * </ul>
249
	 * </p>
250
	 * 
251
	 * <p>The <code>MapControl</code> drawing process will consider the value of this parameter to decide which elements will
252
	 *  be updated or drawn.</p>
253
	 */
254
    private int status = DESACTUALIZADO;
255

  
256
	/**
257
	 * <p>Image with a buffer to accelerate the draw the changes of the graphical items in this component.</p>
258
	 * 
259
	 * <p>Firstly, information will be drawn in the buffer, and, when is outright drawn, that information will be displayed.
260
	 * Meanwhile, the previous image can be kept showed.</p>
261
	 * 
262
	 * @see BufferedImage
263
	 * 
264
	 * @see #getImage()
265
	 */
266
    private BufferedImage image = null;
267

  
268
	/**
269
	 * <p>Name of the tool used currently to interact with this component.</p>
270
	 * 
271
	 * @see #getCurrentTool()
272
	 * @see #setTool(String) 
273
	 */
274
    protected String currentTool;
275

  
276
	/**
277
	 * <p>Object to store the flag that notifies a drawing thread task and <code>MapContext</code>'s layers,
278
	 * that must be canceled or can continue with the process.</p>
279
	 * 
280
	 * @see #cancelDrawing()
281
	 */
282
    private CancelDraw canceldraw;
283

  
284
    //private boolean isCancelled = true;
285

  
286
	/**
287
	 * <p>Fires an action events after a specified delay.</p>
288
	 * 
289
	 * <p><code>MapControl</code> will use the timer to update its visible graphical information during
290
	 *  a drawing process, or allowing to cancel that process.</p>
291
	 * 
292
	 * <p>This is very useful to pretend faster interactivity to user when <code>MapControl</code> has
293
	 *  lots of layers, and / or layers with heavy graphical elements, that need a long time to finish
294
	 *  drawing all its data.</p> 
295
	 */
296
    private Timer timer;
297

  
298
	/**
299
	 * <p>Reference to the {@link ViewPort ViewPort} of the {@link MapContext MapContext} of this component.</p>
300
	 * 
301
	 * <p>The view port once is created an instance of <code>MapControl</code>,
302
	 *  is obtained from the <i>EPSG:23030</i> projection, that's the default projection for this component.</p>
303
	 *  
304
	 * <p>After, the view port will change adapting itself according the current projection and the extent.</p>
305
	 * 
306
	 * @see #getViewPort()
307
	 * 
308
	 * @see ViewPort
309
	 */
310
    protected ViewPort vp;
311

  
312
    //private Drawer drawer;
313

  
314
	/**
315
	 * <p>Manager of all <code>MapControl</code> painting requests.</p>
316
	 */
110 317
    private Drawer2 drawer2;
318

  
111 319
    // private boolean firstDraw = true;
112
	protected MapToolListener mapToolListener = new MapToolListener();
113
	private MapContextListener mapContextListener = new MapContextListener();
114
	private ExceptionHandlingSupport exceptionHandlingSupport = new ExceptionHandlingSupport();
115 320

  
321
	/**
322
	 * <p>Listener of all kind of mouse events produced in this component.</p>
323
	 * 
324
	 * <p>Delegates each mouse event to the current map tool.</p>
325
	 * 
326
	 * @see #addMapTool(String, Behavior)
327
	 * @see #addMapTool(String, Behavior[])
328
	 * @see #getMapTool(String)
329
	 * @see #getMapToolsKeySet()
330
	 * @see #getNamesMapTools()
331
	 * @see #setTool(String)
332
	 */
333
    protected MapToolListener mapToolListener = new MapToolListener();
334

  
335
	/**
336
	 * <p>Listener of all events produced in a this component's <code>MapContext</code>
337
	 * object during an atomic period of time.</p>
338
	 */
339
    private MapContextListener mapContextListener = new MapContextListener();
340

  
341
	/**
342
	 * <p>Group of <code>ExceptionListener</code> that, in whatever moment could be notified a Throwable Java error or exception.</p>
343
	 * 
344
	 * @see #addExceptionListener(ExceptionListener)
345
	 * @see #removeExceptionListener(ExceptionListener)
346
	 */
347
    private ExceptionHandlingSupport exceptionHandlingSupport = new ExceptionHandlingSupport();
348

  
349
    /**
350
     * <p>Name of the previous tool used.</p>
351
     */
116 352
	protected String prevTool;
117 353

  
118 354
	/**
......
121 357
    // private boolean paintEnabled = false;
122 358

  
123 359
	/**
124
	 * Crea un nuevo NewMapControl.
360
	 * <p>Creates a new <code>MapControl</code> instance with the following characteristics:
361
	 * <ul>
362
	 *  <li><i>Name</i>: MapControl .</li>
363
	 *  <li>Disables the double buffer of <code>JComponent</code> .</li>
364
	 *  <li>Sets opaque <i>(see {@link JComponent#setOpaque(boolean)} )</i>. </li>
365
	 *  <li>Sets its status to <code>OUTDATED</code> .</li>
366
	 *  <li>Creates a new {@link CancelDraw CancelDraw} object to notify <code>MapContext</code>'s layers if can continue processing the drawn or must cancel it.</li>
367
	 *  <li>Creates a new {@link MapContext MapContext} with a new {@link ViewPort ViewPort} in the projection <i>"EPSG:23030"</i> .</li>
368
	 *  <li>Creates a new {@link CommandListener CommandListener} for edition operations.</li>
369
	 *  <li>Creates a new {@link MapToolListener MapToolListener}, and associates it as a listener of whatever kind of mouse events produced in this component.</li>
370
	 *  <li>Creates a new {@link Drawer2 Drawer2} for managing the painting requests.</li>
371
	 *  <li>Creates a new timer that will invoke refresh this component <code>drawFrameRate</code> per second, when is running a drawing process, and its enabled
372
	 *   <code>drawAnimationEnabled</code>.</li>
373
	 * </ul>
374
	 * </p>
125 375
	 */
126 376
	public MapControl() {
127 377
		this.setName("MapControl");
......
159 409
	}
160 410

  
161 411
	/**
162
	 * Inserta el modelo.
163
	 *
164
	 * @param model FMap.
412
	 * <p>Sets a <code>MapContext</code> to this component.</p>
413
	 * 
414
	 * <p>The <code>MapContext</code> has the <i>model</i>, and most of the <i>view</i>,
415
	 * and <i>control</i> logic of the layers of this component, including a {@link ViewPort ViewPort} to adapt the
416
	 * information to the projection, and to display it in the available area.</p>
417
	 * 
418
	 * <p>If <code>model</code> hadn't a <code>ViewPort</code>, assigns the current one to it, otherwise, use its <code>ViewPort</code>.</p>
419
	 * 
420
	 * <p>After assigning the <code>MapContext</code> and <code>ViewPort</code>, sets the same {@link MapContextListener MapContextListener}
421
	 *  that was using, and changes the <i>status</i> to <code>OUTDATED</code>.</p>
422
	 * 
423
	 * @param model this component's <code>MapContext</code>, that includes the <code>ViewPort</code>.
424
	 * 
425
	 * @see MapContext
426
	 * 
427
	 * @see #getMapContext()
165 428
	 */
166 429
	public void setMapContext(MapContext model) {
167 430
		if (mapContext != null) {
......
185 448
	}
186 449

  
187 450
	/**
188
	 * Devuelve la proyecci?n.
451
	 * <p>Gets this component's {@link MapContext MapContext} projection.</p>
189 452
	 *
190
	 * @return Proyecci?n.
453
	 * @return this component's {@link MapContext MapContext} projection
454
	 * 
455
	 * @see MapContext#getProjection()
456
	 * @see MapControl#setProjection(IProjection)
191 457
	 */
192 458
	public IProjection getProjection() {
193 459
		return getMapContext().getProjection();
194 460
	}
195 461

  
196 462
	/**
197
	 * Inserta una proyecci?n.
463
	 * <p>Sets the projection to this component's {@link MapContext MapContext}.</p>
198 464
	 *
199
	 * @param proj Proyecci?n.
465
	 * @param proj the kind of projection to this component's {@link MapContext MapContext}
466
	 * 
467
	 * @see MapContext#setProjection(IProjection)
468
	 * @see MapControl#getProjection()
200 469
	 */
201 470
	public void setProjection(IProjection proj) {
202 471
		getMapContext().setProjection(proj);
203 472
	}
204 473

  
205 474
	/**
206
	 * Devuelve el modelo.
207
	 *
208
	 * @return FMap.
475
	 * <p>Gets this component's <code>MapContext</code>, with the <i>model</i>, and most of the <i>view</i>,
476
	 * and <i>control</i> logic of the layers of this component, including a {@link ViewPort ViewPort} to adapt the
477
	 * information to the projection, and display it in the available area.</p>
478
	 * 
479
	 * @return this component's <code>MapContext</code>, that includes the <code>ViewPort</code> used to project the
480
	 * graphical information, and display it in the available area
481
	 * 
482
	 * @see MapContext
483
	 * 
484
	 * @see MapControl#setMapContext(MapContext)
209 485
	 */
210 486
	public MapContext getMapContext() {
211 487
		return mapContext;
212 488
	}
213 489

  
214 490
	/**
215
	 * Registra una herramienta (tool).
491
	 * <p>Registers a new behavior to this component.</p>
492
	 * 
493
	 * <p>According the nature of the {@link Behavior Behavior}, different events will be generated. Those
494
	 *  events can be caught by a particular {@link ToolListener ToolListener}, allowing user to interact with this
495
	 *  <code>MapControl</code> object as a <i>tool</i>.</p>
216 496
	 *
217
	 * @param name Nombre de la herramienta.
218
	 * @param tool Herramienta.
497
	 * @param name name to identify the behavior to add
498
	 * @param tool the behavior to add
499
	 * 
500
	 * @see #addMapTool(String, Behavior[])
501
	 * @see #getNamesMapTools()
502
	 * @see #getMapToolsKeySet()
503
	 * @see #hasTool(String)
219 504
	 */
220 505
	public void addMapTool(String name, Behavior tool) {
221 506
		namesMapTools.put(name, tool);
222 507
		tool.setMapControl(this);
223 508
	}
224 509

  
510
	/**
511
	 * <p>Registers a new behavior to this component as a {@link CompoundBehavior CompoundBehavior} made up of <code>tools</code>.</p>
512
	 * 
513
	 * <p>According the nature of the behaviors registered, different events will be generated. Those
514
	 *  events can be caught by a particular {@link ToolListener ToolListener}, allowing user to interact with this
515
	 *  <code>MapControl</code> object as a <i>tool</i>.</p>
516
	 *
517
	 * @param name name to identify the compound behavior to add
518
	 * @param tools the compound behavior to add
519
	 * 
520
	 * @see #addMapTool(String, Behavior)
521
	 * @see #getNamesMapTools()
522
	 * @see #getMapToolsKeySet()
523
	 * @see #hasTool(String)
524
	 */
225 525
	public void addMapTool(String name, Behavior[] tools){
226 526
		CompoundBehavior tool = new CompoundBehavior(tools);
227 527
		addMapTool(name, tool);
228 528
	}
229 529

  
230 530
	/**
231
	 * Devuelve una herramienta (tool) registrada.
531
	 * <p>Gets the <code>Behavior</code> registered in this component, identified
532
	 *  by <code>name</code>.</p>
232 533
	 *
233
	 * @param name Nombre de la herramienta.
234
	 * @return tool Herramienta.
534
	 * @param name name of a registered behavior
535
	 * 
536
	 * @return tool the registered behavior in this component as <code>name</code>, or <code>null</code> if
537
	 *  no one has that identifier
538
	 *  
539
	 * @see #addMapTool(String, Behavior)
540
	 * @see #addMapTool(String, Behavior[])
541
	 * @see #hasTool(String)
235 542
	 */
236 543
	public Behavior getMapTool(String name) {
237 544
		return (Behavior)namesMapTools.get(name);
238 545
	}
239 546

  
240 547
	/**
241
	 * Devuelve los nombres de herramientas (tool) registradas.
548
	 * <p>Returns a set view of the keys that identified the tools
549
	 *  registered.</p>
242 550
	 *
243
	 * @return Set (String) nombres de las herramientas.
551
	 * @return a set view of the keys that identified the tools registered
552
	 * 
553
	 * @see HashMap#keySet()
554
	 * 
555
	 * @see #getNamesMapTools()
556
 	 * @see #addMapTool(String, Behavior)
557
 	 * @see #addMapTool(String, Behavior[])
244 558
	 */
245 559
	public Set getMapToolsKeySet() {
246 560
		return namesMapTools.keySet();
247 561
	}
248 562

  
249

  
250 563
	/**
251
	 * Returns true if this map control contains a tool named with the value
252
	 * passed in the toolName parameter. If you have added two tools with the
253
	 * same name, the last tool will overwrite the previous ones.
254
	 * @param toolName
255
	 * @return true if the map control contains a tool with the same name than
256
	 * 		toolName. False, otherwise.
564
	 * <p>Returns <code>true</code> if this component contains a tool identified by <code>toolName</code>.</p>
565
	 * 
566
	 * @param toolName identifier of the tool
567
	 * 
568
	 * @return <code>true</code> if this component contains a tool identified by <code>toolName</code>; otherwise <code>false</code>
569
	 * 
570
	 * @see #addMapTool(String, Behavior)
571
	 * @see #addMapTool(String, Behavior[])
257 572
	 */
258 573
	public boolean hasTool(String toolName) {
259 574
		return namesMapTools.containsKey(toolName);
260 575
	}
576

  
261 577
	/**
262
	 * DOCUMENT ME!
263
	 *
264
	 * @param toolName DOCUMENT ME!
578
	 * <p>Sets as current active <code>Behavior</code> associated to this component, that one which
579
	 *  is registered and identified by <code>toolName</code>.</p>
580
	 * 
581
	 * <p>Changing the current active behavior for this <code>MapControl</code>, implies also updating the
582
	 *  previous <i>behavior</i> tool, and the current cursor.</p>
583
	 * 
584
	 * @param toolName name of a registered behavior
585
	 * 
586
	 * @see #getCurrentMapTool()
587
	 * @see #getCurrentTool()
265 588
	 */
266 589
	public void setTool(String toolName) {
267 590
		prevTool=getCurrentTool();
......
270 593
		currentTool = toolName;
271 594
		this.setCursor(mapTool.getCursor());
272 595
	}
596

  
597
	/**
598
	 * <p>Gets as current active <code>Behavior</code> associated to this component, that one which
599
	 *  is registered and identified by <code>toolName</code>.</p>
600
	 * 
601
	 * <p>Changing the current active behavior for this <code>MapControl</code>, implies also updating the
602
	 *  previous <i>behavior</i> tool, and the current cursor.</p>
603
	 * 
604
	 * @param toolName name of a registered behavior
605
	 * 
606
	 * @see #getCurrentTool()
607
	 * @see #setTool(String)
608
	 */
273 609
	public Behavior getCurrentMapTool(){
274 610
		return currentMapTool;
275 611
	}
612

  
276 613
	/**
277
	 * Returns the name of the current selected tool on this MapControl
614
	 * <p>Returns the name of the current selected tool on this MapControl</p>
278 615
	 *
279
	 * @return A tool name.
616
	 * @return the name of the current's behavior tool associated to this component
617
	 * 
618
	 * @see #getCurrentMapTool()
619
	 * @see #setTool(String)
280 620
	 */
281 621
	public String getCurrentTool() {
282 622
		return currentTool;
283 623
	}
284 624

  
285

  
286 625
	/**
287
	 * Cancela el dibujado. Se espera a que la cancelaci?n surta efecto
626
	 * <p>Determines that current drawing process of <code>MapControl</code>'s <code>MapContext</code>'s data must be canceled.</p>
627
	 * 
628
	 * <p>It has no effects if now isn't drawing that graphical information.</p>
629
	 *  
630
	 * <p>At last resort, the particular implementation of each layer in this <code>MapControl</code>'s <code>MapContrext</code>
631
     *   will be that one which will draw the graphical information, and, if supports, which could cancel its drawing subprocess.</p>
288 632
	 */
289 633
	public void cancelDrawing() {
290 634
		/* if (drawer != null) {
......
309 653
        drawerAlive = false; */
310 654
	}
311 655

  
656
	/**
657
	 * <p>Creates a {@link BufferedImage BufferedImage} image if there was no buffered image, or if
658
	 *  its viewport's image height or width is different from this component's size. Once has created
659
	 *  a double-buffer, fills it with the vieport's background color, or with <i>white</i> if it had no background color.</p>
660
	 * 
661
	 * <p>If no double-buffered existed, creates a {@link BufferedImage BufferedImage} with the size of this component,
662
	 * and as an image with 8-bit RGBA color components packed into integer pixels. That image has a <code>DirectColorModel</code> with alpha.
663
	 * The color data in that image is considered not to be premultiplied with alpha.</p> 
664
	 * 
665
	 * <p>Once has created and filled the new inner <code>MapControl</code>'s double-buffer, changes the status to
666
	 * <code>OUTDATED</code>.</p>
667
	 * 
668
	 * @return <code>true</code> if has created and filled a new double-buffer for this <code>MapControl</code> instance; otherwise <code>false</code>
669
	 */
312 670
    private boolean adaptToImageSize()
313 671
    {
314 672
        if ((image == null) || (vp.getImageWidth() != this.getWidth()) || (vp.getImageHeight() != this.getHeight()))
......
339 697
        return false;
340 698
    }
341 699

  
342
	/*
343
	 * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
700
	/**
701
	 * <p>Paints the graphical information of this component using a double buffer.</p>
702
	 * 
703
	 * <p>If the double buffer wasn't created, creates a new one.</p>
704
	 * 
705
	 * <p>Paints the component according the following algorithm:
706
	 * <br>
707
	 *  &nbsp If <i>status</i> is <i>UPDATED</i>:<br>
708
	 *  &nbsp &nbsp If there is no <i>double buffer</i>:<br>
709
	 *  &nbsp &nbsp &nbsp If there is a <i>behavior</i> for managing the <code>MapControl</code> instance, delegates
710
	 *   the drawing process to that behavior, calling: <code><i>behavior_instance</i>.paintComponent(g)</code> &nbsp .<br>
711
	 *  &nbsp &nbsp &nbsp Else, repaints the current graphical information quickly calling: <code>g.drawImage(image,0,0,null)</code> &nbsp .<br>
712
	 *  &nbsp Else, (<i>status</i> is <i>OUTDATED</i>, or <i>ONLY_GRAPHICS</i>): executes a quickly repaint of the previous information calling <code>g.drawImage(image,0,0,null)</code>, and creates
713
	 *   a <i>painting request</i> to delegate the heavy drawing process to the {@link Drawer2 Drawer2}'s worker thread, according the <i>SingleWorketThread</i> pattern, starting a timer to update
714
	 *   (invoking <code>repaint()</code> that comprises invoke this method) the view every delay of 360 ms. during the the process drawing.</p>
715
	 * 
716
  	 * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
717
  	 * @see Drawer2
344 718
	 */
345 719
	protected void paintComponent(Graphics g) {
346 720
        adaptToImageSize();
......
425 799
	}
426 800

  
427 801
	/**
428
	 * Devuelve la imagen de la vista.
429
	 *
430
	 * @return imagen.
802
	 * <p>Gets the {@link BufferedImage BufferedImage} used to accelerate the draw of new ''frames'' with changes, 
803
	 * or new graphical items in this component.</p>
804
	 * 
805
	 * @return double buffered image used by this component to accelerate the draw of its graphical information, or
806
	 * <code>null</code> if isn't already created
807
	 * 
808
	 * @see BufferedImage 
431 809
	 */
432 810
	public BufferedImage getImage() {
433 811
		return image;
434 812
	}
435 813

  
436 814
	/**
437
	 * Marca el mapa para que en el pr?ximo redibujado se acceda a la
438
	 * cartograf?a para reobtener la imagen
439
	 * @param doClear Solo deber?a ser true cuando se llama desde pan
815
	 * <p>Forces repaint all visible graphical information in this component.</p>
816
	 * 
817
	 * <p>If <code>doClear == true</code>, before repainting, clears all graphics before repainting.</p>
818
	 *
819
	 * @param doClear <code>true</code> if needs clearing graphics drawn on the map
820
	 * 
821
	 * @see #cancelDrawing()
822
	 * @see FLayers#setDirty(boolean)
440 823
	 */
441 824
	public void drawMap(boolean doClear) {
442 825
		cancelDrawing();
......
445 828
        getMapContext().getLayers().setDirty(true);
446 829
		if (doClear)
447 830
        {
448
            // image = null; // Se usa para el PAN
831
//            // image = null; // Se usa para el PAN
449 832
            if (image != null)
450 833
            {
451 834
                Graphics2D g = image.createGraphics();
452
                Color theBackColor = vp.getBackColor();
453
                if (theBackColor == null)
454
                    g.setColor(Color.WHITE);
455
                else
456
                    g.setColor(theBackColor);
457
                g.fillRect(0, 0, vp.getImageWidth(), vp.getImageHeight());
835
                g.setColor(Color.BLACK);
836
////                Color theBackColor = vp.getBackColor();
837
////                if (theBackColor == null)
838
////                    g.setColor(Color.WHITE);
839
////                else
840
////                    g.setColor(theBackColor);
841
//                g.fillRect(0, 0, vp.getImageWidth(), vp.getImageHeight());
458 842
                g.dispose();
459 843
            }
460 844
        }
461 845
		repaint();
462 846
	}
463 847

  
848
	/**
849
	 * <p>Cancels any current drawing process, changing the status to <code>OUTDATED</code>, and forcing
850
	 * repaint only the layers dirty.</p>
851
	 * 
852
	 * @see #cancelDrawing()
853
	 */
464 854
	public void rePaintDirtyLayers()
465 855
	{
466 856
		cancelDrawing();
......
468 858
        repaint();
469 859
	}
470 860

  
861
	/**
862
	 * <p>Cancels any current drawing process, changing the status to <code>ONLY_GRAPHICS</code>, and forcing
863
	 * repaint only the graphical layer of the <code>MapContext</code>.</p>
864
	 */
471 865
    public void drawGraphics() {
472 866
        status = ONLY_GRAPHICS;
473 867
        repaint();
......
508 902
	}
509 903

  
510 904
	/**
511
	 * A?ade un listener de tipo ExceptionListener.
512
	 *
513
	 * @param o ExceptionListener.
905
	 * @see ExceptionHandlingSupport#addExceptionListener(ExceptionListener)
514 906
	 */
515 907
	public void addExceptionListener(ExceptionListener o) {
516 908
		exceptionHandlingSupport.addExceptionListener(o);
517 909
	}
518 910

  
519 911
	/**
520
	 * Borra la ExceptioListener que se pasa como par?metro.
521
	 *
522
	 * @param o ExceptionListener.
523
	 *
524
	 * @return True si se borra correctamente.
912
	 * @see ExceptionHandlingSupport#removeExceptionListener(ExceptionListener)
525 913
	 */
526 914
	public boolean removeExceptionListener(ExceptionListener o) {
527 915
		return exceptionHandlingSupport.removeExceptionListener(o);
528 916
	}
529 917

  
530 918
	/**
531
	 * Lanza una Excepci?n.
532
	 *
533
	 * @param t Excepci?n.
919
	 * @see ExceptionHandlingSupport#throwException(Throwable)
534 920
	 */
535 921
	protected void throwException(Throwable t) {
536 922
		exceptionHandlingSupport.throwException(t);
537 923
	}
538 924

  
539

  
925
	/**
926
	 * <p>Represents each <code>MapControl</code>'s data painting request.</p>
927
	 * 
928
	 * <p>The request will be attended by a <code>Drawer2</code>, which will hold it since the <code>Drawer2</code>'s worker
929
	 *  takes it, or arrives a new painting request, which will replace it.</p> 
930
	 */
540 931
    private class PaintingRequest
541 932
    {
542

  
933
    	/**
934
    	 * <p>Creates a new <code>PaintingRequest</p> instance.</p>
935
    	 */
543 936
        public PaintingRequest()
544 937
        {
545 938
        }
546 939

  
940
        /**
941
         * <p><code>MapControl</code> paint process:</p>
942
         * 
943
         * <p>
944
         *  <ul>
945
         *   <li><i>1.- </i>Cancels all previous <code>MapControl</code>'s drawing processes.</li>
946
         *   <li><i>2.- </i>If <i>status</i> was OUTDATED:
947
         *    <ul>
948
         *     <li><i>2.1.- </i>Fills the background color with viewport's background color, or <i>white</i> if it was undefined.</li>
949
         *     <li><i>2.2.- </i>Notifies <i>MapContext</i> to be drawn invoking: <code>mapContext.draw(double-buffer, double-buffer's buffer, shared cancel-draw object, mapContext.getScaleView());</code>.</li>
950
         *     <li><i>2.3.- </i>If <code>canceldraw.isCanceled()</code>
951
         *      <ul>
952
         *       <li><i>2.3.1.- </i>Sets <i>status</i> to OUTDATED.</li>
953
         *       <li><i>2.3.2.- </i>Sets <i>dirty</i> all layers stored in <i>MapContext</i>.</li>
954
         *      </ul>
955
         *     </li>
956
         *     <li><i>2.4.- </i>Else, sets <i>status</i> to UPDATED.</li>
957
         *    </ul>
958
         *   </li>
959
         *   <li><i>3.- </i>Else, if <i>status</i> was ONLY_GRAPHICS:
960
         *    <ul>
961
         *     <li><i>3.1.- </i>Sets <i>status</i> to UPDATED.</li>
962
         *     <li><i>3.2.- </i>Notifies <i>MapContext</i> to be drawn invoking: <code>mapContext.drawGraphics(double-buffer, double-buffer's buffer, shared cancel-draw object, mapContext.getScaleView());</code>.</li>
963
         *    </ul>
964
         *   </li>
965
         *   <li><i>4.- </i>Stops the <i>timer</i>.</li>
966
         *   <li><i>5.- </i>Repaints this component invoking: <code>repaint();</code></li>
967
         *  </ul>
968
         * </p>
969
         * 
970
         * @see #cancelDrawing()
971
         * @see MapContext#draw(BufferedImage, Graphics2D, Cancellable, double)
972
         * @see MapContext#drawGraphics(BufferedImage, Graphics2D, Cancellable, double)
973
         * 
974
         * @see ViewPort
975
         */
547 976
        public void paint()
548 977
        {
549 978
            try
......
617 1046
                throwException(e);
618 1047
            } finally {
619 1048
            }
620

  
621 1049
        }
1050
    }
622 1051

  
623
    }
624
   /**
1052
    /**
1053
     * <p>An instance of <code>Drawer2</code> could manage all <code>MapControl</code> painting requests.</p>
1054
     * 
1055
     * <p>Based on the <i>WorkerThread</i> software pattern, creates a worker thread that will attend sequentially
1056
     *  the current waiting painting request, after finishing the previous (that could be by a cancel action).</p>
1057
     * 
1058
     * <p>All new {@link PaintingRequest PaintingRequest} generated will be stored as <i>waiting requests</i> since the worker
1059
     * attends it.</p>
1060
     * 
1061
     * <p>If a worker finished and there was no <i>painting request</i>, the worker would be set to wait until any
1062
     *  <i>painting request</i> would be put.</p>
1063
     * 
625 1064
     * @author fjp
626
     *
627
     * Basasdo en el patr?n WorkerThread
628
     *
629 1065
     */
630 1066
    public class Drawer2
631 1067
    {
632 1068
        // Una mini cola de 2. No acumulamos peticiones de dibujado
633 1069
        // dibujamos solo lo ?ltimo que nos han pedido.
634
        private PaintingRequest paintingRequest;
635
        private PaintingRequest waitingRequest;
1070
    	
636 1071

  
1072
    	/**
1073
    	 * <p>Painting request that's been attended by the <code>Drawer2</code>'s worker.</p>
1074
    	 * 
1075
    	 * @see #put(com.iver.cit.gvsig.fmap.MapControl.PaintingRequest)
1076
    	 * @see #take()
1077
    	 */
1078
    	private PaintingRequest paintingRequest;
1079

  
1080
    	/**
1081
    	 * <p>Painting request waiting to be attended by the <code>Drawer2</code>'s worker.</p>
1082
    	 * 
1083
    	 * @see #put(com.iver.cit.gvsig.fmap.MapControl.PaintingRequest)
1084
    	 * @see #take()
1085
    	 */
1086
    	private PaintingRequest waitingRequest;
1087

  
1088
    	/**
1089
    	 * <p>Determines that the <code>Drawer2</code>'s worker is busy attending a painting request.</p> 
1090
     	 * 
1091
    	 * @see #put(com.iver.cit.gvsig.fmap.MapControl.PaintingRequest)
1092
    	 * @see #take()
1093
    	 */
637 1094
        private boolean waiting;
1095

  
1096
    	/**
1097
    	 * <p>Notifies the <code>Drawer2</code>'s worker to finish or continue with its process.</p>
1098
    	 * 
1099
    	 * @see #setShutdown(boolean)
1100
    	 */
638 1101
        private boolean shutdown;
639 1102

  
1103
        /**
1104
         * <p>Sets this <code>Drawer2</code>'s worker to finish or continue with its process.</p>
1105
         * 
1106
         * @param isShutdown a boolean value
1107
         */
640 1108
        public void setShutdown(boolean isShutdown)
641 1109
        {
642 1110
            shutdown = isShutdown;
643 1111
        }
644 1112

  
1113
        /**
1114
         * <p>Creates a new drawer for managing all data painting requests in <code>MapControl</code>.</p>
1115
         * 
1116
         * <p>Includes the following steps:
1117
         *  <ul>
1118
         *   <li>By default, there is no <i>current painting request</i>.</li>
1119
         *   <li>By default, there is no <i>waiting painting request</i>.</li>
1120
         *   <li>By default, the worker thread is waiting no <i>painting request</i>.</li>
1121
         *   <li>By default, the worker thread is running.</li>
1122
         *   <li>Creates and starts a worker thread for attending the <i>painting requests</i>.</li>
1123
         *  </ul>
1124
         * </p>
1125
         */
645 1126
        public Drawer2()
646 1127
        {
647 1128
            paintingRequest = null;
......
651 1132
            new Thread(new Worker()).start();
652 1133
        }
653 1134

  
1135
        /**
1136
         * <p>Sets a <code>PaintingRequest</code> to be attended by the worker thread of this object. If 
1137
         *  this one was waiting, wakes up.</p>
1138
         * 
1139
         * <p>All waiting threads will be notified synchronized.</p>
1140
         * 
1141
         * @param newPaintRequest
1142
         * 
1143
         * @see #take()
1144
         */
654 1145
        public void put(PaintingRequest newPaintRequest)
655 1146
        {
656 1147
            waitingRequest = newPaintRequest;
......
662 1153
            }
663 1154
        }
664 1155

  
1156
        /**
1157
         * <p>Used by this object's worker, returns the current waiting drawing request, causing current thread
1158
         *  to wait until another thread invokes {@link #put(com.iver.cit.gvsig.fmap.MapControl.PaintingRequest) #put(com.iver.cit.gvsig.fmap.MapControl.PaintingRequest)},
1159
         *  if there was no waiting request.</p>
1160
         * 
1161
         * <p>All threads will access synchronized to the waiting request.</p>
1162
         * 
1163
         * @return <code>PaintingRequest</code> that was waiting to be attended
1164
         * 
1165
         * @see #put(com.iver.cit.gvsig.fmap.MapControl.PaintingRequest)
1166
         */
665 1167
        public PaintingRequest take()
666 1168
        {
667 1169
            if (waitingRequest == null)
......
682 1184
            return paintingRequest;
683 1185
        }
684 1186

  
685

  
1187
        /**
1188
         * <p>Thread for attending painting requests.</p>
1189
         * 
1190
         * <p>If there was no double buffer, sets the status to <code>OUTDATED</code> and finishes, otherwise
1191
         *  takes the painting request (it's probably that would wait some time), cancel the previous drawing
1192
         *  process, and starts processing the request.</p>
1193
         * 
1194
         * @see Thread
1195
         */
686 1196
        private class Worker implements Runnable
687 1197
        {
688
            public void run()
1198
        	/*
1199
        	 * (non-Javadoc)
1200
        	 * @see java.lang.Runnable#run()
1201
        	 */
1202
        	public void run()
689 1203
            {
690 1204
                while (!shutdown)
691 1205
                {
......
703 1217
    }
704 1218

  
705 1219
	/**
706
	 * Clase utilizada para dibujar las capas.
1220
	 * <p><code>Drawer</code> is implemented for drawing the layers of a <code>MapControl</code>'s <i>MapContext</i> instance
1221
	 *  as a <i>thread</i> of execution.</p>
1222
	 *  
1223
	 * <p>Draws <code>MapControl</code> according its <i>status</i>:
1224
	 *  <ul>
1225
	 *   <li><code><i>ONLY_GRAPHICS</i></code>: refreshes only the graphical layer, changing the status to <code><i>UPDATED</i></code>, via
1226
	 *    {@linkplain MapContext#drawGraphics(BufferedImage, Graphics2D, Cancellable, double) MapContext#drawGraphics(BufferedImage, Graphics2D, Cancellable, double)}.</li>
1227
	 *   <li><code><i>OUTDATED</i></code>: refreshes all layers, changing the status to <code><i>UPDATED</i></code>, via
1228
	 *    {@linkplain MapContext#draw(BufferedImage, Graphics2D, Cancellable, double) MapContext#draw(BufferedImage, Graphics2D, Cancellable, double)}.</li>
1229
	 *  <ul>
1230
	 * </p>
1231
	 * 
1232
	 * <p>This drawing process is accelerated by a <code>BufferedImage</code>, and can be canceled.</p>
1233
	 * 
1234
	 * <p>Once the drawing process has finished, the timer stops and this component gets repainted.</p> 
707 1235
	 *
1236
	 * @deprecated
708 1237
	 * @author Vicente Caballero Navarro
709 1238
	 */
710 1239
	public class Drawer extends Thread {
711 1240
		//private Graphics g;
1241
		
1242
		/**
1243
		 * <p>Image with a buffer to accelerate the draw the changes of the graphical items in this component.</p>
1244
		 * 
1245
		 * <p>Firstly, information will be drawn in the buffer, and, when is outright drawn, that information will be displayed.
1246
		 * Meanwhile, the previous image can be kept showed.</p>
1247
		 * 
1248
		 * @see BufferedImage
1249
		 */
712 1250
		private BufferedImage image = null;
1251

  
1252
		/**
1253
		 * <p>Object to store the flag that notifies the drawing must be canceled or can continue with the process.</p>
1254
		 * 
1255
		 * <p>At last resort, the particular implementation of each layer in a <code>MapControl</code>'s <code>MapContrext</code>
1256
         *   will be which will draw the graphical information, and, if supports, which could cancel its drawing subprocess.</p>
1257
		 */
713 1258
		private CancelDraw cancel;
714 1259
		//private boolean threadCancel = false;
715 1260

  
716 1261
		/**
717
		 * Crea un nuevo Drawer.
718
		 *
1262
		 * <p>Creates a new <code>Drawer</code> instance.</p>
719 1263
		 */
720 1264
		public Drawer(BufferedImage image, CancelDraw cancel)
721 1265
        {
......
726 1270

  
727 1271
		/**
728 1272
		 * @see java.lang.Runnable#run()
1273
		 * @see MapContext#draw(BufferedImage, Graphics2D, Cancellable, double)
1274
		 * @see MapContext#drawGraphics(BufferedImage, Graphics2D, Cancellable, double)
729 1275
		 */
730 1276
		public void run() {
731 1277
			try {
......
769 1315
	}
770 1316

  
771 1317
	/**
772
	 * Clase para cancelar el dibujado.
1318
	 * <p>An instance of <code>CancelDraw</code> will be shared by all this <code>MapControl</code>'s <code>MapContext</code> layers,
1319
	 *  allowing receive a notification that, when they're been drawn, to be cancelled.</p>
773 1320
	 *
1321
	 * @see Cancellable
1322
	 *
774 1323
	 * @author Fernando Gonz?lez Cort?s
775 1324
	 */
776 1325
	public class CancelDraw implements Cancellable {
1326
		/**
1327
		 * <p>Determines if the drawing task must be canceled or not.</p>
1328
		 * 
1329
		 * @see #isCanceled()
1330
		 * @see #setCanceled(boolean)
1331
		 */
777 1332
		private boolean cancel = false;
778 1333

  
779 1334
		/**
780
		 * Crea un nuevo CancelDraw.
1335
		 * Creates a new <code>CancelDraw</code> object.
781 1336
		 */
782 1337
		public CancelDraw() {
783 1338
		}
784 1339

  
785
		/**
786
		 * Insertar si se debe cancelar el dibujado.
787
		 *
788
		 * @param b true si se debe cancelar el dibujado.
1340
		/*
1341
		 * (non-Javadoc)
1342
		 * @see com.iver.utiles.swing.threads.Cancellable#setCanceled(boolean)
789 1343
		 */
790 1344
		public void setCanceled(boolean b) {
791 1345
			cancel = b;
792 1346
		}
793 1347

  
794
		/**
1348
		/*
1349
		 * (non-Javadoc)
795 1350
		 * @see com.iver.utiles.swing.threads.Cancellable#isCanceled()
796 1351
		 */
797 1352
		public boolean isCanceled() {
......
799 1354
		}
800 1355
	}
801 1356

  
802

  
803 1357
	/**
804
	 * Listener del MapTool.
1358
	 * <p>Listens all kind of mouse events produced in {@link MapControl MapControl}, and invokes its current
1359
	 *  map tool <i>({@link MapControl#getCurrentMapTool() MapControl#getCurrentMapTool()}</i> to simulate a behavior.</p>
1360
	 *  
1361
	 * <p>Mouse wheel moved events produce a <i>zoom in</i> operation if wheel rotation is negative, or a <i>zoom out</i>
1362
	 *  if its positive. Both will be centered in the position of the mouse, but, meanwhile <i>zoom in</i> operation
1363
	 *  applies a factor of 0.9, <i>zoom out</i> operation applies a factor of 1.2</p>
1364
	 *  
1365
	 * <p>Mouse wheel moved events can be produced as much frequently, that between each one, the drawing process could
1366
	 *  hadn't finished. This is the reason that, in this situation, cancels always the previous drawing process before
1367
	 *  applying a <i>zoom</i> operation, and ignores all new mouse positions that are produced before 1 second.</p>
805 1368
	 *
806 1369
	 * @author Fernando Gonz?lez Cort?s
807 1370
	 */
808 1371
	public class MapToolListener implements MouseListener, MouseWheelListener,
809 1372
		MouseMotionListener {
810 1373

  
1374
		/**
1375
		 * <p>Used to avoid mouse wheel move events closed.</p>
1376
		 * 
1377
		 * <p>If a mouse wheel move event is produced 
1378
		 */
811 1379
		long t1;
1380

  
1381
		/**
1382
		 * <p>Position of the mouse, in map coordinates.</p>
1383
		 * 
1384
		 * <p>This point coordinates will be used as center of the <i>zoom</i> operation.</p>
1385
		 */
812 1386
		Point2D pReal;
1387

  
813 1388
		/**
814 1389
		 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
1390
		 * @see Behavior#mouseClicked(MouseEvent)
815 1391
		 */
816 1392
		public void mouseClicked(MouseEvent e) {
817 1393
			try {
......
824 1400

  
825 1401
		/**
826 1402
		 * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
1403
		 * @see Behavior#mouseEntered(MouseEvent)
827 1404
		 */
828 1405
		public void mouseEntered(MouseEvent e) {
829 1406
			try {
......
836 1413

  
837 1414
		/**
838 1415
		 * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
1416
		 * @see Behavior#mouseExited(MouseEvent)
839 1417
		 */
840 1418
		public void mouseExited(MouseEvent e) {
841 1419
			try {
......
848 1426

  
849 1427
		/**
850 1428
		 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
1429
		 * @see Behavior#mousePressed(MouseEvent)
851 1430
		 */
852 1431
		public void mousePressed(MouseEvent e) {
853 1432
			try {
......
860 1439

  
861 1440
		/**
862 1441
		 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
1442
		 * @see Behavior#mouseReleased(MouseEvent)
863 1443
		 */
864 1444
		public void mouseReleased(MouseEvent e) {
865 1445
			try {
......
872 1452

  
873 1453
		/**
874 1454
		 * @see java.awt.event.MouseWheelListener#mouseWheelMoved(java.awt.event.MouseWheelEvent)
1455
		 * @see Behavior#mouseWheelMoved(MouseWheelEvent)
875 1456
		 */
876 1457
		public void mouseWheelMoved(MouseWheelEvent e) {
877 1458
			try {
......
939 1520

  
940 1521
		/**
941 1522
		 * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
1523
		 * @see Behavior#mouseDragged(MouseEvent)
942 1524
		 */
943 1525
		public void mouseDragged(MouseEvent e) {
944 1526
			try {
......
951 1533

  
952 1534
		/**
953 1535
		 * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
1536
		 * @see Behavior#mouseMoved(MouseEvent)
954 1537
		 */
955 1538
		public void mouseMoved(MouseEvent e) {
956 1539
			try {
......
963 1546
	}
964 1547

  
965 1548
	/**
966
	 * Listener sobre el MapContext.
1549
	 * <p<code>MapContextListener</code> listens all events produced in a <code>MapControl</code>'s <code>MapContext</code>
1550
	 * object during an atomic period of time, and sets it to dirty, <i>executing <code>drawMap(false)</code>, if any of the
1551
	 * following conditions is accomplished</i>:
1552
	 * <ul>
1553
	 *  <li>Any of the <code>LayerEvent</code> in the <code>AtomicEvent</code> parameter notifies a <i>visibility change</i>.</li>
1554
	 *  <li>There is at least one <code>ColorEvent</code> in the <code>AtomicEvent</code> parameter.</li>
1555
	 *  <li>There is at least one <code>ExtentEvent</code> in the <code>AtomicEvent</code> parameter.</li>
1556
	 *  <li>Any of the <code>LayerCollectionEvent</code> in the <code>AtomicEvent</code> parameter notifies that a driver's layer has reloaded it successfully.</li>
1557
	 *  <li>There is at least one <code>LegendEvent</code> in the <code>AtomicEvent</code> parameter.</li>
1558
	 *  <li>There is at least one <code>SelectionEvent</code> in the <code>AtomicEvent</code> parameter.</li>
1559
	 * </ul>
1560
	 * </p>
967 1561
	 *
968 1562
	 * @author Fernando Gonz?lez Cort?s
969 1563
	 */
......
1021 1615
			}
1022 1616
		}
1023 1617
	}
1618

  
1619
	/**
1620
	 * <p>Gets the <code>ViewPort</code> of this component's {@link MapContext MapContext} .</p>
1621
	 * 
1622
	 * @see MapContext#getViewPort()
1623
	 */
1024 1624
	public ViewPort getViewPort() {
1025 1625
		return vp;
1026 1626
	}
1027 1627

  
1028 1628
	/**
1029
	 * Returns a HashMap with the tools that have been registered
1030
	 * in the Mapcontrol.
1629
	 * <p>Returns all registered <code>Behavior</code> that can define a way to work with this <code>MapControl</code>.</p>
1630
	 * 
1631
	 * @return registered <code>Behavior</code> to this <code>MapControl</code>
1632
	 * 
1633
	 * @see #addMapTool(String, Behavior)
1634
	 * @see #addMapTool(String, Behavior[])
1635
	 * @see #getMapToolsKeySet()
1636
	 * @see #hasTool(String)
1031 1637
	 */
1032 1638
	public HashMap getNamesMapTools() {
1033 1639
		return namesMapTools;
1034 1640
	}
1035 1641

  
1642
	/*
1643
	 * (non-Javadoc)
1644
	 * @see com.iver.cit.gvsig.fmap.edition.commands.CommandListener#commandRepaint()
1645
	 */
1036 1646
	public void commandRepaint() {
1037 1647
		drawMap(false);
1038 1648
	}
1039 1649

  
1650
	/*
1651
	 * (non-Javadoc)
1652
	 * @see com.iver.cit.gvsig.fmap.edition.commands.CommandListener#commandRefresh()
1653
	 */
1040 1654
	public void commandRefresh() {
1041 1655
		// TODO Auto-generated method stub
1042 1656
	}
1043 1657

  
1658
	/**
1659
	 * <p>Equivalent operation to <i>undo</i>.</p>
1660
	 * 
1661
	 * <p>Exchanges the previous tool with the current one.</p>
1662
	 * 
1663
	 * @see #addMapTool(String, Behavior)
1664
	 * @see #addMapTool(String, Behavior[])
1665
	 * @see #setTool(String)
1666
	 */
1044 1667
	public void setPrevTool() {
1045 1668
		setTool(prevTool);
1046 1669
	}
1047 1670

  
1671
	/**
1672
	 * <p>Executes a <i>zoom in</i> operation centered at the center of the extent.</p>
1673
	 * 
1674
	 * <p>This implementation is designed for being invoked outside a <code>Behavior</code>, for example
1675
	 *  by an action of pressing a button; and simulates that the event has been produced by 
1676
	 *  releasing the <i>button 1</i> of the mouse using the registered <code>Behavior</code> in this
1677
	 *  <code>MapControl</code> object that's responsible for the <i>zoom in</i> operation.</p>
1678
	 *  
1679
	 * @see #zoomOut()
1680
	 */
1048 1681
	public void zoomIn() {
1049 1682
		getMapContext().clearAllCachingImageDrawnLayers();
1050 1683
		Behavior mapTool = (Behavior) namesMapTools.get("zoomIn");
......
1059 1692
			throwException(t);
1060 1693
		}
1061 1694
	}
1695
	
1696
	/**
1697
	 * <p>Executes a <i>zoom out</i> operation centered at the center of the extent.</p>
1698
	 * 
1699
	 * <p>This implementation is thought for being invoked outside a <code>Behavior</code>, for example
1700
	 *  by an action of pressing a button, and simulates that the event has been produced by 
1701
	 *  releasing the <i>button 1</i> of the mouse using the registered <code>Behavior</code> in this
1702
	 *  <code>MapControl</code> object that's responsible for the <i>zoom out</i> operation.</p>
1703
	 * 
1704
	 * @see #zoomIn()
1705
	 */
1062 1706
	public void zoomOut() {
1063 1707
		getMapContext().clearAllCachingImageDrawnLayers();
1064 1708
		Behavior mapTool = (Behavior) namesMapTools.get("zoomOut");
......
1073 1717
			throwException(t);
1074 1718
		}
1075 1719
	}
1720

  
1721
	/**
1722
	 * <p>Returns the listener used to catch all mouse events produced in this <code>MapControl</code> instance
1723
	 *  and that redirects the calls to the current map tool.</p> 
1724
	 * 
1725
	 * @return the map tool listener used
1726
	 */
1076 1727
	public MapToolListener getMapToolListener() {
1077 1728
		return mapToolListener;
1078 1729
	}
1730

  
1079 1731
//	 mapTool can be null, for instance, in 3D's navigation tools
1732
	/**
1733
	 * <p>Sets <code>mapTool</code> as this <code>MapControl</code>'s current map tool.
1734
	 * 
1735
	 * @param mapTool a map tool, or <code>null</code> to disable the interaction with the user
1736
	 * 
1737
	 * @see #getCurrentMapTool()
1738
	 * @see #getCurrentTool()
1739
	 * @see #setTool(String)
1740
	 * @see #setPrevTool()
1741
	 * @see #addMapTool(String, Behavior)
1742
	 * @see #addMapTool(String, Behavior[])
1743
	 */
1080 1744
	public void setCurrentMapTool(Behavior mapTool ){
1081 1745
		currentMapTool = mapTool;
1082 1746
	}
1083 1747

  
1748
	/**
1749
	 * <p>Sets the delay to the timer that refreshes this <code>MapControl</code> instance.</p>
1750
	 * 
1751
	 * <p><code>Delay (in ms) = 1000 / getDrawFrameRate()</code></p>
1752
	 * 
1753
	 * @see #getDrawFrameRate()
1754
	 * @see #setDrawFrameRate(int)
1755
	 */
1084 1756
	public void applyFrameRate() {
1085 1757
		if (getDrawFrameRate()>0) {
1086 1758
			timer.setDelay(1000/getDrawFrameRate());
1087 1759
		}
1088 1760
	}
1089 1761

  
1762
	/**
1763
	 * <p>Returns the draw frame rate.</p>
1764
	 * 
1765
	 * <p>Draw frame rate is the number of repaints of this <code>MapControl</code> instance that timer invokes per second.</p>
1766
	 * 
1767
	 * @return number of repaints of this <code>MapControl</code> instance that timer invokes per second
1768
	 * 
1769
	 * @see #applyFrameRate()
1770
	 * @see #setDrawFrameRate(int)
1771
	 */
1090 1772
	public static int getDrawFrameRate() {
1091 1773
		return drawFrameRate;
1092 1774
	}
1093 1775

  
1776
	/**
1777
	 * <p>Sets the draw frame rate.</p>
1778
	 * 
1779
	 * <p>Draw frame rate is the number of repaints of this <code>MapControl</code> instance that timer invokes per second.</p>
1780
	 * 
1781
	 * @param drawFrameRate number of repaints of this <code>MapControl</code> instance that timer invokes per second
1782
	 * 
1783
	 * @see #applyFrameRate()
1784
	 * @see #getDrawFrameRate()
1785
	 */
1094 1786
	public static void setDrawFrameRate(int drawFrameRate) {
1095 1787
		MapControl.drawFrameRate = drawFrameRate;
1096 1788
	}
1097 1789

  
1790
	/**
1791
	 * <p>Determines if its enabled the repaint that invokes the timer according to {@link #getDrawFrameRate() #getDrawFrameRate()}.</p>
1792
	 * 
1793
	 * @return <code>true</code> if its enabled; otherwise <code>false</code>
1794
	 */
1098 1795
	public static boolean isDrawAnimationEnabled() {
1099 1796
		return drawAnimationEnabled;
1100 1797
	}
1101 1798

  
1799
	/**
1800
	 * <p>Sets if its enabled the repaint that invokes the timer according to {@link #getDrawFrameRate() #getDrawFrameRate()}.</p>
1801
	 * 
1802
	 * @param drawAnimationEnabled <code>true</code> to enable the mode; otherwise <code>false</code>
1803
	 */
1102 1804
	public static void setDrawAnimationEnabled(boolean drawAnimationEnabled) {
1103 1805
		MapControl.drawAnimationEnabled = drawAnimationEnabled;
1104 1806
	}
1807

  
1808
	/**
1809
	 * <p>Gets the shared object that determines if a drawing process must be cancelled or can continue.</p>
1810
	 * 
1811
	 * @return the shared object that determines if a drawing process must be cancelled or can continue
1812
	 */
1105 1813
	public CancelDraw getCanceldraw() {
1106 1814
		return canceldraw;
1107 1815
	}

Also available in: Unified diff