Adds abut dialog, version reading and build adjustments

This commit is contained in:
mikael.lantz 2020-12-18 16:50:26 +01:00
parent 4989933fa4
commit 7a9fee0d49
10 changed files with 361 additions and 79 deletions

27
pom.xml
View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>se.lantz</groupId> <groupId>se.lantz</groupId>
<artifactId>PCUGameManager</artifactId> <artifactId>PCUGameManager</artifactId>
<version>0.0.9</version> <version>0.9.0</version>
<name>PCUGameManager</name> <name>PCUGameManager</name>
<dependencies> <dependencies>
<dependency> <dependency>
@ -70,6 +70,11 @@
se.lantz.PCUGameManager se.lantz.PCUGameManager
</mainClass> </mainClass>
</manifest> </manifest>
<manifestEntries>
<buildVersion>
${project.version}
</buildVersion>
</manifestEntries>
</archive> </archive>
<descriptorRefs> <descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef> <descriptorRef>jar-with-dependencies</descriptorRef>
@ -81,12 +86,14 @@
<plugin> <plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId> <groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId> <artifactId>launch4j-maven-plugin</artifactId>
<version>3.12</version> <version>1.7.25</version>
<executions> <executions>
<execution> <execution>
<id>l4j-gui</id> <id>l4j-gui</id>
<phase>package</phase> <phase>package</phase>
<goals><goal>launch4j</goal></goals> <goals>
<goal>launch4j</goal>
</goals>
<configuration> <configuration>
<headerType>gui</headerType> <headerType>gui</headerType>
<outfile>target/PcuGameManager.exe</outfile> <outfile>target/PcuGameManager.exe</outfile>
@ -110,13 +117,13 @@
</splash> </splash>
<icon>target/classes/Icon.ico</icon> <icon>target/classes/Icon.ico</icon>
<versionInfo> <versionInfo>
<fileVersion>0.0.0.1</fileVersion> <fileVersion>${project.version}.1</fileVersion>
<txtFileVersion>txt file version?</txtFileVersion> <txtFileVersion>${project.version}}</txtFileVersion>
<fileDescription>a description</fileDescription> <fileDescription>PCU Game Manager</fileDescription>
<copyright>my copyright</copyright> <copyright>Lantzelot</copyright>
<productVersion>0.0.0.1</productVersion> <productVersion>${project.version}.1</productVersion>
<txtProductVersion>txt product version</txtProductVersion> <txtProductVersion>${project.version}</txtProductVersion>
<productName>PcuGameManager</productName> <productName>PCU Game Manager</productName>
<internalName>pcu</internalName> <internalName>pcu</internalName>
<originalFilename>PcuGameManager.exe</originalFilename> <originalFilename>PcuGameManager.exe</originalFilename>
</versionInfo> </versionInfo>

View File

