Vertex.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /***************************************************************************
  2. Title: GraphBrowser/Vertex.java
  3. ID: $Id$
  4. Author: Stefan Berghofer, TU Muenchen
  5. License: GPL (GNU GENERAL PUBLIC LICENSE)
  6. This class contains attributes and methods common to all kinds of
  7. vertices (e.g. coordinates, successors, predecessors).
  8. ***************************************************************************/
  9. package GraphBrowser;
  10. import java.util.*;
  11. import java.awt.*;
  12. import java.io.*;
  13. abstract class Vertex {
  14. Vector children=new Vector(10,10);
  15. Vector parents=new Vector(10,10);
  16. int degree=0;
  17. int number=-1;
  18. double weight=0;
  19. int x,y;
  20. Graph gra;
  21. public abstract Object clone();
  22. public void setGraph(Graph g) { gra=g; }
  23. public int countChildren() { return children.size(); }
  24. /** getInflate returns a vector of vertices which get **/
  25. /** inflated again if the user clicks on this vertex **/
  26. public void setInflate(Vector v) {}
  27. public Vector getInflate() { return null; }
  28. /** getUp returns a vector of vertices which get inflated **/
  29. /** again, if the user clicks on this vertex's upward arrow **/
  30. public Vector getUp() { return null; }
  31. public void setUp(Vector v) {}
  32. /** getUp returns a vector of vertices which get inflated **/
  33. /** again, if the user clicks on this vertex's downward arrow **/
  34. public Vector getDown() { return null; }
  35. public void setDown(Vector v) {}
  36. /** internal number, for decoding / encoding etc. **/
  37. public int getNumber() { return number; }
  38. public void setNumber(int n) { number=n; }
  39. public String getLabel() {return "";}
  40. public void setLabel(String s) {}
  41. /** unique identifier **/
  42. public String getID() {return "";}
  43. public void setID(String s) {}
  44. public Box getLabelSize(Graphics g) {
  45. AbstractFontMetrics fm = g == null ?
  46. (AbstractFontMetrics) new DefaultFontMetrics(12) :
  47. (AbstractFontMetrics) new AWTFontMetrics(g.getFontMetrics(g.getFont()));
  48. return new Box(Math.max(fm.stringWidth("[. . . .]"),
  49. fm.stringWidth(getLabel())),
  50. fm.getAscent()+fm.getDescent());
  51. }
  52. public String getPath() { return "";}
  53. public void setPath(String p) {}
  54. public String getDir() { return ""; }
  55. public void setDir(String d) {}
  56. public void setWeight(double w) {weight=w;}
  57. public double getWeight() {return weight;}
  58. public void setDegree(int d) { degree=d; }
  59. public int getDegree() { return degree; }
  60. public boolean isDummy() { return false; }
  61. public Enumeration getChildren() {
  62. return ((Vector)(children.clone())).elements();
  63. }
  64. public void addChild(Vertex v) {
  65. children.addElement(v);
  66. v.parents.addElement(this);
  67. }
  68. public void removeChild(Vertex v) {
  69. children.removeElement(v);
  70. v.parents.removeElement(this);
  71. }
  72. public boolean isChild(Vertex v) {
  73. return children.indexOf(v)>=0;
  74. }
  75. public boolean isParent(Vertex v) {
  76. return parents.indexOf(v)>=0;
  77. }
  78. public Enumeration getParents() {
  79. return ((Vector)(parents.clone())).elements();
  80. }
  81. public void addParent(Vertex v) {
  82. parents.addElement(v);
  83. v.children.addElement(this);
  84. }
  85. public void removeParent(Vertex v) {
  86. parents.removeElement(v);
  87. v.children.removeElement(this);
  88. }
  89. /********************************************************************/
  90. /* get all predecessor vertices */
  91. /********************************************************************/
  92. public Vector getPreds() {
  93. Vector v1=new Vector(10,10);
  94. Vertex vx1,vx2;
  95. Enumeration e1,e2;
  96. e1=getParents();
  97. while (e1.hasMoreElements()) {
  98. vx1=(Vertex)(e1.nextElement());
  99. if (v1.indexOf(vx1)<0) v1.addElement(vx1);
  100. e2=vx1.getPreds().elements();
  101. while (e2.hasMoreElements()) {
  102. vx2=(Vertex)(e2.nextElement());
  103. if (v1.indexOf(vx2)<0) v1.addElement(vx2);
  104. }
  105. }
  106. return v1;
  107. }
  108. /********************************************************************/
  109. /* get all successor vertices */
  110. /********************************************************************/
  111. public Vector getSuccs() {
  112. Vector v1=new Vector(10,10);
  113. Vertex vx1,vx2;
  114. Enumeration e1,e2;
  115. e1=getChildren();
  116. while (e1.hasMoreElements()) {
  117. vx1=(Vertex)(e1.nextElement());
  118. if (v1.indexOf(vx1)<0) v1.addElement(vx1);
  119. e2=vx1.getSuccs().elements();
  120. while (e2.hasMoreElements()) {
  121. vx2=(Vertex)(e2.nextElement());
  122. if (v1.indexOf(vx2)<0) v1.addElement(vx2);
  123. }
  124. }
  125. return v1;
  126. }
  127. public void setX(int x) {this.x=x;}
  128. public void setY(int y) {this.y=y;}
  129. public int getX() {return x;}
  130. public int getY() {return y;}
  131. public abstract int leftX();
  132. public abstract int rightX();
  133. public abstract void draw(Graphics g);
  134. public void drawButtons(Graphics g) {}
  135. public void drawBox(Graphics g,Color boxColor) {}
  136. public void removeButtons(Graphics g) {}
  137. public boolean contains(int x,int y) { return false; }
  138. public boolean leftButton(int x,int y) { return false; }
  139. public boolean rightButton(int x,int y) { return false; }
  140. public void PS(PrintWriter p) {}
  141. }