|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ix.iface.util.ToolController
public abstract class ToolController
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(...); } });
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 |
---|
protected java.lang.String toolName
protected java.lang.Object tool
Constructor Detail |
---|
protected ToolController()
public ToolController(java.lang.String toolName)
Method Detail |
---|
public java.lang.String getToolName()
protected abstract java.lang.Object createTool()
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 ToolManager
s and separate ToolControllers
for the same tool object, but at most one of those controllers
should construct a new tool object.
public java.lang.Object getTool()
null
.
public java.lang.Object ensureTool()
setTool()
if the
tool has not already been created.
public java.lang.Object ensureToolVisible()
ensureTool()
and setToolVisible(boolean)
with argument
true
.
public void setTool()
createTool()
and records the result so that
it will be returned by subsequent calls to getTool()
.
public void setToolVisible(boolean t)
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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |