This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskList.java
157 lines (127 loc) · 2.85 KB
/
TaskList.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
/**
* A list of tasks for the user for both levels
*
* Last edit: 6/4/2020
* @author Celeste
* @version 1.0
* @since 1.1
*/
import java.awt.*;
import javax.swing.*;
import java.util.*;
public abstract class TaskList extends GraphicComponent {
/**
* Whether the list is opened or not
*/
protected boolean isOpened;
/**
* The list icon
*/
protected ImageButton icon;
/**
* The back button
*/
protected Button back;
/**
* The list background
*/
protected Image bkgd;
/**
* Whether the list has been added to at some point
*/
protected boolean notInitialEmpty;
public TaskList() {
this(true);
bkgd = Utility.loadImage("Checklist.png",300,400);
icon = new ImageButton(Utility.FRAME_WIDTH - 100, Utility.FRAME_HEIGHT - 100, Utility.loadImage("Scroll_Icon.png",80,80));
back = new ImageButton(Utility.FRAME_WIDTH - 100, Utility.FRAME_HEIGHT - 75, Utility.loadImage("ReturnArrow.png",45,45));
notInitialEmpty = false;
isClicked = false;
isHovered = false;
}
/**
* @param doNotLoad the addition of this parameters prevents image loading
*/
public TaskList(boolean doNotLoad) {
width = 300;
height = 400;
x_coord = (Utility.FRAME_WIDTH-width)/2;
y_coord = (Utility.FRAME_HEIGHT-height)/2;
}
@Override
public void draw(Graphics g) {
if (isOpened) {
g.setColor(new Color(0,0,0,0.4f));
g.fillRect(0,0,Utility.FRAME_WIDTH, Utility.FRAME_HEIGHT);
g.drawImage(bkgd,x_coord,y_coord,null);
drawOpen(g);
back.draw(g);
if (back.isClicked()) {
isOpened = false;
closeDeactivate();
back.deactivate();
icon.activate();
CovidCashier.frame.repaint();
}
} else {
icon.draw(g);
if (icon.isClicked()) {
isOpened = true;
openActivate();
icon.deactivate();
back.activate();
CovidCashier.frame.repaint();
}
}
}
/**
* Draws an opened task list (i.e. displays the tasks on screen)
* @param g the Graphics object to draw on
*/
protected abstract void drawOpen(Graphics g);
/**
* @return whether the entire TaskList has been completed
*/
public abstract boolean isFinished();
/**
* Activate list opening listeners
*/
protected void openActivate() {}
/**
* Deactivate list opening listeners
*/
protected void closeDeactivate() {}
/**
* @return whether the list display is opened
*/
public boolean isOpened() {
return isOpened;
}
/**
* Closes the list display
*/
public void close() {
isOpened = false;
}
/**
* Opens the list display
*/
public void open() {
isOpened = true;
}
/**
* Activates click and hover listeners.
*/
public void activate() {
icon.activate();
}
/**
* Deativates click and hover listeners.
*/
public void deactivate() {
icon.deactivate();
back.deactivate();
}
@Override
protected boolean withinCoordinates() {return false;}
}