Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/awt/CausedFocusEvent.java
38827 views
/*1* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.awt;2627import java.awt.event.FocusEvent;28import java.awt.Component;2930/**31* This class represents FocusEvents with a known "cause" - reason why this event happened. It can32* be mouse press, traversal, activation, and so on - all causes are described as Cause enum. The33* event with the cause can be constructed in two ways - explicitly through constructor of34* CausedFocusEvent class or implicitly, by calling appropriate requestFocusXXX method with "cause"35* parameter. The default cause is UNKNOWN.36*/37@SuppressWarnings("serial")38public class CausedFocusEvent extends FocusEvent {39public enum Cause {40UNKNOWN,41MOUSE_EVENT,42TRAVERSAL,43TRAVERSAL_UP,44TRAVERSAL_DOWN,45TRAVERSAL_FORWARD,46TRAVERSAL_BACKWARD,47MANUAL_REQUEST,48AUTOMATIC_TRAVERSE,49ROLLBACK,50NATIVE_SYSTEM,51ACTIVATION,52CLEAR_GLOBAL_FOCUS_OWNER,53RETARGETED54};5556private final Cause cause;5758public Cause getCause() {59return cause;60}6162public String toString() {63return "java.awt.FocusEvent[" + super.paramString() + ",cause=" + cause + "] on " + getSource();64}6566public CausedFocusEvent(Component source, int id, boolean temporary,67Component opposite, Cause cause) {68super(source, id, temporary, opposite);69if (cause == null) {70cause = Cause.UNKNOWN;71}72this.cause = cause;73}7475/**76* Retargets the original focus event to the new target. If the77* original focus event is CausedFocusEvent, it remains such and78* cause is copied. Otherwise, new CausedFocusEvent is created,79* with cause as RETARGETED.80* @return retargeted event, or null if e is null81*/82public static FocusEvent retarget(FocusEvent e, Component newSource) {83if (e == null) return null;8485return new CausedFocusEvent(newSource, e.getID(), e.isTemporary(), e.getOppositeComponent(),86(e instanceof CausedFocusEvent) ? ((CausedFocusEvent)e).getCause() : Cause.RETARGETED);87}88}899091