freemind.modes
Class ControllerAdapter

java.lang.Object
  extended by freemind.modes.ControllerAdapter
All Implemented Interfaces:
TextTranslator, ModeController
Direct Known Subclasses:
MindMapController, ViewControllerAdapter

public abstract class ControllerAdapter
extends java.lang.Object
implements ModeController

Derive from this class to implement the Controller for your mode. Overload the methods you need for your data model, or use the defaults. There are some default Actions you may want to use for easy editing of your model. Take MindMapController as a sample.


Nested Class Summary
protected  class ControllerAdapter.EditAttributesAction
           
protected  class ControllerAdapter.FileOpener
           
protected  class ControllerAdapter.nodesDepthComparator
          This class sortes nodes by ascending depth of their paths to root.
 class ControllerAdapter.OpenAction
           
 class ControllerAdapter.SaveAction
           
 class ControllerAdapter.SaveAsAction
           
 
Nested classes/interfaces inherited from interface freemind.modes.ModeController
ModeController.NodeLifetimeListener, ModeController.NodeSelectionListener
 
Field Summary
protected  freemind.modes.ControllerAdapter.ControllerPopupMenuListener popupListenerSingleton
          Take care!
 
Fields inherited from interface freemind.modes.ModeController
NODESEPARATOR
 
Constructor Summary
ControllerAdapter(Mode mode)
          Instanciation order: first me and then the model.
 
Method Summary
 void _setFolded(MindMapNode node, boolean folded)
          Don't call me directly!!!
protected  void add(javax.swing.JMenu menu, javax.swing.Action action)
           
protected  javax.swing.JMenuItem add(javax.swing.JMenu menu, javax.swing.Action action, java.lang.String keystroke)
           
protected  javax.swing.JMenuItem add(StructuredMenuHolder holder, java.lang.String category, javax.swing.Action action, java.lang.String keystroke)
           
protected  javax.swing.JMenuItem addCheckBox(StructuredMenuHolder holder, java.lang.String category, javax.swing.Action action, java.lang.String keystroke)
           
protected  javax.swing.JMenuItem addRadioItem(StructuredMenuHolder holder, java.lang.String category, javax.swing.Action action, java.lang.String keystroke, boolean isSelected)
           
 void centerNode(MindMapNode node)
          Node is displayed and selected as the only one selected.
 boolean close(boolean force, MapModuleManager mapModuleManager)
          Return false if user has canceled.
 java.awt.datatransfer.Transferable copy()
           
 java.awt.datatransfer.Transferable copy(java.util.List selectedNodes, boolean copyInvisible)
           
 java.awt.datatransfer.Transferable copy(MindMapNode node, boolean saveInvisible)
           
 java.awt.datatransfer.Transferable copySingle()
           
 java.lang.String createForNodesFlavor(java.util.List selectedNodes, boolean copyInvisible)
           
 MindMapNode createNodeTreeFromXml(java.io.Reader pReader)
          Given a valid Xml parameterization of a node (tree), this method returns freshly created nodes.
abstract  XMLElement createXMLElement()
           
 void deregisterNodeLifetimeListener(ModeController.NodeLifetimeListener listener)
           
 void deregisterNodeSelectionListener(ModeController.NodeSelectionListener listener)
           
 void displayNode(MindMapNode node)
          Unfolds a node if necessary.
 void displayNode(MindMapNode node, java.util.ArrayList nodesUnfoldedByDisplay)
          Display a node in the display (used by find and the goto action by arrow link actions).
 void fireNodePostDeleteEvent(MindMapNode node, MindMapNode parent)
           
 void fireNodePreDeleteEvent(MindMapNode node)
          Is issued before a node is deleted.
 void firePreSaveEvent(MindMapNode node)
          Is issued before a node is saved (eg. to save its notes, too, even if the notes is currently edited).
 void fireRecursiveNodeCreateEvent(MindMapNode node)
           
 AttributeController getAttributeController()
           
 Controller getController()
           
