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