001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings.event;
014:
015: import org.wings.SComponent;
016: import org.wings.SDimension;
017:
018: /**
019: * A low-level event which indicates that a component moved, changed
020: * size, or changed visibility (also, the root class for the other
021: * component-level events).
022: * <p/>
023: * Component events are provided for notification purposes ONLY;
024: * WingS will automatically handle component moves and resizes
025: * internally so that GUI layout works properly regardless of
026: * whether a program is receiving these events or not.
027: * <p/>
028: * In addition to serving as the base class for other component-related
029: * events (InputEvent, FocusEvent, WindowEvent, ContainerEvent),
030: * this class defines the events that indicate changes in
031: * a component's size, position, or visibility.
032: * <p/>
033: * This low-level event is generated by a component object (such as a
034: * SList) when the component is moved, resized, rendered invisible, or made
035: * visible again. The event is passed to every ComponentListener or
036: * ComponentAdapter object which registered to receive such
037: * events using the component's addComponentListener method.
038: * (ComponentAdapter objects implement the
039: * ComponentListener interface.) Each such listener object
040: * gets this ComponentEvent when the event occurs.
041: *
042: * @author <a href="mailto:andre@lison.de">Andre Lison</a>
043: * @see org.wings.event.SComponentAdapter
044: * @see org.wings.event.SComponentListener
045: */
046: public class SComponentEvent extends java.awt.AWTEvent {
047: /**
048: * The first number in the range of ids used for component events.
049: */
050: public static final int COMPONENT_FIRST = 10000;
051:
052: /**
053: * This event indicates that the component was rendered invisible.
054: */
055: public static final int COMPONENT_HIDDEN = COMPONENT_FIRST;
056:
057: /**
058: * This event indicates that the component's position changed.
059: */
060: public static final int COMPONENT_MOVED = COMPONENT_FIRST + 1;
061:
062: /**
063: * This event indicates that the component's size changed.
064: */
065: public static final int COMPONENT_RESIZED = COMPONENT_FIRST + 2;
066:
067: /**
068: * This event indicates that the component was made visible.
069: */
070: public static final int COMPONENT_SHOWN = COMPONENT_FIRST + 3;
071:
072: /**
073: * The last number in the range of ids used for component events.
074: */
075: public static final int COMPONENT_LAST = COMPONENT_SHOWN; // take last.
076:
077: /**
078: * Constructs a ComponentEvent object.
079: *
080: * @param aSource the Component object that originated the event
081: * @param anId an integer indicating the type of event
082: */
083: public SComponentEvent(SComponent aSource, int anId) {
084: super (aSource, anId);
085: }
086:
087: /**
088: * Returns the originator of the event.
089: *
090: * @return the Component object that originated the event
091: */
092: public SComponent getComponent() {
093: return (SComponent) source;
094: }
095:
096: /**
097: * Returns a string representing the state of this event. This
098: * method is intended to be used only for debugging purposes, and the
099: * content and format of the returned string may vary between
100: * implementations. The returned string may be empty but may
101: * not be <tt>null</tt>.
102: */
103: public String paramString() {
104: if (source == null)
105: return "no source";
106:
107: String typeStr;
108: SDimension d = ((SComponent) source).getPreferredSize();
109:
110: switch (id) {
111: case COMPONENT_SHOWN:
112: typeStr = "COMPONENT_SHOWN";
113: break;
114: case COMPONENT_HIDDEN:
115: typeStr = "COMPONENT_HIDDEN";
116: break;
117: case COMPONENT_MOVED:
118: typeStr = "COMPONENT_MOVED (" + d.getWidthInt() + "x"
119: + d.getHeightInt() + ")";
120: break;
121: case COMPONENT_RESIZED:
122: typeStr = "COMPONENT_RESIZED (" + d.getWidthInt() + "x"
123: + d.getHeightInt() + ")";
124: break;
125: default:
126: typeStr = "unknown type";
127: }
128: return typeStr;
129: }
130:
131: public String toString() {
132: return "ComponentEvent[source=" + source + "; " + paramString()
133: + "]";
134: }
135: }
|