awteventmulticaster.java
来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 1,210 行 · 第 1/3 页
JAVA
1,210 行
*
* @param a the "a" listener, may be null
* @param b the "b" listener, may be null
* @return latest entry in the chain
* @since 1.2
*/
public static InputMethodListener add(InputMethodListener a,
InputMethodListener b)
{
return (InputMethodListener) addInternal(a, b);
}
/**
* Chain <code>HierarchyListener</code> a and b.
*
* @param a the "a" listener, may be null
* @param b the "b" listener, may be null
* @return latest entry in the chain
* @since 1.3
*/
public static HierarchyListener add(HierarchyListener a, HierarchyListener b)
{
return (HierarchyListener) addInternal(a, b);
}
/**
* Chain <code>HierarchyBoundsListener</code> a and b.
*
* @param a the "a" listener, may be null
* @param b the "b" listener, may be null
* @return latest entry in the chain
* @since 1.3
*/
public static HierarchyBoundsListener add(HierarchyBoundsListener a,
HierarchyBoundsListener b)
{
return (HierarchyBoundsListener) addInternal(a, b);
}
/**
* Chain <code>MouseWheelListener</code> a and b.
*
* @param a the "a" listener, may be null
* @param b the "b" listener, may be null
* @return latest entry in the chain
* @since 1.4
*/
public static MouseWheelListener add(MouseWheelListener a,
MouseWheelListener b)
{
return (MouseWheelListener) addInternal(a, b);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
*/
public static ComponentListener remove(ComponentListener l,
ComponentListener oldl)
{
return (ComponentListener) removeInternal(l, oldl);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
*/
public static ContainerListener remove(ContainerListener l,
ContainerListener oldl)
{
return (ContainerListener) removeInternal(l, oldl);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
*/
public static FocusListener remove(FocusListener l, FocusListener oldl)
{
return (FocusListener) removeInternal(l, oldl);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
*/
public static KeyListener remove(KeyListener l, KeyListener oldl)
{
return (KeyListener) removeInternal(l, oldl);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
*/
public static MouseListener remove(MouseListener l, MouseListener oldl)
{
return (MouseListener) removeInternal(l, oldl);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
*/
public static MouseMotionListener remove(MouseMotionListener l,
MouseMotionListener oldl)
{
return (MouseMotionListener) removeInternal(l, oldl);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
*/
public static WindowListener remove(WindowListener l, WindowListener oldl)
{
return (WindowListener) removeInternal(l, oldl);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
* @since 1.4
*/
public static WindowStateListener remove(WindowStateListener l,
WindowStateListener oldl)
{
return (WindowStateListener) removeInternal(l, oldl);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
* @since 1.4
*/
public static WindowFocusListener remove(WindowFocusListener l,
WindowFocusListener oldl)
{
return (WindowFocusListener) removeInternal(l, oldl);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
*/
public static ActionListener remove(ActionListener l, ActionListener oldl)
{
return (ActionListener) removeInternal(l, oldl);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
*/
public static ItemListener remove(ItemListener l, ItemListener oldl)
{
return (ItemListener) removeInternal(l, oldl);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
*/
public static AdjustmentListener remove(AdjustmentListener l,
AdjustmentListener oldl)
{
return (AdjustmentListener) removeInternal(l, oldl);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
*/
public static TextListener remove(TextListener l, TextListener oldl)
{
return (TextListener) removeInternal(l, oldl);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
* @since 1.2
*/
public static InputMethodListener remove(InputMethodListener l,
InputMethodListener oldl)
{
return (InputMethodListener) removeInternal(l, oldl);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
* @since 1.3
*/
public static HierarchyListener remove(HierarchyListener l,
HierarchyListener oldl)
{
return (HierarchyListener) removeInternal(l, oldl);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
* @since 1.3
*/
public static HierarchyBoundsListener remove(HierarchyBoundsListener l,
HierarchyBoundsListener oldl)
{
return (HierarchyBoundsListener) removeInternal(l, oldl);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
* @since 1.4
*/
public static MouseWheelListener remove(MouseWheelListener l,
MouseWheelListener oldl)
{
return (MouseWheelListener) removeInternal(l, oldl);
}
/**
* Chain <code>EventListener</code> a and b.
*
* @param a the "a" listener, may be null
* @param b the "b" listener, may be null
* @return latest entry in the chain
*/
protected static EventListener addInternal(EventListener a, EventListener b)
{
if (a == null)
return b;
if (b == null)
return a;
return new AWTEventMulticaster(a, b);
}
/**
* Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
* @param l the listener chain to reduce
* @param oldl the listener to remove
* @return the resulting listener chain
*/
protected static EventListener removeInternal(EventListener l,
EventListener oldl)
{
if (l == oldl)
return null;
if (l instanceof AWTEventMulticaster)
return ((AWTEventMulticaster) l).remove(oldl);
return l;
}
/**
* Saves all Serializable listeners to a serialization stream.
*
* @param s the stream to save to
* @param k a prefix stream put before each serializable listener
* @throws IOException if serialization fails
*/
protected void saveInternal(ObjectOutputStream s, String k)
throws IOException
{
// This is not documented by Sun, but I think it is correct.
if (a instanceof AWTEventMulticaster)
((AWTEventMulticaster) a).saveInternal(s, k);
else if (a instanceof Serializable)
{
s.writeObject(k);
s.writeObject(a);
}
if (b instanceof AWTEventMulticaster)
((AWTEventMulticaster) b).saveInternal(s, k);
else if (b instanceof Serializable)
{
s.writeObject(k);
s.writeObject(b);
}
}
/**
* Saves a Serializable listener chain to a serialization stream.
*
* @param s the stream to save to
* @param k a prefix stream put before each serializable listener
* @param l the listener chain to save
* @throws IOException if serialization fails
*/
protected static void save(ObjectOutputStream s, String k, EventListener l)
throws IOException
{
// This is not documented by Sun, but I think it is correct.
if (l instanceof AWTEventMulticaster)
((AWTEventMulticaster) l).saveInternal(s, k);
else if (l instanceof Serializable)
{
s.writeObject(k);
s.writeObject(l);
}
}
/**
* Returns an array of all chained listeners of the specified type in the
* given chain. A null listener returns an empty array, and a listener
* which is not an AWTEventMulticaster returns an array of one element. If
* no listeners in the chain are of the specified type, an empty array is
* returned.
*
* @param l the listener chain to convert to an array
* @param type the type of listeners to collect
* @return an array of the listeners of that type in the chain
* @throws ClassCastException if type is not assignable from EventListener
* @throws NullPointerException if type is null
* @throws IllegalArgumentException if type is Void.TYPE
* @since 1.4
*/
public static EventListener[] getListeners(EventListener l, Class type)
{
ArrayList list = new ArrayList();
if (l instanceof AWTEventMulticaster)
((AWTEventMulticaster) l).getListeners(list, type);
else if (type.isInstance(l))
list.add(l);
EventListener[] r = (EventListener[]) Array.newInstance(type, list.size());
list.toArray(r);
return r;
}
/**
* Collects all instances of the given type in the chain into the list.
*
* @param l the list to collect into
* @param type the type of listeners to collect
* @throws NullPointerException if type is null
* @see #getListeners(EventListener, Class)
*/
private void getListeners(ArrayList l, Class type)
{
if (a instanceof AWTEventMulticaster)
((AWTEventMulticaster) a).getListeners(l, type);
else if (type.isInstance(a))
l.add(a);
if (b instanceof AWTEventMulticaster)
((AWTEventMulticaster) b).getListeners(l, type);
else if (type.isInstance(b))
l.add(b);
}
} // class AWTEventMulticaster
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?