Interface DrawableFactory
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.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enum
Priority of transformations being made on vertices and prototypes. -
Method Summary
Modifier and TypeMethodDescriptioncreateDrawable
(MTCompleteEdge edge) Creates a drawable used for rendering an edge.createDrawable
(EdgeType edgeType) Creates a drawable for an edge type that can be used to render for example an icon.createDrawable
(ModelType modelType) Creates a drawable for a model type.createDrawable
(SymbolVariant symbolVariant) Creates a drawable for a symbol variant.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.getTransformPriority
(MTCompleteModel model, SymbolVariant variant) Returns the transformation priority for a prototype being transformed by this factory.getTransformPriority
(MTCompleteVertex vertex) Returns the transformation priority for a vertex being transformed by this factory.getType()
boolean
supportsEdgeType
(EdgeType edgeType) Should returntrue
if this factory can supply drawables for a given edge type.boolean
supportsModelType
(ModelType modelType) Should returntrue
if this factory can supply drawables for a given model type.boolean
supportsSymbolVariant
(SymbolVariant variant) Should returntrue
if this factory can supply drawables for a given symbol variant.default boolean
Should returntrue
if this factory wants to receive calls totransformDrawable
,transformPrototypeDrawable
ortransformIcon
when the vertex is located in a model of the given model type.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.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.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.
-
Method Details
-
getIdentifier
String getIdentifier() -
getType
String getType() -
supportsModelType
Should returntrue
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
Should returntrue
if this factory wants to receive calls totransformDrawable
,transformPrototypeDrawable
ortransformIcon
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
Creates a drawable for a model type. To use an icon as a drawable for the model type useDrawableSupport.createIconDrawable
.- Parameters:
modelType
- The model type to create a drawable for.- Returns:
- A drawable representing the model type.
-
supportsSymbolVariant
Should returntrue
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
Creates a drawable for a symbol variant. To create a drawable from an SVG data source useDrawableSupport.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
Should returntrue
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
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 callDrawableSupport.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
Creates a drawable used for rendering an edge. To use the default drawable for the edge callDrawableSupport.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
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 (seesupportsVertexTransform
). Note that this method must not returnnull
. 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 benull
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 returnfalse
fromisUsingColorScheme
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 (seesupportsVertexTransform
). Note that this method must not returnnull
. If no transform is to be made it should return the drawable that was passed as an argument. Note that this method must not returnnull
. 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 benull
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 returnfalse
fromisUsingColorScheme
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
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 returnnull
, 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.
-