Class SmileNode

  • java.lang.Object
    • Node
      • uk.ac.qmul.eecs.ccmi.examples.framework.SmileNode


  • public class SmileNode
    extends Node

    An example of how a CCmI Diagram Editor nodes can be extended, in order to create your own graphic palette.

    Subclasses of Node can define their own appearance in the diagram graph by overriding draw() and a few other abstract methods. They must also define their own sound in the editor tree by providing their own implementation of getSound().

    The draw() method is called by the framework when the graph needs to be rendered, and a java.awt.Graphics2D object 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 SmileNode draw themselves as a square shaped smile icon. This is realized using a .gif image included as a resource in the code. In the editor tree a SmileNode will sound like a clap or a water drop (see getSound()) .

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class and Description
      static class  SmileNode.MOOD
      Available 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 of mood.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      java.lang.Object clone() 
      boolean contains(java.awt.geom.Point2D aPoint)
      Whether the bounds contain the point given as argument.
      void draw(java.awt.Graphics2D g2d)
      Draws itself on a Graphics2D object as a smiling/sad face.
      java.awt.geom.Rectangle2D getBounds()
      Returned object is a square delimiting the picture used to draw the node on the graph.
      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.
      SmileNode.MOOD getMood()
      Whether this node has a happy or a sad face
      java.awt.Shape getShape()
      Same as getBounds() for this class.
      java.io.InputStream getSound()
      Returns a stream to a file with a clap sound for happy mood and water drop sound for sad mood.
      protected void translateImplementation(java.awt.geom.Point2D p, double dx, double dy)
      Translates this node in the graph.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 of mood.
        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 - the x coordinate of the translation
        dy - the y coordinate 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:
        true if aPoint is contained by this object bounds, false otherwise
      • 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 as getBounds() 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 InputStream to the sound of this node.
      • draw

        public void draw(java.awt.Graphics2D g2d)
        Draws itself on a Graphics2D object as a smiling/sad face. In order to accomplish that, a .gif image 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 mood value passed as argument to the constructor