|
instrument/JTree API Documentation | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.pvv.bcd.instrument.JTree.Instrumenter
This class provides instrumentation of JTree objects. What this means is that by associating a JTree with an instance of the Instrumenter class, you can get features such as drag-and-drop, import/export XML, tree structure rearranging and editing of node names pretty much for free. While some of these features require you to do some adaption coding (particularly if you're not 100% happy with the default behaviour), such adaption is designed to be reasonably easy and we also provide means of disabling features that you do not desire.
Typical use of this class is as follows:
JTree tree = new JTree(someModel); Instrumenter instrument = Instrumenter.createInstrument(tree);You now proceed to put your tree into your GUI and will immediately reap the benefit of the instrumenter's many features. If you intend to interact with the instrument in the future, you will want to keep a reference to it. If not, you do not need to do so.
The instrumenter works primarily by attaching listeners to the input tree,
but will also do some tweaking of the tree. Refer to the documentation for
the various setUseDefaultXxx()
methods for details on which
features are available, what they do to your tree, and how to disable them.
To get the maximum usability with the least amount of fuss, it is recommended that you use tree nodes of type DefaultMutableTreeNode. The instrumenter expects this type for a variety of its features. It should be evident in the API documentation what features that require this. If you find any discrepancies, please let us know.
The instrument can be further customised by calling the various public methods in it. Refer to the API documentation for details.
Instances of Instrumenter can only be obtained by calling one of its factory methods;
Field Summary | |
static java.lang.String |
ACTION_ADD_ABOVE
Action name object for "Add Node Above" action |
static java.lang.String |
ACTION_ADD_BELOW
Action name object for "Add Node Below" action |
static java.lang.String |
ACTION_ADD_CHILD
Action name object for "Add Child Node" action |
static java.lang.String |
ACTION_COPY
Action name object for "Copy Selection" action |
static java.lang.String |
ACTION_CUT
Action name object for "Cut Selection" action |
static java.lang.String |
ACTION_DELETE
Action name object for "Delete Selection" action |
static java.lang.String |
ACTION_MAKE_ANCESTOR
Action name object for "Move Left" action |
static java.lang.String |
ACTION_MAKE_CHILD
Action name object for "Move Right" action |
static java.lang.String |
ACTION_MOVE_DOWN
Action name object for "Move Down" action |
static java.lang.String |
ACTION_MOVE_UP
Action name object for "Move Up" action |
static java.lang.String |
ACTION_PASTE
Action name object for "Paste" action |
static java.lang.String |
ACTION_REDO
Action name object for "Redo Undo" action |
static java.lang.String |
ACTION_START_EDIT
Action name object for "Edit Node Name" action |
static java.lang.String |
ACTION_UNDO
Action name object for "Undo Edit" action |
protected javax.swing.AbstractAction |
m_actAddAbove
|
protected javax.swing.AbstractAction |
m_actAddBelow
|
protected javax.swing.AbstractAction |
m_actAddChild
|
protected javax.swing.AbstractAction |
m_actCopy
|
protected javax.swing.AbstractAction |
m_actCut
|
protected javax.swing.AbstractAction |
m_actDelete
|
protected javax.swing.AbstractAction |
m_actMakeAncestor
|
protected javax.swing.AbstractAction |
m_actMakeChild
|
protected javax.swing.AbstractAction |
m_actMoveDown
|
protected javax.swing.AbstractAction |
m_actMoveUp
|
protected javax.swing.AbstractAction |
m_actPaste
|
protected javax.swing.AbstractAction |
m_actRedo
|
protected javax.swing.AbstractAction |
m_actStartEdit
|
protected javax.swing.AbstractAction |
m_actUndo
|
protected javax.swing.Action[] |
m_arrSelectionDependentActions
An array of all actions that are enabled only when 1+ nodes are selected |
java.util.Hashtable |
m_hashDefaultActionMap
|
java.util.Hashtable |
m_hashDefaultInputMap
|
Method Summary | |
void |
addChildNode()
Adds a new node at the end of the selected node's children |
void |
addNodeAbove()
Adds a new node above the selection, or at top if no selection |
void |
addNodeBelow()
Adds a new node below the selection, or at bottom if no selection |
void |
addNodes(javax.swing.tree.DefaultMutableTreeNode parent,
javax.swing.tree.DefaultMutableTreeNode[] nodes,
int parent_index)
Adds a set of nodes to the tree. |
void |
addUndoableEditListener(javax.swing.event.UndoableEditListener listener)
Adds listeners for undoableedit events. |
void |
addVetoableTreeStructureChangeListener(VetoableTreeStructureChangeListener l)
Adds a listener to changes in the tree structure. |
protected void |
configureCellEditor()
This method tweaks a cell editor so that we can use it. |
void |
copyNode()
Puts the selected nodes into the local clipboard. |
java.lang.String |
createFromXml(java.io.InputStream is)
Reads text from the given inputstream, parses it according to infobank.dtd and creates a new tree based upon the information. |
static Instrumenter |
createInstrument(javax.swing.JTree tree)
Convenience factory method to fully instrument a tree with all available functionality, keeping its contents. |
static Instrumenter |
createInstrument(javax.swing.JTree tree,
boolean full_instrumentation)
Convenience factory method instrumenting a tree while keeping the tree's contents. |
static Instrumenter |
createInstrument(javax.swing.JTree tree,
boolean full_instrumentation,
boolean clear)
Factory method for instrumenting a tree and returning the instrument. |
void |
cutNode()
Deletes the selected nodes and puts them into the local clipboard. |
void |
deleteSelectedNodes()
Deletes currently selected nodes with a "delete" semantic (as opposed to a "backspace" semantic). |
void |
doDndCompoundAdd(long op_id,
javax.swing.tree.DefaultMutableTreeNode parent,
javax.swing.tree.DefaultMutableTreeNode node,
int index)
The purpose and workings of this method are shrouded in the mists of time. |
void |
doDndCompoundDelete(long op_id,
javax.swing.tree.DefaultMutableTreeNode node)
The purpose and workings of this method are shrouded in the mists of time. |
void |
finishDndOperation(long op_id,
boolean source)
Finishes a Drag And Drop operation. |
protected void |
fireNodeCreation(VetoableTreeStructureChangeEvent e)
Fires a Node Creation event |
protected void |
fireNodeDeletion(VetoableTreeStructureChangeEvent e)
Fires a Node Deletion event |
protected void |
fireNodeMove(VetoableTreeStructureChangeEvent e)
Fires a Node Move event |
protected void |
fireNodeRename(VetoableTreeStructureChangeEvent e)
Fires a Node Rename event |
javax.swing.Action |
getAddAboveAction()
|
javax.swing.Action |
getAddBelowAction()
|
javax.swing.Action |
getAddChildAction()
|
javax.swing.Action |
getCopyAction()
|
javax.swing.Action |
getCutAction()
|
javax.swing.Action |
getDeleteAction()
|
javax.swing.Action |
getMakeAncestorAction()
|
javax.swing.Action |
getMakeChildAction()
|
javax.swing.Action |
getMoveDownAction()
|
javax.swing.Action |
getMoveUpAction()
|
long |
getMyInstrumentId()
Retrieves my unique instrument ID |
DndId |
getNextDndId()
Utility method that hands out unique IDs to use for identifying drag and drop operations. |
static long |
getNextInstrumentId()
Generates a unique ID. |
NodeFactory |
getNodeFactory()
Retrieve the currently active node factory. |
javax.swing.Action |
getPasteAction()
|
javax.swing.Action |
getRedoAction()
|
javax.swing.Action |
getStartEditAction()
|
javax.swing.Action |
getUndoAction()
|
javax.swing.undo.UndoManager |
getUndoManager()
Returns a reference to the currently active undo manager, if I know about it. |
void |
makeAncestor()
Moves all selected nodes one position to the "left" on the tree. |
void |
makeChild()
Moves all selected nodes one position to the "right" in the tree. |
protected javax.swing.tree.MutableTreeNode |
makeNodeFromXMLRecursive(org.jdom.Element xml_elem,
boolean is_root)
|
protected org.jdom.Element |
makeXMLNodeRecursive(java.lang.Object node,
boolean is_root)
|
void |
moveNode(javax.swing.tree.DefaultMutableTreeNode node_to_move,
javax.swing.tree.DefaultMutableTreeNode dest_node,
int dest_index)
Moves a node in the tree. |
void |
moveNodesDown()
Moves selected nodes one position towards the bottom |
void |
moveNodesUp()
Moves selected nodes one position towards the top |
void |
outputXml(java.io.OutputStream os)
Builds an XML representation of the tree, as defined by infobank.dtd. |
void |
pasteNode()
Makes copies of the nodes in the local clipboard (not the system clipboard) in the currently focused location. |
void |
pasteNode(org.pvv.bcd.instrument.JTree.SubTreeNode[] nodes)
Copies nodes into the currently focused location. |
void |
purgeUndoBuffer()
Empties the undo buffer. |
static javax.swing.tree.TreePath[] |
reduceSelection(javax.swing.tree.TreePath[] original)
Reduces a set of tree nodes to the minimum set that includes them all. |
void |
removeUndoableEditListener(javax.swing.event.UndoableEditListener listener)
Removes an UndoableEdit listener. |
void |
removeVetoableTreeStructureChangeListener(VetoableTreeStructureChangeListener l)
Removes a tree structure change listener. |
void |
setNodeFactory(NodeFactory factory)
Sets the object to use for creating new nodes in the tree. |
void |
setUndoManager(javax.swing.undo.UndoManager manager)
Registers a new undo manager with me. |
void |
setUseDefaultActionMap(boolean b)
Configures whether to use our default actions. |
void |
setUseDefaultDnd(boolean b)
Will configure the tree to use the default Drag And Drop implementation. |
void |
setUseDefaultKeyboardShortcuts(boolean b)
Configures whether to use our default keyboard shortcuts. |
void |
setUseDefaultNodeFactory(boolean b)
Configures whether or not to use the default node factory. |
void |
setUseDefaultTreeConfiguration(boolean b)
Will configure the tree for optimal instrumented operation. |
void |
setUseDefaultUndoManager(boolean b)
Configures whether or not to use the default Infobank undo manager. |
protected void |
updateActionObjects()
Will ensure that the Action objects we have created are in sync with the selection state of the tree. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected javax.swing.AbstractAction m_actAddAbove
protected javax.swing.AbstractAction m_actAddBelow
protected javax.swing.AbstractAction m_actAddChild
protected javax.swing.AbstractAction m_actMakeAncestor
protected javax.swing.AbstractAction m_actMakeChild
protected javax.swing.AbstractAction m_actUndo
protected javax.swing.AbstractAction m_actRedo
protected javax.swing.AbstractAction m_actDelete
protected javax.swing.AbstractAction m_actMoveUp
protected javax.swing.AbstractAction m_actMoveDown
protected javax.swing.AbstractAction m_actCopy
protected javax.swing.AbstractAction m_actCut
protected javax.swing.AbstractAction m_actPaste
protected javax.swing.AbstractAction m_actStartEdit
protected javax.swing.Action[] m_arrSelectionDependentActions
public static final java.lang.String ACTION_MOVE_UP
public static final java.lang.String ACTION_MOVE_DOWN
public static final java.lang.String ACTION_MAKE_ANCESTOR
public static final java.lang.String ACTION_MAKE_CHILD
public static final java.lang.String ACTION_COPY
public static final java.lang.String ACTION_CUT
public static final java.lang.String ACTION_PASTE
public static final java.lang.String ACTION_UNDO
public static final java.lang.String ACTION_REDO
public static final java.lang.String ACTION_ADD_ABOVE
public static final java.lang.String ACTION_ADD_BELOW
public static final java.lang.String ACTION_ADD_CHILD
public static final java.lang.String ACTION_DELETE
public static final java.lang.String ACTION_START_EDIT
public final java.util.Hashtable m_hashDefaultActionMap
public final java.util.Hashtable m_hashDefaultInputMap
Method Detail |
public static Instrumenter createInstrument(javax.swing.JTree tree, boolean full_instrumentation, boolean clear)
tree
- Tree to instrument. It must already have been
constructed (i.e., null pointer not allowed).full_instrumentation
- If true, will install all instrumentation
features. If false, will install only those essential for the correct
operation of the instrumentation. If set to false, you may want to
install a subset of the full instrumentation. This is accomplished by
calling one or more of the setUseXxxx methods with "true"
as parameter.clear
- If true, will clear the contents of the tree and create a
default root node of type DefaultMutableTreeNode. If false,
will keep any old contents.createInstrument(JTree,boolean)
,
createInstrument(JTree)
,
setUseDefaultKeyboardShortcuts(boolean)
,
setUseDefaultActionMap(boolean)
,
setUseDefaultUndoManager(boolean)
,
#setUseDefaultCellEditor
,
setUseDefaultNodeFactory(boolean)
,
setUseDefaultTreeConfiguration(boolean)
public static Instrumenter createInstrument(javax.swing.JTree tree, boolean full_instrumentation)
createInstrument(JTree,boolean,boolean)
public static Instrumenter createInstrument(javax.swing.JTree tree)
createInstrument(JTree,boolean,boolean)
,
protected void configureCellEditor()
This method tweaks a cell editor so that we can use it. Specifically, we add a CellEditorListener to it so we can handle focus when editing stops.
NOTE that when the cell editor changes, we make no attempt to remove the listener from the old cell editor. This is a potential source of memory leaks.
public void setUseDefaultDnd(boolean b)
Will configure the tree to use the default Drag And Drop implementation. This will work for many applications, and when it does not is is generally easy to make it work. If Drag And Drop is not wanted, however, it may make sense to disable it.
This method is called automatically if you choose full instrumentation in the call to createInstrument.b
- If true, uses our default tree config. If false, does nothing.createInstrument(JTree,boolean,boolean)
public void setUseDefaultTreeConfiguration(boolean b)
Will configure the tree for optimal instrumented operation. If you do not call this method (it is called automatically if you choose full instrumentation in the call to createInstrument), take note of the following;
b
- If true, uses our default tree config. If false, does nothing.createInstrument(JTree,boolean,boolean)
public void setUseDefaultNodeFactory(boolean b)
b
- If true, will use our default node factory. If false, does
nothing.createInstrument(JTree,boolean,boolean)
public void setUseDefaultUndoManager(boolean b)
b
- If true, will call setUndoManager() with a new InfoUndoManager.
If false, does nothing.setUndoManager(javax.swing.undo.UndoManager)
,
InfoUndoManager
,
createInstrument(JTree,boolean,boolean)
public void setUseDefaultKeyboardShortcuts(boolean b)
b
- If true, will install our keyboard shortcuts. If false, removes
them (only really useful if you've installed them previously and don't
want them anymore).createInstrument(JTree,boolean,boolean)
,
setUseDefaultActionMap(boolean)
public void setUseDefaultActionMap(boolean b)
b
- If true, will install our actions. If false, removes
them (only really useful if you've installed them previously and don't
want them anymore).createInstrument(JTree,boolean,boolean)
,
setUseDefaultKeyboardShortcuts(boolean)
public void setNodeFactory(NodeFactory factory)
NodeFactory
public NodeFactory getNodeFactory()
setNodeFactory(org.pvv.bcd.instrument.JTree.NodeFactory)
public void addUndoableEditListener(javax.swing.event.UndoableEditListener listener)
UndoableEdit
public void removeUndoableEditListener(javax.swing.event.UndoableEditListener listener)
UndoableEdit
public javax.swing.undo.UndoManager getUndoManager()
public void setUndoManager(javax.swing.undo.UndoManager manager)
getUndoAction()
,
getRedoAction()
public void purgeUndoBuffer()
setUndoManager(javax.swing.undo.UndoManager)
public void moveNodesUp()
public void moveNodesDown()
public void addNodeAbove() throws VetoException
public void addNodeBelow() throws VetoException
public void addChildNode() throws VetoException
public void moveNode(javax.swing.tree.DefaultMutableTreeNode node_to_move, javax.swing.tree.DefaultMutableTreeNode dest_node, int dest_index) throws VetoException
node_to_move
- Reference to the node to movedest_node
- New parent for the node to movedest_index
- Index within dest_node that node_to_move should end
up inVetoException
- The move was vetoed by one of the veto listenerspublic void makeAncestor()
public void makeChild()
public void addNodes(javax.swing.tree.DefaultMutableTreeNode parent, javax.swing.tree.DefaultMutableTreeNode[] nodes, int parent_index)
parent
- Node to place new nodes withinnodes
- Array of nodes to addparent_index
- Index in parent into which the first node in the
node array will be placed. Each following node in the array will be
placed at the next index.public void deleteSelectedNodes()
#deleteSelection(boolean)
public static javax.swing.tree.TreePath[] reduceSelection(javax.swing.tree.TreePath[] original)
original
- Set of tree nodes to reduce.protected void updateActionObjects()
public DndId getNextDndId()
public void finishDndOperation(long op_id, boolean source)
op_id
- Operation ID of DND operation to finishsource
- Set to true if the source is done handling the DND
operation, false if it is not done.public void doDndCompoundAdd(long op_id, javax.swing.tree.DefaultMutableTreeNode parent, javax.swing.tree.DefaultMutableTreeNode node, int index) throws VetoException
public void doDndCompoundDelete(long op_id, javax.swing.tree.DefaultMutableTreeNode node) throws VetoException
public void cutNode()
#m_arrCopiedNodes
public void copyNode()
#m_arrCopiedNodes
public void pasteNode()
#m_arrCopiedNodes
public void pasteNode(org.pvv.bcd.instrument.JTree.SubTreeNode[] nodes)
nodes
- Nodes to be inserted.pasteNode()
public java.lang.String createFromXml(java.io.InputStream is)
Reads text from the given inputstream, parses it according to infobank.dtd and creates a new tree based upon the information. The existing tree is deleted unconditionally.
Note for this to work, you need to make the JDOM package available in your distribution. Consult http://www.jdom.org for latest releases etc.
is
- Inputstream to read XML fromprotected javax.swing.tree.MutableTreeNode makeNodeFromXMLRecursive(org.jdom.Element xml_elem, boolean is_root)
public void outputXml(java.io.OutputStream os) throws java.io.IOException
Builds an XML representation of the tree, as defined by infobank.dtd. Sends the textual data to the outputstream given.
Note for this to work, you need to make the JDOM package available in your distribution. Consult http://www.jdom.org for latest releases etc.
os
- Outputstrem to send XML toprotected org.jdom.Element makeXMLNodeRecursive(java.lang.Object node, boolean is_root)
public javax.swing.Action getAddAboveAction()
public javax.swing.Action getAddBelowAction()
public javax.swing.Action getAddChildAction()
public javax.swing.Action getDeleteAction()
public javax.swing.Action getMakeAncestorAction()
public javax.swing.Action getMakeChildAction()
public javax.swing.Action getMoveDownAction()
public javax.swing.Action getMoveUpAction()
public javax.swing.Action getUndoAction()
public javax.swing.Action getRedoAction()
public javax.swing.Action getCopyAction()
public javax.swing.Action getCutAction()
public javax.swing.Action getPasteAction()
public javax.swing.Action getStartEditAction()
public static long getNextInstrumentId()
getMyInstrumentId()
public long getMyInstrumentId()
getNextInstrumentId()
public void removeVetoableTreeStructureChangeListener(VetoableTreeStructureChangeListener l)
l
- Listener to removepublic void addVetoableTreeStructureChangeListener(VetoableTreeStructureChangeListener l)
l
- Listener to addprotected void fireNodeCreation(VetoableTreeStructureChangeEvent e) throws VetoException
Event
- to sendVetoException
- if one of the listeners didn't like the change. In
this case, the change should not take place.protected void fireNodeDeletion(VetoableTreeStructureChangeEvent e) throws VetoException
Event
- to sendVetoException
- if one of the listeners didn't like the change. In
this case, the change should not take place.protected void fireNodeMove(VetoableTreeStructureChangeEvent e) throws VetoException
Event
- to sendVetoException
- if one of the listeners didn't like the change. In
this case, the change should not take place.protected void fireNodeRename(VetoableTreeStructureChangeEvent e) throws VetoException
Event
- to sendVetoException
- if one of the listeners didn't like the change. In
this case, the change should not take place.
|
instrument/JTree API Documentation | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |