Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / tools / CompoundBehavior.java @ 20100

History | View | Annotate | Download (7.03 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
 * <p>Allows having multiple behaviors when user works with the associated
58
 *  <code>MapControl</code>. Each one with its associated tool listener.</p>
59
 *
60
 * @author Fernando Gonz?lez Cort?s
61
 */
62
public class CompoundBehavior extends Behavior {
63
        /**
64
         * List of all behaviors that compound this one.
65
         */
66
        private ArrayList mapTools = new ArrayList();
67

    
68
        /**
69
         * List that determines which behaviors of this one will be real-time painted. 
70
         */
71
        private ArrayList draws = new ArrayList();
72

    
73
        /**
74
          * <p>Creates a new behavior as a composition of others.</p>
75
          *
76
         * @param tools atomic behaviors that will compound this one</code>
77
         */
78
        public CompoundBehavior(Behavior[] tools){
79
                for (int i = 0; i < tools.length; i++) {
80
                        mapTools.add(tools[i]);
81
                        if (i == 0)
82
                                draws.add(Boolean.TRUE);
83
                        else
84
                                draws.add(Boolean.FALSE);
85
                }
86
        }
87

    
88
        /**
89
         * <p>Adds a new behavior, setting if will be real-time (when user is working with it) drawn or not.</p>
90
         * 
91
         * <p>When user works with a compound behavior, he/she will see on real-time the graphical changes produced at
92
         *  the associated <code>MapControl</code>, only by those which have their associated <i>draw</i> flag to <code>true</code>.</p>
93
         * 
94
         * @param mt the new behavior
95
         * @param draw flag determining if will be real-time drawn or no
96
         */
97
        public void addMapBehavior(Behavior mt, boolean draw){
98
                mapTools.add(mt);
99
                draws.add(new Boolean(draw));
100
        }
101

    
102
        /*
103
         * (non-Javadoc)
104
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getCursor()
105
         */
106
        public Cursor getCursor() {
107
                if (mapTools.size() > 0) {
108
                        return ((Behavior) mapTools.get(0)).getCursor();
109
                } else {
110
                        return null;
111
                }
112
        }
113

    
114
        /*
115
         * (non-Javadoc)
116
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseClicked(java.awt.event.MouseEvent)
117
         */
118
        public void mouseClicked(MouseEvent e) throws BehaviorException {
119
                for (Iterator iter = mapTools.iterator(); iter.hasNext();) {
120
                        Behavior mapTool = (Behavior) iter.next();
121
                        
122
                        mapTool.mouseClicked(e);
123
                }
124
        }
125

    
126
        /*
127
         * (non-Javadoc)
128
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseDragged(java.awt.event.MouseEvent)
129
         */
130
        public void mouseDragged(MouseEvent e) throws BehaviorException {
131
                for (Iterator iter = mapTools.iterator(); iter.hasNext();) {
132
                        Behavior mapTool = (Behavior) iter.next();
133
                        
134
                        mapTool.mouseDragged(e);
135
                }
136
        }
137

    
138
        /*
139
         * (non-Javadoc)
140
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseEntered(java.awt.event.MouseEvent)
141
         */
142
        public void mouseEntered(MouseEvent e) throws BehaviorException {
143
                for (Iterator iter = mapTools.iterator(); iter.hasNext();) {
144
                        Behavior mapTool = (Behavior) iter.next();
145
                        
146
                        mapTool.mouseEntered(e);
147
                }
148
        }
149

    
150
        /*
151
         * (non-Javadoc)
152
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseExited(java.awt.event.MouseEvent)
153
         */
154
        public void mouseExited(MouseEvent e) throws BehaviorException {
155
                for (Iterator iter = mapTools.iterator(); iter.hasNext();) {
156
                        Behavior mapTool = (Behavior) iter.next();
157
                        
158
                        mapTool.mouseExited(e);
159
                }
160
        }
161
        
162
        /*
163
         * (non-Javadoc)
164
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseMoved(java.awt.event.MouseEvent)
165
         */
166
        public void mouseMoved(MouseEvent e) throws BehaviorException {
167
                for (Iterator iter = mapTools.iterator(); iter.hasNext();) {
168
                        Behavior mapTool = (Behavior) iter.next();
169
                        
170
                        mapTool.mouseMoved(e);
171
                }
172
        }
173

    
174
        /*
175
         * (non-Javadoc)
176
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mousePressed(java.awt.event.MouseEvent)
177
         */
178
        public void mousePressed(MouseEvent e) throws BehaviorException {
179
                for (Iterator iter = mapTools.iterator(); iter.hasNext();) {
180
                        Behavior mapTool = (Behavior) iter.next();
181
                        
182
                        mapTool.mousePressed(e);
183
                }
184
        }
185

    
186
        /*
187
         * (non-Javadoc)
188
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseReleased(java.awt.event.MouseEvent)
189
         */
190
        public void mouseReleased(MouseEvent e) throws BehaviorException {
191
                for (Iterator iter = mapTools.iterator(); iter.hasNext();) {
192
                        Behavior mapTool = (Behavior) iter.next();
193
                        
194
                        mapTool.mouseReleased(e);
195
                }
196
        }
197

    
198
        /*
199
         * (non-Javadoc)
200
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseWheelMoved(java.awt.event.MouseWheelEvent)
201
         */
202
        public void mouseWheelMoved(MouseWheelEvent e) throws BehaviorException {
203
                for (Iterator iter = mapTools.iterator(); iter.hasNext();) {
204
                        Behavior mapTool = (Behavior) iter.next();
205
                        
206
                        mapTool.mouseWheelMoved(e);
207
                }
208
        }
209

    
210
        /*
211
         * (non-Javadoc)
212
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
213
         */
214
        public void paintComponent(Graphics g) {
215
                for (int i = 0; i < mapTools.size(); i++) {
216
                        Behavior mapTool = (Behavior) mapTools.get(i);
217
                        
218
                        if (((Boolean) draws.get(i)).booleanValue())
219
                                mapTool.paintComponent(g);
220
                }
221
        }
222

    
223
        /**
224
         * Sets a tool listener to work with a <code>MapControl</code> instance using these behaviors.
225
         * 
226
         * @param listener a <code>RectangleListener</code> object for this behavior
227
         */
228
        public void setListener(ToolListener listener) {
229
                if (listener != null) {
230
                        throw new RuntimeException(
231
                                "CompoundBehavior does not have listeners");
232
                }
233
        }
234

    
235
        /*
236
         * (non-Javadoc)
237
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
238
         */
239
        public ToolListener getListener() {
240
                return null;
241
        }
242

    
243
        /*
244
         * (non-Javadoc)
245
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setMapControl(com.iver.cit.gvsig.fmap.MapControl)
246
         */
247
        public void setMapControl(MapControl mc) {
248
                for (int i = 0; i < mapTools.size(); i++) {
249
                        Behavior mapTool = (Behavior) mapTools.get(i);
250
                        
251
                        mapTool.setMapControl(mc);
252
                }
253
                
254
                super.setMapControl(mc);
255
        }
256
}