@ -0,0 +1,182 @@
package se.lantz.gui;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.KeyStroke;
import se.lantz.util.FileManager;
import java.awt.Font;
public class AboutDialog extends JDialog
{
private JLabel imageLabel;
private JLabel titleLabel;
private JLabel versionLabel;
private JLabel programmedLabel;
private JLabel thanksTo1Label;
private JLabel thanks2Label;
KeyStroke escKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
Action escAction = new AbstractAction()
{
private static final long serialVersionUID = 1756396251349970052L;
@Override
public void actionPerformed(ActionEvent e)
{
setVisible(false);
}
};
private JButton closeButton;
private JLabel jreVersionLabel;
public AboutDialog()
{
super(MainWindow.getInstance(), "About", true);
GridBagLayout gridBagLayout = new GridBagLayout();
getContentPane().setLayout(gridBagLayout);
GridBagConstraints gbc_imageLabel = new GridBagConstraints();
gbc_imageLabel.weightx = 1.0;
gbc_imageLabel.insets = new Insets(0, 0, 5, 0);
gbc_imageLabel.gridx = 0;
gbc_imageLabel.gridy = 0;
getContentPane().add(getImageLabel(), gbc_imageLabel);
GridBagConstraints gbc_titleLabel = new GridBagConstraints();
gbc_titleLabel.insets = new Insets(0, 0, 5, 0);
gbc_titleLabel.gridx = 0;
gbc_titleLabel.gridy = 1;
getContentPane().add(getTitleLabel(), gbc_titleLabel);
GridBagConstraints gbc_versionLabel = new GridBagConstraints();
gbc_versionLabel.insets = new Insets(0, 0, 5, 0);
gbc_versionLabel.gridx = 0;
gbc_versionLabel.gridy = 2;
getContentPane().add(getVersionLabel(), gbc_versionLabel);
GridBagConstraints gbc_jreVersionLabel = new GridBagConstraints();
gbc_jreVersionLabel.insets = new Insets(0, 0, 5, 0);
gbc_jreVersionLabel.gridx = 0;
gbc_jreVersionLabel.gridy = 3;
getContentPane().add(getJreVersionLabel(), gbc_jreVersionLabel);
GridBagConstraints gbc_programmedLabel = new GridBagConstraints();
gbc_programmedLabel.insets = new Insets(0, 0, 5, 0);
gbc_programmedLabel.gridx = 0;
gbc_programmedLabel.gridy = 4;
getContentPane().add(getProgrammedLabel(), gbc_programmedLabel);
GridBagConstraints gbc_thanksTo1Label = new GridBagConstraints();
gbc_thanksTo1Label.insets = new Insets(10, 0, 5, 0);
gbc_thanksTo1Label.gridx = 0;
gbc_thanksTo1Label.gridy = 5;
getContentPane().add(getThanksTo1Label(), gbc_thanksTo1Label);
GridBagConstraints gbc_closeButton = new GridBagConstraints();
gbc_closeButton.anchor = GridBagConstraints.SOUTH;
gbc_closeButton.insets = new Insets(5, 5, 10, 5);
gbc_closeButton.gridx = 0;
gbc_closeButton.gridy = 7;
getContentPane().add(getCloseButton(), gbc_closeButton);
GridBagConstraints gbc_thanks2Label = new GridBagConstraints();
gbc_thanks2Label.insets = new Insets(0, 0, 5, 0);
gbc_thanks2Label.anchor = GridBagConstraints.NORTH;
gbc_thanks2Label.weighty = 1.0;
gbc_thanks2Label.gridx = 0;
gbc_thanks2Label.gridy = 6;
getContentPane().add(getThanks2Label(), gbc_thanks2Label);
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
//Register esc as closing the window
getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escKeyStroke, "closeDialog");
getRootPane().getActionMap().put("closeDialog", escAction);
this.setResizable(false);
}
private JLabel getImageLabel()
{
if (imageLabel == null)
{
imageLabel = new JLabel("");
imageLabel.setIcon(new ImageIcon(getClass().getResource("/se/lantz/PCUGameManager.png")));
}
return imageLabel;
}
private JLabel getTitleLabel()
{
if (titleLabel == null)
{
titleLabel = new JLabel("Project Carousel USB Game Manager");
}
return titleLabel;
}
private JLabel getVersionLabel()
{
if (versionLabel == null)
{
versionLabel = new JLabel("Version: " + FileManager.getPcuVersionFromManifest());
versionLabel.setFont(new Font("Tahoma", Font.BOLD, 11));
}
return versionLabel;
}
private JLabel getProgrammedLabel()
{
if (programmedLabel == null)
{
programmedLabel = new JLabel("Coded by Lantzelot");
}
return programmedLabel;
}
private JLabel getThanksTo1Label()
{
if (thanksTo1Label == null)
{
thanksTo1Label =
new JLabel("Thanks to Spannernick for the Project Carousel USB initiative and idea for this application.");
}
return thanksTo1Label;
}
private JLabel getThanks2Label()
{
if (thanks2Label == null)
{
thanks2Label = new JLabel("");
}
return thanks2Label;
}
private JButton getCloseButton()
{
if (closeButton == null)
{
closeButton = new JButton("Close");
closeButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
setVisible(false);
}
});
}
return closeButton;
}
private JLabel getJreVersionLabel() {
if (jreVersionLabel == null) {
jreVersionLabel = new JLabel("JRE version:" + System.getProperty("java.runtime.version"));
}
return jreVersionLabel;
}
}

View File