protected  javax.swing.JFileChooser getFileChooser()
           
 javax.swing.JFileChooser getFileChooser(javax.swing.filechooser.FileFilter filter)
          Creates a file chooser with the last selected directory as default.
protected  javax.swing.filechooser.FileFilter getFileFilter()
          You may want to implement this...
 FreeMindMain getFrame()
           
 java.io.File getLastCurrentDir()
          If other places want to save/load something, this should be the default path.
 java.awt.Component getLeftToolBar()
          Overwrite this, if you have one.
 java.lang.String getLinkShortText(MindMapNode node)
           
 MindMap getMap()
           
 Mode getMode()
           
 ControllerAdapter getModeController()
          This was inserted by fc, 10.03.04 to enable all actions to refer to its controller easily.
 MapAdapter getModel()
           
 javax.swing.JToolBar getModeToolBar()
          Overwrite this, if you have one.
 NodeAdapter getNodeFromID(java.lang.String nodeID)
          Given a node identifier, this method returns the corresponding node.
 java.lang.String getNodeID(MindMapNode selected)
          Calling this method the map-unique identifier of the node is returned (and created before, if not present)
 java.util.HashSet getNodeLifetimeListeners()
           
 NodeView getNodeView(MindMapNode node)
           
 javax.swing.JPopupMenu getPopupForModel(java.lang.Object obj)
          Default implementation: no context menu.
 java.util.Set getRegisteredMouseWheelEventHandler()
           
 java.net.URL getResource(java.lang.String name)
           
 MindMapNode getRootNode()
           
 MindMapNode getSelected()
           
 java.util.List getSelecteds()
          fc, 24.1.2004: having two methods getSelecteds with different return values (linkedlists of models resp. views) is asking for trouble.
 java.util.List getSelectedsByDepth()
           
 NodeView getSelectedView()
           
 java.awt.Color getSelectionColor()
           
 java.lang.String getText(java.lang.String textId)
          Get text from resource file
 MapView getView()
           
 void handleLoadingException(java.lang.Exception ex)
           
 void insertNodeInto(MindMapNode newChild, MindMapNode parent)
           
 void insertNodeInto(MindMapNode newNode, MindMapNode parent, int index)
           
 void invokeHooksRecursively(NodeAdapter node, MindMap map)
           
 boolean isBlocked()
           
 ModeController load(java.net.URL file)
          You may decide to overload this or take the default and implement the functionality in your MapModel (implements MindMap)
 void loadURL()
           
 void loadURL(java.lang.String relative)
          Opens a link in * the opened map * another map * another file.
 MindMap newMap()
           
 void newMap(MindMap mapModel)
           
 MapAdapter newModel(ModeController modeController)
          You _must_ implement this if you use one of the following actions: OpenAction, NewMapAction.
abstract  MindMapNode newNode(java.lang.Object userObject, MindMap map)
           
 void nodeChanged(MindMapNode node)
          Currently, this method is called by the mapAdapter.
 void nodeRefresh(MindMapNode node)
           
 void nodeStructureChanged(MindMapNode node)
           
 void onDeselectHook(NodeView node)
          Is called when a node is deselected.
 void onSelectHook(NodeView node)
          Is called when a node is selected.
 void onViewCreatedHook(NodeView node)
           
 void onViewRemovedHook(NodeView node)
           
 void open()
           
 void refreshMap()
           
 void refreshMapFrom(MindMapNode node)
           
 void registerNodeLifetimeListener(ModeController.NodeLifetimeListener listener)
          The onCreateNodeHook is called for every node (depest nodes first) after registration.
 void registerNodeSelectionListener(ModeController.NodeSelectionListener listener)
           
 boolean save()
           
 boolean save(java.io.File file)
          Return false is the action was cancelled, e.g. when it has to lead to saving as.
 boolean saveAs()
          Save as; return false is the action was cancelled
 void select(NodeView node)
          Single selection: the node is the only one selected after calling this method.
