View Javadoc

1   package de.fzi.wim.guibase.graphview.graph;
2   
3   import java.util.List;
4   import java.util.LinkedList;
5   
6   /***
7    * The default implementation of the node in the graph.
8     */
9   public class DefaultNode implements Node {
10      /*** The list of edges from the node. */
11      protected List m_edgesFrom;
12      /*** The list of edges to the node. */
13      protected List m_edgesTo;
14      /*** Set to <code>true</code> if the node is fixed. */
15      protected boolean m_fixed;
16      /*** The x location of the node. */
17      protected double m_x;
18      /*** The y location of the node. */
19      protected double m_y;
20  
21      /***
22       * Creates a node.
23       */
24      public DefaultNode() {
25          m_fixed=false;
26          m_edgesFrom=new LinkedList();
27          m_edgesTo=new LinkedList();
28      }
29      /***
30       * Returns the list of edges from the node.
31       *
32       * @return                              the list of edges from the node
33       */
34      public List getEdgesFrom() {
35          return m_edgesFrom;
36      }
37      /***
38       * Returns the list of edges to the node.
39       *
40       * @return                              the list of edges to the node
41       */
42      public List getEdgesTo() {
43          return m_edgesTo;
44      }
45      /***
46       * Set the location of this node.
47       *
48       * @param x                             the X coordination
49       * @param y                             the Y coordination
50       */
51      public void setLocation(double x,double y) {
52          m_x=x;
53          m_y=y;
54      }
55      /***
56       * Returns the X coordinate of this node.
57       *
58       * @return                              the X coordinate
59       */
60      public double getX() {
61          return m_x;
62      }
63      /***
64       * Returns the Y coordinate of this node.
65       *
66       * @return                              the Y coordinate
67       */
68      public double getY() {
69          return m_y;
70      }
71      /***
72       * The repulstion factor (specifies how much does this node repulses other nodes).
73       *
74       * @return                              the repulsion factor of the node
75       */
76      public double getRepulsion() {
77          return 1.0;
78      }
79     /***
80      * Return the label of this node.
81      *
82      * @return                               the label of this node
83      */
84      public String getLabel() {
85          return toString();
86      }
87      /***
88       * Returns <code>true</code> if this node is fixed (in place).
89       *
90       * @return                              <code>true</code> if this node is fixed
91       */
92      public boolean isFixed() {
93          return m_fixed;
94      }
95      /***
96       * Makes this node fixed.
97       *
98       * @param fixed                         <code>true</code> if this node is fixed
99       */
100     public void setFixed(boolean fixed) {
101         m_fixed=fixed;
102     }
103     /***
104      * Notifies the node that the edge has been added to the graph.
105      *
106      * @param edge                          the edge that was added
107      */
108     public void notifyEdgeAdded(Edge edge) {
109         if (edge.getFrom()==this)
110             m_edgesFrom.add(edge);
111         else if (edge.getTo()==this)
112             m_edgesTo.add(edge);
113     }
114     /***
115      * Notifies the node that the edge has been removed from the graph.
116      *
117      * @param edge                          the edge that was removed
118      */
119     public void notifyEdgeRemoved(Edge edge) {
120         if (edge.getFrom()==this)
121             m_edgesFrom.remove(edge);
122         else if (edge.getTo()==this)
123             m_edgesTo.remove(edge);
124     }
125 }