public class NotifyOption extends Option implements OptionNotifier
When the option is invoked, the corresponding short, long, and option values are put in an OptionEvent object, and passed to all registered listeners.
A class must implement the OptionListener interface in order to receive notification of option events.
For a more detailed explanation please refer to the tutorial. The following is a simple example of how a NotifyOption is used.
import gnu.dtools.ritopt.*; public class TellMe implements OptionListener { public static void main( String args[] ) { TellMe m = new TellMe(); Options processor = new Options(); NotifyOption say = new NotifyOption( m ); processor.register( "say", 's', say ); processor.process(); } public void optionInvoked( OptionEvent e ) { if ( e.getCommand().equals( "say" ) ) { String say = e.getValue(); if ( Utility.trim( say ).length() == 0 ) say = "nothing"; System.err.println( "You told me to say " + nothing + "." ); } } } cookies@crazymonster$ javac TellMe.java cookies@crazymonster$ java TellMe cookies@crazymonster$ java TellMe cookies@crazymonster$ java TellMe --say -s You told me to say nothing. You told me to say nothing. cookies@crazymonster$ java TellMe --say hello You told me to say hello. cookies@crazymonster$ java TellMe --say "I'm sorry" You told me to say I'm sorry. cookies@crazymonster$ java TellMe --say="not until tomorrow" -s "I'm crazy" You told me to say not until tomorrow. You told me to say I'm crazy.
Copyright (C) Damian Ryan Eads, 2001. All Rights Reserved. ritopt is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ritopt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ritopt; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
DEFAULT_FILE_COMMENT_SIZE, DEFAULT_FILE_COMPLETE_OPTION_SIZE, DEFAULT_HELP_DEPRECATED_SIZE, DEFAULT_HELP_DESCRIPTION_SIZE, DEFAULT_HELP_OPTION_SIZE, DEFAULT_HELP_TYPENAME_SIZE, DEFAULT_MENU_DEPRECATED_SIZE, DEFAULT_MENU_DESCRIPTION_SIZE, DEFAULT_MENU_OPTION_SIZE, DEFAULT_MENU_TYPENAME_SIZE, invoked
Constructor and Description |
---|
NotifyOption()
Construct a NotifyOption with an empty list of listeners.
|
NotifyOption(NotifyOption op)
Construct a NotifyOption by copying the NotifyOption passed.
|
NotifyOption(OptionListener listener)
Construct a NotifyOption and register the passed listener.
|
NotifyOption(OptionListener listener,
java.lang.String command)
Construct a NotifyOption and register the passed listener.
|
NotifyOption(OptionListener listener,
java.lang.String command,
java.lang.String value)
Construct a NotifyOption and register the passed listener.
|
NotifyOption(java.lang.String value)
Construct a NotifyOption, and initialize its default value to the
value passed.
|
NotifyOption(java.lang.String value,
char shortOption)
Constructs a character option initialized with the value and
short option passed.
|
NotifyOption(java.lang.String value,
java.lang.String longOption)
Constructs a NotifyOption option initialized with the value and
long option passed.
|
NotifyOption(java.lang.String value,
java.lang.String longOption,
char shortOption)
Constructs an NotifyOption option initialized with the value, short
and long option passed.
|
Modifier and Type | Method and Description |
---|---|
void |
addOptionListener(OptionListener listener)
Adds an OptionListener to the notification list.
|
java.lang.Object |
getObject()
Return the value as an object.
|
java.lang.String |
getStringValue()
Return this option as a string.
|
java.lang.String |
getTypeName()
Returns the type name of this option.
|
java.lang.String |
getValue()
Return this option as a string.
|
void |
modify(java.lang.String value)
Modify this option based on a string representation.
|
void |
removeOptionListener(OptionListener listener)
Removes an OptionListener from the notification list.
|
void |
setOptionCommand(java.lang.String command)
Sets the command sent when an option is invoked.
|
void |
setValue(java.lang.String value)
Modify this option based on a string representation.
|
java.lang.String |
toString()
Returns a string representation of this object.
|
action, deprecate, getDescription, getFileCommentSize, getFileCompleteOptionSize, getHashKey, getHashKey, getHashKey, getHashKey, getHelp, getHelpDeprecated, getHelpDeprecatedSize, getHelpDescription, getHelpDescriptionSize, getHelpHeader, getHelpOptionSpecification, getHelpOptionSpecificationSize, getHelpTypeName, getHelpTypenameSize, getLongOption, getMenuDeprecatedSize, getMenuDescriptionSize, getMenuOptionSpecificationSize, getMenuTypenameSize, getName, getOptionFileLine, getShortOption, isDeprecated, isInvoked, setDeprecated, setDescription, setFileCommentSize, setFileCompleteOptionSize, setHelpDeprecatedSize, setHelpDescriptionSize, setHelpOptionSpecificationSize, setHelpTypenameSize, setInvoked, setKey, setKey, setLongOption, setMenuDeprecatedSize, setMenuDescriptionSize, setMenuOptionSpecificationSize, setMenuTypenameSize, setShortOption
public NotifyOption()
public NotifyOption(OptionListener listener)
listener
- The listener to register.public NotifyOption(OptionListener listener, java.lang.String command)
listener
- The listener to register.command
- The value of the command.public NotifyOption(OptionListener listener, java.lang.String command, java.lang.String value)
listener
- The listener to register.command
- The value of the command.value
- The default value of the option.public NotifyOption(NotifyOption op)
op
- The notify option to copy.public NotifyOption(java.lang.String value)
value
- The default value of this option.public NotifyOption(java.lang.String value, java.lang.String longOption)
value
- The initial value of this notify option.longOption
- The long option associated with this notify option.public NotifyOption(java.lang.String value, char shortOption)
value
- The initial value of this NotifyOption option.shortOption
- The short option associated with this option.public NotifyOption(java.lang.String value, java.lang.String longOption, char shortOption)
shortOption
- The short option associated with this option.longOption
- The long option associated with this option.value
- The initial value of this NotifyOption option.public java.lang.Object getObject()
public void modify(java.lang.String value) throws OptionModificationException
modify
in interface OptionModifiable
value
- String representation of the object.OptionModificationException
- Thrown if an error occurs
during modification of an option.public void setValue(java.lang.String value) throws OptionModificationException
value
- String representation of the object.OptionModificationException
- Thrown if an error occurs
during modification of an option.public java.lang.String getValue()
public java.lang.String getStringValue()
getStringValue
in class Option
public java.lang.String getTypeName()
getTypeName
in class Option
public void addOptionListener(OptionListener listener)
addOptionListener
in interface OptionNotifier
listener
- The OptionListener to add.public void removeOptionListener(OptionListener listener)
removeOptionListener
in interface OptionNotifier
listener
- The OptionListener to remove.public void setOptionCommand(java.lang.String command)
setOptionCommand
in interface OptionNotifier
command
- The command to send.public java.lang.String toString()
toString
in class java.lang.Object