001 /* ComponentEvent.java -- notification of events for components 002 Copyright (C) 1999, 2002, 2005, 2006 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 039 package java.awt.event; 040 041 import java.awt.AWTEvent; 042 import java.awt.Component; 043 044 /** 045 * This class is for events generated when a component is moved, resized, 046 * hidden, or shown. These events normally do not need to be handled by the 047 * application, since the AWT system automatically takes care of them. This 048 * is also the superclass for other events on components, but 049 * ComponentListeners ignore such subclasses. 050 * 051 * @author Aaron M. Renn (arenn@urbanophile.com) 052 * @see ComponentAdapter 053 * @see ComponentListener 054 * @since 1.1 055 * @status updated to 1.4 056 */ 057 public class ComponentEvent extends AWTEvent 058 { 059 /** 060 * Compatible with JDK 1.1+. 061 */ 062 private static final long serialVersionUID = 8101406823902992965L; 063 064 /** This is the first id in the range of ids used by this class. */ 065 public static final int COMPONENT_FIRST = 100; 066 067 /** This is the last id in the range of ids used by this class. */ 068 public static final int COMPONENT_LAST = 103; 069 070 /** This id indicates that a component was moved. */ 071 public static final int COMPONENT_MOVED = 100; 072 073 /** This id indicates that a component was resized. */ 074 public static final int COMPONENT_RESIZED = 101; 075 076 /** This id indicates that a component was shown. */ 077 public static final int COMPONENT_SHOWN = 102; 078 079 /** This id indicates that a component was hidden. */ 080 public static final int COMPONENT_HIDDEN = 103; 081 082 /** 083 * Initializes a new instance of <code>ComponentEvent</code> with the 084 * specified source and id. Note that an invalid id leads to unspecified 085 * results. 086 * 087 * @param source the source of the event 088 * @param id the event id 089 * @throws IllegalArgumentException if source is null 090 */ 091 public ComponentEvent(Component source, int id) 092 { 093 super(source, id); 094 } 095 096 /** 097 * This method returns the event source as a <code>Component</code>. If the 098 * source has subsequently been modified to a non-Component, this returns 099 * null. 100 * 101 * @return the event source as a <code>Component</code>, or null 102 */ 103 public Component getComponent() 104 { 105 return source instanceof Component ? (Component) source : null; 106 } 107 108 /** 109 * This method returns a string identifying this event. This is the field 110 * name of the id type, and for COMPONENT_MOVED or COMPONENT_RESIZED, the 111 * new bounding box of the component. 112 * 113 * @return a string identifying this event 114 */ 115 public String paramString() 116 { 117 StringBuffer s = new StringBuffer(); 118 119 // Unlike Sun, we don't throw NullPointerException or ClassCastException 120 // when source was illegally changed. 121 if (id == COMPONENT_MOVED) 122 s.append("COMPONENT_MOVED "); 123 else if (id == COMPONENT_RESIZED) 124 s.append("COMPONENT_RESIZED "); 125 else if (id == COMPONENT_SHOWN) 126 s.append("COMPONENT_SHOWN "); 127 else if (id == COMPONENT_HIDDEN) 128 s.append("COMPONENT_HIDDEN "); 129 else 130 return "unknown type"; 131 132 s.append("(").append(getComponent().getX()).append(",") 133 .append(getComponent().getY()).append(" ") 134 .append(getComponent().getWidth()).append("x") 135 .append(getComponent().getHeight()).append(")"); 136 137 return s.toString(); 138 } 139 140 } // class ComponentEvent