Repository navigation
Expand file tree
/
Copy pathController.java
More file actions
81 lines (67 loc) · 1.92 KB
/
Copy pathController.java
File metadata and controls
81 lines (67 loc) · 1.92 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
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JOptionPane;
public class Controller extends ComponentAdapter implements ActionListener, MouseListener {
// the model that contains the Drawing data
private DrawingModel model;
// used in actionPerformed to carry out commands for add and remove level
private boolean addLevel = false;
public Controller(DrawingModel model) {
this.model = model;
}
/**
* Receives an event
*
* @param e
*/
@Override
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if (command.equals("add level")) {
addLevel = true;
} else if (command.equals("remove level")) {
addLevel = false;
} else {
// reset
model.reset();
}
}
/**
* Used exclusively for radio buttons addLevel and removeLevel
*/
@Override
public void mousePressed(MouseEvent e) {
if (addLevel) {
// if this is false, cannot add another level
if (!model.addLevel(e.getX(), e.getY())) {
JOptionPane.showMessageDialog(null,
"Oh boy. I bet you want to add another level of recursion to the shape you just clicked on.\n"
+ "Well I'm sorry, but you can't! I don't make the rules.\n"
+ "(∩ º ‿‿ º )⊃━☆゚.* You do!",
"Inane warning", JOptionPane.WARNING_MESSAGE);
}
} else {
if (!model.removeLevel(e.getX(), e.getY())) {
JOptionPane.showMessageDialog(null,
"Your level is too low!\n"
+ "Hey! What did you really think was going to happen, huh?! ¯\\_(ツ)_/¯",
"Inane warning", JOptionPane.WARNING_MESSAGE);
}
}
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
}