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 * @return the scroll to event type 58 */ 59 public static EventType<ScrollToEvent<Integer>> scrollToTopIndex() { 60 return SCROLL_TO_TOP_INDEX; 61 } 62 private static final EventType<ScrollToEvent<Integer>> SCROLL_TO_TOP_INDEX = 63 new EventType<ScrollToEvent<Integer>>(ScrollToEvent.ANY, "SCROLL_TO_TOP_INDEX"); 64 65 66 /** 67 * This event occurs if the user requests scrolling a {@link TableColumnBase} 68 * (i.e. {@link TableColumn} or {@link TreeTableColumn}) into view. 69 * @param <T> the type 70 * @return the scroll to event type 71 */ 72 @SuppressWarnings("unchecked") 73 public static <T extends TableColumnBase<?, ?>> EventType<ScrollToEvent<T>> scrollToColumn() { 74 return (EventType<ScrollToEvent<T>>) SCROLL_TO_COLUMN; 75 } 76 private static final EventType<?> SCROLL_TO_COLUMN = 77 new EventType<>(ScrollToEvent.ANY, "SCROLL_TO_COLUMN"); 78 79 private static final long serialVersionUID = -8557345736849482516L; 80 81 private final T scrollTarget; 82 83 /** 84 * Construct a new {@code Event} with the specified event source, target 85 * and type. If the source or target is set to {@code null}, it is replaced 86 * by the {@code NULL_SOURCE_TARGET} value. 87 * 88 * @param source the event source which sent the event 89 * @param target the event source which sent the event 90 * @param type the event type 91 * @param scrollTarget the target of the scroll to operation 92 */ 93 public ScrollToEvent(@NamedArg("source") Object source, @NamedArg("target") EventTarget target, @NamedArg("type") EventType<ScrollToEvent<T>> type, @NamedArg("scrollTarget") T scrollTarget) { 94 super(source, target, type); 95 assert scrollTarget != null; 96 this.scrollTarget = scrollTarget; 97 98 } 99 100 public T getScrollTarget() { 101 return scrollTarget; 102 } 103 }