Quaqua 7.4.2 2011-07-05

ch.randelshofer.quaqua
Class JBrowser

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by ch.randelshofer.quaqua.JBrowser
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.swing.Scrollable

public class JBrowser
extends javax.swing.JComponent
implements javax.swing.Scrollable

JBrowser provides a user interface for displaying and selecting items from a list of data or from hierarchically organized lists of data such as directory paths. When working with a hierarchy of data, the levels are displayed in columns, which are numbered from left to right.

JBrowser is a clean-room implementation of an Aqua column view (NSBrowser), which is used by file dialogs and the finder of Mac OS X.

Usage

In general a JBrowser can be used whenever a JTree is suitable. JBrowsers uses a TreeModel like a JTree.

If you are using JBrowser without the Quaqua Look and Feel, you may notice that it does not fill the viewport with empty columns. To work around this, you may want to use JBrowser together with the helper class JBrowserViewport.

Known bugs

Version:
$Id: JBrowser.java 372 2011-01-28 09:58:35Z wrandelshofer $
Author:
Werner Randelshofer
See Also:
JBrowserViewport, Serialized Form

Nested Class Summary
protected static class JBrowser.BrowserLayout
           
protected static class JBrowser.BrowserScrollPaneLayout
           
protected  class JBrowser.SizeHandle
           
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static java.lang.String CELL_RENDERER_PROPERTY
          Bound property name for cellRenderer.
static java.lang.String COLUMNS_RESIZABLE_PROPERTY
          Bound property name for columnsResizable.
static java.lang.String FIXED_CELL_WIDTH_PROPERTY
          Bound property name for preferredCellWidth.
static java.lang.String MINIMUM_CELL_WIDTH_PROPERTY
          Bound property name for minimumCellWidth.
static java.lang.String PREVIEW_RENDERER_PROPERTY
          Bound property name for cellRenderer.
static java.lang.String SELECTION_MODEL_PROPERTY
          Bound property name for selectionModel.
protected  javax.swing.tree.TreeSelectionModel selectionModel
          Models the set of selected nodes in this tree.
static java.lang.String TREE_MODEL_PROPERTY
          Bound property name for treeModel.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JBrowser()
          Creates a JBrowser with a sample model.
JBrowser(java.util.Hashtable value)
          Creates a JBrowser created from a Hashtable which does not display with root.
JBrowser(java.lang.Object[] value)
          Creates a JBrowser with each element of the specified array as the child of a new root node which is not displayed.
JBrowser(javax.swing.tree.TreeModel newModel)
          Creates an instance of JBrowser which does not display the root node -- the tree is created using the specified data model.
JBrowser(javax.swing.tree.TreeNode root)
          Creates a JBrowser with the specified TreeNode as its root, which does not display the root node.
JBrowser(javax.swing.tree.TreeNode root, boolean asksAllowsChildren)
          Creates a JBrowser with the specified TreeNode as its root, which does not display the root node and which decides whether a node is a leaf node in the specified manner.
JBrowser(java.util.Vector value)
          Creates a JBrowser with each element of the specified Vector as the child of a new root node which is not displayed.
 
Method Summary
protected  void addColumn(javax.swing.tree.TreePath path)
          Appends a new column to the browser.
 void addNotify()
          Calls the configureEnclosingScrollPane method.
 void addSelectionPath(javax.swing.tree.TreePath path)
          Adds the node identified by the specified TreePath to the current selection.
 void addTreeSelectionListener(javax.swing.event.TreeSelectionListener tsl)
          Adds a listener for TreeSelection events.
 void clearSelection()
          Clears the selection.
