PenProfile 2.x

com.livescribe.penlet
Class AbstractPenletPlugin

java.lang.Object
  extended by com.livescribe.penlet.PenletPlugin
      extended by com.livescribe.penlet.AbstractPenletPlugin
Direct Known Subclasses:
AcquireHWPlugin, DrawnButtonController, MenuBookmarkHandlerPlugin

public abstract class AbstractPenletPlugin
extends PenletPlugin

An abstract base class for penlet plugins that provides a basic implementation for the plugin state.

See Also:
PluginListener
Note:
This class is not thread safe.

Field Summary
protected  boolean active
          The active state of this plugin.
protected  Vector listeners
          The listener list.
 
Constructor Summary
protected AbstractPenletPlugin(Penlet penlet)
          Creates a new plugin.
protected AbstractPenletPlugin(Penlet penlet, boolean consumeAllEvents)
          Creates a new plugin and sets whether to consume all the events.
 
Method Summary
 void activate()
          Activates the plugin.
 void addPluginListener(PluginListener l)
          Adds a plugin listener.
 void deactivate()
          Deactivates the plugin.
protected  void fireActivated()
          Fires the activated event to all the listeners.
protected  void fireDeactivated()
          Fires the deactivated event to all the listeners.
 boolean isActive()
          Returns the active state of this plugin.
 boolean onCoordinateEvent(CoordinateEvent ev)
          Handles a coordinate event.
 boolean onDocumentEvent(DocumentEvent ev)
          Handles a document event.
 boolean onMenuEvent(MenuEvent ev)
          Handles a menu event.
 boolean onPenTipEvent(PenTipEvent ev)
          Handles a pen tip event.
 boolean onRegionEvent(RegionEvent ev)
          Handles a region event.
 boolean onStrokeEvent(StrokeEvent ev)
          Handles a stroke event.
 void removePluginListener(PluginListener l)
          Adds a plugin listener.
 void scheduleDeactivation(long delay)
          A convenience method that schedules a call to deactivate() after the specified delay.
 void setConsumeAllEvents(boolean flag)
          Sets whether to consume all the events.
 
Methods inherited from class com.livescribe.penlet.PenletPlugin
getDisplay, getPenlet, restoreDisplay, saveDisplay
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

active

protected boolean active
The active state of this plugin. This is managed by the various active state-related methods in this class.


listeners

protected Vector listeners
The listener list. This is managed by the various listener-related methods in this class.

Constructor Detail

AbstractPenletPlugin

protected AbstractPenletPlugin(Penlet penlet)
Creates a new plugin. By default, all events are not consumed.

Parameters:
penlet - the penlet
See Also:
AbstractPenletPlugin(Penlet, boolean)

AbstractPenletPlugin

protected AbstractPenletPlugin(Penlet penlet,
                               boolean consumeAllEvents)
Creates a new plugin and sets whether to consume all the events.

Parameters:
penlet - the penlet
consumeAllEvents - indicates whether to consume all events
See Also:
setConsumeAllEvents(boolean)
Method Detail

isActive

public boolean isActive()
Returns the active state of this plugin.

Specified by:
isActive in class PenletPlugin
Returns:
the active state of this plugin.
See Also:
active

fireActivated

protected void fireActivated()
Fires the activated event to all the listeners.

See Also:
listeners

fireDeactivated

protected void fireDeactivated()
Fires the deactivated event to all the listeners.

See Also:
listeners

addPluginListener

public void addPluginListener(PluginListener l)
Adds a plugin listener. This does nothing if the specified listener is null. Note that a listener may be added more than once, and will thus receive event notifications more than once.

Specified by:
addPluginListener in class PenletPlugin
Parameters:
l - the listener to add
See Also:
listeners

removePluginListener

public void removePluginListener(PluginListener l)
Adds a plugin listener. This does nothing if the specified listener is null. The listener is found in the list by using its equals implementation, which, unless overridden, is a direct object reference compare.

Specified by:
removePluginListener in class PenletPlugin
Parameters:
l - the listener to add
See Also:
listeners

