8187443: Forest Consolidation: Move files to unified layout

Reviewed-by: darcy, ihse
This commit is contained in:
Erik Joelsson 2017-09-12 19:03:39 +02:00
parent 270fe13182
commit 3789983e89
56923 changed files with 3 additions and 15727 deletions

View file

@ -0,0 +1,63 @@
/*
* 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 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} method. When an event is
* dispatched anywhere in the AWT, that object's
* {@code eventDispatched} 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.
* @param event the event to be processed
*/
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.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}) when
* the component-specific action occurs (such as being pressed).
* The event is passed to every {@code ActionListener} object
* that registered to receive such events using the component's
* {@code addActionListener} method.
* <p>
* <b>Note:</b> To invoke an {@code ActionEvent} on a
* {@code Button} using the keyboard, use the Space bar.
* <P>
* The object that implements the {@code ActionListener} interface
* gets this {@code ActionEvent} 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="http://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 = 1 << 0;
/**
* The control modifier. An indicator that the control key was held
* down during the event.
*/
public static final int CTRL_MASK = 1 << 1;
/**
* The meta modifier. An indicator that the meta key was held
* down during the event.
*/
public static final int META_MASK = 1 << 2;
/**
* The alt modifier. An indicator that the alt key was held
* down during the event.
*/
public static final int ALT_MASK = 1 << 3;
/**
* 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} object.
* <p>
* This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
* A {@code null command} 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} 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} object with modifier keys.
* <p>
* This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
* A {@code null command} 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} 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} object with the specified
* modifier keys and timestamp.
* <p>
* This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
* A {@code null command} 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} 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} command string was passed
* to the constructor for this {@code ActionEvent}, this
* this method returns {@code null}.
*
* @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
*/
@SuppressWarnings("deprecation")
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,53 @@
/*
* 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} method. When the action event
* occurs, that object's {@code actionPerformed} method is
* invoked.
*
* @see ActionEvent
* @see <a href="http://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.
* @param e the event to be processed
*/
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} 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} 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} 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} object with the
* specified {@code Adjustable} source, event type,
* adjustment type, and value.
* <p> This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source The {@code Adjustable} 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} 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} object with the
* specified Adjustable source, event type, adjustment type, and value.
* <p> This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source The {@code Adjustable} 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} if the event is one
* of a series of multiple adjusting events,
* otherwise {@code false}
* @throws IllegalArgumentException if {@code source} 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} object where this event originated.
*
* @return the {@code Adjustable} 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} if this is one of multiple
* adjustment events.
*
* @return {@code true} if this is one of multiple
* adjustment events, otherwise returns {@code false}
* @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,44 @@
/*
* 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 adjustment events.
*
* @author Amy Fowler
* @since 1.1
*/
public interface AdjustmentListener extends EventListener {
/**
* Invoked when the value of the adjustable has changed.
* @param e the event to be processed
*/
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} listener
* and override the methods for the events of interest. (If you implement the
* {@code ComponentListener} 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}
* method. When the component's size, location, or visibility
* changes, the relevant method in the listener object is invoked,
* and the {@code ComponentEvent} is passed to it.
*
* @see ComponentEvent
* @see ComponentListener
* @see <a href="http://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}
* or {@code ComponentAdapter} object which registered to receive such
* events using the component's {@code addComponentListener} method.
* ({@code ComponentAdapter} objects implement the
* {@code ComponentListener} interface.) Each such listener object
* gets this {@code ComponentEvent} 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="http://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} object.
* <p> This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source The {@code Component} 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} 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} object that originated
* the event, or {@code null} if the object is not a
* {@code Component}.
*/
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,78 @@
/*
* 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} 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}
* method. When the component's size, location, or visibility
* changes, the relevant method in the listener object is invoked,
* and the {@code ComponentEvent} 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} or not.
*
* @see ComponentAdapter
* @see ComponentEvent
* @see <a href="http://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.
* @param e the event to be processed
*/
public void componentResized(ComponentEvent e);
/**
* Invoked when the component's position changes.
* @param e the event to be processed
*/
public void componentMoved(ComponentEvent e);
/**
* Invoked when the component has been made visible.
* @param e the event to be processed
*/
public void componentShown(ComponentEvent e);
/**
* Invoked when the component has been made invisible.
* @param e the event to be processed
*/
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} listener
* and override the methods for the events of interest. (If you implement the
* {@code ContainerListener} 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}
* 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} is passed to it.
*
* @see ContainerEvent
* @see ContainerListener
* @see <a href="http://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}
* or {@code ContainerAdapter} object which registered to receive such
* events using the component's {@code addContainerListener} method.
* ({@code ContainerAdapter} objects implement the
* {@code ContainerListener} interface.) Each such listener object
* gets this {@code ContainerEvent} 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="http://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} object.
* <p> This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source The {@code Component} 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} 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} object that originated
* the event, or {@code null} if the object is not a
* {@code Container}.
*/
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,68 @@
/*
* 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} 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}
* 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} 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="http://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.
* @param e the event to be processed
*/
public void componentAdded(ContainerEvent e);
/**
* Invoked when a component has been removed from the container.
* @param e the event to be processed
*/
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} listener
* and override the methods for the events of interest. (If you implement the
* {@code FocusListener} 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}
* method. When the component gains or loses the keyboard focus,
* the relevant method in the listener object is invoked,
* and the {@code FocusEvent} is passed to it.
*
* @see FocusEvent
* @see FocusListener
* @see <a href="http://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,405 @@
/*
* Copyright (c) 1996, 2016, 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.io.ObjectStreamException;
import sun.awt.AWTAccessor;
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} or
* {@code FocusAdapter} object which registered to receive such events
* using the Component's {@code addFocusListener} method.
* ({@code FocusAdapter} objects implement the {@code FocusListener}
* interface.) Each such listener object gets this {@code FocusEvent} 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>
* Every {@code FocusEvent} records its cause - the reason why this event was
* generated. The cause is assigned during the focus event creation and may be
* retrieved by calling {@link #getCause}.
* <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="http://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 {
/**
* This enum represents the cause of a {@code FocusEvent}- the reason why it
* occurred. Possible reasons include mouse events, keyboard focus
* traversal, window activation.
* If no cause is provided then the reason is {@code UNKNOWN}.
*
* @since 9
*/
public enum Cause {
/**
* The default value.
*/
UNKNOWN,
/**
* An activating mouse event.
*/
MOUSE_EVENT,
/**
* A focus traversal action with unspecified direction.
*/
TRAVERSAL,
/**
* An up-cycle focus traversal action.
*/
TRAVERSAL_UP,
/**
* A down-cycle focus traversal action.
*/
TRAVERSAL_DOWN,
/**
* A forward focus traversal action.
*/
TRAVERSAL_FORWARD,
/**
* A backward focus traversal action.
*/
TRAVERSAL_BACKWARD,
/**
* Restoring focus after a focus request has been rejected.
*/
ROLLBACK,
/**
* A system action causing an unexpected focus change.
*/
UNEXPECTED,
/**
* An activation of a toplevel window.
*/
ACTIVATION,
/**
* Clearing global focus owner.
*/
CLEAR_GLOBAL_FOCUS_OWNER
}
/**
* 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 has the reason why this event was generated.
* The cause is set during the focus event creation.
*
* @serial
* @see #getCause()
* @since 9
*/
private final Cause cause;
/**
* 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} object with the
* specified temporary state, opposite {@code Component} and the
* {@code Cause.UNKNOWN} cause.
* The opposite {@code Component} is the other
* {@code Component} involved in this focus change.
* For a {@code FOCUS_GAINED} event, this is the
* {@code Component} that lost focus. For a
* {@code FOCUS_LOST} event, this is the {@code Component}
* 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}, then the opposite
* {@code Component} is {@code null}.
* <p> This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source The {@code Component} 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} if the focus change is temporary;
* {@code false} otherwise
* @param opposite The other Component involved in the focus change,
* or {@code null}
* @throws IllegalArgumentException if {@code source} equals {@code null}
* @see #getSource()
* @see #getID()
* @see #isTemporary()
* @see #getOppositeComponent()
* @see Cause#UNKNOWN
* @since 1.4
*/
public FocusEvent(Component source, int id, boolean temporary,
Component opposite) {
this(source, id, temporary, opposite, Cause.UNKNOWN);
}
/**
* Constructs a {@code FocusEvent} object with the
* specified temporary state, opposite {@code Component} and the cause.
* The opposite {@code Component} is the other
* {@code Component} involved in this focus change.
* For a {@code FOCUS_GAINED} event, this is the
* {@code Component} that lost focus. For a
* {@code FOCUS_LOST} event, this is the {@code Component}
* 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}, then the opposite
* {@code Component} is {@code null}.
* <p> This method throws an
* {@code IllegalArgumentException} if {@code source} or {@code cause}
* is {@code null}.
*
* @param source The {@code Component} 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} if the focus change is temporary;
* {@code false} otherwise
* @param opposite The other Component involved in the focus change,
* or {@code null}
* @param cause The focus event cause.
* @throws IllegalArgumentException if {@code source} equals {@code null}
* or if {@code cause} equals {@code null}
* @see #getSource()
* @see #getID()
* @see #isTemporary()
* @see #getOppositeComponent()
* @see Cause
* @since 9
*/
public FocusEvent(Component source, int id, boolean temporary,
Component opposite, Cause cause) {
super(source, id);
if (cause == null) {
throw new IllegalArgumentException("null cause");
}
this.temporary = temporary;
this.opposite = opposite;
this.cause = cause;
}
/**
* Constructs a {@code FocusEvent} object and identifies
* whether or not the change is temporary.
* <p> This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source The {@code Component} 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} if the focus change is temporary;
* {@code false} otherwise
* @throws IllegalArgumentException if {@code source} 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} object and identifies it
* as a permanent change in focus.
* <p> This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source The {@code Component} 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} 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} if the focus change is temporary;
* {@code false} 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() + ",cause=" + getCause();
}
/**
* Returns the event cause.
*
* @return one of {@link Cause} values
* @since 9
*/
public final Cause getCause() {
return cause;
}
/**
* Checks if this deserialized {@code FocusEvent} instance is compatible
* with the current specification which implies that focus event has
* non-null {@code cause} value. If the check fails a new {@code FocusEvent}
* instance is returned which {@code cause} field equals to
* {@link Cause#UNKNOWN} and its other fields have the same values as in
* this {@code FocusEvent} instance.
*
* @serial
* @see #cause
* @since 9
*/
@SuppressWarnings("serial")
Object readResolve() throws ObjectStreamException {
if (cause != null) {
return this;
}
FocusEvent focusEvent = new FocusEvent(new Component(){}, getID(),
isTemporary(), getOppositeComponent());
focusEvent.setSource(null);
focusEvent.consumed = consumed;
AWTAccessor.AWTEventAccessor accessor =
AWTAccessor.getAWTEventAccessor();
accessor.setBData(focusEvent, accessor.getBData(this));
return focusEvent;
}
}

