30 import java.awt.Rectangle; 31 import java.lang.annotation.Native; 32 33 /** 34 * A low-level event which indicates that a component moved, changed 35 * size, or changed visibility (also, the root class for the other 36 * component-level events). 37 * <P> 38 * Component events are provided for notification purposes ONLY; 39 * The AWT will automatically handle component moves and resizes 40 * internally so that GUI layout works properly regardless of 41 * whether a program is receiving these events or not. 42 * <P> 43 * In addition to serving as the base class for other component-related 44 * events (InputEvent, FocusEvent, WindowEvent, ContainerEvent), 45 * this class defines the events that indicate changes in 46 * a component's size, position, or visibility. 47 * <P> 48 * This low-level event is generated by a component object (such as a 49 * List) when the component is moved, resized, rendered invisible, or made 50 * visible again. The event is passed to every <code>ComponentListener</code> 51 * or <code>ComponentAdapter</code> object which registered to receive such 52 * events using the component's <code>addComponentListener</code> method. 53 * (<code>ComponentAdapter</code> objects implement the 54 * <code>ComponentListener</code> interface.) Each such listener object 55 * gets this <code>ComponentEvent</code> when the event occurs. 56 * <p> 57 * An unspecified behavior will be caused if the {@code id} parameter 58 * of any particular {@code ComponentEvent} instance is not 59 * in the range from {@code COMPONENT_FIRST} to {@code COMPONENT_LAST}. 60 * 61 * @see ComponentAdapter 62 * @see ComponentListener 63 * @see <a href="http://docs.oracle.com/javase/tutorial/uiswing/events/componentlistener.html">Tutorial: Writing a Component Listener</a> 64 * 65 * @author Carl Quinn 66 * @since 1.1 67 */ 68 public class ComponentEvent extends AWTEvent { 69 70 /** 71 * The first number in the range of ids used for component events. 72 */ 73 public static final int COMPONENT_FIRST = 100; 74 75 /** 86 * This event indicates that the component's size changed. 87 */ 88 @Native public static final int COMPONENT_RESIZED = 1 + COMPONENT_FIRST; 89 90 /** 91 * This event indicates that the component was made visible. 92 */ 93 @Native public static final int COMPONENT_SHOWN = 2 + COMPONENT_FIRST; 94 95 /** 96 * This event indicates that the component was rendered invisible. 97 */ 98 @Native public static final int COMPONENT_HIDDEN = 3 + COMPONENT_FIRST; 99 100 /* 101 * JDK 1.1 serialVersionUID 102 */ 103 private static final long serialVersionUID = 8101406823902992965L; 104 105 /** 106 * Constructs a <code>ComponentEvent</code> object. 107 * <p> This method throws an 108 * <code>IllegalArgumentException</code> if <code>source</code> 109 * is <code>null</code>. 110 * 111 * @param source The <code>Component</code> that originated the event 112 * @param id An integer indicating the type of event. 113 * For information on allowable values, see 114 * the class description for {@link ComponentEvent} 115 * @throws IllegalArgumentException if <code>source</code> is null 116 * @see #getComponent() 117 * @see #getID() 118 */ 119 public ComponentEvent(Component source, int id) { 120 super(source, id); 121 } 122 123 /** 124 * Returns the originator of the event. 125 * 126 * @return the <code>Component</code> object that originated 127 * the event, or <code>null</code> if the object is not a 128 * <code>Component</code>. 129 */ 130 public Component getComponent() { 131 return (source instanceof Component) ? (Component)source : null; 132 } 133 134 /** 135 * Returns a parameter string identifying this event. 136 * This method is useful for event-logging and for debugging. 137 * 138 * @return a string identifying the event and its attributes 139 */ 140 public String paramString() { 141 String typeStr; 142 Rectangle b = (source !=null 143 ? ((Component)source).getBounds() 144 : null); 145 146 switch(id) { 147 case COMPONENT_SHOWN: 148 typeStr = "COMPONENT_SHOWN"; | 30 import java.awt.Rectangle; 31 import java.lang.annotation.Native; 32 33 /** 34 * A low-level event which indicates that a component moved, changed 35 * size, or changed visibility (also, the root class for the other 36 * component-level events). 37 * <P> 38 * Component events are provided for notification purposes ONLY; 39 * The AWT will automatically handle component moves and resizes 40 * internally so that GUI layout works properly regardless of 41 * whether a program is receiving these events or not. 42 * <P> 43 * In addition to serving as the base class for other component-related 44 * events (InputEvent, FocusEvent, WindowEvent, ContainerEvent), 45 * this class defines the events that indicate changes in 46 * a component's size, position, or visibility. 47 * <P> 48 * This low-level event is generated by a component object (such as a 49 * List) when the component is moved, resized, rendered invisible, or made 50 * visible again. The event is passed to every {@code ComponentListener} 51 * or {@code ComponentAdapter} object which registered to receive such 52 * events using the component's {@code addComponentListener} method. 53 * ({@code ComponentAdapter} objects implement the 54 * {@code ComponentListener} interface.) Each such listener object 55 * gets this {@code ComponentEvent} when the event occurs. 56 * <p> 57 * An unspecified behavior will be caused if the {@code id} parameter 58 * of any particular {@code ComponentEvent} instance is not 59 * in the range from {@code COMPONENT_FIRST} to {@code COMPONENT_LAST}. 60 * 61 * @see ComponentAdapter 62 * @see ComponentListener 63 * @see <a href="http://docs.oracle.com/javase/tutorial/uiswing/events/componentlistener.html">Tutorial: Writing a Component Listener</a> 64 * 65 * @author Carl Quinn 66 * @since 1.1 67 */ 68 public class ComponentEvent extends AWTEvent { 69 70 /** 71 * The first number in the range of ids used for component events. 72 */ 73 public static final int COMPONENT_FIRST = 100; 74 75 /** 86 * This event indicates that the component's size changed. 87 */ 88 @Native public static final int COMPONENT_RESIZED = 1 + COMPONENT_FIRST; 89 90 /** 91 * This event indicates that the component was made visible. 92 */ 93 @Native public static final int COMPONENT_SHOWN = 2 + COMPONENT_FIRST; 94 95 /** 96 * This event indicates that the component was rendered invisible. 97 */ 98 @Native public static final int COMPONENT_HIDDEN = 3 + COMPONENT_FIRST; 99 100 /* 101 * JDK 1.1 serialVersionUID 102 */ 103 private static final long serialVersionUID = 8101406823902992965L; 104 105 /** 106 * Constructs a {@code ComponentEvent} object. 107 * <p> This method throws an 108 * {@code IllegalArgumentException} if {@code source} 109 * is {@code null}. 110 * 111 * @param source The {@code Component} that originated the event 112 * @param id An integer indicating the type of event. 113 * For information on allowable values, see 114 * the class description for {@link ComponentEvent} 115 * @throws IllegalArgumentException if {@code source} is null 116 * @see #getComponent() 117 * @see #getID() 118 */ 119 public ComponentEvent(Component source, int id) { 120 super(source, id); 121 } 122 123 /** 124 * Returns the originator of the event. 125 * 126 * @return the {@code Component} object that originated 127 * the event, or {@code null} if the object is not a 128 * {@code Component}. 129 */ 130 public Component getComponent() { 131 return (source instanceof Component) ? (Component)source : null; 132 } 133 134 /** 135 * Returns a parameter string identifying this event. 136 * This method is useful for event-logging and for debugging. 137 * 138 * @return a string identifying the event and its attributes 139 */ 140 public String paramString() { 141 String typeStr; 142 Rectangle b = (source !=null 143 ? ((Component)source).getBounds() 144 : null); 145 146 switch(id) { 147 case COMPONENT_SHOWN: 148 typeStr = "COMPONENT_SHOWN"; |