activate

public void activate()
              throws PenletStateChangeException
Activates the plugin. This implementation:

Overriding methods should call this after any other setup is completed. The reason is that the listener notification happens at the end of this method.

It is often the case, however, that more major setup needs to be done when a plugin is activated. In this case, it is probably easier to not call this implementation (via super.activate()) and instead just manage the active field and notify listeners using fireActivated() yourself.

Note that this implementation does not throw a PenletStateChangeException.

Specified by:
activate in class PenletPlugin
Throws:
PenletStateChangeException - if there was a problem activating the plugin.
See Also:
active, fireActivated()

scheduleDeactivation

public void scheduleDeactivation(long delay)
A convenience method that schedules a call to deactivate() after the specified delay.

Parameters:
delay - deactivate the plugin after this delay, in milliseconds

deactivate

public void deactivate()
Deactivates the plugin. This implementation:

Overriding methods should call this after any other cleanup is completed. The reason is that the listener notification happens at the end of this method.

It is often the case, however, that more major cleanup needs to be done when a plugin is deactivated. In this case, it is probably easier to not call this implementation (via super.deactivate()) and instead just manage the active field and notify listeners using fireDeactivated() yourself.

Specified by:
deactivate in class PenletPlugin
See Also:
active, fireDeactivated()

setConsumeAllEvents

public final void setConsumeAllEvents(boolean flag)
Sets whether to consume all the events. This is the value that will be returned from all the onXXXEvent() methods. In other words, this setting controls whether all events are consumed by this plugin or not. PenletPlugin by default does not consume all the events and this method provides a way to configure that.

Note that this does not cause Event.consume() to be called. It only indicates what should be returned from the event handling methods.

The default value of this setting is false.

Parameters:
flag - whether to consume all events

onCoordinateEvent

public boolean onCoordinateEvent(CoordinateEvent ev)
Handles a coordinate event. This returns what was set in setConsumeAllEvents(boolean).

Overrides:
onCoordinateEvent in class PenletPlugin
Parameters:
ev - the coordinate event
Returns:
whether the event is handled.
See Also:
setConsumeAllEvents(boolean)

onDocumentEvent

public boolean onDocumentEvent(DocumentEvent ev)
Handles a document event. This returns what was set in setConsumeAllEvents(boolean).

Overrides:
onDocumentEvent in class PenletPlugin
Parameters:
ev - the document event
Returns:
whether the event is handled.
See Also:
setConsumeAllEvents(boolean)

onMenuEvent

public boolean onMenuEvent(MenuEvent ev)
Handles a menu event. This returns what was set in setConsumeAllEvents(boolean).

Overrides:
onMenuEvent in class PenletPlugin
Parameters:
ev - the menu event
Returns:
whether the event is handled.
See Also:
setConsumeAllEvents(boolean)

onPenTipEvent

public boolean onPenTipEvent(PenTipEvent ev)
Handles a pen tip event. This returns what was set in setConsumeAllEvents(boolean).

Overrides:
onPenTipEvent in class PenletPlugin
Parameters:
ev - the pen tip event
Returns:
whether the event is handled.
See Also:
setConsumeAllEvents(boolean)

onRegionEvent

public boolean onRegionEvent(RegionEvent ev)
Handles a region event. This returns what was set in setConsumeAllEvents(boolean).

Overrides:
onRegionEvent in class PenletPlugin
Parameters:
ev - the region event
Returns:
whether the event is handled.
See Also:
setConsumeAllEvents(boolean)

onStrokeEvent

public boolean onStrokeEvent(StrokeEvent ev)
Handles a stroke event. This returns what was set in setConsumeAllEvents(boolean).

Overrides:
onStrokeEvent in class PenletPlugin
Parameters:
ev - the stroke event
Returns:
whether the event is handled.
See Also:
setConsumeAllEvents(boolean)

PenProfile 2.x

Copyright © 2010 Livescribe Inc. All Rights Reserved.
Confidential and subject to NDA.