View file

@ -0,0 +1,63 @@
/*
* 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} 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}
* method. When the component gains or loses the keyboard focus,
* the relevant method in the listener object
* is invoked, and the {@code FocusEvent} is passed to it.
*
* @see FocusAdapter
* @see FocusEvent
* @see <a href="http://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.
* @param e the event to be processed
*/
public void focusGained(FocusEvent e);
/**
* Invoked when a component loses the keyboard focus.
* @param e the event to be processed
*/
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} 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}
* 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} 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,64 @@
/*
* Copyright (c) 1999, 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 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} 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}
* 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} 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} 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.
* @param e the event to be processed
*/
public void ancestorMoved(HierarchyEvent e);
/**
* Called when an ancestor of the source is resized.
* @param e the event to be processed
*/
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}
* hierarchy to which {@code Component} 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 removeNotify}, {@code show}, or
* {@code hide} method is called. The {@code ANCESTOR_MOVED} and
* {@code ANCESTOR_RESIZED}
* events are dispatched to every {@code HierarchyBoundsListener} or
* {@code HierarchyBoundsAdapter} object which registered to receive
* such events using the Component's {@code addHierarchyBoundsListener}
* method. ({@code HierarchyBoundsAdapter} objects implement the
* {@code HierarchyBoundsListener} interface.) The {@code HIERARCHY_CHANGED} events are
* dispatched to every {@code HierarchyListener} object which registered
* to receive such events using the Component's {@code addHierarchyListener}
* method. Each such listener object gets this {@code HierarchyEvent}
* 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} event
* was generated by a reparenting operation.
*/
public static final int PARENT_CHANGED = 0x1;
/**
* A change flag indicates that the {@code HIERARCHY_CHANGED} event
* was generated due to the changing of the hierarchy displayability.
* To discern the
* current displayability of the hierarchy, call the
* {@code Component.isDisplayable} method. Displayability changes occur
* in response to explicit or implicit calls of the
* {@code Component.addNotify} and
* {@code Component.removeNotify} 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} 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} 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} and
* {@code Component.hide} 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} object to identify a
* change in the {@code Component} hierarchy.
* <p>This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source The {@code Component} 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} at the top of
* the hierarchy which was changed
* @param changedParent The parent of the {@code changed} component.
* This
* may be the parent before or after the
* change, depending on the type of change
* @throws IllegalArgumentException if {@code source} 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} object to identify
* a change in the {@code Component} hierarchy.
* <p> This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source The {@code Component} 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} at the top
* of the hierarchy which was changed
* @param changedParent The parent of the {@code changed} 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} events
* represented in this event object.
* For information on allowable values, see
* the class description for {@link HierarchyEvent}
* @throws IllegalArgumentException if {@code source} 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} object that originated
* the event, or {@code null} if the object is not a
* {@code Component}.
*/
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()}. For a HIERARCHY_CHANGED event where the
* change was of type PARENT_CHANGED via a call to
* {@code Container.add}, 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}, 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,58 @@
/*
* Copyright (c) 1999, 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 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}
* method. When the hierarchy to which the Component belongs changes, the
* {@code hierarchyChanged} method in the listener object is invoked,
* and the {@code HierarchyEvent} 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} 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()}.
*
* @param e the event to be processed
* @see HierarchyEvent#getChangeFlags()
*/
public void hierarchyChanged(HierarchyEvent e);
}

