net.refractions.udig.style
Class IStyleConfigurator

java.lang.Object
  extended by net.refractions.udig.style.IStyleConfigurator

public abstract class IStyleConfigurator
extends java.lang.Object

Configures a style object.

Responsibilities:

Style objects are stored a StyleBlackboard. Configurators use the blackboard to collaborate. Objects are stored on the blackboard by id. When a configurator queries the blackboard for an object and it does not exist, a default object should be created and placed on the blackboard. The following is an example: ... StyleBlackboard styleBlackboard = getStyleBlackboard(); Point style = styleBlackboard.lookup("point.style"); if (style == null) { style = new Point(); style.setX(0); style.setY(0); styleBlackboard.put("point.style", style); } ...

Each Layer has a StyleBlackboard. Configurators should not write to this blackboard directly. Each configurator is supplied with a copy of the actual layer blackboard.

Note:Each time a style object is changed, it must be replaced onto the blackboard for persistance reasons. StyleBlackboard styleBlackboard = getStyleBlackboard(); Point style = styleBlackboard.lookup("point.style"); ... style.setX(10); style.setY(10); styleBlackboard.put("point.style", style);

The StyleConfigurator should store no state. All state should be stored in the style objects on the style blackboard. When a ui widget changes state, the style object should be written to immediately to reflect the change. When the configurator becomes active, the ui widgets should be initialized from the values of style objects on the blackboard. This should be performed every time refresh() is called.

Whenever style objects are read from the blackboard,

void apply() { StyleBlackboard styleBlackboard = getStyleBlackboard(); Point style = styleBlackboard.lookup("point.style"); if (style == null) { style = new Point(); styleBlackboard.put("point.style", style); } style.setX(...) //set to some value from ui style.setY(...) //set to some value from ui } void init() { StyleBlackboard styleBlackboard = getStyleBlackboard(); Point style = styleBlackboard.lookup("point.style"); if (style != null) { //set some ui widget to value of style.getX(); //set some ui widget to value of style.getY(); } }

A StyleConfigurator is not considered active until its ui has been created.

Since:
0.6.0
Author:
Justin Deoliveira

Field Summary
static java.lang.String XPID
          extension point id
 
Constructor Summary
IStyleConfigurator()
           
 
Method Summary
abstract  boolean canStyle(Layer aLayer)
          Determines if the configurator can be used to configure the style for a specified layer.
abstract  void createControl(Composite parent)
          Creates the control that is to be used to configure the style.
 void dispose()
          Cleans up any resources (like icons) held by this StyleConfigurator.
 void focus(Layer layer1)
          Sets the layer and style blackboard that the configurator can populate with style.
protected  IAction getApplyAction()
           
 java.lang.String getLabel()
          Returns the label describing the configurator.
 Layer getLayer()
          Gets the current layer to which the current style being configured is to be applied to.
 IBlackboard getStyleBlackboard()
          Returns the style blackboard that the configurator is populating with style information.
 java.lang.String getStyleId()
          Returns the declared style id of the style the configurator depends on.
 IViewSite getViewSite()
          Returns the site for this view.
protected  void init()
          Initialize this style configurator.
 void init(IViewSite viewSite)
          Initializes this view with the given view site.
protected  void makeActionDoStuff()
          Runs the apply action.
 void preApply()
          Called after apply action has been triggeredbefore apply is executed.
protected abstract  void refresh()
          Called when new layer and blackbard values are available.
 void setAction(IAction applyAction1)
          Sets the apply action.
 void setLabel(java.lang.String label)
          Sets the label describing the configurator.
 void setStyleId(java.lang.String id)
          Sets the declared style id of the style the configurator depends on.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XPID

public static final java.lang.String XPID
extension point id

See Also:
Constant Field Values
Constructor Detail

IStyleConfigurator

public IStyleConfigurator()
Method Detail

setAction

public final void setAction(IAction applyAction1)
Sets the apply action.

Parameters:
applyAction1 -

makeActionDoStuff

protected void makeActionDoStuff()
Runs the apply action.


getApplyAction

protected IAction getApplyAction()

preApply

public void preApply()
Called after apply action has been triggeredbefore apply is executed.


getStyleId

public final java.lang.String getStyleId()
Returns the declared style id of the style the configurator depends on.

This is provided by SetStyleId by the extention point.

When keeping information associated with a IStyleConfigurator (in a Map, or Memento) use this as a KEY. Don't use label, two IStyleConfigurator may have the same label.

Returns:
styleId The style id.

setStyleId

public final void setStyleId(java.lang.String id)
Sets the declared style id of the style the configurator depends on.

Called by the extention point processor.

Parameters:
id - The style id.

getLabel

public final java.lang.String getLabel()
Returns the label describing the configurator. Used mainly for ui purposes.

Returns:
A short description of the configurator.

setLabel

public void setLabel(java.lang.String label)
Sets the label describing the configurator. Used mainly for ui purposes.

Parameters:
label - A short description of the configurator.

getViewSite

public IViewSite getViewSite()
Returns the site for this view. This method is equivalent to (IViewSite) getSite().

The site can be null while the view is being initialized. After the initialization is complete, this value must be non-null for the remainder of the view's life cycle.

Returns:
the view site; this value may be null if the view has not yet been initialized

init

public void init(IViewSite viewSite)
          throws PartInitException
Initializes this view with the given view site.

This method is automatically shortly after the part is instantiated. It marks the start of the views's lifecycle. Clients must not call this method.

Parameters:
viewSite - the view site
Throws:
PartInitException

init

protected void init()
             throws PartInitException
Initialize this style configurator.

You must call super.init();

Throws:
PartInitException

canStyle

public abstract boolean canStyle(Layer aLayer)
Determines if the configurator can be used to configure the style for a specified layer.

Parameters:
aLayer - The layer to be styled.
Returns:
true if the configurator can work with the layer, otherwise false.

getLayer

public final Layer getLayer()
Gets the current layer to which the current style being configured is to be applied to.

The layer can be null while the view is being initialized or created. This value must be non-null when the IStyleConfigurator.getControl() is visiable.

Returns:
Layer being edited at the moment

getStyleBlackboard

public final IBlackboard getStyleBlackboard()
Returns the style blackboard that the configurator is populating with style information.

The blackboard can be null while the view is being initialized or created. This value must be non-null when the IStyleConfigurator.getControl() is visiable.

Returns:
A style blackboard.

focus

public void focus(Layer layer1)
Sets the layer and style blackboard that the configurator can populate with style. information. Upon this method, ui state should be reinitialized against the new layer and blackboard.

When changing layers:


refresh

protected abstract void refresh()
Called when new layer and blackbard values are available.

This provides update information as a callback (rather than an event listener).

This should only be called after create part control has had a chance to be called.


createControl

public abstract void createControl(Composite parent)
Creates the control that is to be used to configure the style.

This method uses a template pattern to get the subclass to create the control. This method will not be called until after init and setViewPart. The parent container (composite) passed in is for the explicit use of the configurator, this method must set a layout for the container.

You can set the layout to the parent to be whatever you want.

Parameters:
parent -

dispose

public void dispose()
Cleans up any resources (like icons) held by this StyleConfigurator.

You should not assume that create, or even init has been called. You must call super.dispose();