root / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / ui / zoom / tools / BaseViewTool.java @ 18530
History | View | Annotate | Download (3.6 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.georeferencing.ui.zoom.tools; |
20 |
|
21 |
import java.awt.Graphics; |
22 |
import java.util.ArrayList; |
23 |
|
24 |
import org.gvsig.georeferencing.ui.zoom.CanvasZone; |
25 |
|
26 |
/**
|
27 |
* Clase base de la que deben extender las herramientas para la vista del
|
28 |
* zoom.
|
29 |
*
|
30 |
* 17/01/2008
|
31 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
32 |
*/
|
33 |
public abstract class BaseViewTool implements ToolListener { |
34 |
|
35 |
protected ArrayList listeners = new ArrayList(); |
36 |
protected boolean active = false; |
37 |
protected CanvasZone canvas = null; |
38 |
|
39 |
private boolean sleepActive = false; |
40 |
private boolean sleep = false; |
41 |
|
42 |
/**
|
43 |
* Constructor. Asigna el canvas y el listener para la tool.
|
44 |
* @param canvas
|
45 |
* @param listener
|
46 |
*/
|
47 |
public BaseViewTool(CanvasZone canvas, ToolListener listener) {
|
48 |
this.canvas = canvas;
|
49 |
addToolListener(listener); |
50 |
} |
51 |
|
52 |
/**
|
53 |
* A?ade un listener para eventos de la tool
|
54 |
* @param listener
|
55 |
*/
|
56 |
public void addToolListener(ToolListener listener) { |
57 |
if(!listeners.contains(listener))
|
58 |
listeners.add(listener); |
59 |
} |
60 |
|
61 |
/**
|
62 |
* Informa de que la herramienta est? activa.
|
63 |
* @param ev
|
64 |
*/
|
65 |
public void onTool(ToolEvent ev) { |
66 |
for (int i = 0; i < listeners.size(); i++) { |
67 |
((ToolListener)listeners.get(i)).onTool(ev); |
68 |
} |
69 |
} |
70 |
|
71 |
/**
|
72 |
* Informa de que la herramienta est? activa.
|
73 |
* @param ev
|
74 |
*/
|
75 |
public void offTool(ToolEvent ev) { |
76 |
for (int i = 0; i < listeners.size(); i++) { |
77 |
((ToolListener)listeners.get(i)).offTool(ev); |
78 |
} |
79 |
} |
80 |
|
81 |
/**
|
82 |
* Evento de finalizaci?n de las acciones de la tool
|
83 |
* @param ev ToolEvent
|
84 |
*/
|
85 |
public void endAction(ToolEvent ev) { |
86 |
for (int i = 0; i < listeners.size(); i++) { |
87 |
((ToolListener)listeners.get(i)).endAction(ev); |
88 |
} |
89 |
} |
90 |
|
91 |
/**
|
92 |
* Consulta si est? activo el evento de pinchado y arrastrado de los puntos de
|
93 |
* control.
|
94 |
* @return
|
95 |
*/
|
96 |
public boolean isActive() { |
97 |
return active;
|
98 |
} |
99 |
|
100 |
/**
|
101 |
* Asigna el flag que activa y desactiva la herramienta
|
102 |
* @param active true para activarla y false para desactivarla
|
103 |
*/
|
104 |
public void setActive(boolean active) { |
105 |
this.active = active;
|
106 |
} |
107 |
|
108 |
/**
|
109 |
* Desactiva la herramienta temporalmente. Guarda el estado en el que estaba
|
110 |
* para restaurarlo cuando se invoque a awake
|
111 |
*/
|
112 |
public void sleep() { |
113 |
if(!sleep) {
|
114 |
sleepActive = active; |
115 |
active = false;
|
116 |
sleep = true;
|
117 |
} |
118 |
} |
119 |
|
120 |
/**
|
121 |
* Recupera el estado de activaci?n que ten?a antes de la ?ltima invocaci?n
|
122 |
* de sleep
|
123 |
*/
|
124 |
public void awake() { |
125 |
if(sleep) {
|
126 |
active = sleepActive; |
127 |
sleep = false;
|
128 |
} |
129 |
} |
130 |
|
131 |
/**
|
132 |
* Parte gr?fica de una tool. Una tool puede dibujar sobre una vista
|
133 |
* @param img BufferedImage
|
134 |
* @param ext Rectangle2D
|
135 |
*/
|
136 |
public abstract void draw(Graphics g); |
137 |
|
138 |
/**
|
139 |
* Obtiene el resultado de la aplicaci?n de la herramienta
|
140 |
* @return Object
|
141 |
*/
|
142 |
public abstract Object getResult(); |
143 |
} |