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