org.freehep.jas.plugin.tree
Class DefaultFTreeNodeAdapterProxy

java.lang.Object
  extended byorg.freehep.jas.plugin.tree.DefaultFTreeNodeAdapterProxy
All Implemented Interfaces:
FTreeNodeAdapter

public class DefaultFTreeNodeAdapterProxy
extends java.lang.Object
implements FTreeNodeAdapter

A FTreeNodeAdapter define the behaviour of FTreeNodes through its methods. This class is the base class for each node adapter; each node adapter must extend this base class. The methods below provide the default behavior for nodes on FTree and have to be overwritten if a different behavior is desired. A FTreeNodeAdapter has to be registered with the FTree via its method registerFTreeNodeAdapter() by providing a Class. This Class is used to assign the given FTreeNodeAdapter to FTreeNodes by inheritance. So, if an adapter is registered for class A and on the FTree there is a node of type B that inherits from A, the behaviour of the node B will be handled by the adapter registered for class A. At the constructor leven the adapter's priority is specified. This priority is used internally by each method to order the adapters in the case when there are multiple adapters contributing to the behavior of a given node. Depending on the method this ordering can either be from the lower to the higher priority or from the higher to the lower priority. Depending on the method the node's behavior will either be provided by all the adapters in the priority-sorted list or by only one of such adapters. In the first case (like for popup menus) the ordering will be from low to high priority, giving the higher priority adapters a chance to overwrite the lower priority adapters. In the second case (like for double click) the ordering will be from high to low priority and the behavior will be given by only one adapter: the first one in such list that overwrites the default behavior (see the method's documentation for more details).


Constructor Summary
DefaultFTreeNodeAdapterProxy(java.lang.Class clazz)
           
 
Method Summary
 boolean acceptNewText(FTreeNodeTextChangeEvent evt, boolean oldAcceptNewName)
          Invoked when a node's text is being changed to check if the corresponding adapters accept the new text.
 boolean allowsChildren(FTreeNode node, boolean allowsChildren)
          This method is invoked to check if the adapter allows the node to have a substructure.
 boolean canTextBeChanged(FTreeNodeTextChangeEvent evt, boolean oldCanBeRenamed)
          Check if the given node's text can be changed.
 void checkForChildren(FTreeNode node)
          This method is invoked when the FTree needs to know about a given FTreeNode's structure.
 CommandProcessor commandProcessor(FTreeNode[] selectedNodes)
          Invoked after each selection change to get the CommandProcessor for the selected nodes.
 boolean doubleClick(FTreeNode node)
          This method defines the double click behavior of the given node.
 javax.swing.Icon icon(FTreeNode node, javax.swing.Icon oldIcon, boolean selected, boolean expanded)
          Returns the icon of a given node in a given selected/expanded state.
 javax.swing.JPopupMenu modifyPopupMenu(FTreeNode[] nodes, javax.swing.JPopupMenu menu)
          This method is invoked when a popupmenu is to be displayied for a given set of nodes.
 FTreeNodeTransferable modifyTransferable(FTreeNode[] nodes, FTreeNodeTransferable transferable)
          This method is invoked when a Drag and Drop action is initiated on a set of nodes.
 boolean mouseClicked(FTreeNode node, java.awt.event.MouseEvent mouseEvent, java.awt.Dimension dimension)
          This method is invoked every time a mouse click event occurs on the representation of the FTreeNode.
 void nodeBeingDeleted(FTreeNode node)
          Invoked when the given node is being removed from then FTree.
 FTreeNodeStructureProvider nodeStructureProvider(FTreeNode node)
          Get the FTreeNodeStructureProvider for a given node.
 void nodeTextChanged(FTreeNodeTextChangeEvent evt)
          The FTree does not change the text of a node.
 int priority(FTree tree)
          The FTreeNodeAdapter's priority for a given tree.
 boolean selectionChanged(FTreeSelectionEvent e)
          This method is invoked on a node's adapters starting from the highest priority one when the selected nodes have changed.
 java.lang.String statusMessage(FTreeNode node, java.lang.String oldMessage)
          This method is invoked when the status message is to be displayied for a given node.
 java.lang.String text(FTreeNode node, java.lang.String oldText)
          The text to be displayied next to the icon for a given FTreeNode.
 java.lang.String toolTipMessage(FTreeNode node, java.lang.String oldMessage)
          This method is invoked when the tooltip is to be displayied for a given node.
 java.awt.Component treeCellRendererComponent(java.awt.Component component, FTreeNode node, boolean sel, boolean expanded, boolean leaf, boolean hasFocus)
          This method is invoked on all adapters, starting from the lower priority one each time the corresponding FTreeNode is to be rendered in the FTree.
 FTreeNodeObjectProvider treeNodeObjectProvider(FTreeNode node)
          Get the FTreeNodeObjectProvider for a given node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFTreeNodeAdapterProxy

public DefaultFTreeNodeAdapterProxy(java.lang.Class clazz)
Method Detail

icon

public javax.swing.Icon icon(FTreeNode node,
                             javax.swing.Icon oldIcon,
                             boolean selected,
                             boolean expanded)
Description copied from interface: FTreeNodeAdapter
Returns the icon of a given node in a given selected/expanded state. This method will be invoked on all the adapters contributing to the given node from the lower priority one to the higher priority. Each adapter can contribute by either modifying the icon provided by the lower priority adapters, by returning a new icon or by returning null to specify that the defaultIcon should be used. The default is to return the passed icon unchanged. To avoid slowing down the rendering of the FTree the icon for a given node's status is cached after the first time in the corresponding node. So the icon for a given node's status cannot change unless the node's information is reset.

Specified by:
icon in interface FTreeNodeAdapter
Parameters:
node - The FTreeNode for which the icon is to be provided.
oldIcon - The icon as provided by the lower priority adapers. It can never be null.
selected - true if the node is currently selected.
expanded - true if the node is currently expanded.
Returns:
The Icon for the node in the current selecte/expanded state.

doubleClick

public boolean doubleClick(FTreeNode node)
Description copied from interface: FTreeNodeAdapter
This method defines the double click behavior of the given node. The trivial behavior is to do nothing and return false to specify that no behavior is provided. The double click action will be provided by the adapter with the highest priority that returns true. This method is called only for leaves on the FTree. The behavior of folders, when double clicking, cannot be changed.

Specified by:
doubleClick in interface FTreeNodeAdapter
Parameters:
node - The FTreeNode for which the doubleClick action is to be provided.
Returns:
true if a doubleClick behavior is provided. false otherwise.

statusMessage

public java.lang.String statusMessage(FTreeNode node,
                                      java.lang.String oldMessage)
Description copied from interface: FTreeNodeAdapter
This method is invoked when the status message is to be displayied for a given node. This method allows the adapter to control the status message that applications like JAS3 or WIRED display. It is invoked for all the adapters contributing to the given node from the low priority one to the higher priority ones. Each adapter can either modify the passed message (as provided by lower priority adapters), return a new message (overwriting the lower priority adapters) or return null to specify that no message should be displayed (unless a higher priority node will change this). The default is to return the passed message unchanged.

Specified by:
statusMessage in interface FTreeNodeAdapter
Parameters:
node - The FTreeNode for which the status message is to be provided.
oldMessage - The current message as modified by previous adapters. It is never null.
Returns:
The message to be displayied on the status bar. null if no status is to be displayied.
See Also:
{@link FTreeAdapter#toolTipMessage(String) toolTipMessage}

toolTipMessage

public java.lang.String toolTipMessage(FTreeNode node,
                                       java.lang.String oldMessage)
Description copied from interface: FTreeNodeAdapter
This method is invoked when the tooltip is to be displayied for a given node. This method allows the adapter to control the message that will be tooltip. It is invoked for all the adapters contributing to the given node from the low priority one to the higher priority ones. Each adapter can either modify the passed message (as provided by lower priority adapters), return a new message (overwriting the lower priority adapters) or return null to specify that no message should be displayed (unless a higher priority node will change this). The default is to return the statusMessage. To avoid slowing down the rendering of the FTree the tooltip message information is cached after the first time in the corresponding node. So the tooltip message cannot change unless the node's information is reset.

Specified by:
toolTipMessage in interface FTreeNodeAdapter
Parameters:
node - The fTreeNode for which the status message is to be provided.
oldMessage - The current message as modified by previous adapters. It is never null.
Returns:
The message to be displayied on the tooltip. null if no tooltip is to be displayied.
See Also:
{@link FTreeAdapter#statusMessage(String) statusMessage}

text

public java.lang.String text(FTreeNode node,
                             java.lang.String oldText)
Description copied from interface: FTreeNodeAdapter
The text to be displayied next to the icon for a given FTreeNode. By default the node's name will be displayied (i.e. the last part of the node's path in the FTree); alternatively the user can choose to display the text as provided by the adapter. This could be the title of the node's object or any other text. This method allows the adapter to control the text that will be shown. It is invoked for all the adapters contributing to the given node from the low priority one to the higher priority ones. Each adapter can either modify the passed text (as provided by lower priority adapters), return a new text (overwriting the lower priority adapters) or return null to specify that no text is provided. The default is to return the passed text. To avoid slowing down the rendering of the FTree this text information is cached after the first time in the corresponding node. So the text cannot change unless the node's information is reset.

Specified by:
text in interface FTreeNodeAdapter
Parameters:
node - The FTreeNode for which the text shoud be provided.
oldText - The current text as provided by previous adapters. It can be null.
Returns:
The text to be displayied next to the object. null if the name is to be displayied.

allowsChildren

public boolean allowsChildren(FTreeNode node,
                              boolean allowsChildren)
Description copied from interface: FTreeNodeAdapter
This method is invoked to check if the adapter allows the node to have a substructure. It is invoked on all the compatible adapters from the lower to the higher priority. Each adapter has the opportunity to change the behavior of the previous adapter by changing the passed boolean. The default is to returned the passed boolean unchanged.

Specified by:
allowsChildren in interface FTreeNodeAdapter
Parameters:
node - The FTreeNode for which allowsChildren is invoked.
allowsChildren - The returned boolean by the lower priority adapters.
Returns:
true if the node has a substructure.

nodeBeingDeleted

public void nodeBeingDeleted(FTreeNode node)
Description copied from interface: FTreeNodeAdapter
Invoked when the given node is being removed from then FTree. It is invoked on all the compatible adapters going from the higher priority to the lower priority one. The adapter specific underlying substructure should be removed.

Specified by:
nodeBeingDeleted in interface FTreeNodeAdapter
Parameters:
node - The FTreeNode being deleted.

modifyPopupMenu

public javax.swing.JPopupMenu modifyPopupMenu(FTreeNode[] nodes,
                                              javax.swing.JPopupMenu menu)
Description copied from interface: FTreeNodeAdapter
This method is invoked when a popupmenu is to be displayied for a given set of nodes. It is invoked on all the adapters contributing to the given nodes going from the lower priority one to the higher priority ones. This way the higher priority adapters can overwrite the behavior of the lower priority adapters. Each adapter can contribute to the popup menu by adding a menu/menuItem to the passed menu, by returning a new menu or by returning null to specify that no popup menu should be displayied. The menu passed in is never null. The default is to return the passed menu unchanged.

Specified by:
modifyPopupMenu in interface FTreeNodeAdapter
Parameters:
nodes - The array of FTreeNode for which the popup menu is to be provided. The nodes are in the order in which they were selected.
menu - The current menu as it will be popped up if unchanged. It is never null.
Returns:
The menu as it should be popped up. If null no popup menu will be displayied.

modifyTransferable

public FTreeNodeTransferable modifyTransferable(FTreeNode[] nodes,
                                                FTreeNodeTransferable transferable)
Description copied from interface: FTreeNodeAdapter
This method is invoked when a Drag and Drop action is initiated on a set of nodes. It is invoked on all the compatible adapters from the lower priority to the higher priority one. Each node can add data to the FTreeNodeTransferable. The default behavior is to return the passed transferable unchanged.

Specified by:
modifyTransferable in interface FTreeNodeAdapter
Parameters:
nodes - The set of FTreeNode being dragged. The nodes are ordered as they were selected.
transferable - The FTreeNodeTransferable carrying the data of the DnD action.

commandProcessor

public CommandProcessor commandProcessor(FTreeNode[] selectedNodes)
Description copied from interface: FTreeNodeAdapter
Invoked after each selection change to get the CommandProcessor for the selected nodes. The defult is to return null to specify that no CommandProcessor is provided. All the compatible adapters will be invoked and each non null CommandProcessor will be installed. The state of the commands provided by the CommandProcessor usually depends on the selected nodes. The utility method selectedNodes() should be used within this method to get the list of the selected FTreeNodes. Such list is not provided as an argument to this method to avoid each adapter having to store such list.

Specified by:
commandProcessor in interface FTreeNodeAdapter
Returns:
The corresponding CommandProcessor.

canTextBeChanged

public boolean canTextBeChanged(FTreeNodeTextChangeEvent evt,
                                boolean oldCanBeRenamed)
Description copied from interface: FTreeNodeAdapter
Check if the given node's text can be changed. The showing text can either be the node's name or the text provided by a node adapter. This method is invoked from the lower priority to the higher priority nodes. The higher priority nodes can overwrite the behavior of the lower priority nodes by changing the given result of earlier invocations. The default is to return the given result unchanged. By default it is assumed that the node's text cannot be changed.

Specified by:
canTextBeChanged in interface FTreeNodeAdapter
Parameters:
evt - The FTreeNodeTextChangeEvent containing the information for this change of text.
oldCanBeRenamed - The result as given by lower priority adapters.
Returns:
true if the name of this node can be changed.

acceptNewText

public boolean acceptNewText(FTreeNodeTextChangeEvent evt,
                             boolean oldAcceptNewName)
Description copied from interface: FTreeNodeAdapter
Invoked when a node's text is being changed to check if the corresponding adapters accept the new text. This method is invoked from the lower priority to the higher priority adapters. The result from the invocation of lower priority adapters is provided. The default is to return the provided result unchanged.

Specified by:
acceptNewText in interface FTreeNodeAdapter
Parameters:
evt - The FTreeNodeTextChangeEvent containing the information for this change of text.
oldAcceptNewName - The result of lower priority adapters.
Returns:
true if the new name has been accepted.

nodeTextChanged

public void nodeTextChanged(FTreeNodeTextChangeEvent evt)
Description copied from interface: FTreeNodeAdapter
The FTree does not change the text of a node. The change of the text has to be performed by the adapter responsible for the text being changed. This method is invoked from the higher priority adapter to the lower ones. The adapter responsible for changing the node's text should consume the event by invoking the consume() method. This will end the propagation of the event to lower priority adapters.

Specified by:
nodeTextChanged in interface FTreeNodeAdapter
Parameters:
evt - The FTreeNodeTextChangeEvent containing the information of the text change.

priority

public int priority(FTree tree)
Description copied from interface: FTreeNodeAdapter
The FTreeNodeAdapter's priority for a given tree. This method is used by the FTreeLookupAdapter create a sorted list of FTreeNodeAdapters.

Specified by:
priority in interface FTreeNodeAdapter
Parameters:
tree - The FTree on which the adapter will act.
Returns:
The adapter's priority.

checkForChildren

public void checkForChildren(FTreeNode node)
Description copied from interface: FTreeNodeAdapter
This method is invoked when the FTree needs to know about a given FTreeNode's structure. This method is invoked only once, unless the FTreeNode's information is reset. This is the place where an adapter should add the node's structure by notifying the FTree.

Specified by:
checkForChildren in interface FTreeNodeAdapter
Parameters:
node - The FTreeNode for which the sub-structure is being requested.

selectionChanged

public boolean selectionChanged(FTreeSelectionEvent e)
Description copied from interface: FTreeNodeAdapter
This method is invoked on a node's adapters starting from the highest priority one when the selected nodes have changed. The default selection behaviour is to cancel any existing selection, effectively reducing the tree to a SINGLE_SELECTION_MODEL. This method is to be overwritten if a more sophisticated selection handling is required, in which case true should be returned.

Specified by:
selectionChanged in interface FTreeNodeAdapter
Parameters:
e - The FTreeSelectionEvent containing the information of the selection change.
Returns:
true if selection behavior, other than the default one, is provided. false otherwise.

treeCellRendererComponent

public java.awt.Component treeCellRendererComponent(java.awt.Component component,
                                                    FTreeNode node,
                                                    boolean sel,
                                                    boolean expanded,
                                                    boolean leaf,
                                                    boolean hasFocus)
Description copied from interface: FTreeNodeAdapter
This method is invoked on all adapters, starting from the lower priority one each time the corresponding FTreeNode is to be rendered in the FTree. This method should be used to modify the way the FTreeNode appears in the tree. Consider that the icon and the text already have dedicated methods.

Specified by:
treeCellRendererComponent in interface FTreeNodeAdapter
Parameters:
component - The FTreeNode's renderer as provided by lower priority adapters.
node - The FTreeNode for which the rendering is taking place.
sel - true if the node is selected.
expanded - true if the node is expanded.
leaf - true if the node is a leaf.
hasFocus - true if the node has focus.
Returns:
The Component that will render the FTreeNode in the FTree.

mouseClicked

public boolean mouseClicked(FTreeNode node,
                            java.awt.event.MouseEvent mouseEvent,
                            java.awt.Dimension dimension)
Description copied from interface: FTreeNodeAdapter
This method is invoked every time a mouse click event occurs on the representation of the FTreeNode. It is invoked starting from the highest priority adapter, stopping when the first one with a non-trivial behavior is found, i.e. the first one returning true.

Specified by:
mouseClicked in interface FTreeNodeAdapter
Parameters:
node - The FTreeNode on which the mouse has been clicked.
mouseEvent - The MouseEvent describing the click.
dimension - The location of the click in the FTreeNode's interal representation.
Returns:
true if a non trivial behavior is provided.

treeNodeObjectProvider

public FTreeNodeObjectProvider treeNodeObjectProvider(FTreeNode node)
Description copied from interface: FTreeNodeAdapter
Get the FTreeNodeObjectProvider for a given node. The FTreeNodeObjectProvider is used to provide the objects when the FTreeNode's method objectForClass() is invoked.

Specified by:
treeNodeObjectProvider in interface FTreeNodeAdapter
Parameters:
node - The FTreeNode for which the object provider is to be returned.
Returns:
The FTreeNodeObjectProvider for this adapter. If the adapater does not provide objects, null is to be returned (the default).

nodeStructureProvider

public FTreeNodeStructureProvider nodeStructureProvider(FTreeNode node)
Description copied from interface: FTreeNodeAdapter
Get the FTreeNodeStructureProvider for a given node. This method is to be overwritten by adapters that provide a non-default node structure. This method is invoked from the highest priority adapter to the lower ones. The first non-null structure provider is used.

Specified by:
nodeStructureProvider in interface FTreeNodeAdapter
Parameters:
node - The FTreeNode for which the FTreeNodeStructureProvider is requested.
Returns:
The FTreeNodeStructureProvider for the given node.