/Users/lyon/j4p/src/graphics/graph/ControlPanel.java
|
1 package graphics.graph;
2
3 import gui.run.RunButton;
4 import gui.run.RunCheckBox;
5
6 import java.awt.*;
7
8 public class ControlPanel {
9 private ImagePanel imagePanel
10 = ImagePanel.getImagePanel();
11 private GraphManager graphManager
12 = GraphManager.getGraphManager();
13
14
15 private Panel controlPanel
16 = getControlPanel();
17 private Nodes nodes
18 = GraphFactory.getNodes();
19 private EdgesBean edgesBean
20 = EdgesBean.getEdgesBean();
21
22 public Nodes getNodes() {
23 return nodes;
24 }
25
26 public void println(Object o) {
27 System.out.println(o);
28 }
29
30 public void println(Object o[]) {
31 for (int i = 0; i < o.length; i++)
32 System.out.println(o[i]);
33 }
34
35 public void synthesizeRMI() {
36 println("Synthesizing RMI");
37 println("getting bridge endpoints:");
38 Node fixedNodes[] =
39 nodes.getFixedNodes();
40 println(fixedNodes);
41 }
42
43 public void addEdge(String nodeName1, String nodeName2) {
44 edgesBean.addEdge(nodeName1, nodeName2);
45 }
46
47 public GraphManager getGraphManager() {
48 return graphManager;
49 }
50
51 public ImagePanel getImagePanel() {
52 return imagePanel;
53 }
54
55 public Panel getControlPanel() {
56 Panel p = new Panel();
57 p.setLayout(new FlowLayout());
58 addComponentsToPanel(p);
59 return p;
60 }
61
62 private void addComponentsToPanel(Panel p) {
63 p.add(new RunButton("Scramble") {
64 public void run() {
65 scrambleNodes();
66 }
67 });
68 p.add(new RunButton("Synthesize RMI") {
69 public void run() {
70 synthesizeRMI();
71 }
72 });
73 p.add(new RunButton("Shake") {
74 public void run() {
75 shakeNodes();
76 }
77 });
78
79 p.add(new RunCheckBox("Stress") {
80 public void run() {
81 StressBean sb = StressBean.getStressBean();
82 sb.setStress(isSelected());
83 }
84 });
85
86 p.add(new RunCheckBox("Random") {
87 public void run() {
88 RandomBean rb = RandomBean.getRandomBean();
89 rb.setRandom(isSelected());
90 graphManager.getRelaxThreadMgr().setRandom(isSelected());
91 }
92 });
93 }
94
95 public void start() {
96 graphManager.start();
97 }
98
99 private void shakeNodes() {
100 Dimension d = imagePanel.getSize();
101 for (int i = 0;
102 i < nodes.getNumberOfNodes();
103 i++) {
104 Node n = nodes.getNode(i);
105 if (n.isFixed()) return;
106 n.setX(n.getX()
107 + (180 * Math.random() - 90));
108 n.setY(n.getY()
109 + (180 * Math.random() - 90));
110 }
111 }
112
113 private void scrambleNodes() {
114 Dimension d = imagePanel.getSize();
115 for (int i = 0; i < nodes.getNumberOfNodes(); i++) {
116 Node n = nodes.getNode(i);
117 if (!n.isFixed()) {
118 n.setX(10 + (d.width - 20) * Math.random());
119 n.setY(10 + (d.height - 20) * Math.random());
120 }
121 }
122 }
123 }
124