@ -144,6 +144,8 @@ public class ListPanel extends JPanel
listViewComboBox.addActionListener(new ActionListener() listViewComboBox.addActionListener(new ActionListener()
{ {
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{
if (!uiModel.isDisableChangeNotifcation())
{ {
uiModel.setSelectedGameView((GameView) listViewComboBox.getSelectedItem()); uiModel.setSelectedGameView((GameView) listViewComboBox.getSelectedItem());
//TODO: keep track of selected index for the view and select it once data is updated //TODO: keep track of selected index for the view and select it once data is updated
@ -153,6 +155,7 @@ public class ListPanel extends JPanel
getList().ensureIndexIsVisible(0); getList().ensureIndexIsVisible(0);
}); });
} }
}
}); });
listViewComboBox.setModel(uiModel.getGameViewModel()); listViewComboBox.setModel(uiModel.getGameViewModel());
} }
@ -290,7 +293,7 @@ public class ListPanel extends JPanel
list.addListSelectionListener(e -> { list.addListSelectionListener(e -> {
if (!e.getValueIsAdjusting() || pageButtonPressed) if (!e.getValueIsAdjusting() || pageButtonPressed)
{ {
if (!delayDetailsUpdate) if (!delayDetailsUpdate && !uiModel.isDisableChangeNotifcation())
{ {
updateSelectedGame(); updateSelectedGame();
} }
@ -308,6 +311,7 @@ public class ListPanel extends JPanel
private void updateSelectedGame() private void updateSelectedGame()
{ {
System.out.println("Update selected Game!!!");
SwingUtilities SwingUtilities
.invokeLater(() -> mainPanel.getGameDetailsBackgroundPanel().updateSelectedGame(list.getSelectedValue())); .invokeLater(() -> mainPanel.getGameDetailsBackgroundPanel().updateSelectedGame(list.getSelectedValue()));
} }

View File

@ -6,10 +6,13 @@ import javax.swing.ImageIcon;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JMenu; import javax.swing.JMenu;
import javax.swing.JMenuBar; import javax.swing.JMenuBar;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import se.lantz.model.MainViewModel; import se.lantz.model.MainViewModel;
import se.lantz.util.FileManager;
public class MainWindow extends JFrame public final class MainWindow extends JFrame
{ {
/** /**
* *
@ -43,7 +46,7 @@ public class MainWindow extends JFrame
this.setTitle("PCU Game Manager"); this.setTitle("PCU Game Manager");
uiModel = new MainViewModel(); uiModel = new MainViewModel();
menuManager = new MenuManager(uiModel, this); menuManager = new MenuManager(uiModel, this);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
this.addWindowListener(new java.awt.event.WindowAdapter() this.addWindowListener(new java.awt.event.WindowAdapter()
{ {
@ -56,11 +59,19 @@ public class MainWindow extends JFrame
this.setJMenuBar(getMainMenuBar()); this.setJMenuBar(getMainMenuBar());
//Update title with version if available
String versionValue = FileManager.getPcuVersionFromManifest();
if (!versionValue.isEmpty())
{
setTitle("PCU Game Manager v." + versionValue);
}
} }
public void initialize() public void initialize()
{ {
getMainPanel().initialize(); getMainPanel().initialize();
menuManager.intialize();
} }
MainPanel getMainPanel() MainPanel getMainPanel()

View File

@ -94,22 +94,11 @@ public class MenuManager
helpMenu = new JMenu("Help"); helpMenu = new JMenu("Help");
helpMenu.add(getHelpItem()); helpMenu.add(getHelpItem());
helpMenu.add(getAboutItem()); helpMenu.add(getAboutItem());
}
uiModel.addSaveChangeListener(e -> { public void intialize()
addGameItem.setEnabled(!uiModel.isDataChanged()); {
}); uiModel.addSaveChangeListener(e -> addGameItem.setEnabled(!uiModel.isDataChanged()));
// KeyStroke keyStrokeToAddGame = KeyStroke.getKeyStroke(KeyEvent.VK_P, KeyEvent.CTRL_DOWN_MASK);
//
// mainWindow.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStrokeToAddGame, "AddGame");
// mainWindow.getRootPane().getActionMap().put("AddGame", new AbstractAction()
// {
// @Override
// public void actionPerformed(ActionEvent arg0)
// {
// mainWindow.getMainPanel().addNewGame();
// }
// });
} }
public List<JMenu> getMenues() public List<JMenu> getMenues()
@ -224,7 +213,10 @@ public class MenuManager
{ {
aboutItem = new JMenuItem("About..."); aboutItem = new JMenuItem("About...");
aboutItem.addActionListener(e -> { aboutItem.addActionListener(e -> {
//TODO AboutDialog dialog = new AboutDialog();
dialog.pack();
dialog.setLocationRelativeTo(this.mainWindow);
dialog.setVisible(true);
}); });
return aboutItem; return aboutItem;
} }

View File

@ -125,19 +125,31 @@ public class ScreenshotsPanel extends JPanel
private void reloadScreens() private void reloadScreens()
{ {
String modelCoverFile = model.getCoverFile(); String modelCoverFile = model.getCoverFile();
if (!modelCoverFile.equals(currentCoverFile)) if (modelCoverFile.isEmpty())
{
getCoverImageLabel().setIcon(getMissingCoverImageIcon());
}
else if (!modelCoverFile.equals(currentCoverFile))
{ {
loadCover(modelCoverFile); loadCover(modelCoverFile);
currentCoverFile = modelCoverFile; currentCoverFile = modelCoverFile;
} }
String modelScreen1File = model.getScreens1File(); String modelScreen1File = model.getScreens1File();
if (!model.getScreens1File().equals(currentScreen1File)) if (modelScreen1File.isEmpty())
{
getScreen1ImageLabel().setIcon(getMissingScreenshotImageIcon());
}
else if (!model.getScreens1File().equals(currentScreen1File))
{ {
loadScreen(modelScreen1File, getScreen1ImageLabel()); loadScreen(modelScreen1File, getScreen1ImageLabel());
currentScreen1File = modelScreen1File; currentScreen1File = modelScreen1File;
} }
String modelScreen2File = model.getScreens2File(); String modelScreen2File = model.getScreens2File();
if (!modelScreen2File.equals(currentScreen2File)) if (modelScreen2File.isEmpty())
{
getScreen2ImageLabel().setIcon(getMissingScreenshotImageIcon());
}
else if (!modelScreen2File.equals(currentScreen2File))
{ {
loadScreen(modelScreen2File, getScreen2ImageLabel()); loadScreen(modelScreen2File, getScreen2ImageLabel());
currentScreen2File = modelScreen2File; currentScreen2File = modelScreen2File;

View File

@ -122,7 +122,7 @@ public class SystemPanel extends JPanel
add(getConfigPanel(), gbc_configPanel); add(getConfigPanel(), gbc_configPanel);
if (!Beans.isDesignTime()) if (!Beans.isDesignTime())
{ {
model.addPropertyChangeListener((e) -> modelChanged()); model.addPropertyChangeListener(e -> modelChanged());
} }
} }
@ -181,6 +181,7 @@ public class SystemPanel extends JPanel
if (c64Button == null) if (c64Button == null)
{ {
c64Button = new JRadioButton("Commodore 64"); c64Button = new JRadioButton("Commodore 64");
c64Button.setSelected(true);
c64Button.addItemListener(new ItemListener() c64Button.addItemListener(new ItemListener()
{ {
public void itemStateChanged(ItemEvent e) public void itemStateChanged(ItemEvent e)
@ -192,7 +193,6 @@ public class SystemPanel extends JPanel
} }
} }
}); });
c64Button.setSelected(true);
c64Button.addActionListener(new ActionListener() c64Button.addActionListener(new ActionListener()
{ {
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)

View File

@ -48,9 +48,18 @@ public abstract class AbstractModel
propertyChangeSupport.firePropertyChange("notify", null, ""); propertyChangeSupport.firePropertyChange("notify", null, "");
} }
public void resetDataChangedAfterInit()
{
dataChanged = false;
}
public void disableChangeNotification(boolean disable) public void disableChangeNotification(boolean disable)
{ {
this.disable = disable; this.disable = disable;
}
public boolean isDisableChangeNotifcation()
{
return disable;
} }
} }

View File

@ -57,6 +57,8 @@ public class MainViewModel extends AbstractModel
joy2Model.setPrimaryChangeListener(e -> joy1Model joy2Model.setPrimaryChangeListener(e -> joy1Model
.setPrimaryWithoutListenerNotification(!Boolean.valueOf(e.getActionCommand()))); .setPrimaryWithoutListenerNotification(!Boolean.valueOf(e.getActionCommand())));
resetDataChangedAfterInit();
} }
private void setupGameViews() private void setupGameViews()
@ -74,9 +76,10 @@ public class MainViewModel extends AbstractModel
public void reloadGameViews() public void reloadGameViews()
{ {
this.disableChangeNotification(true);
gameViewModel.removeAllElements(); gameViewModel.removeAllElements();
setupGameViews(); setupGameViews();
reloadCurrentGameView(); this.disableChangeNotification(false);
} }
public ListModel<GameListData> getGameListModel() public ListModel<GameListData> getGameListModel()
@ -175,6 +178,7 @@ public class MainViewModel extends AbstractModel
public void reloadCurrentGameView() public void reloadCurrentGameView()
{ {
setSelectedGameView(getSelectedGameView()); setSelectedGameView(getSelectedGameView());
resetDataChanged();
} }
public void setSelectedGameView(GameView gameView) public void setSelectedGameView(GameView gameView)
@ -182,6 +186,7 @@ public class MainViewModel extends AbstractModel
this.selectedGameView = gameView; this.selectedGameView = gameView;
if (gameView != null) if (gameView != null)
{ {
this.disableChangeNotification(true);
logger.debug("Fetching games for view {}...", gameView); logger.debug("Fetching games for view {}...", gameView);
gameListModel.clear(); gameListModel.clear();
List<GameListData> gamesList = dbConnector.fetchGamesByView(gameView); List<GameListData> gamesList = dbConnector.fetchGamesByView(gameView);
@ -194,6 +199,7 @@ public class MainViewModel extends AbstractModel
{ {
this.allGamesCount = gamesList.size(); this.allGamesCount = gamesList.size();
} }
this.disableChangeNotification(false);
logger.debug("...done."); logger.debug("...done.");
} }
} }
@ -243,6 +249,24 @@ public class MainViewModel extends AbstractModel
systemModel.isDataChanged(); systemModel.isDataChanged();
} }
@Override
public void resetDataChanged()
{
infoModel.resetDataChanged();
joy1Model.resetDataChanged();
joy2Model.resetDataChanged();
systemModel.resetDataChanged();
}
@Override
public void resetDataChangedAfterInit()
{
infoModel.resetDataChangedAfterInit();
joy1Model.resetDataChangedAfterInit();
joy2Model.resetDataChangedAfterInit();
systemModel.resetDataChangedAfterInit();
}
/** /**
* *
* @return true if save was successful, false if not. * @return true if save was successful, false if not.
@ -376,6 +400,7 @@ public class MainViewModel extends AbstractModel
if (gameListModel.get(gameListModel.getSize() - 1).getGameId().isEmpty()) if (gameListModel.get(gameListModel.getSize() - 1).getGameId().isEmpty())
{ {
gameListModel.remove(gameListModel.getSize() - 1); gameListModel.remove(gameListModel.getSize() - 1);
resetDataChanged();
} }
} }
} }

View File

@ -10,6 +10,7 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URL;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -17,6 +18,8 @@ import java.nio.file.StandardCopyOption;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
@ -26,6 +29,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import se.lantz.db.DbConnector; import se.lantz.db.DbConnector;
import se.lantz.gui.MainWindow;
import se.lantz.model.InfoModel; import se.lantz.model.InfoModel;
import se.lantz.model.data.GameDetails; import se.lantz.model.data.GameDetails;
@ -523,6 +527,17 @@ public class FileManager
{ {
List<String> returnList = new ArrayList<>(); List<String> returnList = new ArrayList<>();
File backupFolder = new File(BACKUP); File backupFolder = new File(BACKUP);
if (!backupFolder.exists())
{
try
{
Files.createDirectory(backupFolder.toPath());
}
catch (IOException e)
{
ExceptionHandler.handleException(e, "Could not create backup folder");
}
}
for (File file : backupFolder.listFiles()) for (File file : backupFolder.listFiles())
{ {
if (file.isDirectory()) if (file.isDirectory())
@ -532,4 +547,29 @@ public class FileManager
} }
return returnList; return returnList;
} }
public static String getPcuVersionFromManifest()
{
String returnValue = "";
Class clazz = FileManager.class;
String className = clazz.getSimpleName() + ".class";
String classPath = clazz.getResource(className).toString();
if (classPath.startsWith("jar"))
{
String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
Manifest manifest;
try
{
manifest = new Manifest(new URL(manifestPath).openStream());
Attributes attr = manifest.getMainAttributes();
returnValue = attr.getValue("BuildVersion");
}
catch (IOException e1)
{
// TODO Auto-generated catch block
ExceptionHandler.handleException(e1, "Could not read manifest");
}
}
return returnValue;
}
} }