com.levigo.jadice.swing.tool
Class ToolManager

java.lang.Object
  extended by com.levigo.jadice.swing.tool.ToolManager

public final class ToolManager
extends Object


Constructor Summary
ToolManager(ViewComponent viewComponent)
           
 
Method Summary
 void activate(Class<? extends Tool> tc)
          Activates the tool of the given class.
 void addPropertyChangeListener(PropertyChangeListener listener)
           
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
           
protected  void changeEnabledState(Tool t, boolean enabled)
           
 Tool deregister(Class<? extends Tool> tc)
          Deregisters the tool of the given class if the tool instance of this class is currently registered as tool.
 ToolActivationPolicy getActivationPolicy()
           
 Class<? extends Tool> getActiveTool()
          Returns the Class of the currently active Tool or null if no Tool has been activated
<T> Collection<T>
getCompatibleTools(Class<T> clazz)
          Return all registered Tools which are derived from the given class or which implement the given interface.
<T> Collection<T>
getCompatibleTools(Class<T> clazz, boolean enabledOnly)
          Return all registered Tools which are derived from the given class or which implement the given interface.
 Collection<? extends MenuContributor> getMenuContributors()
          Return the current list of tools suitable as menu contributors.
 Collection<Class<? extends Tool>> getRegisteredToolClasses()
          Allows access to all registered tool classes.
 String getStatusFeedback()
           
<T extends Tool>
T
getTool(Class<T> cls)
          Return the tool instance for the given tool class, or null if no such tool is registered.
static String getToolPropertyPrefix(Class<? extends Tool> tc)
          Constructs the property name prefix for Tool property change events.
 ViewComponent getViewComponent()
           
 void handleEditEvent(Class<?> context, EditEvent e)
           
 boolean hasTool(Class<? extends Tool> cls)
          Return whether this tool manager currently manages a tool of the given class.
 boolean isActive(Class<? extends Tool> tc)
          Return whether the tool of the given class is currently active.
protected  boolean isActive(Tool t)
          Return whether the given tool is currently active.
 boolean isEnabled(Class<? extends Tool> tc)
          Checks whether the given Tool is enabled.
 boolean isExclusive()
          Return whether the exclusive tool mode is active, i.e.
<T extends Tool>
T
register(Class<T> tc, boolean enabled)
          Registers the tool of the given class if the tool instance of this class is not currently registered as tool.
 void removePropertyChangeListener(PropertyChangeListener listener)
           
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
           
 void render(RenderParameters parameters)
          Render the Tool UIs onto the given Graphics2D context using the given RenderControls.
 void repaint(Page p)
          Repaint the area pertaining to the given page.
 void repaint(Page p, Rectangle2D boundsDU)
          Repaint the area pertaining to the given page and bounds.
 void setActivationPolicy(ToolActivationPolicy activationPolicy)
           
protected  void setCursor(Cursor cursor)
           
 void setEnabled(Class<? extends Tool> tc, boolean enabled)
          Change the enabled state of the tool of the given class.
 void setExclusive(Class<? extends Tool> tc)
          Set the tool of the given class to be the exclusive tool.
 void setNonExclusive(Class<? extends Tool> tc)
          Leave exclusive mode.
protected  void setStatusFeedback(String statusFeedback)
           
 void toolPropertyChanged(Tool tool, String propertyName, Object oldValue, Object newValue)
          Send a PropertyChangeEvent for the specified Tool property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ToolManager

@CallOnEDT
public ToolManager(ViewComponent viewComponent)
Method Detail

getToolPropertyPrefix

@CallableOffEDT
public static String getToolPropertyPrefix(Class<? extends Tool> tc)
Constructs the property name prefix for Tool property change events. Any Event sent using toolPropertyChanged(Tool, String, Object, Object) will use the value returned by this class as a prefix.

Parameters:
tc - the Tool implementation class
Returns:
the property name prefix, which will be used.

repaint

@CallOnEDT
public void repaint(Page p)
Repaint the area pertaining to the given page.

Parameters:
p -

repaint

@CallOnEDT
public void repaint(Page p,
                              Rectangle2D boundsDU)
Repaint the area pertaining to the given page and bounds. The bounds are interpreted in document units relative to the page's origin.

Parameters:
p -
boundsDU -

