org.netbeans.swing.outline 1.7

org.netbeans.swing.outline
Class Outline

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JTable
                  extended by org.netbeans.swing.etable.ETable
                      extended by org.netbeans.swing.outline.Outline
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditorListener, ListSelectionListener, TableColumnModelListener, TableModelListener, Scrollable

public class Outline
extends ETable

An Outline, or tree-table component. Takes an instance of OutlineModel, an interface which merges TreeModel and TableModel.

Simplest usage:

  1. Create a standard tree model for the tree node portion of the outline.
  2. Implement RowModel. RowModel is a subset of TableModel - it is passed the value in column 0 of the Outline and a column index, and returns the value in the column in question.
  3. Pass the TreeModel and the RowModel to DefaultOutlineModel.createModel()
This will generate an instance of DefaultOutlineModel which will use the TreeModel for the rows/tree column content, and use the RowModel to provide the additional table columns.

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;
      }
   }
 

Note: This API is still under development and may change even in incompatible way during its stabilization phase. The API will be finalized in NetBeans version 6.5.

See Also:
Serialized Form

Nested Class Summary
protected  class Outline.OutlineColumn
           
 
Nested classes/interfaces inherited from class org.netbeans.swing.etable.ETable
ETable.RowMapping
 
Nested classes/interfaces inherited from class javax.swing.JTable
JTable.AccessibleJTable, JTable.PrintMode
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class org.netbeans.swing.etable.ETable
inverseSortingPermutation, sortingPermutation
 
Fields inherited from class javax.swing.JTable
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
 
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
Outline()
          Creates a new instance of Outline
Outline(OutlineModel mdl)
           
 
Method Summary
 void addNotify()
          Computes row height ...
 void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend)
           
 void collapsePath(TreePath path)
           
protected  void configureTreeCellEditor(Component editor, int row, int column)
           
protected  TableColumn createColumn(int modelIndex)
          Allow to plug own TableColumn implementation.
 boolean editCellAt(int row, int column, EventObject e)
          Overriden 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)
           
 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)
           
 RenderDataProvider getRenderDataProvider()
          Get the RenderDataProvider which is providing text, icons and tooltips for items in the tree column.
 boolean isExpanded(TreePath path)
           
 boolean isRootVisible()
          Is the tree root visible.
 boolean isVisible(TreePath path)
           
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)
           
 void tableChanged(TableModelEvent e)
          If the table data model is changed we reset (and then recompute) the sorting permutation and the row count.
 
Methods inherited from class org.netbeans.swing.etable.ETable
acceptByQuickFilter, configureEnclosingScrollPane, convertRowIndexToModel, convertRowIndexToView, convertValueToString, createDefaultColumnModel, createDefaultColumnsFromModel, displaySearchField, doLayout, getColumnDisplayName, getColumnSelector, getDefaultColumnSelector, getQuickFilterColumn, getQuickFilterCompareItem, getQuickFilterEqualsItem, getQuickFilterFormatStrings, getQuickFilterNoFilterItem, getQuickFilterObject, getQuickFilterPopup, getRowCount, getToolTipText, getTransferDelimiter, getValueAt, initializeLocalVars, isCellEditable, isColumnHidingAllowed, isFullyEditable, isFullyNonEditable, isPopupUsedFromTheCorner, processKeyBinding, readSettings, removeEditor, setCellBackground, setColumnHidingAllowed, setColumnSelector, setColumnSorted, setDefaultColumnSelector, setFullyEditable, setFullyNonEditable, setPopupUsedFromTheCorner, setQuickFilter, setQuickFilterFormatStrings, setSelectVisibleColumnsLabel, setValueAt, sortAndFilter, transformValue, unsetQuickFilter, writeSettings
 
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addRowSelectionInterval, clearSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, convertColumnIndexToModel, convertColumnIndexToView, createDefaultDataModel, createDefaultEditors, createDefaultRenderers, createDefaultSelectionModel, createDefaultTableHeader, createScrollPaneForTable, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getEditingColumn, getEditingRow, getEditorComponent, 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, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, prepareEditor, prepareRenderer, print, print, print, print, removeColumn, removeColumnSelectionInterval, removeNotify, removeRowSelectionInterval, resizeAndRepaint, rowAtPoint, selectAll, setAutoCreateColumnsFromModel, setAutoResizeMode, setCellEditor, setCellSelectionEnabled, setColumnModel, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setEditingColumn, setEditingRow, setGridColor, setIntercellSpacing, setPreferredScrollableViewportSize, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setSelectionBackground, setSelectionForeground, setSelectionMode, setSelectionModel, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUI, sizeColumnsToFit, sizeColumnsToFit, unconfigureEnclosingScrollPane, updateUI, valueChanged
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, 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
 
