OSDN Git Service

2005-02-17 Michael Koch <konqueror@gmx.de>
[pf3gnuchains/gcc-fork.git] / libjava / java / awt / event / AWTEventListenerProxy.java
1 /* AWTEventListenerProxy.java -- wrapper/filter for AWTEventListener
2    Copyright (C) 2002, 2005  Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
20
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library.  Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
25
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module.  An independent module is a module which is not derived from
33 or based on this library.  If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so.  If you do not wish to do so, delete this
36 exception statement from your version. */
37
38
39 package java.awt.event;
40
41 import java.awt.AWTEvent;
42 import java.util.EventListenerProxy;
43
44 /**
45  * This class allows adding an AWTEventListener which only pays attention to
46  * a specific event mask.
47  *
48  * @author Eric Blake (ebb9@email.byu.edu)
49  * @see Toolkit
50  * @see EventListenerProxy
51  * @since 1.4
52  * @status updated to 1.4
53  */
54 public class AWTEventListenerProxy extends EventListenerProxy
55   implements AWTEventListener
56 {
57   /** The event mask. */
58   private final long mask;
59
60   /**
61    * Construct an AWT Event Listener which only listens to events in the given
62    * mask, passing the work on to the real listener.
63    *
64    * @param eventMask the mask of events to listen to
65    * @param listener the wrapped listener
66    */
67   public AWTEventListenerProxy(long eventMask, AWTEventListener listener)
68   {
69     super(listener);
70     mask = eventMask;
71   }
72
73   /**
74    * Forwards events on to the delegate if they meet the event mask.
75    *
76    * @param event the property change event to filter
77    * @throws NullPointerException if the delegate this was created with is null
78    */
79   public void eventDispatched(AWTEvent event)
80   {
81     int id = event == null ? 0 : event.getID();
82     if (((mask & AWTEvent.ACTION_EVENT_MASK) != 0
83          && event instanceof ActionEvent)
84         || ((mask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0
85             && event instanceof AdjustmentEvent)
86         || ((mask & AWTEvent.COMPONENT_EVENT_MASK) != 0
87             && event instanceof ComponentEvent
88             && (id >= ComponentEvent.COMPONENT_FIRST
89                 && id <= ComponentEvent.COMPONENT_LAST))
90         || ((mask & AWTEvent.CONTAINER_EVENT_MASK) != 0
91             && event instanceof ContainerEvent)
92         || ((mask & AWTEvent.FOCUS_EVENT_MASK) != 0
93             && event instanceof FocusEvent)
94         || ((mask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0
95             && event instanceof HierarchyEvent
96             && (id == HierarchyEvent.ANCESTOR_MOVED
97                 || id == HierarchyEvent.ANCESTOR_RESIZED))
98         || ((mask & AWTEvent.HIERARCHY_EVENT_MASK) != 0
99             && event instanceof HierarchyEvent
100             && id == HierarchyEvent.HIERARCHY_CHANGED)
101         || ((mask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0
102             && event instanceof InputMethodEvent)
103         || ((mask & AWTEvent.INVOCATION_EVENT_MASK) != 0
104             && event instanceof InvocationEvent)
105         || ((mask & AWTEvent.ITEM_EVENT_MASK) != 0
106             && event instanceof ItemEvent)
107         || ((mask & AWTEvent.KEY_EVENT_MASK) != 0
108             && event instanceof KeyEvent)
109         || ((mask & AWTEvent.MOUSE_EVENT_MASK) != 0
110             && event instanceof MouseEvent
111             && (id == MouseEvent.MOUSE_PRESSED
112                 || id == MouseEvent.MOUSE_RELEASED
113                 || id == MouseEvent.MOUSE_CLICKED
114                 || id == MouseEvent.MOUSE_ENTERED
115                 || id == MouseEvent.MOUSE_EXITED))
116         || ((mask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0
117             && event instanceof MouseEvent
118             && (id == MouseEvent.MOUSE_MOVED
119                 || id == MouseEvent.MOUSE_DRAGGED))
120         || ((mask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0
121             && event instanceof MouseWheelEvent)
122         || ((mask & AWTEvent.PAINT_EVENT_MASK) != 0
123             && event instanceof PaintEvent)
124         || ((mask & AWTEvent.TEXT_EVENT_MASK) != 0
125             && event instanceof TextEvent)
126         || ((mask & AWTEvent.WINDOW_EVENT_MASK) != 0
127             && event instanceof WindowEvent
128             && (id == WindowEvent.WINDOW_OPENED
129                 || id == WindowEvent.WINDOW_CLOSING
130                 || id == WindowEvent.WINDOW_CLOSED
131                 || id == WindowEvent.WINDOW_ICONIFIED
132                 || id == WindowEvent.WINDOW_DEICONIFIED
133                 || id == WindowEvent.WINDOW_ACTIVATED
134                 || id == WindowEvent.WINDOW_DEACTIVATED))
135         || ((mask & AWTEvent.WINDOW_FOCUS_EVENT_MASK) != 0
136             && event instanceof WindowEvent
137             && (id == WindowEvent.WINDOW_GAINED_FOCUS
138                 || id == WindowEvent.WINDOW_LOST_FOCUS))
139         || ((mask & AWTEvent.WINDOW_STATE_EVENT_MASK) != 0
140             && event instanceof WindowEvent
141             && id == WindowEvent.WINDOW_STATE_CHANGED))
142       ((AWTEventListener) getListener()).eventDispatched(event);
143   }
144
145   /**
146    * This returns the event mask associated with this listener.
147    *
148    * @return the event mask
149    */
150   public long getEventMask()
151   {
152     return mask;
153   }
154 } // class AWTEventListenerProxy