1 7 8 package java.awt.event; 9 10 import java.awt.Component ; 11 import java.awt.Event ; 12 13 import sun.awt.AppContext; 14 import sun.awt.SunToolkit; 15 16 48 public class FocusEvent extends ComponentEvent { 49 50 53 public static final int FOCUS_FIRST = 1004; 54 55 58 public static final int FOCUS_LAST = 1005; 59 60 63 public static final int FOCUS_GAINED = FOCUS_FIRST; 65 68 public static final int FOCUS_LOST = 1 + FOCUS_FIRST; 70 79 boolean temporary; 80 81 91 transient Component opposite; 92 93 96 private static final long serialVersionUID = 523753786457416396L; 97 98 123 public FocusEvent(Component source, int id, boolean temporary, 124 Component opposite) { 125 super(source, id); 126 this.temporary = temporary; 127 this.opposite = opposite; 128 } 129 130 144 public FocusEvent(Component source, int id, boolean temporary) { 145 this(source, id, temporary, null); 146 } 147 148 160 public FocusEvent(Component source, int id) { 161 this(source, id, false); 162 } 163 164 170 public boolean isTemporary() { 171 return temporary; 172 } 173 174 185 public Component getOppositeComponent() { 186 if (opposite == null) { 187 return null; 188 } 189 190 return (SunToolkit.targetToAppContext(opposite) == 191 AppContext.getAppContext()) 192 ? opposite 193 : null; 194 } 195 196 202 public String paramString() { 203 String typeStr; 204 switch(id) { 205 case FOCUS_GAINED: 206 typeStr = "FOCUS_GAINED"; 207 break; 208 case FOCUS_LOST: 209 typeStr = "FOCUS_LOST"; 210 break; 211 default: 212 typeStr = "unknown type"; 213 } 214 return typeStr + (temporary ? ",temporary" : ",permanent") + 215 ",opposite=" + getOppositeComponent(); 216 } 217 218 } 219 | Popular Tags |