1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package javafx.scene.control; 26 27 import javafx.beans.NamedArg; 28 import javafx.event.Event; 29 import javafx.event.EventTarget; 30 import javafx.event.EventType; 31 32 /** 33 * Event related to dialog showing/hiding actions. In particular, this event is 34 * used exclusively by the following methods: 35 * 36 * <ul> 37 * <li>{@link Dialog#onShowingProperty()} 38 * <li>{@link Dialog#onShownProperty()} 39 * <li>{@link Dialog#onHidingProperty()} 40 * <li>{@link Dialog#onCloseRequestProperty()} 41 * <li>{@link Dialog#onHiddenProperty()()} 42 * </ul> 43 * 44 * @see Dialog 45 * @since JavaFX 8u40 46 */ 47 public class DialogEvent extends Event { 48 49 private static final long serialVersionUID = 20140716L; 50 51 /** 52 * Common supertype for all dialog event types. 53 */ 54 public static final EventType<DialogEvent> ANY = 55 new EventType<DialogEvent>(Event.ANY, "DIALOG"); 56 57 /** 58 * This event occurs on dialog just before it is shown. 59 */ 60 public static final EventType<DialogEvent> DIALOG_SHOWING = 61 new EventType<DialogEvent>(DialogEvent.ANY, "DIALOG_SHOWING"); 62 63 /** 64 * This event occurs on dialog just after it is shown. 65 */ 66 public static final EventType<DialogEvent> DIALOG_SHOWN = 67 new EventType<DialogEvent>(DialogEvent.ANY, "DIALOG_SHOWN"); 68 69 /** 70 * This event occurs on dialog just before it is hidden. 71 */ 72 public static final EventType<DialogEvent> DIALOG_HIDING = 73 new EventType<DialogEvent>(DialogEvent.ANY, "DIALOG_HIDING"); 74 75 /** 76 * This event occurs on dialog just after it is hidden. 77 */ 78 public static final EventType<DialogEvent> DIALOG_HIDDEN = 79 new EventType<DialogEvent>(DialogEvent.ANY, "DIALOG_HIDDEN"); 80 81 /** 82 * This event is delivered to a 83 * dialog when there is an external request to close that dialog. If the 84 * event is not consumed by any installed dialog event handler, the default 85 * handler for this event closes the corresponding dialog. 86 */ 87 public static final EventType<DialogEvent> DIALOG_CLOSE_REQUEST = 88 new EventType<DialogEvent>(DialogEvent.ANY, "DIALOG_CLOSE_REQUEST"); 89 90 /** 91 * Construct a new {@code Event} with the specified event source, target 92 * and type. If the source or target is set to {@code null}, it is replaced 93 * by the {@code NULL_SOURCE_TARGET} value. 94 * 95 * @param source the event source which sent the event 96 * @param eventType the event type 97 */ 98 public DialogEvent(final @NamedArg("source") Dialog<?> source, final @NamedArg("eventType") EventType<? extends Event> eventType) { 99 super(source, source, eventType); 100 } 101 102 /** 103 * Returns a string representation of this {@code DialogEvent} object. 104 * @return a string representation of this {@code DialogEvent} object. 105 */ 106 @Override public String toString() { 107 final StringBuilder sb = new StringBuilder("DialogEvent ["); 108 109 sb.append("source = ").append(getSource()); 110 sb.append(", target = ").append(getTarget()); 111 sb.append(", eventType = ").append(getEventType()); 112 sb.append(", consumed = ").append(isConsumed()); 113 114 return sb.append("]").toString(); 115 } 116 117 @Override public DialogEvent copyFor(Object newSource, EventTarget newTarget) { 118 return (DialogEvent) super.copyFor(newSource, newTarget); 119 } 120 121 /** 122 * Creates a copy of the given event with the given fields substituted. 123 * @param newSource the new source of the copied event 124 * @param newTarget the new target of the copied event 125 * @param type the new eventType 126 * @return the event copy with the fields substituted 127 * @since JavaFX 8.0 128 */ 129 public DialogEvent copyFor(Object newSource, EventTarget newTarget, EventType<DialogEvent> type) { 130 DialogEvent e = copyFor(newSource, newTarget); 131 e.eventType = type; 132 return e; 133 } 134 135 @SuppressWarnings("unchecked") 136 @Override public EventType<DialogEvent> getEventType() { 137 return (EventType<DialogEvent>) super.getEventType(); 138 } 139 }