View file

@ -0,0 +1,585 @@
/*
* Copyright (c) 1996, 2016, 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.awt.AWTPermissions;
import sun.util.logging.PlatformLogger;
/**
* 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.
*
* @deprecated It is recommended that SHIFT_DOWN_MASK and
* {@link #getModifiersEx()} be used instead
*/
@Deprecated(since = "9")
public static final int SHIFT_MASK = Event.SHIFT_MASK;
/**
* The Control key modifier constant.
*
* @deprecated It is recommended that CTRL_DOWN_MASK and
* {@link #getModifiersEx()} be used instead
*/
@Deprecated(since = "9")
public static final int CTRL_MASK = Event.CTRL_MASK;
/**
* The Meta key modifier constant.
*
* @deprecated It is recommended that META_DOWN_MASK and
* {@link #getModifiersEx()} be used instead
*/
@Deprecated(since = "9")
public static final int META_MASK = Event.META_MASK;
/**
* The Alt key modifier constant.
*
* @deprecated It is recommended that ALT_DOWN_MASK and
* {@link #getModifiersEx()} be used instead
*/
@Deprecated(since = "9")
public static final int ALT_MASK = Event.ALT_MASK;
/**
* The AltGraph key modifier constant.
*
* @deprecated It is recommended that ALT_GRAPH_DOWN_MASK and
* {@link #getModifiersEx()} be used instead
*/
@Deprecated(since = "9")
public static final int ALT_GRAPH_MASK = 1 << 5;
/**
* The Mouse Button1 modifier constant.
*
* @deprecated It is recommended that BUTTON1_DOWN_MASK and
* {@link #getModifiersEx()} be used instead
*/
@Deprecated(since = "9")
public static final int BUTTON1_MASK = 1 << 4;
/**
* The Mouse Button2 modifier constant.
*
* @deprecated It is recommended that BUTTON2_DOWN_MASK and
* {@link #getModifiersEx()} be used instead. Note that
* BUTTON2_MASK has the same value as ALT_MASK.
*/
@Deprecated(since = "9")
public static final int BUTTON2_MASK = Event.ALT_MASK;
/**
* The Mouse Button3 modifier constant.
*
* @deprecated It is recommended that BUTTON3_DOWN_MASK and
* {@link #getModifiersEx()} be used instead. Note that
* BUTTON3_MASK has the same value as META_MASK.
*/
@Deprecated(since = "9")
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 1.7
*/
private static final int [] BUTTON_DOWN_MASK = new int [] { BUTTON1_DOWN_MASK,
BUTTON2_DOWN_MASK,
BUTTON3_DOWN_MASK,
1<<14, //4th physical 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 1.7
*/
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()}.
*
* @return a mask for an existing mouse button.
* @throws IllegalArgumentException if {@code button} is less than zero or greater than the number
* of button masks reserved for buttons
* @since 1.7
* @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();
}
public boolean canAccessSystemClipboard(InputEvent event) {
return event.canAccessSystemClipboard;
}
@Override
public void setCanAccessSystemClipboard(InputEvent event,
boolean canAccessSystemClipboard) {
event.canAccessSystemClipboard = canAccessSystemClipboard;
}
});
}
/**
* 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} if {@code source}
* is {@code null}.
*
* @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} 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(AWTPermissions.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.
* @return whether or not the Shift modifier is down on this event
*/
public boolean isShiftDown() {
return (modifiers & SHIFT_DOWN_MASK) != 0;
}
/**
* Returns whether or not the Control modifier is down on this event.
* @return whether or not the Control modifier is down on this event
*/
public boolean isControlDown() {
return (modifiers & CTRL_DOWN_MASK) != 0;
}
/**
* Returns whether or not the Meta modifier is down on this event.
* @return whether or not the Meta modifier is down on this event
*/
public boolean isMetaDown() {
return (modifiers & META_DOWN_MASK) != 0;
}
/**
* Returns whether or not the Alt modifier is down on this event.
* @return whether or not the Alt modifier is down on this event
*/
public boolean isAltDown() {
return (modifiers & ALT_DOWN_MASK) != 0;
}
/**
* Returns whether or not the AltGraph modifier is down on this event.
* @return whether or not the AltGraph modifier is down on this event
*/
public boolean isAltGraphDown() {
return (modifiers & ALT_GRAPH_DOWN_MASK) != 0;
}
/**
* Returns the difference in milliseconds between the timestamp of when this event occurred and
* midnight, January 1, 1970 UTC.
* @return the difference in milliseconds between the timestamp and midnight, January 1, 1970 UTC
*/
public long getWhen() {
return when;
}
/**
* Returns the modifier mask for this event.
*
* @return the modifier mask for this event
* @deprecated It is recommended that extended modifier keys and
* {@link #getModifiersEx()} be used instead
*/
@Deprecated(since = "9")
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 BUTTON1_DOWN_MASK}
* {@code MOUSE_PRESSED}: {@code BUTTON1_DOWN_MASK | BUTTON2_DOWN_MASK}
* {@code MOUSE_RELEASED}: {@code BUTTON2_DOWN_MASK}
* {@code MOUSE_CLICKED}: {@code BUTTON2_DOWN_MASK}
* {@code MOUSE_RELEASED}:
* {@code MOUSE_CLICKED}:
* </PRE>
* <P>
* It is not recommended to compare the return value of this method
* using {@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.
*
* @return the extended modifier mask for this event
* @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.
* @return 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} 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.
*
* @return a String describing the extended modifier keys and
* mouse buttons
*
* @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,443 @@
/*
* 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} 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}
* if this is an {@code INPUT_METHOD_TEXT_CHANGED} event,
* the composed text within the {@code text} of the
* preceding {@code INPUT_METHOD_TEXT_CHANGED} event otherwise.
* <p>Note that passing in an invalid {@code id} results in
* unspecified behavior. This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @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}
* when the event type is {@code CARET_POSITION_CHANGED};
* may be {@code null} for
* {@code INPUT_METHOD_TEXT_CHANGED} 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} if there's no caret within current
* composed text
* @param visiblePosition the position that's most important
* to be visible; {@code null} if there's no
* recommendation for a visible position within current
* composed text
* @throws IllegalArgumentException if {@code id} is not
* in the range
* {@code INPUT_METHOD_FIRST}..{@code INPUT_METHOD_LAST};
* or if id is {@code CARET_POSITION_CHANGED} and
* {@code text} is not {@code null};
* or if {@code committedCharacterCount} is not in the range
* {@code 0}..{@code (text.getEndIndex() - text.getBeginIndex())}
* @throws IllegalArgumentException if {@code source} 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} 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}
* if this is an {@code INPUT_METHOD_TEXT_CHANGED} event,
* the composed text within the {@code text} of the
* preceding {@code INPUT_METHOD_TEXT_CHANGED} 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} results in
* unspecified behavior. This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @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}
* when the event type is {@code CARET_POSITION_CHANGED};
* may be {@code null} for
* {@code INPUT_METHOD_TEXT_CHANGED} 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} if there's no caret within current
* composed text
* @param visiblePosition the position that's most important
* to be visible; {@code null} if there's no
* recommendation for a visible position within current
* composed text
* @throws IllegalArgumentException if {@code id} is not
* in the range
* {@code INPUT_METHOD_FIRST}..{@code INPUT_METHOD_LAST};
* or if id is {@code CARET_POSITION_CHANGED} and
* {@code text} is not {@code null};
* or if {@code committedCharacterCount} is not in the range
* {@code 0}..{@code (text.getEndIndex() - text.getBeginIndex())}
* @throws IllegalArgumentException if {@code source} 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} with the
* specified source component, type, caret, and visiblePosition.
* The text is set to {@code null},
* {@code committedCharacterCount} to 0.
* <p>
* The offsets of {@code caret} and {@code visiblePosition}
* are relative to the current composed text; that is,
* the composed text within the {@code text} of the
* preceding {@code INPUT_METHOD_TEXT_CHANGED} event if the
* event being constructed as a {@code CARET_POSITION_CHANGED} event.
* For an {@code INPUT_METHOD_TEXT_CHANGED} event without text,
* {@code caret} and {@code visiblePosition} must be
* {@code null}.
* The time stamp for this event is initialized by invoking
* {@link java.awt.EventQueue#getMostRecentEventTime()}.
* <p>Note that passing in an invalid {@code id} results in
* unspecified behavior. This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source the object where the event originated
* @param id the event type
* @param caret the caret (a.k.a. insertion point);
* {@code null} if there's no caret within current
* composed text
* @param visiblePosition the position that's most important
* to be visible; {@code null} if there's no
* recommendation for a visible position within current
* composed text
* @throws IllegalArgumentException if {@code id} is not
* in the range
* {@code INPUT_METHOD_FIRST}..{@code INPUT_METHOD_LAST}
* @throws IllegalArgumentException if {@code source} 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} 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.
* @return 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} event,
* the composed text within getText() of the
* preceding {@code INPUT_METHOD_TEXT_CHANGED} 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} event,
* the composed text within getText() of the
* preceding {@code INPUT_METHOD_TEXT_CHANGED} 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} 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, 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 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.
* @param event the event to be processed
*/
void inputMethodTextChanged(InputMethodEvent event);
/**
* Invoked when the caret within composed text has changed.
* @param event the event to be processed
*/
void caretPositionChanged(InputMethodEvent event);
}

