public abstract class ALcyTool extends Object implements ILcdPropertyChangeSource
Abstract class that represents a piece of functionality that assists in achieving a specific task. For examples of such tasks, please check out the subclasses.
This tool is activated using its plugInto
method, usually called from
ALcyAddOn#plugInto
.
It is deactivated using unplugFrom
, usually called from
ALcyAddOn#unplugFrom
.
Constructor and Description |
---|
ALcyTool() |
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener aListener)
Registers the given
PropertyChangeListener to be notified when this object's
properties change. |
void |
addPropertyChangeListener(String aProperty,
PropertyChangeListener aListener)
Adds the given listener to the list of listeners, so that it will receive notifications
about changes in
aProperty . |
protected void |
assertPlugged()
This method checks if the
plugInto method of this ALcyTool
has been called correctly, and throws an IllegalStateException if not. |
protected void |
firePropertyChange(String aProperty,
Object aOldValue,
Object aNewValue)
Fires the given event to the associated listeners.
|
static String |
getLongPrefix(Class aClass)
Returns the long prefix for a given class (normally an add-on), which is its package name,
suffixed with a dot (.).
|
static String |
getLongPrefixWithClassName(Class aClass)
Returns the long prefix for a given class (normally an add-on), which is its fully qualified
class name suffixed with a dot (.).
|
ILcyLucyEnv |
getLucyEnv()
Returns the
ILcyLucyEnv that was provided in plugInto . |
static String |
getShortPrefix(Class aClass)
Returns the short prefix for a given class (normally an add-on), which is its short class
name, suffixed with a dot (.).
|
void |
plugInto(ILcyLucyEnv aLucyEnv)
Plugs this tool.
|
void |
removePropertyChangeListener(PropertyChangeListener aListener)
De-registers the given
PropertyChangeListener from receiving property change events
for this object. |
void |
removePropertyChangeListener(String aProperty,
PropertyChangeListener aListener)
Removes the given listener for the given property, so that it no longer receives
those change events.
|
void |
unplugFrom(ILcyLucyEnv aLucyEnv)
Unplugs this tool.
|
public void addPropertyChangeListener(PropertyChangeListener aListener)
ILcdPropertyChangeSource
Registers the given PropertyChangeListener
to be notified when this object's
properties change.
In case you need to register a listener which keeps a reference to an object with a shorter life-time than this change source,
you can use a ALcdWeakPropertyChangeListener
instance as property change listener.
addPropertyChangeListener
in interface ILcdPropertyChangeSource
aListener
- The listener to be notifiedALcdWeakPropertyChangeListener
,
ILcdPropertyChangeSource.removePropertyChangeListener(java.beans.PropertyChangeListener)
public void addPropertyChangeListener(String aProperty, PropertyChangeListener aListener)
aProperty
.aProperty
- The property to watch for changes.aListener
- The listener to add.public void removePropertyChangeListener(PropertyChangeListener aListener)
ILcdPropertyChangeSource
De-registers the given PropertyChangeListener
from receiving property change events
for this object.
If the listener was added more than once, it will be notified one less time after being
removed.
If the listener is null
, or was never added, no exception is thrown and no action is taken.
removePropertyChangeListener
in interface ILcdPropertyChangeSource
aListener
- the listener that should no longer be notified of changes of
this object's propertiesILcdPropertyChangeSource.addPropertyChangeListener(java.beans.PropertyChangeListener)
public void removePropertyChangeListener(String aProperty, PropertyChangeListener aListener)
aProperty
- The property to stop listening to.aListener
- The listener to remove.protected void firePropertyChange(String aProperty, Object aOldValue, Object aNewValue)
aProperty
- The property that was changed.aOldValue
- The old value.aNewValue
- The new value.public ILcyLucyEnv getLucyEnv()
ILcyLucyEnv
that was provided in plugInto
.ILcyLucyEnv
.public void plugInto(ILcyLucyEnv aLucyEnv)
Plugs this tool. This method is usually called from
ALcyAddOn#plugInto
.
aLucyEnv
- The environment to plug into.public void unplugFrom(ILcyLucyEnv aLucyEnv)
Unplugs this tool. This method is usually called from
ALcyAddOn#unplugFrom
.
aLucyEnv
- The environment to unplug from, must be identical to the environment given to
plugInto
.protected void assertPlugged()
This method checks if the plugInto
method of this ALcyTool
has been called correctly, and throws an IllegalStateException
if not.
Calling this method is in no way mandatory, but it can be convenient for subclasses in
order to avoid developers struggling with for example obscure NullPointerException
s
because the ILcyLucyEnv
is null
.
IllegalStateException
- If not plugged correctly, that is getLucyEnv()
returns null
.public static String getLongPrefix(Class aClass)
Returns the long prefix for a given class (normally an add-on), which is its package name,
suffixed with a dot (.). It can for example be used as the long prefix in
TLcyPreferencesTool
For example, the class com.luciad.lucy.addons.about.TLcyAboutBoxAddon
has
com.luciad.lucy.addons.about.
as its long prefix.
Warning: Avoid getLongPrefix(getClass())
as it returns
a different value in sub-classes. Instead use for example
getLongPrefix(TLcyAboutBoxAddOn.class)
. Also, when multiple add-ons exist in
the same package, the getLongPrefixWithClassName(Class)
should be used because the
package name is then no longer unique.
aClass
- The class to derive the long prefix from, normally an ALcyAddOn
sub-class.getLongPrefixWithClassName(Class)
public static String getLongPrefixWithClassName(Class aClass)
Returns the long prefix for a given class (normally an add-on), which is its fully qualified
class name suffixed with a dot (.). It can for example be used as the long prefix in
TLcyPreferencesTool
For example, the class com.luciad.lucy.addons.about.TLcyAboutBoxAddon
has
com.luciad.lucy.addons.about.TLcyAboutBoxAddon.
as its long prefix.
Warning: Avoid getLongPrefixWithClassName(getClass())
as it returns
a different value in sub-classes. Instead use for example
getLongPrefixWithClassName(TLcyAboutBoxAddOn.class)
.
aClass
- The class to derive the long prefix from, normally an ALcyAddOn
sub-class.public static String getShortPrefix(Class aClass)
Returns the short prefix for a given class (normally an add-on), which is its short class
name, suffixed with a dot (.). It can for example be used as the short prefix in
TLcyPreferencesTool
For example, the class com.luciad.lucy.addons.about.TLcyAboutBoxAddon
has
TLcyAboutBoxAddon.
as its short prefix.
Warning: Avoid getShortPrefix(getClass())
as it returns
a different value in sub-classes. Instead use for example
getShortPrefix(TLcyAboutBoxAddOn.class)
.
aClass
- The class to derive the short prefix from, normally an ALcyAddOn
sub-class.