001/* 002 * Copyright (c) 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.scene.control; 027 028import javafx.event.Event; 029import javafx.event.EventTarget; 030import javafx.event.EventType; 031import javafx.scene.Node; 032 033/** 034 * Event related to {@link ScrollPane} and virtualised controls such as 035 * {@link ListView}, {@link TableView}, {@link TreeView} and {@link TreeTableView}. 036 */ 037public class ScrollToEvent<T> extends Event { 038// /** 039// * This event occurs if the user requests scrolling a node into view. 040// */ 041// @SuppressWarnings("unchecked") 042// public static EventType<ScrollToEvent<Node>> scrollToNode() { 043// return SCROLL_TO_NODE; 044// } 045// private static final EventType<ScrollToEvent<Node>> SCROLL_TO_NODE = 046// new EventType<ScrollToEvent<Node>>(ScrollToEvent.ANY, "SCROLL_TO_NODE"); 047 048 /** 049 * Common supertype for all scroll-to event types. 050 */ 051 public static final EventType<ScrollToEvent> ANY = 052 new EventType<ScrollToEvent> (Event.ANY, "SCROLL_TO"); 053 054 /** 055 * This event occurs if the user requests scrolling a given index into view. 056 */ 057 @SuppressWarnings("unchecked") 058 public static EventType<ScrollToEvent<Integer>> scrollToTopIndex() { 059 return SCROLL_TO_TOP_INDEX; 060 } 061 private static final EventType<ScrollToEvent<Integer>> SCROLL_TO_TOP_INDEX = 062 new EventType<ScrollToEvent<Integer>>(ScrollToEvent.ANY, "SCROLL_TO_TOP_INDEX"); 063 064 065 /** 066 * This event occurs if the user requests scrolling a {@link TableColumnBase} 067 * (i.e. {@link TableColumn} or {@link TreeTableColumn}) into view. 068 */ 069 @SuppressWarnings("unchecked") 070 public static <T extends TableColumnBase<?, ?>> EventType<ScrollToEvent<T>> scrollToColumn() { 071 return (EventType<ScrollToEvent<T>>) SCROLL_TO_COLUMN; 072 } 073 private static final EventType<?> SCROLL_TO_COLUMN = 074 new EventType(ScrollToEvent.ANY, "SCROLL_TO_COLUMN"); 075 076 private static final long serialVersionUID = -8557345736849482516L; 077 078 private final T scrollTarget; 079 080 /** 081 * Construct a new {@code Event} with the specified event source, target 082 * and type. If the source or target is set to {@code null}, it is replaced 083 * by the {@code NULL_SOURCE_TARGET} value. 084 * 085 * @param source the event source which sent the event 086 * @param target the event source which sent the event 087 * @param type the event type 088 * @param target the target of the scroll to operation 089 */ 090 public ScrollToEvent(Object source, EventTarget target, EventType<ScrollToEvent<T>> type, T scrollTarget) { 091 super(source, target, type); 092 assert scrollTarget != null; 093 this.scrollTarget = scrollTarget; 094 095 } 096 097 public T getScrollTarget() { 098 return scrollTarget; 099 } 100}