protected  void setAllActions(boolean enabled)
          Overwrite this to set all of your actions which are dependent on whether there is a map or not.
 void setBlocked(boolean isBlocked)
           
 void setLastCurrentDir(java.io.File pLastCurrentDir)
          If some load/save operation has changed the path, it should be mentioned here.
protected  void setMode(Mode mode)
           
 void setModel(MapAdapter model)
          This method must only be used by the model itself at creation time.
 void setVisible(boolean visible)
          This method is used to hide the map "under" another opened map.
 void showPopupMenu(java.awt.event.MouseEvent e)
           
 void shutdownController()
           
 void sortNodesByDepth(java.util.List inPlaceList)
          nodes with greater depth occur first.
 void startupController()
          This method is called after and before a change of the map module.
protected  void updateMapModuleName()
           
protected  void updateNode(MindMapNode node)
          Overwrite this method to perform additional operations to an node update.
 void updatePopupMenu(StructuredMenuHolder holder)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface freemind.modes.ModeController
doubleClick, extendSelection, getHookFactory, getPopupMenu, plainClick, setFolded, updateMenus
 

Field Detail

popupListenerSingleton

protected final freemind.modes.ControllerAdapter.ControllerPopupMenuListener popupListenerSingleton
Take care! This listener is also used for modelpopups (as for graphical links).

Constructor Detail

ControllerAdapter

public ControllerAdapter(Mode mode)
Instanciation order: first me and then the model.

Method Detail

setModel

public void setModel(MapAdapter model)
Description copied from interface: ModeController
This method must only be used by the model itself at creation time. Don't use this method.

Specified by:
setModel in interface ModeController

newNode

public abstract MindMapNode newNode(java.lang.Object userObject,
                                    MindMap map)

createXMLElement

public abstract XMLElement createXMLElement()

newModel

public MapAdapter newModel(ModeController modeController)
You _must_ implement this if you use one of the following actions: OpenAction, NewMapAction.

Parameters:
modeController - TODO

getFileFilter

protected javax.swing.filechooser.FileFilter getFileFilter()
You may want to implement this... It returns the FileFilter that is used by the open() and save() JFileChoosers.


nodeChanged

public void nodeChanged(MindMapNode node)
Currently, this method is called by the mapAdapter. This is buggy, and is to be changed.

Specified by:
nodeChanged in interface ModeController

nodeRefresh

public void nodeRefresh(MindMapNode node)
Specified by:
nodeRefresh in interface ModeController

refreshMap

public void refreshMap()
Specified by:
refreshMap in interface ModeController

refreshMapFrom

public void refreshMapFrom(MindMapNode node)

nodeStructureChanged

public void nodeStructureChanged(MindMapNode node)

updateNode

protected void updateNode(MindMapNode node)
Overwrite this method to perform additional operations to an node update.


onSelectHook

public void onSelectHook(NodeView node)
Description copied from interface: ModeController
Is called when a node is selected.

Specified by:
onSelectHook in interface ModeController

onDeselectHook

public void onDeselectHook(NodeView node)
Description copied from interface: ModeController
Is called when a node is deselected.

Specified by:
onDeselectHook in interface ModeController

onViewCreatedHook

public void onViewCreatedHook(NodeView node)
Specified by:
onViewCreatedHook in interface ModeController

onViewRemovedHook

public void onViewRemovedHook(NodeView node)
Specified by:
onViewRemovedHook in interface ModeController

registerNodeSelectionListener

public void registerNodeSelectionListener(ModeController.NodeSelectionListener listener)
Specified by:
registerNodeSelectionListener in interface ModeController

deregisterNodeSelectionListener

public void deregisterNodeSelectionListener(ModeController.NodeSelectionListener listener)
Specified by:
deregisterNodeSelectionListener in interface ModeController

registerNodeLifetimeListener

