Skip to content

Commit

Permalink
Timer picker!
Browse files Browse the repository at this point in the history
  • Loading branch information
octo-kumo committed Aug 10, 2020
1 parent 6adde25 commit c3b1910
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;

Expand All @@ -24,17 +25,17 @@ public class AddExamController {
/**
* The constant dateFormatter used for date picker (user friendly, shows jan feb etc)
*/
public static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy MMM dd");
public static final DateTimeFormatter dateFormatter = new DateTimeFormatterBuilder().parseCaseInsensitive().appendPattern("yyyy MMM dd").toFormatter();
/**
* The time formatters that will be supported by start and end fields
*/
public static final DateTimeFormatter[] timeFormatters = {
DateTimeFormatter.ofPattern("hh:mma"),
DateTimeFormatter.ofPattern("HH:mm"),
DateTimeFormatter.ofPattern("h:mma"),
DateTimeFormatter.ofPattern("H:mm"),
DateTimeFormatter.ofPattern("hha"),
DateTimeFormatter.ofPattern("ha")
new DateTimeFormatterBuilder().parseCaseInsensitive().appendPattern("hh:mma").toFormatter(),
new DateTimeFormatterBuilder().parseCaseInsensitive().appendPattern("HH:mm").toFormatter(),
new DateTimeFormatterBuilder().parseCaseInsensitive().appendPattern("h:mma").toFormatter(),
new DateTimeFormatterBuilder().parseCaseInsensitive().appendPattern("H:mm").toFormatter(),
new DateTimeFormatterBuilder().parseCaseInsensitive().appendPattern("hha").toFormatter(),
new DateTimeFormatterBuilder().parseCaseInsensitive().appendPattern("ha").toFormatter()
};

public Form form;
Expand Down Expand Up @@ -96,7 +97,7 @@ public LocalDate fromString(String dateString) {
@FXML
public void addExam(ActionEvent event) {
try {
Exam exam = new Exam(name_input.getText(), date_input.getValue(), parseTime(start_time_input.getText().toLowerCase(), 0), parseTime(end_time_input.getText().toLowerCase(), 0));
Exam exam = new Exam(name_input.getText(), date_input.getValue(), parseTime(start_time_input.getText(), 0), parseTime(end_time_input.getText(), 0));
mainController.addExam(exam);
} catch (Exception e) {
Alert alert = new Alert(Alert.AlertType.ERROR, e.getMessage());
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/app/nush/examclock/display/TimePicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;

import static app.nush.examclock.controllers.AddExamController.parseTime;

public class TimePicker extends TextField {
public static final DateTimeFormatter defaultFormatter = DateTimeFormatter.ofPattern("hh:mm a");
public static final DateTimeFormatter defaultFormatter = new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.appendPattern("hh:mm a")
.toFormatter();

private final TimePopup popup;
public SimpleObjectProperty<LocalTime> timeProperty;
public SimpleIntegerProperty hour;
Expand Down
16 changes: 11 additions & 5 deletions src/main/resources/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@
}

.list-item {
-fx-fill: white;
-fx-text-fill: -fx-fill;
-fx-background-color: -fx-control-inner-background;
}

.list-item * {
-fx-fill: -fx-foreground;
}

.list-item:hover {
-fx-background: -fx-background;
}

.list-item .text {
-fx-fill: white;
-fx-text-fill: -fx-fill;
.list-item:active {
-fx-background: -fx-accent;
}


Expand Down

0 comments on commit c3b1910

Please sign in to comment.