lib/browser/GraphBrowser/Region.java
author paulson
Wed, 02 Dec 1998 15:53:05 +0100
changeset 6006 d2e271b8d651
parent 3599 89cbba12863d
child 33686 8e33ca8832b1
permissions -rw-r--r--
new rule rev_bexI
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/Region.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 is an auxiliary class which is used by the layout algorithm when
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     8
  calculating coordinates with the "pendulum method". A "region" is a
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     9
  group of nodes which "stick together".
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
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    12
package GraphBrowser;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    13
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    14
import java.util.*;
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 Region {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    17
	Vector vertices=new Vector(10,10);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    18
	Graph gra;
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 Region(Graph g) { gra=g; }
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    21
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    22
	public void addVertex(Vertex v) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    23
		vertices.addElement(v);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    24
	}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    25
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    26
	public Enumeration getVertices() {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    27
		return vertices.elements();
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
	public int pred_deflection() {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    31
		float d1=0;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    32
		int n=0;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    33
		Enumeration e1=vertices.elements();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    34
		while (e1.hasMoreElements()) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    35
			float d2=0;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    36
			int p=0;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    37
			n++;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    38
			Vertex v=(Vertex)(e1.nextElement());
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    39
			Enumeration e2=v.getParents();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    40
			while (e2.hasMoreElements()) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    41
				p++;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    42
				d2+=((Vertex)(e2.nextElement())).getX()-v.getX();
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
			if (p>0) d1+=d2/p;
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
		return (int)(Math.round(d1/n));
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
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    49
	public int succ_deflection() {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    50
		float d1=0;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    51
		int n=0;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    52
		Enumeration e1=vertices.elements();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    53
		while (e1.hasMoreElements()) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    54
			float d2=0;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    55
			int p=0;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    56
			n++;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    57
			Vertex v=(Vertex)(e1.nextElement());
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    58
			Enumeration e2=v.getChildren();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    59
			while (e2.hasMoreElements()) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    60
				p++;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    61
				d2+=((Vertex)(e2.nextElement())).getX()-v.getX();
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
			if (p>0) d1+=d2/p;
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
		return (int)(Math.round(d1/n));
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
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    68
	public void move(int x) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    69
		Enumeration e1=vertices.elements();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    70
		while (e1.hasMoreElements()) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    71
			Vertex v=(Vertex)(e1.nextElement());
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    72
			v.setX(v.getX()+x);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    73
		}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    74
	}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    75
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    76
	public void combine(Region r2) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    77
		Enumeration e1=r2.getVertices();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    78
		while (e1.hasMoreElements()) addVertex((Vertex)(e1.nextElement()));
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    79
	}
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
	public int spaceBetween(Region r2) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    82
		return ((Vertex)(r2.getVertices().nextElement())).leftX()-
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    83
			((Vertex)(vertices.lastElement())).rightX()-
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    84
			gra.box_hspace+gra.box_width;
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 boolean touching(Region r2) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    88
		return spaceBetween(r2)==0;
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
}