Spec-Zone .ru
спецификации, руководства, описания, API
001/*
002 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.  Oracle designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Oracle in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
022 * or visit www.oracle.com if you need additional information or have any
023 * questions.
024 */
025
026package javafx.stage;
027
028import javafx.event.Event;
029import javafx.event.EventTarget;
030import javafx.event.EventType;
031
032/**
033 * Event related to window showing/hiding actions.
034 */
035public class WindowEvent extends Event {
036
037    private static final long serialVersionUID = 20121107L;
038    
039    /**
040     * Common supertype for all window event types.
041     */
042    public static final EventType<WindowEvent> ANY =
043            new EventType<WindowEvent>(Event.ANY, "WINDOW");
044
045    /**
046     * This event occurs on window just before it is shown.
047     */
048    public static final EventType<WindowEvent> WINDOW_SHOWING =
049            new EventType<WindowEvent>(WindowEvent.ANY, "WINDOW_SHOWING");
050
051    /**
052     * This event occurs on window just after it is shown.
053     */
054    public static final EventType<WindowEvent> WINDOW_SHOWN =
055            new EventType<WindowEvent>(WindowEvent.ANY, "WINDOW_SHOWN");
056
057    /**
058     * This event occurs on window just before it is hidden.
059     */
060    public static final EventType<WindowEvent> WINDOW_HIDING =
061            new EventType<WindowEvent>(WindowEvent.ANY, "WINDOW_HIDING");
062
063    /**
064     * This event occurs on window just after it is hidden.
065     */
066    public static final EventType<WindowEvent> WINDOW_HIDDEN =
067            new EventType<WindowEvent>(WindowEvent.ANY, "WINDOW_HIDDEN");
068
069    /**
070     * This event is delivered to a
071     * window when there is an external request to close that window. If the
072     * event is not consumed by any installed window event handler, the default
073     * handler for this event closes the corresponding window.
074     */
075    public static final EventType<WindowEvent> WINDOW_CLOSE_REQUEST =
076            new EventType<WindowEvent>(WindowEvent.ANY, "WINDOW_CLOSE_REQUEST");
077
078    /**
079     * Construct a new {@code Event} with the specified event source, target
080     * and type. If the source or target is set to {@code null}, it is replaced
081     * by the {@code NULL_SOURCE_TARGET} value.
082     *
083     * @param source    the event source which sent the event
084     * @param eventType the event type
085     */
086    public WindowEvent(final Window source, final EventType<? extends Event> eventType) {
087        super(source, source, eventType);
088    }
089
090    /**
091     * Returns a string representation of this {@code WindowEvent} object.
092     * @return a string representation of this {@code WindowEvent} object.
093     */ 
094    @Override public String toString() {
095        final StringBuilder sb = new StringBuilder("WindowEvent [");
096
097        sb.append("source = ").append(getSource());
098        sb.append(", target = ").append(getTarget());
099        sb.append(", eventType = ").append(getEventType());
100        sb.append(", consumed = ").append(isConsumed());
101
102        return sb.append("]").toString();
103    }
104
105    @Override
106    public WindowEvent copyFor(Object newSource, EventTarget newTarget) {
107        return (WindowEvent) super.copyFor(newSource, newTarget);
108    }
109
110    /**
111     * Creates a copy of the given event with the given fields substituted.
112     * @param source the new source of the copied event
113     * @param target the new target of the copied event
114     * @param eventType the new eventType
115     * @return the event copy with the fields substituted
116     */
117    public WindowEvent copyFor(Object newSource, EventTarget newTarget, EventType<WindowEvent> type) {
118        WindowEvent e = copyFor(newSource, newTarget);
119        e.eventType = type;
120        return e;
121    }
122
123    @Override
124    public EventType<WindowEvent> getEventType() {
125        return (EventType<WindowEvent>) super.getEventType();
126    }
127    
128    
129}