public class Outline extends ETable
Simplest usage:
DefaultOutlineModel.createModel()
It is also useful to provide an implementation of RenderDataProvider
to supply icons and affect text display of cells - this covers most of the
needs for which it is necessary to write a custom cell renderer in JTable/JTree.
Example usage:
Assume FileTreeModel is a model which, given a root directory, will
expose the files and folders underneath it. We will implement a
RowModel to expose the file size and date, and a RenderDataProvider which
will use a gray color for uneditable files and expose the full file path as
a tooltip. Assume the class this is implemented in is a
JPanel subclass or other Swing container.
XXX todo: clean up formatting & edit for style
public void initComponents() { setLayout (new BorderLayout()); TreeModel treeMdl = new FileTreeModel (someDirectory); OutlineModel mdl = DefaultOutlineModel.createOutlineModel(treeMdl, new FileRowModel(), true); outline = new Outline(); outline.setRenderDataProvider(new FileDataProvider()); outline.setRootVisible (true); outline.setModel (mdl); add (outline, BorderLayout.CENTER); } private class FileRowModel implements RowModel { public Class getColumnClass(int column) { switch (column) { case 0 : return Date.class; case 1 : return Long.class; default : assert false; } return null; } public int getColumnCount() { return 2; } public String getColumnName(int column) { return column == 0 ? "Date" : "Size"; } public Object getValueFor(Object node, int column) { File f = (File) node; switch (column) { case 0 : return new Date (f.lastModified()); case 1 : return new Long (f.length()); default : assert false; } return null; } public boolean isCellEditable(Object node, int column) { return false; } public void setValueFor(Object node, int column, Object value) { //do nothing, nothing is editable } } private class FileDataProvider implements RenderDataProvider { public java.awt.Color getBackground(Object o) { return null; } public String getDisplayName(Object o) { return ((File) o).getName(); } public java.awt.Color getForeground(Object o) { File f = (File) o; if (!f.isDirectory() && !f.canWrite()) { return UIManager.getColor ("controlShadow"); } return null; } public javax.swing.Icon getIcon(Object o) { return null; } public String getTooltipText(Object o) { return ((File) o).getAbsolutePath(); } public boolean isHtmlDisplayName(Object o) { return false; } }
Modifier and Type | Class and Description |
---|---|
protected class |
Outline.OutlineColumn
An Outline implementation of table column.
|
ETable.ColumnSelection, ETable.RowMapping
JTable.AccessibleJTable, JTable.DropLocation, JTable.PrintMode
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
inverseSortingPermutation, PROP_QUICK_FILTER, sortingPermutation
AUTO_RESIZE_ALL_COLUMNS, AUTO_RESIZE_LAST_COLUMN, AUTO_RESIZE_NEXT_COLUMN, AUTO_RESIZE_OFF, AUTO_RESIZE_SUBSEQUENT_COLUMNS, autoCreateColumnsFromModel, autoResizeMode, cellEditor, cellSelectionEnabled, columnModel, dataModel, defaultEditorsByColumnClass, defaultRenderersByColumnClass, editingColumn, editingRow, editorComp, gridColor, preferredViewportSize, rowHeight, rowMargin, rowSelectionAllowed, selectionBackground, selectionForeground, selectionModel, showHorizontalLines, showVerticalLines, tableHeader
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
Outline()
Creates a new instance of Outline
|
Outline(OutlineModel mdl) |
Modifier and Type | Method and Description |
---|---|
void |
addNotify()
Computes row height ...
|
void |
changeSelection(int rowIndex,
int columnIndex,
boolean toggle,
boolean extend) |
protected boolean |
checkAt(int row,
int column,
MouseEvent me)
Perform a selection/deselection of a check box on the given row and column,
if a check box exists on the given position.
|
void |
collapsePath(TreePath path)
Collapse the given tree path.
|
protected void |
configureTreeCellEditor(Component editor,
int row,
int column)
Configure the cell editor.
|
protected TableColumn |
createColumn(int modelIndex)
Allow to plug own TableColumn implementation.
|
JToolTip |
createToolTip() |
boolean |
editCellAt(int row,
int column,
EventObject e)
Overridden to force requesting the focus after the user starts editing.
|
void |
expandPath(TreePath path)
Expand a tree path
|
TableCellRenderer |
getCellRenderer(int row,
int column)
Always returns the default renderer for Object.class for the tree column
|
TreePath |
getClosestPathForLocation(int x,
int y)
Find the tree path that is closest to the given position.
|
AbstractLayoutCache |
getLayoutCache()
Get the layout cache which manages layout data for the Outline.
|
OutlineModel |
getOutlineModel()
Convenience getter for the
TableModel as an instance of
OutlineModel. |
Rectangle |
getPathBounds(TreePath path)
Get the UI bounds of the given tree path.
|
RenderDataProvider |
getRenderDataProvider()
Get the RenderDataProvider which is providing text, icons and tooltips
for items in the tree column.
|
String |
getToolTipText(MouseEvent event)
Overridden to make a speed optimization.
|
boolean |
isExpanded(TreePath path) |
boolean |
isRootVisible()
Is the tree root visible.
|
boolean |
isVisible(TreePath path) |
protected boolean |
processKeyBinding(KeyStroke ks,
KeyEvent e,
int condition,
boolean pressed)
Overridden to implement CTRL-+ for resizing of all columns,
CTRL-- for clearing the quick filter and CTRL-* for invoking the
column selection dialog.
|
protected void |
processMouseEvent(MouseEvent e) |
void |
setModel(TableModel mdl)
Overridden to throw an exception if the passed model is not an instance
of
OutlineModel (with the exception of calls from the
superclass constructor) |
void |
setRenderDataProvider(RenderDataProvider provider)
Set the RenderDataProvider which will provide text, icons and tooltips
for items in the tree column.
|
void |
setRootVisible(boolean val)
Set whether or not the root is visible
|
void |
setRowHeight(int val)
Overridden to pass the fixed row height to the tree layout cache
|
void |
setRowHeight(int row,
int rowHeight) |
protected void |
sortAndFilter()
Sorts the rows of the tree table.
|
void |
tableChanged(TableModelEvent e)
If the table data model is changed we reset (and then recompute)
the sorting permutation and the row count.
|
acceptByQuickFilter, configureEnclosingScrollPane, convertRowIndexToModel, convertRowIndexToView, convertValueToString, createDefaultColumnModel, createDefaultColumnsFromModel, createDefaultSelectionModel, createDefaultTableHeader, displaySearchField, doLayout, getColumnDisplayName, getColumnSelectionOn, getColumnSelector, getDefaultColumnSelector, getQuickFilterColumn, getQuickFilterCompareItem, getQuickFilterEqualsItem, getQuickFilterFormatStrings, getQuickFilterNoFilterItem, getQuickFilterObject, getQuickFilterPopup, getRowCount, getRowSorter, getTransferDelimiter, getValueAt, initializeLocalVars, isCellEditable, isColumnHidingAllowed, isFullyEditable, isFullyNonEditable, isPopupUsedFromTheCorner, readSettings, removeEditor, setAutoCreateRowSorter, setCellBackground, setColumnHidingAllowed, setColumnSelectionOn, setColumnSelector, setColumnSorted, setDefaultColumnSelector, setFullyEditable, setFullyNonEditable, setPopupUsedFromTheCorner, setQuickFilter, setQuickFilterFormatStrings, setRowSorter, setSelectVisibleColumnsLabel, setValueAt, showColumnSelectionDialog, transformValue, unsetQuickFilter, writeSettings
addColumn, addColumnSelectionInterval, addRowSelectionInterval, clearSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, convertColumnIndexToModel, convertColumnIndexToView, createDefaultDataModel, createDefaultEditors, createDefaultRenderers, createScrollPaneForTable, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoCreateRowSorter, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getDropLocation, getDropMode, getEditingColumn, getEditingRow, getEditorComponent, getFillsViewportHeight, getGridColor, getIntercellSpacing, getModel, getPreferredScrollableViewportSize, getPrintable, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getUI, getUIClassID, getUpdateSelectionOnSort, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, prepareEditor, prepareRenderer, print, print, print, print, print, removeColumn, removeColumnSelectionInterval, removeNotify, removeRowSelectionInterval, resizeAndRepaint, rowAtPoint, selectAll, setAutoCreateColumnsFromModel, setAutoResizeMode, setCellEditor, setCellSelectionEnabled, setColumnModel, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setDropMode, setEditingColumn, setEditingRow, setFillsViewportHeight, setGridColor, setIntercellSpacing, setPreferredScrollableViewportSize, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setSelectionBackground, setSelectionForeground, setSelectionMode, setSelectionModel, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUI, setUpdateSelectionOnSort, sizeColumnsToFit, sizeColumnsToFit, sorterChanged, unconfigureEnclosingScrollPane, updateUI, valueChanged
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, 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, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, 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, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, 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, transferFocusDownCycle, validate, validateTree
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, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public Outline()
public Outline(OutlineModel mdl)
public TableCellRenderer getCellRenderer(int row, int column)
getCellRenderer
in class JTable
public RenderDataProvider getRenderDataProvider()
public void setRenderDataProvider(RenderDataProvider provider)
toString()
on objects in the tree model and
using the look and feel's default tree folder and tree leaf icons.public final AbstractLayoutCache getLayoutCache()
getTreePathSupport()
.public boolean isVisible(TreePath path)
public void setRowHeight(int val)
setRowHeight
in class JTable
public void setRootVisible(boolean val)
public boolean isRootVisible()
public void setRowHeight(int row, int rowHeight)
setRowHeight
in class JTable
protected TableColumn createColumn(int modelIndex)
ETable
createColumn
in class ETable
public String getToolTipText(MouseEvent event)
ETable
getToolTipText
in class ETable
public JToolTip createToolTip()
createToolTip
in class JComponent
protected void sortAndFilter()
sortAndFilter
in class ETable
public void setModel(TableModel mdl)
OutlineModel
(with the exception of calls from the
superclass constructor)setModel
in class ETable
JTable.setModel(TableModel)
public OutlineModel getOutlineModel()
TableModel
as an instance of
OutlineModel. If no OutlineModel has been set, returns null.public void expandPath(TreePath path)
public boolean isExpanded(TreePath path)
public void collapsePath(TreePath path)
path
- The tree path to collapse.public Rectangle getPathBounds(TreePath path)
path
- The tree path to get the bounds for.public TreePath getClosestPathForLocation(int x, int y)
x
- The X coordinate of the positiony
- The Y coordinate of the positionprotected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed)
ETable
processKeyBinding
in class ETable
JTable.processKeyBinding(KeyStroke, KeyEvent, int, boolean)
public boolean editCellAt(int row, int column, EventObject e)
ETable
editCellAt
in class ETable
JTable.editCellAt(int, int, EventObject)
protected final boolean checkAt(int row, int column, MouseEvent me)
row
- The row of the check boxcolumn
- The column of the check boxme
- The mouse event that performs the check, or null
.true
if a CheckRenderDataProvider
is found
on the given row and column, is checkable and enabled and the
mouse event is either null
or upon the check-box
location. Returns false
otherwise.protected void configureTreeCellEditor(Component editor, int row, int column)
editor
- The editor componentrow
- Editor's rowcolumn
- Editor's columnpublic void tableChanged(TableModelEvent e)
ETable
tableChanged
in interface TableModelListener
tableChanged
in class ETable
public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend)
changeSelection
in class JTable
protected void processMouseEvent(MouseEvent e)
processMouseEvent
in class JComponent