fix: Pressing F5 in the carousel preview will reload the content.

Small bugfix for showing the border for the selected game properly when the dialog is opened.
This commit is contained in:
lantzelot-swe 2024-05-03 23:03:49 +02:00
parent bbc4d2fbb3
commit 1690fa3c55
3 changed files with 47 additions and 29 deletions

View File

@ -1,13 +1,17 @@
package se.lantz.gui.carousel; package se.lantz.gui.carousel;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Frame; import java.awt.event.ActionEvent;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.beans.Beans; import java.beans.Beans;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import se.lantz.gui.BaseDialog; import se.lantz.gui.BaseDialog;
import se.lantz.gui.MainWindow; import se.lantz.gui.MainWindow;
@ -16,12 +20,24 @@ import se.lantz.model.carousel.CarouselPreviewModel;
public class CarouselPreviewDialog extends BaseDialog public class CarouselPreviewDialog extends BaseDialog
{ {
private static final Logger logger = LoggerFactory.getLogger(CarouselPreviewDialog.class);
private BackgroundPanel panel; private BackgroundPanel panel;
private MainViewModel uiModel; private MainViewModel uiModel;
private MainWindow mainWindow; private MainWindow mainWindow;
private CarouselPreviewModel model; private CarouselPreviewModel model;
private JButton runGameButton; private JButton runGameButton;
private Action reloadAction = new AbstractAction()
{
@Override
public void actionPerformed(ActionEvent e)
{
logger.debug("Reloading carousel");
model.reloadCarousel();
}
};
public CarouselPreviewDialog(final MainWindow owner, final MainViewModel uiModel) public CarouselPreviewDialog(final MainWindow owner, final MainViewModel uiModel)
{ {
super(owner); super(owner);
@ -34,6 +50,9 @@ public class CarouselPreviewDialog extends BaseDialog
addContent(getBackgroundPanel()); addContent(getBackgroundPanel());
getButtonPanel().setVisible(false); getButtonPanel().setVisible(false);
getBackgroundPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("F5"), "reload");
getBackgroundPanel().getActionMap().put("reload", reloadAction);
if (!Beans.isDesignTime()) if (!Beans.isDesignTime())
{ {
uiModel.addPropertyChangeListener("selectedGamelistView", e -> modelChanged()); uiModel.addPropertyChangeListener("selectedGamelistView", e -> modelChanged());

View File

@ -72,7 +72,6 @@ public class CoverPanel extends JPanel
{ {
model.addPropertyChangeListener(CarouselPreviewModel.SELECTED_GAME, e -> { model.addPropertyChangeListener(CarouselPreviewModel.SELECTED_GAME, e -> {
reloadScreens(); reloadScreens();
updateSelectedBorder();
}); });
model.addPropertyChangeListener(CarouselPreviewModel.CLEAR_SELECTION, e -> { model.addPropertyChangeListener(CarouselPreviewModel.CLEAR_SELECTION, e -> {
@ -179,32 +178,32 @@ public class CoverPanel extends JPanel
{ {
label.setBorder(BorderFactory.createLineBorder(Color.YELLOW, 5)); label.setBorder(BorderFactory.createLineBorder(Color.YELLOW, 5));
label.addMouseListener(new MouseAdapter() label.addMouseListener(new MouseAdapter()
{
@Override
public void mouseClicked(MouseEvent e)
{ {
if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2)
@Override
public void mouseClicked(MouseEvent e)
{ {
//trigger run game if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2)
mainWindow.getMainPanel().runCurrentGame(); {
//trigger run game
mainWindow.getMainPanel().runCurrentGame();
}
} }
} });
});
} }
else else
{ {
label.addMouseListener(new MouseAdapter() label.addMouseListener(new MouseAdapter()
{
@Override
public void mouseClicked(MouseEvent e)
{ {
if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 1) @Override
public void mouseClicked(MouseEvent e)
{ {
mainWindow.setSelectedGameInGameList(label.getGameId()); if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 1)
{
mainWindow.setSelectedGameInGameList(label.getGameId());
}
} }
} });
});
} }
return label; return label;
} }
@ -246,6 +245,7 @@ public class CoverPanel extends JPanel
} }
scrollToPosition(); scrollToPosition();
panel.setVisible(true); panel.setVisible(true);
updateSelectedBorder();
} }
private void updateSelectedBorder() private void updateSelectedBorder()
@ -301,8 +301,7 @@ public class CoverPanel extends JPanel
{ {
BufferedImage image = ImageIO.read(imagefile); BufferedImage image = ImageIO.read(imagefile);
Image newImage = image.getScaledInstance(125, 175, Image.SCALE_SMOOTH); Image newImage = image.getScaledInstance(125, 175, Image.SCALE_SMOOTH);
BufferedImage copyOfImage = BufferedImage copyOfImage = new BufferedImage(125, 175, BufferedImage.TYPE_INT_ARGB);
new BufferedImage(125, 175, BufferedImage.TYPE_INT_ARGB);
Graphics g = copyOfImage.createGraphics(); Graphics g = copyOfImage.createGraphics();
g.drawImage(newImage, 0, 0, null); g.drawImage(newImage, 0, 0, null);
label.setIcon(new ImageIcon(copyOfImage.getSubimage(5, 5, 115, 165))); label.setIcon(new ImageIcon(copyOfImage.getSubimage(5, 5, 115, 165)));

View File

@ -49,7 +49,7 @@ public class CarouselPreviewModel extends AbstractModel
} }
} }
private void reloadCarousel() public void reloadCarousel()
{ {
logger.debug("RELOAD carousel in preview"); logger.debug("RELOAD carousel in preview");
if (mainModel.getCurrentGameViewGameCount() < 10) if (mainModel.getCurrentGameViewGameCount() < 10)