-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIManager.pde
91 lines (85 loc) · 2.26 KB
/
UIManager.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import java.util.HashMap;
class UIManager{
public UIManager(){
menus = new HashMap <String, Menu>();
graphs = new HashMap <String, Graph>();
}
public void addMenu(String id, int w, int h){
menus.put(id,new Menu(w,h));
}
public void addMenuButton(String menuId, String buttonId, LabelInterface labelInterface){
getMenu(menuId).addButton(buttonId, labelInterface);
}
public void setGraph(String id, Graph graph){
this.graphs.put(id,graph);
}
public Menu getMenu(String id){
return menus.get(id);
}
public void hideMenu(String id){
Menu m=getMenu(id);
if( m != null){
m.hide();
m.unhighlight();
}
}
public void hideAllMenus(){
for(Menu m : menus.values()){
m.hide();
m.unhighlight();
}
}
public void clear(){
menus.clear();
for(Graph g : graphs.values())
g.clear();
}
public Graph getGraph(String id){
return graphs.get(id);
}
public void drawMenus(){
for(Menu m : menus.values())
m.draw();
}
public Label getIntersectingLabel(float x, float y){
Label l = null;
//for all graphs
Iterator itX =graphs.values().iterator();
while(l == null && itX.hasNext()){
Graph g = (Graph)itX.next();
//check if point intersects any labels
if(g != null){
Iterator itY =g.getVertexSet().iterator();
if(g.isDrawVertices()){
while(l==null && itY.hasNext()){
Vertex v = (Vertex)itY.next();
if(v.intersects(x,y)){
l = v;
}
}
}
if(g.isDrawEdges()){
//check all edges
itY = g.getEdgeSet().iterator();
while(l==null && itY.hasNext()){
Edge v = (Edge)itY.next();
if(v.intersects(x,y)){
l = v;
}
}
//check menu labels if intersecting label still not found
}
}//end if g != null
}//end while not found
Iterator itZ = menus.values().iterator();
while(l==null && itZ.hasNext()){
Button b = ((Menu)itZ.next()).getIntersectingButton(x,y);
if(b != null){
l = b;
}
}
return l;
}
HashMap <String, Menu> menus;
HashMap <String, Graph> graphs;
}