|
Search this API | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objecty.view.NodeRealizer
y.view.GenericNodeRealizer
public class GenericNodeRealizer
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 customizeGenericNodeRealizer.Painter)GenericNodeRealizer.HotSpotPainter and GenericNodeRealizer.HotSpotHitTest)GenericNodeRealizer.ContainsTest and GenericNodeRealizer.IntersectionTest)GenericNodeRealizer.UnionRectCalculator)GenericNodeRealizer.UserDataHandler)GenericNodeRealizer.BoundsChangedHandler)GenericNodeRealizer.PortCandidateListProvider)MouseInputEditor instances for mouse interaction (see GenericNodeRealizer.GenericMouseInputEditorProvider)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));
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(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(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,
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. |
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. |
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. |
Object |
getStyleProperty(String propertyKey)
Retrieves the value of the property that has been stored with this instance for the given key using setStyleProperty(String, Object) |
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(Graphics2D g)
Uses the registered GenericNodeRealizer.Painter implementation to
delegate the actual work to. |
void |
paintHotSpots(Graphics2D g)
Uses the registered GenericNodeRealizer.HotSpotPainter implementation to
delegate the actual work to. |
void |
paintNode(Graphics2D g)
This implementation by default calls paintHotSpots(g), draws
a (filled) background rectangle, calls paintPorts(g), and
paintText(g). |
void |
paintSloppy(Graphics2D g)
Uses the registered GenericNodeRealizer.Painter implementation to
delegate the actual work to. |
void |
read(ObjectInputStream in)
Deprecated. Use the GraphML format instead. |
void |
removeStyleProperty(String propertyKey)
Removes a previously stored style property from this instance's set of style properties. |
void |
setConfiguration(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(String propertyKey,
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(Object userData)
Sets the user-defined data object. |
void |
write(ObjectOutputStream out)
Deprecated. Use the GraphML format instead. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public GenericNodeRealizer()
setConfiguration(String)public GenericNodeRealizer(String configuration)
IllegalArgumentException - if configuration is not registered in the factoryconfiguration - the identifier of the configuration to useGenericNodeRealizer.Factory.addConfiguration(String, java.util.Map)public GenericNodeRealizer(NodeRealizer nr)
nr is not of type GenericNodeRealizer, the default
configuration will be used for the new GenericNodeRealizer object.
nr - The realizer to copy the values from.setConfiguration(String)| Method Detail |
|---|
public static GenericNodeRealizer.Factory getFactory()
public void setStyleProperty(String propertyKey,
Object value)
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.
propertyKey - The key under which the value will be stored.value - The value that is stored.getStyleProperty(String),
getStyleProperties()public Object getStyleProperty(String propertyKey)
setStyleProperty(String, Object)
propertyKey - the key to retrieve the property value of
null.public Set getStyleProperties()
Set of Map.Entry instances that
contains all property value pairs that have been associated with this
instance via the setStyleProperty(String, Object) method.
Set of Map.Entry instances.getStyleProperty(String)public void removeStyleProperty(String propertyKey)
propertyKey - The key which was used to set
the style property earlier.public String getConfiguration()
public void setConfiguration(String configuration)
factory under the given configuration name.
configuration - The name of the configuration to use.
It must have been registered with the factory prior to the invocation of this
method.protected void adoptValues(GenericNodeRealizer cnr)
GenericNodeRealizer.UserDataHandler implementation or by
reference if no such handler is registered with the argument's instance.
cnr - the realizer to obtain the configuration frompublic NodeRealizer createCopy(NodeRealizer nr)
createCopy in class NodeRealizernr - the realizer to create the copy of
GenericNodeRealizerpublic void paintNode(Graphics2D g)
paintHotSpots(g), draws
a (filled) background rectangle, calls paintPorts(g), and
paintText(g).
paintNode in class NodeRealizerg - the graphics contextpaint(Graphics2D)protected void boundsChanged()
GenericNodeRealizer.BoundsChangedHandler implementation to
delegate the actual work to. If no such instance is registered with this
instance nothing is done.
boundsChanged in class NodeRealizerprotected void labelBoundsChanged(NodeLabel label)
GenericNodeRealizer.LabelBoundsChangedHandler implementation to
delegate the actual work to. If no such instance is registered with this
instance nothing is done.
labelBoundsChanged in class NodeRealizerlabel - the label whose bounds have changed.public YList getPortCandidates(double gridResolution)
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.
getPortCandidates in class NodeRealizergridResolution - the distance between two grid points, the origin of the grid is
at (0,0) in world coordinates
YPoint instances, each specifying an absolute port positionpublic byte getLayer()
GenericNodeRealizer.LayerHandler implementation to
delegate the actual work to. If no such instance is registered with this
instance super.getLayer(); is called.
getLayer in class NodeRealizerGraph2DView.FG_LAYER,
Graph2DView.BG_LAYERpublic void setLayer(byte l)
GenericNodeRealizer.LayerHandler implementation to
delegate the actual work to. If no such instance is registered with this
instance super.setLayer(l); is called.
setLayer in class NodeRealizerGraph2DView.FG_LAYER,
Graph2DView.BG_LAYERpublic void paint(Graphics2D g)
GenericNodeRealizer.Painter implementation to
delegate the actual work to. If no such instance is registered with this
instance super.paint(g); is called.
paint in class NodeRealizerpublic void paintSloppy(Graphics2D g)
GenericNodeRealizer.Painter implementation to
delegate the actual work to. If no such instance is registered with this
instance super.paintSloppy(g); is called.
paintSloppy in class NodeRealizer
public boolean contains(double x,
double y)
GenericNodeRealizer.ContainsTest implementation to
delegate the actual work to. If no such instance is registered with this
instance super.contains(x, y); is evaluated.
contains in class NodeRealizerx - the x-coordinate of the point to check.y - the y-coordinate of the point to check.
true if the bounding box of this realizer
contains the specified point; false otherwise.
public byte hotSpotHit(double hx,
double hy)
GenericNodeRealizer.HotSpotHitTest implementation to
delegate the actual work to. If no such instance is registered with this
instance super.hotSpotHit(hx, hy); is evaluated.
hotSpotHit in class NodeRealizer
public boolean findIntersection(double ix,
double iy,
double ox,
double oy,
Point2D result)
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.
findIntersection in class NodeRealizerpublic void paintHotSpots(Graphics2D g)
GenericNodeRealizer.HotSpotPainter implementation to
delegate the actual work to. If no such instance is registered with this
instance super.paintHotSpots(g); is called.
paintHotSpots in class NodeRealizerpublic void calcUnionRect(Rectangle2D r)
GenericNodeRealizer.UnionRectCalculator implementation to
delegate the actual work to. If no such instance is registered with this
instance super.calcUnionRect(r); is called.
calcUnionRect in class NodeRealizerpublic NodeLabel createNodeLabel()
GenericNodeRealizer.LabelFactory implementation
to delegate the actual work to. If no such instance is registered with this
instance super.createNodeLabel(); is called.
createNodeLabel in class NodeRealizerNodeLabel instance.
public void read(ObjectInputStream in)
throws IOException,
ClassNotFoundException
GraphML format instead.
NodeRealizerNodeRealizer.write(ObjectOutputStream) method.
read in class NodeRealizerIOException
ClassNotFoundException
public void write(ObjectOutputStream out)
throws IOException
GraphML format instead.
NodeRealizer
write in class NodeRealizerIOExceptionpublic Object getUserData()
GenericNodeRealizer.UserDataHandler installed
with this instance.
public void setUserData(Object userData)
GenericNodeRealizer.UserDataHandler installed
with this instance.
userData - the new instancepublic MouseInputEditorProvider getMouseInputEditorProvider()
GenericNodeRealizer.GenericMouseInputEditorProvider.
getMouseInputEditorProvider in class NodeRealizerMouseInputEditorProvider or null,
if no such provider is bound to this realizer.findMouseInputEditor(Graph2DView, double, double, HitInfo)
public MouseInputEditor findMouseInputEditor(Graph2DView view,
double x,
double y,
HitInfo hitInfo)
GenericNodeRealizer.GenericMouseInputEditorProvider implementation to
delegate the actual work to. If no such instance is registered with this
instance null is returned.
findMouseInputEditor in interface MouseInputEditorProviderview - the view that will host the editorx - the x coordinate of the mouse eventy - the y coordinate of the mouse eventhitInfo - the HitInfo that may be used to determine what instance to return or null
nullMouseInputMode.setNodeSearchingEnabled(boolean)public SizeConstraintProvider getSizeConstraintProvider()
NodeRealizer
getSizeConstraintProvider in class NodeRealizerSizeConstraintProvider or null,
if no such provider is bound to this realizer.
|
© Copyright 2000-2013, yWorks GmbH. All rights reserved. |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||