Skip to content

Commit 7b7b5f0

Browse files
author
extremq
committed
Can now reset timer.
1 parent 5737de7 commit 7b7b5f0

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

src/com/codebind/App.java

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ private void startTimerTask() {
149149
// Pick whether we choose to subtract from session or break time.
150150
long sessionMinutes = 0;
151151
if (getState() == State.BOOTED || getState() == State.FOCUS) {
152+
setState(State.FOCUS);
152153
sessionMinutes = getFocusMinutes();
153154
}
154155
else if (getState() == State.BREAK) {
@@ -164,7 +165,10 @@ public void run() {
164165
// If the timer is below zero, or it has been stopped, cancel the updates.
165166
if (systemTime - startTime > finalSessionMinutes * 60 * 1000 || isTimerStopped()) {
166167
this.cancel();
167-
if (getState() == State.BOOTED || getState() == State.FOCUS) {
168+
if (getState() == State.BOOTED) {
169+
resetTimerAndMessage(Locale.GREET_MESSAGE);
170+
}
171+
else if (getState() == State.FOCUS) {
168172
endFocusPeriod();
169173
}
170174
else if (getState() == State.BREAK) {
@@ -173,7 +177,7 @@ else if (getState() == State.BREAK) {
173177
}
174178
// Update the timer with the new remaining time.
175179
else {
176-
setLabelTimer(Utils.convertRemainingMillisToMinutes(systemTime - startTime, getFocusMinutes()));
180+
setLabelTimer(Utils.convertRemainingMillisToMinutes(systemTime - startTime, finalSessionMinutes));
177181
}
178182
}
179183
}, 0, 100);
@@ -212,18 +216,28 @@ public void actionPerformed(ActionEvent e) {
212216

213217
helpMenu.add(aboutItem);
214218
helpMenu.add(usageItem);
219+
220+
JMenuItem resetItem = new JMenuItem("Reset");
221+
JMenu settingsMenu = new JMenu("Settings");
222+
223+
resetItem.addActionListener(new ActionListener() {
224+
@Override
225+
public void actionPerformed(ActionEvent e) {
226+
setState(State.BOOTED);
227+
setTimerStopped(true);
228+
229+
JOptionPane.showMessageDialog(null, Locale.RESET_MESSAGE);
230+
}
231+
});
232+
233+
settingsMenu.add(resetItem);
234+
235+
menubar.add(settingsMenu);
215236
menubar.add(helpMenu);
216237
frame.setJMenuBar(menubar);
217238
}
218239

219-
public App() {
220-
this.frame = new JFrame();
221-
initFrame(this.frame);
222-
223-
this.menubar = new JMenuBar();
224-
initMenuBar(this.menubar, this.frame);
225-
226-
// Start button logic
240+
private void initButtons(JButton buttonStart, JButton buttonStop) {
227241
buttonStart.addActionListener(new ActionListener() {
228242
@Override
229243
public void actionPerformed(ActionEvent e) {
@@ -254,6 +268,17 @@ public void actionPerformed(ActionEvent e) {
254268
});
255269
}
256270

271+
public App() {
272+
this.frame = new JFrame();
273+
initFrame(this.frame);
274+
275+
this.menubar = new JMenuBar();
276+
initMenuBar(this.menubar, this.frame);
277+
278+
// Start button logic
279+
initButtons(this.buttonStart, this.buttonStop);
280+
}
281+
257282
public static void main(String[] args) {
258283
new App();
259284
}

src/com/codebind/Locale.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class Locale {
1010
public static final String FOCUS_DONE_MESSAGE = "Let's take a break.";
1111
public static final String BREAK_DONE_MESSAGE = "Let's focus.";
1212
public static final String GREET_MESSAGE = "Nice to see you!";
13+
public static final String RESET_MESSAGE = "The app has been reset!";
1314
public static final String ABOUT_MESSAGE = "This application was made by Extremq as an exercise and as a necessity." +
1415
"\n\n" + "The source code is available at https://github.com/extremq/pomodoro" +
1516
"\n" + "and is available freely to anyone." +

0 commit comments

Comments
 (0)