public void registerNodeLifetimeListener(ModeController.NodeLifetimeListener listener)
Description copied from interface: ModeController
The onCreateNodeHook is called for every node (depest nodes first) after registration.

Specified by:
registerNodeLifetimeListener in interface ModeController

deregisterNodeLifetimeListener

public void deregisterNodeLifetimeListener(ModeController.NodeLifetimeListener listener)
Specified by:
deregisterNodeLifetimeListener in interface ModeController

getNodeLifetimeListeners

public java.util.HashSet getNodeLifetimeListeners()

fireNodePreDeleteEvent

public void fireNodePreDeleteEvent(MindMapNode node)
Description copied from interface: ModeController
Is issued before a node is deleted. It is issued via NodeLifetimeListener.

Specified by:
fireNodePreDeleteEvent in interface ModeController

fireNodePostDeleteEvent

public void fireNodePostDeleteEvent(MindMapNode node,
                                    MindMapNode parent)

fireRecursiveNodeCreateEvent

public void fireRecursiveNodeCreateEvent(MindMapNode node)

firePreSaveEvent

public void firePreSaveEvent(MindMapNode node)
Description copied from interface: ModeController
Is issued before a node is saved (eg. to save its notes, too, even if the notes is currently edited). It is issued via NodeSelectionListener.

Specified by:
firePreSaveEvent in interface ModeController

getText

public java.lang.String getText(java.lang.String textId)
Description copied from interface: ModeController
Get text from resource file

Specified by:
getText in interface TextTranslator
Specified by:
getText in interface ModeController

newMap

public MindMap newMap()
Specified by:
newMap in interface ModeController

newMap

public void newMap(MindMap mapModel)

load

public ModeController load(java.net.URL file)
                    throws java.io.FileNotFoundException,
                           java.io.IOException,
                           XMLParseException,
                           java.net.URISyntaxException
You may decide to overload this or take the default and implement the functionality in your MapModel (implements MindMap)

Specified by:
load in interface ModeController
Parameters:
file - Nowadays this is an URL to unify the behaviour of the browser and the other modes.
Returns:
returns the new mode controller created for this url.
Throws:
java.io.FileNotFoundException
java.io.IOException
XMLParseException
java.net.URISyntaxException

save

public boolean save()
Specified by:
save in interface ModeController
Returns:
true, if successfully saved. False, if canceled or exception.

loadURL

public void loadURL(java.lang.String relative)
Description copied from interface: ModeController
Opens a link in * the opened map * another map * another file.

Specified by:
loadURL in interface ModeController

createNodeTreeFromXml

public MindMapNode createNodeTreeFromXml(java.io.Reader pReader)
                                  throws XMLParseException,
                                         java.io.IOException
Description copied from interface: ModeController
Given a valid Xml parameterization of a node (tree), this method returns freshly created nodes.

Specified by:
createNodeTreeFromXml in interface ModeController
Throws:
XMLParseException
java.io.IOException

invokeHooksRecursively

public void invokeHooksRecursively(NodeAdapter node,
                                   MindMap map)

getSelecteds

public java.util.List getSelecteds()
fc, 24.1.2004: having two methods getSelecteds with different return values (linkedlists of models resp. views) is asking for trouble. @see MapView

Specified by:
getSelecteds in interface ModeController
Returns:
returns a list of MindMapNode s.

select

public void select(NodeView node)
Description copied from interface: ModeController
Single selection: the node is the only one selected after calling this method.

Specified by:
select in interface ModeController

getSelectedsByDepth

public java.util.List getSelectedsByDepth()
Specified by:
getSelectedsByDepth in interface ModeController
Returns:
a LinkedList of MindMapNodes ordered by depth. nodes with greater depth occur first.

sortNodesByDepth

public void sortNodesByDepth(java.util.List inPlaceList)
Description copied from interface: ModeController
nodes with greater depth occur first.

Specified by:
sortNodesByDepth in interface ModeController
Parameters:
inPlaceList - the given list is sorted by reference.

