| 
3599
 | 
     1  | 
/***************************************************************************
  | 
| 
 | 
     2  | 
  Title:      GraphBrowser/Vertex.java
  | 
| 
 | 
     3  | 
  ID:         $Id$
  | 
| 
 | 
     4  | 
  Author:     Stefan Berghofer, TU Muenchen
  | 
| 
 | 
     5  | 
  | 
| 
 | 
     6  | 
  This class contains attributes and methods common to all kinds of
  | 
| 
 | 
     7  | 
  vertices (e.g. coordinates, successors, predecessors).
  | 
| 
 | 
     8  | 
***************************************************************************/
  | 
| 
 | 
     9  | 
  | 
| 
 | 
    10  | 
package GraphBrowser;
  | 
| 
 | 
    11  | 
  | 
| 
 | 
    12  | 
import java.util.*;
  | 
| 
 | 
    13  | 
import java.awt.*;
  | 
| 
 | 
    14  | 
import java.io.*;
  | 
| 
 | 
    15  | 
  | 
| 
 | 
    16  | 
abstract class Vertex {
 | 
| 
 | 
    17  | 
	Vector children=new Vector(10,10);
  | 
| 
 | 
    18  | 
	Vector parents=new Vector(10,10);
  | 
| 
 | 
    19  | 
	int degree=0;
  | 
| 
 | 
    20  | 
	int number=-1;
  | 
| 
 | 
    21  | 
	double weight=0;
  | 
| 
 | 
    22  | 
	int x,y;
  | 
| 
 | 
    23  | 
	Graph gra;
  | 
| 
 | 
    24  | 
  | 
| 
 | 
    25  | 
	public abstract Object clone();
  | 
| 
 | 
    26  | 
  | 
| 
 | 
    27  | 
	public void setGraph(Graph g) { gra=g; }
 | 
| 
 | 
    28  | 
  | 
| 
 | 
    29  | 
	public int countChildren() { return children.size(); }
 | 
| 
 | 
    30  | 
  | 
| 
 | 
    31  | 
	/** getInflate returns a vector of vertices which get **/
  | 
| 
 | 
    32  | 
	/** inflated again if the user clicks on this vertex  **/
  | 
| 
 | 
    33  | 
  | 
| 
 | 
    34  | 
	public void setInflate(Vector v) {}
 | 
| 
 | 
    35  | 
  | 
| 
 | 
    36  | 
	public Vector getInflate() { return null; }
 | 
| 
 | 
    37  | 
  | 
| 
 | 
    38  | 
	/** getUp returns a vector of vertices which get inflated   **/
  | 
| 
 | 
    39  | 
	/** again, if the user clicks on this vertex's upward arrow **/
  | 
| 
 | 
    40  | 
  | 
| 
 | 
    41  | 
	public Vector getUp() { return null; }
 | 
| 
 | 
    42  | 
  | 
| 
 | 
    43  | 
	public void setUp(Vector v) {}
 | 
| 
 | 
    44  | 
  | 
| 
 | 
    45  | 
	/** getUp returns a vector of vertices which get inflated     **/
  | 
| 
 | 
    46  | 
	/** again, if the user clicks on this vertex's downward arrow **/
  | 
| 
 | 
    47  | 
  | 
| 
 | 
    48  | 
	public Vector getDown() { return null; }
 | 
| 
 | 
    49  | 
  | 
| 
 | 
    50  | 
	public void setDown(Vector v) {}
 | 
| 
 | 
    51  | 
  | 
| 
 | 
    52  | 
	/** internal number, for decoding / encoding etc. **/
  | 
| 
 | 
    53  | 
  | 
| 
 | 
    54  | 
	public int getNumber() { return number; }
 | 
| 
 | 
    55  | 
  | 
| 
 | 
    56  | 
	public void setNumber(int n) { number=n; }
 | 
| 
 | 
    57  | 
  | 
| 
 | 
    58  | 
	public String getLabel() {return "";}
 | 
| 
 | 
    59  | 
  | 
| 
 | 
    60  | 
	public void setLabel(String s) {}
 | 
| 
 | 
    61  | 
  | 
| 
 | 
    62  | 
	/** unique identifier **/
  | 
| 
 | 
    63  | 
  | 
| 
 | 
    64  | 
	public String getID() {return "";}
 | 
| 
 | 
    65  | 
  | 
| 
 | 
    66  | 
	public void setID(String s) {}
 | 
| 
 | 
    67  | 
  | 
| 
13968
 | 
    68  | 
	public Box getLabelSize(Graphics g) {
 | 
| 
 | 
    69  | 
		AbstractFontMetrics fm = g == null ? 
  | 
| 
 | 
    70  | 
      (AbstractFontMetrics) new DefaultFontMetrics(12) : 
  | 
| 
 | 
    71  | 
      (AbstractFontMetrics) new AWTFontMetrics(g.getFontMetrics(g.getFont()));
  | 
| 
3599
 | 
    72  | 
		
  | 
| 
13968
 | 
    73  | 
		return new Box(Math.max(fm.stringWidth("[. . . .]"),
 | 
| 
 | 
    74  | 
                            fm.stringWidth(getLabel())),
  | 
| 
 | 
    75  | 
                   fm.getAscent()+fm.getDescent());
  | 
| 
3599
 | 
    76  | 
	}
  | 
| 
 | 
    77  | 
		
