001: /*
002: * @(#)ComponentEvent.java 1.24 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package java.awt.event;
029:
030: import java.awt.AWTEvent;
031: import java.awt.Component;
032: import java.awt.Rectangle;
033:
034: /**
035: * The root event class for all component-level events.
036: * These events are provided for notification purposes ONLY;
037: * The AWT will automatically handle component moves and resizes
038: * internally so that GUI layout works properly regardless of
039: * whether a program is receiving these events or not.
040: *
041: * @see ComponentListener
042: *
043: * @version 1.20 08/19/02
044: * @author Carl Quinn
045: */
046: public class ComponentEvent extends AWTEvent {
047: /**
048: * Marks the first integer id for the range of component event ids.
049: */
050: public static final int COMPONENT_FIRST = 100;
051: /**
052: * Marks the last integer id for the range of component event ids.
053: */
054: public static final int COMPONENT_LAST = 103;
055: /**
056: * The component moved event type.
057: */
058: public static final int COMPONENT_MOVED = COMPONENT_FIRST;
059: /**
060: * The component resized event type.
061: */
062: public static final int COMPONENT_RESIZED = 1 + COMPONENT_FIRST;
063: /**
064: * The component shown event type.
065: */
066: public static final int COMPONENT_SHOWN = 2 + COMPONENT_FIRST;
067: /**
068: * The component hidden event type.
069: */
070: public static final int COMPONENT_HIDDEN = 3 + COMPONENT_FIRST;
071: /*
072: * JDK 1.1 serialVersionUID
073: */
074: private static final long serialVersionUID = 8101406823902992965L;
075:
076: /**
077: * Constructs a ComponentEvent object with the specified source component
078: * and type.
079: * @param source the component where the event originated
080: * @id the event type
081: */
082: public ComponentEvent(Component source, int id) {
083: super (source, id);
084: }
085:
086: /**
087: * Returns the component where this event originated.
088: */
089: public Component getComponent() {
090: // return (source instanceof Component) ? (Component)source : null;
091: return (Component) source; // cast should always be OK, type was checked in constructor
092: }
093:
094: public String paramString() {
095: String typeStr;
096: Rectangle b = (source != null ? ((Component) source)
097: .getBounds() : null);
098: switch (id) {
099: case COMPONENT_SHOWN:
100: typeStr = "COMPONENT_SHOWN";
101: break;
102:
103: case COMPONENT_HIDDEN:
104: typeStr = "COMPONENT_HIDDEN";
105: break;
106:
107: case COMPONENT_MOVED:
108: typeStr = "COMPONENT_MOVED (" + b.x + "," + b.y + " "
109: + b.width + "x" + b.height + ")";
110: break;
111:
112: case COMPONENT_RESIZED:
113: typeStr = "COMPONENT_RESIZED (" + b.x + "," + b.y + " "
114: + b.width + "x" + b.height + ")";
115: break;
116:
117: default:
118: typeStr = "unknown type";
119: }
120: return typeStr;
121: }
122: }
|