jdk/src/share/classes/java/awt/event/ContainerEvent.java
author mcherkas
Fri, 04 Oct 2013 20:13:32 +0400
changeset 20455 f6f9a0c2796b
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index. Reviewed-by: anthony, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     2
 * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * A low-level event which indicates that a container's contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * changed because a component was added or removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Container events are provided for notification purposes ONLY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * The AWT will automatically handle changes to the containers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * contents internally so that the program works properly regardless of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * whether the program is receiving these events or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * This low-level event is generated by a container object (such as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Panel) when a component is added to it or removed from it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * The event is passed to every <code>ContainerListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * or <code>ContainerAdapter</code> object which registered to receive such
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * events using the component's <code>addContainerListener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * (<code>ContainerAdapter</code> objects implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <code>ContainerListener</code> interface.) Each such listener object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * gets this <code>ContainerEvent</code> when the event occurs.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    48
 * <p>
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    49
 * An unspecified behavior will be caused if the {@code id} parameter
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    50
 * of any particular {@code ContainerEvent} instance is not
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    51
 * in the range from {@code CONTAINER_FIRST} to {@code CONTAINER_LAST}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see ContainerAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see ContainerListener
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 5506
diff changeset
    55
 * @see <a href="http://docs.oracle.com/javase/tutorial/uiswing/events/containerlistener.html">Tutorial: Writing a Container Listener</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @author Tim Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author Amy Fowler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @since 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
public class ContainerEvent extends ComponentEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * The first number in the range of ids used for container events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public static final int CONTAINER_FIRST             = 300;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * The last number in the range of ids used for container events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public static final int CONTAINER_LAST              = 301;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * This event indicates that a component was added to the container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public static final int COMPONENT_ADDED     = CONTAINER_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * This event indicates that a component was removed from the container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static final int COMPONENT_REMOVED = 1 + CONTAINER_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * The non-null component that is being added or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * removed from the Container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @see #getChild()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    Component child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static final long serialVersionUID = -4114942250539772041L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Constructs a <code>ContainerEvent</code> object.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    99
     * <p> This method throws an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   103
     * @param source The <code>Component</code> object (container)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *               that originated the event
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   105
     * @param id     An integer indicating the type of event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   106
     *                     For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   107
     *                     the class description for {@link ContainerEvent}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param child  the component that was added or removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @throws IllegalArgumentException if <code>source</code> is null
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   110
     * @see #getContainer()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   111
     * @see #getID()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   112
     * @see #getChild()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public ContainerEvent(Component source, int id, Component child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        super(source, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        this.child = child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Returns the originator of the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @return the <code>Container</code> object that originated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * the event, or <code>null</code> if the object is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <code>Container</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public Container getContainer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        return (source instanceof Container) ? (Container)source : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Returns the component that was affected by the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @return the Component object that was added or removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public Component getChild() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Returns a parameter string identifying this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * This method is useful for event-logging and for debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @return a string identifying the event and its attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        String typeStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
          case COMPONENT_ADDED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
              typeStr = "COMPONENT_ADDED";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
          case COMPONENT_REMOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
              typeStr = "COMPONENT_REMOVED";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
              typeStr = "unknown type";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return typeStr + ",child="+child.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
}