Methods inherited from class java.awt.Container
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, 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, getKeyListeners, 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, setDropTarget, 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
 

Constructor Detail

Outline

public Outline()
Creates a new instance of Outline


Outline

public Outline(OutlineModel mdl)
Method Detail

getCellRenderer

public TableCellRenderer getCellRenderer(int row,
                                         int column)
Always returns the default renderer for Object.class for the tree column

Overrides:
getCellRenderer in class JTable

getRenderDataProvider

public RenderDataProvider getRenderDataProvider()
Get the RenderDataProvider which is providing text, icons and tooltips for items in the tree column. The default property for this value is null, in which case standard JTable/JTree object -> icon/string conventions are used


setRenderDataProvider

public void setRenderDataProvider(RenderDataProvider provider)
Set the RenderDataProvider which will provide text, icons and tooltips for items in the tree column. The default is null. If null, the data displayed will be generated in the standard JTable/JTree way - calling toString() on objects in the tree model and using the look and feel's default tree folder and tree leaf icons.


getLayoutCache

public final AbstractLayoutCache getLayoutCache()
Get the layout cache which manages layout data for the Outline. Under no circumstances directly call the methods on the layout cache which change the expanded state - such changes will not be propagated into the table model, and will leave the model and its layout in inconsistent states. Any calls that affect expanded state must go through getTreePathSupport().


isVisible

public boolean isVisible(TreePath path)

setRowHeight

public void setRowHeight(int val)
Overridden to pass the fixed row height to the tree layout cache

Overrides:
setRowHeight in class JTable

setRootVisible

public void setRootVisible(boolean val)
Set whether or not the root is visible


isRootVisible

public boolean isRootVisible()
Is the tree root visible. Default value is true.


setRowHeight

public void setRowHeight(int row,
                         int rowHeight)
Overrides:
setRowHeight in class JTable

createColumn

protected TableColumn createColumn(int modelIndex)
Description copied from class: ETable
Allow to plug own TableColumn implementation. This implementation returns ETableColumn. Called from createDefaultColumnsFromModel().

Overrides:
createColumn in class ETable

setModel

public 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)

Overrides:
setModel in class ETable
See Also:
JTable.setModel(TableModel)

getOutlineModel

public OutlineModel getOutlineModel()
Convenience getter for the TableModel as an instance of OutlineModel. If no OutlineModel has been set, returns null.


expandPath

public void expandPath(TreePath path)
Expand a tree path


isExpanded

public boolean isExpanded(TreePath path)

collapsePath

public void collapsePath(TreePath path)

getPathBounds

public Rectangle getPathBounds(TreePath path)

getClosestPathForLocation

public TreePath getClosestPathForLocation(int x,
                                          int y)

editCellAt

public boolean editCellAt(int row,
                          int column,
                          EventObject e)
Description copied from class: ETable
Overriden to force requesting the focus after the user starts editing.

Overrides:
editCellAt in class ETable
See Also:
JTable.editCellAt(int, int, EventObject)

configureTreeCellEditor

protected void configureTreeCellEditor(Component editor,
                                       int row,
                                       int column)

addNotify

public void addNotify()
Computes row height ...

Overrides:
addNotify in class JTable

tableChanged

public void tableChanged(TableModelEvent e)
Description copied from class: ETable
If the table data model is changed we reset (and then recompute) the sorting permutation and the row count. The selection is restored when needed.

Specified by:
tableChanged in interface TableModelListener
Overrides:
tableChanged in class ETable

changeSelection

public void changeSelection(int rowIndex,
                            int columnIndex,
                            boolean toggle,
                            boolean extend)
Overrides:
changeSelection in class JTable

processMouseEvent

protected void processMouseEvent(MouseEvent e)
Overrides:
processMouseEvent in class JComponent

org.netbeans.swing.outline 1.7

Built on November 21 2009.  |  Portions Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.