save

public boolean save(java.io.File file)
Return false is the action was cancelled, e.g. when it has to lead to saving as.

Specified by:
save in interface ModeController

add

protected javax.swing.JMenuItem add(javax.swing.JMenu menu,
                                    javax.swing.Action action,
                                    java.lang.String keystroke)
Returns:
returns the new JMenuItem.

add

protected javax.swing.JMenuItem add(StructuredMenuHolder holder,
                                    java.lang.String category,
                                    javax.swing.Action action,
                                    java.lang.String keystroke)
Parameters:
keystroke - can be null, if no keystroke should be assigned.
Returns:
returns the new JMenuItem.

addCheckBox

protected javax.swing.JMenuItem addCheckBox(StructuredMenuHolder holder,
                                            java.lang.String category,
                                            javax.swing.Action action,
                                            java.lang.String keystroke)
Parameters:
keystroke - can be null, if no keystroke should be assigned.
Returns:
returns the new JCheckBoxMenuItem.

addRadioItem

protected javax.swing.JMenuItem addRadioItem(StructuredMenuHolder holder,
                                             java.lang.String category,
                                             javax.swing.Action action,
                                             java.lang.String keystroke,
                                             boolean isSelected)

add

protected void add(javax.swing.JMenu menu,
                   javax.swing.Action action)

open

public void open()
Specified by:
open in interface ModeController

getFileChooser

public javax.swing.JFileChooser getFileChooser(javax.swing.filechooser.FileFilter filter)
Creates a file chooser with the last selected directory as default.

Specified by:
getFileChooser in interface ModeController

getFileChooser

protected javax.swing.JFileChooser getFileChooser()

handleLoadingException

public void handleLoadingException(java.lang.Exception ex)

saveAs

public boolean saveAs()
Save as; return false is the action was cancelled

Specified by:
saveAs in interface ModeController

close

public boolean close(boolean force,
                     MapModuleManager mapModuleManager)
Return false if user has canceled.

Specified by:
close in interface ModeController

setVisible

public void setVisible(boolean visible)
Description copied from interface: ModeController
This method is used to hide the map "under" another opened map. In fact, should remove the focus, stop plugins, if necessary, etc.

Specified by:
setVisible in interface ModeController

setAllActions

protected void setAllActions(boolean enabled)
Overwrite this to set all of your actions which are dependent on whether there is a map or not.


showPopupMenu

public void showPopupMenu(java.awt.event.MouseEvent e)
Specified by:
showPopupMenu in interface ModeController

getPopupForModel

public javax.swing.JPopupMenu getPopupForModel(java.lang.Object obj)
Default implementation: no context menu.

Specified by:
getPopupForModel in interface ModeController

getLeftToolBar

public java.awt.Component getLeftToolBar()
Overwrite this, if you have one.

Specified by:
getLeftToolBar in interface ModeController

getModeToolBar

public javax.swing.JToolBar getModeToolBar()
Overwrite this, if you have one.

Specified by:
getModeToolBar in interface ModeController

isBlocked

public boolean isBlocked()
Specified by:
isBlocked in interface ModeController

setBlocked

public void setBlocked(boolean isBlocked)

getMode

public Mode getMode()
Specified by:
getMode in interface ModeController

setMode

protected void setMode(Mode mode)

getMap

public MindMap getMap()
Specified by:
getMap in interface ModeController

getRootNode

public MindMapNode getRootNode()

getResource

public java.net.URL getResource(java.lang.String name)
Specified by:
getResource in interface ModeController

getController

public Controller getController()
Specified by:
getController in interface ModeController

getFrame

public FreeMindMain getFrame()
Specified by:
getFrame in interface ModeController

getModeController

public ControllerAdapter getModeController()
This was inserted by fc, 10.03.04 to enable all actions to refer to its controller easily.


getModel

public MapAdapter getModel()

getView

public MapView getView()
Specified by:
getView in interface ModeController

