From 963ae7e3a3ae4e99340554504a2a49bf900c7b74 Mon Sep 17 00:00:00 2001
From: lantzelot-swe <75668734+lantzelot-swe@users.noreply.github.com>
Date: Fri, 5 Apr 2024 14:50:04 +0200
Subject: [PATCH] fix: adds a number to the "saved states" and "extra disks"
tabs when data is available
---
pom.xml | 2 +-
.../lantz/gui/GameDetailsBackgroundPanel.java | 42 ++++++++++++
.../java/se/lantz/gui/SystemTabComponent.java | 67 +++++++++++++++++++
src/main/java/se/lantz/model/InfoModel.java | 26 +++++++
.../java/se/lantz/model/SavedStatesModel.java | 22 ++++++
5 files changed, 158 insertions(+), 1 deletion(-)
create mode 100644 src/main/java/se/lantz/gui/SystemTabComponent.java
diff --git a/pom.xml b/pom.xml
index c4c2216..9efeca6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
4.0.0
se.lantz
PCUAEManager
- 2.16.2
+ 2.16.3
PCUAEManager
Cp1252
diff --git a/src/main/java/se/lantz/gui/GameDetailsBackgroundPanel.java b/src/main/java/se/lantz/gui/GameDetailsBackgroundPanel.java
index 9be1d7a..dbf6007 100644
--- a/src/main/java/se/lantz/gui/GameDetailsBackgroundPanel.java
+++ b/src/main/java/se/lantz/gui/GameDetailsBackgroundPanel.java
@@ -10,6 +10,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
+import java.beans.Beans;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -60,6 +61,8 @@ public class GameDetailsBackgroundPanel extends JPanel
private SystemPanel systemPanel;
private SaveStateBackgroundPanel savesBackgroundPanel;
private ExtraDisksPanel extraDisksPanel;
+ private SystemTabComponent savedStatesTabComponent;
+ private SystemTabComponent extraDisksTabComponent;
private JPanel buttonPanel;
private JButton saveButton;
private ScraperDialog scraperDialog = null;
@@ -105,6 +108,12 @@ public class GameDetailsBackgroundPanel extends JPanel
saveButton.setEnabled(model.isDataChanged());
runButton.setEnabled(!model.getInfoModel().getGamesFile().isEmpty());
});
+
+ if (!Beans.isDesignTime())
+ {
+ model.getSavedStatesModel().addPropertyChangeListener(e -> updateSystemTabs());
+ model.getInfoModel().addPropertyChangeListener(e -> updateSystemTabs());
+ }
cursorTimer = new Timer(500, defaultCursorAction);
}
@@ -192,10 +201,34 @@ public class GameDetailsBackgroundPanel extends JPanel
systemSavesTabbedPane.addTab("System Settings", getSystemPanel());
systemSavesTabbedPane.addTab("Saved states", getSavesBackgroundPanel());
systemSavesTabbedPane.addTab("Extra disks", getExtraDisksPanel());
+
+ systemSavesTabbedPane.setTabComponentAt(1, getSavedStatesTabComponent());
+ systemSavesTabbedPane.setTabComponentAt(2, getExtraDisksTabComponent());
+
updateSavedStatesTabTitle();
}
return systemSavesTabbedPane;
}
+
+ private SystemTabComponent getSavedStatesTabComponent()
+ {
+ if (savedStatesTabComponent == null)
+ {
+ savedStatesTabComponent = new SystemTabComponent("Saved states");
+ savedStatesTabComponent.setNumber("");
+ }
+ return savedStatesTabComponent;
+ }
+
+ private SystemTabComponent getExtraDisksTabComponent()
+ {
+ if (extraDisksTabComponent == null)
+ {
+ extraDisksTabComponent = new SystemTabComponent("Extra disks");
+ extraDisksTabComponent.setNumber("");
+ }
+ return extraDisksTabComponent;
+ }
protected InfoBackgroundPanel getInfoBackgroundPanel()
{
@@ -528,4 +561,13 @@ public class GameDetailsBackgroundPanel extends JPanel
getSystemSavesTabbedPane().setTitleAt(1, title);
getSavesBackgroundPanel().resetCurrentGameReference();
}
+
+ private void updateSystemTabs()
+ {
+ int availableSavedStates = model.getSavedStatesModel().getNumberOfAvailableSavedStates();
+ getSavedStatesTabComponent().setNumber(availableSavedStates > 0 ? Integer.toString(availableSavedStates) : "");
+
+ int availableExtraDisks = model.getInfoModel().getNumberOfExtraDisks();
+ getExtraDisksTabComponent().setNumber(availableExtraDisks > 0 ? Integer.toString(availableExtraDisks) : "");
+ }
}
diff --git a/src/main/java/se/lantz/gui/SystemTabComponent.java b/src/main/java/se/lantz/gui/SystemTabComponent.java
new file mode 100644
index 0000000..612e290
--- /dev/null
+++ b/src/main/java/se/lantz/gui/SystemTabComponent.java
@@ -0,0 +1,67 @@
+package se.lantz.gui;
+
+import java.awt.Font;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+public class SystemTabComponent extends JPanel
+{
+ private JLabel textLabel;
+ private JLabel numberLabel;
+
+ public SystemTabComponent(String text)
+ {
+ GridBagLayout gridBagLayout = new GridBagLayout();
+ gridBagLayout.columnWidths = new int[] { 0, 0, 0 };
+ gridBagLayout.rowHeights = new int[] { 0, 0 };
+ gridBagLayout.columnWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
+ gridBagLayout.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
+ setLayout(gridBagLayout);
+ GridBagConstraints gbc_descrLabel = new GridBagConstraints();
+ gbc_descrLabel.insets = new Insets(0, 0, 0, 5);
+ gbc_descrLabel.gridx = 0;
+ gbc_descrLabel.gridy = 0;
+ add(getTextLabel(), gbc_descrLabel);
+ GridBagConstraints gbc_languageLabel = new GridBagConstraints();
+ gbc_languageLabel.gridx = 1;
+ gbc_languageLabel.gridy = 0;
+ add(getNumberLabel(), gbc_languageLabel);
+ getTextLabel().setText(text);
+ this.setOpaque(false);
+ }
+
+ private JLabel getTextLabel()
+ {
+ if (textLabel == null)
+ {
+ textLabel = new JLabel("");
+ }
+ return textLabel;
+ }
+
+ private JLabel getNumberLabel()
+ {
+ if (numberLabel == null)
+ {
+ numberLabel = new JLabel("");
+ numberLabel.setFont(getNumberLabel().getFont().deriveFont(Font.BOLD));
+ }
+ return numberLabel;
+ }
+
+ public void setNumber(String text)
+ {
+ if (text.isBlank())
+ {
+ getNumberLabel().setText("");
+ }
+ else
+ {
+ getNumberLabel().setText("(" + text + ")");
+ }
+ }
+}
diff --git a/src/main/java/se/lantz/model/InfoModel.java b/src/main/java/se/lantz/model/InfoModel.java
index 4486e41..8001cd6 100644
--- a/src/main/java/se/lantz/model/InfoModel.java
+++ b/src/main/java/se/lantz/model/InfoModel.java
@@ -592,6 +592,32 @@ public class InfoModel extends AbstractModel implements CommonInfoModel
notifyChange();
}
}
+
+ public int getNumberOfExtraDisks()
+ {
+ int extraDisks = 0;
+ if (!disk2File.isBlank())
+ {
+ extraDisks++;
+ }
+ if (!disk3File.isBlank())
+ {
+ extraDisks++;
+ }
+ if (!disk4File.isBlank())
+ {
+ extraDisks++;
+ }
+ if (!disk5File.isBlank())
+ {
+ extraDisks++;
+ }
+ if (!disk6File.isBlank())
+ {
+ extraDisks++;
+ }
+ return extraDisks;
+ }
public void updateFileNames()
{
diff --git a/src/main/java/se/lantz/model/SavedStatesModel.java b/src/main/java/se/lantz/model/SavedStatesModel.java
index 7134d62..aff62f1 100644
--- a/src/main/java/se/lantz/model/SavedStatesModel.java
+++ b/src/main/java/se/lantz/model/SavedStatesModel.java
@@ -359,6 +359,28 @@ public class SavedStatesModel extends AbstractModel
notifyChange();
}
+ public int getNumberOfAvailableSavedStates()
+ {
+ int availableStates = 0;
+ if (!state1File.isBlank())
+ {
+ availableStates++;
+ }
+ if (!state2File.isBlank())
+ {
+ availableStates++;
+ }
+ if (!state3File.isBlank())
+ {
+ availableStates++;
+ }
+ if (!state4File.isBlank())
+ {
+ availableStates++;
+ }
+ return availableStates;
+ }
+
public void resetProperties()
{
state1PngFile = "";