|
|||||||||
| 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");
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.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.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. |
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. |
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. |
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); and
super.paintSloppy(g);
and paintText(g); |
void |
paintSloppy(Graphics2D g)
Uses the registered GenericNodeRealizer.Painter implementation to
delegate the actual work to. |
void |
read(ObjectInputStream in)
Reads in the serialized form of this realizer. |
void |
setConfiguration(String configuration)
Configures this instance to use the implementations provided by the factory under the given configuration name. |
void |
setUserData(Object userData)
Sets the user-defined data object. |
void |
write(ObjectOutputStream out)
Writes this realizer in a serialized form to the given stream. |
| 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)
configuration - the configuration to usesetConfiguration(String)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 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); and
super.paintSloppy(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 whoose 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 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 NodeRealizer
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 NodeRealizer
public void read(ObjectInputStream in)
throws IOException,
ClassNotFoundException
NodeRealizerNodeRealizer.write(ObjectOutputStream) method.
read in class NodeRealizerIOException
ClassNotFoundException
public void write(ObjectOutputStream out)
throws IOException
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-2008, yWorks GmbH. All rights reserved. |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||