Class ALcyLspStyleFormat

Direct Known Subclasses:
TLcyLspRasterFormat, TLcyLspVectorFormat

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.

Configuration options

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.

Since:
2012.0
  • Constructor Details

    • ALcyLspStyleFormat

      protected ALcyLspStyleFormat(ILcyLucyEnv aLucyEnv, String aLongPrefix, String aShortPrefix, ALcyProperties aPreferences, ILcdFilter<ILcdModel> aModelFilter)
      Create a new style format
      Parameters:
      aLucyEnv - The Lucy back-end
      aLongPrefix - The long prefix of this format.
      aShortPrefix - The short prefix of this format
      aPreferences - The preferences
      aModelFilter - 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.
  • Method Details

    • createAll

      public void createAll()
      Description copied from class: 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.

      Overrides:
      createAll in class ALcyLspFormat
    • createLayerFactoryImpl

      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.

      Layer requirements

      The layers returned by this layer factory should match the following requirements:

      Layer styling

      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;
           }
        };
       
      Specified by:
      createLayerFactoryImpl in class ALcyLspStyleFileFormat
      Returns:
      The layer factory for this format. May be null
    • retrieveFeatureTypeStyle

      protected final TLcdSLDFeatureTypeStyle retrieveFeatureTypeStyle(ILcdModel aModel)

      Utility method which tries to find a TLcdSLDFeatureTypeStyle for the specified model. It will return:

      • The parsed SLD file located next to the source file of the model, if available.
      • The configured default style file if that is an SLD file.
      • null otherwise.
      Parameters:
      aModel - The model
      Returns:
      The TLcdSLDFeatureTypeStyle for aModel
      Since:
      2017.0
      See Also:
    • createLayerStyleProviders

      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.

      Overrides:
      createLayerStyleProviders in class ALcyLspFormat
      Returns:
      The style provider to retrieve and encode the style of the layers. Must not be null. The array may be empty, but must not contain null.
      See Also:
    • createLayerStyleCodecs

      protected ILcyLayerStyleCodec[] createLayerStyleCodecs()
      Description copied from class: 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.

      Overrides:
      createLayerStyleCodecs in class ALcyLspStyleFileFormat
      Returns:
      an array of ILcyLayerStyleCodec instances. Must not be null. The array may be empty, but must not contain null.
      See Also:
    • createLayerStyleCodecFileTypeDescriptors

      protected ALcyFileTypeDescriptor[] createLayerStyleCodecFileTypeDescriptors()
      Description copied from class: ALcyLspStyleFileFormat

      Creates ALcyFileTypeDescriptors for the ILcyLayerStyleCodecs. 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 ALcyFileTypeDescriptors 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 ALcyFileTypeDescriptors. When no ALcyFileTypeDescriptors are available (or only null ALcyFileTypeDescriptors) 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.

      Overrides:
      createLayerStyleCodecFileTypeDescriptors in class ALcyLspStyleFileFormat
      Returns:
      An array of 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.
      See Also:
    • createLayerStyleCodecImpl

      protected ILcyLayerStyleCodec createLayerStyleCodecImpl()
      Description copied from class: ALcyLspStyleFileFormat
      Creates the actual ILcyLayerStyleCodec
      Specified by:
      createLayerStyleCodecImpl in class ALcyLspStyleFileFormat
      Returns:
      a new ILcyLayerStyleCodec for the layers of this format. Must not be null.
      See Also: