Skip to content

Commit

Permalink
customizable time period
Browse files Browse the repository at this point in the history
  • Loading branch information
cylorun committed Jun 11, 2024
1 parent 84c2b6c commit cb483bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/main/java/me/cylorun/pace/PaceStatusOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class PaceStatusOptions {
public boolean enabled = true;
public boolean show_enter_count = true;
public boolean show_enter_avg = true;
public boolean show_nph = false;
public int time_period = 24;
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
private static final Path SAVE_PATH = Paths.get(System.getProperty("user.home")).resolve(".Julti").resolve("pacestatus_options.json").toAbsolutePath();
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/me/cylorun/pace/ui/PaceStatusGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class PaceStatusGUI extends JFrame {
private JCheckBox showEnterCount;
private JCheckBox showEnterAvg;
private JTextField usernameField;
private JSpinner timePeriodSpinner;
private JPanel mainPanel;
private JButton saveButton;
private boolean closed = false;
Expand All @@ -40,6 +41,7 @@ public void windowClosing(WindowEvent e) {
this.usernameField.setEnabled(this.checkBoxEnabled());
this.showEnterCount.setEnabled(this.checkBoxEnabled());
this.showEnterAvg.setEnabled(this.checkBoxEnabled());
this.timePeriodSpinner.setEnabled(this.checkBoxEnabled());
});

this.usernameField.setText(options.username);
Expand All @@ -57,11 +59,13 @@ public void keyReleased(KeyEvent e) {

this.usernameField.setEnabled(options.enabled);
this.showEnterCount.setEnabled(options.enabled);
this.showEnterAvg.setEnabled(options.enabled);
this.timePeriodSpinner.setEnabled(options.enabled);

this.showEnterAvg.addActionListener(e -> this.saveButton.setEnabled(PaceStatusGUI.this.hasChanges()));
this.showEnterCount.addActionListener(e -> this.saveButton.setEnabled(PaceStatusGUI.this.hasChanges()));
this.timePeriodSpinner.addChangeListener(e -> this.saveButton.setEnabled(PaceStatusGUI.this.hasChanges()));

this.showEnterAvg.setEnabled(options.enabled);
this.saveButton.addActionListener(e -> this.save());
this.saveButton.setEnabled(this.hasChanges());
this.revalidate();
Expand All @@ -88,7 +92,8 @@ private boolean hasChanges() {
return (this.checkBoxEnabled() != options.enabled) ||
(!Objects.equals(this.getKeyBoxText(), options.username)) ||
(this.showEnterCount.isSelected() != options.show_enter_count) ||
(this.showEnterAvg.isSelected() != options.show_enter_avg);
(this.showEnterAvg.isSelected() != options.show_enter_avg) ||
((int) this.timePeriodSpinner.getValue() != options.time_period);
}

private void save() {
Expand All @@ -97,6 +102,7 @@ private void save() {
options.username = this.getKeyBoxText();
options.show_enter_count = this.showEnterCount.isSelected();
options.show_enter_avg = this.showEnterAvg.isSelected();
options.time_period = (int) this.timePeriodSpinner.getValue();
try {
PaceStatusOptions.save();
} catch (IOException ex) {
Expand Down Expand Up @@ -128,6 +134,7 @@ private void setUpWindow() {
this.saveButton = new JButton("Save");
this.showEnterCount = new JCheckBox();
this.showEnterAvg = new JCheckBox();
this.timePeriodSpinner = new JSpinner(new SpinnerNumberModel(PaceStatusOptions.getInstance().time_period, 0, Integer.MAX_VALUE, 1));

GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(5, 5, 5, 5);
Expand Down Expand Up @@ -172,11 +179,19 @@ private void setUpWindow() {

gbc.gridx = 0;
gbc.gridy = 5;
gbc.gridwidth = 1;
this.mainPanel.add(new JLabel("Time Period (hours)"), gbc);
gbc.gridx = 1;
gbc.gridwidth = 2;
this.mainPanel.add(this.timePeriodSpinner, gbc);

gbc.gridx = 0;
gbc.gridy = 6;
gbc.gridwidth = 3;
this.mainPanel.add(new JSeparator(), gbc);

gbc.gridx = 0;
gbc.gridy = 6;
gbc.gridy = 7;
gbc.gridwidth = 3;
gbc.anchor = GridBagConstraints.SOUTH;
gbc.fill = GridBagConstraints.NONE;
Expand Down

0 comments on commit cb483bf

Please sign in to comment.