View file

@ -0,0 +1,426 @@
/*
* 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()} method on a {@code Runnable
* } when dispatched by the AWT event dispatcher thread. This class can
* be used as a reference implementation of {@code ActiveEvent} rather
* than declaring a new class and defining {@code dispatch()}.<p>
*
* Instances of this class are placed on the {@code EventQueue} by calls
* to {@code invokeLater} and {@code invokeAndWait}. Client code
* can use this fact to write replacement functions for {@code invokeLater
* } and {@code invokeAndWait} without writing special-case code
* in any {@code AWTEventListener} 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()} method of the {@code runnable}
* 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} with the specified
* source which will execute the runnable's {@code run}
* method when dispatched.
* <p>This is a convenience constructor. An invocation of the form
* {@code InvocationEvent(source, runnable)}
* behaves in exactly the same way as the invocation of
* {@link #InvocationEvent(Object, Runnable, Object, boolean)
* InvocationEvent(source, runnable, null, false)}.
* <p> This method throws an {@code IllegalArgumentException}
* if {@code source} is {@code null}.
*
* @param source The {@code Object} that originated the event
* @param runnable The {@code Runnable} whose {@code run}
* method will be executed
* @throws IllegalArgumentException if {@code source} 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} with the specified
* source which will execute the runnable's {@code run}
* method when dispatched. If notifier is non-{@code null},
* {@code notifyAll()} will be called on it
* immediately after {@code run} has returned or thrown an exception.
* <p>An invocation of the form
* {@code InvocationEvent(source, runnable, notifier, catchThrowables)}
* behaves in exactly the same way as the invocation of
* {@link #InvocationEvent(Object, int, Runnable, Object, boolean)
* InvocationEvent(source, InvocationEvent.INVOCATION_DEFAULT, runnable, notifier, catchThrowables)}.
* <p>This method throws an {@code IllegalArgumentException}
* if {@code source} is {@code null}.
*
* @param source The {@code Object} that originated
* the event
* @param runnable The {@code Runnable} whose
* {@code run} method will be
* executed
* @param notifier The {@code Object} whose {@code notifyAll}
* method will be called after
* {@code Runnable.run} has returned or
* thrown an exception or after the event was
* disposed
* @param catchThrowables Specifies whether {@code dispatch}
* should catch Throwable when executing
* the {@code Runnable}'s {@code run}
* method, or should instead propagate those
* Throwables to the EventDispatchThread's
* dispatch loop
* @throws IllegalArgumentException if {@code source} 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} with the specified
* source which will execute the runnable's {@code run}
* method when dispatched. If listener is non-{@code null},
* {@code listener.run()} will be called immediately after
* {@code run} has returned, thrown an exception or the event
* was disposed.
* <p>This method throws an {@code IllegalArgumentException}
* if {@code source} is {@code null}.
*
* @param source The {@code Object} that originated
* the event
* @param runnable The {@code Runnable} whose
* {@code run} method will be
* executed
* @param listener The {@code Runnable}Runnable whose
* {@code run()} method will be called
* after the {@code InvocationEvent}
* was dispatched or disposed
* @param catchThrowables Specifies whether {@code dispatch}
* should catch Throwable when executing
* the {@code Runnable}'s {@code run}
* method, or should instead propagate those
* Throwables to the EventDispatchThread's
* dispatch loop
* @throws IllegalArgumentException if {@code source} is null
*/
public InvocationEvent(Object source, Runnable runnable, Runnable listener,
boolean catchThrowables) {
this(source, INVOCATION_DEFAULT, runnable, null, listener, catchThrowables);
}
/**
* Constructs an {@code InvocationEvent} with the specified
* source and ID which will execute the runnable's {@code run}
* method when dispatched. If notifier is non-{@code null},
* {@code notifyAll} will be called on it immediately after
* {@code run} has returned or thrown an exception.
* <p>This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source The {@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 InvocationEvent}
* @param runnable The {@code Runnable} whose
* {@code run} method will be executed
* @param notifier The {@code Object} whose {@code notifyAll}
* method will be called after
* {@code Runnable.run} has returned or
* thrown an exception or after the event was
* disposed
* @param catchThrowables Specifies whether {@code dispatch}
* should catch Throwable when executing the
* {@code Runnable}'s {@code run}
* method, or should instead propagate those
* Throwables to the EventDispatchThread's
* dispatch loop
* @throws IllegalArgumentException if {@code source} 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()} method and notifies the
* notifier (if any) when {@code run()} 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()} 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()} 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} object which
* registered to receive such events using the component's
* {@code addItemListener} method.
* <P>
* The object that implements the {@code ItemListener} interface gets
* this {@code ItemEvent} 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="http://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} indicates whether the {@code item}
* was selected or deselected.
*
* @serial
* @see #getStateChange()
*/
int stateChange;
/*
* JDK 1.1 serialVersionUID
*/
private static final long serialVersionUID = -608708132447206933L;
/**
* Constructs an {@code ItemEvent} object.
* <p> This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source The {@code ItemSelectable} 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} 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,57 @@
/*
* 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} method. When an
* item-selection event occurs, the listener object's
* {@code itemStateChanged} method is invoked.
*
* @author Amy Fowler
*
* @see java.awt.ItemSelectable
* @see ItemEvent
* @see <a href="http://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).
* @param e the event to be processed
*/
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} listener
* and override the methods for the events of interest. (If you implement the
* {@code KeyListener} 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}
* method. When a key is pressed, released, or typed,
* the relevant method in the listener object is invoked,
* and the {@code KeyEvent} is passed to it.
*
* @author Carl Quinn
*
* @see KeyEvent
* @see KeyListener
* @see <a href="http://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,76 @@
/*
* 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} 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}
* 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} 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.
* @param e the event to be processed
*/
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.
* @param e the event to be processed
*/
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.
* @param e the event to be processed
*/
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="http://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,89 @@
/*
* 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}.)
* <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} 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}
* 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} is passed to it.
*
* @author Carl Quinn
*
* @see MouseAdapter
* @see MouseEvent
* @see <a href="http://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.
* @param e the event to be processed
*/
public void mouseClicked(MouseEvent e);
/**
* Invoked when a mouse button has been pressed on a component.
* @param e the event to be processed
*/
public void mousePressed(MouseEvent e);
/**
* Invoked when a mouse button has been released on a component.
* @param e the event to be processed
*/
public void mouseReleased(MouseEvent e);
/**
* Invoked when the mouse enters a component.
* @param e the event to be processed
*/
public void mouseEntered(MouseEvent e);
/**
* Invoked when the mouse exits a component.
* @param e the event to be processed
*/
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} listener
* and override the methods for the events of interest. (If you implement the
* {@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 addMouseMotionListener}
* method. When the mouse is moved or dragged, the relevant method in the
* listener object is invoked and the {@code MouseEvent} is passed to it.
*
* @author Amy Fowler
*
* @see MouseEvent
* @see MouseMotionListener
* @see <a href="http://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,77 @@
/*
* 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}.)
* <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} 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}
* 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} is passed to it.
*
* @author Amy Fowler
*
* @see MouseMotionAdapter
* @see MouseEvent
* @see <a href="http://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} 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} events may not be delivered during a native
* Drag&amp;Drop operation.
* @param e the event to be processed
*/
public void mouseDragged(MouseEvent e);
/**
* Invoked when the mouse cursor has been moved onto a component
* but no buttons have been pushed.
* @param e the event to be processed
*/
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}
* object which registered to receive the "interesting" mouse events using the
* component's {@code addMouseWheelListener} method. Each such listener
* object gets a {@code MouseEvent} 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} 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}
* 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} 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} results in
* unspecified behavior. This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source the {@code Component} 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} and
* {@code WHEEL_BLOCK_SCROLL}
* @param scrollAmount for scrollType {@code WHEEL_UNIT_SCROLL},
* 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} 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} 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} results in
* unspecified behavior. This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.<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} 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} and
* {@code WHEEL_BLOCK_SCROLL}
* @param scrollAmount for scrollType {@code WHEEL_UNIT_SCROLL},
* 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} 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} 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} parameter results
* in unspecified behavior. This method throws an
* {@code IllegalArgumentException} if {@code source} equals
* {@code null}.
* <p>Even if inconsistent values for relative and absolute coordinates
* are passed to the constructor, a {@code MouseWheelEvent} instance
* is still created and no exception is thrown.
*
* @param source the {@code Component} 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} coordinate for the
* mouse location
* @param y the vertical {@code y} coordinate for the
* mouse location
* @param xAbs the absolute horizontal {@code x} coordinate for
* the mouse location
* @param yAbs the absolute vertical {@code y} coordinate for
* the mouse location
* @param clickCount the number of mouse clicks associated with the event
* @param popupTrigger a boolean value, {@code 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} and
* {@code WHEEL_BLOCK_SCROLL}
* @param scrollAmount for scrollType {@code WHEEL_UNIT_SCROLL},
* 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} 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} returns
* {@code MouseWheelEvent.WHEEL_UNIT_SCROLL}
*
* @return number of units to scroll, or an undefined value if
* {@code getScrollType} returns
* {@code MouseWheelEvent.WHEEL_BLOCK_SCROLL}
* @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} and
* {@code JScrollPane} 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} 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,59 @@
/*
* 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 mouse wheel events on a component.
* (For clicks and other mouse events, use the {@code MouseListener}.
* For mouse movement and drags, use the {@code MouseMotionListener}.)
* <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}
* method. A mouse wheel event is generated when the mouse wheel is rotated.
* When a mouse wheel event occurs, that object's {@code mouseWheelMoved}
* 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.
* @param e the event to be processed
* @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,141 @@
/*
* 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 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} object with the specified
* source component and type.
* <p> This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @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} 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.
* @return 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} object which registered to receive such
* events using the component's {@code addTextListener} method.
* <P>
* The object that implements the {@code TextListener} interface gets
* this {@code TextEvent} 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} object.
* <p> This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source The ({@code TextComponent}) 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} 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,57 @@
/*
* 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 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} method. When the
* component's text changes, the listener object's
* {@code textValueChanged} 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.
*
* @param e the event to be processed
*/
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} listener
* and override the methods for the events of interest. (If you implement the
* {@code WindowListener} 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}
* 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} is passed to it.
*
* @see WindowEvent
* @see WindowListener
* @see <a href="http://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
* transferred into or out of the Window.
* <P>
* The event is passed to every {@code WindowListener}
* or {@code WindowAdapter} object which registered to receive such
* events using the window's {@code addWindowListener} method.
* ({@code WindowAdapter} objects implement the
* {@code WindowListener} interface.) Each such listener object
* gets this {@code WindowEvent} 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="http://docs.oracle.com/javase/tutorial/uiswing/events/windowlistener.html">Tutorial: Writing a Window Listener</a>
*
* @since 1.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} object.
* <p>This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source The {@code Window} 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}
* @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} 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} object with the
* specified opposite {@code Window}. The opposite
* {@code Window} is the other {@code Window}
* involved in this focus or activation change.
* For a {@code WINDOW_ACTIVATED} or
* {@code WINDOW_GAINED_FOCUS} event, this is the
* {@code Window} that lost activation or focus.
* For a {@code WINDOW_DEACTIVATED} or
* {@code WINDOW_LOST_FOCUS} event, this is the
* {@code Window} 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}, then the opposite Window is {@code null}.
* <p>This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source The {@code Window} 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} of other event types
* will always be {@code null}.
* @param opposite The other {@code Window} involved in the
* focus or activation change, or {@code null}
* @throws IllegalArgumentException if {@code source} 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} object with the specified
* previous and new window states.
* <p>This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source The {@code Window} 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} 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} object.
* <p>This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source The {@code Window} 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} 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} events returns the
* previous state of the window. The state is
* represented as a bitwise mask.
* <ul>
* <li>{@code NORMAL}
* <br>Indicates that no state bits are set.
* <li>{@code ICONIFIED}
* <li>{@code MAXIMIZED_HORIZ}
* <li>{@code MAXIMIZED_VERT}
* <li>{@code MAXIMIZED_BOTH}
* <br>Concatenates {@code MAXIMIZED_HORIZ}
* and {@code MAXIMIZED_VERT}.
* </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} events returns the
* new state of the window. The state is
* represented as a bitwise mask.
* <ul>
* <li>{@code NORMAL}
* <br>Indicates that no state bits are set.
* <li>{@code ICONIFIED}
* <li>{@code MAXIMIZED_HORIZ}
* <li>{@code MAXIMIZED_VERT}
* <li>{@code MAXIMIZED_BOTH}
* <br>Concatenates {@code MAXIMIZED_HORIZ}
* and {@code MAXIMIZED_VERT}.
* </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,71 @@
/*
* 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}, including
* {@code WINDOW_GAINED_FOCUS} and {@code WINDOW_LOST_FOCUS} events.
* The class that is interested in processing a {@code WindowEvent}
* either implements this interface (and
* all the methods it contains) or extends the abstract
* {@code WindowAdapter} class (overriding only the methods of interest).
* The listener object created from that class is then registered with a
* {@code Window}
* using the {@code Window}'s {@code addWindowFocusListener} method.
* When the {@code Window}'s
* status changes by virtue of it being opened, closed, activated, deactivated,
* iconified, or deiconified, or by focus being transferred into or out of the
* {@code Window}, the relevant method in the listener object is invoked,
* and the {@code WindowEvent} is passed to it.
*
* @author David Mendenhall
*
* @see WindowAdapter
* @see WindowEvent
* @see <a href="http://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.
* @param e the event to be processed
*/
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.
* @param e the event to be processed
*/
public void windowLostFocus(WindowEvent e);
}

