Class SmileNode
- java.lang.Object
-
- Node
-
- uk.ac.qmul.eecs.ccmi.examples.framework.SmileNode
-
public class SmileNode extends NodeAn example of how a CCmI Diagram Editor nodes can be extended, in order to create your own graphic palette.
Subclasses of
Nodecan define their own appearance in the diagram graph by overridingdraw()and a few other abstract methods. They must also define their own sound in the editor tree by providing their own implementation ofgetSound().The
draw()method is called by the framework when the graph needs to be rendered, and ajava.awt.Graphics2Dobject is passed as argument. Therefore, Java 2D API can be used to draw your own node: from graphic primitives and arbitrary shapes to images.Instances of
SmileNodedraw themselves as a square shaped smile icon. This is realized using a.gifimage included as a resource in the code. In the editor tree aSmileNodewill sound like a clap or a water drop (seegetSound()) .
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classSmileNode.MOODAvailable moods for the smile nodes.
-
Constructor Summary
Constructors Constructor and Description SmileNode(SmileNode.MOOD mood)Create a simple instance with no property types and type name "Happy Node" or "Sad Node", according to the value ofmood.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description java.lang.Objectclone()booleancontains(java.awt.geom.Point2D aPoint)Whether the bounds contain the point given as argument.voiddraw(java.awt.Graphics2D g2d)Draws itself on aGraphics2Dobject as a smiling/sad face.java.awt.geom.Rectangle2DgetBounds()Returned object is a square delimiting the picture used to draw the node on the graph.java.awt.geom.Point2DgetConnectionPoint(Direction d)Returns the point where an edge attached to this node would get in contact with it, once the direction is given.SmileNode.MOODgetMood()Whether this node has a happy or a sad facejava.awt.ShapegetShape()Same asgetBounds()for this class.java.io.InputStreamgetSound()Returns a stream to a file with a clap sound for happy mood and water drop sound for sad mood.protected voidtranslateImplementation(java.awt.geom.Point2D p, double dx, double dy)Translates this node in the graph.
-
-
-
Constructor Detail
-
SmileNode
public SmileNode(SmileNode.MOOD mood)
Create a simple instance with no property types and type name "Happy Node" or "Sad Node", according to the value ofmood.- Parameters:
mood- Whether the guy is happy or sad
-
-
Method Detail
-
translateImplementation
protected void translateImplementation(java.awt.geom.Point2D p, double dx, double dy)Translates this node in the graph.- Parameters:
p- the point in the graph where the user clicked to start the translation (not used for this class)dx- thexcoordinate of the translationdy- theycoordinate of the translation
-
contains
public boolean contains(java.awt.geom.Point2D aPoint)
Whether the bounds contain the point given as argument.- Parameters:
aPoint- the point to check- Returns:
trueifaPointis contained by this object bounds,falseotherwise
-
getBounds
public java.awt.geom.Rectangle2D getBounds()
Returned object is a square delimiting the picture used to draw the node on the graph.- Returns:
- the bounding rectangle
-
getConnectionPoint
public java.awt.geom.Point2D getConnectionPoint(Direction d)
Returns the point where an edge attached to this node would get in contact with it, once the direction is given. This method is fundamental for getting edges, that are attached to this node, to be drawn properly.
Since this node is square shaped, the contact point lays on the square perimeter and changes according to the direction.
- Parameters:
d- the direction the attached edge is coming towards- Returns:
- the point on the perimeter where the edge is touching this node
-
getShape
public java.awt.Shape getShape()
Same asgetBounds()for this class.- Returns:
- the bounding square
-
getSound
public java.io.InputStream getSound()
Returns a stream to a file with a clap sound for happy mood and water drop sound for sad mood. The sound is loaded in a static block defined in this class.- Returns:
- returns the
InputStreamto the sound of this node.
-
draw
public void draw(java.awt.Graphics2D g2d)
Draws itself on aGraphics2Dobject as a smiling/sad face. In order to accomplish that, a.gifimage of the popular smile icon is used.
-
clone
public java.lang.Object clone()
-
getMood
public SmileNode.MOOD getMood()
Whether this node has a happy or a sad face- Returns:
- the
moodvalue passed as argument to the constructor
-
-