svn-gvsig-desktop / tags / v1_0_2_Build_912 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / tools / CompoundBehavior.java @ 11422
History | View | Annotate | Download (5.77 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.tools; |
42 |
|
43 |
import com.iver.cit.gvsig.fmap.MapControl; |
44 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
45 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
46 |
|
47 |
import java.awt.Cursor; |
48 |
import java.awt.Graphics; |
49 |
import java.awt.event.MouseEvent; |
50 |
import java.awt.event.MouseWheelEvent; |
51 |
|
52 |
import java.util.ArrayList; |
53 |
import java.util.Iterator; |
54 |
|
55 |
|
56 |
/**
|
57 |
* Behavior mediante el que se pueden combinar varios behaviors
|
58 |
* a la vez en un mismo MapControl
|
59 |
*
|
60 |
* @author Fernando Gonz?lez Cort?s
|
61 |
*/
|
62 |
public class CompoundBehavior extends Behavior { |
63 |
private ArrayList mapTools = new ArrayList(); |
64 |
private ArrayList draws = new ArrayList(); |
65 |
|
66 |
public CompoundBehavior(Behavior[] tools){ |
67 |
for (int i = 0; i < tools.length; i++) { |
68 |
mapTools.add(tools[i]); |
69 |
if (i == 0) |
70 |
draws.add(Boolean.TRUE);
|
71 |
else
|
72 |
draws.add(Boolean.FALSE);
|
73 |
} |
74 |
} |
75 |
|
76 |
public void addMapBehavior(Behavior mt, boolean draw){ |
77 |
mapTools.add(mt); |
78 |
draws.add(new Boolean(draw)); |
79 |
} |
80 |
|
81 |
/**
|
82 |
* DOCUMENT ME!
|
83 |
*
|
84 |
* @return DOCUMENT ME!
|
85 |
*/
|
86 |
public Cursor getCursor() { |
87 |
if (mapTools.size() > 0) { |
88 |
return ((Behavior) mapTools.get(0)).getCursor(); |
89 |
} else {
|
90 |
return null; |
91 |
} |
92 |
} |
93 |
|
94 |
/**
|
95 |
* DOCUMENT ME!
|
96 |
*
|
97 |
* @param e DOCUMENT ME!
|
98 |
*
|
99 |
* @throws BehaviorException DOCUMENT ME!
|
100 |
*/
|
101 |
public void mouseClicked(MouseEvent e) throws BehaviorException { |
102 |
for (Iterator iter = mapTools.iterator(); iter.hasNext();) { |
103 |
Behavior mapTool = (Behavior) iter.next(); |
104 |
|
105 |
mapTool.mouseClicked(e); |
106 |
} |
107 |
} |
108 |
|
109 |
/**
|
110 |
* DOCUMENT ME!
|
111 |
*
|
112 |
* @param e DOCUMENT ME!
|
113 |
*
|
114 |
* @throws BehaviorException DOCUMENT ME!
|
115 |
*/
|
116 |
public void mouseDragged(MouseEvent e) throws BehaviorException { |
117 |
for (Iterator iter = mapTools.iterator(); iter.hasNext();) { |
118 |
Behavior mapTool = (Behavior) iter.next(); |
119 |
|
120 |
mapTool.mouseDragged(e); |
121 |
} |
122 |
} |
123 |
|
124 |
/**
|
125 |
* DOCUMENT ME!
|
126 |
*
|
127 |
* @param e DOCUMENT ME!
|
128 |
*
|
129 |
* @throws BehaviorException DOCUMENT ME!
|
130 |
*/
|
131 |
public void mouseEntered(MouseEvent e) throws BehaviorException { |
132 |
for (Iterator iter = mapTools.iterator(); iter.hasNext();) { |
133 |
Behavior mapTool = (Behavior) iter.next(); |
134 |
|
135 |
mapTool.mouseEntered(e); |
136 |
} |
137 |
} |
138 |
|
139 |
/**
|
140 |
* DOCUMENT ME!
|
141 |
*
|
142 |
* @param e DOCUMENT ME!
|
143 |
*
|
144 |
* @throws BehaviorException DOCUMENT ME!
|
145 |
*/
|
146 |
public void mouseExited(MouseEvent e) throws BehaviorException { |
147 |
for (Iterator iter = mapTools.iterator(); iter.hasNext();) { |
148 |
Behavior mapTool = (Behavior) iter.next(); |
149 |
|
150 |
mapTool.mouseExited(e); |
151 |
} |
152 |
} |
153 |
|
154 |
/**
|
155 |
* DOCUMENT ME!
|
156 |
*
|
157 |
* @param e DOCUMENT ME!
|
158 |
*
|
159 |
* @throws BehaviorException DOCUMENT ME!
|
160 |
*/
|
161 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
162 |
for (Iterator iter = mapTools.iterator(); iter.hasNext();) { |
163 |
Behavior mapTool = (Behavior) iter.next(); |
164 |
|
165 |
mapTool.mouseMoved(e); |
166 |
} |
167 |
} |
168 |
|
169 |
/**
|
170 |
* DOCUMENT ME!
|
171 |
*
|
172 |
* @param e DOCUMENT ME!
|
173 |
*
|
174 |
* @throws BehaviorException DOCUMENT ME!
|
175 |
*/
|
176 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
177 |
for (Iterator iter = mapTools.iterator(); iter.hasNext();) { |
178 |
Behavior mapTool = (Behavior) iter.next(); |
179 |
|
180 |
mapTool.mousePressed(e); |
181 |
} |
182 |
} |
183 |
|
184 |
/**
|
185 |
* DOCUMENT ME!
|
186 |
*
|
187 |
* @param e DOCUMENT ME!
|
188 |
*
|
189 |
* @throws BehaviorException DOCUMENT ME!
|
190 |
*/
|
191 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
192 |
for (Iterator iter = mapTools.iterator(); iter.hasNext();) { |
193 |
Behavior mapTool = (Behavior) iter.next(); |
194 |
|
195 |
mapTool.mouseReleased(e); |
196 |
} |
197 |
} |
198 |
|
199 |
/**
|
200 |
* DOCUMENT ME!
|
201 |
*
|
202 |
* @param e DOCUMENT ME!
|
203 |
*
|
204 |
* @throws BehaviorException DOCUMENT ME!
|
205 |
*/
|
206 |
public void mouseWheelMoved(MouseWheelEvent e) throws BehaviorException { |
207 |
for (Iterator iter = mapTools.iterator(); iter.hasNext();) { |
208 |
Behavior mapTool = (Behavior) iter.next(); |
209 |
|
210 |
mapTool.mouseWheelMoved(e); |
211 |
} |
212 |
} |
213 |
|
214 |
/**
|
215 |
* DOCUMENT ME!
|
216 |
*
|
217 |
* @param g DOCUMENT ME!
|
218 |
*/
|
219 |
public void paintComponent(Graphics g) { |
220 |
for (int i = 0; i < mapTools.size(); i++) { |
221 |
Behavior mapTool = (Behavior) mapTools.get(i); |
222 |
|
223 |
if (((Boolean) draws.get(i)).booleanValue()) |
224 |
mapTool.paintComponent(g); |
225 |
} |
226 |
} |
227 |
|
228 |
/**
|
229 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setListener(com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener)
|
230 |
*/
|
231 |
public void setListener(ToolListener listener) { |
232 |
if (listener != null) { |
233 |
throw new RuntimeException( |
234 |
"CompoundBehavior does not have listeners");
|
235 |
} |
236 |
} |
237 |
|
238 |
/**
|
239 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
|
240 |
*/
|
241 |
public ToolListener getListener() {
|
242 |
return null; |
243 |
} |
244 |
public void setMapControl(MapControl mc) { |
245 |
for (int i = 0; i < mapTools.size(); i++) { |
246 |
Behavior mapTool = (Behavior) mapTools.get(i); |
247 |
|
248 |
mapTool.setMapControl(mc); |
249 |
} |
250 |
|
251 |
super.setMapControl(mc);
|
252 |
} |
253 |
} |