StyleDefinition

net.refractions.udig.core.StyleDefinition

0.3.0

Styles are represented as a Memento object which contains style information as a tree of mementos each of which contains strings. Only the renderers that render a layer know the concrete style class. This means that only certain renderers are capable of rendering certain styles. However as far as UDig is concerned a style is a memento. This causes problems with the user interface because udig does not know anything about the style. To overcome this limitation a style must be associated with an editor dialog. The editor must extend the StyleEditor class.

<!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.



net.refractions.udig.project.impl.render.SLDEditor net.refractions.udig.project.impl.render.SLDStyle

A plugin that defines a style (Note: a single plugin could define a style and a renderer) must implement a net.refractions.udig.project.impl.render.StyleEditor and a class that implements the Style interface. The StyleEditor interface extends eclipse's IDialogPage interface and contains an additional init() method that accepts a StyleMemento object as a parameter. The StyleMemento contains the style information that the editor can edit. The other method is getMemento which returns a StyleMemento object.

SLDStyle is the Style included with uDig. It is essentially a adapter for Geotool's Style objects. The StyleMemento 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;