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 */ 025 026package javafx.scene.control; 027 028import java.lang.ref.WeakReference; 029 030/** 031 * This class is used to represent a single row/column/cell in a TableView. 032 * This is used throughout the TableView API to represent which rows/columns/cells 033 * are currently selected, focused, being edited, etc. Note that this class is 034 * immutable once it is created. 035 * 036 * <p>Because the TableView can have different 037 * {@link SelectionMode selection modes}, the row and column properties in 038 * TablePosition can be 'disabled' to represent an entire row or column. This is 039 * done by setting the unrequired property to -1 or null. 040 * 041 * @param <S> The type of the items contained within the TableView (i.e. the same 042 * generic type as the S in TableView<S>). 043 * @param <T> The type of the items contained within the TableColumn. 044 * @see TableView 045 * @see TableColumn 046 */ 047public class TablePosition<S,T> extends TablePositionBase<TableColumn<S,T>> { 048 049 /*************************************************************************** 050 * * 051 * Constructors * 052 * * 053 **************************************************************************/ 054 055 /** 056 * Constructs a TablePosition instance to represent the given row/column 057 * position in the given TableView instance. Both the TableView and 058 * TableColumn are referenced weakly in this class, so it is possible that 059 * they will be null when their respective getters are called. 060 * 061 * @param tableView The TableView that this position is related to. 062 * @param row The row that this TablePosition is representing. 063 * @param tableColumn The TableColumn instance that this TablePosition represents. 064 */ 065 public TablePosition(TableView<S> tableView, int row, TableColumn<S,T> tableColumn) { 066 super(row, tableColumn); 067 this.controlRef = new WeakReference<TableView<S>>(tableView); 068 } 069 070 071 072 /*************************************************************************** 073 * * 074 * Instance Variables * 075 * * 076 **************************************************************************/ 077 078 private final WeakReference<TableView<S>> controlRef; 079 080 081 /*************************************************************************** 082 * * 083 * Public API * 084 * * 085 **************************************************************************/ 086 087 /** 088 * The column index that this TablePosition represents in the TableView. It 089 * is -1 if the TableView or TableColumn instances are null. 090 */ 091 @Override public int getColumn() { 092 TableView<S> tableView = getTableView(); 093 TableColumn<S,T> tableColumn = getTableColumn(); 094 return tableView == null || tableColumn == null ? -1 : 095 tableView.getVisibleLeafIndex(tableColumn); 096 } 097 098 /** 099 * The TableView that this TablePosition is related to. 100 */ 101 public final TableView<S> getTableView() { 102 return controlRef.get(); 103 } 104 105 /** {@inheritDoc} */ 106 @Override public final TableColumn<S,T> getTableColumn() { 107 // Forcing the return type to be TableColumn<S,T>, not TableColumnBase<S,T> 108 return super.getTableColumn(); 109 } 110 111 /** 112 * Returns a string representation of this {@code TablePosition} object. 113 * @return a string representation of this {@code TablePosition} object. 114 */ 115 @Override public String toString() { 116 return "TablePosition [ row: " + getRow() + ", column: " + getTableColumn() + ", " 117 + "tableView: " + getTableView() + " ]"; 118 } 119}