01: /*
02: * Copyright 2000,2005 wingS development team.
03: *
04: * This file is part of wingS (http://wingsframework.org).
05: *
06: * wingS is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * Please see COPYING for the complete licence.
12: */
13: package org.wings.event;
14:
15: import org.wings.SComponent;
16: import org.wings.SContainer;
17:
18: /**
19: * A container event, that is issued, whenever a
20: * component is added or removed from an container.
21: *
22: * @author <a href="mailto:H.Zeller@acm.org">Henner Zeller</a>
23: * @see org.wings.SContainer#addContainerListener(SContainerListener)
24: */
25: public class SContainerEvent extends SComponentEvent {
26: /**
27: * The first number of used IDs for container events.
28: */
29: public static final int CONTAINER_FIRST = 11000;
30:
31: /**
32: * An event with this ID indicates, that a component was added to
33: * the container.
34: */
35: public static final int COMPONENT_ADDED = CONTAINER_FIRST;
36:
37: /**
38: * An event with this ID indicates, that a component was removed from
39: * the container.
40: */
41: public static final int COMPONENT_REMOVED = CONTAINER_FIRST + 1;
42:
43: /**
44: * The last number of used IDs for container events.
45: */
46: public static final int CONTAINER_LAST = COMPONENT_REMOVED;
47:
48: /**
49: * the child component that has been added or removed.
50: */
51: private final SComponent child;
52:
53: /**
54: * create a new container event issued by 'source' and affecting
55: * 'child'.
56: *
57: * @param source the Container issuing this event
58: * @param id the integer ID describing the action; one of
59: * <code>COMPONENT_ADDED</code>
60: * or <code>COMPONENT_REMOVED</code>.
61: * @param child the component that is affected by this event, i.e. that
62: * is added or removed.
63: */
64: public SContainerEvent(SContainer source, int id, SComponent child) {
65: super (source, id);
66: this .child = child;
67: }
68:
69: /**
70: * returns the source container, this event origins from.
71: */
72: public SContainer getContainer() {
73: return (SContainer) source;
74: }
75:
76: /**
77: * returns the child component, whose new status in the container
78: * is reported by this event.
79: */
80: public SComponent getChild() {
81: return child;
82: }
83:
84: public String paramString() {
85: switch (id) {
86: case COMPONENT_ADDED:
87: return "COMPONENT_ADDED";
88: case COMPONENT_REMOVED:
89: return "COMPONENT_REMOVED";
90: default:
91: return super .paramString();
92: }
93: }
94:
95: public String toString() {
96: return "ContainerEvent[container=" + source + "; "
97: + paramString() + "child=" + child + "]";
98: }
99: }
|