View file

@ -0,0 +1,110 @@
/*
* 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} 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}
* 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} is passed to it.
*
* @author Carl Quinn
*
* @see WindowAdapter
* @see WindowEvent
* @see <a href="http://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.
* @param e the event to be processed
*/
public void windowOpened(WindowEvent e);
/**
* Invoked when the user attempts to close the window
* from the window's system menu.
* @param e the event to be processed
*/
public void windowClosing(WindowEvent e);
/**
* Invoked when a window has been closed as the result
* of calling dispose on the window.
* @param e the event to be processed
*/
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.
* @param e the event to be processed
* @see java.awt.Frame#setIconImage
*/
public void windowIconified(WindowEvent e);
/**
* Invoked when a window is changed from a minimized
* to a normal state.
* @param e the event to be processed
*/
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.
* @param e the event to be processed
*/
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.
* @param e the event to be processed
*/
public void windowDeactivated(WindowEvent e);
}

View file

@ -0,0 +1,56 @@
/*
* Copyright (c) 2001, 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 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} 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}'s
* {@code addWindowStateListener} method. When the window's
* state changes by virtue of being iconified, maximized etc., the
* {@code windowStateChanged} method in the listener object is
* invoked, and the {@code WindowEvent} 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.
* @param e the event to be processed
*/
public void windowStateChanged(WindowEvent e);
}

View file

@ -0,0 +1,37 @@
/*
* Copyright (c) 1998, 2017, 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.
*/
/**
* Provides interfaces and classes for dealing with different types of events
* fired by AWT components. See the {@link java.awt.AWTEvent java.awt.AWTEvent}
* class for details on the AWT event model. Events are fired by event sources.
* An event listener registers with an event source to receive notifications
* about the events of a particular type. This package defines events and event
* listeners, as well as event listener adapters, which are convenience classes
* to make easier the process of writing event listeners.
*
* @since 1.1
*/
package java.awt.event;