getViewComponent

@CallOnEDT
public ViewComponent getViewComponent()

register

@CallOnEDT
public <T extends Tool> T register(Class<T> tc,
                                             boolean enabled)
Registers the tool of the given class if the tool instance of this class is not currently registered as tool. If a tool of this class is already registered, this method simply returns the registered instance. Otherwise a tool instance will be created, registered and returned.

Parameters:
tc - the tool class
enabled - whether the tool will initially be enabled
Returns:
the registered tool instance
Throws:
IllegalStateException - if the calling thread is not the Event Dispatch Thread

deregister

@CallOnEDT
public Tool deregister(Class<? extends Tool> tc)
Deregisters the tool of the given class if the tool instance of this class is currently registered as tool. The deregistered tool instance will be returned if a matching tool instance was found and deregistered. Otherwise null will be returned.

NOTE: Once the view component has been realized, this method must not be called on a thread other than the Event Dispatch Thread. For details please see: TGASwingUtil.ensureEventDispatchThread(Component)

Parameters:
tc - the tool class
Returns:
the deregistered tool instance or null if available otherwise null. Be aware this tool instance is already deregistered when returned and can not be used as tool anymore.
Throws:
IllegalStateException - if the component has been realized and the calling thread is not the Event Dispatch Thread

activate

@CallOnEDT
public void activate(Class<? extends Tool> tc)
Activates the tool of the given class.

NOTE: Once the view component has been realized, this method must not be called on a thread other than the Event Dispatch Thread. For details please see: TGASwingUtil.ensureEventDispatchThread(Component)

Parameters:
tc - the tool class
Throws:
IllegalArgumentException - if no tool of the given class is currently managed by this ToolManager.
IllegalStateException - if the component has been realized and the calling thread is not the Event Dispatch Thread

handleEditEvent

@CallOnEDT
public void handleEditEvent(Class<?> context,
                                      EditEvent e)

hasTool

@CallableOffEDT
public boolean hasTool(Class<? extends Tool> cls)
Return whether this tool manager currently manages a tool of the given class.


getTool

@CallableOffEDT
public <T extends Tool> T getTool(Class<T> cls)
Return the tool instance for the given tool class, or null if no such tool is registered.


isActive

@CallOnEDT
public boolean isActive(Class<? extends Tool> tc)
Return whether the tool of the given class is currently active.

Parameters:
tc - the tool class
Returns:
true if the tool is active

isActive

@CallOnEDT
protected boolean isActive(Tool t)
Return whether the given tool is currently active.

Parameters:
t - the tool
Returns:
true if the tool is active

isExclusive

@CallOnEDT
public boolean isExclusive()
Return whether the exclusive tool mode is active, i.e. if the currently active tool is also the exclusive tool. In exclusive mode no tools except the exclusive one get a chance to render or handle events.

Returns:
true if exclusive mode is active

render

@CallOnEDT
public void render(RenderParameters parameters)
Render the Tool UIs onto the given Graphics2D context using the given RenderControls.

This render method is usually called within the context and during the rendering of a single page. It will dispatch the render calls to all active tools.

Parameters:
parameters - the render parameters to use.

setEnabled

@CallOnEDT
public void setEnabled(Class<? extends Tool> tc,
                                 boolean enabled)
Change the enabled state of the tool of the given class.

NOTE: Once the view component has been realized, this method must not be called on a thread other than the Event Dispatch Thread. For details please see: TGASwingUtil.ensureEventDispatchThread(Component)

Parameters:
tc - the tool class
enabled - true to enabled the tool, otherwise false
Throws:
IllegalArgumentException - if no tool of the given class is currently managed by this ToolManager.
IllegalStateException - if the component has been realized and the calling thread is not the Event Dispatch Thread

changeEnabledState

@CallOnEDT
protected void changeEnabledState(Tool t,
                                            boolean enabled)

isEnabled

@CallOnEDT
public boolean isEnabled(Class<? extends Tool> tc)
Checks whether the given Tool is enabled. This method will not fail if the Tool has not yet been registered. Instead, for non registered tools this method will return false.

Parameters:
tc -
Returns:
true if the Tool is enabled, or false if it is not or the Tool has not yet been registered.

setExclusive

