Search this API

y.view
Class GenericEdgeRealizer

java.lang.Object
  extended by y.view.EdgeRealizer
      extended by y.view.GenericEdgeRealizer
All Implemented Interfaces:
EdgeLayout, MouseInputEditorProvider

public class GenericEdgeRealizer
extends EdgeRealizer
implements MouseInputEditorProvider

This class can be used to easily create customized edge appearances. In contrast to the older yFiles way, developers don't need to and normally should not subclass this class in order to create a new visual appearance, but may use pluggable instances of specialized interfaces to replace different phases of the edge rendering process.

This class knows multiple inner interfaces that can be used as callback routines to customize

This class provides access to a factory, that is used by the implementation to manage different edge style configurations.

Programmers have to use that factory to register different style configurations using their own implementations of the interfaces described above.

Instances of this class correctly implement the createCopy(EdgeRealizer) method and IO methods (read(ObjectInputStream) and write(ObjectOutputStream)) so that programmers don't have to re-implement these methods for each and every realizer specialization.

Finally, this class makes it possible to generically attach user-defined data to realizer instances which may then be used for arbitrary purposes.

This type of realizer can be serialized and deserialized into the YGF graph exchange file format using the YGFIOHandler (if an appropriate GenericEdgeRealizer.UserDataHandler instance is registered, the user-defined data object can be serialized and deserialized, too).

