KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > event > SComponentEvent


1 /*
2  * $Id: SComponentEvent.java,v 1.7 2005/02/08 13:24:48 hengels Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.event;
15
16 import org.wings.SComponent;
17 import org.wings.SDimension;
18
19 /**
20  * A low-level event which indicates that a component moved, changed
21  * size, or changed visibility (also, the root class for the other
22  * component-level events).
23  * <p/>
24  * Component events are provided for notification purposes ONLY;
25  * WingS will automatically handle component moves and resizes
26  * internally so that GUI layout works properly regardless of
27  * whether a program is receiving these events or not.
28  * <p/>
29  * In addition to serving as the base class for other component-related
30  * events (InputEvent, FocusEvent, WindowEvent, ContainerEvent),
31  * this class defines the events that indicate changes in
32  * a component's size, position, or visibility.
33  * <p/>
34  * This low-level event is generated by a component object (such as a
35  * SList) when the component is moved, resized, rendered invisible, or made
36  * visible again. The event is passed to every ComponentListener or
37  * ComponentAdapter object which registered to receive such
38  * events using the component's addComponentListener method.
39  * (ComponentAdapter objects implement the
40  * ComponentListener interface.) Each such listener object
41  * gets this ComponentEvent when the event occurs.
42  *
43  * @author <a HREF="mailto:andre@lison.de">Andre Lison</a>
44  * @version $Revision: 1.7 $, $Date: 2005/02/08 13:24:48 $
45  * @see org.wings.event.SComponentAdapter
46  * @see org.wings.event.SComponentListener
47  */

48 public class SComponentEvent
49         extends java.awt.AWTEvent JavaDoc {
50     /**
51      * The first number in the range of ids used for component events.
52      */

53     public static final int COMPONENT_FIRST = 10000;
54
55     /**
56      * This event indicates that the component was rendered invisible.
57      */

58     public static final int COMPONENT_HIDDEN = COMPONENT_FIRST;
59
60     /**
61      * This event indicates that the component's position changed.
62      */

63     public static final int COMPONENT_MOVED = COMPONENT_FIRST + 1;
64
65     /**
66      * This event indicates that the component's size changed.
67      */

68     public static final int COMPONENT_RESIZED = COMPONENT_FIRST + 2;
69
70     /**
71      * This event indicates that the component was made visible.
72      */

73     public static final int COMPONENT_SHOWN = COMPONENT_FIRST + 3;
74
75     /**
76      * The last number in the range of ids used for component events.
77      */

78     public static final int COMPONENT_LAST = COMPONENT_SHOWN; // take last.
79

80     /**
81      * Constructs a ComponentEvent object.
82      *
83      * @param aSource the Component object that originated the event
84      * @param anId an integer indicating the type of event
85      */

86     public SComponentEvent(SComponent aSource, int anId) {
87         super(aSource, anId);
88     }
89
90     /**
91      * Returns the originator of the event.
92      *
93      * @return the Component object that originated the event
94      */

95     public SComponent getComponent() {
96         return (SComponent) source;
97     }
98
99     /**
100      * Returns a string representing the state of this event. This
101      * method is intended to be used only for debugging purposes, and the
102      * content and format of the returned string may vary between
103      * implementations. The returned string may be empty but may
104      * not be <tt>null</tt>.
105      */

106     public String JavaDoc paramString() {
107         if (source == null)
108             return "no source";
109
110         String JavaDoc typeStr;
111         SDimension d = ((SComponent) source).getPreferredSize();
112
113         switch (id) {
114             case COMPONENT_SHOWN:
115                 typeStr = "COMPONENT_SHOWN";
116                 break;
117             case COMPONENT_HIDDEN:
118                 typeStr = "COMPONENT_HIDDEN";
119                 break;
120             case COMPONENT_MOVED:
121                 typeStr = "COMPONENT_MOVED (" + d.getIntWidth() + "x" + d.getIntHeight()+ ")";
122                 break;
123             case COMPONENT_RESIZED:
124                 typeStr = "COMPONENT_RESIZED (" + d.getIntWidth() + "x" + d.getIntHeight() + ")";
125                 break;
126             default:
127                 typeStr = "unknown type";
128         }
129         return typeStr;
130     }
131
132     public String JavaDoc toString() {
133         return "ComponentEvent[source=" + source + "; " + paramString() + "]";
134     }
135 }
136
Popular Tags