001 /* TreeUI.java -- 002 Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 039 package javax.swing.plaf; 040 041 import java.awt.Rectangle; 042 043 import javax.swing.JTree; 044 import javax.swing.tree.TreePath; 045 046 /** 047 * An abstract base class for delegates that provide the user 048 * interface for <code>JTree</code>. 049 * 050 * @see javax.swing.JTree 051 * 052 * @author Sascha Brawer (brawer@dandelis.ch) 053 */ 054 public abstract class TreeUI extends ComponentUI 055 { 056 /** 057 * Constructs a new <code>TreeUI</code>. 058 */ 059 public TreeUI() 060 { 061 // Nothing to do here. 062 } 063 064 065 /** 066 * Determines the geometric extent of the label that is 067 * drawn for a path. 068 * 069 * @param tree the <code>JTree</code> for which this delegate 070 * object provides the user interface. 071 * 072 * @param path the path whose label extent is requested. 073 * 074 * @return a rectangle enclosing the label, or <code>null</code> 075 * if <code>path</code> contains invalid nodes. 076 */ 077 public abstract Rectangle getPathBounds(JTree tree, TreePath path); 078 079 080 /** 081 * Creates a <code>TreePath</code> for the specified row. 082 * 083 * @param tree the <code>JTree</code> for which this delegate 084 * object provides the user interface. 085 * 086 * @param row the index of the row, which should be a number 087 * in the range <code>[0, getRowCount(tree) - 1]</code>. 088 * 089 * @return a <code>TreePath</code> for the specified row, or 090 * <code>null</code> if <code>row</code> is outside 091 * the valid range. 092 */ 093 public abstract TreePath getPathForRow(JTree tree, int row); 094 095 096 /** 097 * Determines in which row a <code>TreePath</code> is currently 098 * being displayed. 099 * 100 * @param tree the <code>JTree</code> for which this delegate 101 * object provides the user interface. 102 * 103 * @param path the path for which the caller wants to know 104 * in which row it is being displayed. 105 * 106 * @return a number in the range <code>[0, getRowCount(tree) 107 * - 1]</code> if the path is currently on display; 108 * <code>-1</code> if the path is not shown to the 109 * user. 110 */ 111 public abstract int getRowForPath(JTree tree, TreePath path); 112 113 114 /** 115 * Counts how many rows are currently displayed. 116 * 117 * @param tree the <code>JTree</code> for which this delegate 118 * object provides the user interface. 119 * 120 * @return the number of visible rows. 121 */ 122 public abstract int getRowCount(JTree tree); 123 124 125 /** 126 * Finds the path that is closest to the specified position. 127 * 128 * <p><img src="doc-files/TreeUI-1.png" width="300" height="250" 129 * alt="[A screen shot of a JTree]" /> 130 * 131 * <p>As shown by the above illustration, the bounds of the 132 * closest path do not necessarily need to contain the passed 133 * location. 134 * 135 * @param tree the <code>JTree</code> for which this delegate 136 * object provides the user interface. 137 * 138 * @param x the horizontal location, relative to the origin 139 * of <code>tree</code>. 140 * 141 * @param y the vertical location, relative to the origin 142 * of <code>tree</code>. 143 * 144 * @return the closest path, or <code>null</code> if the 145 * tree is currenlty not displaying any paths at all. 146 */ 147 public abstract TreePath getClosestPathForLocation(JTree tree, 148 int x, int y); 149 150 151 /** 152 * Determines whether the user is currently editing a tree cell. 153 * 154 * @param tree the <code>JTree</code> for which this delegate 155 * object provides the user interface. 156 * 157 * @see #getEditingPath 158 */ 159 public abstract boolean isEditing(JTree tree); 160 161 162 /** 163 * Stops editing a tree cell, committing the entered value into the 164 * tree’s model. If no editing session is active, or if the 165 * active editor does not agree to stopping, nothing happens. In 166 * some look and feels, this action happens when the user has 167 * pressed the enter key. 168 * 169 * @param tree the <code>JTree</code> for which this delegate 170 * object provides the user interface. 171 * 172 * @return <code>false</code> if the editing still goes on because 173 * the cell editor has objected to stopping the session; 174 * <code>true</code> if editing has been stopped. 175 */ 176 public abstract boolean stopEditing(JTree tree); 177 178 179 /** 180 * Cancels editing a tree cell, discarding any entered value. 181 * If no editing session is active, nothing happens. The cell 182 * editor is not given an opportunity to veto the canceling. 183 * In some look and feels, this action happens when the user has 184 * pressed the escape key. 185 * 186 * @param tree the <code>JTree</code> for which this delegate 187 * object provides the user interface. 188 */ 189 public abstract void cancelEditing(JTree tree); 190 191 192 /** 193 * Starts a session to edit a tree cell. If the cell editor 194 * rejects editing the cell, it will just be selected. 195 * 196 * @param tree the <code>JTree</code> for which this delegate 197 * object provides the user interface. 198 * 199 * @param path the cell to edit. 200 */ 201 public abstract void startEditingAtPath(JTree tree, TreePath path); 202 203 204 /** 205 * Retrieves the tree cell that is currently being edited. 206 * 207 * @return the currently edited path, or <code>null</code> 208 * if no editing session is currently active. 209 */ 210 public abstract TreePath getEditingPath(JTree tree); 211 }