awteventmulticaster.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 854 行 · 第 1/2 页
JAVA
854 行
/* * @(#)AWTEventMulticaster.java 1.19 03/11/25 * * Copyright 1990-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */package java.awt;import java.awt.event.*;import java.util.EventListener;import java.io.Serializable;import java.io.ObjectOutputStream;import java.io.IOException;import java.lang.reflect.Array;/** * A class which implements efficient and thread-safe multi-cast event * dispatching for the AWT events defined in the java.awt.event package. * This class will manage an immutable structure consisting of a chain of * event listeners and will dispatch events to those listeners. Because * the structure is immutable, it is safe to use this API to add/remove * listeners during the process of an event dispatch operation. * * An example of how this class could be used to implement a new * component which fires "action" events: * * <pre><code> * public myComponent extends Component { * ActionListener actionListener = null; * * public void addActionListener(ActionListener l) { * actionListener = AWTEventMulticaster.add(actionListener, l); * } * public void removeActionListener(ActionListener l) { * actionListener = AWTEventMulticaster.remove(actionListener, l); * } * public void processEvent(AWTEvent e) { * // when event occurs which causes "action" semantic * if (actionListener != null) { * actionListener.actionPerformed(new ActionEvent()); * } * } * </code></pre> * * @version 1.17, 08/19/02 * @author John Rose * @author Amy Fowler */public class AWTEventMulticaster implements ComponentListener, ContainerListener, FocusListener, KeyListener, MouseListener, MouseMotionListener, WindowListener, WindowFocusListener, ActionListener, ItemListener, AdjustmentListener, InputMethodListener, TextListener, MouseWheelListener { protected final EventListener a, b; /** * Creates an event multicaster instance which chains listener-a * with listener-b. * @param a listener-a * @param b listener-b */ protected AWTEventMulticaster(EventListener a, EventListener b) { this.a = a; this.b = b; } /** * Removes a listener from this multicaster and returns the * resulting multicast listener. * @param oldl the listener to be removed */ protected EventListener remove(EventListener oldl) { if (oldl == a) return b; if (oldl == b) return a; EventListener a2 = removeInternal(a, oldl); EventListener b2 = removeInternal(b, oldl); if (a2 == a && b2 == b) { return this; // it's not here } return addInternal(a2, b2); } /** * Handles the componentResized event by invoking the * componentResized methods on listener-a and listener-b. * @param e the component event */ public void componentResized(ComponentEvent e) { ((ComponentListener) a).componentResized(e); ((ComponentListener) b).componentResized(e); } /** * Handles the componentMoved event by invoking the * componentMoved methods on listener-a and listener-b. * @param e the component event */ public void componentMoved(ComponentEvent e) { ((ComponentListener) a).componentMoved(e); ((ComponentListener) b).componentMoved(e); } /** * Handles the componentShown event by invoking the * componentShown methods on listener-a and listener-b. * @param e the component event */ public void componentShown(ComponentEvent e) { ((ComponentListener) a).componentShown(e); ((ComponentListener) b).componentShown(e); } /** * Handles the componentHidden event by invoking the * componentHidden methods on listener-a and listener-b. * @param e the component event */ public void componentHidden(ComponentEvent e) { ((ComponentListener) a).componentHidden(e); ((ComponentListener) b).componentHidden(e); } /** * Handles the componentAdded container event by invoking the * componentAdded methods on listener-a and listener-b. * @param e the component event */ public void componentAdded(ContainerEvent e) { ((ContainerListener) a).componentAdded(e); ((ContainerListener) b).componentAdded(e); } /** * Handles the componentRemoved container event by invoking the * componentRemoved methods on listener-a and listener-b. * @param e the component event */ public void componentRemoved(ContainerEvent e) { ((ContainerListener) a).componentRemoved(e); ((ContainerListener) b).componentRemoved(e); } /** * Handles the focusGained event by invoking the * focusGained methods on listener-a and listener-b. * @param e the focus event */ public void focusGained(FocusEvent e) { ((FocusListener) a).focusGained(e); ((FocusListener) b).focusGained(e); } /** * Handles the focusLost event by invoking the * focusLost methods on listener-a and listener-b. * @param e the focus event */ public void focusLost(FocusEvent e) { ((FocusListener) a).focusLost(e); ((FocusListener) b).focusLost(e); } /** * Handles the keyTyped event by invoking the * keyTyped methods on listener-a and listener-b. * @param e the key event */ public void keyTyped(KeyEvent e) { ((KeyListener) a).keyTyped(e); ((KeyListener) b).keyTyped(e); } /** * Handles the keyPressed event by invoking the * keyPressed methods on listener-a and listener-b. * @param e the key event */ public void keyPressed(KeyEvent e) { ((KeyListener) a).keyPressed(e); ((KeyListener) b).keyPressed(e); } /** * Handles the keyReleased event by invoking the * keyReleased methods on listener-a and listener-b. * @param e the key event */ public void keyReleased(KeyEvent e) { ((KeyListener) a).keyReleased(e); ((KeyListener) b).keyReleased(e); } /** * Handles the mouseClicked event by invoking the * mouseClicked methods on listener-a and listener-b. * @param e the mouse event */ public void mouseClicked(MouseEvent e) { ((MouseListener) a).mouseClicked(e); ((MouseListener) b).mouseClicked(e); } /** * Handles the mousePressed event by invoking the * mousePressed methods on listener-a and listener-b. * @param e the mouse event */ public void mousePressed(MouseEvent e) { ((MouseListener) a).mousePressed(e); ((MouseListener) b).mousePressed(e); } /** * Handles the mouseReleased event by invoking the * mouseReleased methods on listener-a and listener-b. * @param e the mouse event */ public void mouseReleased(MouseEvent e) { ((MouseListener) a).mouseReleased(e); ((MouseListener) b).mouseReleased(e); } /** * Handles the mouseEntered event by invoking the * mouseEntered methods on listener-a and listener-b. * @param e the mouse event */ public void mouseEntered(MouseEvent e) { ((MouseListener) a).mouseEntered(e); ((MouseListener) b).mouseEntered(e); } /** * Handles the mouseExited event by invoking the * mouseExited methods on listener-a and listener-b. * @param e the mouse event */ public void mouseExited(MouseEvent e) { ((MouseListener) a).mouseExited(e); ((MouseListener) b).mouseExited(e); } /** * Handles the mouseDragged event by invoking the * mouseDragged methods on listener-a and listener-b. * @param e the mouse event */ public void mouseDragged(MouseEvent e) { ((MouseMotionListener) a).mouseDragged(e); ((MouseMotionListener) b).mouseDragged(e); } /** * Handles the mouseMoved event by invoking the * mouseMoved methods on listener-a and listener-b. * @param e the mouse event */ public void mouseMoved(MouseEvent e) { ((MouseMotionListener) a).mouseMoved(e); ((MouseMotionListener) b).mouseMoved(e); } /** * Handles the windowOpened event by invoking the * windowOpened methods on listener-a and listener-b. * @param e the window event */ public void windowOpened(WindowEvent e) { ((WindowListener) a).windowOpened(e); ((WindowListener) b).windowOpened(e); } /** * Handles the windowClosing event by invoking the * windowClosing methods on listener-a and listener-b. * @param e the window event */ public void windowClosing(WindowEvent e) { ((WindowListener) a).windowClosing(e); ((WindowListener) b).windowClosing(e); } /** * Handles the windowClosed event by invoking the * windowClosed methods on listener-a and listener-b. * @param e the window event */ public void windowClosed(WindowEvent e) { ((WindowListener) a).windowClosed(e); ((WindowListener) b).windowClosed(e); } /** * Handles the windowIconified event by invoking the * windowIconified methods on listener-a and listener-b. * @param e the window event */ public void windowIconified(WindowEvent e) { ((WindowListener) a).windowIconified(e); ((WindowListener) b).windowIconified(e); } /** * Handles the windowDeiconfied event by invoking the * windowDeiconified methods on listener-a and listener-b. * @param e the window event */ public void windowDeiconified(WindowEvent e) { ((WindowListener) a).windowDeiconified(e); ((WindowListener) b).windowDeiconified(e); } /** * Handles the windowActivated event by invoking the * windowActivated methods on listener-a and listener-b. * @param e the window event */ public void windowActivated(WindowEvent e) { ((WindowListener) a).windowActivated(e); ((WindowListener) b).windowActivated(e); } /** * Handles the windowDeactivated event by invoking the * windowDeactivated methods on listener-a and listener-b. * @param e the window event */ public void windowDeactivated(WindowEvent e) { ((WindowListener) a).windowDeactivated(e); ((WindowListener) b).windowDeactivated(e); } /** * Handles the windowGainedFocus event by invoking the windowGainedFocus * methods on listener-a and listener-b. * @param e the window event */ public void windowGainedFocus(WindowEvent e) { ((WindowFocusListener)a).windowGainedFocus(e); ((WindowFocusListener)b).windowGainedFocus(e); } /** * Handles the windowLostFocus event by invoking the windowLostFocus * methods on listener-a and listener-b. * @param e the window event */ public void windowLostFocus(WindowEvent e) { ((WindowFocusListener)a).windowLostFocus(e); ((WindowFocusListener)b).windowLostFocus(e); } /** * Handles the actionPerformed event by invoking the * actionPerformed methods on listener-a and listener-b. * @param e the action event */ public void actionPerformed(ActionEvent e) { ((ActionListener) a).actionPerformed(e); ((ActionListener) b).actionPerformed(e); } /** * Handles the itemStateChanged event by invoking the * itemStateChanged methods on listener-a and listener-b. * @param e the item event */ public void itemStateChanged(ItemEvent e) { ((ItemListener) a).itemStateChanged(e); ((ItemListener) b).itemStateChanged(e); } /** * Handles the adjustmentValueChanged event by invoking the * adjustmentValueChanged methods on listener-a and listener-b. * @param e the adjustment event */ public void adjustmentValueChanged(AdjustmentEvent e) { ((AdjustmentListener) a).adjustmentValueChanged(e); ((AdjustmentListener) b).adjustmentValueChanged(e); } public void textValueChanged(TextEvent e) { ((TextListener) a).textValueChanged(e); ((TextListener) b).textValueChanged(e); } /** * Handles the inputMethodTextChanged event by invoking the * inputMethodTextChanged methods on listener-a and listener-b. * @param e the item event */ public void inputMethodTextChanged(InputMethodEvent e) { ((InputMethodListener)a).inputMethodTextChanged(e); ((InputMethodListener)b).inputMethodTextChanged(e); } /** * Handles the caretPositionChanged event by invoking the * caretPositionChanged methods on listener-a and listener-b. * @param e the item event */ public void caretPositionChanged(InputMethodEvent e) { ((InputMethodListener)a).caretPositionChanged(e); ((InputMethodListener)b).caretPositionChanged(e); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?