updateMapModuleName

protected void updateMapModuleName()

getNodeFromID

public NodeAdapter getNodeFromID(java.lang.String nodeID)
Description copied from interface: ModeController
Given a node identifier, this method returns the corresponding node.

Specified by:
getNodeFromID in interface ModeController

getNodeID

public java.lang.String getNodeID(MindMapNode selected)
Description copied from interface: ModeController
Calling this method the map-unique identifier of the node is returned (and created before, if not present)

Specified by:
getNodeID in interface ModeController

getSelected

public MindMapNode getSelected()
Specified by:
getSelected in interface ModeController

getSelectedView

public NodeView getSelectedView()
Specified by:
getSelectedView in interface ModeController

copy

public java.awt.datatransfer.Transferable copy(MindMapNode node,
                                               boolean saveInvisible)
Specified by:
copy in interface ModeController

copy

public java.awt.datatransfer.Transferable copy()
Specified by:
copy in interface ModeController

copySingle

public java.awt.datatransfer.Transferable copySingle()
Specified by:
copySingle in interface ModeController

copy

public java.awt.datatransfer.Transferable copy(java.util.List selectedNodes,
                                               boolean copyInvisible)
Specified by:
copy in interface ModeController

createForNodesFlavor

public java.lang.String createForNodesFlavor(java.util.List selectedNodes,
                                             boolean copyInvisible)
                                      throws java.awt.datatransfer.UnsupportedFlavorException,
                                             java.io.IOException
Throws:
java.awt.datatransfer.UnsupportedFlavorException
java.io.IOException

getSelectionColor

public java.awt.Color getSelectionColor()
Specified by:
getSelectionColor in interface ModeController

updatePopupMenu

public void updatePopupMenu(StructuredMenuHolder holder)
Specified by:
updatePopupMenu in interface ModeController

shutdownController

public void shutdownController()
Specified by:
shutdownController in interface ModeController

startupController

public void startupController()
This method is called after and before a change of the map module. Use it to perform the actions that cannot be performed at creation time.

Specified by:
startupController in interface ModeController

_setFolded

public void _setFolded(MindMapNode node,
                       boolean folded)
Don't call me directly!!! The basic folding method. Without undo.


getLinkShortText

public java.lang.String getLinkShortText(MindMapNode node)
Specified by:
getLinkShortText in interface ModeController

displayNode

public void displayNode(MindMapNode node)
Description copied from interface: ModeController
Unfolds a node if necessary.

Specified by:
displayNode in interface ModeController

displayNode

public void displayNode(MindMapNode node,
                        java.util.ArrayList nodesUnfoldedByDisplay)
Display a node in the display (used by find and the goto action by arrow link actions).


centerNode

public void centerNode(MindMapNode node)
Description copied from interface: ModeController
Node is displayed and selected as the only one selected. It is moved to the center of the screen.

Specified by:
centerNode in interface ModeController

getLastCurrentDir

public java.io.File getLastCurrentDir()
Description copied from interface: ModeController
If other places want to save/load something, this should be the default path.

Specified by:
getLastCurrentDir in interface ModeController

setLastCurrentDir

public void setLastCurrentDir(java.io.File pLastCurrentDir)
Description copied from interface: ModeController
If some load/save operation has changed the path, it should be mentioned here.

Specified by:
setLastCurrentDir in interface ModeController

getAttributeController

public AttributeController getAttributeController()
Specified by:
getAttributeController in interface ModeController

getNodeView

public NodeView getNodeView(MindMapNode node)
Specified by:
getNodeView in interface ModeController

insertNodeInto

public void insertNodeInto(MindMapNode newNode,
                           MindMapNode parent,
                           int index)

insertNodeInto

public void insertNodeInto(MindMapNode newChild,
                           MindMapNode parent)

loadURL

public void loadURL()

getRegisteredMouseWheelEventHandler

public java.util.Set getRegisteredMouseWheelEventHandler()