StyleDefinition
Identifier:
net.refractions.udig.core.StyleDefinition
Since:
0.3.0
Description:
Define style information to be stored on the style blackboard at specific ID. The extention point defines ID used to store information; and a StyleContent class that is used to persist information between runs.
The concrete class used to represent a style is only known by; renderers that render a layer; style configurators that change the style.
Internally StyleContent uses a Memento object (which contains style information as a tree of mementos each of which contains strings). As far as the style blackboard persistence is concerned a style is just a memento (one per each ID); turning the memento into an Object is delegated to the StyleConent for that ID.
If you would like to let the user control the style; you can make a user interface that modifies the contents of the style blackboard. We ask that you only modify the contents of the style blackboard under user control (rather than over the course of rendering) to prevent a cycle.
Udig provides the style configurator and style editor page extention points for working with the style blackboard. In each case the user interface is responsible for looking up an ID on the style blackboard and making modifications directly.
Configuration Markup:
<!ELEMENT extension (style+)>
<!ATTLIST extension
point CDATA #REQUIRED
>
A style is used for rendering purposes. Renderers use style objects when rendering Layer data. A style can be any object. Extenders are expected to create the style object itself, as well as an implementation of StyleContent which is uses a factory for the style. Style objects are placed onto a Layer blackboard so they can be accessed by other entities such as Renderers and StyleConfigurators.
<!ELEMENT style EMPTY>
<!ATTLIST style
id CDATA #REQUIRED
name CDATA #REQUIRED
class CDATA #REQUIRED
>
A Style provided by a plugin author. Styles are only useful if they can be rendered so a style that extends this extension point should also have an associated renderer that know how to use the style.
- id - An id that will be used to identify the style.
This is the key which the style is placed under when a style is placed onto a StyleBlackboard. It is used Renderer and StyleConfigurator to identify the style.
- name - A human readable name that can be used as a short description of the style.
- class - An implemtation of StyleContent. This class is responsible for loading and saving the underlying style object from persistant storage.
Examples:
The net.refractions.udig.style.sld.SLDContent class is used to save and load an org.geotools.styling.Style object from the style blackboard. This value is saved with the id ""net.refractions.udig.style.sld"" (by convention this constant SLDContent.ID)
This example is specific to syling features; you can store anything you want on the style blackboard; it is only a contract between you and a renderer (and the user if you make a style configurator).
API Information:
Implementations of this extention point are required to provide a StyleContent class. A StyleContent implementation is responsible for teaching the system how to load and save an instane of getStyleClass().
StyleContent methods:
- getId() - this is the ID used store the content on the blackboard
- getStyleClass()
- save(IMemento, Object)
- load(IMemento)
- load(URL, IProgressMonitor)
- createDefaultStyle(IGeoResource, Color, IProgressMonitor)
The createDefaultStyle implementation is uesd to generate a default style for the provided resource; if the provided resource cannot be handled by this style their is no obligation
Supplied Implementation:
SLDContent is a style content implementation included with uDig.
The IMemento created by SLDStyle contains two properties: a type property which is set to SLDStyle and a version property which at the time of the UDIG version 1.0 release is set to 1.0. The StyleMemento contains an SLD document formatted string in its text field. The SLD document can be retrieved using the getTextData() method call.
SLDEditor is the default Style Editor class has been included since the 0.5 release.
The following the code SLDStyle uses to create its StyleMemento:
//Write Style to a string in SLD format
SLDTransformer transformer=new SLDTransformer();
String out=null;
try {
out = transformer.transform(this);
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//create and fill out StyleMemento object
StyleMemento memo=new StyleMemento("SLDStyle", getName(), "net.refractions.udig.project.SLDStyle");
memo.putTextData(out);
memo.putString("type","SLDStyle");
memo.putString("version","1.0");
return memo;
Refractions Research Inc. 2008