-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTable.java~
207 lines (185 loc) · 4.9 KB
/
Table.java~
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/** Table class
* Sherwin Chiu and Kyro Nassif
* Tables used for Prom Display
* 2/13/2020
*/
// Imports
import java.awt.*;
import java.util.ArrayList;
class Table{
private int size;
private ArrayList<Student> students = new ArrayList<>(0);
private ArrayList<Rectangle> nameRect = new ArrayList<>(0);
private int x;
private int y;
private int chairX;
private int chairY;
private double angleIncr = (2.0*Math.PI/(double)this.students.size());
private boolean dragged = false;
private int diameter = 150;
private Rectangle tableRect = new Rectangle(this.x, this.y, this.diameter, this.diameter);
public Table(int size){
this.size = size;
}
public Table(int x, int y, int size){
this.x = x;
this.y = y;
this.size = size;
}
/**
* @return int
*/
public int getSize(){
return this.size;
}
public void clearTable(){
students = new ArrayList<>();
}
/**
* @param b
*/
public void setDragged(boolean b){
this.dragged = b;
}
/**
* @param r
*/
public void setDiameter(int r){
this.diameter = r;
this.tableRect.width = r;
this.tableRect.height = r;
}
/**
* @return boolean
*/
public boolean getDragged(){
return this.dragged;
}
/**
* @param s
*/
public void addStudent(Student s){
this.students.add(s);
}
/**
* @param s
*/
public void removeStudent(Student s){
for(int i = 0; i < this.size; i++){
if (s.getId() == this.students.get(i).getId())
this.students.set(i, null);
}
}
/**
* @return ArrayList<Student>
*/
public ArrayList<Student> getStudents(){
return this.students;
}
/**
* @param s
*/
public void setStudents(ArrayList<Student> s){
for(int i = 0; i < s.size(); i++){
this.nameRect.add(new Rectangle());
}
this.students = s;
}
/**
* @return int
*/
public int getX(){
return this.x;
}
/**
* @param x
*/
public void setX(int x){
this.x = x;
tableRect.x = x;
}
/**
* @return int
*/
public int getDiameter() {
return this.diameter;
}
/**
* @return int
*/
public int getY(){
return this.y;
}
/**
* @param y
*/
public void setY(int y){
this.y = y;
tableRect.y = y;
}
/**
* @return boolean
*/
public boolean isFull(){
if(this.students.size() >= this.size)
return true;
else
return false;
}
/**
* @return Rectangle
*/
public Rectangle getTableRect(){
return this.tableRect;
}
/**
* @param index
* @return Rectangle
*/
public Rectangle getNameRect(int index){
return this.nameRect.get(index);
}
/**
* @param g
*/
public void drawTable(Graphics g){
g.drawOval(this.x, this.y, this.diameter, this.diameter);
}
public void refreshChairs(){
int nameRectSize = nameRect.size();
for (int i = students.size(); i > nameRectSize; i--){
this.nameRect.add(new Rectangle());
}
for (int i = 0; i < this.students.size(); i++){
this.chairX = (int)(Math.cos((double)i*angleIncr)*(this.diameter/2+this.diameter/10));
this.chairY = (int)(Math.sin((double)i*angleIncr)*(this.diameter/2+this.diameter/10));
if (this.chairY>= 0){
this.nameRect.get(i).setRect(this.x+this.diameter/2+this.chairX-this.students.get(i).getName().length(),
this.y+this.diameter/2+this.chairY+15, this.students.get(i).getName().length()*5, 14);
}else{
this.nameRect.get(i).setRect(this.x+this.diameter/2+this.chairX-this.students.get(i).getName().length(),
this.y+this.diameter/2+this.chairY-25, this.students.get(i).getName().length()*5, 14);
}
}
}
/**
* @param g
*/
public void drawChair(Graphics g){
this.angleIncr = (2.0*Math.PI/(double)this.students.size());
if (this.students.size() > 0){
for(int i = 0; i < this.students.size(); i++){
this.chairX = (int)(Math.cos((double)i*angleIncr)*(this.diameter/2+this.diameter/10));
this.chairY = (int)(Math.sin((double)i*angleIncr)*(this.diameter/2+this.diameter/10));
if(this.chairY >= 0){
g.drawString(this.students.get(i).getName(), this.x+this.diameter/2+this.chairX-this.students.get(i).getName().length()*2
, this.y+this.diameter/2+this.chairY+25);
} else{
g.drawString(this.students.get(i).getName(), this.x+this.diameter/2+this.chairX-this.students.get(i).getName().length()*2
, this.y+this.diameter/2+this.chairY-15);
}
g.drawOval(this.x+this.diameter/2+this.chairX-12, this.y+this.diameter/2+this.chairY-10, 20, 20);
}
}
}
}