Add up/down control to time field
This commit is contained in:
parent
9cb0eae10f
commit
807e13d239
@ -140,15 +140,49 @@ public class MainSettingsController {
|
|||||||
// Consume the event to block the default behavior
|
// Consume the event to block the default behavior
|
||||||
if (!(code == KeyCode.LEFT ||
|
if (!(code == KeyCode.LEFT ||
|
||||||
code == KeyCode.RIGHT ||
|
code == KeyCode.RIGHT ||
|
||||||
code == KeyCode.UP ||
|
|
||||||
code == KeyCode.DOWN ||
|
|
||||||
code == KeyCode.HOME ||
|
code == KeyCode.HOME ||
|
||||||
code == KeyCode.END ||
|
code == KeyCode.END)) {
|
||||||
code == KeyCode.PAGE_UP ||
|
|
||||||
code == KeyCode.PAGE_DOWN)) {
|
|
||||||
event.consume();
|
event.consume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.getEventType() == KeyEvent.KEY_PRESSED &&
|
||||||
|
(code == KeyCode.UP || code == KeyCode.DOWN)) {
|
||||||
|
boolean up = false;
|
||||||
|
if (code == KeyCode.UP) {
|
||||||
|
up = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] timeParts = scheduleStartTimeField.getText().split(":");
|
||||||
|
if (timeParts.length == 3) {
|
||||||
|
int hours = Integer.parseInt(timeParts[0]);
|
||||||
|
int minutes = Integer.parseInt(timeParts[1]);
|
||||||
|
int seconds = Integer.parseInt(timeParts[2]);
|
||||||
|
|
||||||
|
if (cursorPosition < 3) {
|
||||||
|
if (up && hours < 23) {
|
||||||
|
hours++;
|
||||||
|
} else if (!up && hours > 0) {
|
||||||
|
hours--;
|
||||||
|
}
|
||||||
|
} else if (cursorPosition < 6) {
|
||||||
|
if (up && minutes < 59) {
|
||||||
|
minutes++;
|
||||||
|
} else if (!up && minutes > 0) {
|
||||||
|
minutes--;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (up && seconds < 59) {
|
||||||
|
seconds++;
|
||||||
|
} else if (!up && seconds > 0) {
|
||||||
|
seconds--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scheduleStartTimeField.setText(String.format("%02d:%02d:%02d", hours, minutes, seconds));
|
||||||
|
scheduleStartTimeField.positionCaret(cursorPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (event.getEventType() == KeyEvent.KEY_PRESSED &&
|
if (event.getEventType() == KeyEvent.KEY_PRESSED &&
|
||||||
(code == KeyCode.DIGIT0 ||
|
(code == KeyCode.DIGIT0 ||
|
||||||
code == KeyCode.DIGIT1 ||
|
code == KeyCode.DIGIT1 ||
|
||||||
@ -178,10 +212,17 @@ public class MainSettingsController {
|
|||||||
int minutes = Integer.parseInt(timeParts[1]);
|
int minutes = Integer.parseInt(timeParts[1]);
|
||||||
int seconds = Integer.parseInt(timeParts[2]);
|
int seconds = Integer.parseInt(timeParts[2]);
|
||||||
|
|
||||||
|
if (hours > 23) {
|
||||||
|
hours = 23;
|
||||||
|
editedTime = "23" + editedTime.substring(2);
|
||||||
|
}
|
||||||
|
|
||||||
if (!(hours < 0 || hours > 23 || minutes < 0 || minutes > 59 || seconds < 0 || seconds > 59)) {
|
if (!(hours < 0 || hours > 23 || minutes < 0 || minutes > 59 || seconds < 0 || seconds > 59)) {
|
||||||
scheduleStartTimeField.setText(editedTime);
|
scheduleStartTimeField.setText(editedTime);
|
||||||
scheduleStartTimeField.positionCaret(cursorPosition + 1);
|
scheduleStartTimeField.positionCaret(cursorPosition + 1);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
scheduleStartTimeField.setText("00:00:00");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user