lib/browser/GraphBrowser/NormalVertex.java
author wenzelm
Thu, 10 Feb 2000 20:54:40 +0100
changeset 8232 6b19ee96546c
parent 6541 d3ac35b2bfbf
child 11872 4f24fd4dbcf5
permissions -rw-r--r--
\isabellesimplestyle;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3599
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     1
/***************************************************************************
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     2
  Title:      GraphBrowser/NormalVertex.java
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     3
  ID:         $Id$
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     4
  Author:     Stefan Berghofer, TU Muenchen
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     5
  Copyright   1997  TU Muenchen
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     6
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     7
  This class represents an ordinary vertex. It contains methods for
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     8
  drawing and PostScript output.
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     9
***************************************************************************/
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    10
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    11
package GraphBrowser;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    12
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    13
import java.util.*;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    14
import java.awt.*;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    15
import java.io.*;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    16
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    17
class NormalVertex extends Vertex {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    18
	String label="",path="",dir="",ID="";
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    19
	Vector up,down,inflate=null;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    20
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    21
	public Object clone() {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    22
		Vertex ve=new NormalVertex(label);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    23
                ve.setID(ID);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    24
		ve.setNumber(getNumber());
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    25
		ve.setUp(getUp());ve.setDown(getDown());
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    26
		ve.setX(getX());ve.setY(getY());
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    27
		ve.setPath(getPath());
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    28
		return ve;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    29
	}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    30
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    31
	/*** Constructor ***/
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    32
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    33
	public NormalVertex(String s) { label=s; }
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    34
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    35
	public void setInflate(Vector v) { inflate=v; }
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    36
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    37
	public Vector getInflate() { return inflate; }
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    38
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    39
	public Vector getUp() { return up; }
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    40
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    41
	public void setUp(Vector v) { up=v; }
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    42
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    43
	public Vector getDown() { return down; }
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    44
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    45
	public void setDown(Vector v) { down=v; }
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    46
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    47
	public String getLabel() {return label;}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    48
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    49
	public void setLabel(String s) {label=s;}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    50
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    51
	public void setID(String s) { ID=s; }
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    52
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    53
        public String getID() { return ID; }
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    54
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    55
	public String getPath() { return path;}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    56
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    57
	public void setPath(String p) { path=p; }
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    58
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    59
	public String getDir() { return dir; }
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    60
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    61
	public void setDir(String d) { dir=d; }
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    62
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    63
	public int leftX() { return getX()-gra.box_width2; }
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    64
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    65
	public int rightX() { return getX()+gra.box_width2; }
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    66
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    67
	public void drawBox(Graphics g,Color boxColor) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    68
		FontMetrics fm=g.getFontMetrics(font);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    69
		g.setFont(font);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    70
		int h=fm.getAscent()+fm.getDescent();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    71
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    72
		g.setColor(boxColor);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    73
		g.fillRect(getX()-gra.box_width2,getY(),gra.box_width,gra.box_height);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    74
		g.setColor(Color.black);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    75
		g.drawRect(getX()-gra.box_width2,getY(),gra.box_width,gra.box_height);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    76
		if (getNumber()<0) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    77
			g.setColor(Color.red);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    78
			label=label.substring(1,label.length()-1);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    79
			while (label.length()>0 && fm.stringWidth("["+label+"]")>gra.box_width-8)
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    80
					label=label.substring(0,label.length()-1);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    81
			label="["+label+"]";
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    82
		}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    83
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    84
		g.drawString(label,
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    85
		             (int)Math.round((gra.box_width-fm.stringWidth(label))/2.0)+getX()-gra.box_width2,
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    86
				fm.getAscent()+(int)Math.round((gra.box_height-h)/2.0)+getY());
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    87
	}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    88
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    89
	public void removeButtons(Graphics g) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    90
		drawBox(g,Color.lightGray);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    91
	}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    92
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    93
	public void draw(Graphics g) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    94
		drawBox(g,Color.lightGray);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    95
		g.setColor(Color.black);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    96
		Enumeration e1=getChildren();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    97
		while (e1.hasMoreElements()) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    98
			Vertex v=(Vertex)(e1.nextElement());
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    99
			if (!v.isDummy())
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   100
				g.drawLine(getX(),getY()+gra.box_height,v.getX(),v.getY());
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   101
		}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   102
	}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   103
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   104
	public boolean contains(int x,int y) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   105
		return (x>=leftX() && x<=rightX() && y>=getY() &&
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   106
                        y<=getY()+gra.box_height);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   107
	}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   108
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   109
	public boolean leftButton(int x,int y) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   110
		return contains(x,y) && x<=leftX()+gra.box_height && getParents().hasMoreElements() && getNumber()>=0;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   111
	}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   112
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   113
	public boolean rightButton(int x,int y) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   114
		return contains(x,y) && x>=rightX()-gra.box_height && getChildren().hasMoreElements() && getNumber()>=0;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   115
	}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   116
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   117
	public void drawButtons(Graphics g) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   118
		if (getNumber()<0) return;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   119
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   120
		int l=gra.box_height*2/3,d=gra.box_height/6;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   121
		int up_x[] = { leftX()+d , leftX()+d+l/2 , leftX()+d+l };
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   122
		int up_y[] = { getY()+d+l , getY()+d , getY()+d+l };
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   123
		int down_x[] = { rightX()-d-l , rightX()-d-l/2 , rightX()-d };
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   124
		int down_y[] = { getY()+d , getY()+d+l , getY()+d };
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   125
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   126
		if (getParents().hasMoreElements()) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   127
			g.setColor(Color.gray);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   128
			g.fillRect(leftX()+1,getY()+1,gra.box_height-1,gra.box_height-1);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   129
			g.setColor(getUp()!=null ? Color.red : Color.green);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   130
			g.fillPolygon(up_x,up_y,3);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   131
		}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   132
		if (getChildren().hasMoreElements()) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   133
			g.setColor(Color.gray);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   134
			g.fillRect(rightX()+1-gra.box_height,getY()+1,gra.box_height,gra.box_height-1);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   135
			g.setColor(getDown()!=null ? Color.red : Color.green);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   136
			g.fillPolygon(down_x,down_y,3);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   137
		}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   138
		g.setColor(Color.black);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   139
	}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   140
6541
d3ac35b2bfbf Updated to JDK 1.1.x
berghofe
parents: 3599
diff changeset
   141
	public void PS(PrintWriter p) {
3599
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   142
		p.print(leftX()+" "+getY()+" "+gra.box_width+" "+
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   143
		        gra.box_height+" (");
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   144
		for (int i=0;i<label.length();i++)
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   145
		{
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   146
			if (("()\\").indexOf(label.charAt(i))>=0)
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   147
				p.print("\\");
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   148
			p.print(label.charAt(i));
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   149
		}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   150
		p.println(") b");
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   151
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   152
		Enumeration e1=getChildren();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   153
		while (e1.hasMoreElements()) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   154
			Vertex v=(Vertex)(e1.nextElement());
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   155
			if (!v.isDummy())
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   156
				p.println("n "+getX()+" "+(getY()+gra.box_height)+
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   157
				" m "+v.getX()+" "+v.getY()+" l s");
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   158
		}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   159
	}	
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   160
}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   161