public abstract class ALcyLspStyleFormat extends ALcyLspStyleFileFormat
This ALcyLspFormat
implementation is designed for layers styled using SLD or for layers using an
ILspCustomizableStyler
.
The format provides full style support for such layers (saving, loading and copying of the style and workspace support
for both the layer and its style).
This format creates default implementations for the ILcyLayerStyleProvider
and
the ILcyLayerStyleCodec
.
The only thing remaining for the extensions of this class is to provide a layer factory
.
The layers created by this layer factory must fulfil the requirements listed in the javadoc of the
createLayerFactoryImpl()
method.
More specialized extensions of this class are available with a default layer factory. Consult the javadoc of these classes to see whether your format can benefit from this default implementation.
This format checks for the following properties in the ALcyProperties
:
# Configuration of the file type descriptor for the style files
# These style files contain the settings for a layer styled using an ILspCustomizableStyler
shortPrefix.style.fileTypeDescriptor.displayName = Style Files
shortPrefix.style.fileTypeDescriptor.defaultExtension = sty
shortPrefix.style.fileTypeDescriptor.filters = *.sty
shortPrefix.style.fileTypeDescriptor.groupIDs = All Style Files
# The path to the file containing the default style to apply on each created layer
# This file should be a match for an SLD file (*.sld) or customizable style file type descriptor as defined above
shortPrefix.defaultStyleFile = path/to/defaultStyleFile.sty
Warning: this format should only be used when the created layers fulfill the requirements
documented in createLayerFactoryImpl()
.
If your layers cannot meet those requirements, it might be better to extend from ALcyLspStyleFileFormat
or
ALcyLspGeneralFormat
directly.
Warning: this format should be wrapped with a TLcyLspSafeGuardFormatWrapper
before plugging it into the Lucy back-end.
DEFAULT_STYLE_FILE_SUFFIX
Modifier | Constructor and Description |
---|---|
protected |
ALcyLspStyleFormat(ILcyLucyEnv aLucyEnv,
String aLongPrefix,
String aShortPrefix,
ALcyProperties aPreferences,
ILcdFilter<ILcdModel> aModelFilter)
Create a new style format
|
Modifier and Type | Method and Description |
---|---|
void |
createAll()
Creates all the instances of the concepts of this class by calling all the abstract
create<Concept> methods, and performs some validity checks on the created
values. |
protected abstract ILspLayerFactory |
createLayerFactoryImpl()
Creates the layer factory for this format.
|
protected ALcyFileTypeDescriptor[] |
createLayerStyleCodecFileTypeDescriptors()
Creates
ALcyFileTypeDescriptor s for the ILcyLayerStyleCodec s. |
protected ILcyLayerStyleCodec |
createLayerStyleCodecImpl()
Creates the actual
ILcyLayerStyleCodec |
protected ILcyLayerStyleCodec[] |
createLayerStyleCodecs()
Creates the
ILcyLayerStyleCodec instances which can encode/decode the style of
the layers created by the layer factory of this format. |
protected ILcyLayerStyleProvider[] |
createLayerStyleProviders()
Creates the style provider instances that can retrieve and encode the style of the layers
created by the layer factory of this format.
|
protected TLcdSLDFeatureTypeStyle |
retrieveFeatureTypeStyle(ILcdModel aModel)
Utility method which tries to find a
TLcdSLDFeatureTypeStyle for the specified model. |
canHandleModel, createLayerFactory
getLongPrefix, getLucyEnv, getProperties, getShortPrefix
checkInitialized, createBalloonContentProviders, createFormatBarFactory, createLayerContextOfFormatFilter, createLayerCustomizerPanelFactories, createLayerCustomizerPanelWorkspaceCodecs, createLayerMeasureProviderFactory, createLayerSelectionTransferHandlers, createLayerWorkspaceCodecs, getBalloonContentProviders, getFormatBarFactory, getLayerCustomizerPanelFactories, getLayerCustomizerPanelWorkspaceCodecs, getLayerFactory, getLayerMeasureProviderFactory, getLayerSelectionTransferHandlers, getLayerStyleCodecFileTypeDescriptors, getLayerStyleCodecs, getLayerStyleProviders, getLayerWorkspaceCodecs, isLayerOfFormat, toString
protected ALcyLspStyleFormat(ILcyLucyEnv aLucyEnv, String aLongPrefix, String aShortPrefix, ALcyProperties aPreferences, ILcdFilter<ILcdModel> aModelFilter)
aLucyEnv
- The Lucy back-endaLongPrefix
- The long prefix of this format.aShortPrefix
- The short prefix of this formataPreferences
- The preferencesaModelFilter
- Filter used to determine whether a model can be handled by this format.
When the model can be handled by this format, it should be accepted by the
filter. Filter must not be null
. null
models will
never be passed to the filter, but always rejected.public void createAll()
ALcyLspFormat
Creates all the instances of the concepts of this class by calling all the abstract
create<Concept>
methods, and performs some validity checks on the created
values. All created instances can later on be retrieved by calling the appropriate
get<Concept>
methods.
createAll
in class ALcyLspFormat
protected abstract ILspLayerFactory createLayerFactoryImpl()
Creates the layer factory for this format. This method will be called from the ALcyLspStyleFileFormat.createLayerFactory()
method. This factory must not return ILcdLayerTreeNode
instances. In case you want
to support empty nodes, consider using a TLcyLspLayerTreeNodeFormatWrapper
.
The layers returned by this layer factory should match the following requirements:
ILspStyledLayer
interface.TLspShapeLayerBuilder.sldStyle(TLcdSLDFeatureTypeStyle)
or TLspRasterLayerBuilder.sldStyle(TLcdSLDFeatureTypeStyle)
.REGULAR_BODY
and the
REGULAR_LABEL
stylers must be ILspCustomizableStyler
instances containing regular
ALspStyle
instances.The default style of this format as defined in the default style file will be automatically applied on each layer. If a style is present next to the model source file of the layer, this style will be applied as well. It is not necessary to include this functionality in the layer factory returned by this method.
Note however that an SLD style file can only be applied on layers which use SLD styling, and
customizable styler based style files can only be applied on layers which use an ILspCustomizableStyler
.
This means that the layer factory decides which kind of styling is available for which layer.
To facilitate this, this format has a utility method
to check whether SLD styling can be found for
a certain model.
The layer factory can opt to use this method to decide between SLD based styling or customizable styler based styling.
An example implementation of this method could be:
return new ALspSingleLayerFactory() {
@Override
public ILspLayer createLayer(ILcdModel aModel) {
//This example implementation assumes the data is vector data
TLcdSLDFeatureTypeStyle featureTypeStyle = retrieveFeatureTypeStyle(aModel);
if(featureTypeStyle == null){
//create a customizable styler with default styles and set it on the layer
TLspCustomizableStyler bodyStyler = new TLspCustomizableStyler(
TLspLineStyle.newBuilder().elevationMode(ILspWorldElevationStyle.ElevationMode.ON_TERRAIN)
.color(Color.WHITE)
.width(2)
.build(),
TLspFillStyle.newBuilder().elevationMode(ILspWorldElevationStyle.ElevationMode.ON_TERRAIN)
.color(new Color(255, 255, 0, 128))
.build(),
TLspIconStyle.newBuilder().icon(new TLcdSymbol(TLcdSymbol.FILLED_RECT, 5)).build()
);
return TLspShapeLayerBuilder.newBuilder()
.model(aModel)
.bodyStyler(TLspPaintState.REGULAR, bodyStyler)
.build();
} else {
//Create a layer which uses SLD styling
return TLspShapeLayerBuilder.newBuilder()
.model(aModel)
.sldStyle(featureTypeStyle)
.build();
}
}
@Override
public boolean canCreateLayers(ILcdModel aModel) {
//the format should be wrapped with a TLcyLspSafeGuardFormatWrapper so we can just return true
return true;
}
};
createLayerFactoryImpl
in class ALcyLspStyleFileFormat
null
protected final TLcdSLDFeatureTypeStyle retrieveFeatureTypeStyle(ILcdModel aModel)
Utility method which tries to find a TLcdSLDFeatureTypeStyle
for the specified model.
It will return:
null
otherwise.aModel
- The modelTLcdSLDFeatureTypeStyle
for aModel
createLayerFactoryImpl()
protected final ILcyLayerStyleProvider[] createLayerStyleProviders()
Creates the style provider instances that can retrieve and encode the style of the layers created by the layer factory of this format.
The default implementation returns an empty array.
Returns an array of ILcyLayerStyleProvider
instances, capable of
handling the layers created by this format.
createLayerStyleProviders
in class ALcyLspFormat
null
. The array may be empty, but must not contain null
.ALcyLspFormat.getLayerStyleProviders()
protected ILcyLayerStyleCodec[] createLayerStyleCodecs()
ALcyLspStyleFileFormat
Creates the ILcyLayerStyleCodec
instances which can encode/decode the style of
the layers created by the layer factory of this format.
The default implementation returns an empty array.
The default implementation returns an array containing the ILcyLayerStyleCodec
created
in ALcyLspStyleFileFormat.createLayerStyleCodecImpl()
.
Warning: when overriding this method, make sure to either return an array of length
1 or to override ALcyLspStyleFileFormat.createLayerStyleCodecFileTypeDescriptors()
as well.
createLayerStyleCodecs
in class ALcyLspStyleFileFormat
ILcyLayerStyleCodec
instances. Must not be null
.
The array may be empty, but must not contain null
.ALcyLspStyleFileFormat.createLayerStyleCodecFileTypeDescriptors()
protected ALcyFileTypeDescriptor[] createLayerStyleCodecFileTypeDescriptors()
ALcyLspStyleFileFormat
Creates ALcyFileTypeDescriptor
s for the ILcyLayerStyleCodec
s. The
length of the returned array must be equal to that of ALcyLspFormat.createLayerStyleCodecs()
.
The default implementation returns a zero-length array.
This format uses these ALcyFileTypeDescriptor
instances to determine
whether a style file is located next to source file of a layer, and apply that style when
such a layer is created in the layer factory. The layer factory will only try to find style files
with an extension defined by the returned ALcyFileTypeDescriptor
s of this method.
Another example usage of these ALcyFileTypeDescriptor
instances is the File | Save layer style
action which is available in Lucy. It allows to save the style of a layer to a file ending with
an extension as specified by these ALcyFileTypeDescriptor
s. When no
ALcyFileTypeDescriptor
s are available (or only null
ALcyFileTypeDescriptor
s) it will not be possible to save
the layer style to file.
The default implementation returns a file type descriptor based on the info contained in the properties of this format, or a default file type descriptor in case the properties do not contain this info. The file type descriptor can be configured in the configuration file as follows (where "shortPrefix." stands for the short prefix of this format):
shortPrefix.style.fileTypeDescriptor.displayName=... shortPrefix.style.fileTypeDescriptor.defaultExtension=... shortPrefix.style.fileTypeDescriptor.filters=... shortPrefix.style.fileTypeDescriptor.groupIDs=...
Warning: when overriding this method, make sure to either return an array of length
1 or to override ALcyLspStyleFileFormat.createLayerStyleCodecs()
()} as well.
createLayerStyleCodecFileTypeDescriptors
in class ALcyLspStyleFileFormat
ALcyFileTypeDescriptor
instances. Must not be null
and its length must be equal to the length of the array of layer style encoders created
by this format. May contain null
.ALcyLspStyleFileFormat.createLayerStyleCodecs()
protected ILcyLayerStyleCodec createLayerStyleCodecImpl()
ALcyLspStyleFileFormat
ILcyLayerStyleCodec
createLayerStyleCodecImpl
in class ALcyLspStyleFileFormat
ILcyLayerStyleCodec
for the layers of this format. Must not be null
.ALcyLspStyleFileFormat.createLayerStyleCodecs()