@CallOnEDT
public void setExclusive(Class<? extends Tool> tc)
Set the tool of the given class to be the exclusive tool.

NOTE: Once the view component has been realized, this method must not be called on a thread other than the Event Dispatch Thread. For details please see: TGASwingUtil.ensureEventDispatchThread(Component)

Parameters:
tc - the class of the tool to make exclusive
Throws:
IllegalArgumentException - if no tool of the given class is currently managed by this ToolManager.
IllegalStateException - if the component has been realized and the calling thread is not the Event Dispatch Thread

setNonExclusive

@CallOnEDT
public void setNonExclusive(Class<? extends Tool> tc)
Leave exclusive mode. Whatever tool is currently exclusive will lose its exclusive status. If there is currently no exclusive mode tool, this call has no effect.


toolPropertyChanged

public void toolPropertyChanged(Tool tool,
                                String propertyName,
                                Object oldValue,
                                Object newValue)
Send a PropertyChangeEvent for the specified Tool property. The property name will be qualified using the following schema: "ToolPropertyPrefix .propertyName "

Parameters:
tool -
propertyName - the property name, which will be prefixed with a Tool specific prefix
oldValue -
newValue -
See Also:
getToolPropertyPrefix(Class)

addPropertyChangeListener

@CallableOffEDT
public void addPropertyChangeListener(PropertyChangeListener listener)
Parameters:
listener -
See Also:
PropertyChangeSupport.addPropertyChangeListener(java.beans.PropertyChangeListener)

addPropertyChangeListener

@CallableOffEDT
public void addPropertyChangeListener(String propertyName,
                                                     PropertyChangeListener listener)
Parameters:
propertyName -
listener -
See Also:
PropertyChangeSupport.addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)

removePropertyChangeListener

@CallableOffEDT
public void removePropertyChangeListener(PropertyChangeListener listener)
Parameters:
listener -
See Also:
PropertyChangeSupport.removePropertyChangeListener(java.beans.PropertyChangeListener)

removePropertyChangeListener

@CallableOffEDT
public void removePropertyChangeListener(String propertyName,
                                                        PropertyChangeListener listener)
Parameters:
propertyName -
listener -
See Also:
PropertyChangeSupport.removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)

getCompatibleTools

@CallOnEDT
public <T> Collection<T> getCompatibleTools(Class<T> clazz)
Return all registered Tools which are derived from the given class or which implement the given interface. Only tools in the state 'enabled' are considered.

Type Parameters:
T - type of class or interface in question
Parameters:
clazz - the class or interface in question
Returns:
a (possibly empty) collection of tools

getCompatibleTools

@CallOnEDT
public <T> Collection<T> getCompatibleTools(Class<T> clazz,
                                                      boolean enabledOnly)
Return all registered Tools which are derived from the given class or which implement the given interface.

Type Parameters:
T - type of class or interface in question
Parameters:
clazz - the class or interface in question
enabledOnly - whether only enabled tools (true) or all registered tools shall be considered
Returns:
a (possibly empty) collection of tools

getRegisteredToolClasses

@CallableOffEDT
public Collection<Class<? extends Tool>> getRegisteredToolClasses()
Allows access to all registered tool classes. This method will return active and inactive Tools. The returned Collection is read-only and does not follow any kind of sorting. (The order is random)

Returns:
a Collection of all registered Tool classes.

getMenuContributors

@CallOnEDT
public Collection<? extends MenuContributor> getMenuContributors()
Return the current list of tools suitable as menu contributors.

Returns:
a read-only list of tools.

setActivationPolicy

@CallOnEDT
public void setActivationPolicy(ToolActivationPolicy activationPolicy)

getActivationPolicy

@CallOnEDT
public ToolActivationPolicy getActivationPolicy()

setCursor

@CallOnEDT
protected void setCursor(Cursor cursor)

setStatusFeedback

@CallOnEDT
protected void setStatusFeedback(String statusFeedback)

getStatusFeedback

@CallOnEDT
public String getStatusFeedback()

getActiveTool

@CallOnEDT
public Class<? extends Tool> getActiveTool()
Returns the Class of the currently active Tool or null if no Tool has been activated

Returns:
the Class of the currently active Tool or null


Copyright © 1995-2020 levigo holding gmbh. All Rights Reserved.