1 /* 2 * Copyright (c) 1997, 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 javax.swing.plaf; 27 28 import java.awt.Rectangle; 29 import javax.swing.JTree; 30 import javax.swing.tree.TreePath; 31 32 /** 33 * Pluggable look and feel interface for JTree. 34 * 35 * @author Rob Davis 36 * @author Scott Violet 37 */ 38 public abstract class TreeUI extends ComponentUI 39 { 40 /** 41 * Constructor for subclasses to call. 42 */ TreeUI()43 protected TreeUI() {} 44 45 /** 46 * Returns the Rectangle enclosing the label portion that the 47 * last item in path will be drawn into. Will return null if 48 * any component in path is currently valid. 49 * 50 * @param tree the {@code JTree} for {@code path} 51 * @param path the {@code TreePath} identifying the node 52 * @return the {@code Rectangle} enclosing the label portion that the 53 * last item in path will be drawn into, {@code null} if any 54 * component in path is currently valid. 55 */ getPathBounds(JTree tree, TreePath path)56 public abstract Rectangle getPathBounds(JTree tree, TreePath path); 57 58 /** 59 * Returns the path for passed in row. If row is not visible 60 * null is returned. 61 * 62 * @param tree a {@code JTree} object 63 * @param row an integer specifying a row 64 * @return the {@code path} for {@code row} or {@code null} if {@code row} 65 * is not visible 66 */ getPathForRow(JTree tree, int row)67 public abstract TreePath getPathForRow(JTree tree, int row); 68 69 /** 70 * Returns the row that the last item identified in path is visible 71 * at. Will return -1 if any of the elements in path are not 72 * currently visible. 73 * 74 * @param tree the {@code JTree} for {@code path} 75 * @param path the {@code TreePath} object to look in 76 * @return an integer specifying the row at which the last item 77 * identified is visible, -1 if any of the elements in 78 * {@code path} are not currently visible 79 */ getRowForPath(JTree tree, TreePath path)80 public abstract int getRowForPath(JTree tree, TreePath path); 81 82 /** 83 * Returns the number of rows that are being displayed. 84 * 85 * @param tree the {@code JTree} for which to count rows 86 * @return an integer specifying the number of row being displayed 87 */ getRowCount(JTree tree)88 public abstract int getRowCount(JTree tree); 89 90 /** 91 * Returns the path to the node that is closest to x,y. If 92 * there is nothing currently visible this will return null, otherwise 93 * it'll always return a valid path. If you need to test if the 94 * returned object is exactly at x, y you should get the bounds for 95 * the returned path and test x, y against that. 96 * 97 * @param tree a {@code JTree} object 98 * @param x an integer giving the number of pixels horizontally from the 99 * left edge of the display area 100 * @param y an integer giving the number of pixels vertically from the top 101 * of the display area, minus any top margin 102 * @return the {@code TreePath} node closest to {@code x,y} or {@code null} 103 * if there is nothing currently visible 104 */ getClosestPathForLocation(JTree tree, int x, int y)105 public abstract TreePath getClosestPathForLocation(JTree tree, int x, 106 int y); 107 108 /** 109 * Returns true if the tree is being edited. The item that is being 110 * edited can be returned by getEditingPath(). 111 * 112 * @param tree a {@code JTree} object 113 * @return true if {@code tree} is being edited 114 */ isEditing(JTree tree)115 public abstract boolean isEditing(JTree tree); 116 117 /** 118 * Stops the current editing session. This has no effect if the 119 * tree isn't being edited. Returns true if the editor allows the 120 * editing session to stop. 121 * 122 * @param tree a {@code JTree} object 123 * @return true if the editor allows the editing session to stop 124 */ stopEditing(JTree tree)125 public abstract boolean stopEditing(JTree tree); 126 127 /** 128 * Cancels the current editing session. This has no effect if the 129 * tree isn't being edited. 130 * 131 * @param tree a {@code JTree} object 132 */ cancelEditing(JTree tree)133 public abstract void cancelEditing(JTree tree); 134 135 /** 136 * Selects the last item in path and tries to edit it. Editing will 137 * fail if the CellEditor won't allow it for the selected item. 138 * 139 * @param tree the {@code JTree} being edited 140 * @param path the {@code TreePath} to be edited 141 */ startEditingAtPath(JTree tree, TreePath path)142 public abstract void startEditingAtPath(JTree tree, TreePath path); 143 144 /** 145 * Returns the path to the element that is being edited. 146 * 147 * @param tree the {@code JTree} for which to return a path 148 * @return a {@code TreePath} containing the path to {@code tree} 149 */ getEditingPath(JTree tree)150 public abstract TreePath getEditingPath(JTree tree); 151 } 152