|
org.netbeans.swing.outline 1.20 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JTable
org.netbeans.swing.etable.ETable
org.netbeans.swing.outline.Outline
public class Outline
An Outline, or tree-table component. Takes an instance of OutlineModel, an interface which merges TreeModel and TableModel.
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;
}
}
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.
| Nested Class Summary | |
|---|---|
protected class |
Outline.OutlineColumn
An Outline implementation of table column. |
| Nested classes/interfaces inherited from class org.netbeans.swing.etable.ETable |
|---|
ETable.ColumnSelection, ETable.RowMapping |
| Nested classes/interfaces inherited from class javax.swing.JTable |
|---|
JTable.AccessibleJTable, JTable.DropLocation, 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.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary |
|---|
| Fields inherited from class org.netbeans.swing.etable.ETable |
|---|
inverseSortingPermutation, PROP_QUICK_FILTER, sortingPermutation |
| 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)
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)
Overriden to make a speed optimization. |
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)
|
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Outline()
public Outline(OutlineModel mdl)
| Method Detail |
|---|
public TableCellRenderer getCellRenderer(int row,
int column)
getCellRenderer in class JTablepublic 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 JTablepublic void setRootVisible(boolean val)
public boolean isRootVisible()
public void setRowHeight(int row,
int rowHeight)
setRowHeight in class JTableprotected TableColumn createColumn(int modelIndex)
ETable
createColumn in class ETablepublic String getToolTipText(MouseEvent event)
ETable
getToolTipText in class ETablepublic JToolTip createToolTip()
createToolTip in class JComponentprotected void sortAndFilter()
sortAndFilter in class ETablepublic void setModel(TableModel mdl)
OutlineModel (with the exception of calls from the
superclass constructor)
setModel in class ETableJTable.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 position
public boolean editCellAt(int row,
int column,
EventObject e)
ETable
editCellAt in class ETableJTable.editCellAt(int, int, EventObject)
protected void configureTreeCellEditor(Component editor,
int row,
int column)
editor - The editor componentrow - Editor's rowcolumn - Editor's columnpublic void addNotify()
addNotify in class JTablepublic void tableChanged(TableModelEvent e)
ETable
tableChanged in interface TableModelListenertableChanged in class ETable
public void changeSelection(int rowIndex,
int columnIndex,
boolean toggle,
boolean extend)
changeSelection in class JTableprotected void processMouseEvent(MouseEvent e)
processMouseEvent in class JComponent
|
org.netbeans.swing.outline 1.20 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||