  | 
| 
 | 
    78  | 
	public String getPath() { return "";}
 | 
| 
 | 
    79  | 
  | 
| 
 | 
    80  | 
	public void setPath(String p) {}
 | 
| 
 | 
    81  | 
  | 
| 
 | 
    82  | 
	public String getDir() { return ""; }
 | 
| 
 | 
    83  | 
  | 
| 
 | 
    84  | 
	public void setDir(String d) {}
 | 
| 
 | 
    85  | 
  | 
| 
 | 
    86  | 
	public void setWeight(double w) {weight=w;}
 | 
| 
 | 
    87  | 
  | 
| 
 | 
    88  | 
	public double getWeight() {return weight;}
 | 
| 
 | 
    89  | 
  | 
| 
 | 
    90  | 
	public void setDegree(int d) { degree=d; }
 | 
| 
 | 
    91  | 
  | 
| 
 | 
    92  | 
	public int getDegree() { return degree; }
 | 
| 
 | 
    93  | 
  | 
| 
 | 
    94  | 
	public boolean isDummy() { return false; }
 | 
| 
 | 
    95  | 
  | 
| 
 | 
    96  | 
	public Enumeration getChildren() {
 | 
| 
 | 
    97  | 
		return ((Vector)(children.clone())).elements();
  | 
| 
 | 
    98  | 
	}
  | 
| 
 | 
    99  | 
  | 
| 
 | 
   100  | 
	public void addChild(Vertex v) {
 | 
| 
 | 
   101  | 
		children.addElement(v);
  | 
| 
 | 
   102  | 
		v.parents.addElement(this);
  | 
| 
 | 
   103  | 
	}
  | 
| 
 | 
   104  | 
  | 
| 
 | 
   105  | 
	public void removeChild(Vertex v) {
 | 
| 
 | 
   106  | 
		children.removeElement(v);
  | 
| 
 | 
   107  | 
		v.parents.removeElement(this);
  | 
| 
 | 
   108  | 
	}
  | 
| 
 | 
   109  | 
  | 
| 
 | 
   110  | 
	public boolean isChild(Vertex v) {
 | 
| 
 | 
   111  | 
		return children.indexOf(v)>=0;
  | 
| 
 | 
   112  | 
	}
  | 
| 
 | 
   113  | 
  | 
| 
 | 
   114  | 
	public boolean isParent(Vertex v) {
 | 
| 
 | 
   115  | 
		return parents.indexOf(v)>=0;
  | 
| 
 | 
   116  | 
	}
  | 
| 
 | 
   117  | 
  | 
| 
 | 
   118  | 
	public Enumeration getParents() {
 | 
| 
 | 
   119  | 
		return ((Vector)(parents.clone())).elements();
  | 
| 
 | 
   120  | 
	}
  | 
| 
 | 
   121  | 
  | 
| 
 | 
   122  | 
	public void addParent(Vertex v) {
 | 
| 
 | 
   123  | 
		parents.addElement(v);
  | 
| 
 | 
   124  | 
		v.children.addElement(this);
  | 
| 
 | 
   125  | 
	}
  | 
| 
 | 
   126  | 
  | 
| 
 | 
   127  | 
	public void removeParent(Vertex v) {
 | 
| 
 | 
   128  | 
		parents.removeElement(v);
  | 
| 
 | 
   129  | 
		v.children.removeElement(this);
  | 
| 
 | 
   130  | 
	}
  | 
| 
 | 
   131  | 
  | 
| 
 | 
   132  | 
	/********************************************************************/
  | 
| 
 | 
   133  | 
	/*                   get all predecessor vertices                   */
  | 
| 
 | 
   134  | 
	/********************************************************************/
  | 
| 
 | 
   135  | 
  | 
| 
 | 
   136  | 
	public Vector getPreds() {
 | 
| 
17771
 | 
   137  | 
	    Vector preds=new Vector(10,10);
  | 
| 
 | 
   138  | 
	    Vector todo=(Vector)(parents.clone());
  | 
| 
 | 
   139  | 
	    Vertex vx1,vx2;
  | 
| 
 | 
   140  | 
	    Enumeration e;
  | 
| 
3599
 | 
   141  | 
  | 
| 
17771
 | 
   142  | 
	    while (!todo.isEmpty()) {
 | 
| 
 | 
   143  | 
		vx1=(Vertex)(todo.lastElement());
  | 
| 
 | 
   144  | 
		todo.removeElementAt(todo.size()-1);
  | 
| 
 | 
   145  | 
		preds.addElement(vx1);
  | 
| 
 | 
   146  | 
		e=vx1.parents.elements();
  | 
| 
 | 
   147  | 
		while (e.hasMoreElements()) {
 | 
| 
 | 
   148  | 
		    vx2=(Vertex)(e.nextElement());
  | 
| 
 | 
   149  | 
		    if (preds.indexOf(vx2)<0 && todo.indexOf(vx2)<0)
  | 
| 
 | 
   150  | 
			todo.addElement(vx2);
  | 
| 
3599
 | 
   151  | 
		}
  | 
| 
17771
 | 
   152  | 
	    }
  | 
| 
3599
 | 
   153  | 
  | 
| 
17771
 | 
   154  | 
	    return preds;
  | 
| 
3599
 | 
   155  | 
	}
  | 
| 
 | 
   156  | 
  | 
| 
 | 
   157  | 
	/********************************************************************/
  | 
| 
 | 
   158  | 
	/*                     get all successor vertices                   */
  | 
| 
 | 
   159  | 
	/********************************************************************/
  | 
| 
 | 
   160  | 
  | 
| 
 | 
   161  | 
	public Vector getSuccs() {
 | 
| 
17771
 | 
   162  | 
	    Vector succs=new Vector(10,10);
  | 
| 
 | 
   163  | 
	    Vector todo=(Vector)(children.clone());
  | 
| 
 | 
   164  | 
	    Vertex vx1,vx2;
  | 
| 
 | 
   165  | 
	    Enumeration e;
  | 
| 
3599
 | 
   166  | 
  | 
| 
17771
 | 
   167  | 
	    while (!todo.isEmpty()) {
 | 
| 
 | 
   168  | 
		vx1=(Vertex)(todo.lastElement());
  | 
| 
 | 
   169  | 
		todo.removeElementAt(todo.size()-1);
  | 
| 
 | 
   170  | 
		succs.addElement(vx1);
  | 
| 
 | 
   171  | 
		e=vx1.children.elements();
  | 
| 
 | 
   172  | 
		while (e.hasMoreElements()) {
 | 
| 
 | 
   173  | 
		    vx2=(Vertex)(e.nextElement());
  | 
| 
 | 
   174  | 
		    if (succs.indexOf(vx2)<0 && todo.indexOf(vx2)<0)
  | 
| 
 | 
   175  | 
			todo.addElement(vx2);
  | 
| 
3599
 | 
   176  | 
		}
  | 
| 
17771
 | 
   177  | 
	    }
  | 
| 
3599
 | 
   178  | 
  | 
| 
17771
 | 
   179  | 
	    return succs;
  | 
| 
3599
 | 
   180  | 
	}
  | 
| 
 | 
   181  | 
  | 
| 
 | 
   182  | 
	public void setX(int x) {this.x=x;}
 | 
| 
 | 
   183  | 
  | 
| 
 | 
   184  | 
	public void setY(int y) {this.y=y;}
 | 
| 
 | 
   185  | 
  | 
| 
 | 
   186  | 
	public int getX() {return x;}
 | 
| 
 | 
   187  | 
  | 
| 
 | 
   188  | 
	public int getY() {return y;}
 | 
| 
 | 
   189  | 
  | 
| 
 | 
   190  | 
	public abstract int leftX();
  | 
| 
 | 
   191  | 
  | 
| 
 | 
   192  | 
	public abstract int rightX();
  | 
| 
 | 
   193  | 
  | 
| 
 | 
   194  | 
	public abstract void draw(Graphics g);
  | 
| 
 | 
   195  | 
  | 
| 
 | 
   196  | 
	public void drawButtons(Graphics g) {}
 | 
| 
 | 
   197  | 
  | 
| 
 | 
   198  | 
	public void drawBox(Graphics g,Color boxColor) {}
 | 
| 
 | 
   199  | 
  | 
| 
 | 
   200  | 
	public void removeButtons(Graphics g) {}
 | 
| 
 | 
   201  | 
  | 
| 
 | 
   202  | 
	public boolean contains(int x,int y) { return false; }
 | 
| 
 | 
   203  | 
  | 
| 
 | 
   204  | 
	public boolean leftButton(int x,int y) { return false; }
 | 
| 
 | 
   205  | 
  | 
| 
 | 
   206  | 
	public boolean rightButton(int x,int y) { return false; }
 | 
| 
 | 
   207  | 
  | 
| 
6541
 | 
   208  | 
	public void PS(PrintWriter p) {}
 | 
| 
3599
 | 
   209  | 
}
  |