GMLIOHandler and XGMLIOHandler also support serialization and deserialization of this kind of realizer (in this case the user-defined data is written to the GML file if an appropriate ObjectStringConverter is registered with the global ObjectStringConversion singleton.

Note that only the name of the configuration and optionally the user-defined data will be stored and that it is the responsibility of the application to register and configure the configurations in the factory so that the I/O mechanisms can serialize and deserialize the information correctly.

The following piece of code demonstrates how to correctly initialize a custom generic edge realizer.

 // Get the static default factory instance
 GenericEdgeRealizer.Factory factory = GenericEdgeRealizer.getFactory();

 // Retrieve a map that holds the default GenericEdgeRealizer configuration.
 // The implementations contained therein can be replaced one by one in order
 // to create custom configurations...
 Map implementationsMap = factory.createDefaultConfigurationMap();

 // create and register customizations...

 // e.g. create a custom painter
 // (see demo.view.realizer.GenericEdgeRealizerDemo for example implementations)
 MyCustomPainter painter = new MyCustomPainter();
 // put it into the map using the interface class as the key
 implementationsMap.put(GenericEdgeRealizer.Painter.class, painter);

 // add the configuration using an arbitrary String identifier to the factory
 factory.addConfiguration("type1", implementationsMap);

 // now create an instance that uses our customizations
 GenericEdgeRealizer er = new GenericEdgeRealizer();
 // initialize the instance using the previously registered configuration
 er.setConfiguration("type1");
 

Note that each custom configuration must contain implementations for interfaces GenericEdgeRealizer.BendHandler and GenericEdgeRealizer.PathCalculator to form a valid configuration.

See Also:
GenericEdgePainter, SimpleUserDataHandler, GenericNodeRealizer
 

Nested Class Summary
static interface GenericEdgeRealizer.ArrowPainter
          This interface is used as a callback by EdgeRealizer to paint the arrows.
static interface GenericEdgeRealizer.BendHandler
          This interface is used as a callback by GenericEdgeRealizer to handle the list of bends.
static interface GenericEdgeRealizer.BendPainter
          This interface is used as a callback by GenericEdgeRealizer to paint the bends.
static interface GenericEdgeRealizer.BridgeCalculatorHandler
          This interface is used as a callback by GenericEdgeRealizer to insert obstacles into a given BridgeCalculator instance for a two-pass rendering.
static interface GenericEdgeRealizer.ContainsTest
          This interface is used as a callback by GenericEdgeRealizer to evaluate hit tests.
static class GenericEdgeRealizer.Factory
          This class is used for managing the different configurations for GenericEdgeRealizer instances.
static interface GenericEdgeRealizer.GenericMouseInputEditorProvider
          This interface is used by GenericEdgeRealizer to delegate the work of the MouseInputEditorProvider interface to.
static interface GenericEdgeRealizer.Initializer
          This interface is used by GenericEdgeRealizer for initialization purposes.
static interface GenericEdgeRealizer.IntersectionTest
          This interface is used as a callback by GenericEdgeRealizer to evaluate intersection tests.
static interface GenericEdgeRealizer.LabelFactory
          This interface is used by GenericEdgeRealizer to delegate the work of the createEdgeLabel() method to.
static interface GenericEdgeRealizer.LabelPainter
          This interface is used as a callback by EdgeRealizer to paint the labels.
static interface GenericEdgeRealizer.Painter
          This interface is used as a callback by GenericEdgeRealizer to perform the painting.
static interface GenericEdgeRealizer.PathCalculator
          This interface is used as a callback by GenericEdgeRealizer to calculate the final path.
static interface GenericEdgeRealizer.PortPainter
          This interface is used as a callback by GenericEdgeRealizer to paint the ports.
static interface GenericEdgeRealizer.SelectionChangeHandler
          This interface is used by GenericEdgeRealizer to notify interested parties of selection state changes.
static interface GenericEdgeRealizer.UnionRectCalculator
          This interface is used as a callback by GenericEdgeRealizer to calculate the bounds.
static interface GenericEdgeRealizer.UserDataHandler
          This interface is used by GenericEdgeRealizer to delegate the copying and serialization/deserialization of any user-defined data to.
 
Field Summary
 
Fields inherited from class y.view.EdgeRealizer
bends, path, PATH_CLIPPED_AT_SOURCE, PATH_CLIPPED_AT_SOURCE_AND_TARGET, PATH_CLIPPED_AT_TARGET, PATH_INVISBLE, PATH_UNCLIPPED
 
Constructor Summary
GenericEdgeRealizer()
          Creates a new instance of GenericEdgeRealizer using the default configuration.
GenericEdgeRealizer(EdgeRealizer er)
          Creates a new instance of GenericEdgeRealizer which is a copy of the given realizer instance.
GenericEdgeRealizer(java.lang.String configuration)
          Creates a new instances of GenericEdgeRealizer using the given configuration.
 
Method Summary
 void bendChanged(Bend b, double oldX, double oldY)
          Informs the edge, that a bend has changed position By default this method does nothing.
protected  byte calculatePath(java.awt.geom.Point2D sourceIntersectionPointOut, java.awt.geom.Point2D targetIntersectionPointOut)
          Calculates the visible path of this realizer.
 void calcUnionRect(java.awt.geom.Rectangle2D r)
          Calculates the union of rectangle enclosed by this realizer and r.
 void clearBends()
          Removes all bends from this realizer.
 boolean contains(double x, double y)
          Query if the visible path of this realizer contains the point (x,y).
 int containsSeg(double x, double y)
          like contains(), but returns number of the hit segment, 0 otherwise.
 Bend createBend(double x, double y, Bend refBend, int dir)
          Adds a new bend before or after the given reference bend.
 EdgeRealizer createCopy(EdgeRealizer er)
          Returns a realizer of the same type as this realizer, that adopts as many attributes as possible from the given realizer.
 EdgeLabel createEdgeLabel()
          Creates a new edge label that can be added to this realizer.
 MouseInputEditor findMouseInputEditor(Graph2DView view, double x, double y, HitInfo hitInfo)
          Uses the registered GenericEdgeRealizer.GenericMouseInputEditorProvider implementation to delegate the actual work to.
 java.lang.String getConfiguration()
          Returns the name of the current configuration for this GenericEdgeRealizer
static GenericEdgeRealizer.Factory getFactory()
          Returns the factory instance that will be used to read and write customization configurations.
 int getMinBendCount()
          Returns the minimal number of bends the edge must have.
 MouseInputEditorProvider getMouseInputEditorProvider()
          Returns a provider, that can be used to query for a mouse input editor for this realizer.
 java.util.Set getStyleProperties()
          Yields a Set of Map.Entry instances that contains all property value pairs that have been associated with this instance via the setStyleProperty(String, Object) method.
 java.lang.Object getStyleProperty(java.lang.String propertyKey)
          Retrieves the value of the property that has been stored with this instance for the given key using setStyleProperty(String, Object)
 java.lang.Object getUserData()
          Returns the user-defined data object.
 Bend insertBend(double x, double y)
          Inserts a new bend into this realizer and returns it.
 void paint(java.awt.Graphics2D gfx)
          Paints this realizer on the given graphics context.
protected  void paintArrows(java.awt.Graphics2D g)
          Paints the arrows of this realizer.
protected  void paintBends(java.awt.Graphics2D gfx)
          Paints the bends if they are in selected state.
protected  void paintHighlightedBends(java.awt.Graphics2D gfx)
          Paints the bends if this realizer is in a selected state
protected  void paintLabels(java.awt.Graphics2D gfx)
          Paints the labels belonging to this realizer.
protected  void paintPorts(java.awt.Graphics2D gfx)
          Paints the ports of this realizer.
 void paintSloppy(java.awt.Graphics2D gfx)
          Paints this realizer in a quick and rather sloppy way.
 boolean pathIntersects(java.awt.geom.Rectangle2D box, boolean considerLabels)
          This method complements the EdgeRealizer.contains(double,double) method.
 void read(java.io.ObjectInputStream in)
          Reads in the serialized form of this realizer.
 void registerObstacles(BridgeCalculator calculator)
          This callback method is e.g. by DefaultGraph2DRenderer if a BridgeCalculator is used for the rendering whose crossing mode is set to values other than BridgeCalculator.CROSSING_MODE_ORDER_INDUCED.
 void reInsertBend(Bend bend, Bend refBend, int dir)
          Reinserts a bend to the edge which had been removed before.
 Bend removeBend(Bend b)
          Removes a Bend of this realizer.
 void removeStyleProperty(java.lang.String propertyKey)
          Removes a previously stored style property from this instance's set of style properties.
 void setConfiguration(java.lang.String configuration)
          Configures this instance to use the implementations provided by the factory under the given configuration name.
 void setStyleProperty(java.lang.String propertyKey, java.lang.Object value)
          Sets a named key value pair that is a property which can be used by the implementations in the configuration to retrieve per instance settings.
 void setUserData(java.lang.Object userData)
          Sets the user-defined data object.
 void write(java.io.ObjectOutputStream out)
          Deprecated. Use the GraphML format instead.
 
Methods inherited from class y.view.EdgeRealizer
addLabel, addPoint, appendBend, bendCount, bendPos, bends, bindEdge, calculateClippingAndIntersection, clearPoints, createCopy, firstBend, getArrow, getArrowScaleFactor, getBend, getEdge, getHighlightedBendColor, getLabel, getLabel, getLabelText, getLayer, getLineColor, getLineType, getPath, getPoint, getSelectionColor, getSelectionStroke, getSourceArrow, getSourceIntersection, getSourcePoint, getSourcePort, getSourceRealizer, getTargetArrow, getTargetIntersection, getTargetPoint, getTargetPort, getTargetRealizer, hasVisiblePath, intersects, isDirty, isLabelRenderingOrderInverted, isPathClippedAtSource, isPathClippedAtTarget, isReversedPathRenderingEnabled, isSelected, isVisible, labelBoundsChanged, labelCount, lastBend, pointCount, recalculateFeatures, removeLabel, removeLabel, repaint, setArrow, setDirty, setHighlightedBendColor, setLabelRenderingOrderInverted, setLabelText, setLayer, setLineColor, setLineType, setPoint, setPorts, setReversedPathRenderingEnabled, setSelected, setSelectionColor, setSelectionStroke, setSourceArrow, setSourcePoint, setSourcePort, setTargetArrow, setTargetPoint, setTargetPort, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericEdgeRealizer

public GenericEdgeRealizer()
Creates a new instance of GenericEdgeRealizer using the default configuration. The default configuration renders a poly-line edge path.

See Also:
setConfiguration(String)

GenericEdgeRealizer

public GenericEdgeRealizer(java.lang.String configuration)
Creates a new instances of GenericEdgeRealizer using the given configuration. The configuration must have been registered with the factory before.

Parameters:
configuration - the identifier of the configuration to use
Throws:
java.lang.IllegalArgumentException - if configuration is not registered in the factory
See Also:
GenericEdgeRealizer.Factory.addConfiguration(String, java.util.Map)

GenericEdgeRealizer

public GenericEdgeRealizer(EdgeRealizer er)
Creates a new instance of GenericEdgeRealizer which is a copy of the given realizer instance. Note that if er is not of type GenericEdgeRealizer, the default configuration will be used for the new GenericEdgeRealizer object.

Parameters:
er - The realizer to copy the values from.
See Also:
setConfiguration(String)
Method Detail

getFactory

public static GenericEdgeRealizer.Factory getFactory()
Returns the factory instance that will be used to read and write customization configurations.

Returns:
a default implementation

setStyleProperty

public void setStyleProperty(java.lang.String propertyKey,
                             java.lang.Object value)
Sets a named key value pair that is a property which can be used by the implementations in the configuration to retrieve per instance settings. Property value pairs are copied by reference to copies of this instance.

Parameters:
propertyKey - The key under which the value will be stored.
value - The value that is stored.
See Also:
getStyleProperty(String), getStyleProperties()

getStyleProperty

public java.lang.Object getStyleProperty(java.lang.String propertyKey)
Retrieves the value of the property that has been stored with this instance for the given key using setStyleProperty(String, Object)

Parameters:
propertyKey - the key to retrieve the property value of
Returns:
The value that has been associated with the key or null.

getStyleProperties

public java.util.Set getStyleProperties()
Yields a Set of Map.Entry instances that contains all property value pairs that have been associated with this instance via the setStyleProperty(String, Object) method.

Returns:
a Set of Map.Entry instances.
See Also:
getStyleProperty(String)

removeStyleProperty

public void removeStyleProperty(java.lang.String propertyKey)
Removes a previously stored style property from this instance's set of style properties.

Parameters:
propertyKey - The key which was used to set the style property earlier.

getUserData

public java.lang.Object getUserData()
Returns the user-defined data object. This can be any kind of object that can be handled by the GenericEdgeRealizer.UserDataHandler installed with this instance.

Returns:
the current user-defined data object.

setUserData

public void setUserData(java.lang.Object userData)
Sets the user-defined data object. This can be any kind of object that can be handled by the GenericEdgeRealizer.UserDataHandler installed with this instance.

Parameters:
userData - the new instance

getMouseInputEditorProvider

public MouseInputEditorProvider getMouseInputEditorProvider()
Returns a provider, that can be used to query for a mouse input editor for this realizer. This implementation returns this realizer, if its configuration contains an implementation of GenericEdgeRealizer.GenericMouseInputEditorProvider.

Overrides:
getMouseInputEditorProvider in class EdgeRealizer
Returns:
an implementation of interface MouseInputEditorProvider or null, if no such provider is bound to this realizer.
See Also:
findMouseInputEditor(Graph2DView, double, double, HitInfo)

findMouseInputEditor

public MouseInputEditor findMouseInputEditor(Graph2DView view,
                                             double x,
                                             double y,
                                             HitInfo hitInfo)
Uses the registered GenericEdgeRealizer.GenericMouseInputEditorProvider implementation to delegate the actual work to. If no such instance is registered with this instance null is returned.

Specified by:
findMouseInputEditor in interface MouseInputEditorProvider
Parameters:
view - the view that will host the editor
x - the x coordinate of the mouse event
y - the y coordinate of the mouse event
hitInfo - the HitInfo that may be used to determine what instance to return or null
Returns:
the editor to install or null
See Also:
MouseInputMode.setEdgeSearchingEnabled(boolean)

calcUnionRect

public void calcUnionRect(java.awt.geom.Rectangle2D r)
Description copied from class: EdgeRealizer
Calculates the union of rectangle enclosed by this realizer and r. For efficiency reasons the result is returned by modifying r.

Overrides:
calcUnionRect in class EdgeRealizer

reInsertBend

public void reInsertBend(Bend bend,
                         Bend refBend,
                         int dir)
Description copied from class: EdgeRealizer
Reinserts a bend to the edge which had been removed before.

Specified by:
reInsertBend in class EdgeRealizer
Parameters:
bend - the bend to be reinserted
refBend - reference bend already contained in this realizer
dir - indicates whether the bend should be inserted before or after the reference bend.Allowed values are Graph.AFTER and Graph.BEFORE.

removeBend

public Bend removeBend(Bend b)
Description copied from class: EdgeRealizer
Removes a Bend of this realizer.

Specified by:
removeBend in class EdgeRealizer
Parameters:
b - Bend to be removed

createCopy

public EdgeRealizer createCopy(EdgeRealizer er)
Description copied from class: EdgeRealizer
Returns a realizer of the same type as this realizer, that adopts as many attributes as possible from the given realizer.

Subclass realizers should always implement or overwrite this method, to guarantee correct copy behavior of the realizer.

Note: This method must not return null.

Specified by:
createCopy in class EdgeRealizer

createBend

public Bend createBend(double x,
                       double y,
                       Bend refBend,
                       int dir)
Description copied from class: EdgeRealizer
Adds a new bend before or after the given reference bend.

Specified by:
createBend in class EdgeRealizer
Parameters:
x - X-coordinate of the Bend
y - Y-coordinate of the Bend
refBend - Bend which should be neighbor
dir - indicates if the new Bend should be added before Graph.BEFORE or after Graph.AFTER the refBend in the bend sequence of the edge

paintArrows

protected void paintArrows(java.awt.Graphics2D g)
Description copied from class: EdgeRealizer
Paints the arrows of this realizer.

Overrides:
paintArrows in class EdgeRealizer

paintLabels

protected void paintLabels(java.awt.Graphics2D gfx)
Description copied from class: EdgeRealizer
Paints the labels belonging to this realizer.

Overrides:
paintLabels in class EdgeRealizer

bendChanged

public void bendChanged(Bend b,
                        double oldX,
                        double oldY)
Description copied from class: EdgeRealizer
Informs the edge, that a bend has changed position By default this method does nothing.

Overrides:
bendChanged in class EdgeRealizer
Parameters:
b - Bend which has changed position
oldX - previous x-coordinate
oldY - previous y-coordinate

insertBend

public Bend insertBend(double x,
                       double y)
Description copied from class: EdgeRealizer
Inserts a new bend into this realizer and returns it. If the given coordinate lies on an visible segment of the path, then the bend will be inserted in such a way that the segments splits in two parts. Otherwise the bend will be appended to the list of bends.

Specified by:
insertBend in class EdgeRealizer
Parameters:
x - X-coordinates of the bend
y - Y-coordinates of the bend
Returns:
a new Bend instance or null if no bend was created for the given coordinates.

registerObstacles

public void registerObstacles(BridgeCalculator calculator)
Description copied from class: EdgeRealizer
This callback method is e.g. by DefaultGraph2DRenderer if a BridgeCalculator is used for the rendering whose crossing mode is set to values other than BridgeCalculator.CROSSING_MODE_ORDER_INDUCED. Implementations should use the provided calculator instance to call BridgeCalculator.registerObstacles(java.awt.geom.PathIterator) using the EdgeRealizer.getPath() method for example or BridgeCalculator.registerObstacleLine(double, double, double, double) directly to add obstacle lines for the calculation directly. This implementation does nothing.

Overrides:
registerObstacles in class EdgeRealizer
Parameters:
calculator - the calculator instance used for the next rendering pass.

calculatePath

protected byte calculatePath(java.awt.geom.Point2D sourceIntersectionPointOut,
                             java.awt.geom.Point2D targetIntersectionPointOut)
Description copied from class: EdgeRealizer
Calculates the visible path of this realizer. Subclasses need to implement this. Implementations have to set the source intersection point and target intersection point via the out-parameters. This method returns whether the calculated path takes into account the length of the source and/or target arrow. Implementations of this method may use the EdgeRealizer.calculateClippingAndIntersection(EdgeRealizer, java.awt.geom.GeneralPath, java.awt.geom.GeneralPath, java.awt.geom.Point2D, java.awt.geom.Point2D) method to perform the clipping.

Specified by:
calculatePath in class EdgeRealizer
Parameters:
sourceIntersectionPointOut - a Point2D instance that must be set by the implementation to point to the source intersection point unless the path is empty.
targetIntersectionPointOut - a Point2D instance that must be set by the implementation to point to the target intersection point unless the path is empty.
Returns:
either EdgeRealizer.PATH_UNCLIPPED, EdgeRealizer.PATH_CLIPPED_AT_SOURCE, EdgeRealizer.PATH_CLIPPED_AT_TARGET, or EdgeRealizer.PATH_CLIPPED_AT_SOURCE_AND_TARGET
See Also:
EdgeRealizer.path, EdgeRealizer.isPathClippedAtSource(), EdgeRealizer.isPathClippedAtTarget()

paint

public void paint(java.awt.Graphics2D gfx)
Description copied from class: EdgeRealizer
Paints this realizer on the given graphics context.

Overrides:
paint in class EdgeRealizer

paintPorts

protected void paintPorts(java.awt.Graphics2D gfx)
Description copied from class: EdgeRealizer
Paints the ports of this realizer.

Overrides:
paintPorts in class EdgeRealizer

paintHighlightedBends

protected void paintHighlightedBends(java.awt.Graphics2D gfx)
Description copied from class: EdgeRealizer
Paints the bends if this realizer is in a selected state

Overrides:
paintHighlightedBends in class EdgeRealizer

paintBends

protected void paintBends(java.awt.Graphics2D gfx)
Description copied from class: EdgeRealizer
Paints the bends if they are in selected state.

Overrides:
paintBends in class EdgeRealizer

paintSloppy

public void paintSloppy(java.awt.Graphics2D gfx)
Description copied from class: EdgeRealizer
Paints this realizer in a quick and rather sloppy way. Useful if a small zoom level is applied to the graphics context.

Overrides:
paintSloppy in class EdgeRealizer

getMinBendCount

public int getMinBendCount()
Description copied from class: EdgeRealizer
Returns the minimal number of bends the edge must have. The return value defaults to 0.

Overrides:
getMinBendCount in class EdgeRealizer

clearBends

public void clearBends()
Description copied from class: EdgeRealizer
Removes all bends from this realizer.

Overrides:
clearBends in class EdgeRealizer

contains

public boolean contains(double x,
                        double y)
Description copied from class: EdgeRealizer
Query if the visible path of this realizer contains the point (x,y). Essentially a hit test.

Overrides:
contains in class EdgeRealizer

containsSeg

public int containsSeg(double x,
                       double y)
Description copied from class: EdgeRealizer
like contains(), but returns number of the hit segment, 0 otherwise.

Overrides:
containsSeg in class EdgeRealizer

pathIntersects

public boolean pathIntersects(java.awt.geom.Rectangle2D box,
                              boolean considerLabels)
Description copied from class: EdgeRealizer
This method complements the EdgeRealizer.contains(double,double) method. Its primary use is for checking whether or not an edge lies within the bounds of a selection box.

Overrides:
pathIntersects in class EdgeRealizer
Parameters:
box - the box that will be used for the intersection test
considerLabels - if true, labels will be considered
Returns:
if any segment or label intersects the given box

createEdgeLabel

public EdgeLabel createEdgeLabel()
Description copied from class: EdgeRealizer
Creates a new edge label that can be added to this realizer.

Overrides:
createEdgeLabel in class EdgeRealizer

setConfiguration

public void setConfiguration(java.lang.String configuration)
Configures this instance to use the implementations provided by the factory under the given configuration name.

Parameters:
configuration - the name of the configuration to use. It must have been registered with the factory prior to the invocation of this method.
Throws:
java.lang.IllegalArgumentException - if configuration is not registered within the factory

getConfiguration

public java.lang.String getConfiguration()
Returns the name of the current configuration for this GenericEdgeRealizer

Returns:
the name of the configuration

read

public void read(java.io.ObjectInputStream in)
          throws java.io.IOException,
                 java.lang.ClassNotFoundException
Description copied from class: EdgeRealizer
Reads in the serialized form of this realizer. The realizer must have been written out before by it's EdgeRealizer.write(ObjectOutputStream) method.

Overrides:
read in class EdgeRealizer
Throws:
java.io.IOException
java.lang.ClassNotFoundException

write

public void write(java.io.ObjectOutputStream out)
           throws java.io.IOException
Deprecated. Use the GraphML format instead.

Description copied from class: EdgeRealizer
Writes out this realizer in a serialized form.

Overrides:
write in class EdgeRealizer
Throws:
java.io.IOException

© Copyright 2000-2022,
yWorks GmbH.
All rights reserved.