Source for java.awt.event.HierarchyEvent

   1: /* HierarchyEvent.java -- generated for a change in hierarchy
   2:    Copyright (C) 2000, 2002 Free Software Foundation
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package java.awt.event;
  40: 
  41: import java.awt.AWTEvent;
  42: import java.awt.Component;
  43: import java.awt.Container;
  44: 
  45: /**
  46:  * This class represents an event generated for an ancestor component which
  47:  * may affect this component. These events normally do not need to be handled
  48:  * by the application, since the AWT system automatically takes care of them.
  49:  *
  50:  * <p>There are two types of hierarchy events. The first type is handled by
  51:  * HierarchyListener, and includes addition or removal of an ancestor, or
  52:  * an ancestor changing its on-screen status (visible and/or displayble). The
  53:  * second type is handled by HierarchyBoundsListener, and includes resizing
  54:  * or moving of an ancestor.
  55:  *
  56:  * @author Bryce McKinlay
  57:  * @see HierarchyListener
  58:  * @see HierarchyBoundsAdapter
  59:  * @see HierarchyBoundsListener
  60:  * @since 1.3
  61:  * @status updated to 1.4
  62:  */
  63: public class HierarchyEvent extends AWTEvent
  64: {
  65:   /**
  66:    * Compatible with JDK 1.3+.
  67:    */
  68:   private static final long serialVersionUID = -5337576970038043990L;
  69: 
  70:   /** This is the first id in the range of ids used by this class. */
  71:   public static final int HIERARCHY_FIRST = 1400;
  72: 
  73:   /** This id indicates that the hierarchy tree changed. */
  74:   public static final int HIERARCHY_CHANGED = 1400;
  75: 
  76:   /** This id indicates that an ancestor was moved. */
  77:   public static final int ANCESTOR_MOVED = 1401;
  78: 
  79:   /** This id indicates that an ancestor was resized. */
  80:   public static final int ANCESTOR_RESIZED = 1402;
  81: 
  82:   /** This is the last id in the range of ids used by this class. */
  83:   public static final int HIERARCHY_LAST = 1402;
  84: 
  85:   /** This indicates that the HIERARCHY_CHANGED is a changed parent. */
  86:   public static final int PARENT_CHANGED = 1;
  87: 
  88:   /**
  89:    * This indicates that the HIERARCHY_CHANGED is caused by a change in
  90:    * displayability.
  91:    *
  92:    * @see Component#isDisplayable()
  93:    * @see Component#addNotify()
  94:    * @see Component#removeNotify()
  95:    */
  96:   public static final int DISPLAYABILITY_CHANGED = 2;
  97: 
  98:   /**
  99:    * This indicates that the HIERARCHY_CHANGED is a changed visibility.
 100:    *
 101:    * @see Component#isShowing()
 102:    * @see Component#addNotify()
 103:    * @see Component#removeNotify()
 104:    * @see Component#show()
 105:    * @see Component#hide()
 106:    */
 107:   public static final int SHOWING_CHANGED = 4;
 108: 
 109:   /**
 110:    * The component at the top of the changed hierarchy.
 111:    *
 112:    * @serial the top component changed
 113:    */
 114:   private final Component changed;
 115: 
 116:   /**
 117:    * The parent of this component, either before or after the change depending
 118:    * on the type of change.
 119:    *
 120:    * @serial the parent component changed
 121:    */
 122:   private final Container changedParent;
 123: 
 124:   /**
 125:    * The bitmask of HIERARCHY_CHANGED event types.
 126:    *
 127:    * @serial the change flags
 128:    */
 129:   private final long changeFlags;
 130: 
 131:   /**
 132:    * Initializes a new instance of <code>HierarchyEvent</code> with the
 133:    * specified parameters. Note that an invalid id leads to unspecified
 134:    * results.
 135:    *
 136:    * @param source the component whose hierarchy changed
 137:    * @param id the event id
 138:    * @param changed the top component in the tree of changed hierarchy
 139:    * @param changedParent the updated parent of this object
 140:    * @throws IllegalArgumentException if source is null
 141:    */
 142:   public HierarchyEvent(Component source, int id, Component changed,
 143:                         Container changedParent)
 144:   {
 145:     this(source, id, changed, changedParent, 0);
 146:   }
 147: 
 148:   /**
 149:    * Initializes a new instance of <code>HierarchyEvent</code> with the
 150:    * specified parameters. Note that an invalid id leads to unspecified
 151:    * results.
 152:    *
 153:    * @param source the component whose hierarchy changed
 154:    * @param id the event id
 155:    * @param changed the top component in the tree of changed hierarchy
 156:    * @param changedParent the updated parent of this object
 157:    * @param changeFlags the bitmask of specific HIERARCHY_CHANGED events
 158:    * @throws IllegalArgumentException if source is null
 159:    */
 160:   public HierarchyEvent(Component source, int id, Component changed,
 161:                         Container changedParent, long changeFlags)
 162:   {
 163:     super(source, id);
 164:     this.changed = changed;
 165:     this.changedParent = changedParent;
 166:     this.changeFlags = changeFlags;
 167:   }
 168: 
 169:   /**
 170:    * This method returns the event source as a <code>Component</code>. If the
 171:    * source has subsequently been modified to a non-Component, this returns
 172:    * null.
 173:    *
 174:    * @return the event source as a <code>Component</code>, or null
 175:    */
 176:   public Component getComponent()
 177:   {
 178:     return source instanceof Component ? (Component) source : null;
 179:   }
 180: 
 181:   /**
 182:    * Returns the component at the top of the hierarchy which changed.
 183:    *
 184:    * @return the top changed component
 185:    */
 186:   public Component getChanged()
 187:   {
 188:     return changed;
 189:   }
 190: 
 191:   /**
 192:    * Returns the parent of the component listed in <code>getChanged()</code>.
 193:    * If the cause of this event was <code>Container.add</code>, this is the
 194:    * new parent; if the cause was <code>Container.remove</code>, this is the
 195:    * old parent; otherwise it is the unchanged parent.
 196:    *
 197:    * @return the parent container of the changed component
 198:    */
 199:   public Container getChangedParent()
 200:   {
 201:     return changedParent;
 202:   }
 203: 
 204:   /**
 205:    * If this is a HIERARCHY_CHANGED event, this returns a bitmask of the
 206:    * types of changes that took place.
 207:    *
 208:    * @return the bitwise or of hierarchy change types, or 0
 209:    * @see #PARENT_CHANGED
 210:    * @see #DISPLAYABILITY_CHANGED
 211:    * @see #SHOWING_CHANGED
 212:    */
 213:   public long getChangeFlags()
 214:   {
 215:     return changeFlags;
 216:   }
 217: 
 218:   /**
 219:    * This method returns a string identifying this event. This is the field
 220:    * name of the id type, followed by a parenthesized listing of the changed
 221:    * component and its parent container. In addition, if the type is
 222:    * HIERARCHY_CHANGED, the flags preceed the changed component, in the
 223:    * order PARENT_CHANGED, DISPLAYABILITY_CHANGED, and SHOWING_CHANGED.
 224:    *
 225:    * @return a string identifying this event
 226:    */
 227:   public String paramString()
 228:   {
 229:     StringBuffer r = new StringBuffer();
 230:     switch (id)
 231:       {
 232:       case HIERARCHY_CHANGED:
 233:         r.append("HIERARCHY_CHANGED (");
 234:         if ((changeFlags & PARENT_CHANGED) != 0)
 235:           r.append("PARENT_CHANGED,");
 236:         if ((changeFlags & DISPLAYABILITY_CHANGED) != 0)
 237:           r.append("DISPLAYABILITY_CHANGED,");
 238:         if ((changeFlags & SHOWING_CHANGED) != 0)
 239:           r.append("SHOWING_CHANGED,");
 240:         break;
 241:       case ANCESTOR_MOVED:
 242:         r.append("ANCESTOR_MOVED (");
 243:         break;
 244:       case ANCESTOR_RESIZED:
 245:         r.append("ANCESTOR_RESIZED (");
 246:         break;
 247:       default:
 248:         return "unknown type";
 249:       }
 250:     r.append(changed).append(',').append(changedParent).append(')');
 251:     return r.toString();
 252:   }
 253: } // class HierarchyEvent