Interface DrawableFactory


public interface DrawableFactory
Implemented to provide drawables for models, symbols and edges. The implementation can use an instance of DrawableSupport (available as a service through OSGi) to reuse existing functionality for creating SVG drawables for symbols, icon drawables for icons and the default edge drawables for rendering edges.
  • Method Details

    • getIdentifier

      String getIdentifier()
    • getType

      String getType()
    • supportsModelType

      boolean supportsModelType(ModelType modelType)
      Should return true if this factory can supply drawables for a given model type.
      Parameters:
      modelType - The model type.
      Returns:
      true if this factory can supply a drawable for this type.
    • supportsVertexTransform

      default boolean supportsVertexTransform(ModelType type)
      Should return true if this factory wants to receive calls to transformDrawable, transformPrototypeDrawable or transformIcon when the vertex is located in a model of the given model type.
      Parameters:
      type - The type of the model.
      Returns:
      True if this factory wants an opportunity to transform drawables for a vertex or prototype located in a model of the given type, false otherwise.
    • createDrawable

      Drawable createDrawable(ModelType modelType)
      Creates a drawable for a model type. To use an icon as a drawable for the model type use DrawableSupport.createIconDrawable.
      Parameters:
      modelType - The model type to create a drawable for.
      Returns:
      A drawable representing the model type.
    • supportsSymbolVariant

      boolean supportsSymbolVariant(SymbolVariant variant)
      Should return true if this factory can supply drawables for a given symbol variant.
      Parameters:
      variant - The symbol variant.
      Returns:
      true if this factory can supply a drawable for this variant.
    • createDrawable

      Drawable createDrawable(SymbolVariant symbolVariant)
      Creates a drawable for a symbol variant. To create a drawable from an SVG data source use DrawableSupport.createSVGDrawable.

      This method should never be invoked unless this factory supports the variant. It is recommended that an IllegalArgumentException is thrown if this factory does not support the variant, but the only guarantee that this factory makes is that either an exception is thrown or null is returned. The factory must not return a drawable.

      Parameters:
      symbolVariant - The symbol variant to create a drawable for.
      Returns:
      A drawable representing the symbol variant.
      Throws:
      IllegalArgumentException - If this factory does not support the symbol variant.
    • supportsEdgeType

      boolean supportsEdgeType(EdgeType edgeType)
      Should return true if this factory can supply drawables for a given edge type.
      Parameters:
      edgeType - The edge type.
      Returns:
      true if this factory can supply a drawable for this type.
    • createDrawable

      Drawable createDrawable(EdgeType edgeType)
      Creates a drawable for an edge type that can be used to render for example an icon. Since no actual path is available for an edge this is only a drawable representing the type. To use the default drawable for the type call DrawableSupport.createDefaultEdgeDrawable

      This method should never be invoked unless this factory supports the type. It is recommended that an IllegalArgumentException is thrown if this factory does not support the type, but the only guarantee that this factory makes is that either an exception is thrown or null is returned. The factory must not return a drawable.

      Parameters:
      edgeType - The edge type to create a drawable for.
      Returns:
      A drawable representing the edge type.
      Throws:
      IllegalArgumentException - If this factory does not support the edge type.
    • createDrawable

      Drawable createDrawable(MTCompleteEdge edge)
      Creates a drawable used for rendering an edge. To use the default drawable for the edge call DrawableSupport.createDefaultEdgeDrawable. If the implementation provides a custom drawable for the edge it should still take the edge shape into consideration (available through edge.getPath().getShape()), to remain consistent with how the edge is routed.

      This method should never be invoked unless this factory supports the edge's edge type. It is recommended that an IllegalArgumentException is thrown if this factory does not support the type, but the only guarantee that this factory makes is that either an exception is thrown or null is returned. The factory must not return a drawable.

      Parameters:
      edge - The edge to create a drawable for.
      Returns:
      A drawable for the edge
      Throws:
      IllegalArgumentException - If this factory does not support the edge's edge type.
    • getTransformPriority

      default DrawableFactory.TransformPriority getTransformPriority(MTCompleteVertex vertex)
      Returns the transformation priority for a vertex being transformed by this factory. Transforms with high priority will be called after transforms with low and default priorities.
      Parameters:
      vertex - The vertex being transformed.
      Returns:
      A transform priority.
    • getTransformPriority

      default DrawableFactory.TransformPriority getTransformPriority(MTCompleteModel model, SymbolVariant variant)
      Returns the transformation priority for a prototype being transformed by this factory. Transforms with high priority will be called after transforms with low and default priorities.
      Parameters:
      model - The model the prototype is being placed in.
      variant - The variant of the prototype.
      Returns:
      A transform priority.
    • transformDrawable

      Drawable transformDrawable(Drawable drawable, MTCompleteVertex vertex, DrawableRenderer<Graphics2D> renderer, MTColorScheme colorScheme)
      The factory can transform the vertex in some way if necessary given the actual vertex as context. This will be called first for any factories supporting the symbol variant and then for any factories supporting the transformation in the vertex's model (see supportsVertexTransform). Note that this method must not return null. If no transform is to be made it should return the drawable that was passed as an argument. NOTE: any factory not supporting the symbol variant or model type should still make sure to return the same drawable. This will ensure correct behavior if this implementation is changed in the future to allow all factories to transform the drawable. NOTE: This method will only be called once if both the symbol variant and the model type is supported and this will be in the first iteration (factories supporting the symbol variant).
      Parameters:
      drawable - The drawable to transform.
      vertex - The vertex to transform.
      renderer - A renderer that can be used to create an image of the existing drawable if needed. Note that the renderer could be null if no renderer service is started.
      colorScheme - The current color scheme used. This can be used to transform certain colors in the transformed drawable using the color scheme. The transformed drawable can then return false from isUsingColorScheme to avoid any further color transformations during rendering.
      Returns:
      A transformed drawable, or the same drawable passed in to make no changes.
    • transformPrototypeDrawable

      Drawable transformPrototypeDrawable(Drawable drawable, SymbolVariant variant, MTCompleteModel model, DrawableRenderer<Graphics2D> renderer, MTColorScheme colorScheme)
      The factory can transform the prototype drawn when placing a new vertex in some way if necessary given the variant being placed and the model as context. This will be called first for any factories supporting the symbol variant and then for any factories supporting the transformation in the vertex's model (see supportsVertexTransform). Note that this method must not return null. If no transform is to be made it should return the drawable that was passed as an argument. Note that this method must not return null. If no transform is to be made it should return the drawable that was passed as an argument. NOTE: any factory not supporting the symbol variant or model type should still make sure to return the same drawable. This will ensure correct behavior if this implementation is changed in the future to allow all factories to transform the drawable. NOTE: This method will only be called once if both the symbol variant and the model type is supported and this will be in the first iteration (factories supporting the symbol variant).
      Parameters:
      drawable - The drawable to transform.
      variant - The variant that the drawable represents.
      model - The model that the prototype is placed in.
      renderer - A renderer that can be used to create an image of the existing drawable if needed. Note that the renderer could be null if no renderer service is started.
      colorScheme - The current color scheme used. This can be used to transform certain colors in the transformed drawable using the color scheme. The transformed drawable can then return false from isUsingColorScheme to avoid any further color transformations during rendering.
      Returns:
      A transformed drawable, or the same drawable passed in to make no changes.
    • transformIcon

      default Icon transformIcon(Icon icon, SymbolVariant variant, MTCompleteModel model, MTColorScheme colorScheme)
      Lets the factory transform an icon used for a symbol variant in a given model.
      Parameters:
      icon - The icon to transform.
      variant - The symbol variant the icon is created for.
      model - The model the icon is created for.
      colorScheme - The current color scheme.
      Returns:
      A transformed icon or the same icon that was passed in to do no transformation.
    • decorateDrawable

      Drawable decorateDrawable(Drawable drawable, MTCompleteVertex vertex)
      The factory can choose to decorate the drawable for a vertex in some way by returning a new drawable that draws something on top of the current drawable. This will be called for all factories, not just the one supporting the symbol type or model type of the vertex. Note that this method may not return null, if no decorator is needed it should return the drawable that was passed as an argument.
      Parameters:
      drawable - The drawable to decorate.
      vertex - The vertex that the given drawable represents.
      Returns:
      A decorated drawable, or the same drawable passed in to make no changes.