1 /* 2 * Copyright (c) 2013, 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 26 package javafx.scene.control; 27 28 import javafx.beans.NamedArg; 29 import javafx.event.Event; 30 import javafx.event.EventTarget; 31 import javafx.event.EventType; 32 33 /** 34 * Event related to {@link ScrollPane} and virtualised controls such as 35 * {@link ListView}, {@link TableView}, {@link TreeView} and {@link TreeTableView}. 36 * @since JavaFX 8.0 37 */ 38 public class ScrollToEvent<T> extends Event { 39 // /** 40 // * This event occurs if the user requests scrolling a node into view. 41 // */ 42 // @SuppressWarnings("unchecked") 43 // public static EventType<ScrollToEvent<Node>> scrollToNode() { 44 // return SCROLL_TO_NODE; 45 // } 46 // private static final EventType<ScrollToEvent<Node>> SCROLL_TO_NODE = 47 // new EventType<ScrollToEvent<Node>>(ScrollToEvent.ANY, "SCROLL_TO_NODE"); 48 49 /** 50 * Common supertype for all scroll-to event types. 51 */ 52 public static final EventType<ScrollToEvent> ANY = 53 new EventType<ScrollToEvent> (Event.ANY, "SCROLL_TO"); 54 55 /** 56 * This event occurs if the user requests scrolling a given index into view. 57 */ 58 public static EventType<ScrollToEvent<Integer>> scrollToTopIndex() { 59 return SCROLL_TO_TOP_INDEX; 60 } 61 private static final EventType<ScrollToEvent<Integer>> SCROLL_TO_TOP_INDEX = 62 new EventType<ScrollToEvent<Integer>>(ScrollToEvent.ANY, "SCROLL_TO_TOP_INDEX"); 63 64 65 /** 66 * This event occurs if the user requests scrolling a {@link TableColumnBase} 67 * (i.e. {@link TableColumn} or {@link TreeTableColumn}) into view. 68 */ 69 @SuppressWarnings("unchecked") 70 public static <T extends TableColumnBase<?, ?>> EventType<ScrollToEvent<T>> scrollToColumn() { 71 return (EventType<ScrollToEvent<T>>) SCROLL_TO_COLUMN; 72 } 73 private static final EventType<?> SCROLL_TO_COLUMN = 74 new EventType<>(ScrollToEvent.ANY, "SCROLL_TO_COLUMN"); 75 76 private static final long serialVersionUID = -8557345736849482516L; 77 78 private final T scrollTarget; 79 80 /** 81 * Construct a new {@code Event} with the specified event source, target 82 * and type. If the source or target is set to {@code null}, it is replaced 83 * by the {@code NULL_SOURCE_TARGET} value. 84 * 85 * @param source the event source which sent the event 86 * @param target the event source which sent the event 87 * @param type the event type 88 * @param target the target of the scroll to operation 89 */ 90 public ScrollToEvent(@NamedArg("source") Object source, @NamedArg("target") EventTarget target, @NamedArg("type") EventType<ScrollToEvent<T>> type, @NamedArg("scrollTarget") T scrollTarget) { 91 super(source, target, type); 92 assert scrollTarget != null; 93 this.scrollTarget = scrollTarget; 94 95 } 96 97 public T getScrollTarget() { 98 return scrollTarget; 99 } 100 }