Spec-Zone .ru
спецификации, руководства, описания, API
|
001/* 002 * Copyright (c) 2011, 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 */ 025package javafx.scene.web; 026 027import javafx.event.Event; 028import javafx.event.EventType; 029 030/** 031 * {@code WebEvent} instances are passed into {@code EventHandler}s registered 032 * with a {@link WebEngine} by JavaScript running on a Web page. An event holds 033 * a single data item of type {@code T}. 034 * 035 * @see WebEngine 036 * @see WebEngine#setOnAlert 037 * @see WebEngine#setOnResized 038 * @see WebEngine#setOnStatusChanged 039 * @see WebEngine#setOnVisibilityChanged 040 */ 041final public class WebEvent<T> extends Event { 042 043 /** 044 * Common supertype for all Web event types. 045 */ 046 public static final EventType<WebEvent> ANY = 047 new EventType<WebEvent>(Event.ANY, "WEB"); 048 049 /** 050 * This event occurs when a script changes location of the JavaScript 051 * {@code window} object. 052 */ 053 public static final EventType<WebEvent> RESIZED = 054 new EventType<WebEvent>(WebEvent.ANY, "WEB_RESIZED"); 055 056 /** 057 * This event occurs when a script changes status line text. 058 */ 059 public static final EventType<WebEvent> STATUS_CHANGED = 060 new EventType<WebEvent>(WebEvent.ANY, "WEB_STATUS_CHANGED"); 061 062 /** 063 * This event occurs when a script changes visibility of the JavaScript 064 * {@code window} object. 065 */ 066 public static final EventType<WebEvent> VISIBILITY_CHANGED = 067 new EventType<WebEvent>(WebEvent.ANY, "WEB_VISIBILITY_CHANGED"); 068 069 /** 070 * This event occurs when a script calls the JavaScript {@code alert} 071 * function. 072 */ 073 public static final EventType<WebEvent> ALERT = 074 new EventType<WebEvent>(WebEvent.ANY, "WEB_ALERT"); 075 076 private final T data; 077 078 /** 079 * Creates a new event object. 080 */ 081 public WebEvent(Object source, EventType<WebEvent> type, T data) { 082 super(source, null, type); 083 this.data = data; 084 } 085 086 /** 087 * Returns data item carried by this event. 088 */ 089 public T getData() { 090 return data; 091 } 092 093 /** 094 * Returns a string representation of this {@code WebEvent} object. 095 * @return a string representation of this {@code WebEvent} object. 096 */ 097 @Override public String toString() { 098 return String.format( 099 "WebEvent [source = %s, eventType = %s, data = %s]", 100 getSource(), getEventType(), getData()); 101 } 102}