summaryrefslogtreecommitdiffstats
path: root/voronoi/CompGeomTest.java
blob: ebad8a93f484a5d5bdec403e7c34029a786580bd (plain) (blame)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package voronoi;
import java.applet.Applet;
import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.Color;
import java.awt.Event;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Panel;

public class CompGeomTest extends Frame {
	private static final long serialVersionUID = 1L;

	private Button clear, close, simde, simvo;
	private Checkbox hull, deltri, voronoi;
    
	private Panel subp1, subp022, subp2, subp3,  p,canvasp;
	private GeomCanvas c;
	
	private int cw, ch; // width and height for info frame and canvas

	private Font f;

	public CompGeomTest(Applet a) {
		super("COSC 6114 Computational Geometry - Zhenyu Pan");
		setBackground(Color.lightGray);

		// cw = Integer.parseInt(a.getParameter("canvas width"));
		cw = 750;
		// ch = Integer.parseInt(a.getParameter("canvas height"));
		ch = 550;

		clear = new Button("Clear Screen");
		close = new Button("Close Window");
		simde = new Button("Simulation Delaunay");
		simvo = new Button("Simulation Voronoi");
		hull = new Checkbox("Show Convex Hull");
		deltri = new Checkbox("Show Delaunay");
		voronoi = new Checkbox("Show Voronoi");

		subp1 = new Panel();
		subp1.setLayout(new BorderLayout());
		subp1.add("Center",clear);
		subp1.add("South",close);

		subp022 = new Panel();
		subp022.setLayout(new BorderLayout());
		subp022.add("Center",simde);
		subp022.add("South",simvo);

		subp3 = new Panel();
		subp3.setLayout(new BorderLayout());
		subp3.add("North",hull);
		subp3.add("Center",deltri);
		subp3.add("South",voronoi);

		subp2 = new Panel();
		subp2.setLayout(new BorderLayout());
		subp2.add("North", subp1);
		subp2.add("Center", subp022);
		subp2.add("South", subp3);

		p = new Panel();
		p.setBackground(Color.lightGray);
		p.setLayout(new BorderLayout());
		p.add("North", subp2);

		c = new GeomCanvas(cw, ch, this);
		c.SetRegime("point");

		canvasp = new Panel();
		canvasp.setLayout(new BorderLayout());
		canvasp.add("Center", c);

		setLayout(new BorderLayout());
		add("Center", canvasp);
		add("East", p);

	}

	public boolean action(Event e, Object o) {
		if (e.target instanceof Checkbox) {
			Checkbox checkbox = (Checkbox) e.target;
			if (e.target == hull)
				c.ToCH(checkbox.getState());

			if (e.target == deltri) {
				c.ToDelTri(checkbox.getState());
			}
			if (e.target == voronoi){
				c.ToVoronoi(checkbox.getState());
			}
		} // end of instanceof Checkbox

		if (e.target instanceof Button) {
			if (e.target == clear) {
				c.ToBeCleared();// boolean variable
				c.CoorClear();
				c.SetPaint();
			}
			if (e.target == close) {
				setVisible(false);
				c.CoorClear();
    			c.animator=null;
			}
			if (e.target == simde) {
				c.SimDe();// boolean variabble
			}

			if (e.target == simvo) {
				c.SimVo();
			}
		}
		return true;
	}

	public void processevent(AWTEvent e) {
		if (e.getID() == Event.WINDOW_DESTROY) {
			setVisible(false);
			dispose();
			return;
		}
		super.processEvent(e);
	}

	public void resetBLabel(Button bprev) {
		bprev.setFont(f);
	}

}