-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientFrame.java
More file actions
172 lines (142 loc) · 3.86 KB
/
ClientFrame.java
File metadata and controls
172 lines (142 loc) · 3.86 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*----------------------------------------------------------------------+
| Title: ClientFrame.java |
| Java class ClientFrame extends Frame |
| |
| Author: David E. Joyce |
| Department of Mathematics and Computer Science |
| Clark University |
| Worcester, MA 01610-1477 |
| U.S.A. |
| |
| http://aleph0.clarku.edu/~djoyce/home.html |
| djoyce@clarku.edu |
| |
| Date: May, 1996. |
+----------------------------------------------------------------------*/
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.lang.Integer;
import java.lang.StringBuffer;
import java.util.Vector;
import javax.swing.JOptionPane;
public class ClientFrame extends Frame implements ActionListener, MouseListener, MouseMotionListener {
enum EntryMode
{ SELECT, POINT, LINE, CIRCLE, SQUARE }
/**
*
*/
private static final long serialVersionUID = 3294763193966833804L;
Geometry app;
Slate slate;
Button closeButton, resetButton;
Button selectButton, pointButton;
EntryMode currentMode;
public ClientFrame (String s) {
super(s);
}
public ClientFrame (String s, Geometry app)
{
super(s);
this.app = app;
this.slate = app.slate;
InitializeGUI();
}
private void InitializeGUI()
{
this.currentMode = EntryMode.SELECT;
closeButton = new Button("Close");
resetButton = new Button("Reset");
selectButton = new Button("Select");
pointButton = new Button("Add Point");
Panel south = new Panel();
Panel west = new Panel(new GridLayout(8,1));
closeButton.addActionListener(this);
resetButton.addActionListener(this);
south.add(resetButton);
south.add(closeButton);
selectButton.addActionListener(this);
pointButton.addActionListener(this);
west.add(selectButton);
west.add(pointButton);
add("South",south);
add("Center",slate);
add("West",west);
slate.addMouseMotionListener(this);
slate.addMouseListener(this);
setSize(app.baseSize.width,app.baseSize.height+50);
}
public void actionPerformed(ActionEvent e)
{
Object target = e.getSource();
if (target==closeButton) {
remove(slate);
currentMode = EntryMode.SELECT;
app.unFloatWindow();
}
else if (target == resetButton)
{
slate.reset();
slate.repaint();
}
else if (target == selectButton)
{
currentMode = EntryMode.SELECT;
}
else if (target == pointButton)
{
currentMode = EntryMode.POINT;
}
}
@Override
public void mouseClicked(MouseEvent e)
{
switch(currentMode)
{
case SELECT:
break;
case POINT:
String newPointName = JOptionPane.showInputDialog("Enter a name for the point.");
newPointName = newPointName.replace(";", "");
StringBuffer error = new StringBuffer();
Element N = app.parseElement(newPointName + ";point;free;"+ Integer.toString(e.getX()) + "," + Integer.toString(e.getY()), error);
slate.repaint();
if(N==null) JOptionPane.showMessageDialog(this, error);
break;
}
}
@Override
public void mouseEntered(MouseEvent e)
{}
@Override
public void mouseExited(MouseEvent e)
{}
@Override
public void mousePressed(MouseEvent e)
{}
@Override
public void mouseReleased(MouseEvent e)
{}
@Override
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseMoved(MouseEvent e) {
Element elements[] = slate.element;
if(currentMode == EntryMode.SELECT)
{
for(int i = 0; i < slate.eCount; i++)
{
if(elements[i].hitTest(e.getX(), e.getY()))
elements[i].setHighlight(true);
else
elements[i].setHighlight(false);
}
slate.repaint();
}
}
}