mesquite.lib
Class CommandChecker

java.lang.Object
  extended bymesquite.lib.CommandChecker

public class CommandChecker
extends java.lang.Object

An object designed primarily to allow Mesquite, at startup, to harvest a list of available commands. In its default mode, it is nothing but a string comparer (using equalsIgnoresCase or startsWidth), in that its 'compare' and 'compareStart' methods are used in the doCommand methods of Commandable objects to see what command was passed (it is also used in Puppeteer's sendCommands method). However, when in accumulateMode, a CommandChecker always returns false to the query of whether the strings are the same, but in the process accumulates information on what commands are being sought by the Commandable. This means that one call to the doCommand method of the Commandable, passing an accumulating checker, will cause the checker to acquire a list of all the commands sought by the commandable. This system was designed so that the available commands would be harvested automatically at startup, and wouldn't depend on the programmer keeping a separate manual page of commands up to date.


Field Summary
static CommandChecker defaultChecker
           
static boolean documentationComposed
           
static java.util.Vector registeredClasses
           
static java.util.Vector representingClasses
           
 
Constructor Summary
CommandChecker()
           
 
Method Summary
static CommandChecker accumulate(Commandable c, CommandChecker checker)
          Accumulates (menus and ) commands from the given commandable and passes back a vector of strings describing the (menus and ) commands.
 void accumulateOnlyFrom(java.lang.Class c)
          Sets what exact class the checker is to accumulate commands from (will not accumulate from super or subclasses).
 void addString(java.lang.String s)
          Adds a string to the vector of strings being accumulated by the checker.
static java.util.Vector commandsFromRegisteredClasses()
          Returns a vector of strings showing the classes that were registered with registerClass and their available commands.
 boolean compare(java.lang.Class classCommanded, java.lang.String explanation, java.lang.String parameters, java.lang.String command, java.lang.String targetCommand)
           
 boolean compareStart(java.lang.Class classCommanded, java.lang.String explanation, java.lang.String parameters, java.lang.String command, java.lang.String targetCommand)
          This method is the same as compare except that when in comparing mode (1) it returns true of the command starts with the targetCommand as a substring.
 void composeDocumentation()
          Composes documentation about modules and scripting.
 java.util.Vector getAccumulatedCommands()
          returns the vector of strings for commands accumulated by the checker when in accumulateMode
 java.util.Vector getAccumulatedExplanations()
          returns the vector of strings for commands accumulated by the checker when in accumulateMode
 java.util.Vector getAccumulatedMenus()
          returns the vector of strings for menus accumulated by the checker when in accumulateMode
 boolean getAccumulateMode()
          Returns whether the checker is an accumulator (or comparer).
static java.lang.String getCommandExplanation(MesquiteCommand command, CommandChecker checker, boolean includeParameters)
          Accumulates (menus and ) commands from the given commandable and passes back a vector of strings describing the (menus and ) commands.
static java.lang.String getCommandExplanation(MesquiteCommand command, CommandChecker checker, boolean includeParameters, boolean useHTMLmode)
          Accumulates (menus and ) commands from the given commandable and passes back a vector of strings describing the (menus and ) commands.
 MesquiteFile getFile()
          Returns the file of the script being executed via this checker.
static java.lang.String getQueryModeString(java.lang.String item, MesquiteCommand command, java.lang.Object widget)
          Returns string explaining the operation of the widget (menu item, tool, button, etc.) that uses the given command; for use in query mode and in commands pending list
static void registerClass(java.lang.Class c, java.lang.Class representing)
          This static method registers a class for inclusion in the list of commands available (under 'other' in the Scripting Commands page available from the Help menu in Mesquite).
 void registerMenuItem(MesquiteModule ownerModule, java.lang.String itemName, MesquiteCommand command)
           
 void setAccumulateMode(boolean mode)
          Sets the mode of the checker: if true is passed, it accumulates a list of commands instead of comparing a commandname to a target
 void setFile(MesquiteFile f)
          Sets the file of the script being executed via this checker.
 void setHTMLMode(boolean mode)
          Sets whether an accumulating checker is to put HTML codes in the explanations of commands.
 void setLIMode(boolean mode)
          Sets whether an accumulating checker is to put '' at the start of each line of the accumulated commands.
 void setSparseMode()
          Sets checker as sparse in accumulated text.
static void showExplanations(java.awt.Component c, java.awt.MenuBar mBar, java.lang.String name)
          Shows the explanations of menu items and controls (Explainable Components including tools of tool palettes) for a window.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

registeredClasses

public static java.util.Vector registeredClasses

representingClasses

public static java.util.Vector representingClasses

defaultChecker

public static CommandChecker defaultChecker

documentationComposed

public static boolean documentationComposed
Constructor Detail

CommandChecker

public CommandChecker()
Method Detail

setFile

public void setFile(MesquiteFile f)
Sets the file of the script being executed via this checker.


getFile

public MesquiteFile getFile()
Returns the file of the script being executed via this checker.


setAccumulateMode

public void setAccumulateMode(boolean mode)
Sets the mode of the checker: if true is passed, it accumulates a list of commands instead of comparing a commandname to a target


getAccumulateMode

public boolean getAccumulateMode()
Returns whether the checker is an accumulator (or comparer).


setLIMode

public void setLIMode(boolean mode)
Sets whether an accumulating checker is to put '
  • ' at the start of each line of the accumulated commands.


  • setHTMLMode

    public void setHTMLMode(boolean mode)
    Sets whether an accumulating checker is to put HTML codes in the explanations of commands.


    setSparseMode

    public void setSparseMode()
    Sets checker as sparse in accumulated text.


    accumulateOnlyFrom

    public void accumulateOnlyFrom(java.lang.Class c)
    Sets what exact class the checker is to accumulate commands from (will not accumulate from super or subclasses).


    accumulate

    public static CommandChecker accumulate(Commandable c,
                                            CommandChecker checker)
    Accumulates (menus and ) commands from the given commandable and passes back a vector of strings describing the (menus and ) commands.


    getQueryModeString

    public static java.lang.String getQueryModeString(java.lang.String item,
                                                      MesquiteCommand command,
                                                      java.lang.Object widget)
    Returns string explaining the operation of the widget (menu item, tool, button, etc.) that uses the given command; for use in query mode and in commands pending list


    getCommandExplanation

    public static java.lang.String getCommandExplanation(MesquiteCommand command,
                                                         CommandChecker checker,
                                                         boolean includeParameters)
    Accumulates (menus and ) commands from the given commandable and passes back a vector of strings describing the (menus and ) commands.


    getCommandExplanation

    public static java.lang.String getCommandExplanation(MesquiteCommand command,
                                                         CommandChecker checker,
                                                         boolean includeParameters,
                                                         boolean useHTMLmode)
    Accumulates (menus and ) commands from the given commandable and passes back a vector of strings describing the (menus and ) commands.


    addString

    public void addString(java.lang.String s)
    Adds a string to the vector of strings being accumulated by the checker.


    registerMenuItem

    public void registerMenuItem(MesquiteModule ownerModule,
                                 java.lang.String itemName,
                                 MesquiteCommand command)

    compare

    public boolean compare(java.lang.Class classCommanded,
                           java.lang.String explanation,
                           java.lang.String parameters,
                           java.lang.String command,
                           java.lang.String targetCommand)

    compareStart

    public boolean compareStart(java.lang.Class classCommanded,
                                java.lang.String explanation,
                                java.lang.String parameters,
                                java.lang.String command,
                                java.lang.String targetCommand)
    This method is the same as compare except that when in comparing mode (1) it returns true of the command starts with the targetCommand as a substring.


    getAccumulatedCommands

    public java.util.Vector getAccumulatedCommands()
    returns the vector of strings for commands accumulated by the checker when in accumulateMode


    getAccumulatedExplanations

    public java.util.Vector getAccumulatedExplanations()
    returns the vector of strings for commands accumulated by the checker when in accumulateMode


    getAccumulatedMenus

    public java.util.Vector getAccumulatedMenus()
    returns the vector of strings for menus accumulated by the checker when in accumulateMode


    registerClass

    public static void registerClass(java.lang.Class c,
                                     java.lang.Class representing)
    This static method registers a class for inclusion in the list of commands available (under 'other' in the Scripting Commands page available from the Help menu in Mesquite). This must be done early in startup to be useful (e.g., in a module's mesquiteStartup() method). The first class passed must be instantiable (i.e. Not abstract) and have at least one constructor without arguments. This first class is the class to be registered, or a subclass of it. The second class passed is the actual class whose commands are to be documented. (This second class may be abstract, which is the reason two classes need to be passed.) See the documentation for the method commandsFromRegisteredClasses for information on how the two classes are used.


    commandsFromRegisteredClasses

    public static java.util.Vector commandsFromRegisteredClasses()
    Returns a vector of strings showing the classes that were registered with registerClass and their available commands. As noted under the method registerClass, two classes are registered at a time: a first class (which must be instantiable) and a second class (which may be abstract and must be the same as or a superclass of the first class). The method commandsFromRegisteredClasses makes an accumulating CommandChecker and then examines each of the registered pair of classes. For each pair, the CommandChecker's accumulateOnlyFrom method is the second class, (the 'representing' parameter in registerClass) to restrict the class from which commands are to be accumulated to the second (possibly abstract) class. Then, it instantiates the first class passed, and (if it's appropriately a Commandable) passes it the CommandChecker to its doCommand method to accumulate the commands.


    composeDocumentation

    public void composeDocumentation()
    Composes documentation about modules and scripting. This is done once per run of Mesquite, the first time a call is made to show a web page.


    showExplanations

    public static void showExplanations(java.awt.Component c,
                                        java.awt.MenuBar mBar,
                                        java.lang.String name)
    Shows the explanations of menu items and controls (Explainable Components including tools of tool palettes) for a window. Must be passed the parental component (typically graphics[0] of the window) and the menu bar of the window