fix: adds a number to the "saved states" and "extra disks" tabs when data is available

This commit is contained in:
lantzelot-swe 2024-04-05 14:50:04 +02:00
parent 3dda927383
commit 963ae7e3a3
5 changed files with 158 additions and 1 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>se.lantz</groupId>
<artifactId>PCUAEManager</artifactId>
<version>2.16.2</version>
<version>2.16.3</version>
<name>PCUAEManager</name>
<properties>
<project.build.sourceEncoding>Cp1252</project.build.sourceEncoding>

View File

@ -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) : "");
}
}

View File

@ -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 + ")");
}
}
}

View File

@ -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()
{

View File

@ -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 = "";