| 
3599
 | 
     1  | 
/***************************************************************************
  | 
| 
 | 
     2  | 
  Title:      GraphBrowser/Region.java
  | 
| 
 | 
     3  | 
  Author:     Stefan Berghofer, TU Muenchen
  | 
| 
50473
 | 
     4  | 
  Options:    :tabSize=4:
  | 
| 
3599
 | 
     5  | 
  | 
| 
 | 
     6  | 
  This is an auxiliary class which is used by the layout algorithm when
  | 
| 
 | 
     7  | 
  calculating coordinates with the "pendulum method". A "region" is a
  | 
| 
 | 
     8  | 
  group of nodes which "stick together".
  | 
| 
 | 
     9  | 
***************************************************************************/
  | 
| 
 | 
    10  | 
  | 
| 
 | 
    11  | 
package GraphBrowser;
  | 
| 
 | 
    12  | 
  | 
| 
 | 
    13  | 
import java.util.*;
  | 
| 
 | 
    14  | 
  | 
| 
 | 
    15  | 
class Region {
 | 
| 
 | 
    16  | 
	Vector vertices=new Vector(10,10);
  | 
| 
 | 
    17  | 
	Graph gra;
  | 
| 
 | 
    18  | 
  | 
| 
 | 
    19  | 
	public Region(Graph g) { gra=g; }
 | 
| 
 | 
    20  | 
  | 
| 
 | 
    21  | 
	public void addVertex(Vertex v) {
 | 
| 
 | 
    22  | 
		vertices.addElement(v);
  | 
| 
 | 
    23  | 
	}
  | 
| 
 | 
    24  | 
  | 
| 
 | 
    25  | 
	public Enumeration getVertices() {
 | 
| 
 | 
    26  | 
		return vertices.elements();
  | 
| 
 | 
    27  | 
	}
  | 
| 
 | 
    28  | 
  | 
| 
 | 
    29  | 
	public int pred_deflection() {
 | 
| 
 | 
    30  | 
		float d1=0;
  | 
| 
 | 
    31  | 
		int n=0;
  | 
| 
 | 
    32  | 
		Enumeration e1=vertices.elements();
  | 
| 
 | 
    33  | 
		while (e1.hasMoreElements()) {
 | 
| 
 | 
    34  | 
			float d2=0;
  | 
| 
 | 
    35  | 
			int p=0;
  | 
| 
 | 
    36  | 
			n++;
  | 
| 
 | 
    37  | 
			Vertex v=(Vertex)(e1.nextElement());
  | 
| 
 | 
    38  | 
			Enumeration e2=v.getParents();
  | 
| 
 | 
    39  | 
			while (e2.hasMoreElements()) {
 | 
| 
 | 
    40  | 
				p++;
  | 
| 
 | 
    41  | 
				d2+=((Vertex)(e2.nextElement())).getX()-v.getX();
  | 
| 
 | 
    42  | 
			}
  | 
| 
 | 
    43  | 
			if (p>0) d1+=d2/p;
  | 
| 
 | 
    44  | 
		}
  | 
| 
 | 
    45  | 
		return (int)(Math.round(d1/n));
  | 
| 
 | 
    46  | 
	}
  | 
| 
 | 
    47  | 
  | 
| 
 | 
    48  | 
	public int succ_deflection() {
 | 
| 
 | 
    49  | 
		float d1=0;
  | 
| 
 | 
    50  | 
		int n=0;
  | 
| 
 | 
    51  | 
		Enumeration e1=vertices.elements();
  | 
| 
 | 
    52  | 
		while (e1.hasMoreElements()) {
 | 
| 
 | 
    53  | 
			float d2=0;
  | 
| 
 | 
    54  | 
			int p=0;
  | 
| 
 | 
    55  | 
			n++;
  | 
| 
 | 
    56  | 
			Vertex v=(Vertex)(e1.nextElement());
  | 
| 
 | 
    57  | 
			Enumeration e2=v.getChildren();
  | 
| 
 | 
    58  | 
			while (e2.hasMoreElements()) {
 | 
| 
 | 
    59  | 
				p++;
  | 
| 
 | 
    60  | 
				d2+=((Vertex)(e2.nextElement())).getX()-v.getX();
  | 
| 
 | 
    61  | 
			}
  | 
| 
 | 
    62  | 
			if (p>0) d1+=d2/p;
  | 
| 
 | 
    63  | 
		}
  | 
| 
 | 
    64  | 
		return (int)(Math.round(d1/n));
  | 
| 
 | 
    65  | 
	}
  | 
| 
 | 
    66  | 
  | 
| 
 | 
    67  | 
	public void move(int x) {
 | 
| 
 | 
    68  | 
		Enumeration e1=vertices.elements();
  | 
| 
 | 
    69  | 
		while (e1.hasMoreElements()) {
 | 
| 
 | 
    70  | 
			Vertex v=(Vertex)(e1.nextElement());
  | 
| 
 | 
    71  | 
			v.setX(v.getX()+x);
  | 
| 
 | 
    72  | 
		}
  | 
| 
 | 
    73  | 
	}
  | 
| 
 | 
    74  | 
  | 
| 
 | 
    75  | 
	public void combine(Region r2) {
 | 
| 
 | 
    76  | 
		Enumeration e1=r2.getVertices();
  | 
| 
 | 
    77  | 
		while (e1.hasMoreElements()) addVertex((Vertex)(e1.nextElement()));
  | 
| 
 | 
    78  | 
	}
  | 
| 
 | 
    79  | 
  | 
| 
 | 
    80  | 
	public int spaceBetween(Region r2) {
 | 
| 
 | 
    81  | 
		return ((Vertex)(r2.getVertices().nextElement())).leftX()-
  | 
| 
 | 
    82  | 
			((Vertex)(vertices.lastElement())).rightX()-
  | 
| 
37738
 | 
    83  | 
			20;
  | 
| 
3599
 | 
    84  | 
	}
  | 
| 
 | 
    85  | 
  | 
| 
 | 
    86  | 
	public boolean touching(Region r2) {
 | 
| 
 | 
    87  | 
		return spaceBetween(r2)==0;
  | 
| 
 | 
    88  | 
	}
  | 
| 
 | 
    89  | 
}
  |