Search this API

y.view
Class GenericNodeRealizer

java.lang.Object
  extended by y.view.NodeRealizer
      extended by y.view.GenericNodeRealizer
All Implemented Interfaces:
NodeLayout, MouseInputEditorProvider
Direct Known Subclasses:
GenericGroupNodeRealizer

public class GenericNodeRealizer
extends NodeRealizer
implements MouseInputEditorProvider

This class can be used to easily create customized node appearances. In contrast to the usual way, developers don't need to subclass this class in order to create a new visual appearance, but may use pluggable instances of specialized interfaces to replace different steps of the node 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 node 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(NodeRealizer) 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 GenericNodeRealizer.UserDataHandler 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 node realizer.

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

 // Retrieve a map that holds the default GenericNodeRealizer 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.GenericNodeRealizerDemo for example implementations)
 MyCustomPainter painter = new MyCustomPainter(new Ellipse2D.Double());
 // put it into the map using the interface class as the key
 implementationsMap.put(GenericNodeRealizer.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
 GenericNodeRealizer nr = new GenericNodeRealizer();
 // initialize the instance using the previously registered configuration
 nr.setConfiguration("type1");

 // finally store a custom style property with the
 // instance that will be used by the MyCustomPainter
 // implementation to foo-ify the shape in a very clever way
 nr.setStyleProperty("MyCustomPainter.FooValue", new Double(42.0d));
 

See Also:
AbstractCustomNodePainter, AbstractCustomHotSpotPainter, SimpleUserDataHandler
 

Nested Class Summary
static interface GenericNodeRealizer.BoundsChangedHandler
          This interface is used by GenericNodeRealizer as a callback to boundsChanged().
static interface GenericNodeRealizer.ContainsTest
          This interface is used by GenericNodeRealizer to delegate the work of the contains(double, double) method to.
static class GenericNodeRealizer.Factory
          This class is used to manage the different configurations for GenericNodeRealizer instances.
static interface GenericNodeRealizer.GenericMouseInputEditorProvider
          This interface is used by GenericNodeRealizer to delegate the work of the MouseInputEditorProvider interface GenericNodeRealizer implements to.
static interface GenericNodeRealizer.GenericSizeConstraintProvider
          Additional interface for node realizers that have specified size constraints.
static interface GenericNodeRealizer.HotSpotHitTest
          This interface is used by GenericNodeRealizer to delegate the work of the hotSpotHit(double, double) method to.
static interface GenericNodeRealizer.HotSpotPainter
          This interface is used by GenericNodeRealizer to delegate the work of the paintHotSpots(Graphics2D) method to.
static interface GenericNodeRealizer.Initializer
          This interface is used by GenericNodeRealizer for initialization purposes.
static interface GenericNodeRealizer.IntersectionTest
          This interface is used by GenericNodeRealizer to delegate the work of the findIntersection(double, double, double, double, Point2D) method to.
static interface GenericNodeRealizer.LabelBoundsChangedHandler
          This interface is used by GenericNodeRealizer as a callback to labelBoundsChanged(NodeLabel label).
static interface GenericNodeRealizer.LabelFactory
          This interface is used by GenericNodeRealizer to delegate the work of the createNodeLabel() method to.
static interface GenericNodeRealizer.LayerHandler
          This interface is used by GenericNodeRealizer to delegate the work of the getLayer() and the setLayer(byte) methods to.
static interface GenericNodeRealizer.Painter
          This interface is used by GenericNodeRealizer to delegate the work of the painting methods to.
static interface GenericNodeRealizer.PortCandidateListProvider
          This interface is used by GenericNodeRealizer as a callback to getPortCandidates(double).
static interface GenericNodeRealizer.SelectionChangeHandler
          This interface is used by GenericNodeRealizer to notify interested parties of selection state changes.
static interface GenericNodeRealizer.UnionRectCalculator
          This interface is used by GenericNodeRealizer to delegate the work of the calcUnionRect(java.awt.geom.Rectangle2D) method to.
static interface GenericNodeRealizer.UserDataHandler
          This interface is used by GenericNodeRealizer to delegate the copying and serialization/deserialization of any user-defined data to.
 
Field Summary
 
Fields inherited from class y.view.NodeRealizer
height, HOTSPOT_E, HOTSPOT_N, HOTSPOT_NE, HOTSPOT_NONE, HOTSPOT_NW, HOTSPOT_S, HOTSPOT_SE, HOTSPOT_SW, HOTSPOT_W, width, x, y
 
Constructor Summary
GenericNodeRealizer()
          Creates a new instance of GenericNodeRealizer using the default configuration.
GenericNodeRealizer(NodeRealizer nr)
          Creates a new instance of GenericNodeRealizer which is a copy of the given realizer instance.
GenericNodeRealizer(java.lang.String configuration)
          Creates a new instance of GenericNodeRealizer using the given configuration.
 
Method Summary
protected  void adoptValues(GenericNodeRealizer cnr)
          Tries to copy all the values from the given instance to this instance.
protected  void boundsChanged()
          Uses the registered GenericNodeRealizer.BoundsChangedHandler implementation to delegate the actual work to.
 void calcUnionRect(java.awt.geom.Rectangle2D r)
          Uses the registered GenericNodeRealizer.UnionRectCalculator implementation to delegate the actual work to.
 boolean contains(double x, double y)
          Uses the registered GenericNodeRealizer.ContainsTest implementation to delegate the actual work to.
 NodeRealizer createCopy(NodeRealizer nr)
          Creates a copy of the given Realizer, using as much information as possible from the given instance to create a new GenericNodeRealizer instance.
 NodeLabel createNodeLabel()
          Uses the registered GenericNodeRealizer.LabelFactory implementation to delegate the actual work to.
 boolean findIntersection(double ix, double iy, double ox, double oy, java.awt.geom.Point2D result)
          Uses the registered GenericNodeRealizer.IntersectionTest implementation to delegate the actual work to.
 MouseInputEditor findMouseInputEditor(Graph2DView view, double x, double y, HitInfo hitInfo)
          Uses the registered GenericNodeRealizer.GenericMouseInputEditorProvider implementation to delegate the actual work to.
 java.lang.String getConfiguration()
          Returns the name of the current configuration for this GenericNodeRealizer.
static GenericNodeRealizer.Factory getFactory()
          Returns the factory instance that will be used to read and write customization configurations.
 byte getLayer()
          Uses the registered GenericNodeRealizer.LayerHandler implementation to delegate the actual work to.
 MouseInputEditorProvider getMouseInputEditorProvider()
          Returns a provider, that can be used to query for a mouse input editor for this realizer.
 YList getPortCandidates(double gridResolution)
          Uses the registered GenericNodeRealizer.PortCandidateListProvider implementation to retrieve the list of port candidate points from.
 SizeConstraintProvider getSizeConstraintProvider()
          Returns a provider, that can be used to request information about size constraints 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.
 byte hotSpotHit(double hx, double hy)
          Uses the registered GenericNodeRealizer.HotSpotHitTest implementation to delegate the actual work to.
protected  void labelBoundsChanged(NodeLabel label)
          Uses the registered GenericNodeRealizer.LabelBoundsChangedHandler implementation to delegate the actual work to.
 void paint(java.awt.Graphics2D g)
          Uses the registered GenericNodeRealizer.Painter implementation to delegate the actual work to.
 void paintHotSpots(java.awt.Graphics2D g)
          Uses the registered GenericNodeRealizer.HotSpotPainter implementation to delegate the actual work to.
 void paintNode(java.awt.Graphics2D g)
          This implementation by default calls paintHotSpots(g), draws a (filled) background rectangle, calls paintPorts(g), and paintText(g).
 void paintSloppy(java.awt.Graphics2D g)
          Uses the registered GenericNodeRealizer.Painter implementation to delegate the actual work to.
 void read(java.io.ObjectInputStream in)
          Deprecated. Use the GraphML format instead.
 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 setLayer(byte l)
          Uses the registered GenericNodeRealizer.LayerHandler implementation to delegate the actual work to.
 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.NodeRealizer
addLabel, addPort, calcUnionRect, calcUnionRectImpl, calcUnionRectLabels, calcUnionRectPorts, createCopy, findBBIntersection, getAutoBoundsFeature, getBoundingBox, getCenterX, getCenterY, getFillColor, getFillColor2, getHeight, getHotSpotColor, getLabel, getLabel, getLabelText, getLineColor, getLineType, getNode, getPort, getSloppySelectionColor, getWidth, getX, getY, intersects, invalidatePortPositions, isInBox, isSelected, isTransparent, isVisible, labelCount, moveBy, paintLayer, paintLayerSloppy, paintPorts, paintText, portCount, removeLabel, removeLabel, removePort, removePort, repaint, setCenter, setCenterX, setCenterY, setEdgesDirty, setFillColor, setFillColor2, setFrame, setFrame, setHeight, setHotSpotColor, setLabel, setLabelText, setLayer, setLineColor, setLineType, setLocation, setSelected, setSize, setSloppySelectionColor, setTransparent, setVisible, setWidth, setX, setY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericNodeRealizer

public GenericNodeRealizer()
Creates a new instance of GenericNodeRealizer using the default configuration. The default configuration renders a rectangular shape.

See Also:
setConfiguration(String)

GenericNodeRealizer

public GenericNodeRealizer(java.lang.String configuration)
Creates a new instance of GenericNodeRealizer 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:
GenericNodeRealizer.Factory.addConfiguration(String, java.util.Map)

GenericNodeRealizer

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

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

getFactory

public static GenericNodeRealizer.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.

Value types either have to implement the Serializable interface or a suitable ObjectStringConverter implementation has to be registered with the globally available ObjectStringConversion instance in order to be able to serialize/deserialize the realizer to/from YGF format.

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.

getConfiguration

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

Returns:
the name of the configuration

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.

adoptValues

protected void adoptValues(GenericNodeRealizer cnr)
Tries to copy all the values from the given instance to this instance. Customization interfaces will be copied by reference, user-defined data will be copied using the GenericNodeRealizer.UserDataHandler implementation or by reference if no such handler is registered with the argument's instance.

Parameters:
cnr - the realizer to obtain the configuration from

createCopy

public NodeRealizer createCopy(NodeRealizer nr)
Creates a copy of the given Realizer, using as much information as possible from the given instance to create a new GenericNodeRealizer instance.

Specified by:
createCopy in class NodeRealizer
Parameters:
nr - the realizer to create the copy of
Returns:
a instance of GenericNodeRealizer

paintNode

public void paintNode(java.awt.Graphics2D g)
This implementation by default calls paintHotSpots(g), draws a (filled) background rectangle, calls paintPorts(g), and paintText(g).

Specified by:
paintNode in class NodeRealizer
Parameters:
g - the graphics context
See Also:
paint(Graphics2D)

boundsChanged

protected void boundsChanged()
Uses the registered GenericNodeRealizer.BoundsChangedHandler implementation to delegate the actual work to. If no such instance is registered with this instance nothing is done.

Overrides:
boundsChanged in class NodeRealizer

labelBoundsChanged

protected void labelBoundsChanged(NodeLabel label)
Uses the registered GenericNodeRealizer.LabelBoundsChangedHandler implementation to delegate the actual work to. If no such instance is registered with this instance nothing is done.

Overrides:
labelBoundsChanged in class NodeRealizer
Parameters:
label - the label whose bounds have changed.

getPortCandidates

public YList getPortCandidates(double gridResolution)
Uses the registered GenericNodeRealizer.PortCandidateListProvider implementation to retrieve the list of port candidate points from. If no such instance is registered with this instance super.getPortCandidates(gridResolution) is called.

Overrides:
getPortCandidates in class NodeRealizer
Parameters:
gridResolution - the distance between two grid points, the origin of the grid is at (0,0) in world coordinates
Returns:
a YList of YPoint instances, each specifying an absolute port position

getLayer

public byte getLayer()
Uses the registered GenericNodeRealizer.LayerHandler implementation to delegate the actual work to. If no such instance is registered with this instance super.getLayer(); is called.

Overrides:
getLayer in class NodeRealizer
See Also:
Graph2DView.FG_LAYER, Graph2DView.BG_LAYER

setLayer

public void setLayer(byte l)
Uses the registered GenericNodeRealizer.LayerHandler implementation to delegate the actual work to. If no such instance is registered with this instance super.setLayer(l); is called.

Overrides:
setLayer in class NodeRealizer
See Also:
Graph2DView.FG_LAYER, Graph2DView.BG_LAYER

paint

public void paint(java.awt.Graphics2D g)
Uses the registered GenericNodeRealizer.Painter implementation to delegate the actual work to. If no such instance is registered with this instance super.paint(g); is called.

Overrides:
paint in class NodeRealizer

paintSloppy

public void paintSloppy(java.awt.Graphics2D g)
Uses the registered GenericNodeRealizer.Painter implementation to delegate the actual work to. If no such instance is registered with this instance super.paintSloppy(g); is called.

Overrides:
paintSloppy in class NodeRealizer

contains

public boolean contains(double x,
                        double y)
Uses the registered GenericNodeRealizer.ContainsTest implementation to delegate the actual work to. If no such instance is registered with this instance super.contains(x, y); is evaluated.

Overrides:
contains in class NodeRealizer
Parameters:
x - the x-coordinate of the point to check.
y - the y-coordinate of the point to check.
Returns:
true if the bounding box of this realizer contains the specified point; false otherwise.

hotSpotHit

public byte hotSpotHit(double hx,
                       double hy)
Uses the registered GenericNodeRealizer.HotSpotHitTest implementation to delegate the actual work to. If no such instance is registered with this instance super.hotSpotHit(hx, hy); is evaluated.

Overrides:
hotSpotHit in class NodeRealizer

findIntersection

public boolean findIntersection(double ix,
                                double iy,
                                double ox,
                                double oy,
                                java.awt.geom.Point2D result)
Uses the registered GenericNodeRealizer.IntersectionTest implementation to delegate the actual work to. If no such instance is registered with this instance super.findIntersection(ix, iy, ox, oy, result); is evaluated.

Overrides:
findIntersection in class NodeRealizer
Parameters:
ix - the x-coordinate of a point inside the realizer's visual bounds.
iy - the y-coordinate of a point inside the realizer's visual bounds.
ox - the x-coordinate of a point outside the realizer's visual bounds.
oy - the y-coordinate of a point outside the realizer's visual bounds.
result - output parameter for the absolute world coordinates of the calculated intersection point.
Returns:
true if (ix,iy) lies inside and (ox,oy) lies outside this realizer's visual bounds; false otherwise.
See Also:
NodeRealizer.contains(double, double)

paintHotSpots

public void paintHotSpots(java.awt.Graphics2D g)
Uses the registered GenericNodeRealizer.HotSpotPainter implementation to delegate the actual work to. If no such instance is registered with this instance super.paintHotSpots(g); is called.

Overrides:
paintHotSpots in class NodeRealizer

calcUnionRect

public void calcUnionRect(java.awt.geom.Rectangle2D r)
Uses the registered GenericNodeRealizer.UnionRectCalculator implementation to delegate the actual work to. If no such instance is registered with this instance super.calcUnionRect(r); is called.

Overrides:
calcUnionRect in class NodeRealizer

createNodeLabel

public NodeLabel createNodeLabel()
Uses the registered GenericNodeRealizer.LabelFactory implementation to delegate the actual work to. If no such instance is registered with this instance super.createNodeLabel(); is called.

Overrides:
createNodeLabel in class NodeRealizer
Returns:
a new NodeLabel instance.

read

public void read(java.io.ObjectInputStream in)
          throws java.io.IOException,
                 java.lang.ClassNotFoundException
Deprecated. Use the GraphML format instead.

Description copied from class: NodeRealizer
Reads in the serialized form of this realizer. The realizer must have been written out before by it's NodeRealizer.write(ObjectOutputStream) method.

Overrides:
read in class NodeRealizer
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: NodeRealizer
Writes this realizer in a serialized form to the given stream.

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

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 GenericNodeRealizer.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 GenericNodeRealizer.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 GenericNodeRealizer.GenericMouseInputEditorProvider.

Overrides:
getMouseInputEditorProvider in class NodeRealizer
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 GenericNodeRealizer.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.setNodeSearchingEnabled(boolean)

getSizeConstraintProvider

public SizeConstraintProvider getSizeConstraintProvider()
Description copied from class: NodeRealizer
Returns a provider, that can be used to request information about size constraints for this realizer. E.g. minimum and maximum sizes can be defined.

Overrides:
getSizeConstraintProvider in class NodeRealizer
Returns:
an implementation of interface SizeConstraintProvider or null, if no such provider is bound to this realizer.

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