public abstract class CommandBase extends Object implements Command
DocumentView
.
The prepare(com.xmlmind.xmledit.view.DocumentView, java.lang.String, int, int)
and execute(com.xmlmind.xmledit.view.DocumentView, java.lang.String, int, int)
methods are passed
a DocumentView rather than a mere Gadget
.
Modifier and Type | Field and Description |
---|---|
protected boolean |
recordable |
protected boolean |
repeatable |
Modifier | Constructor and Description |
---|---|
protected |
CommandBase(boolean repeatable,
boolean recordable)
Constructs a command.
|
Modifier and Type | Method and Description |
---|---|
abstract CommandResult |
doExecute(DocumentView docView,
String parameter,
int x,
int y)
Actually executes this command with specified parameter and in
specified context.
|
static CommandResult |
doExecuteByName(DocumentView docView,
String commandName,
String commandParameter,
int x,
int y)
Convenience method: executes specified command by the means
of
doExecute(com.xmlmind.xmledit.view.DocumentView, java.lang.String, int, int) (NOT execute(com.xmlmind.xmledit.view.DocumentView, java.lang.String, int, int) or executeCommand(com.xmlmind.xmledit.gadget.Gadget, java.lang.String, int, int) )
in the context of specified DocumentView. |
CommandResult |
execute(DocumentView docView,
String parameter,
int x,
int y)
This method invokes
doExecute(com.xmlmind.xmledit.view.DocumentView, java.lang.String, int, int) to actually
execute the command. |
CommandResult |
executeCommand(Gadget gadget,
String parameter,
int x,
int y)
|
boolean |
isRecordable()
Returns
true if this command is recordable;
false otherwise. |
boolean |
isRepeatable()
Returns
true if this command is repeatable;
false otherwise. |
abstract boolean |
prepare(DocumentView docView,
String parameter,
int x,
int y)
Tests whether this command can be executed with specified parameter
and in specified context.
|
boolean |
prepareCommand(Gadget gadget,
String parameter,
int x,
int y)
|
protected CommandBase(boolean repeatable, boolean recordable)
repeatable
- true
if this command is repeatable;
false
otherwiserecordable
- true
if this command is recordable;
false
otherwisepublic boolean isRepeatable()
true
if this command is repeatable;
false
otherwise.public boolean isRecordable()
true
if this command is recordable;
false
otherwise.public boolean prepareCommand(Gadget gadget, String parameter, int x, int y)
prepareCommand
in interface Command
gadget
- the target of this commandparameter
- parameterizes the command (that is, modifies the
behavior of the command in a command specific way)x
- X position relative to gadget of the mouse event
having triggered this command; -1 if this command was triggered by a
keyboard inputy
- Y position relative to gadget of the mouse event
having triggered this command; -1 if this command was triggered by a
keyboard inputpublic CommandResult executeCommand(Gadget gadget, String parameter, int x, int y)
executeCommand
in interface Command
gadget
- the target of this commandparameter
- parameterizes the command (that is, modifies the
behavior of the command in a command specific way)x
- X position relative to gadget of the mouse event
having triggered this command; -1 if this command was triggered by a
keyboard inputy
- Y position relative to gadget of the mouse event
having triggered this command; -1 if this command was triggered by a
keyboard inputnull
public abstract boolean prepare(DocumentView docView, String parameter, int x, int y)
If the command can be executed, this method returns
true
after having configured its internal state for
consumption by method execute(com.xmlmind.xmledit.view.DocumentView, java.lang.String, int, int)
which should be invoked
immediately after this one.
Returns false
if this command cannot be executed with
specified parameter and in specified context.
docView
- the target of this commandparameter
- parameterizes the command (that is, modifies the
behavior of the command in a command specific way)x
- X position relative to docView of the mouse event
having triggered this command; -1 if this command was triggered by a
keyboard inputy
- Y position relative to docView of the mouse event
having triggered this command; -1 if this command was triggered by a
keyboard inputpublic CommandResult execute(DocumentView docView, String parameter, int x, int y)
doExecute(com.xmlmind.xmledit.view.DocumentView, java.lang.String, int, int)
to actually
execute the command. It's basically a convenience method which
automatically deals with the command history and
the macro-recorder (if any).
IMPORTANT: a command which executes another command
must always use doExecute(com.xmlmind.xmledit.view.DocumentView, java.lang.String, int, int)
to do so, NOT execute(com.xmlmind.xmledit.view.DocumentView, java.lang.String, int, int)
or
executeCommand(com.xmlmind.xmledit.gadget.Gadget, java.lang.String, int, int)
.
public abstract CommandResult doExecute(DocumentView docView, String parameter, int x, int y)
This method assumes that prepare(com.xmlmind.xmledit.view.DocumentView, java.lang.String, int, int)
has been
successfully invoked immediately before its own invocation.
IMPORTANT: application code which executes a command
must always use execute(com.xmlmind.xmledit.view.DocumentView, java.lang.String, int, int)
or executeCommand(com.xmlmind.xmledit.gadget.Gadget, java.lang.String, int, int)
to do so,
NOT doExecute(com.xmlmind.xmledit.view.DocumentView, java.lang.String, int, int)
. doExecute(com.xmlmind.xmledit.view.DocumentView, java.lang.String, int, int)
is intended to be used
only by commands which invoke helper "sub-commands".
docView
- the target of this commandparameter
- parameterizes the command (that is, modifies the
behavior of the command in a command specific way)x
- X position relative to docView of the mouse event
having triggered this command; -1 if this command was triggered by a
keyboard inputy
- Y position relative to docView of the mouse event
having triggered this command; -1 if this command was triggered by a
keyboard inputnull
.
If the command execution is successful and
the command is repeatable and/or recordable then
CommandResult.details
field of the result is expected
to be one of:
null
Object
String
s
public static CommandResult doExecuteByName(DocumentView docView, String commandName, String commandParameter, int x, int y)
doExecute(com.xmlmind.xmledit.view.DocumentView, java.lang.String, int, int)
(NOT execute(com.xmlmind.xmledit.view.DocumentView, java.lang.String, int, int)
or executeCommand(com.xmlmind.xmledit.gadget.Gadget, java.lang.String, int, int)
)
in the context of specified DocumentView.CommandResult
if specified command
has been executed (whether successfully or not);
null
(NOT a CommandResult
!)
if specified command is unknown or is not a CommandBase
or cannot be executedDocumentView.executeCommandByName(java.lang.String, java.lang.String, int, int)