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