Adds run menu item and doubleclick in list to run. Various bug fixes.

This commit is contained in:
lantzelot-swe 2020-12-28 23:46:25 +01:00
parent cb60726142
commit 2b5ab18861
6 changed files with 112 additions and 13 deletions

View File

@ -8,11 +8,19 @@ import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.border.TitledBorder;
import org.slf4j.Logger;
@ -45,6 +53,16 @@ public class GameDetailsBackgroundPanel extends JPanel
private JPanel detailsPanel;
private CardLayout cardLayout;
private JButton scrapeButton;
private Action runGameAction = new AbstractAction("Run Game") {
@Override
public void actionPerformed(ActionEvent e)
{
if (runButton.isEnabled())
{
model.runGameInVice();
}
}};
private final ScraperManager scraperManager;
@ -290,9 +308,16 @@ public class GameDetailsBackgroundPanel extends JPanel
}
private JButton getRunButton() {
if (runButton == null) {
runButton = new JButton("Run game");
runButton.addActionListener(e -> model.runGameInVice());
runButton = new JButton(runGameAction);
}
return runButton;
}
public void runCurrentGame()
{
if (getRunButton().isEnabled())
{
getRunButton().doClick();
}
}
}

View File

@ -8,6 +8,8 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JComboBox;
@ -233,6 +235,16 @@ public class ListPanel extends JPanel
//Override setSelectionInterval to only allow changing game if no changes needs saving
list = new JList<GameListData>()
{
@Override
public void removeSelectionInterval(int start, int end)
{
//Don't allow clearing selection if unsaved data
if (!uiModel.isDataChanged())
{
super.removeSelectionInterval(start, end);
}
}
@Override
public void setSelectionInterval(int anchor, int lead)
{
@ -242,6 +254,11 @@ public class ListPanel extends JPanel
}
else
{
if (list.getSelectedIndex() == anchor)
{
//Clicked on the selected game, just ignore
return;
}
//Just ignore
int value = mainPanel.showUnsavedChangesDialog();
if (value == JOptionPane.YES_OPTION)
@ -298,7 +315,19 @@ public class ListPanel extends JPanel
}
}
});
list.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() == 2)
{
//trigger run game...
MainWindow.getInstance().getMainPanel().runCurrentGame();
}
}
});
list.addListSelectionListener(e -> {
if (!e.getValueIsAdjusting() || pageButtonPressed)
{

View File

@ -165,4 +165,12 @@ public class MainPanel extends JPanel
{
getListPanel().toggleFavorite();
}
public void runCurrentGame()
{
if (getListPanel().getSelectedIndexInList() > -1)
{
getGameDetailsBackgroundPanel().runCurrentGame();
}
}
}

View File

@ -57,6 +57,7 @@ public class MenuManager
private JMenuItem addGameItem;
private JMenuItem deleteGameItem;
private JMenuItem runGameItem;
private JMenuItem importItem;
private JMenuItem exportItem;
@ -100,6 +101,8 @@ public class MenuManager
fileMenu.add(getAddGameMenuItem());
fileMenu.add(getDeleteGameMenuItem());
fileMenu.addSeparator();
fileMenu.add(getRunGameMenuItem());
fileMenu.addSeparator();
fileMenu.add(getImportItem());
fileMenu.add(getExportItem());
fileMenu.addSeparator();
@ -118,7 +121,14 @@ public class MenuManager
public void intialize()
{
uiModel.addSaveChangeListener(e -> addGameItem.setEnabled(!uiModel.isDataChanged()));
uiModel.addSaveChangeListener(e -> {
boolean okToEnable = !uiModel.isDataChanged();
addGameItem.setEnabled(okToEnable);
importItem.setEnabled(okToEnable);
exportItem.setEnabled(okToEnable);
toggleFavoriteItem.setEnabled(okToEnable);
runGameItem.setEnabled(!uiModel.getInfoModel().getGamesFile().isEmpty());
});
}
public List<JMenu> getMenues()
@ -152,6 +162,17 @@ public class MenuManager
deleteGameItem.addActionListener(e -> mainWindow.getMainPanel().deleteCurrentGame());
return deleteGameItem;
}
JMenuItem getRunGameMenuItem()
{
runGameItem = new JMenuItem("Run Current Game");
KeyStroke keyStrokeToRunGame = KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK);
runGameItem.setAccelerator(keyStrokeToRunGame);
runGameItem.setMnemonic('R');
runGameItem.addActionListener(e -> mainWindow.getMainPanel().runCurrentGame());
return runGameItem;
}
private JMenuItem getImportItem()
{
@ -176,6 +197,9 @@ public class MenuManager
private JMenuItem getExitItem()
{
exitItem = new JMenuItem("Exit");
KeyStroke keyStrokeExit = KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_DOWN_MASK);
exitItem.setAccelerator(keyStrokeExit);
exitItem.setMnemonic('x');
exitItem.addActionListener(e -> {
if (uiModel.isDataChanged())

View File

@ -304,5 +304,6 @@ public class InfoModel extends AbstractModel
this.coverImage = null;
this.screen1Image = null;
this.screen2Image = null;
this.gamesPath = null;
}
}

View File

@ -96,7 +96,7 @@ public class FileManager
}
catch (IOException e)
{
logger.error("Could not store cover", e);
ExceptionHandler.handleException(e, "Could not store cover");
}
}
@ -109,7 +109,7 @@ public class FileManager
}
catch (IOException e)
{
logger.error("Could not store screen1", e);
ExceptionHandler.handleException(e, "Could not store screen1");
}
}
@ -122,7 +122,7 @@ public class FileManager
}
catch (IOException e)
{
logger.error("Could not store screen2", e);
ExceptionHandler.handleException(e, "Could not store screen2");
}
}
@ -136,16 +136,22 @@ public class FileManager
System.err.printf("The path %s doesn't exist!", source);
return;
}
try
{
compressGzip(source, target);
if (source.toString().endsWith(".gz"))
{
//Just copy
Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
}
else
{
compressGzip(source, target);
}
}
catch (IOException e)
{
e.printStackTrace();
ExceptionHandler.handleException(e, "Could not copy game file from " + source.toString());
}
}
}
@ -373,12 +379,18 @@ public class FileManager
if (model.getJoy1Model().isPrimary())
{
command.append("-joydev1 1 ");
command.append("-joydev2 0");
if (systemModel.isC64())
{
command.append("-joydev2 0");
}
}
else
{
command.append("-joydev1 0 ");
command.append("-joydev2 1");
if (systemModel.isC64())
{
command.append("-joydev2 1");
}
}
//Launch Vice