From 6db71717049ac2680e0181b6471288f50095d572 Mon Sep 17 00:00:00 2001 From: gered Date: Thu, 3 Dec 2015 20:06:49 -0500 Subject: [PATCH] add attempt counter display and a setting to turn it on/off --- .../java/org/fenix/llanfair/Language.java | 1 + src/main/java/org/fenix/llanfair/Run.java | 6 +++ .../org/fenix/llanfair/config/Settings.java | 2 + .../fenix/llanfair/dialog/TabComponents.java | 2 + .../java/org/fenix/llanfair/gui/RunPane.java | 52 +++++++++++++++---- src/main/resources/language.properties | 1 + 6 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/fenix/llanfair/Language.java b/src/main/java/org/fenix/llanfair/Language.java index 062d38c..e7e5134 100644 --- a/src/main/java/org/fenix/llanfair/Language.java +++ b/src/main/java/org/fenix/llanfair/Language.java @@ -57,6 +57,7 @@ public enum Language { // Settings > Header setting_header_goal, setting_header_title, + setting_header_showAttempts, // Settings > History setting_history_rowCount, diff --git a/src/main/java/org/fenix/llanfair/Run.java b/src/main/java/org/fenix/llanfair/Run.java index 7c494ec..292c6dc 100644 --- a/src/main/java/org/fenix/llanfair/Run.java +++ b/src/main/java/org/fenix/llanfair/Run.java @@ -99,6 +99,10 @@ public class Run implements TableModel, Serializable { public static final String COUNTER_EDIT_PROPERTY = "run.counters.edit"; + public static final String ATTEMPT_COUNTER_PROPERTY = "run.attemptCounter"; + + public static final String COMPLETED_ATTEMPT_COUNTER_PROPERTY = "run.completedAttemptCounter"; + // ------------------------------------------------------------- ATTRIBUTES /** @@ -700,6 +704,7 @@ public class Run implements TableModel, Serializable { numberOfAttempts += 1; + pcSupport.firePropertyChange(ATTEMPT_COUNTER_PROPERTY, numberOfAttempts - 1, numberOfAttempts); pcSupport.firePropertyChange(STATE_PROPERTY, State.READY, state); pcSupport.firePropertyChange(CURRENT_SEGMENT_PROPERTY, -1, 0); } @@ -725,6 +730,7 @@ public class Run implements TableModel, Serializable { if (current == getRowCount()) { // run is finished numberOfCompletedAttempts += 1; + pcSupport.firePropertyChange(COMPLETED_ATTEMPT_COUNTER_PROPERTY, numberOfCompletedAttempts - 1, numberOfCompletedAttempts); stop(); } else { segments.get(current).setStartTime(stopTime); diff --git a/src/main/java/org/fenix/llanfair/config/Settings.java b/src/main/java/org/fenix/llanfair/config/Settings.java index d683867..925b11b 100644 --- a/src/main/java/org/fenix/llanfair/config/Settings.java +++ b/src/main/java/org/fenix/llanfair/config/Settings.java @@ -66,6 +66,7 @@ public class Settings { public static final Property headerShowGoal = new Property<>( "header.goal" ); public static final Property headerShowTitle = new Property<>( "header.title" ); + public static final Property headerShowAttempts = new Property<>( "header.showAttempts" ); /* HISTORY properties */ @@ -225,6 +226,7 @@ public class Settings { global.put( headerShowGoal.key, true ); global.put( headerShowTitle.key, true ); + global.put( headerShowAttempts.key, true ); global.put( historyRowCount.key, 8 ); global.put( historyTabular.key, true ); diff --git a/src/main/java/org/fenix/llanfair/dialog/TabComponents.java b/src/main/java/org/fenix/llanfair/dialog/TabComponents.java index f02733c..53a1fec 100644 --- a/src/main/java/org/fenix/llanfair/dialog/TabComponents.java +++ b/src/main/java/org/fenix/llanfair/dialog/TabComponents.java @@ -39,6 +39,7 @@ public class TabComponents extends SettingsTab SCB_SETTINGS.add(Settings.coreShowSegmentTimer); SCB_SETTINGS.add(Settings.coreShowIcons); SCB_SETTINGS.add(Settings.headerShowGoal); + SCB_SETTINGS.add(Settings.headerShowAttempts); } private JComboBox iconSizes; @@ -219,6 +220,7 @@ public class TabComponents extends SettingsTab miscPanel.add(checkBoxes.get(Settings.headerShowGoal.getKey()), GBC.grid(0, 0).anchor(GBC.LS)); miscPanel.add(checkBoxes.get(Settings.headerShowTitle.getKey()), GBC.grid(0, 1).anchor(GBC.LS)); miscPanel.add(checkBoxes.get(Settings.graphDisplay.getKey()), GBC.grid(0, 2).anchor(GBC.LS)); + miscPanel.add(checkBoxes.get(Settings.headerShowAttempts.getKey()), GBC.grid(0, 3).anchor(GBC.LS)); miscPanel.setBorder( BorderFactory.createTitledBorder("" + Language.MISC) ); diff --git a/src/main/java/org/fenix/llanfair/gui/RunPane.java b/src/main/java/org/fenix/llanfair/gui/RunPane.java index 06e6f6d..15857b9 100644 --- a/src/main/java/org/fenix/llanfair/gui/RunPane.java +++ b/src/main/java/org/fenix/llanfair/gui/RunPane.java @@ -77,6 +77,11 @@ public class RunPane extends JPanel { */ private static final int FOOTER = 0x40; + /** + * Update identifier for the attempt counter component. + */ + private static final int ATTEMPTS = 0x80; + // ------------------------------------------------------------- ATTRIBUTES @@ -106,6 +111,11 @@ public class RunPane extends JPanel { */ private JPanel goalPane; + /** + * Label displaying the number of attempts the user has made of this run. + */ + private JLabel attemptCounter; + /** * A list containing empty labels serving as separators. */ @@ -149,6 +159,7 @@ public class RunPane extends JPanel { title = new JLabel(); goal = new JLabel(); goalText = new JLabel(); + attemptCounter = new JLabel(); core = new Core(run); graph = new Graph(run); history = new History(run); @@ -245,9 +256,15 @@ public class RunPane extends JPanel { } else if (Settings.headerShowGoal.equals(property)) { updateVisibility(TITLE | GOAL); updateValues(SEPARATOR); + } else if (Settings.headerShowAttempts.equals(property)) { + updateVisibility(ATTEMPTS); + updateValues(SEPARATOR); } else if (Settings.accuracy.equals(property) || Run.GOAL_PROPERTY.equals(property)) { updateValues(GOAL); + } else if (Run.ATTEMPT_COUNTER_PROPERTY.equals(property) || + Run.COMPLETED_ATTEMPT_COUNTER_PROPERTY.equals(property)) { + updateValues(ATTEMPTS); } } @@ -292,10 +309,11 @@ public class RunPane extends JPanel { goalPane.add(goal, GBC.grid(1, 1).insets(0, 3, 0, 0)); goalPane.setOpaque(false); } - add(createSeparator(), GBC.grid(0, 2).insets(3, 0).fill(GBC.H)); - add(history, GBC.grid(0, 3).fill(GBC.H).insets(0, 5)); - add(createSeparator(), GBC.grid(0, 4).insets(3, 0).fill(GBC.H)); - add(createSeparator(), GBC.grid(0, 6).insets(3, 0, 0, 0).fill(GBC.H)); + add(attemptCounter, GBC.grid(0, 2).insets(1, 0, 1, 3).anchor(GBC.LE)); + add(createSeparator(), GBC.grid(0, 3).insets(3, 0).fill(GBC.H)); + add(history, GBC.grid(0, 4).fill(GBC.H).insets(0, 5)); + add(createSeparator(), GBC.grid(0, 5).insets(3, 0).fill(GBC.H)); + add(createSeparator(), GBC.grid(0, 7).insets(3, 0, 0, 0).fill(GBC.H)); updateVisibility(ALL); } @@ -321,12 +339,23 @@ public class RunPane extends JPanel { if ((identifier & TITLE) == TITLE) { title.setText("" + run.getName()); } + if ((identifier & ATTEMPTS) == ATTEMPTS) { + int attempts = run.getNumberOfAttempts(); + int completedAttempts = run.getNumberOfCompletedAttempts(); + if (attempts == 0) + attemptCounter.setText("0"); + else if (completedAttempts == 0) + attemptCounter.setText(String.format("%d", attempts)); + else + attemptCounter.setText(String.format("%d / %d", completedAttempts, attempts)); + } if ((identifier & SEPARATOR) == SEPARATOR) { boolean hdTitle = Settings.headerShowGoal.get(); boolean hdGoal = Settings.headerShowTitle.get(); + boolean hdAttempts = Settings.headerShowAttempts.get(); boolean hsRows = history.getRowCount() > 0; - separators.get(0).setVisible(hdTitle || hdGoal); + separators.get(0).setVisible(hdTitle || hdGoal || hdAttempts); separators.get(1).setVisible(hsRows); } } @@ -357,6 +386,8 @@ public class RunPane extends JPanel { BorderFactory.createMatteBorder(1, 0, 0, 0, color)); } } + + attemptCounter.setForeground(Color.WHITE); } /** @@ -369,19 +400,19 @@ public class RunPane extends JPanel { if ((identifier & GRAPH) == GRAPH) { if (Settings.graphDisplay.get()) { remove(core); - add(core, GBC.grid(0, 5).insets(0, 5).fill(GBC.H)); - add(graph, GBC.grid(0, 7).fill(GBC.B).insets(0, 0, 3, 0) + add(core, GBC.grid(0, 6).insets(0, 5).fill(GBC.H)); + add(graph, GBC.grid(0, 8).fill(GBC.B).insets(0, 0, 3, 0) .weight(1.0, 1.0)); } else { remove(graph); remove(core); - add(core, GBC.grid(0, 5).insets(0, 5).fill(GBC.H) + add(core, GBC.grid(0, 6).insets(0, 5).fill(GBC.H) .weight(1.0, 1.0)); } } if ((identifier & FOOTER) == FOOTER) { if (Settings.footerDisplay.get()) { - add(footer, GBC.grid(0, 8).insets(0, 3).fill(GBC.H)); + add(footer, GBC.grid(0, 9).insets(0, 3).fill(GBC.H)); } else { remove(footer); } @@ -400,6 +431,9 @@ public class RunPane extends JPanel { if ((identifier & TITLE) == TITLE) { title.setVisible(Settings.headerShowTitle.get()); } + if ((identifier & ATTEMPTS) == ATTEMPTS) { + attemptCounter.setVisible(Settings.headerShowAttempts.get()); + } revalidate(); repaint(); } diff --git a/src/main/resources/language.properties b/src/main/resources/language.properties index d19a296..b72ce5a 100644 --- a/src/main/resources/language.properties +++ b/src/main/resources/language.properties @@ -38,6 +38,7 @@ GLOBAL_HOTKEYS_HOOK_ERROR = Key event hook registration failed. You will need to # Settings > Header setting_header_goal = Display Goal setting_header_title = Display Run Title +setting_header_showAttempts = Display Attempt Counter # Settings > History setting_history_rowCount = Number of Rows