feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
import java.awt.AWTEvent;
/**
* The listener interface for receiving notification of events
* dispatched to objects that are instances of Component or
* MenuComponent or their subclasses. Unlike the other EventListeners
* in this package, AWTEventListeners passively observe events
* being dispatched in the AWT, system-wide. Most applications
* should never use this class; applications which might use
* AWTEventListeners include event recorders for automated testing,
* and facilities such as the Java Accessibility package.
* <p>
* The class that is interested in monitoring AWT events
* implements this interface, and the object created with that
* class is registered with the Toolkit, using the Toolkit's
* <code>addAWTEventListener</code> method. When an event is
* dispatched anywhere in the AWT, that object's
* <code>eventDispatched</code> method is invoked.
*
* @see java.awt.AWTEvent
* @see java.awt.Toolkit#addAWTEventListener
* @see java.awt.Toolkit#removeAWTEventListener
*
* @author Fred Ecks
* @since 1.2
*/
public interface AWTEventListener extends EventListener {
/**
* Invoked when an event is dispatched in the AWT.
*/
public void eventDispatched(AWTEvent event);
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (c) 2001, 2007, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListenerProxy;
import java.awt.AWTEvent;
/**
* A class which extends the {@code EventListenerProxy}
* specifically for adding an {@code AWTEventListener}
* for a specific event mask.
* Instances of this class can be added as {@code AWTEventListener}s
* to a {@code Toolkit} object.
* <p>
* The {@code getAWTEventListeners} method of {@code Toolkit}
* can return a mixture of {@code AWTEventListener}
* and {@code AWTEventListenerProxy} objects.
*
* @see java.awt.Toolkit
* @see java.util.EventListenerProxy
* @since 1.4
*/
public class AWTEventListenerProxy
extends EventListenerProxy<AWTEventListener>
implements AWTEventListener {
private final long eventMask;
/**
* Constructor which binds the {@code AWTEventListener}
* to a specific event mask.
*
* @param eventMask the bitmap of event types to receive
* @param listener the listener object
*/
public AWTEventListenerProxy (long eventMask, AWTEventListener listener) {
super(listener);
this.eventMask = eventMask;
}
/**
* Forwards the AWT event to the listener delegate.
*
* @param event the AWT event
*/
public void eventDispatched(AWTEvent event) {
getListener().eventDispatched(event);
}
/**
* Returns the event mask associated with the listener.
*
* @return the event mask associated with the listener
*/
public long getEventMask() {
return this.eventMask;
}
}

View File

@@ -0,0 +1,289 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.awt.AWTEvent;
import java.awt.Event;
import java.lang.annotation.Native;
/**
* A semantic event which indicates that a component-defined action occurred.
* This high-level event is generated by a component (such as a
* <code>Button</code>) when
* the component-specific action occurs (such as being pressed).
* The event is passed to every <code>ActionListener</code> object
* that registered to receive such events using the component's
* <code>addActionListener</code> method.
* <p>
* <b>Note:</b> To invoke an <code>ActionEvent</code> on a
* <code>Button</code> using the keyboard, use the Space bar.
* <P>
* The object that implements the <code>ActionListener</code> interface
* gets this <code>ActionEvent</code> when the event occurs. The listener
* is therefore spared the details of processing individual mouse movements
* and mouse clicks, and can instead process a "meaningful" (semantic)
* event like "button pressed".
* <p>
* An unspecified behavior will be caused if the {@code id} parameter
* of any particular {@code ActionEvent} instance is not
* in the range from {@code ACTION_FIRST} to {@code ACTION_LAST}.
*
* @see ActionListener
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html">Tutorial: How to Write an Action Listener</a>
*
* @author Carl Quinn
* @since 1.1
*/
public class ActionEvent extends AWTEvent {
/**
* The shift modifier. An indicator that the shift key was held
* down during the event.
*/
public static final int SHIFT_MASK = Event.SHIFT_MASK;
/**
* The control modifier. An indicator that the control key was held
* down during the event.
*/
public static final int CTRL_MASK = Event.CTRL_MASK;
/**
* The meta modifier. An indicator that the meta key was held
* down during the event.
*/
public static final int META_MASK = Event.META_MASK;
/**
* The alt modifier. An indicator that the alt key was held
* down during the event.
*/
public static final int ALT_MASK = Event.ALT_MASK;
/**
* The first number in the range of ids used for action events.
*/
public static final int ACTION_FIRST = 1001;
/**
* The last number in the range of ids used for action events.
*/
public static final int ACTION_LAST = 1001;
/**
* This event id indicates that a meaningful action occurred.
*/
@Native public static final int ACTION_PERFORMED = ACTION_FIRST; //Event.ACTION_EVENT
/**
* The nonlocalized string that gives more details
* of what actually caused the event.
* This information is very specific to the component
* that fired it.
* @serial
* @see #getActionCommand
*/
String actionCommand;
/**
* Timestamp of when this event occurred. Because an ActionEvent is a high-
* level, semantic event, the timestamp is typically the same as an
* underlying InputEvent.
*
* @serial
* @see #getWhen
*/
long when;
/**
* This represents the key modifier that was selected,
* and is used to determine the state of the selected key.
* If no modifier has been selected it will default to
* zero.
*
* @serial
* @see #getModifiers
*/
int modifiers;
/*
* JDK 1.1 serialVersionUID
*/
private static final long serialVersionUID = -7671078796273832149L;
/**
* Constructs an <code>ActionEvent</code> object.
* <p>
* This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
* A <code>null</code> <code>command</code> string is legal,
* but not recommended.
*
* @param source The object that originated the event
* @param id An integer that identifies the event.
* For information on allowable values, see
* the class description for {@link ActionEvent}
* @param command A string that may specify a command (possibly one
* of several) associated with the event
* @throws IllegalArgumentException if <code>source</code> is null
* @see #getSource()
* @see #getID()
* @see #getActionCommand()
*/
public ActionEvent(Object source, int id, String command) {
this(source, id, command, 0);
}
/**
* Constructs an <code>ActionEvent</code> object with modifier keys.
* <p>
* This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
* A <code>null</code> <code>command</code> string is legal,
* but not recommended.
*
* @param source The object that originated the event
* @param id An integer that identifies the event.
* For information on allowable values, see
* the class description for {@link ActionEvent}
* @param command A string that may specify a command (possibly one
* of several) associated with the event
* @param modifiers The modifier keys down during event
* (shift, ctrl, alt, meta).
* Passing negative parameter is not recommended.
* Zero value means that no modifiers were passed
* @throws IllegalArgumentException if <code>source</code> is null
* @see #getSource()
* @see #getID()
* @see #getActionCommand()
* @see #getModifiers()
*/
public ActionEvent(Object source, int id, String command, int modifiers) {
this(source, id, command, 0, modifiers);
}
/**
* Constructs an <code>ActionEvent</code> object with the specified
* modifier keys and timestamp.
* <p>
* This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
* A <code>null</code> <code>command</code> string is legal,
* but not recommended.
*
* @param source The object that originated the event
* @param id An integer that identifies the event.
* For information on allowable values, see
* the class description for {@link ActionEvent}
* @param command A string that may specify a command (possibly one
* of several) associated with the event
* @param modifiers The modifier keys down during event
* (shift, ctrl, alt, meta).
* Passing negative parameter is not recommended.
* Zero value means that no modifiers were passed
* @param when A long that gives the time the event occurred.
* Passing negative or zero value
* is not recommended
* @throws IllegalArgumentException if <code>source</code> is null
* @see #getSource()
* @see #getID()
* @see #getActionCommand()
* @see #getModifiers()
* @see #getWhen()
*
* @since 1.4
*/
public ActionEvent(Object source, int id, String command, long when,
int modifiers) {
super(source, id);
this.actionCommand = command;
this.when = when;
this.modifiers = modifiers;
}
/**
* Returns the command string associated with this action.
* This string allows a "modal" component to specify one of several
* commands, depending on its state. For example, a single button might
* toggle between "show details" and "hide details". The source object
* and the event would be the same in each case, but the command string
* would identify the intended action.
* <p>
* Note that if a <code>null</code> command string was passed
* to the constructor for this <code>ActionEvent</code>, this
* this method returns <code>null</code>.
*
* @return the string identifying the command for this event
*/
public String getActionCommand() {
return actionCommand;
}
/**
* Returns the timestamp of when this event occurred. Because an
* ActionEvent is a high-level, semantic event, the timestamp is typically
* the same as an underlying InputEvent.
*
* @return this event's timestamp
* @since 1.4
*/
public long getWhen() {
return when;
}
/**
* Returns the modifier keys held down during this action event.
*
* @return the bitwise-or of the modifier constants
*/
public int getModifiers() {
return modifiers;
}
/**
* Returns a parameter string identifying this action event.
* This method is useful for event-logging and for debugging.
*
* @return a string identifying the event and its associated command
*/
public String paramString() {
String typeStr;
switch(id) {
case ACTION_PERFORMED:
typeStr = "ACTION_PERFORMED";
break;
default:
typeStr = "unknown type";
}
return typeStr + ",cmd="+actionCommand+",when="+when+",modifiers="+
KeyEvent.getKeyModifiersText(modifiers);
}
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving action events.
* The class that is interested in processing an action event
* implements this interface, and the object created with that
* class is registered with a component, using the component's
* <code>addActionListener</code> method. When the action event
* occurs, that object's <code>actionPerformed</code> method is
* invoked.
*
* @see ActionEvent
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html">How to Write an Action Listener</a>
*
* @author Carl Quinn
* @since 1.1
*/
public interface ActionListener extends EventListener {
/**
* Invoked when an action occurs.
*/
public void actionPerformed(ActionEvent e);
}

View File

@@ -0,0 +1,291 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.awt.Adjustable;
import java.awt.AWTEvent;
import java.lang.annotation.Native;
/**
* The adjustment event emitted by Adjustable objects like
* {@link java.awt.Scrollbar} and {@link java.awt.ScrollPane}.
* When the user changes the value of the scrolling component,
* it receives an instance of {@code AdjustmentEvent}.
* <p>
* An unspecified behavior will be caused if the {@code id} parameter
* of any particular {@code AdjustmentEvent} instance is not
* in the range from {@code ADJUSTMENT_FIRST} to {@code ADJUSTMENT_LAST}.
* <p>
* The {@code type} of any {@code AdjustmentEvent} instance takes one of the following
* values:
* <ul>
* <li> {@code UNIT_INCREMENT}
* <li> {@code UNIT_DECREMENT}
* <li> {@code BLOCK_INCREMENT}
* <li> {@code BLOCK_DECREMENT}
* <li> {@code TRACK}
* </ul>
* Assigning the value different from listed above will cause an unspecified behavior.
* @see java.awt.Adjustable
* @see AdjustmentListener
*
* @author Amy Fowler
* @since 1.1
*/
public class AdjustmentEvent extends AWTEvent {
/**
* Marks the first integer id for the range of adjustment event ids.
*/
public static final int ADJUSTMENT_FIRST = 601;
/**
* Marks the last integer id for the range of adjustment event ids.
*/
public static final int ADJUSTMENT_LAST = 601;
/**
* The adjustment value changed event.
*/
public static final int ADJUSTMENT_VALUE_CHANGED = ADJUSTMENT_FIRST; //Event.SCROLL_LINE_UP
/**
* The unit increment adjustment type.
*/
@Native public static final int UNIT_INCREMENT = 1;
/**
* The unit decrement adjustment type.
*/
@Native public static final int UNIT_DECREMENT = 2;
/**
* The block decrement adjustment type.
*/
@Native public static final int BLOCK_DECREMENT = 3;
/**
* The block increment adjustment type.
*/
@Native public static final int BLOCK_INCREMENT = 4;
/**
* The absolute tracking adjustment type.
*/
@Native public static final int TRACK = 5;
/**
* The adjustable object that fired the event.
*
* @serial
* @see #getAdjustable
*/
Adjustable adjustable;
/**
* <code>value</code> will contain the new value of the
* adjustable object. This value will always be in a
* range associated adjustable object.
*
* @serial
* @see #getValue
*/
int value;
/**
* The <code>adjustmentType</code> describes how the adjustable
* object value has changed.
* This value can be increased/decreased by a block or unit amount
* where the block is associated with page increments/decrements,
* and a unit is associated with line increments/decrements.
*
* @serial
* @see #getAdjustmentType
*/
int adjustmentType;
/**
* The <code>isAdjusting</code> is true if the event is one
* of the series of multiple adjustment events.
*
* @since 1.4
* @serial
* @see #getValueIsAdjusting
*/
boolean isAdjusting;
/*
* JDK 1.1 serialVersionUID
*/
private static final long serialVersionUID = 5700290645205279921L;
/**
* Constructs an <code>AdjustmentEvent</code> object with the
* specified <code>Adjustable</code> source, event type,
* adjustment type, and value.
* <p> This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source The <code>Adjustable</code> object where the
* event originated
* @param id An integer indicating the type of event.
* For information on allowable values, see
* the class description for {@link AdjustmentEvent}
* @param type An integer indicating the adjustment type.
* For information on allowable values, see
* the class description for {@link AdjustmentEvent}
* @param value The current value of the adjustment
* @throws IllegalArgumentException if <code>source</code> is null
* @see #getSource()
* @see #getID()
* @see #getAdjustmentType()
* @see #getValue()
*/
public AdjustmentEvent(Adjustable source, int id, int type, int value) {
this(source, id, type, value, false);
}
/**
* Constructs an <code>AdjustmentEvent</code> object with the
* specified Adjustable source, event type, adjustment type, and value.
* <p> This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source The <code>Adjustable</code> object where the
* event originated
* @param id An integer indicating the type of event.
* For information on allowable values, see
* the class description for {@link AdjustmentEvent}
* @param type An integer indicating the adjustment type.
* For information on allowable values, see
* the class description for {@link AdjustmentEvent}
* @param value The current value of the adjustment
* @param isAdjusting A boolean that equals <code>true</code> if the event is one
* of a series of multiple adjusting events,
* otherwise <code>false</code>
* @throws IllegalArgumentException if <code>source</code> is null
* @since 1.4
* @see #getSource()
* @see #getID()
* @see #getAdjustmentType()
* @see #getValue()
* @see #getValueIsAdjusting()
*/
public AdjustmentEvent(Adjustable source, int id, int type, int value, boolean isAdjusting) {
super(source, id);
adjustable = source;
this.adjustmentType = type;
this.value = value;
this.isAdjusting = isAdjusting;
}
/**
* Returns the <code>Adjustable</code> object where this event originated.
*
* @return the <code>Adjustable</code> object where this event originated
*/
public Adjustable getAdjustable() {
return adjustable;
}
/**
* Returns the current value in the adjustment event.
*
* @return the current value in the adjustment event
*/
public int getValue() {
return value;
}
/**
* Returns the type of adjustment which caused the value changed
* event. It will have one of the following values:
* <ul>
* <li>{@link #UNIT_INCREMENT}
* <li>{@link #UNIT_DECREMENT}
* <li>{@link #BLOCK_INCREMENT}
* <li>{@link #BLOCK_DECREMENT}
* <li>{@link #TRACK}
* </ul>
* @return one of the adjustment values listed above
*/
public int getAdjustmentType() {
return adjustmentType;
}
/**
* Returns <code>true</code> if this is one of multiple
* adjustment events.
*
* @return <code>true</code> if this is one of multiple
* adjustment events, otherwise returns <code>false</code>
* @since 1.4
*/
public boolean getValueIsAdjusting() {
return isAdjusting;
}
public String paramString() {
String typeStr;
switch(id) {
case ADJUSTMENT_VALUE_CHANGED:
typeStr = "ADJUSTMENT_VALUE_CHANGED";
break;
default:
typeStr = "unknown type";
}
String adjTypeStr;
switch(adjustmentType) {
case UNIT_INCREMENT:
adjTypeStr = "UNIT_INCREMENT";
break;
case UNIT_DECREMENT:
adjTypeStr = "UNIT_DECREMENT";
break;
case BLOCK_INCREMENT:
adjTypeStr = "BLOCK_INCREMENT";
break;
case BLOCK_DECREMENT:
adjTypeStr = "BLOCK_DECREMENT";
break;
case TRACK:
adjTypeStr = "TRACK";
break;
default:
adjTypeStr = "unknown type";
}
return typeStr
+ ",adjType="+adjTypeStr
+ ",value="+value
+ ",isAdjusting="+isAdjusting;
}
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving adjustment events.
*
* @author Amy Fowler
* @since 1.1
*/
public interface AdjustmentListener extends EventListener {
/**
* Invoked when the value of the adjustable has changed.
*/
public void adjustmentValueChanged(AdjustmentEvent e);
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
/**
* An abstract adapter class for receiving component events.
* The methods in this class are empty. This class exists as
* convenience for creating listener objects.
* <P>
* Extend this class to create a <code>ComponentEvent</code> listener
* and override the methods for the events of interest. (If you implement the
* <code>ComponentListener</code> interface, you have to define all of
* the methods in it. This abstract class defines null methods for them
* all, so you can only have to define methods for events you care about.)
* <P>
* Create a listener object using your class and then register it with a
* component using the component's <code>addComponentListener</code>
* method. When the component's size, location, or visibility
* changes, the relevant method in the listener object is invoked,
* and the <code>ComponentEvent</code> is passed to it.
*
* @see ComponentEvent
* @see ComponentListener
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/componentlistener.html">Tutorial: Writing a Component Listener</a>
*
* @author Carl Quinn
* @since 1.1
*/
public abstract class ComponentAdapter implements ComponentListener {
/**
* Invoked when the component's size changes.
*/
public void componentResized(ComponentEvent e) {}
/**
* Invoked when the component's position changes.
*/
public void componentMoved(ComponentEvent e) {}
/**
* Invoked when the component has been made visible.
*/
public void componentShown(ComponentEvent e) {}
/**
* Invoked when the component has been made invisible.
*/
public void componentHidden(ComponentEvent e) {}
}

View File

@@ -0,0 +1,166 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.awt.AWTEvent;
import java.awt.Component;
import java.awt.Rectangle;
import java.lang.annotation.Native;
/**
* A low-level event which indicates that a component moved, changed
* size, or changed visibility (also, the root class for the other
* component-level events).
* <P>
* Component events are provided for notification purposes ONLY;
* The AWT will automatically handle component moves and resizes
* internally so that GUI layout works properly regardless of
* whether a program is receiving these events or not.
* <P>
* In addition to serving as the base class for other component-related
* events (InputEvent, FocusEvent, WindowEvent, ContainerEvent),
* this class defines the events that indicate changes in
* a component's size, position, or visibility.
* <P>
* This low-level event is generated by a component object (such as a
* List) when the component is moved, resized, rendered invisible, or made
* visible again. The event is passed to every <code>ComponentListener</code>
* or <code>ComponentAdapter</code> object which registered to receive such
* events using the component's <code>addComponentListener</code> method.
* (<code>ComponentAdapter</code> objects implement the
* <code>ComponentListener</code> interface.) Each such listener object
* gets this <code>ComponentEvent</code> when the event occurs.
* <p>
* An unspecified behavior will be caused if the {@code id} parameter
* of any particular {@code ComponentEvent} instance is not
* in the range from {@code COMPONENT_FIRST} to {@code COMPONENT_LAST}.
*
* @see ComponentAdapter
* @see ComponentListener
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/componentlistener.html">Tutorial: Writing a Component Listener</a>
*
* @author Carl Quinn
* @since 1.1
*/
public class ComponentEvent extends AWTEvent {
/**
* The first number in the range of ids used for component events.
*/
public static final int COMPONENT_FIRST = 100;
/**
* The last number in the range of ids used for component events.
*/
public static final int COMPONENT_LAST = 103;
/**
* This event indicates that the component's position changed.
*/
@Native public static final int COMPONENT_MOVED = COMPONENT_FIRST;
/**
* This event indicates that the component's size changed.
*/
@Native public static final int COMPONENT_RESIZED = 1 + COMPONENT_FIRST;
/**
* This event indicates that the component was made visible.
*/
@Native public static final int COMPONENT_SHOWN = 2 + COMPONENT_FIRST;
/**
* This event indicates that the component was rendered invisible.
*/
@Native public static final int COMPONENT_HIDDEN = 3 + COMPONENT_FIRST;
/*
* JDK 1.1 serialVersionUID
*/
private static final long serialVersionUID = 8101406823902992965L;
/**
* Constructs a <code>ComponentEvent</code> object.
* <p> This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source The <code>Component</code> that originated the event
* @param id An integer indicating the type of event.
* For information on allowable values, see
* the class description for {@link ComponentEvent}
* @throws IllegalArgumentException if <code>source</code> is null
* @see #getComponent()
* @see #getID()
*/
public ComponentEvent(Component source, int id) {
super(source, id);
}
/**
* Returns the originator of the event.
*
* @return the <code>Component</code> object that originated
* the event, or <code>null</code> if the object is not a
* <code>Component</code>.
*/
public Component getComponent() {
return (source instanceof Component) ? (Component)source : null;
}
/**
* Returns a parameter string identifying this event.
* This method is useful for event-logging and for debugging.
*
* @return a string identifying the event and its attributes
*/
public String paramString() {
String typeStr;
Rectangle b = (source !=null
? ((Component)source).getBounds()
: null);
switch(id) {
case COMPONENT_SHOWN:
typeStr = "COMPONENT_SHOWN";
break;
case COMPONENT_HIDDEN:
typeStr = "COMPONENT_HIDDEN";
break;
case COMPONENT_MOVED:
typeStr = "COMPONENT_MOVED ("+
b.x+","+b.y+" "+b.width+"x"+b.height+")";
break;
case COMPONENT_RESIZED:
typeStr = "COMPONENT_RESIZED ("+
b.x+","+b.y+" "+b.width+"x"+b.height+")";
break;
default:
typeStr = "unknown type";
}
return typeStr;
}
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving component events.
* The class that is interested in processing a component event
* either implements this interface (and all the methods it
* contains) or extends the abstract <code>ComponentAdapter</code> class
* (overriding only the methods of interest).
* The listener object created from that class is then registered with a
* component using the component's <code>addComponentListener</code>
* method. When the component's size, location, or visibility
* changes, the relevant method in the listener object is invoked,
* and the <code>ComponentEvent</code> is passed to it.
* <P>
* Component events are provided for notification purposes ONLY;
* The AWT will automatically handle component moves and resizes
* internally so that GUI layout works properly regardless of
* whether a program registers a <code>ComponentListener</code> or not.
*
* @see ComponentAdapter
* @see ComponentEvent
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/componentlistener.html">Tutorial: Writing a Component Listener</a>
*
* @author Carl Quinn
* @since 1.1
*/
public interface ComponentListener extends EventListener {
/**
* Invoked when the component's size changes.
*/
public void componentResized(ComponentEvent e);
/**
* Invoked when the component's position changes.
*/
public void componentMoved(ComponentEvent e);
/**
* Invoked when the component has been made visible.
*/
public void componentShown(ComponentEvent e);
/**
* Invoked when the component has been made invisible.
*/
public void componentHidden(ComponentEvent e);
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
/**
* An abstract adapter class for receiving container events.
* The methods in this class are empty. This class exists as
* convenience for creating listener objects.
* <P>
* Extend this class to create a <code>ContainerEvent</code> listener
* and override the methods for the events of interest. (If you implement the
* <code>ContainerListener</code> interface, you have to define all of
* the methods in it. This abstract class defines null methods for them
* all, so you can only have to define methods for events you care about.)
* <P>
* Create a listener object using the extended class and then register it with
* a component using the component's <code>addContainerListener</code>
* method. When the container's contents change because a component has
* been added or removed, the relevant method in the listener object is invoked,
* and the <code>ContainerEvent</code> is passed to it.
*
* @see ContainerEvent
* @see ContainerListener
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/containerlistener.html">Tutorial: Writing a Container Listener</a>
*
* @author Amy Fowler
* @since 1.1
*/
public abstract class ContainerAdapter implements ContainerListener {
/**
* Invoked when a component has been added to the container.
*/
public void componentAdded(ContainerEvent e) {}
/**
* Invoked when a component has been removed from the container.
*/
public void componentRemoved(ContainerEvent e) {}
}

View File

@@ -0,0 +1,159 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.awt.Container;
import java.awt.Component;
/**
* A low-level event which indicates that a container's contents
* changed because a component was added or removed.
* <P>
* Container events are provided for notification purposes ONLY;
* The AWT will automatically handle changes to the containers
* contents internally so that the program works properly regardless of
* whether the program is receiving these events or not.
* <P>
* This low-level event is generated by a container object (such as a
* Panel) when a component is added to it or removed from it.
* The event is passed to every <code>ContainerListener</code>
* or <code>ContainerAdapter</code> object which registered to receive such
* events using the component's <code>addContainerListener</code> method.
* (<code>ContainerAdapter</code> objects implement the
* <code>ContainerListener</code> interface.) Each such listener object
* gets this <code>ContainerEvent</code> when the event occurs.
* <p>
* An unspecified behavior will be caused if the {@code id} parameter
* of any particular {@code ContainerEvent} instance is not
* in the range from {@code CONTAINER_FIRST} to {@code CONTAINER_LAST}.
*
* @see ContainerAdapter
* @see ContainerListener
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/containerlistener.html">Tutorial: Writing a Container Listener</a>
*
* @author Tim Prinzing
* @author Amy Fowler
* @since 1.1
*/
public class ContainerEvent extends ComponentEvent {
/**
* The first number in the range of ids used for container events.
*/
public static final int CONTAINER_FIRST = 300;
/**
* The last number in the range of ids used for container events.
*/
public static final int CONTAINER_LAST = 301;
/**
* This event indicates that a component was added to the container.
*/
public static final int COMPONENT_ADDED = CONTAINER_FIRST;
/**
* This event indicates that a component was removed from the container.
*/
public static final int COMPONENT_REMOVED = 1 + CONTAINER_FIRST;
/**
* The non-null component that is being added or
* removed from the Container.
*
* @serial
* @see #getChild()
*/
Component child;
/*
* JDK 1.1 serialVersionUID
*/
private static final long serialVersionUID = -4114942250539772041L;
/**
* Constructs a <code>ContainerEvent</code> object.
* <p> This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source The <code>Component</code> object (container)
* that originated the event
* @param id An integer indicating the type of event.
* For information on allowable values, see
* the class description for {@link ContainerEvent}
* @param child the component that was added or removed
* @throws IllegalArgumentException if <code>source</code> is null
* @see #getContainer()
* @see #getID()
* @see #getChild()
*/
public ContainerEvent(Component source, int id, Component child) {
super(source, id);
this.child = child;
}
/**
* Returns the originator of the event.
*
* @return the <code>Container</code> object that originated
* the event, or <code>null</code> if the object is not a
* <code>Container</code>.
*/
public Container getContainer() {
return (source instanceof Container) ? (Container)source : null;
}
/**
* Returns the component that was affected by the event.
*
* @return the Component object that was added or removed
*/
public Component getChild() {
return child;
}
/**
* Returns a parameter string identifying this event.
* This method is useful for event-logging and for debugging.
*
* @return a string identifying the event and its attributes
*/
public String paramString() {
String typeStr;
switch(id) {
case COMPONENT_ADDED:
typeStr = "COMPONENT_ADDED";
break;
case COMPONENT_REMOVED:
typeStr = "COMPONENT_REMOVED";
break;
default:
typeStr = "unknown type";
}
return typeStr + ",child="+child.getName();
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving container events.
* The class that is interested in processing a container event
* either implements this interface (and all the methods it
* contains) or extends the abstract <code>ContainerAdapter</code> class
* (overriding only the methods of interest).
* The listener object created from that class is then registered with a
* component using the component's <code>addContainerListener</code>
* method. When the container's contents change because a component
* has been added or removed, the relevant method in the listener object
* is invoked, and the <code>ContainerEvent</code> is passed to it.
* <P>
* Container events are provided for notification purposes ONLY;
* The AWT will automatically handle add and remove operations
* internally so the program works properly regardless of
* whether the program registers a {@code ContainerListener} or not.
*
* @see ContainerAdapter
* @see ContainerEvent
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/containerlistener.html">Tutorial: Writing a Container Listener</a>
*
* @author Tim Prinzing
* @author Amy Fowler
* @since 1.1
*/
public interface ContainerListener extends EventListener {
/**
* Invoked when a component has been added to the container.
*/
public void componentAdded(ContainerEvent e);
/**
* Invoked when a component has been removed from the container.
*/
public void componentRemoved(ContainerEvent e);
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
/**
* An abstract adapter class for receiving keyboard focus events.
* The methods in this class are empty. This class exists as
* convenience for creating listener objects.
* <P>
* Extend this class to create a <code>FocusEvent</code> listener
* and override the methods for the events of interest. (If you implement the
* <code>FocusListener</code> interface, you have to define all of
* the methods in it. This abstract class defines null methods for them
* all, so you can only have to define methods for events you care about.)
* <P>
* Create a listener object using the extended class and then register it with
* a component using the component's <code>addFocusListener</code>
* method. When the component gains or loses the keyboard focus,
* the relevant method in the listener object is invoked,
* and the <code>FocusEvent</code> is passed to it.
*
* @see FocusEvent
* @see FocusListener
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/focuslistener.html">Tutorial: Writing a Focus Listener</a>
*
* @author Carl Quinn
* @since 1.1
*/
public abstract class FocusAdapter implements FocusListener {
/**
* Invoked when a component gains the keyboard focus.
*/
public void focusGained(FocusEvent e) {}
/**
* Invoked when a component loses the keyboard focus.
*/
public void focusLost(FocusEvent e) {}
}

View File

@@ -0,0 +1,249 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.awt.Component;
import sun.awt.AppContext;
import sun.awt.SunToolkit;
/**
* A low-level event which indicates that a Component has gained or lost the
* input focus. This low-level event is generated by a Component (such as a
* TextField). The event is passed to every <code>FocusListener</code> or
* <code>FocusAdapter</code> object which registered to receive such events
* using the Component's <code>addFocusListener</code> method. (<code>
* FocusAdapter</code> objects implement the <code>FocusListener</code>
* interface.) Each such listener object gets this <code>FocusEvent</code> when
* the event occurs.
* <p>
* There are two levels of focus events: permanent and temporary. Permanent
* focus change events occur when focus is directly moved from one Component to
* another, such as through a call to requestFocus() or as the user uses the
* TAB key to traverse Components. Temporary focus change events occur when
* focus is temporarily lost for a Component as the indirect result of another
* operation, such as Window deactivation or a Scrollbar drag. In this case,
* the original focus state will automatically be restored once that operation
* is finished, or, for the case of Window deactivation, when the Window is
* reactivated. Both permanent and temporary focus events are delivered using
* the FOCUS_GAINED and FOCUS_LOST event ids; the level may be distinguished in
* the event using the isTemporary() method.
* <p>
* An unspecified behavior will be caused if the {@code id} parameter
* of any particular {@code FocusEvent} instance is not
* in the range from {@code FOCUS_FIRST} to {@code FOCUS_LAST}.
*
* @see FocusAdapter
* @see FocusListener
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/focuslistener.html">Tutorial: Writing a Focus Listener</a>
*
* @author Carl Quinn
* @author Amy Fowler
* @since 1.1
*/
public class FocusEvent extends ComponentEvent {
/**
* The first number in the range of ids used for focus events.
*/
public static final int FOCUS_FIRST = 1004;
/**
* The last number in the range of ids used for focus events.
*/
public static final int FOCUS_LAST = 1005;
/**
* This event indicates that the Component is now the focus owner.
*/
public static final int FOCUS_GAINED = FOCUS_FIRST; //Event.GOT_FOCUS
/**
* This event indicates that the Component is no longer the focus owner.
*/
public static final int FOCUS_LOST = 1 + FOCUS_FIRST; //Event.LOST_FOCUS
/**
* A focus event can have two different levels, permanent and temporary.
* It will be set to true if some operation takes away the focus
* temporarily and intends on getting it back once the event is completed.
* Otherwise it will be set to false.
*
* @serial
* @see #isTemporary
*/
boolean temporary;
/**
* The other Component involved in this focus change. For a FOCUS_GAINED
* event, this is the Component that lost focus. For a FOCUS_LOST event,
* this is the Component that gained focus. If this focus change occurs
* with a native application, a Java application in a different VM, or with
* no other Component, then the opposite Component is null.
*
* @see #getOppositeComponent
* @since 1.4
*/
transient Component opposite;
/*
* JDK 1.1 serialVersionUID
*/
private static final long serialVersionUID = 523753786457416396L;
/**
* Constructs a <code>FocusEvent</code> object with the
* specified temporary state and opposite <code>Component</code>.
* The opposite <code>Component</code> is the other
* <code>Component</code> involved in this focus change.
* For a <code>FOCUS_GAINED</code> event, this is the
* <code>Component</code> that lost focus. For a
* <code>FOCUS_LOST</code> event, this is the <code>Component</code>
* that gained focus. If this focus change occurs with a native
* application, with a Java application in a different VM,
* or with no other <code>Component</code>, then the opposite
* <code>Component</code> is <code>null</code>.
* <p> This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source The <code>Component</code> that originated the event
* @param id An integer indicating the type of event.
* For information on allowable values, see
* the class description for {@link FocusEvent}
* @param temporary Equals <code>true</code> if the focus change is temporary;
* <code>false</code> otherwise
* @param opposite The other Component involved in the focus change,
* or <code>null</code>
* @throws IllegalArgumentException if <code>source</code> equals {@code null}
* @see #getSource()
* @see #getID()
* @see #isTemporary()
* @see #getOppositeComponent()
* @since 1.4
*/
public FocusEvent(Component source, int id, boolean temporary,
Component opposite) {
super(source, id);
this.temporary = temporary;
this.opposite = opposite;
}
/**
* Constructs a <code>FocusEvent</code> object and identifies
* whether or not the change is temporary.
* <p> This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source The <code>Component</code> that originated the event
* @param id An integer indicating the type of event.
* For information on allowable values, see
* the class description for {@link FocusEvent}
* @param temporary Equals <code>true</code> if the focus change is temporary;
* <code>false</code> otherwise
* @throws IllegalArgumentException if <code>source</code> equals {@code null}
* @see #getSource()
* @see #getID()
* @see #isTemporary()
*/
public FocusEvent(Component source, int id, boolean temporary) {
this(source, id, temporary, null);
}
/**
* Constructs a <code>FocusEvent</code> object and identifies it
* as a permanent change in focus.
* <p> This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source The <code>Component</code> that originated the event
* @param id An integer indicating the type of event.
* For information on allowable values, see
* the class description for {@link FocusEvent}
* @throws IllegalArgumentException if <code>source</code> equals {@code null}
* @see #getSource()
* @see #getID()
*/
public FocusEvent(Component source, int id) {
this(source, id, false);
}
/**
* Identifies the focus change event as temporary or permanent.
*
* @return <code>true</code> if the focus change is temporary;
* <code>false</code> otherwise
*/
public boolean isTemporary() {
return temporary;
}
/**
* Returns the other Component involved in this focus change. For a
* FOCUS_GAINED event, this is the Component that lost focus. For a
* FOCUS_LOST event, this is the Component that gained focus. If this
* focus change occurs with a native application, with a Java application
* in a different VM or context, or with no other Component, then null is
* returned.
*
* @return the other Component involved in the focus change, or null
* @since 1.4
*/
public Component getOppositeComponent() {
if (opposite == null) {
return null;
}
return (SunToolkit.targetToAppContext(opposite) ==
AppContext.getAppContext())
? opposite
: null;
}
/**
* Returns a parameter string identifying this event.
* This method is useful for event-logging and for debugging.
*
* @return a string identifying the event and its attributes
*/
public String paramString() {
String typeStr;
switch(id) {
case FOCUS_GAINED:
typeStr = "FOCUS_GAINED";
break;
case FOCUS_LOST:
typeStr = "FOCUS_LOST";
break;
default:
typeStr = "unknown type";
}
return typeStr + (temporary ? ",temporary" : ",permanent") +
",opposite=" + getOppositeComponent();
}
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving keyboard focus events on
* a component.
* The class that is interested in processing a focus event
* either implements this interface (and all the methods it
* contains) or extends the abstract <code>FocusAdapter</code> class
* (overriding only the methods of interest).
* The listener object created from that class is then registered with a
* component using the component's <code>addFocusListener</code>
* method. When the component gains or loses the keyboard focus,
* the relevant method in the listener object
* is invoked, and the <code>FocusEvent</code> is passed to it.
*
* @see FocusAdapter
* @see FocusEvent
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/focuslistener.html">Tutorial: Writing a Focus Listener</a>
*
* @author Carl Quinn
* @since 1.1
*/
public interface FocusListener extends EventListener {
/**
* Invoked when a component gains the keyboard focus.
*/
public void focusGained(FocusEvent e);
/**
* Invoked when a component loses the keyboard focus.
*/
public void focusLost(FocusEvent e);
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
/**
* An abstract adapter class for receiving ancestor moved and resized events.
* The methods in this class are empty. This class exists as a
* convenience for creating listener objects.
* <p>
* Extend this class and override the method for the event of interest. (If
* you implement the <code>HierarchyBoundsListener</code> interface, you have
* to define both methods in it. This abstract class defines null methods for
* them both, so you only have to define the method for the event you care
* about.)
* <p>
* Create a listener object using your class and then register it with a
* Component using the Component's <code>addHierarchyBoundsListener</code>
* method. When the hierarchy to which the Component belongs changes by
* resize or movement of an ancestor, the relevant method in the listener
* object is invoked, and the <code>HierarchyEvent</code> is passed to it.
*
* @author David Mendenhall
* @see HierarchyBoundsListener
* @see HierarchyEvent
* @since 1.3
*/
public abstract class HierarchyBoundsAdapter implements HierarchyBoundsListener
{
/**
* Called when an ancestor of the source is moved.
*/
public void ancestorMoved(HierarchyEvent e) {}
/**
* Called when an ancestor of the source is resized.
*/
public void ancestorResized(HierarchyEvent e) {}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving ancestor moved and resized events.
* The class that is interested in processing these events either implements
* this interface (and all the methods it contains) or extends the abstract
* <code>HierarchyBoundsAdapter</code> class (overriding only the method of
* interest).
* The listener object created from that class is then registered with a
* Component using the Component's <code>addHierarchyBoundsListener</code>
* method. When the hierarchy to which the Component belongs changes by
* the resizing or movement of an ancestor, the relevant method in the listener
* object is invoked, and the <code>HierarchyEvent</code> is passed to it.
* <p>
* Hierarchy events are provided for notification purposes ONLY;
* The AWT will automatically handle changes to the hierarchy internally so
* that GUI layout works properly regardless of whether a
* program registers an <code>HierarchyBoundsListener</code> or not.
*
* @author David Mendenhall
* @see HierarchyBoundsAdapter
* @see HierarchyEvent
* @since 1.3
*/
public interface HierarchyBoundsListener extends EventListener {
/**
* Called when an ancestor of the source is moved.
*/
public void ancestorMoved(HierarchyEvent e);
/**
* Called when an ancestor of the source is resized.
*/
public void ancestorResized(HierarchyEvent e);
}

View File

@@ -0,0 +1,337 @@
/*
* Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.awt.AWTEvent;
import java.awt.Component;
import java.awt.Container;
/**
* An event which indicates a change to the <code>Component</code>
* hierarchy to which <code>Component</code> belongs.
* <ul>
* <li>Hierarchy Change Events (HierarchyListener)
* <ul>
* <li> addition of an ancestor
* <li> removal of an ancestor
* <li> hierarchy made displayable
* <li> hierarchy made undisplayable
* <li> hierarchy shown on the screen (both visible and displayable)
* <li> hierarchy hidden on the screen (either invisible or undisplayable)
* </ul>
* <li>Ancestor Reshape Events (HierarchyBoundsListener)
* <ul>
* <li> an ancestor was resized
* <li> an ancestor was moved
* </ul>
* </ul>
* <p>
* Hierarchy events are provided for notification purposes ONLY.
* The AWT will automatically handle changes to the hierarchy internally so
* that GUI layout and displayability works properly regardless of whether a
* program is receiving these events or not.
* <p>
* This event is generated by a Container object (such as a Panel) when the
* Container is added, removed, moved, or resized, and passed down the
* hierarchy. It is also generated by a Component object when that object's
* <code>addNotify</code>, <code>removeNotify</code>, <code>show</code>, or
* <code>hide</code> method is called. The {@code ANCESTOR_MOVED} and
* {@code ANCESTOR_RESIZED}
* events are dispatched to every <code>HierarchyBoundsListener</code> or
* <code>HierarchyBoundsAdapter</code> object which registered to receive
* such events using the Component's <code>addHierarchyBoundsListener</code>
* method. (<code>HierarchyBoundsAdapter</code> objects implement the <code>
* HierarchyBoundsListener</code> interface.) The {@code HIERARCHY_CHANGED} events are
* dispatched to every <code>HierarchyListener</code> object which registered
* to receive such events using the Component's <code>addHierarchyListener
* </code> method. Each such listener object gets this <code>HierarchyEvent
* </code> when the event occurs.
* <p>
* An unspecified behavior will be caused if the {@code id} parameter
* of any particular {@code HierarchyEvent} instance is not
* in the range from {@code HIERARCHY_FIRST} to {@code HIERARCHY_LAST}.
* <br>
* The {@code changeFlags} parameter of any {@code HierarchyEvent} instance takes one of the following
* values:
* <ul>
* <li> {@code HierarchyEvent.PARENT_CHANGED}
* <li> {@code HierarchyEvent.DISPLAYABILITY_CHANGED}
* <li> {@code HierarchyEvent.SHOWING_CHANGED}
* </ul>
* Assigning the value different from listed above will cause unspecified behavior.
*
* @author David Mendenhall
* @see HierarchyListener
* @see HierarchyBoundsAdapter
* @see HierarchyBoundsListener
* @since 1.3
*/
public class HierarchyEvent extends AWTEvent {
/*
* serialVersionUID
*/
private static final long serialVersionUID = -5337576970038043990L;
/**
* Marks the first integer id for the range of hierarchy event ids.
*/
public static final int HIERARCHY_FIRST = 1400; // 1300 used by sun.awt.windows.ModalityEvent
/**
* The event id indicating that modification was made to the
* entire hierarchy tree.
*/
public static final int HIERARCHY_CHANGED = HIERARCHY_FIRST;
/**
* The event id indicating an ancestor-Container was moved.
*/
public static final int ANCESTOR_MOVED = 1 + HIERARCHY_FIRST;
/**
* The event id indicating an ancestor-Container was resized.
*/
public static final int ANCESTOR_RESIZED = 2 + HIERARCHY_FIRST;
/**
* Marks the last integer id for the range of ancestor event ids.
*/
public static final int HIERARCHY_LAST = ANCESTOR_RESIZED;
/**
* A change flag indicates that the <code>HIERARCHY_CHANGED</code> event
* was generated by a reparenting operation.
*/
public static final int PARENT_CHANGED = 0x1;
/**
* A change flag indicates that the <code>HIERARCHY_CHANGED</code> event
* was generated due to the changing of the hierarchy displayability.
* To discern the
* current displayability of the hierarchy, call the
* <code>Component.isDisplayable</code> method. Displayability changes occur
* in response to explicit or implicit calls of the
* <code>Component.addNotify</code> and
* <code>Component.removeNotify</code> methods.
*
* @see java.awt.Component#isDisplayable()
* @see java.awt.Component#addNotify()
* @see java.awt.Component#removeNotify()
*/
public static final int DISPLAYABILITY_CHANGED = 0x2;
/**
* A change flag indicates that the <code>HIERARCHY_CHANGED</code> event
* was generated due to the changing of the hierarchy showing state.
* To discern the
* current showing state of the hierarchy, call the
* <code>Component.isShowing</code> method. Showing state changes occur
* when either the displayability or visibility of the
* hierarchy occurs. Visibility changes occur in response to explicit
* or implicit calls of the <code>Component.show</code> and
* <code>Component.hide</code> methods.
*
* @see java.awt.Component#isShowing()
* @see java.awt.Component#addNotify()
* @see java.awt.Component#removeNotify()
* @see java.awt.Component#show()
* @see java.awt.Component#hide()
*/
public static final int SHOWING_CHANGED = 0x4;
Component changed;
Container changedParent;
long changeFlags;
/**
* Constructs an <code>HierarchyEvent</code> object to identify a
* change in the <code>Component</code> hierarchy.
* <p>This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source The <code>Component</code> object that
* originated the event
* @param id An integer indicating the type of event.
* For information on allowable values, see
* the class description for {@link HierarchyEvent}
* @param changed The <code>Component</code> at the top of
* the hierarchy which was changed
* @param changedParent The parent of the <code>changed</code> component.
* This
* may be the parent before or after the
* change, depending on the type of change
* @throws IllegalArgumentException if <code>source</code> is {@code null}
* @see #getSource()
* @see #getID()
* @see #getChanged()
* @see #getChangedParent()
*/
public HierarchyEvent(Component source, int id, Component changed,
Container changedParent) {
super(source, id);
this.changed = changed;
this.changedParent = changedParent;
}
/**
* Constructs an <code>HierarchyEvent</code> object to identify
* a change in the <code>Component</code> hierarchy.
* <p> This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source The <code>Component</code> object that
* originated the event
* @param id An integer indicating the type of event.
* For information on allowable values, see
* the class description for {@link HierarchyEvent}
* @param changed The <code>Component</code> at the top
* of the hierarchy which was changed
* @param changedParent The parent of the <code>changed</code> component.
* This
* may be the parent before or after the
* change, depending on the type of change
* @param changeFlags A bitmask which indicates the type(s) of
* the <code>HIERARCHY_CHANGED</code> events
* represented in this event object.
* For information on allowable values, see
* the class description for {@link HierarchyEvent}
* @throws IllegalArgumentException if <code>source</code> is null
* @see #getSource()
* @see #getID()
* @see #getChanged()
* @see #getChangedParent()
* @see #getChangeFlags()
*/
public HierarchyEvent(Component source, int id, Component changed,
Container changedParent, long changeFlags) {
super(source, id);
this.changed = changed;
this.changedParent = changedParent;
this.changeFlags = changeFlags;
}
/**
* Returns the originator of the event.
*
* @return the <code>Component</code> object that originated
* the event, or <code>null</code> if the object is not a
* <code>Component</code>.
*/
public Component getComponent() {
return (source instanceof Component) ? (Component)source : null;
}
/**
* Returns the Component at the top of the hierarchy which was
* changed.
*
* @return the changed Component
*/
public Component getChanged() {
return changed;
}
/**
* Returns the parent of the Component returned by <code>
* getChanged()</code>. For a HIERARCHY_CHANGED event where the
* change was of type PARENT_CHANGED via a call to <code>
* Container.add</code>, the parent returned is the parent
* after the add operation. For a HIERARCHY_CHANGED event where
* the change was of type PARENT_CHANGED via a call to <code>
* Container.remove</code>, the parent returned is the parent
* before the remove operation. For all other events and types,
* the parent returned is the parent during the operation.
*
* @return the parent of the changed Component
*/
public Container getChangedParent() {
return changedParent;
}
/**
* Returns a bitmask which indicates the type(s) of
* HIERARCHY_CHANGED events represented in this event object.
* The bits have been bitwise-ored together.
*
* @return the bitmask, or 0 if this is not an HIERARCHY_CHANGED
* event
*/
public long getChangeFlags() {
return changeFlags;
}
/**
* Returns a parameter string identifying this event.
* This method is useful for event-logging and for debugging.
*
* @return a string identifying the event and its attributes
*/
public String paramString() {
String typeStr;
switch(id) {
case ANCESTOR_MOVED:
typeStr = "ANCESTOR_MOVED ("+changed+","+changedParent+")";
break;
case ANCESTOR_RESIZED:
typeStr = "ANCESTOR_RESIZED ("+changed+","+changedParent+")";
break;
case HIERARCHY_CHANGED: {
typeStr = "HIERARCHY_CHANGED (";
boolean first = true;
if ((changeFlags & PARENT_CHANGED) != 0) {
first = false;
typeStr += "PARENT_CHANGED";
}
if ((changeFlags & DISPLAYABILITY_CHANGED) != 0) {
if (first) {
first = false;
} else {
typeStr += ",";
}
typeStr += "DISPLAYABILITY_CHANGED";
}
if ((changeFlags & SHOWING_CHANGED) != 0) {
if (first) {
first = false;
} else {
typeStr += ",";
}
typeStr += "SHOWING_CHANGED";
}
if (!first) {
typeStr += ",";
}
typeStr += changed + "," + changedParent + ")";
break;
}
default:
typeStr = "unknown type";
}
return typeStr;
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving hierarchy changed events.
* The class that is interested in processing a hierarchy changed event
* should implement this interface.
* The listener object created from that class is then registered with a
* Component using the Component's <code>addHierarchyListener</code>
* method. When the hierarchy to which the Component belongs changes, the
* <code>hierarchyChanged</code> method in the listener object is invoked,
* and the <code>HierarchyEvent</code> is passed to it.
* <p>
* Hierarchy events are provided for notification purposes ONLY;
* The AWT will automatically handle changes to the hierarchy internally so
* that GUI layout, displayability, and visibility work properly regardless
* of whether a program registers a <code>HierarchyListener</code> or not.
*
* @author David Mendenhall
* @see HierarchyEvent
* @since 1.3
*/
public interface HierarchyListener extends EventListener {
/**
* Called when the hierarchy has been changed. To discern the actual
* type of change, call <code>HierarchyEvent.getChangeFlags()</code>.
*
* @see HierarchyEvent#getChangeFlags()
*/
public void hierarchyChanged(HierarchyEvent e);
}

View File

@@ -0,0 +1,533 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.awt.Event;
import java.awt.Component;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.util.Arrays;
import sun.awt.AWTAccessor;
import sun.util.logging.PlatformLogger;
import sun.security.util.SecurityConstants;
/**
* The root event class for all component-level input events.
*
* Input events are delivered to listeners before they are
* processed normally by the source where they originated.
* This allows listeners and component subclasses to "consume"
* the event so that the source will not process them in their
* default manner. For example, consuming mousePressed events
* on a Button component will prevent the Button from being
* activated.
*
* @author Carl Quinn
*
* @see KeyEvent
* @see KeyAdapter
* @see MouseEvent
* @see MouseAdapter
* @see MouseMotionAdapter
*
* @since 1.1
*/
public abstract class InputEvent extends ComponentEvent {
private static final PlatformLogger logger = PlatformLogger.getLogger("java.awt.event.InputEvent");
/**
* The Shift key modifier constant.
* It is recommended that SHIFT_DOWN_MASK be used instead.
*/
public static final int SHIFT_MASK = Event.SHIFT_MASK;
/**
* The Control key modifier constant.
* It is recommended that CTRL_DOWN_MASK be used instead.
*/
public static final int CTRL_MASK = Event.CTRL_MASK;
/**
* The Meta key modifier constant.
* It is recommended that META_DOWN_MASK be used instead.
*/
public static final int META_MASK = Event.META_MASK;
/**
* The Alt key modifier constant.
* It is recommended that ALT_DOWN_MASK be used instead.
*/
public static final int ALT_MASK = Event.ALT_MASK;
/**
* The AltGraph key modifier constant.
*/
public static final int ALT_GRAPH_MASK = 1 << 5;
/**
* The Mouse Button1 modifier constant.
* It is recommended that BUTTON1_DOWN_MASK be used instead.
*/
public static final int BUTTON1_MASK = 1 << 4;
/**
* The Mouse Button2 modifier constant.
* It is recommended that BUTTON2_DOWN_MASK be used instead.
* Note that BUTTON2_MASK has the same value as ALT_MASK.
*/
public static final int BUTTON2_MASK = Event.ALT_MASK;
/**
* The Mouse Button3 modifier constant.
* It is recommended that BUTTON3_DOWN_MASK be used instead.
* Note that BUTTON3_MASK has the same value as META_MASK.
*/
public static final int BUTTON3_MASK = Event.META_MASK;
/**
* The Shift key extended modifier constant.
* @since 1.4
*/
public static final int SHIFT_DOWN_MASK = 1 << 6;
/**
* The Control key extended modifier constant.
* @since 1.4
*/
public static final int CTRL_DOWN_MASK = 1 << 7;
/**
* The Meta key extended modifier constant.
* @since 1.4
*/
public static final int META_DOWN_MASK = 1 << 8;
/**
* The Alt key extended modifier constant.
* @since 1.4
*/
public static final int ALT_DOWN_MASK = 1 << 9;
/**
* The Mouse Button1 extended modifier constant.
* @since 1.4
*/
public static final int BUTTON1_DOWN_MASK = 1 << 10;
/**
* The Mouse Button2 extended modifier constant.
* @since 1.4
*/
public static final int BUTTON2_DOWN_MASK = 1 << 11;
/**
* The Mouse Button3 extended modifier constant.
* @since 1.4
*/
public static final int BUTTON3_DOWN_MASK = 1 << 12;
/**
* The AltGraph key extended modifier constant.
* @since 1.4
*/
public static final int ALT_GRAPH_DOWN_MASK = 1 << 13;
/**
* An array of extended modifiers for additional buttons.
* @see getButtonDownMasks
* There are twenty buttons fit into 4byte space.
* one more bit is reserved for FIRST_HIGH_BIT.
* @since 7.0
*/
private static final int [] BUTTON_DOWN_MASK = new int [] { BUTTON1_DOWN_MASK,
BUTTON2_DOWN_MASK,
BUTTON3_DOWN_MASK,
1<<14, //4th phisical button (this is not a wheel!)
1<<15, //(this is not a wheel!)
1<<16,
1<<17,
1<<18,
1<<19,
1<<20,
1<<21,
1<<22,
1<<23,
1<<24,
1<<25,
1<<26,
1<<27,
1<<28,
1<<29,
1<<30};
/**
* A method to access an array of extended modifiers for additional buttons.
* @since 7.0
*/
private static int [] getButtonDownMasks(){
return Arrays.copyOf(BUTTON_DOWN_MASK, BUTTON_DOWN_MASK.length);
}
/**
* A method to obtain a mask for any existing mouse button.
* The returned mask may be used for different purposes. Following are some of them:
* <ul>
* <li> {@link java.awt.Robot#mousePress(int) mousePress(buttons)} and
* {@link java.awt.Robot#mouseRelease(int) mouseRelease(buttons)}
* <li> as a {@code modifiers} parameter when creating a new {@link MouseEvent} instance
* <li> to check {@link MouseEvent#getModifiersEx() modifiersEx} of existing {@code MouseEvent}
* </ul>
* @param button is a number to represent a button starting from 1.
* For example,
* <pre>
* int button = InputEvent.getMaskForButton(1);
* </pre>
* will have the same meaning as
* <pre>
* int button = InputEvent.getMaskForButton(MouseEvent.BUTTON1);
* </pre>
* because {@link MouseEvent#BUTTON1 MouseEvent.BUTTON1} equals to 1.
* If a mouse has three enabled buttons(see {@link java.awt.MouseInfo#getNumberOfButtons() MouseInfo.getNumberOfButtons()})
* then the values from the left column passed into the method will return
* corresponding values from the right column:
* <PRE>
* <b>button </b> <b>returned mask</b>
* {@link MouseEvent#BUTTON1 BUTTON1} {@link MouseEvent#BUTTON1_DOWN_MASK BUTTON1_DOWN_MASK}
* {@link MouseEvent#BUTTON2 BUTTON2} {@link MouseEvent#BUTTON2_DOWN_MASK BUTTON2_DOWN_MASK}
* {@link MouseEvent#BUTTON3 BUTTON3} {@link MouseEvent#BUTTON3_DOWN_MASK BUTTON3_DOWN_MASK}
* </PRE>
* If a mouse has more than three enabled buttons then more values
* are admissible (4, 5, etc.). There is no assigned constants for these extended buttons.
* The button masks for the extra buttons returned by this method have no assigned names like the
* first three button masks.
* <p>
* This method has the following implementation restriction.
* It returns masks for a limited number of buttons only. The maximum number is
* implementation dependent and may vary.
* This limit is defined by the relevant number
* of buttons that may hypothetically exist on the mouse but it is greater than the
* {@link java.awt.MouseInfo#getNumberOfButtons() MouseInfo.getNumberOfButtons()}.
* <p>
* @throws IllegalArgumentException if {@code button} is less than zero or greater than the number
* of button masks reserved for buttons
* @since 7.0
* @see java.awt.MouseInfo#getNumberOfButtons()
* @see Toolkit#areExtraMouseButtonsEnabled()
* @see MouseEvent#getModifiers()
* @see MouseEvent#getModifiersEx()
*/
public static int getMaskForButton(int button) {
if (button <= 0 || button > BUTTON_DOWN_MASK.length) {
throw new IllegalArgumentException("button doesn\'t exist " + button);
}
return BUTTON_DOWN_MASK[button - 1];
}
// the constant below MUST be updated if any extra modifier
// bits are to be added!
// in fact, it is undesirable to add modifier bits
// to the same field as this may break applications
// see bug# 5066958
static final int FIRST_HIGH_BIT = 1 << 31;
static final int JDK_1_3_MODIFIERS = SHIFT_DOWN_MASK - 1;
static final int HIGH_MODIFIERS = ~( FIRST_HIGH_BIT - 1 );
/**
* The input event's Time stamp in UTC format. The time stamp
* indicates when the input event was created.
*
* @serial
* @see #getWhen()
*/
long when;
/**
* The state of the modifier mask at the time the input
* event was fired.
*
* @serial
* @see #getModifiers()
* @see #getModifiersEx()
* @see java.awt.event.KeyEvent
* @see java.awt.event.MouseEvent
*/
int modifiers;
/*
* A flag that indicates that this instance can be used to access
* the system clipboard.
*/
private transient boolean canAccessSystemClipboard;
static {
/* ensure that the necessary native libraries are loaded */
NativeLibLoader.loadLibraries();
if (!GraphicsEnvironment.isHeadless()) {
initIDs();
}
AWTAccessor.setInputEventAccessor(
new AWTAccessor.InputEventAccessor() {
public int[] getButtonDownMasks() {
return InputEvent.getButtonDownMasks();
}
});
}
/**
* Initialize JNI field and method IDs for fields that may be
accessed from C.
*/
private static native void initIDs();
/**
* Constructs an InputEvent object with the specified source component,
* modifiers, and type.
* <p> This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source the object where the event originated
* @param id the integer that identifies the event type.
* It is allowed to pass as parameter any value that
* allowed for some subclass of {@code InputEvent} class.
* Passing in the value different from those values result
* in unspecified behavior
* @param when a long int that gives the time the event occurred.
* Passing negative or zero value
* is not recommended
* @param modifiers a modifier mask describing the modifier keys and mouse
* buttons (for example, shift, ctrl, alt, and meta) that
* are down during the event.
* Only extended modifiers are allowed to be used as a
* value for this parameter (see the {@link InputEvent#getModifiersEx}
* class for the description of extended modifiers).
* Passing negative parameter
* is not recommended.
* Zero value means that no modifiers were passed
* @throws IllegalArgumentException if <code>source</code> is null
* @see #getSource()
* @see #getID()
* @see #getWhen()
* @see #getModifiers()
*/
InputEvent(Component source, int id, long when, int modifiers) {
super(source, id);
this.when = when;
this.modifiers = modifiers;
canAccessSystemClipboard = canAccessSystemClipboard();
}
private boolean canAccessSystemClipboard() {
boolean b = false;
if (!GraphicsEnvironment.isHeadless()) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
try {
sm.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
b = true;
} catch (SecurityException se) {
if (logger.isLoggable(PlatformLogger.Level.FINE)) {
logger.fine("InputEvent.canAccessSystemClipboard() got SecurityException ", se);
}
}
} else {
b = true;
}
}
return b;
}
/**
* Returns whether or not the Shift modifier is down on this event.
*/
public boolean isShiftDown() {
return (modifiers & SHIFT_MASK) != 0;
}
/**
* Returns whether or not the Control modifier is down on this event.
*/
public boolean isControlDown() {
return (modifiers & CTRL_MASK) != 0;
}
/**
* Returns whether or not the Meta modifier is down on this event.
*/
public boolean isMetaDown() {
return (modifiers & META_MASK) != 0;
}
/**
* Returns whether or not the Alt modifier is down on this event.
*/
public boolean isAltDown() {
return (modifiers & ALT_MASK) != 0;
}
/**
* Returns whether or not the AltGraph modifier is down on this event.
*/
public boolean isAltGraphDown() {
return (modifiers & ALT_GRAPH_MASK) != 0;
}
/**
* Returns the difference in milliseconds between the timestamp of when this event occurred and
* midnight, January 1, 1970 UTC.
*/
public long getWhen() {
return when;
}
/**
* Returns the modifier mask for this event.
*/
public int getModifiers() {
return modifiers & (JDK_1_3_MODIFIERS | HIGH_MODIFIERS);
}
/**
* Returns the extended modifier mask for this event.
* <P>
* Extended modifiers are the modifiers that ends with the _DOWN_MASK suffix,
* such as ALT_DOWN_MASK, BUTTON1_DOWN_MASK, and others.
* <P>
* Extended modifiers represent the state of all modal keys,
* such as ALT, CTRL, META, and the mouse buttons just after
* the event occurred.
* <P>
* For example, if the user presses <b>button 1</b> followed by
* <b>button 2</b>, and then releases them in the same order,
* the following sequence of events is generated:
* <PRE>
* <code>MOUSE_PRESSED</code>: <code>BUTTON1_DOWN_MASK</code>
* <code>MOUSE_PRESSED</code>: <code>BUTTON1_DOWN_MASK | BUTTON2_DOWN_MASK</code>
* <code>MOUSE_RELEASED</code>: <code>BUTTON2_DOWN_MASK</code>
* <code>MOUSE_CLICKED</code>: <code>BUTTON2_DOWN_MASK</code>
* <code>MOUSE_RELEASED</code>:
* <code>MOUSE_CLICKED</code>:
* </PRE>
* <P>
* It is not recommended to compare the return value of this method
* using <code>==</code> because new modifiers can be added in the future.
* For example, the appropriate way to check that SHIFT and BUTTON1 are
* down, but CTRL is up is demonstrated by the following code:
* <PRE>
* int onmask = SHIFT_DOWN_MASK | BUTTON1_DOWN_MASK;
* int offmask = CTRL_DOWN_MASK;
* if ((event.getModifiersEx() &amp; (onmask | offmask)) == onmask) {
* ...
* }
* </PRE>
* The above code will work even if new modifiers are added.
*
* @since 1.4
*/
public int getModifiersEx() {
return modifiers & ~JDK_1_3_MODIFIERS;
}
/**
* Consumes this event so that it will not be processed
* in the default manner by the source which originated it.
*/
public void consume() {
consumed = true;
}
/**
* Returns whether or not this event has been consumed.
* @see #consume
*/
public boolean isConsumed() {
return consumed;
}
// state serialization compatibility with JDK 1.1
static final long serialVersionUID = -2482525981698309786L;
/**
* Returns a String describing the extended modifier keys and
* mouse buttons, such as "Shift", "Button1", or "Ctrl+Shift".
* These strings can be localized by changing the
* <code>awt.properties</code> file.
* <p>
* Note that passing negative parameter is incorrect,
* and will cause the returning an unspecified string.
* Zero parameter means that no modifiers were passed and will
* cause the returning an empty string.
*
* @param modifiers a modifier mask describing the extended
* modifier keys and mouse buttons for the event
* @return a text description of the combination of extended
* modifier keys and mouse buttons that were held down
* during the event.
* @since 1.4
*/
public static String getModifiersExText(int modifiers) {
StringBuilder buf = new StringBuilder();
if ((modifiers & InputEvent.META_DOWN_MASK) != 0) {
buf.append(Toolkit.getProperty("AWT.meta", "Meta"));
buf.append("+");
}
if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
buf.append(Toolkit.getProperty("AWT.control", "Ctrl"));
buf.append("+");
}
if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0) {
buf.append(Toolkit.getProperty("AWT.alt", "Alt"));
buf.append("+");
}
if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
buf.append(Toolkit.getProperty("AWT.shift", "Shift"));
buf.append("+");
}
if ((modifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
buf.append(Toolkit.getProperty("AWT.altGraph", "Alt Graph"));
buf.append("+");
}
int buttonNumber = 1;
for (int mask : InputEvent.BUTTON_DOWN_MASK){
if ((modifiers & mask) != 0) {
buf.append(Toolkit.getProperty("AWT.button"+buttonNumber, "Button"+buttonNumber));
buf.append("+");
}
buttonNumber++;
}
if (buf.length() > 0) {
buf.setLength(buf.length()-1); // remove trailing '+'
}
return buf.toString();
}
}

View File

@@ -0,0 +1,442 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import sun.awt.AWTAccessor;
import sun.awt.AppContext;
import sun.awt.SunToolkit;
import java.awt.AWTEvent;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.font.TextHitInfo;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.text.AttributedCharacterIterator;
import java.text.CharacterIterator;
import java.lang.annotation.Native;
/**
* Input method events contain information about text that is being
* composed using an input method. Whenever the text changes, the
* input method sends an event. If the text component that's currently
* using the input method is an active client, the event is dispatched
* to that component. Otherwise, it is dispatched to a separate
* composition window.
*
* <p>
* The text included with the input method event consists of two parts:
* committed text and composed text. Either part may be empty. The two
* parts together replace any uncommitted composed text sent in previous events,
* or the currently selected committed text.
* Committed text should be integrated into the text component's persistent
* data, it will not be sent again. Composed text may be sent repeatedly,
* with changes to reflect the user's editing operations. Committed text
* always precedes composed text.
*
* @author JavaSoft Asia/Pacific
* @since 1.2
*/
public class InputMethodEvent extends AWTEvent {
/**
* Serial Version ID.
*/
private static final long serialVersionUID = 4727190874778922661L;
/**
* Marks the first integer id for the range of input method event ids.
*/
@Native public static final int INPUT_METHOD_FIRST = 1100;
/**
* The event type indicating changed input method text. This event is
* generated by input methods while processing input.
*/
@Native public static final int INPUT_METHOD_TEXT_CHANGED = INPUT_METHOD_FIRST;
/**
* The event type indicating a changed insertion point in input method text.
* This event is
* generated by input methods while processing input if only the caret changed.
*/
@Native public static final int CARET_POSITION_CHANGED = INPUT_METHOD_FIRST + 1;
/**
* Marks the last integer id for the range of input method event ids.
*/
@Native public static final int INPUT_METHOD_LAST = INPUT_METHOD_FIRST + 1;
/**
* The time stamp that indicates when the event was created.
*
* @serial
* @see #getWhen
* @since 1.4
*/
long when;
// Text object
private transient AttributedCharacterIterator text;
private transient int committedCharacterCount;
private transient TextHitInfo caret;
private transient TextHitInfo visiblePosition;
/**
* Constructs an <code>InputMethodEvent</code> with the specified
* source component, type, time, text, caret, and visiblePosition.
* <p>
* The offsets of caret and visiblePosition are relative to the current
* composed text; that is, the composed text within <code>text</code>
* if this is an <code>INPUT_METHOD_TEXT_CHANGED</code> event,
* the composed text within the <code>text</code> of the
* preceding <code>INPUT_METHOD_TEXT_CHANGED</code> event otherwise.
* <p>Note that passing in an invalid <code>id</code> results in
* unspecified behavior. This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source the object where the event originated
* @param id the event type
* @param when a long integer that specifies the time the event occurred
* @param text the combined committed and composed text,
* committed text first; must be <code>null</code>
* when the event type is <code>CARET_POSITION_CHANGED</code>;
* may be <code>null</code> for
* <code>INPUT_METHOD_TEXT_CHANGED</code> if there's no
* committed or composed text
* @param committedCharacterCount the number of committed
* characters in the text
* @param caret the caret (a.k.a. insertion point);
* <code>null</code> if there's no caret within current
* composed text
* @param visiblePosition the position that's most important
* to be visible; <code>null</code> if there's no
* recommendation for a visible position within current
* composed text
* @throws IllegalArgumentException if <code>id</code> is not
* in the range
* <code>INPUT_METHOD_FIRST</code>..<code>INPUT_METHOD_LAST</code>;
* or if id is <code>CARET_POSITION_CHANGED</code> and
* <code>text</code> is not <code>null</code>;
* or if <code>committedCharacterCount</code> is not in the range
* <code>0</code>..<code>(text.getEndIndex() - text.getBeginIndex())</code>
* @throws IllegalArgumentException if <code>source</code> is null
*
* @since 1.4
*/
public InputMethodEvent(Component source, int id, long when,
AttributedCharacterIterator text, int committedCharacterCount,
TextHitInfo caret, TextHitInfo visiblePosition) {
super(source, id);
if (id < INPUT_METHOD_FIRST || id > INPUT_METHOD_LAST) {
throw new IllegalArgumentException("id outside of valid range");
}
if (id == CARET_POSITION_CHANGED && text != null) {
throw new IllegalArgumentException("text must be null for CARET_POSITION_CHANGED");
}
this.when = when;
this.text = text;
int textLength = 0;
if (text != null) {
textLength = text.getEndIndex() - text.getBeginIndex();
}
if (committedCharacterCount < 0 || committedCharacterCount > textLength) {
throw new IllegalArgumentException("committedCharacterCount outside of valid range");
}
this.committedCharacterCount = committedCharacterCount;
this.caret = caret;
this.visiblePosition = visiblePosition;
}
/**
* Constructs an <code>InputMethodEvent</code> with the specified
* source component, type, text, caret, and visiblePosition.
* <p>
* The offsets of caret and visiblePosition are relative to the current
* composed text; that is, the composed text within <code>text</code>
* if this is an <code>INPUT_METHOD_TEXT_CHANGED</code> event,
* the composed text within the <code>text</code> of the
* preceding <code>INPUT_METHOD_TEXT_CHANGED</code> event otherwise.
* The time stamp for this event is initialized by invoking
* {@link java.awt.EventQueue#getMostRecentEventTime()}.
* <p>Note that passing in an invalid <code>id</code> results in
* unspecified behavior. This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source the object where the event originated
* @param id the event type
* @param text the combined committed and composed text,
* committed text first; must be <code>null</code>
* when the event type is <code>CARET_POSITION_CHANGED</code>;
* may be <code>null</code> for
* <code>INPUT_METHOD_TEXT_CHANGED</code> if there's no
* committed or composed text
* @param committedCharacterCount the number of committed
* characters in the text
* @param caret the caret (a.k.a. insertion point);
* <code>null</code> if there's no caret within current
* composed text
* @param visiblePosition the position that's most important
* to be visible; <code>null</code> if there's no
* recommendation for a visible position within current
* composed text
* @throws IllegalArgumentException if <code>id</code> is not
* in the range
* <code>INPUT_METHOD_FIRST</code>..<code>INPUT_METHOD_LAST</code>;
* or if id is <code>CARET_POSITION_CHANGED</code> and
* <code>text</code> is not <code>null</code>;
* or if <code>committedCharacterCount</code> is not in the range
* <code>0</code>..<code>(text.getEndIndex() - text.getBeginIndex())</code>
* @throws IllegalArgumentException if <code>source</code> is null
*/
public InputMethodEvent(Component source, int id,
AttributedCharacterIterator text, int committedCharacterCount,
TextHitInfo caret, TextHitInfo visiblePosition) {
this(source, id,
getMostRecentEventTimeForSource(source),
text, committedCharacterCount,
caret, visiblePosition);
}
/**
* Constructs an <code>InputMethodEvent</code> with the
* specified source component, type, caret, and visiblePosition.
* The text is set to <code>null</code>,
* <code>committedCharacterCount</code> to 0.
* <p>
* The offsets of <code>caret</code> and <code>visiblePosition</code>
* are relative to the current composed text; that is,
* the composed text within the <code>text</code> of the
* preceding <code>INPUT_METHOD_TEXT_CHANGED</code> event if the
* event being constructed as a <code>CARET_POSITION_CHANGED</code> event.
* For an <code>INPUT_METHOD_TEXT_CHANGED</code> event without text,
* <code>caret</code> and <code>visiblePosition</code> must be
* <code>null</code>.
* The time stamp for this event is initialized by invoking
* {@link java.awt.EventQueue#getMostRecentEventTime()}.
* <p>Note that passing in an invalid <code>id</code> results in
* unspecified behavior. This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source the object where the event originated
* @param id the event type
* @param caret the caret (a.k.a. insertion point);
* <code>null</code> if there's no caret within current
* composed text
* @param visiblePosition the position that's most important
* to be visible; <code>null</code> if there's no
* recommendation for a visible position within current
* composed text
* @throws IllegalArgumentException if <code>id</code> is not
* in the range
* <code>INPUT_METHOD_FIRST</code>..<code>INPUT_METHOD_LAST</code>
* @throws IllegalArgumentException if <code>source</code> is null
*/
public InputMethodEvent(Component source, int id, TextHitInfo caret,
TextHitInfo visiblePosition) {
this(source, id,
getMostRecentEventTimeForSource(source),
null, 0, caret, visiblePosition);
}
/**
* Gets the combined committed and composed text.
* Characters from index 0 to index <code>getCommittedCharacterCount() - 1</code> are committed
* text, the remaining characters are composed text.
*
* @return the text.
* Always null for CARET_POSITION_CHANGED;
* may be null for INPUT_METHOD_TEXT_CHANGED if there's no composed or committed text.
*/
public AttributedCharacterIterator getText() {
return text;
}
/**
* Gets the number of committed characters in the text.
*/
public int getCommittedCharacterCount() {
return committedCharacterCount;
}
/**
* Gets the caret.
* <p>
* The offset of the caret is relative to the current
* composed text; that is, the composed text within getText()
* if this is an <code>INPUT_METHOD_TEXT_CHANGED</code> event,
* the composed text within getText() of the
* preceding <code>INPUT_METHOD_TEXT_CHANGED</code> event otherwise.
*
* @return the caret (a.k.a. insertion point).
* Null if there's no caret within current composed text.
*/
public TextHitInfo getCaret() {
return caret;
}
/**
* Gets the position that's most important to be visible.
* <p>
* The offset of the visible position is relative to the current
* composed text; that is, the composed text within getText()
* if this is an <code>INPUT_METHOD_TEXT_CHANGED</code> event,
* the composed text within getText() of the
* preceding <code>INPUT_METHOD_TEXT_CHANGED</code> event otherwise.
*
* @return the position that's most important to be visible.
* Null if there's no recommendation for a visible position within current composed text.
*/
public TextHitInfo getVisiblePosition() {
return visiblePosition;
}
/**
* Consumes this event so that it will not be processed
* in the default manner by the source which originated it.
*/
public void consume() {
consumed = true;
}
/**
* Returns whether or not this event has been consumed.
* @see #consume
*/
public boolean isConsumed() {
return consumed;
}
/**
* Returns the time stamp of when this event occurred.
*
* @return this event's timestamp
* @since 1.4
*/
public long getWhen() {
return when;
}
/**
* Returns a parameter string identifying this event.
* This method is useful for event-logging and for debugging.
* It contains the event ID in text form, the characters of the
* committed and composed text
* separated by "+", the number of committed characters,
* the caret, and the visible position.
*
* @return a string identifying the event and its attributes
*/
public String paramString() {
String typeStr;
switch(id) {
case INPUT_METHOD_TEXT_CHANGED:
typeStr = "INPUT_METHOD_TEXT_CHANGED";
break;
case CARET_POSITION_CHANGED:
typeStr = "CARET_POSITION_CHANGED";
break;
default:
typeStr = "unknown type";
}
String textString;
if (text == null) {
textString = "no text";
} else {
StringBuilder textBuffer = new StringBuilder("\"");
int committedCharacterCount = this.committedCharacterCount;
char c = text.first();
while (committedCharacterCount-- > 0) {
textBuffer.append(c);
c = text.next();
}
textBuffer.append("\" + \"");
while (c != CharacterIterator.DONE) {
textBuffer.append(c);
c = text.next();
}
textBuffer.append("\"");
textString = textBuffer.toString();
}
String countString = committedCharacterCount + " characters committed";
String caretString;
if (caret == null) {
caretString = "no caret";
} else {
caretString = "caret: " + caret.toString();
}
String visiblePositionString;
if (visiblePosition == null) {
visiblePositionString = "no visible position";
} else {
visiblePositionString = "visible position: " + visiblePosition.toString();
}
return typeStr + ", " + textString + ", " + countString + ", " + caretString + ", " + visiblePositionString;
}
/**
* Initializes the <code>when</code> field if it is not present in the
* object input stream. In that case, the field will be initialized by
* invoking {@link java.awt.EventQueue#getMostRecentEventTime()}.
*/
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
s.defaultReadObject();
if (when == 0) {
// Can't use getMostRecentEventTimeForSource because source is always null during deserialization
when = EventQueue.getMostRecentEventTime();
}
}
/**
* Get the most recent event time in the {@code EventQueue} which the {@code source}
* belongs to.
*
* @param source the source of the event
* @exception IllegalArgumentException if source is null.
* @return most recent event time in the {@code EventQueue}
*/
private static long getMostRecentEventTimeForSource(Object source) {
if (source == null) {
// throw the IllegalArgumentException to conform to EventObject spec
throw new IllegalArgumentException("null source");
}
AppContext appContext = SunToolkit.targetToAppContext(source);
EventQueue eventQueue = SunToolkit.getSystemEventQueueImplPP(appContext);
return AWTAccessor.getEventQueueAccessor().getMostRecentEventTime(eventQueue);
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 1997, 1999, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving input method events. A text editing
* component has to install an input method event listener in order to work
* with input methods.
*
* <p>
* The text editing component also has to provide an instance of InputMethodRequests.
*
* @author JavaSoft Asia/Pacific
* @see InputMethodEvent
* @see java.awt.im.InputMethodRequests
* @since 1.2
*/
public interface InputMethodListener extends EventListener {
/**
* Invoked when the text entered through an input method has changed.
*/
void inputMethodTextChanged(InputMethodEvent event);
/**
* Invoked when the caret within composed text has changed.
*/
void caretPositionChanged(InputMethodEvent event);
}

View File

@@ -0,0 +1,424 @@
/*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import sun.awt.AWTAccessor;
import java.awt.ActiveEvent;
import java.awt.AWTEvent;
/**
* An event which executes the <code>run()</code> method on a <code>Runnable
* </code> when dispatched by the AWT event dispatcher thread. This class can
* be used as a reference implementation of <code>ActiveEvent</code> rather
* than declaring a new class and defining <code>dispatch()</code>.<p>
*
* Instances of this class are placed on the <code>EventQueue</code> by calls
* to <code>invokeLater</code> and <code>invokeAndWait</code>. Client code
* can use this fact to write replacement functions for <code>invokeLater
* </code> and <code>invokeAndWait</code> without writing special-case code
* in any <code>AWTEventListener</code> objects.
* <p>
* An unspecified behavior will be caused if the {@code id} parameter
* of any particular {@code InvocationEvent} instance is not
* in the range from {@code INVOCATION_FIRST} to {@code INVOCATION_LAST}.
*
* @author Fred Ecks
* @author David Mendenhall
*
* @see java.awt.ActiveEvent
* @see java.awt.EventQueue#invokeLater
* @see java.awt.EventQueue#invokeAndWait
* @see AWTEventListener
*
* @since 1.2
*/
public class InvocationEvent extends AWTEvent implements ActiveEvent {
static {
AWTAccessor.setInvocationEventAccessor(new AWTAccessor.InvocationEventAccessor() {
@Override
public void dispose(InvocationEvent invocationEvent) {
invocationEvent.finishedDispatching(false);
}
});
}
/**
* Marks the first integer id for the range of invocation event ids.
*/
public static final int INVOCATION_FIRST = 1200;
/**
* The default id for all InvocationEvents.
*/
public static final int INVOCATION_DEFAULT = INVOCATION_FIRST;
/**
* Marks the last integer id for the range of invocation event ids.
*/
public static final int INVOCATION_LAST = INVOCATION_DEFAULT;
/**
* The Runnable whose run() method will be called.
*/
protected Runnable runnable;
/**
* The (potentially null) Object whose notifyAll() method will be called
* immediately after the Runnable.run() method has returned or thrown an exception
* or after the event was disposed.
*
* @see #isDispatched
*/
protected volatile Object notifier;
/**
* The (potentially null) Runnable whose run() method will be called
* immediately after the event was dispatched or disposed.
*
* @see #isDispatched
* @since 1.8
*/
private final Runnable listener;
/**
* Indicates whether the <code>run()</code> method of the <code>runnable</code>
* was executed or not.
*
* @see #isDispatched
* @since 1.7
*/
private volatile boolean dispatched = false;
/**
* Set to true if dispatch() catches Throwable and stores it in the
* exception instance variable. If false, Throwables are propagated up
* to the EventDispatchThread's dispatch loop.
*/
protected boolean catchExceptions;
/**
* The (potentially null) Exception thrown during execution of the
* Runnable.run() method. This variable will also be null if a particular
* instance does not catch exceptions.
*/
private Exception exception = null;
/**
* The (potentially null) Throwable thrown during execution of the
* Runnable.run() method. This variable will also be null if a particular
* instance does not catch exceptions.
*/
private Throwable throwable = null;
/**
* The timestamp of when this event occurred.
*
* @serial
* @see #getWhen
*/
private long when;
/*
* JDK 1.1 serialVersionUID.
*/
private static final long serialVersionUID = 436056344909459450L;
/**
* Constructs an <code>InvocationEvent</code> with the specified
* source which will execute the runnable's <code>run</code>
* method when dispatched.
* <p>This is a convenience constructor. An invocation of the form
* <tt>InvocationEvent(source, runnable)</tt>
* behaves in exactly the same way as the invocation of
* <tt>{@link #InvocationEvent(Object, Runnable, Object, boolean) InvocationEvent}(source, runnable, null, false)</tt>.
* <p> This method throws an <code>IllegalArgumentException</code>
* if <code>source</code> is <code>null</code>.
*
* @param source The <code>Object</code> that originated the event
* @param runnable The <code>Runnable</code> whose <code>run</code>
* method will be executed
* @throws IllegalArgumentException if <code>source</code> is null
*
* @see #getSource()
* @see #InvocationEvent(Object, Runnable, Object, boolean)
*/
public InvocationEvent(Object source, Runnable runnable) {
this(source, INVOCATION_DEFAULT, runnable, null, null, false);
}
/**
* Constructs an <code>InvocationEvent</code> with the specified
* source which will execute the runnable's <code>run</code>
* method when dispatched. If notifier is non-<code>null</code>,
* <code>notifyAll()</code> will be called on it
* immediately after <code>run</code> has returned or thrown an exception.
* <p>An invocation of the form <tt>InvocationEvent(source,
* runnable, notifier, catchThrowables)</tt>
* behaves in exactly the same way as the invocation of
* <tt>{@link #InvocationEvent(Object, int, Runnable, Object, boolean) InvocationEvent}(source, InvocationEvent.INVOCATION_DEFAULT, runnable, notifier, catchThrowables)</tt>.
* <p>This method throws an <code>IllegalArgumentException</code>
* if <code>source</code> is <code>null</code>.
*
* @param source The <code>Object</code> that originated
* the event
* @param runnable The <code>Runnable</code> whose
* <code>run</code> method will be
* executed
* @param notifier The {@code Object} whose <code>notifyAll</code>
* method will be called after
* <code>Runnable.run</code> has returned or
* thrown an exception or after the event was
* disposed
* @param catchThrowables Specifies whether <code>dispatch</code>
* should catch Throwable when executing
* the <code>Runnable</code>'s <code>run</code>
* method, or should instead propagate those
* Throwables to the EventDispatchThread's
* dispatch loop
* @throws IllegalArgumentException if <code>source</code> is null
*
* @see #getSource()
* @see #InvocationEvent(Object, int, Runnable, Object, boolean)
*/
public InvocationEvent(Object source, Runnable runnable, Object notifier,
boolean catchThrowables) {
this(source, INVOCATION_DEFAULT, runnable, notifier, null, catchThrowables);
}
/**
* Constructs an <code>InvocationEvent</code> with the specified
* source which will execute the runnable's <code>run</code>
* method when dispatched. If listener is non-<code>null</code>,
* <code>listener.run()</code> will be called immediately after
* <code>run</code> has returned, thrown an exception or the event
* was disposed.
* <p>This method throws an <code>IllegalArgumentException</code>
* if <code>source</code> is <code>null</code>.
*
* @param source The <code>Object</code> that originated
* the event
* @param runnable The <code>Runnable</code> whose
* <code>run</code> method will be
* executed
* @param listener The <code>Runnable</code>Runnable whose
* <code>run()</code> method will be called
* after the {@code InvocationEvent}
* was dispatched or disposed
* @param catchThrowables Specifies whether <code>dispatch</code>
* should catch Throwable when executing
* the <code>Runnable</code>'s <code>run</code>
* method, or should instead propagate those
* Throwables to the EventDispatchThread's
* dispatch loop
* @throws IllegalArgumentException if <code>source</code> is null
*/
public InvocationEvent(Object source, Runnable runnable, Runnable listener,
boolean catchThrowables) {
this(source, INVOCATION_DEFAULT, runnable, null, listener, catchThrowables);
}
/**
* Constructs an <code>InvocationEvent</code> with the specified
* source and ID which will execute the runnable's <code>run</code>
* method when dispatched. If notifier is non-<code>null</code>,
* <code>notifyAll</code> will be called on it immediately after
* <code>run</code> has returned or thrown an exception.
* <p>This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source The <code>Object</code> that originated
* the event
* @param id An integer indicating the type of event.
* For information on allowable values, see
* the class description for {@link InvocationEvent}
* @param runnable The <code>Runnable</code> whose
* <code>run</code> method will be executed
* @param notifier The <code>Object</code> whose <code>notifyAll</code>
* method will be called after
* <code>Runnable.run</code> has returned or
* thrown an exception or after the event was
* disposed
* @param catchThrowables Specifies whether <code>dispatch</code>
* should catch Throwable when executing the
* <code>Runnable</code>'s <code>run</code>
* method, or should instead propagate those
* Throwables to the EventDispatchThread's
* dispatch loop
* @throws IllegalArgumentException if <code>source</code> is null
* @see #getSource()
* @see #getID()
*/
protected InvocationEvent(Object source, int id, Runnable runnable,
Object notifier, boolean catchThrowables) {
this(source, id, runnable, notifier, null, catchThrowables);
}
private InvocationEvent(Object source, int id, Runnable runnable,
Object notifier, Runnable listener, boolean catchThrowables) {
super(source, id);
this.runnable = runnable;
this.notifier = notifier;
this.listener = listener;
this.catchExceptions = catchThrowables;
this.when = System.currentTimeMillis();
}
/**
* Executes the Runnable's <code>run()</code> method and notifies the
* notifier (if any) when <code>run()</code> has returned or thrown an exception.
*
* @see #isDispatched
*/
public void dispatch() {
try {
if (catchExceptions) {
try {
runnable.run();
}
catch (Throwable t) {
if (t instanceof Exception) {
exception = (Exception) t;
}
throwable = t;
}
}
else {
runnable.run();
}
} finally {
finishedDispatching(true);
}
}
/**
* Returns any Exception caught while executing the Runnable's <code>run()
* </code> method.
*
* @return A reference to the Exception if one was thrown; null if no
* Exception was thrown or if this InvocationEvent does not
* catch exceptions
*/
public Exception getException() {
return (catchExceptions) ? exception : null;
}
/**
* Returns any Throwable caught while executing the Runnable's <code>run()
* </code> method.
*
* @return A reference to the Throwable if one was thrown; null if no
* Throwable was thrown or if this InvocationEvent does not
* catch Throwables
* @since 1.5
*/
public Throwable getThrowable() {
return (catchExceptions) ? throwable : null;
}
/**
* Returns the timestamp of when this event occurred.
*
* @return this event's timestamp
* @since 1.4
*/
public long getWhen() {
return when;
}
/**
* Returns {@code true} if the event is dispatched or any exception is
* thrown while dispatching, {@code false} otherwise. The method should
* be called by a waiting thread that calls the {@code notifier.wait()} method.
* Since spurious wakeups are possible (as explained in {@link Object#wait()}),
* this method should be used in a waiting loop to ensure that the event
* got dispatched:
* <pre>
* while (!event.isDispatched()) {
* notifier.wait();
* }
* </pre>
* If the waiting thread wakes up without dispatching the event,
* the {@code isDispatched()} method returns {@code false}, and
* the {@code while} loop executes once more, thus, causing
* the awakened thread to revert to the waiting mode.
* <p>
* If the {@code notifier.notifyAll()} happens before the waiting thread
* enters the {@code notifier.wait()} method, the {@code while} loop ensures
* that the waiting thread will not enter the {@code notifier.wait()} method.
* Otherwise, there is no guarantee that the waiting thread will ever be woken
* from the wait.
*
* @return {@code true} if the event has been dispatched, or any exception
* has been thrown while dispatching, {@code false} otherwise
* @see #dispatch
* @see #notifier
* @see #catchExceptions
* @since 1.7
*/
public boolean isDispatched() {
return dispatched;
}
/**
* Called when the event was dispatched or disposed
* @param dispatched true if the event was dispatched
* false if the event was disposed
*/
private void finishedDispatching(boolean dispatched) {
this.dispatched = dispatched;
if (notifier != null) {
synchronized (notifier) {
notifier.notifyAll();
}
}
if (listener != null) {
listener.run();
}
}
/**
* Returns a parameter string identifying this event.
* This method is useful for event-logging and for debugging.
*
* @return A string identifying the event and its attributes
*/
public String paramString() {
String typeStr;
switch(id) {
case INVOCATION_DEFAULT:
typeStr = "INVOCATION_DEFAULT";
break;
default:
typeStr = "unknown type";
}
return typeStr + ",runnable=" + runnable + ",notifier=" + notifier +
",catchExceptions=" + catchExceptions + ",when=" + when;
}
}

View File

@@ -0,0 +1,202 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.awt.AWTEvent;
import java.awt.ItemSelectable;
/**
* A semantic event which indicates that an item was selected or deselected.
* This high-level event is generated by an ItemSelectable object (such as a
* List) when an item is selected or deselected by the user.
* The event is passed to every <code>ItemListener</code> object which
* registered to receive such events using the component's
* <code>addItemListener</code> method.
* <P>
* The object that implements the <code>ItemListener</code> interface gets
* this <code>ItemEvent</code> when the event occurs. The listener is
* spared the details of processing individual mouse movements and mouse
* clicks, and can instead process a "meaningful" (semantic) event like
* "item selected" or "item deselected".
* <p>
* An unspecified behavior will be caused if the {@code id} parameter
* of any particular {@code ItemEvent} instance is not
* in the range from {@code ITEM_FIRST} to {@code ITEM_LAST}.
* <p>
* The {@code stateChange} of any {@code ItemEvent} instance takes one of the following
* values:
* <ul>
* <li> {@code ItemEvent.SELECTED}
* <li> {@code ItemEvent.DESELECTED}
* </ul>
* Assigning the value different from listed above will cause an unspecified behavior.
*
* @author Carl Quinn
*
* @see java.awt.ItemSelectable
* @see ItemListener
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/itemlistener.html">Tutorial: Writing an Item Listener</a>
*
* @since 1.1
*/
public class ItemEvent extends AWTEvent {
/**
* The first number in the range of ids used for item events.
*/
public static final int ITEM_FIRST = 701;
/**
* The last number in the range of ids used for item events.
*/
public static final int ITEM_LAST = 701;
/**
* This event id indicates that an item's state changed.
*/
public static final int ITEM_STATE_CHANGED = ITEM_FIRST; //Event.LIST_SELECT
/**
* This state-change value indicates that an item was selected.
*/
public static final int SELECTED = 1;
/**
* This state-change-value indicates that a selected item was deselected.
*/
public static final int DESELECTED = 2;
/**
* The item whose selection state has changed.
*
* @serial
* @see #getItem()
*/
Object item;
/**
* <code>stateChange</code> indicates whether the <code>item</code>
* was selected or deselected.
*
* @serial
* @see #getStateChange()
*/
int stateChange;
/*
* JDK 1.1 serialVersionUID
*/
private static final long serialVersionUID = -608708132447206933L;
/**
* Constructs an <code>ItemEvent</code> object.
* <p> This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source The <code>ItemSelectable</code> object
* that originated the event
* @param id The integer that identifies the event type.
* For information on allowable values, see
* the class description for {@link ItemEvent}
* @param item An object -- the item affected by the event
* @param stateChange An integer that indicates whether the item was
* selected or deselected.
* For information on allowable values, see
* the class description for {@link ItemEvent}
* @throws IllegalArgumentException if <code>source</code> is null
* @see #getItemSelectable()
* @see #getID()
* @see #getStateChange()
*/
public ItemEvent(ItemSelectable source, int id, Object item, int stateChange) {
super(source, id);
this.item = item;
this.stateChange = stateChange;
}
/**
* Returns the originator of the event.
*
* @return the ItemSelectable object that originated the event.
*/
public ItemSelectable getItemSelectable() {
return (ItemSelectable)source;
}
/**
* Returns the item affected by the event.
*
* @return the item (object) that was affected by the event
*/
public Object getItem() {
return item;
}
/**
* Returns the type of state change (selected or deselected).
*
* @return an integer that indicates whether the item was selected
* or deselected
*
* @see #SELECTED
* @see #DESELECTED
*/
public int getStateChange() {
return stateChange;
}
/**
* Returns a parameter string identifying this item event.
* This method is useful for event-logging and for debugging.
*
* @return a string identifying the event and its attributes
*/
public String paramString() {
String typeStr;
switch(id) {
case ITEM_STATE_CHANGED:
typeStr = "ITEM_STATE_CHANGED";
break;
default:
typeStr = "unknown type";
}
String stateStr;
switch(stateChange) {
case SELECTED:
stateStr = "SELECTED";
break;
case DESELECTED:
stateStr = "DESELECTED";
break;
default:
stateStr = "unknown type";
}
return typeStr + ",item="+item + ",stateChange="+stateStr;
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving item events.
* The class that is interested in processing an item event
* implements this interface. The object created with that
* class is then registered with a component using the
* component's <code>addItemListener</code> method. When an
* item-selection event occurs, the listener object's
* <code>itemStateChanged</code> method is invoked.
*
* @author Amy Fowler
*
* @see java.awt.ItemSelectable
* @see ItemEvent
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/itemlistener.html">Tutorial: Writing an Item Listener</a>
*
* @since 1.1
*/
public interface ItemListener extends EventListener {
/**
* Invoked when an item has been selected or deselected by the user.
* The code written for this method performs the operations
* that need to occur when an item is selected (or deselected).
*/
void itemStateChanged(ItemEvent e);
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
/**
* An abstract adapter class for receiving keyboard events.
* The methods in this class are empty. This class exists as
* convenience for creating listener objects.
* <P>
* Extend this class to create a <code>KeyEvent</code> listener
* and override the methods for the events of interest. (If you implement the
* <code>KeyListener</code> interface, you have to define all of
* the methods in it. This abstract class defines null methods for them
* all, so you can only have to define methods for events you care about.)
* <P>
* Create a listener object using the extended class and then register it with
* a component using the component's <code>addKeyListener</code>
* method. When a key is pressed, released, or typed,
* the relevant method in the listener object is invoked,
* and the <code>KeyEvent</code> is passed to it.
*
* @author Carl Quinn
*
* @see KeyEvent
* @see KeyListener
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html">Tutorial: Writing a Key Listener</a>
*
* @since 1.1
*/
public abstract class KeyAdapter implements KeyListener {
/**
* Invoked when a key has been typed.
* This event occurs when a key press is followed by a key release.
*/
public void keyTyped(KeyEvent e) {}
/**
* Invoked when a key has been pressed.
*/
public void keyPressed(KeyEvent e) {}
/**
* Invoked when a key has been released.
*/
public void keyReleased(KeyEvent e) {}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,73 @@
/*
* Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving keyboard events (keystrokes).
* The class that is interested in processing a keyboard event
* either implements this interface (and all the methods it
* contains) or extends the abstract <code>KeyAdapter</code> class
* (overriding only the methods of interest).
* <P>
* The listener object created from that class is then registered with a
* component using the component's <code>addKeyListener</code>
* method. A keyboard event is generated when a key is pressed, released,
* or typed. The relevant method in the listener
* object is then invoked, and the <code>KeyEvent</code> is passed to it.
*
* @author Carl Quinn
*
* @see KeyAdapter
* @see KeyEvent
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html">Tutorial: Writing a Key Listener</a>
*
* @since 1.1
*/
public interface KeyListener extends EventListener {
/**
* Invoked when a key has been typed.
* See the class description for {@link KeyEvent} for a definition of
* a key typed event.
*/
public void keyTyped(KeyEvent e);
/**
* Invoked when a key has been pressed.
* See the class description for {@link KeyEvent} for a definition of
* a key pressed event.
*/
public void keyPressed(KeyEvent e);
/**
* Invoked when a key has been released.
* See the class description for {@link KeyEvent} for a definition of
* a key released event.
*/
public void keyReleased(KeyEvent e);
}

View File

@@ -0,0 +1,113 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
/**
* An abstract adapter class for receiving mouse events.
* The methods in this class are empty. This class exists as
* convenience for creating listener objects.
* <P>
* Mouse events let you track when a mouse is pressed, released, clicked,
* moved, dragged, when it enters a component, when it exits and
* when a mouse wheel is moved.
* <P>
* Extend this class to create a {@code MouseEvent}
* (including drag and motion events) or/and {@code MouseWheelEvent}
* listener and override the methods for the events of interest. (If you implement the
* {@code MouseListener},
* {@code MouseMotionListener}
* interface, you have to define all of
* the methods in it. This abstract class defines null methods for them
* all, so you can only have to define methods for events you care about.)
* <P>
* Create a listener object using the extended class and then register it with
* a component using the component's {@code addMouseListener}
* {@code addMouseMotionListener}, {@code addMouseWheelListener}
* methods.
* The relevant method in the listener object is invoked and the {@code MouseEvent}
* or {@code MouseWheelEvent} is passed to it in following cases:
* <ul>
* <li>when a mouse button is pressed, released, or clicked (pressed and released)
* <li>when the mouse cursor enters or exits the component
* <li>when the mouse wheel rotated, or mouse moved or dragged
* </ul>
*
* @author Carl Quinn
* @author Andrei Dmitriev
*
* @see MouseEvent
* @see MouseWheelEvent
* @see MouseListener
* @see MouseMotionListener
* @see MouseWheelListener
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/mouselistener.html">Tutorial: Writing a Mouse Listener</a>
*
* @since 1.1
*/
public abstract class MouseAdapter implements MouseListener, MouseWheelListener, MouseMotionListener {
/**
* {@inheritDoc}
*/
public void mouseClicked(MouseEvent e) {}
/**
* {@inheritDoc}
*/
public void mousePressed(MouseEvent e) {}
/**
* {@inheritDoc}
*/
public void mouseReleased(MouseEvent e) {}
/**
* {@inheritDoc}
*/
public void mouseEntered(MouseEvent e) {}
/**
* {@inheritDoc}
*/
public void mouseExited(MouseEvent e) {}
/**
* {@inheritDoc}
* @since 1.6
*/
public void mouseWheelMoved(MouseWheelEvent e){}
/**
* {@inheritDoc}
* @since 1.6
*/
public void mouseDragged(MouseEvent e){}
/**
* {@inheritDoc}
* @since 1.6
*/
public void mouseMoved(MouseEvent e){}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,84 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving "interesting" mouse events
* (press, release, click, enter, and exit) on a component.
* (To track mouse moves and mouse drags, use the
* <code>MouseMotionListener</code>.)
* <P>
* The class that is interested in processing a mouse event
* either implements this interface (and all the methods it
* contains) or extends the abstract <code>MouseAdapter</code> class
* (overriding only the methods of interest).
* <P>
* The listener object created from that class is then registered with a
* component using the component's <code>addMouseListener</code>
* method. A mouse event is generated when the mouse is pressed, released
* clicked (pressed and released). A mouse event is also generated when
* the mouse cursor enters or leaves a component. When a mouse event
* occurs, the relevant method in the listener object is invoked, and
* the <code>MouseEvent</code> is passed to it.
*
* @author Carl Quinn
*
* @see MouseAdapter
* @see MouseEvent
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/mouselistener.html">Tutorial: Writing a Mouse Listener</a>
*
* @since 1.1
*/
public interface MouseListener extends EventListener {
/**
* Invoked when the mouse button has been clicked (pressed
* and released) on a component.
*/
public void mouseClicked(MouseEvent e);
/**
* Invoked when a mouse button has been pressed on a component.
*/
public void mousePressed(MouseEvent e);
/**
* Invoked when a mouse button has been released on a component.
*/
public void mouseReleased(MouseEvent e);
/**
* Invoked when the mouse enters a component.
*/
public void mouseEntered(MouseEvent e);
/**
* Invoked when the mouse exits a component.
*/
public void mouseExited(MouseEvent e);
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
/**
* An abstract adapter class for receiving mouse motion events.
* The methods in this class are empty. This class exists as
* convenience for creating listener objects.
* <P>
* Mouse motion events occur when a mouse is moved or dragged.
* (Many such events will be generated in a normal program.
* To track clicks and other mouse events, use the MouseAdapter.)
* <P>
* Extend this class to create a <code>MouseEvent</code> listener
* and override the methods for the events of interest. (If you implement the
* <code>MouseMotionListener</code> interface, you have to define all of
* the methods in it. This abstract class defines null methods for them
* all, so you can only have to define methods for events you care about.)
* <P>
* Create a listener object using the extended class and then register it with
* a component using the component's <code>addMouseMotionListener</code>
* method. When the mouse is moved or dragged, the relevant method in the
* listener object is invoked and the <code>MouseEvent</code> is passed to it.
*
* @author Amy Fowler
*
* @see MouseEvent
* @see MouseMotionListener
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/mousemotionlistener.html">Tutorial: Writing a Mouse Motion Listener</a>
*
* @since 1.1
*/
public abstract class MouseMotionAdapter implements MouseMotionListener {
/**
* Invoked when a mouse button is pressed on a component and then
* dragged. Mouse drag events will continue to be delivered to
* the component where the first originated until the mouse button is
* released (regardless of whether the mouse position is within the
* bounds of the component).
*/
public void mouseDragged(MouseEvent e) {}
/**
* Invoked when the mouse button has been moved on a component
* (with no buttons no down).
*/
public void mouseMoved(MouseEvent e) {}
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving mouse motion events on a component.
* (For clicks and other mouse events, use the <code>MouseListener</code>.)
* <P>
* The class that is interested in processing a mouse motion event
* either implements this interface (and all the methods it
* contains) or extends the abstract <code>MouseMotionAdapter</code> class
* (overriding only the methods of interest).
* <P>
* The listener object created from that class is then registered with a
* component using the component's <code>addMouseMotionListener</code>
* method. A mouse motion event is generated when the mouse is moved
* or dragged. (Many such events will be generated). When a mouse motion event
* occurs, the relevant method in the listener object is invoked, and
* the <code>MouseEvent</code> is passed to it.
*
* @author Amy Fowler
*
* @see MouseMotionAdapter
* @see MouseEvent
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/mousemotionlistener.html">Tutorial: Writing a Mouse Motion Listener</a>
*
* @since 1.1
*/
public interface MouseMotionListener extends EventListener {
/**
* Invoked when a mouse button is pressed on a component and then
* dragged. <code>MOUSE_DRAGGED</code> events will continue to be
* delivered to the component where the drag originated until the
* mouse button is released (regardless of whether the mouse position
* is within the bounds of the component).
* <p>
* Due to platform-dependent Drag&amp;Drop implementations,
* <code>MOUSE_DRAGGED</code> events may not be delivered during a native
* Drag&amp;Drop operation.
*/
public void mouseDragged(MouseEvent e);
/**
* Invoked when the mouse cursor has been moved onto a component
* but no buttons have been pushed.
*/
public void mouseMoved(MouseEvent e);
}

View File

@@ -0,0 +1,449 @@
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.awt.Component;
import java.lang.annotation.Native;
/**
* An event which indicates that the mouse wheel was rotated in a component.
* <P>
* A wheel mouse is a mouse which has a wheel in place of the middle button.
* This wheel can be rotated towards or away from the user. Mouse wheels are
* most often used for scrolling, though other uses are possible.
* <P>
* A MouseWheelEvent object is passed to every <code>MouseWheelListener</code>
* object which registered to receive the "interesting" mouse events using the
* component's <code>addMouseWheelListener</code> method. Each such listener
* object gets a <code>MouseEvent</code> containing the mouse event.
* <P>
* Due to the mouse wheel's special relationship to scrolling Components,
* MouseWheelEvents are delivered somewhat differently than other MouseEvents.
* This is because while other MouseEvents usually affect a change on
* the Component directly under the mouse
* cursor (for instance, when clicking a button), MouseWheelEvents often have
* an effect away from the mouse cursor (moving the wheel while
* over a Component inside a ScrollPane should scroll one of the
* Scrollbars on the ScrollPane).
* <P>
* MouseWheelEvents start delivery from the Component underneath the
* mouse cursor. If MouseWheelEvents are not enabled on the
* Component, the event is delivered to the first ancestor
* Container with MouseWheelEvents enabled. This will usually be
* a ScrollPane with wheel scrolling enabled. The source
* Component and x,y coordinates will be relative to the event's
* final destination (the ScrollPane). This allows a complex
* GUI to be installed without modification into a ScrollPane, and
* for all MouseWheelEvents to be delivered to the ScrollPane for
* scrolling.
* <P>
* Some AWT Components are implemented using native widgets which
* display their own scrollbars and handle their own scrolling.
* The particular Components for which this is true will vary from
* platform to platform. When the mouse wheel is
* moved over one of these Components, the event is delivered straight to
* the native widget, and not propagated to ancestors.
* <P>
* Platforms offer customization of the amount of scrolling that
* should take place when the mouse wheel is moved. The two most
* common settings are to scroll a certain number of "units"
* (commonly lines of text in a text-based component) or an entire "block"
* (similar to page-up/page-down). The MouseWheelEvent offers
* methods for conforming to the underlying platform settings. These
* platform settings can be changed at any time by the user. MouseWheelEvents
* reflect the most recent settings.
* <P>
* The <code>MouseWheelEvent</code> class includes methods for
* getting the number of "clicks" by which the mouse wheel is rotated.
* The {@link #getWheelRotation} method returns the integer number
* of "clicks" corresponding to the number of notches by which the wheel was
* rotated. In addition to this method, the <code>MouseWheelEvent</code>
* class provides the {@link #getPreciseWheelRotation} method which returns
* a double number of "clicks" in case a partial rotation occurred.
* The {@link #getPreciseWheelRotation} method is useful if a mouse supports
* a high-resolution wheel, such as a freely rotating wheel with no
* notches. Applications can benefit by using this method to process
* mouse wheel events more precisely, and thus, making visual perception
* smoother.
*
* @author Brent Christian
* @see MouseWheelListener
* @see java.awt.ScrollPane
* @see java.awt.ScrollPane#setWheelScrollingEnabled(boolean)
* @see javax.swing.JScrollPane
* @see javax.swing.JScrollPane#setWheelScrollingEnabled(boolean)
* @since 1.4
*/
public class MouseWheelEvent extends MouseEvent {
/**
* Constant representing scrolling by "units" (like scrolling with the
* arrow keys)
*
* @see #getScrollType
*/
@Native public static final int WHEEL_UNIT_SCROLL = 0;
/**
* Constant representing scrolling by a "block" (like scrolling
* with page-up, page-down keys)
*
* @see #getScrollType
*/
@Native public static final int WHEEL_BLOCK_SCROLL = 1;
/**
* Indicates what sort of scrolling should take place in response to this
* event, based on platform settings. Legal values are:
* <ul>
* <li> WHEEL_UNIT_SCROLL
* <li> WHEEL_BLOCK_SCROLL
* </ul>
*
* @see #getScrollType
*/
int scrollType;
/**
* Only valid for scrollType WHEEL_UNIT_SCROLL.
* Indicates number of units that should be scrolled per
* click of mouse wheel rotation, based on platform settings.
*
* @see #getScrollAmount
* @see #getScrollType
*/
int scrollAmount;
/**
* Indicates how far the mouse wheel was rotated.
*
* @see #getWheelRotation
*/
int wheelRotation;
/**
* Indicates how far the mouse wheel was rotated.
*
* @see #getPreciseWheelRotation
*/
double preciseWheelRotation;
/*
* serialVersionUID
*/
private static final long serialVersionUID = 6459879390515399677L;
/**
* Constructs a <code>MouseWheelEvent</code> object with the
* specified source component, type, modifiers, coordinates,
* scroll type, scroll amount, and wheel rotation.
* <p>Absolute coordinates xAbs and yAbs are set to source's location on screen plus
* relative coordinates x and y. xAbs and yAbs are set to zero if the source is not showing.
* <p>Note that passing in an invalid <code>id</code> results in
* unspecified behavior. This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source the <code>Component</code> that originated
* the event
* @param id the integer that identifies the event
* @param when a long that gives the time the event occurred
* @param modifiers the modifier keys down during event
* (shift, ctrl, alt, meta)
* @param x the horizontal x coordinate for the mouse location
* @param y the vertical y coordinate for the mouse location
* @param clickCount the number of mouse clicks associated with event
* @param popupTrigger a boolean, true if this event is a trigger for a
* popup-menu
* @param scrollType the type of scrolling which should take place in
* response to this event; valid values are
* <code>WHEEL_UNIT_SCROLL</code> and
* <code>WHEEL_BLOCK_SCROLL</code>
* @param scrollAmount for scrollType <code>WHEEL_UNIT_SCROLL</code>,
* the number of units to be scrolled
* @param wheelRotation the integer number of "clicks" by which the mouse
* wheel was rotated
*
* @throws IllegalArgumentException if <code>source</code> is null
* @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)
* @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, int, int, boolean, int)
*/
public MouseWheelEvent (Component source, int id, long when, int modifiers,
int x, int y, int clickCount, boolean popupTrigger,
int scrollType, int scrollAmount, int wheelRotation) {
this(source, id, when, modifiers, x, y, 0, 0, clickCount,
popupTrigger, scrollType, scrollAmount, wheelRotation);
}
/**
* Constructs a <code>MouseWheelEvent</code> object with the
* specified source component, type, modifiers, coordinates,
* absolute coordinates, scroll type, scroll amount, and wheel rotation.
* <p>Note that passing in an invalid <code>id</code> results in
* unspecified behavior. This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.<p>
* Even if inconsistent values for relative and absolute coordinates are
* passed to the constructor, the MouseWheelEvent instance is still
* created and no exception is thrown.
*
* @param source the <code>Component</code> that originated
* the event
* @param id the integer that identifies the event
* @param when a long that gives the time the event occurred
* @param modifiers the modifier keys down during event
* (shift, ctrl, alt, meta)
* @param x the horizontal x coordinate for the mouse location
* @param y the vertical y coordinate for the mouse location
* @param xAbs the absolute horizontal x coordinate for the mouse location
* @param yAbs the absolute vertical y coordinate for the mouse location
* @param clickCount the number of mouse clicks associated with event
* @param popupTrigger a boolean, true if this event is a trigger for a
* popup-menu
* @param scrollType the type of scrolling which should take place in
* response to this event; valid values are
* <code>WHEEL_UNIT_SCROLL</code> and
* <code>WHEEL_BLOCK_SCROLL</code>
* @param scrollAmount for scrollType <code>WHEEL_UNIT_SCROLL</code>,
* the number of units to be scrolled
* @param wheelRotation the integer number of "clicks" by which the mouse
* wheel was rotated
*
* @throws IllegalArgumentException if <code>source</code> is null
* @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)
* @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, int, int, boolean, int)
* @since 1.6
*/
public MouseWheelEvent (Component source, int id, long when, int modifiers,
int x, int y, int xAbs, int yAbs, int clickCount, boolean popupTrigger,
int scrollType, int scrollAmount, int wheelRotation) {
this(source, id, when, modifiers, x, y, xAbs, yAbs, clickCount, popupTrigger,
scrollType, scrollAmount, wheelRotation, wheelRotation);
}
/**
* Constructs a <code>MouseWheelEvent</code> object with the specified
* source component, type, modifiers, coordinates, absolute coordinates,
* scroll type, scroll amount, and wheel rotation.
* <p>Note that passing in an invalid <code>id</code> parameter results
* in unspecified behavior. This method throws an
* <code>IllegalArgumentException</code> if <code>source</code> equals
* <code>null</code>.
* <p>Even if inconsistent values for relative and absolute coordinates
* are passed to the constructor, a <code>MouseWheelEvent</code> instance
* is still created and no exception is thrown.
*
* @param source the <code>Component</code> that originated the event
* @param id the integer value that identifies the event
* @param when a long value that gives the time when the event occurred
* @param modifiers the modifier keys down during event
* (shift, ctrl, alt, meta)
* @param x the horizontal <code>x</code> coordinate for the
* mouse location
* @param y the vertical <code>y</code> coordinate for the
* mouse location
* @param xAbs the absolute horizontal <code>x</code> coordinate for
* the mouse location
* @param yAbs the absolute vertical <code>y</code> coordinate for
* the mouse location
* @param clickCount the number of mouse clicks associated with the event
* @param popupTrigger a boolean value, <code>true</code> if this event is a trigger
* for a popup-menu
* @param scrollType the type of scrolling which should take place in
* response to this event; valid values are
* <code>WHEEL_UNIT_SCROLL</code> and
* <code>WHEEL_BLOCK_SCROLL</code>
* @param scrollAmount for scrollType <code>WHEEL_UNIT_SCROLL</code>,
* the number of units to be scrolled
* @param wheelRotation the integer number of "clicks" by which the mouse wheel
* was rotated
* @param preciseWheelRotation the double number of "clicks" by which the mouse wheel
* was rotated
*
* @throws IllegalArgumentException if <code>source</code> is null
* @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)
* @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, int, int, boolean, int)
* @since 1.7
*/
public MouseWheelEvent (Component source, int id, long when, int modifiers,
int x, int y, int xAbs, int yAbs, int clickCount, boolean popupTrigger,
int scrollType, int scrollAmount, int wheelRotation, double preciseWheelRotation) {
super(source, id, when, modifiers, x, y, xAbs, yAbs, clickCount,
popupTrigger, MouseEvent.NOBUTTON);
this.scrollType = scrollType;
this.scrollAmount = scrollAmount;
this.wheelRotation = wheelRotation;
this.preciseWheelRotation = preciseWheelRotation;
}
/**
* Returns the type of scrolling that should take place in response to this
* event. This is determined by the native platform. Legal values are:
* <ul>
* <li> MouseWheelEvent.WHEEL_UNIT_SCROLL
* <li> MouseWheelEvent.WHEEL_BLOCK_SCROLL
* </ul>
*
* @return either MouseWheelEvent.WHEEL_UNIT_SCROLL or
* MouseWheelEvent.WHEEL_BLOCK_SCROLL, depending on the configuration of
* the native platform.
* @see java.awt.Adjustable#getUnitIncrement
* @see java.awt.Adjustable#getBlockIncrement
* @see javax.swing.Scrollable#getScrollableUnitIncrement
* @see javax.swing.Scrollable#getScrollableBlockIncrement
*/
public int getScrollType() {
return scrollType;
}
/**
* Returns the number of units that should be scrolled per
* click of mouse wheel rotation.
* Only valid if <code>getScrollType</code> returns
* <code>MouseWheelEvent.WHEEL_UNIT_SCROLL</code>
*
* @return number of units to scroll, or an undefined value if
* <code>getScrollType</code> returns
* <code>MouseWheelEvent.WHEEL_BLOCK_SCROLL</code>
* @see #getScrollType
*/
public int getScrollAmount() {
return scrollAmount;
}
/**
* Returns the number of "clicks" the mouse wheel was rotated, as an integer.
* A partial rotation may occur if the mouse supports a high-resolution wheel.
* In this case, the method returns zero until a full "click" has been accumulated.
*
* @return negative values if the mouse wheel was rotated up/away from
* the user, and positive values if the mouse wheel was rotated down/
* towards the user
* @see #getPreciseWheelRotation
*/
public int getWheelRotation() {
return wheelRotation;
}
/**
* Returns the number of "clicks" the mouse wheel was rotated, as a double.
* A partial rotation may occur if the mouse supports a high-resolution wheel.
* In this case, the return value will include a fractional "click".
*
* @return negative values if the mouse wheel was rotated up or away from
* the user, and positive values if the mouse wheel was rotated down or
* towards the user
* @see #getWheelRotation
* @since 1.7
*/
public double getPreciseWheelRotation() {
return preciseWheelRotation;
}
/**
* This is a convenience method to aid in the implementation of
* the common-case MouseWheelListener - to scroll a ScrollPane or
* JScrollPane by an amount which conforms to the platform settings.
* (Note, however, that <code>ScrollPane</code> and
* <code>JScrollPane</code> already have this functionality built in.)
* <P>
* This method returns the number of units to scroll when scroll type is
* MouseWheelEvent.WHEEL_UNIT_SCROLL, and should only be called if
* <code>getScrollType</code> returns MouseWheelEvent.WHEEL_UNIT_SCROLL.
* <P>
* Direction of scroll, amount of wheel movement,
* and platform settings for wheel scrolling are all accounted for.
* This method does not and cannot take into account value of the
* Adjustable/Scrollable unit increment, as this will vary among
* scrolling components.
* <P>
* A simplified example of how this method might be used in a
* listener:
* <pre>
* mouseWheelMoved(MouseWheelEvent event) {
* ScrollPane sp = getScrollPaneFromSomewhere();
* Adjustable adj = sp.getVAdjustable()
* if (MouseWheelEvent.getScrollType() == WHEEL_UNIT_SCROLL) {
* int totalScrollAmount =
* event.getUnitsToScroll() *
* adj.getUnitIncrement();
* adj.setValue(adj.getValue() + totalScrollAmount);
* }
* }
* </pre>
*
* @return the number of units to scroll based on the direction and amount
* of mouse wheel rotation, and on the wheel scrolling settings of the
* native platform
* @see #getScrollType
* @see #getScrollAmount
* @see MouseWheelListener
* @see java.awt.Adjustable
* @see java.awt.Adjustable#getUnitIncrement
* @see javax.swing.Scrollable
* @see javax.swing.Scrollable#getScrollableUnitIncrement
* @see java.awt.ScrollPane
* @see java.awt.ScrollPane#setWheelScrollingEnabled
* @see javax.swing.JScrollPane
* @see javax.swing.JScrollPane#setWheelScrollingEnabled
*/
public int getUnitsToScroll() {
return scrollAmount * wheelRotation;
}
/**
* Returns a parameter string identifying this event.
* This method is useful for event-logging and for debugging.
*
* @return a string identifying the event and its attributes
*/
public String paramString() {
String scrollTypeStr = null;
if (getScrollType() == WHEEL_UNIT_SCROLL) {
scrollTypeStr = "WHEEL_UNIT_SCROLL";
}
else if (getScrollType() == WHEEL_BLOCK_SCROLL) {
scrollTypeStr = "WHEEL_BLOCK_SCROLL";
}
else {
scrollTypeStr = "unknown scroll type";
}
return super.paramString()+",scrollType="+scrollTypeStr+
",scrollAmount="+getScrollAmount()+",wheelRotation="+
getWheelRotation()+",preciseWheelRotation="+getPreciseWheelRotation();
}
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving mouse wheel events on a component.
* (For clicks and other mouse events, use the <code>MouseListener</code>.
* For mouse movement and drags, use the <code>MouseMotionListener</code>.)
* <P>
* The class that is interested in processing a mouse wheel event
* implements this interface (and all the methods it contains).
* <P>
* The listener object created from that class is then registered with a
* component using the component's <code>addMouseWheelListener</code>
* method. A mouse wheel event is generated when the mouse wheel is rotated.
* When a mouse wheel event occurs, that object's <code>mouseWheelMoved</code>
* method is invoked.
* <p>
* For information on how mouse wheel events are dispatched, see
* the class description for {@link MouseWheelEvent}.
*
* @author Brent Christian
* @see MouseWheelEvent
* @since 1.4
*/
public interface MouseWheelListener extends EventListener {
/**
* Invoked when the mouse wheel is rotated.
* @see MouseWheelEvent
*/
public void mouseWheelMoved(MouseWheelEvent e);
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
class NativeLibLoader {
/**
* This is copied from java.awt.Toolkit since we need the library
* loaded in sun.awt.image also:
*
* WARNING: This is a temporary workaround for a problem in the
* way the AWT loads native libraries. A number of classes in this
* package (sun.awt.image) have a native method, initIDs(),
* which initializes
* the JNI field and method ids used in the native portion of
* their implementation.
*
* Since the use and storage of these ids is done by the
* implementation libraries, the implementation of these method is
* provided by the particular AWT implementations (for example,
* "Toolkit"s/Peer), such as Motif, Microsoft Windows, or Tiny. The
* problem is that this means that the native libraries must be
* loaded by the java.* classes, which do not necessarily know the
* names of the libraries to load. A better way of doing this
* would be to provide a separate library which defines java.awt.*
* initIDs, and exports the relevant symbols out to the
* implementation libraries.
*
* For now, we know it's done by the implementation, and we assume
* that the name of the library is "awt". -br.
*/
static void loadLibraries() {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("awt");
return null;
}
});
}
}

View File

@@ -0,0 +1,139 @@
/*
* Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.awt.Component;
import java.awt.Rectangle;
/**
* The component-level paint event.
* This event is a special type which is used to ensure that
* paint/update method calls are serialized along with the other
* events delivered from the event queue. This event is not
* designed to be used with the Event Listener model; programs
* should continue to override paint/update methods in order
* render themselves properly.
* <p>
* An unspecified behavior will be caused if the {@code id} parameter
* of any particular {@code PaintEvent} instance is not
* in the range from {@code PAINT_FIRST} to {@code PAINT_LAST}.
*
* @author Amy Fowler
* @since 1.1
*/
public class PaintEvent extends ComponentEvent {
/**
* Marks the first integer id for the range of paint event ids.
*/
public static final int PAINT_FIRST = 800;
/**
* Marks the last integer id for the range of paint event ids.
*/
public static final int PAINT_LAST = 801;
/**
* The paint event type.
*/
public static final int PAINT = PAINT_FIRST;
/**
* The update event type.
*/
public static final int UPDATE = PAINT_FIRST + 1; //801
/**
* This is the rectangle that represents the area on the source
* component that requires a repaint.
* This rectangle should be non null.
*
* @serial
* @see java.awt.Rectangle
* @see #setUpdateRect(Rectangle)
* @see #getUpdateRect()
*/
Rectangle updateRect;
/*
* JDK 1.1 serialVersionUID
*/
private static final long serialVersionUID = 1267492026433337593L;
/**
* Constructs a <code>PaintEvent</code> object with the specified
* source component and type.
* <p> This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source The object where the event originated
* @param id The integer that identifies the event type.
* For information on allowable values, see
* the class description for {@link PaintEvent}
* @param updateRect The rectangle area which needs to be repainted
* @throws IllegalArgumentException if <code>source</code> is null
* @see #getSource()
* @see #getID()
* @see #getUpdateRect()
*/
public PaintEvent(Component source, int id, Rectangle updateRect) {
super(source, id);
this.updateRect = updateRect;
}
/**
* Returns the rectangle representing the area which needs to be
* repainted in response to this event.
*/
public Rectangle getUpdateRect() {
return updateRect;
}
/**
* Sets the rectangle representing the area which needs to be
* repainted in response to this event.
* @param updateRect the rectangle area which needs to be repainted
*/
public void setUpdateRect(Rectangle updateRect) {
this.updateRect = updateRect;
}
public String paramString() {
String typeStr;
switch(id) {
case PAINT:
typeStr = "PAINT";
break;
case UPDATE:
typeStr = "UPDATE";
break;
default:
typeStr = "unknown type";
}
return typeStr + ",updateRect="+(updateRect != null ? updateRect.toString() : "null");
}
}

View File

@@ -0,0 +1,113 @@
/*
* Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.awt.AWTEvent;
/**
* A semantic event which indicates that an object's text changed.
* This high-level event is generated by an object (such as a TextComponent)
* when its text changes. The event is passed to
* every <code>TextListener</code> object which registered to receive such
* events using the component's <code>addTextListener</code> method.
* <P>
* The object that implements the <code>TextListener</code> interface gets
* this <code>TextEvent</code> when the event occurs. The listener is
* spared the details of processing individual mouse movements and key strokes
* Instead, it can process a "meaningful" (semantic) event like "text changed".
* <p>
* An unspecified behavior will be caused if the {@code id} parameter
* of any particular {@code TextEvent} instance is not
* in the range from {@code TEXT_FIRST} to {@code TEXT_LAST}.
*
* @author Georges Saab
*
* @see java.awt.TextComponent
* @see TextListener
*
* @since 1.1
*/
public class TextEvent extends AWTEvent {
/**
* The first number in the range of ids used for text events.
*/
public static final int TEXT_FIRST = 900;
/**
* The last number in the range of ids used for text events.
*/
public static final int TEXT_LAST = 900;
/**
* This event id indicates that object's text changed.
*/
public static final int TEXT_VALUE_CHANGED = TEXT_FIRST;
/*
* JDK 1.1 serialVersionUID
*/
private static final long serialVersionUID = 6269902291250941179L;
/**
* Constructs a <code>TextEvent</code> object.
* <p> This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source The (<code>TextComponent</code>) object that
* originated the event
* @param id An integer that identifies the event type.
* For information on allowable values, see
* the class description for {@link TextEvent}
* @throws IllegalArgumentException if <code>source</code> is null
* @see #getSource()
* @see #getID()
*/
public TextEvent(Object source, int id) {
super(source, id);
}
/**
* Returns a parameter string identifying this text event.
* This method is useful for event-logging and for debugging.
*
* @return a string identifying the event and its attributes
*/
public String paramString() {
String typeStr;
switch(id) {
case TEXT_VALUE_CHANGED:
typeStr = "TEXT_VALUE_CHANGED";
break;
default:
typeStr = "unknown type";
}
return typeStr;
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving text events.
*
* The class that is interested in processing a text event
* implements this interface. The object created with that
* class is then registered with a component using the
* component's <code>addTextListener</code> method. When the
* component's text changes, the listener object's
* <code>textValueChanged</code> method is invoked.
*
* @author Georges Saab
*
* @see TextEvent
*
* @since 1.1
*/
public interface TextListener extends EventListener {
/**
* Invoked when the value of the text has changed.
* The code written for this method performs the operations
* that need to occur when text changes.
*/
public void textValueChanged(TextEvent e);
}

View File

@@ -0,0 +1,117 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
/**
* An abstract adapter class for receiving window events.
* The methods in this class are empty. This class exists as
* convenience for creating listener objects.
* <P>
* Extend this class to create a <code>WindowEvent</code> listener
* and override the methods for the events of interest. (If you implement the
* <code>WindowListener</code> interface, you have to define all of
* the methods in it. This abstract class defines null methods for them
* all, so you can only have to define methods for events you care about.)
* <P>
* Create a listener object using the extended class and then register it with
* a Window using the window's <code>addWindowListener</code>
* method. When the window's status changes by virtue of being opened,
* closed, activated or deactivated, iconified or deiconified,
* the relevant method in the listener
* object is invoked, and the <code>WindowEvent</code> is passed to it.
*
* @see WindowEvent
* @see WindowListener
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/windowlistener.html">Tutorial: Writing a Window Listener</a>
*
* @author Carl Quinn
* @author Amy Fowler
* @author David Mendenhall
* @since 1.1
*/
public abstract class WindowAdapter
implements WindowListener, WindowStateListener, WindowFocusListener
{
/**
* Invoked when a window has been opened.
*/
public void windowOpened(WindowEvent e) {}
/**
* Invoked when a window is in the process of being closed.
* The close operation can be overridden at this point.
*/
public void windowClosing(WindowEvent e) {}
/**
* Invoked when a window has been closed.
*/
public void windowClosed(WindowEvent e) {}
/**
* Invoked when a window is iconified.
*/
public void windowIconified(WindowEvent e) {}
/**
* Invoked when a window is de-iconified.
*/
public void windowDeiconified(WindowEvent e) {}
/**
* Invoked when a window is activated.
*/
public void windowActivated(WindowEvent e) {}
/**
* Invoked when a window is de-activated.
*/
public void windowDeactivated(WindowEvent e) {}
/**
* Invoked when a window state is changed.
* @since 1.4
*/
public void windowStateChanged(WindowEvent e) {}
/**
* Invoked when the Window is set to be the focused Window, which means
* that the Window, or one of its subcomponents, will receive keyboard
* events.
*
* @since 1.4
*/
public void windowGainedFocus(WindowEvent e) {}
/**
* Invoked when the Window is no longer the focused Window, which means
* that keyboard events will no longer be delivered to the Window or any of
* its subcomponents.
*
* @since 1.4
*/
public void windowLostFocus(WindowEvent e) {}
}

View File

@@ -0,0 +1,431 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.awt.Window;
import java.lang.annotation.Native;
import sun.awt.AppContext;
import sun.awt.SunToolkit;
/**
* A low-level event that indicates that a window has changed its status. This
* low-level event is generated by a Window object when it is opened, closed,
* activated, deactivated, iconified, or deiconified, or when focus is
* transfered into or out of the Window.
* <P>
* The event is passed to every <code>WindowListener</code>
* or <code>WindowAdapter</code> object which registered to receive such
* events using the window's <code>addWindowListener</code> method.
* (<code>WindowAdapter</code> objects implement the
* <code>WindowListener</code> interface.) Each such listener object
* gets this <code>WindowEvent</code> when the event occurs.
* <p>
* An unspecified behavior will be caused if the {@code id} parameter
* of any particular {@code WindowEvent} instance is not
* in the range from {@code WINDOW_FIRST} to {@code WINDOW_LAST}.
*
* @author Carl Quinn
* @author Amy Fowler
*
* @see WindowAdapter
* @see WindowListener
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/windowlistener.html">Tutorial: Writing a Window Listener</a>
*
* @since JDK1.1
*/
public class WindowEvent extends ComponentEvent {
/**
* The first number in the range of ids used for window events.
*/
public static final int WINDOW_FIRST = 200;
/**
* The window opened event. This event is delivered only
* the first time a window is made visible.
*/
@Native public static final int WINDOW_OPENED = WINDOW_FIRST; // 200
/**
* The "window is closing" event. This event is delivered when
* the user attempts to close the window from the window's system menu.
* If the program does not explicitly hide or dispose the window
* while processing this event, the window close operation will be
* cancelled.
*/
@Native public static final int WINDOW_CLOSING = 1 + WINDOW_FIRST; //Event.WINDOW_DESTROY
/**
* The window closed event. This event is delivered after the displayable
* window has been closed as the result of a call to dispose.
* @see java.awt.Component#isDisplayable
* @see Window#dispose
*/
@Native public static final int WINDOW_CLOSED = 2 + WINDOW_FIRST;
/**
* The window iconified event. This event is delivered when
* the window has been changed from a normal to a minimized state.
* For many platforms, a minimized window is displayed as
* the icon specified in the window's iconImage property.
* @see java.awt.Frame#setIconImage
*/
@Native public static final int WINDOW_ICONIFIED = 3 + WINDOW_FIRST; //Event.WINDOW_ICONIFY
/**
* The window deiconified event type. This event is delivered when
* the window has been changed from a minimized to a normal state.
*/
@Native public static final int WINDOW_DEICONIFIED = 4 + WINDOW_FIRST; //Event.WINDOW_DEICONIFY
/**
* The window-activated event type. This event is delivered when the Window
* becomes the active Window. Only a Frame or a Dialog can be the active
* Window. The native windowing system may denote the active Window or its
* children with special decorations, such as a highlighted title bar. The
* active Window is always either the focused Window, or the first Frame or
* Dialog that is an owner of the focused Window.
*/
@Native public static final int WINDOW_ACTIVATED = 5 + WINDOW_FIRST;
/**
* The window-deactivated event type. This event is delivered when the
* Window is no longer the active Window. Only a Frame or a Dialog can be
* the active Window. The native windowing system may denote the active
* Window or its children with special decorations, such as a highlighted
* title bar. The active Window is always either the focused Window, or the
* first Frame or Dialog that is an owner of the focused Window.
*/
@Native public static final int WINDOW_DEACTIVATED = 6 + WINDOW_FIRST;
/**
* The window-gained-focus event type. This event is delivered when the
* Window becomes the focused Window, which means that the Window, or one
* of its subcomponents, will receive keyboard events.
*/
@Native public static final int WINDOW_GAINED_FOCUS = 7 + WINDOW_FIRST;
/**
* The window-lost-focus event type. This event is delivered when a Window
* is no longer the focused Window, which means keyboard events will no
* longer be delivered to the Window or any of its subcomponents.
*/
@Native public static final int WINDOW_LOST_FOCUS = 8 + WINDOW_FIRST;
/**
* The window-state-changed event type. This event is delivered
* when a Window's state is changed by virtue of it being
* iconified, maximized etc.
* @since 1.4
*/
@Native public static final int WINDOW_STATE_CHANGED = 9 + WINDOW_FIRST;
/**
* The last number in the range of ids used for window events.
*/
public static final int WINDOW_LAST = WINDOW_STATE_CHANGED;
/**
* The other Window involved in this focus or activation change. For a
* WINDOW_ACTIVATED or WINDOW_GAINED_FOCUS event, this is the Window that
* lost activation or focus. For a WINDOW_DEACTIVATED or WINDOW_LOST_FOCUS
* event, this is the Window that gained activation or focus. For any other
* type of WindowEvent, or if the focus or activation change occurs with a
* native application, a Java application in a different VM, or with no
* other Window, null is returned.
*
* @see #getOppositeWindow
* @since 1.4
*/
transient Window opposite;
/**
* TBS
*/
int oldState;
int newState;
/*
* JDK 1.1 serialVersionUID
*/
private static final long serialVersionUID = -1567959133147912127L;
/**
* Constructs a <code>WindowEvent</code> object.
* <p>This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source The <code>Window</code> object
* that originated the event
* @param id An integer indicating the type of event.
* For information on allowable values, see
* the class description for {@link WindowEvent}
* @param opposite The other window involved in the focus or activation
* change, or <code>null</code>
* @param oldState Previous state of the window for window state change event.
* See {@code #getOldState()} for allowable values
* @param newState New state of the window for window state change event.
* See {@code #getNewState()} for allowable values
* @throws IllegalArgumentException if <code>source</code> is null
* @see #getWindow()
* @see #getID()
* @see #getOppositeWindow()
* @see #getOldState()
* @see #getNewState()
* @since 1.4
*/
public WindowEvent(Window source, int id, Window opposite,
int oldState, int newState)
{
super(source, id);
this.opposite = opposite;
this.oldState = oldState;
this.newState = newState;
}
/**
* Constructs a <code>WindowEvent</code> object with the
* specified opposite <code>Window</code>. The opposite
* <code>Window</code> is the other <code>Window</code>
* involved in this focus or activation change.
* For a <code>WINDOW_ACTIVATED</code> or
* <code>WINDOW_GAINED_FOCUS</code> event, this is the
* <code>Window</code> that lost activation or focus.
* For a <code>WINDOW_DEACTIVATED</code> or
* <code>WINDOW_LOST_FOCUS</code> event, this is the
* <code>Window</code> that gained activation or focus.
* If this focus change occurs with a native application, with a
* Java application in a different VM, or with no other
* <code>Window</code>, then the opposite Window is <code>null</code>.
* <p>This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source The <code>Window</code> object that
* originated the event
* @param id An integer indicating the type of event.
* For information on allowable values, see
* the class description for {@link WindowEvent}.
* It is expected that this constructor will not
* be used for other then
* {@code WINDOW_ACTIVATED},{@code WINDOW_DEACTIVATED},
* {@code WINDOW_GAINED_FOCUS}, or {@code WINDOW_LOST_FOCUS}.
* {@code WindowEvent} types,
* because the opposite <code>Window</code> of other event types
* will always be {@code null}.
* @param opposite The other <code>Window</code> involved in the
* focus or activation change, or <code>null</code>
* @throws IllegalArgumentException if <code>source</code> is null
* @see #getWindow()
* @see #getID()
* @see #getOppositeWindow()
* @since 1.4
*/
public WindowEvent(Window source, int id, Window opposite) {
this(source, id, opposite, 0, 0);
}
/**
* Constructs a <code>WindowEvent</code> object with the specified
* previous and new window states.
* <p>This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source The <code>Window</code> object
* that originated the event
* @param id An integer indicating the type of event.
* For information on allowable values, see
* the class description for {@link WindowEvent}.
* It is expected that this constructor will not
* be used for other then
* {@code WINDOW_STATE_CHANGED}
* {@code WindowEvent}
* types, because the previous and new window
* states are meaningless for other event types.
* @param oldState An integer representing the previous window state.
* See {@code #getOldState()} for allowable values
* @param newState An integer representing the new window state.
* See {@code #getNewState()} for allowable values
* @throws IllegalArgumentException if <code>source</code> is null
* @see #getWindow()
* @see #getID()
* @see #getOldState()
* @see #getNewState()
* @since 1.4
*/
public WindowEvent(Window source, int id, int oldState, int newState) {
this(source, id, null, oldState, newState);
}
/**
* Constructs a <code>WindowEvent</code> object.
* <p>This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source The <code>Window</code> object that originated the event
* @param id An integer indicating the type of event.
* For information on allowable values, see
* the class description for {@link WindowEvent}.
* @throws IllegalArgumentException if <code>source</code> is null
* @see #getWindow()
* @see #getID()
*/
public WindowEvent(Window source, int id) {
this(source, id, null, 0, 0);
}
/**
* Returns the originator of the event.
*
* @return the Window object that originated the event
*/
public Window getWindow() {
return (source instanceof Window) ? (Window)source : null;
}
/**
* Returns the other Window involved in this focus or activation change.
* For a WINDOW_ACTIVATED or WINDOW_GAINED_FOCUS event, this is the Window
* that lost activation or focus. For a WINDOW_DEACTIVATED or
* WINDOW_LOST_FOCUS event, this is the Window that gained activation or
* focus. For any other type of WindowEvent, or if the focus or activation
* change occurs with a native application, with a Java application in a
* different VM or context, or with no other Window, null is returned.
*
* @return the other Window involved in the focus or activation change, or
* null
* @since 1.4
*/
public Window getOppositeWindow() {
if (opposite == null) {
return null;
}
return (SunToolkit.targetToAppContext(opposite) ==
AppContext.getAppContext())
? opposite
: null;
}
/**
* For <code>WINDOW_STATE_CHANGED</code> events returns the
* previous state of the window. The state is
* represented as a bitwise mask.
* <ul>
* <li><code>NORMAL</code>
* <br>Indicates that no state bits are set.
* <li><code>ICONIFIED</code>
* <li><code>MAXIMIZED_HORIZ</code>
* <li><code>MAXIMIZED_VERT</code>
* <li><code>MAXIMIZED_BOTH</code>
* <br>Concatenates <code>MAXIMIZED_HORIZ</code>
* and <code>MAXIMIZED_VERT</code>.
* </ul>
*
* @return a bitwise mask of the previous window state
* @see java.awt.Frame#getExtendedState()
* @since 1.4
*/
public int getOldState() {
return oldState;
}
/**
* For <code>WINDOW_STATE_CHANGED</code> events returns the
* new state of the window. The state is
* represented as a bitwise mask.
* <ul>
* <li><code>NORMAL</code>
* <br>Indicates that no state bits are set.
* <li><code>ICONIFIED</code>
* <li><code>MAXIMIZED_HORIZ</code>
* <li><code>MAXIMIZED_VERT</code>
* <li><code>MAXIMIZED_BOTH</code>
* <br>Concatenates <code>MAXIMIZED_HORIZ</code>
* and <code>MAXIMIZED_VERT</code>.
* </ul>
*
* @return a bitwise mask of the new window state
* @see java.awt.Frame#getExtendedState()
* @since 1.4
*/
public int getNewState() {
return newState;
}
/**
* Returns a parameter string identifying this event.
* This method is useful for event-logging and for debugging.
*
* @return a string identifying the event and its attributes
*/
public String paramString() {
String typeStr;
switch(id) {
case WINDOW_OPENED:
typeStr = "WINDOW_OPENED";
break;
case WINDOW_CLOSING:
typeStr = "WINDOW_CLOSING";
break;
case WINDOW_CLOSED:
typeStr = "WINDOW_CLOSED";
break;
case WINDOW_ICONIFIED:
typeStr = "WINDOW_ICONIFIED";
break;
case WINDOW_DEICONIFIED:
typeStr = "WINDOW_DEICONIFIED";
break;
case WINDOW_ACTIVATED:
typeStr = "WINDOW_ACTIVATED";
break;
case WINDOW_DEACTIVATED:
typeStr = "WINDOW_DEACTIVATED";
break;
case WINDOW_GAINED_FOCUS:
typeStr = "WINDOW_GAINED_FOCUS";
break;
case WINDOW_LOST_FOCUS:
typeStr = "WINDOW_LOST_FOCUS";
break;
case WINDOW_STATE_CHANGED:
typeStr = "WINDOW_STATE_CHANGED";
break;
default:
typeStr = "unknown type";
}
typeStr += ",opposite=" + getOppositeWindow()
+ ",oldState=" + oldState + ",newState=" + newState;
return typeStr;
}
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving <code>WindowEvents</code>, including
* <code>WINDOW_GAINED_FOCUS</code> and <code>WINDOW_LOST_FOCUS</code> events.
* The class that is interested in processing a <code>WindowEvent</code>
* either implements this interface (and
* all the methods it contains) or extends the abstract
* <code>WindowAdapter</code> class (overriding only the methods of interest).
* The listener object created from that class is then registered with a
* <code>Window</code>
* using the <code>Window</code>'s <code>addWindowFocusListener</code> method.
* When the <code>Window</code>'s
* status changes by virtue of it being opened, closed, activated, deactivated,
* iconified, or deiconified, or by focus being transfered into or out of the
* <code>Window</code>, the relevant method in the listener object is invoked,
* and the <code>WindowEvent</code> is passed to it.
*
* @author David Mendenhall
*
* @see WindowAdapter
* @see WindowEvent
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/windowlistener.html">Tutorial: Writing a Window Listener</a>
*
* @since 1.4
*/
public interface WindowFocusListener extends EventListener {
/**
* Invoked when the Window is set to be the focused Window, which means
* that the Window, or one of its subcomponents, will receive keyboard
* events.
*/
public void windowGainedFocus(WindowEvent e);
/**
* Invoked when the Window is no longer the focused Window, which means
* that keyboard events will no longer be delivered to the Window or any of
* its subcomponents.
*/
public void windowLostFocus(WindowEvent e);
}

View File

@@ -0,0 +1,103 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving window events.
* The class that is interested in processing a window event
* either implements this interface (and all the methods it
* contains) or extends the abstract <code>WindowAdapter</code> class
* (overriding only the methods of interest).
* The listener object created from that class is then registered with a
* Window using the window's <code>addWindowListener</code>
* method. When the window's status changes by virtue of being opened,
* closed, activated or deactivated, iconified or deiconified,
* the relevant method in the listener object is invoked, and the
* <code>WindowEvent</code> is passed to it.
*
* @author Carl Quinn
*
* @see WindowAdapter
* @see WindowEvent
* @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/windowlistener.html">Tutorial: How to Write Window Listeners</a>
*
* @since 1.1
*/
public interface WindowListener extends EventListener {
/**
* Invoked the first time a window is made visible.
*/
public void windowOpened(WindowEvent e);
/**
* Invoked when the user attempts to close the window
* from the window's system menu.
*/
public void windowClosing(WindowEvent e);
/**
* Invoked when a window has been closed as the result
* of calling dispose on the window.
*/
public void windowClosed(WindowEvent e);
/**
* Invoked when a window is changed from a normal to a
* minimized state. For many platforms, a minimized window
* is displayed as the icon specified in the window's
* iconImage property.
* @see java.awt.Frame#setIconImage
*/
public void windowIconified(WindowEvent e);
/**
* Invoked when a window is changed from a minimized
* to a normal state.
*/
public void windowDeiconified(WindowEvent e);
/**
* Invoked when the Window is set to be the active Window. Only a Frame or
* a Dialog can be the active Window. The native windowing system may
* denote the active Window or its children with special decorations, such
* as a highlighted title bar. The active Window is always either the
* focused Window, or the first Frame or Dialog that is an owner of the
* focused Window.
*/
public void windowActivated(WindowEvent e);
/**
* Invoked when a Window is no longer the active Window. Only a Frame or a
* Dialog can be the active Window. The native windowing system may denote
* the active Window or its children with special decorations, such as a
* highlighted title bar. The active Window is always either the focused
* Window, or the first Frame or Dialog that is an owner of the focused
* Window.
*/
public void windowDeactivated(WindowEvent e);
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving window state events.
* <p>
* The class that is interested in processing a window state event
* either implements this interface (and all the methods it contains)
* or extends the abstract <code>WindowAdapter</code> class
* (overriding only the methods of interest).
* <p>
* The listener object created from that class is then registered with
* a window using the <code>Window</code>'s
* <code>addWindowStateListener</code> method. When the window's
* state changes by virtue of being iconified, maximized etc., the
* <code>windowStateChanged</code> method in the listener object is
* invoked, and the <code>WindowEvent</code> is passed to it.
*
* @see java.awt.event.WindowAdapter
* @see java.awt.event.WindowEvent
*
* @since 1.4
*/
public interface WindowStateListener extends EventListener {
/**
* Invoked when window state is changed.
*/
public void windowStateChanged(WindowEvent e);
}