NormalVertex.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /***************************************************************************
  2. Title: GraphBrowser/NormalVertex.java
  3. ID: $Id$
  4. Author: Stefan Berghofer, TU Muenchen
  5. License: GPL (GNU GENERAL PUBLIC LICENSE)
  6. This class represents an ordinary vertex. It contains methods for
  7. drawing and PostScript output.
  8. ***************************************************************************/
  9. package GraphBrowser;
  10. import java.util.*;
  11. import java.awt.*;
  12. import java.io.*;
  13. class NormalVertex extends Vertex {
  14. String label="",path="",dir="",ID="";
  15. Vector up,down,inflate=null;
  16. public Object clone() {
  17. Vertex ve=new NormalVertex(label);
  18. ve.setID(ID);
  19. ve.setNumber(getNumber());
  20. ve.setUp(getUp());ve.setDown(getDown());
  21. ve.setX(getX());ve.setY(getY());
  22. ve.setPath(getPath());
  23. return ve;
  24. }
  25. /*** Constructor ***/
  26. public NormalVertex(String s) { label=s; }
  27. public void setInflate(Vector v) { inflate=v; }
  28. public Vector getInflate() { return inflate; }
  29. public Vector getUp() { return up; }
  30. public void setUp(Vector v) { up=v; }
  31. public Vector getDown() { return down; }
  32. public void setDown(Vector v) { down=v; }
  33. public String getLabel() {return label;}
  34. public void setLabel(String s) {label=s;}
  35. public void setID(String s) { ID=s; }
  36. public String getID() { return ID; }
  37. public String getPath() { return path;}
  38. public void setPath(String p) { path=p; }
  39. public String getDir() { return dir; }
  40. public void setDir(String d) { dir=d; }
  41. public int leftX() { return getX()-gra.box_width2; }
  42. public int rightX() { return getX()+gra.box_width2; }
  43. public void drawBox(Graphics g,Color boxColor) {
  44. FontMetrics fm = g.getFontMetrics(g.getFont());
  45. int h=fm.getAscent()+fm.getDescent();
  46. g.setColor(boxColor);
  47. g.fillRect(getX()-gra.box_width2,getY(),gra.box_width,gra.box_height);
  48. g.setColor(Color.black);
  49. g.drawRect(getX()-gra.box_width2,getY(),gra.box_width,gra.box_height);
  50. if (getNumber()<0) {
  51. g.setColor(Color.red);
  52. label=label.substring(1,label.length()-1);
  53. while (label.length()>0 && fm.stringWidth("["+label+"]")>gra.box_width-8)
  54. label=label.substring(0,label.length()-1);
  55. label="["+label+"]";
  56. }
  57. g.drawString(label,
  58. (int)Math.round((gra.box_width-fm.stringWidth(label))/2.0)+getX()-gra.box_width2,
  59. fm.getAscent()+(int)Math.round((gra.box_height-h)/2.0)+getY());
  60. }
  61. public void removeButtons(Graphics g) {
  62. drawBox(g,Color.lightGray);
  63. }
  64. public void draw(Graphics g) {
  65. drawBox(g,Color.lightGray);
  66. g.setColor(Color.black);
  67. Enumeration e1=getChildren();
  68. while (e1.hasMoreElements()) {
  69. Vertex v=(Vertex)(e1.nextElement());
  70. if (!v.isDummy())
  71. g.drawLine(getX(),getY()+gra.box_height,v.getX(),v.getY());
  72. }
  73. }
  74. public boolean contains(int x,int y) {
  75. return (x>=leftX() && x<=rightX() && y>=getY() &&
  76. y<=getY()+gra.box_height);
  77. }
  78. public boolean leftButton(int x,int y) {
  79. return contains(x,y) && x<=leftX()+gra.box_height && getParents().hasMoreElements() && getNumber()>=0;
  80. }
  81. public boolean rightButton(int x,int y) {
  82. return contains(x,y) && x>=rightX()-gra.box_height && getChildren().hasMoreElements() && getNumber()>=0;
  83. }
  84. public void drawButtons(Graphics g) {
  85. if (getNumber()<0) return;
  86. int l=gra.box_height*2/3,d=gra.box_height/6;
  87. int up_x[] = { leftX()+d , leftX()+d+l/2 , leftX()+d+l };
  88. int up_y[] = { getY()+d+l , getY()+d , getY()+d+l };
  89. int down_x[] = { rightX()-d-l , rightX()-d-l/2 , rightX()-d };
  90. int down_y[] = { getY()+d , getY()+d+l , getY()+d };
  91. if (getParents().hasMoreElements()) {
  92. g.setColor(Color.gray);
  93. g.fillRect(leftX()+1,getY()+1,gra.box_height-1,gra.box_height-1);
  94. g.setColor(getUp()!=null ? Color.red : Color.green);
  95. g.fillPolygon(up_x,up_y,3);
  96. }
  97. if (getChildren().hasMoreElements()) {
  98. g.setColor(Color.gray);
  99. g.fillRect(rightX()+1-gra.box_height,getY()+1,gra.box_height,gra.box_height-1);
  100. g.setColor(getDown()!=null ? Color.red : Color.green);
  101. g.fillPolygon(down_x,down_y,3);
  102. }
  103. g.setColor(Color.black);
  104. }
  105. public void PS(PrintWriter p) {
  106. p.print(leftX()+" "+getY()+" "+gra.box_width+" "+
  107. gra.box_height+" (");
  108. for (int i=0;i<label.length();i++)
  109. {
  110. if (("()\\").indexOf(label.charAt(i))>=0)
  111. p.print("\\");
  112. p.print(label.charAt(i));
  113. }
  114. p.println(") b");
  115. Enumeration e1=getChildren();
  116. while (e1.hasMoreElements()) {
  117. Vertex v=(Vertex)(e1.nextElement());
  118. if (!v.isDummy())
  119. p.println("n "+getX()+" "+(getY()+gra.box_height)+
  120. " m "+v.getX()+" "+v.getY()+" l s");
  121. }
  122. }
  123. }