ix.iface.util
Class ToolController

java.lang.Object
  extended by ix.iface.util.ToolController
Direct Known Subclasses:
AppletCommunicationTool.Controller, Ip2Example.ExampleToolController, IServeCommTool.Controller

public abstract class ToolController
extends java.lang.Object

An object used to manage a "tool" -- a utility usually reached via the "Tools" menu of an I-X agent's user interface.

ToolController provides reasonable defaults for most methods. Normally, a subclass needs to define only the createTool() method. However, if the tool object lacks a setVisible(boolean) method, setToolVisible(boolean) must also be defined. A typical use is therefore something like this:

    ToolManager toolManager = new ToolManager();
    ...
    toolManager.addTool(new ToolController("XML Editor") {
        public Object createTool() {
            return new XMLTreeEditorFrame(...);
        }
    });
 

See Also:
ToolManager

Field Summary
protected  java.lang.Object tool
           
protected  java.lang.String toolName
           
 
Constructor Summary
protected ToolController()
           
  ToolController(java.lang.String toolName)
           
 
Method Summary
protected abstract  java.lang.Object createTool()
          Consturucts the tool when it does not already exist.
 java.lang.Object ensureTool()
          Returns the tool after calling setTool() if the tool has not already been created.
 java.lang.Object ensureToolVisible()
          Returns the tool after calling ensureTool() and setToolVisible(boolean) with argument true.
 java.lang.Object getTool()
          Returns the tool object if it exists, otherwise null.
 java.lang.String getToolName()
          Returns a string that can be used to identify the tool in a menu or in other lookup mechanisms.
 void setTool()
          Calls createTool() and records the result so that it will be returned by subsequent calls to getTool().
 void setToolVisible(boolean t)
          Causes the tool to be visible or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

toolName

protected java.lang.String toolName

tool

protected java.lang.Object tool
Constructor Detail

ToolController

protected ToolController()

ToolController

public ToolController(java.lang.String toolName)
Method Detail

getToolName

public java.lang.String getToolName()
Returns a string that can be used to identify the tool in a menu or in other lookup mechanisms.


createTool

protected abstract java.lang.Object createTool()
Consturucts the tool when it does not already exist.

This method should be called only if the getTool() method returns null, and it should not normally be called directly. Call setTool() instead, or use a method that calls setTool(), such as ensureTool().

That ensures that createTool is called only once per ToolController and that the controller remembers the tool so that getTool() can return it. Note, however, that it is not strictly necessary for createTool to construct a new object. In some cases, it might return an existing object that has not yet been made known to this ToolController. For example, if two different frames share a tool, they would have separate ToolManagers and separate ToolControllers for the same tool object, but at most one of those controllers should construct a new tool object.


getTool

public java.lang.Object getTool()
Returns the tool object if it exists, otherwise null.


ensureTool

public java.lang.Object ensureTool()
Returns the tool after calling setTool() if the tool has not already been created.


ensureToolVisible

public java.lang.Object ensureToolVisible()
Returns the tool after calling ensureTool() and setToolVisible(boolean) with argument true.


setTool

public void setTool()
Calls createTool() and records the result so that it will be returned by subsequent calls to getTool().


setToolVisible

public void setToolVisible(boolean t)
Causes the tool to be visible or not. For example, if the tool object is or contains a frame, this method might call the setVisible method of that frame.

The method provided by the ToolController class uses reflection to call the tool object's setVisible(boolean) method, if it has one. If it doesn't, an UnsupportedOperationException is thrown.