protected  void configureEnclosingScrollPane()
          If this JTable is the viewportView of an enclosing JScrollPane (the usual situation), configure this ScrollPane by, amongst other things, installing the table's tableHeader as the columnHeaderView of the scroll pane.
 java.lang.String convertValueToText(java.lang.Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
          Called by the renderers to convert the specified value to text.
protected static javax.swing.tree.TreeModel createTreeModel(java.lang.Object value)
          Returns a TreeModel wrapping the specified object.
 void ensurePathIsVisible(javax.swing.tree.TreePath path)
          Ensures that the last node of the specified path is visible.
protected  void fireValueChanged(javax.swing.event.TreeSelectionEvent e)
          Notifies all listeners that have registered interest for notification on this event type.
 BrowserCellRenderer getCellRenderer()
          Gets the delegate that's used to paint each cell in the browser.
 java.awt.Point getCellTipOrigin()
          Returns the origin of the cell tip tooltip relative to the origin of the cell renderer.
 javax.swing.tree.TreePath getClosestPathForLocation(int x, int y)
          Returns the path to the node that is closest to x,y.
 javax.swing.ListCellRenderer getColumnCellRenderer()
          Gets the delegate that's used to paint a column cell in the browser.
 int getColumnWidth(int column)
          Gets the width of a column.
protected static javax.swing.tree.TreeModel getDefaultTreeModel()
          Creates and returns a sample TreeModel.
 boolean getDragEnabled()
          Gets the dragEnabled property.
 int getFixedCellWidth()
           
 java.awt.event.KeyListener[] getKeyListeners()
          Returns an array of all the key listeners registered on this component.
 int getMinimumCellWidth()
           
 javax.swing.tree.TreeModel getModel()
          Returns the TreeModel that is providing the data.
 java.awt.Rectangle getPathBounds(javax.swing.tree.TreePath path)
          Returns the Rectangle that the specified node will be drawn into.
 javax.swing.tree.TreePath getPathForLocation(int x, int y)
          Returns the path for the node at the specified location.
 int getPreferredColumnWidth(int column)
          Gets the preferred width of a column, which usually is the width of the largest cell.
 java.awt.Dimension getPreferredScrollableViewportSize()
          Returns the preferred display size of a JBrowser.
 int getPreviewColumnWidth()
          Gets the width of the preview column.
 int getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Returns the amount to increment when scrolling.
 boolean getScrollableTracksViewportHeight()
          Returns true to indicate that the height of the viewport determines the height of the browser.
 boolean getScrollableTracksViewportWidth()
          Returns false to indicate that the width of the viewport does not determine the width of the browser, unless the preferred width of the browser is smaller than the viewports width.
 int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Returns the amount to increment when scrolling.
 int getSelectionCount()
          Returns the number of nodes selected.
 javax.swing.tree.TreeSelectionModel getSelectionModel()
          Returns the model for selections.
 javax.swing.tree.TreePath getSelectionPath()
          Returns the path to the first selected node.
 javax.swing.tree.TreePath[] getSelectionPaths()
          Returns the paths of all selected values.
 BrowserUI getUI()
          Returns the look and feel (L&F) object that renders this component.
 java.lang.String getUIClassID()
          Returns the suffix used to construct the name of the look and feel (L&F) class used to render this component.
 boolean isColumnsResizable()
          Returns true, if the columns are resizable by the uesr.
 boolean isPathSelected(javax.swing.tree.TreePath path)
          Returns true if the item identified by the path is currently selected.
 boolean isShowCellTips()
          Returns true if the JBrowser shows cell tips for list cells that don't fit into a column.
protected  void removeColumn(int columnIndex)
          Removes the specified column from the browser.
protected  void removeLastListColumn()
          Removes the last list column from the browser.
 void removeNotify()
          Calls the unconfigureEnclosingScrollPane method.
 void removeSelectionPath(javax.swing.tree.TreePath path)
          Removes the node identified by the specified path from the current selection.
 void removeTreeSelectionListener(javax.swing.event.TreeSelectionListener tsl)
          Removes a TreeSelection listener.
 void requestFocus()
           
 void setCellRenderer(BrowserCellRenderer cellRenderer)
          Sets the delegate that's used to paint each cell in the browser.
 void setColumnCellRenderer(javax.swing.ListCellRenderer cellRenderer)
          Sets the delegate that's used to paint a cell and the arrows in the browser.
 void setColumnsResizable(boolean newValue)
          Sets whether columns should be resizable.
 void setColumnWidth(int column, int width)
          Sets the width of a column.
 void setDragEnabled(boolean b)
          Sets the dragEnabled property, which must be true to enable automatic drag handling (the first part of drag and drop) on this component.
 void setDropTarget(java.awt.dnd.DropTarget t)
           
 void setFixedCellWidth(int width)
          Sets the width of every cell in the browser.
 void setMinimumCellWidth(int newValue)
          Sets the minimum width of cells in the browser.
 void setModel(javax.swing.tree.TreeModel newModel)
          Sets the TreeModel that will provide the data.
 void setPreviewColumnWidth(int width)
          Sets the width of the preview column.
 void setPreviewRenderer(BrowserPreviewRenderer newValue)
          Sets the delegate that's used to paint the preview column in the browser.
 void setPrototypeCellValue(java.lang.Object prototypeCellValue)
           
 void setSelectionMode(int selectionMode)
          Sets the selection mode, which must be one of TreeSelectionModel.SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
 void setSelectionModel(javax.swing.tree.TreeSelectionModel selectionModel)
          Sets the tree's selection model.
 void setSelectionPath(javax.swing.tree.TreePath path)
          Selects the node identified by the specified path.
 void setSelectionPaths(javax.swing.tree.TreePath[] paths)
          Selects the nodes identified by the specified array of paths.
 void setShowCellTipOrigin(java.awt.Point newValue)
          Sets the origin of the cell tip tooltip relative to the origin of the cell renderer.
 void setShowCellTips(boolean newValue)
          Set this to true, if you want to JBrowser to display a tooltip for the cell over which the mouse is hovering.
 void setTransferHandler(javax.swing.TransferHandler newValue)
           
 void setUI(BrowserUI ui)
          Sets the look and feel (L&F) object that renders this component.
protected  void unconfigureEnclosingScrollPane()
          Reverses the effect of configureEnclosingScrollPane by replacing the columnHeaderView of the enclosing scroll pane with null.
 void updatePreviewColumn()
           
 void updateUI()
          Resets the UI property with the value from the current look and feel.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

selectionModel

protected transient javax.swing.tree.TreeSelectionModel selectionModel
Models the set of selected nodes in this tree.


CELL_RENDERER_PROPERTY

public static final java.lang.String CELL_RENDERER_PROPERTY
Bound property name for cellRenderer.

See Also:
Constant Field Values

PREVIEW_RENDERER_PROPERTY

public static final java.lang.String PREVIEW_RENDERER_PROPERTY
Bound property name for cellRenderer.

See Also:
Constant Field Values

TREE_MODEL_PROPERTY

public static final java.lang.String TREE_MODEL_PROPERTY
Bound property name for treeModel.

See Also:
Constant Field Values

SELECTION_MODEL_PROPERTY

public static final java.lang.String SELECTION_MODEL_PROPERTY
Bound property name for selectionModel.

See Also:
Constant Field Values

FIXED_CELL_WIDTH_PROPERTY

public static final java.lang.String FIXED_CELL_WIDTH_PROPERTY
Bound property name for preferredCellWidth.

See Also:
Constant Field Values

MINIMUM_CELL_WIDTH_PROPERTY

public static final java.lang.String MINIMUM_CELL_WIDTH_PROPERTY
Bound property name for minimumCellWidth.

See Also:
Constant Field Values

COLUMNS_RESIZABLE_PROPERTY

public static final java.lang.String COLUMNS_RESIZABLE_PROPERTY
Bound property name for columnsResizable.

See Also:
Constant Field Values
Constructor Detail

JBrowser

public JBrowser()
Creates a JBrowser with a sample model. The default model used by the browser defines a leaf node as any node without children.

See Also:
DefaultTreeModel.asksAllowsChildren

JBrowser

public JBrowser(java.lang.Object[] value)
Creates a JBrowser with each element of the specified array as the child of a new root node which is not displayed. By default, the browser defines a leaf node as any node without children.

Parameters:
value - an array of Objects
See Also:
DefaultTreeModel.asksAllowsChildren

JBrowser

public JBrowser(java.util.Vector value)
Creates a JBrowser with each element of the specified Vector as the child of a new root node which is not displayed. By default, the tree defines a leaf node as any node without children.

Parameters:
value - a Vector
See Also:
DefaultTreeModel.asksAllowsChildren

JBrowser

public JBrowser(java.util.Hashtable value)
Creates a JBrowser created from a Hashtable which does not display with root. Each value-half of the key/value pairs in the HashTable becomes a child of the new root node. By default, the tree defines a leaf node as any node without children.

Parameters:
value - a Hashtable
See Also:
DefaultTreeModel.asksAllowsChildren

JBrowser

public JBrowser(javax.swing.tree.TreeNode root)
Creates a JBrowser with the specified TreeNode as its root, which does not display the root node. By default, the tree defines a leaf node as any node without children.

Parameters:
root - a TreeNode object
See Also:
DefaultTreeModel.asksAllowsChildren

JBrowser

public JBrowser(javax.swing.tree.TreeNode root,
                boolean asksAllowsChildren)
Creates a JBrowser with the specified TreeNode as its root, which does not display the root node and which decides whether a node is a leaf node in the specified manner.

Parameters:
root - a TreeNode object
asksAllowsChildren - if false, any node without children is a leaf node; if true, only nodes that do not allow children are leaf nodes
See Also:
DefaultTreeModel.asksAllowsChildren

JBrowser

public JBrowser(javax.swing.tree.TreeModel newModel)
Creates an instance of JBrowser which does not display the root node -- the tree is created using the specified data model.

Parameters:
newModel - the TreeModel to use as the data model
Method Detail

getUI

public BrowserUI getUI()
Returns the look and feel (L&F) object that renders this component.

Returns:
the ListUI object that renders this component

setUI

public void setUI(BrowserUI ui)
Sets the look and feel (L&F) object that renders this component.

Parameters:
ui - the BrowserUI L&F object
See Also:
UIDefaults.getUI(javax.swing.JComponent)

updateUI

public void updateUI()
Resets the UI property with the value from the current look and feel.

Overrides:
updateUI in class javax.swing.JComponent
See Also:
UIManager.getUI(javax.swing.JComponent)

getUIClassID

public java.lang.String getUIClassID()
Returns the suffix used to construct the name of the look and feel (L&F) class used to render this component.

Overrides:
getUIClassID in class javax.swing.JComponent
Returns:
the string "BrowserUI"
See Also:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

setPrototypeCellValue

public void setPrototypeCellValue(java.lang.Object prototypeCellValue)

setDragEnabled

public void setDragEnabled(boolean b)
Sets the dragEnabled property, which must be true to enable automatic drag handling (the first part of drag and drop) on this component. The transferHandler property needs to be set to a non-null value for the drag to do anything. The default value of the dragEnabled property is false.

When automatic drag handling is enabled, most look and feels begin a drag-and-drop operation whenever the user presses the mouse button over a selection and then moves the mouse a few pixels. Setting this property to true can therefore have a subtle effect on how selections behave.

Some look and feels might not support automatic drag and drop; they will ignore this property. You can work around such look and feels by modifying the component to directly call the exportAsDrag method of a TransferHandler.

Parameters:
b - the value to set the dragEnabled property to
Throws:
java.awt.HeadlessException - if b is true and GraphicsEnvironment.isHeadless() returns true
See Also:
GraphicsEnvironment.isHeadless(), getDragEnabled(), setTransferHandler(javax.swing.TransferHandler), TransferHandler

setTransferHandler

public void setTransferHandler(javax.swing.TransferHandler newValue)
Overrides:
setTransferHandler in class javax.swing.JComponent

getDragEnabled

public boolean getDragEnabled()
Gets the dragEnabled property.

Returns:
the value of the dragEnabled property
See Also:
setDragEnabled(boolean)

getDefaultTreeModel

protected static javax.swing.tree.TreeModel getDefaultTreeModel()
Creates and returns a sample TreeModel. Used primarily for beanbuilders to show something interesting.

Returns:
the default TreeModel

createTreeModel

protected static javax.swing.tree.TreeModel createTreeModel(java.lang.Object value)
Returns a TreeModel wrapping the specified object. If the object is:then a new root node is created with each of the incoming objects as children. Otherwise, a new root is created with the specified object as its value.

Parameters:
value - the Object used as the foundation for the TreeModel
Returns:
a TreeModel wrapping the specified object

getClosestPathForLocation

public javax.swing.tree.TreePath getClosestPathForLocation(int x,
                                                           int y)
Returns the path to the node that is closest to x,y. If no nodes are currently viewable, or there is no model, returns null, otherwise it always returns a valid path. To test if the node is exactly at x, y, get the node's bounds and test x, y against that.

Parameters:
x - an integer giving the number of pixels horizontally from the left edge of the display area, minus any left margin
y - an integer giving the number of pixels vertically from the top of the display area, minus any top margin
Returns:
the TreePath for the node closest to that location,
See Also:
getPathForLocation(int, int), getPathBounds(javax.swing.tree.TreePath)

getPathBounds

public java.awt.Rectangle getPathBounds(javax.swing.tree.TreePath path)
Returns the Rectangle that the specified node will be drawn into. Returns null if any component in the path is hidden (under a collapsed parent).

Note:
This method returns a valid rectangle, even if the specified node is not currently displayed.

Parameters:
path - the TreePath identifying the node
Returns:
the Rectangle the node is drawn in, or null

setShowCellTips

public void setShowCellTips(boolean newValue)
Set this to true, if you want to JBrowser to display a tooltip for the cell over which the mouse is hovering. The tooltip is shown only for cells which are wider than the current width of the browser column.


isShowCellTips

public boolean isShowCellTips()
Returns true if the JBrowser shows cell tips for list cells that don't fit into a column.


setShowCellTipOrigin

public void setShowCellTipOrigin(java.awt.Point newValue)
Sets the origin of the cell tip tooltip relative to the origin of the cell renderer.


getCellTipOrigin

public java.awt.Point getCellTipOrigin()
Returns the origin of the cell tip tooltip relative to the origin of the cell renderer.


isPathSelected

public boolean isPathSelected(javax.swing.tree.TreePath path)
Returns true if the item identified by the path is currently selected.

Parameters:
path - a TreePath identifying a node
Returns:
true if the node is selected

addSelectionPath

public void addSelectionPath(javax.swing.tree.TreePath path)
Adds the node identified by the specified TreePath to the current selection. If any component of the path isn't viewable, and getExpandsSelectedPaths is true it is made viewable.

Note that JBrowser does not allow duplicate nodes to exist as children under the same parent -- each sibling must be a unique object.

Parameters:
path - the TreePath to add

ensurePathIsVisible

public void ensurePathIsVisible(javax.swing.tree.TreePath path)
Ensures that the last node of the specified path is visible.
Nothing happens, if it is impossible to make the node visible without changing the selection of the JBrowser.

Parameters:
path - the TreePath specifying the node to make visible.

setSelectionPath

public void setSelectionPath(javax.swing.tree.TreePath path)
Selects the node identified by the specified path.

Parameters:
path - the TreePath specifying the node to select

removeSelectionPath

public void removeSelectionPath(javax.swing.tree.TreePath path)
Removes the node identified by the specified path from the current selection.

Parameters:
path - the TreePath identifying a node

getPathForLocation

public javax.swing.tree.TreePath getPathForLocation(int x,
                                                    int y)
Returns the path for the node at the specified location.

Parameters:
x - an integer giving the number of pixels horizontally from the left edge of the display area, minus any left margin
y - an integer giving the number of pixels vertically from the top of the display area, minus any top margin
Returns:
the TreePath for the node at that location

clearSelection

public void clearSelection()
Clears the selection. This collapses all columns.


setFixedCellWidth

public void setFixedCellWidth(int width)
Sets the width of every cell in the browser. If width is -1, cell widths are computed by applying getPreferredSize to the cellRenderer component for each tree node.

The default value of this property is 175.

This is a JavaBeans bound property.

Parameters:
width - the width, in pixels, for all cells in this list
See Also:
setMinimumCellWidth(int), Container.addPropertyChangeListener(java.beans.PropertyChangeListener)

getFixedCellWidth

public int getFixedCellWidth()

setMinimumCellWidth

public void setMinimumCellWidth(int newValue)
Sets the minimum width of cells in the browser. This width affects the minimum width of columns, when the user resizes them.

The default value of this property is 150.

This is a JavaBeans bound property.

Parameters:
newValue - the width, in pixels.
See Also:
setFixedCellWidth(int), Container.addPropertyChangeListener(java.beans.PropertyChangeListener)

getMinimumCellWidth

public int getMinimumCellWidth()

setColumnWidth

public void setColumnWidth(int column,
                           int width)
Sets the width of a column.

Parameters:
column - Index of the column.
width - The width.

getColumnWidth

public int getColumnWidth(int column)
Gets the width of a column.

Parameters:
column - Index of the column.

getPreferredColumnWidth

public int getPreferredColumnWidth(int column)
Gets the preferred width of a column, which usually is the width of the largest cell.

Parameters:
column - Index of the column.

setPreviewColumnWidth

public void setPreviewColumnWidth(int width)
Sets the width of the preview column.

Parameters:
width - The width.

getPreviewColumnWidth

public int getPreviewColumnWidth()
Gets the width of the preview column.


setColumnsResizable

public void setColumnsResizable(boolean newValue)
Sets whether columns should be resizable.

Parameters:
newValue - The new value.

isColumnsResizable

public boolean isColumnsResizable()
Returns true, if the columns are resizable by the uesr.

Returns:
The columnsResizable-property.

setColumnCellRenderer

public void setColumnCellRenderer(javax.swing.ListCellRenderer cellRenderer)
Sets the delegate that's used to paint a cell and the arrows in the browser. If you don't want to render the arrows, use setCellRenderer instead.

The default value of this property is provided by the ListUI delegate, i.e. by the look and feel implementation.

This is a JavaBeans bound property.

Parameters:
cellRenderer - the ListCellRenderer that paints browser cells
See Also:
getColumnCellRenderer(), setCellRenderer(ch.randelshofer.quaqua.BrowserCellRenderer)

getColumnCellRenderer

public javax.swing.ListCellRenderer getColumnCellRenderer()
Gets the delegate that's used to paint a column cell in the browser.

The default value of this property is provided by the BrowserUI delegate, i.e. by the look and feel implementation.

This is a JavaBeans bound property.

Returns:
The ListCellRenderer that paints browser cells

setCellRenderer

public void setCellRenderer(BrowserCellRenderer cellRenderer)
Sets the delegate that's used to paint each cell in the browser. If you use this delegate, you don't have to render the arrows for non-leaf items. If you want to render these arrows, use setColumnCellRenderer instead.

The default value of this property is provided by the ListUI delegate, i.e. by the look and feel implementation.

This is a JavaBeans bound property.

Parameters:
cellRenderer - the ListCellRenderer that paints browser cells
See Also:
getCellRenderer(), setColumnCellRenderer(javax.swing.ListCellRenderer)

getCellRenderer

public BrowserCellRenderer getCellRenderer()
Gets the delegate that's used to paint each cell in the browser.

The default value of this property is provided by the BrowserUI delegate, i.e. by the look and feel implementation. This can be null, if the ListCellRenderer for columns does not make use of a BrowserCellRenderer to render a cell.

This is a JavaBeans bound property.

Returns:
The BrowserCellRenderer that paints browser cells

setPreviewRenderer

public void setPreviewRenderer(BrowserPreviewRenderer newValue)
Sets the delegate that's used to paint the preview column in the browser.

The default value of this property is null. If null, no preview column is shown.

This is a JavaBeans bound property.

Parameters:
newValue - the ListCellRenderer that paints the preview column.
See Also:
getColumnCellRenderer()

setDropTarget

public void setDropTarget(java.awt.dnd.DropTarget t)
Overrides:
setDropTarget in class java.awt.Component

getSelectionCount

public int getSelectionCount()
Returns the number of nodes selected.

Returns:
the number of nodes selected

setSelectionModel

public void setSelectionModel(javax.swing.tree.TreeSelectionModel selectionModel)
Sets the tree's selection model.

Parameters:
selectionModel - the TreeSelectionModel to use.
Throws:
java.lang.IllegalArgumentException - if the selectionModel is null.
See Also:
TreeSelectionModel

getSelectionModel

public javax.swing.tree.TreeSelectionModel getSelectionModel()
Returns the model for selections. This should always return a non-null value. If you don't want to allow anything to be selected set the selection model to null, which forces an empty selection model to be used.

See Also:
setSelectionModel(javax.swing.tree.TreeSelectionModel)

setSelectionMode

public void setSelectionMode(int selectionMode)
Sets the selection mode, which must be one of TreeSelectionModel.SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.

This may change the selection if the current selection is not valid for the new mode. For example, if three TreePaths are selected when the mode is changed to SINGLE_TREE_SELECTION, only one TreePath will remain selected. It is up to the particular implementation to decide what TreePath remains selected.


getSelectionPath

public javax.swing.tree.TreePath getSelectionPath()
Returns the path to the first selected node.

Returns:
the TreePath for the first selected node, or null if nothing is currently selected

getSelectionPaths

public javax.swing.tree.TreePath[] getSelectionPaths()
Returns the paths of all selected values.

Returns:
an array of TreePath objects indicating the selected nodes, or null if nothing is currently selected

setSelectionPaths

public void setSelectionPaths(javax.swing.tree.TreePath[] paths)
Selects the nodes identified by the specified array of paths. All path components except the last one of the paths must be equal.

Parameters:
paths - an array of TreePath objects that specifies the nodes to select

getKeyListeners

public java.awt.event.KeyListener[] getKeyListeners()
Returns an array of all the key listeners registered on this component.

Overrides:
getKeyListeners in class java.awt.Component
Returns:
all of this component's KeyListeners or an empty array if no key listeners are currently registered

updatePreviewColumn

public void updatePreviewColumn()

addTreeSelectionListener

public void addTreeSelectionListener(javax.swing.event.TreeSelectionListener tsl)
Adds a listener for TreeSelection events.

Parameters:
tsl - the TreeSelectionListener that will be notified when a node is selected or deselected (a "negative selection")

removeTreeSelectionListener

public void removeTreeSelectionListener(javax.swing.event.TreeSelectionListener tsl)
Removes a TreeSelection listener.

Parameters:
tsl - the TreeSelectionListener to remove

fireValueChanged

protected void fireValueChanged(javax.swing.event.TreeSelectionEvent e)
Notifies all listeners that have registered interest for notification on this event type.

Parameters:
e - the TreeSelectionEvent to be fired; generated by the TreeSelectionModel when a node is selected or deselected
See Also:
EventListenerList

getModel

public javax.swing.tree.TreeModel getModel()
Returns the TreeModel that is providing the data.

Returns:
the TreeModel that is providing the data

setModel

public void setModel(javax.swing.tree.TreeModel newModel)
Sets the TreeModel that will provide the data.

Parameters:
newModel - the TreeModel that is to provide the data

addColumn

protected void addColumn(javax.swing.tree.TreePath path)
Appends a new column to the browser.


removeLastListColumn

protected void removeLastListColumn()
Removes the last list column from the browser.


removeColumn

protected void removeColumn(int columnIndex)
Removes the specified column from the browser.


getPreferredScrollableViewportSize

public java.awt.Dimension getPreferredScrollableViewportSize()
Returns the preferred display size of a JBrowser. The height is determined from getVisibleRowCount and the width is the current preferred width of two columns.

Specified by:
getPreferredScrollableViewportSize in interface javax.swing.Scrollable
Returns:
a Dimension object containing the preferred size

getScrollableUnitIncrement

public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Returns the amount to increment when scrolling. The amount is 10 or the width of the first/last displayed column that isn't completely in view or, if it is totally displayed, the width of the next column in the scrolling direction.

The height is always 10.

FIXME - Find a better way to compute the height.

Specified by:
getScrollableUnitIncrement in interface javax.swing.Scrollable
Parameters:
visibleRect - the view area visible within the viewport
orientation - either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL
direction - less than zero to scroll up/left, greater than zero for down/right
Returns:
the "unit" increment for scrolling in the specified direction
See Also:
JScrollBar.setUnitIncrement(int)

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Returns true to indicate that the height of the viewport determines the height of the browser.

In other words: the JScrollPane must never show a vertical scroll bar, because each column of the JBrowser provides one.

Specified by:
getScrollableTracksViewportHeight in interface javax.swing.Scrollable
Returns:
true
See Also:
Scrollable.getScrollableTracksViewportHeight()

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Returns false to indicate that the width of the viewport does not determine the width of the browser, unless the preferred width of the browser is smaller than the viewports width. In other words: ensure that the browser is never smaller than its viewport.

Specified by:
getScrollableTracksViewportWidth in interface javax.swing.Scrollable
Returns:
false
See Also:
Scrollable.getScrollableTracksViewportWidth()

getScrollableBlockIncrement

public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Returns the amount to increment when scrolling. The amount is the distance to the next column in the scrolling direction which is outside of the view.

The height is always 10.

FIXME - Find a better way to compute the height.

Specified by:
getScrollableBlockIncrement in interface javax.swing.Scrollable
Parameters:
visibleRect - the view area visible within the viewport
orientation - either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL
direction - less than zero to scroll up/left, greater than zero for down/right
Returns:
the "unit" increment for scrolling in the specified direction
See Also:
JScrollBar.setUnitIncrement(int)

addNotify

public void addNotify()
Calls the configureEnclosingScrollPane method.

Overrides:
addNotify in class javax.swing.JComponent
See Also:
configureEnclosingScrollPane()

configureEnclosingScrollPane

protected void configureEnclosingScrollPane()
If this JTable is the viewportView of an enclosing JScrollPane (the usual situation), configure this ScrollPane by, amongst other things, installing the table's tableHeader as the columnHeaderView of the scroll pane. When a JTable is added to a JScrollPane in the usual way, using new JScrollPane(myTable), addNotify is called in the JTable (when the table is added to the viewport). JTable's addNotify method in turn calls this method, which is protected so that this default installation procedure can be overridden by a subclass.

See Also:
addNotify()

removeNotify

public void removeNotify()
Calls the unconfigureEnclosingScrollPane method.

Overrides:
removeNotify in class javax.swing.JComponent
See Also:
unconfigureEnclosingScrollPane()

unconfigureEnclosingScrollPane

protected void unconfigureEnclosingScrollPane()
Reverses the effect of configureEnclosingScrollPane by replacing the columnHeaderView of the enclosing scroll pane with null. JTable's removeNotify method calls this method, which is protected so that this default uninstallation procedure can be overridden by a subclass.

See Also:
removeNotify(), configureEnclosingScrollPane()

requestFocus

public void requestFocus()
Overrides:
requestFocus in class javax.swing.JComponent

convertValueToText

public java.lang.String convertValueToText(java.lang.Object value,
                                           boolean selected,
                                           boolean expanded,
                                           boolean leaf,
                                           int row,
                                           boolean hasFocus)
Called by the renderers to convert the specified value to text. This implementation returns value.toString, ignoring all other arguments. To control the conversion, subclass this method and use any of the arguments you need.

Parameters:
value - the Object to convert to text
selected - true if the node is selected
expanded - true if the node is expanded
leaf - true if the node is a leaf node
row - an integer specifying the node's display row, where 0 is the first row in the display
hasFocus - true if the node has the focus
Returns:
the String representation of the node's value

Copyright 2003-2007 (c) Werner Randelshofer.
All rights reserved.