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;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.beans.Beans;
import javax.swing.AbstractAction;
import javax.swing.Action;
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.MainWindow;
@ -16,12 +20,24 @@ import se.lantz.model.carousel.CarouselPreviewModel;
public class CarouselPreviewDialog extends BaseDialog
{
private static final Logger logger = LoggerFactory.getLogger(CarouselPreviewDialog.class);
private BackgroundPanel panel;
private MainViewModel uiModel;
private MainWindow mainWindow;
private CarouselPreviewModel model;
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)
{
super(owner);
@ -34,6 +50,9 @@ public class CarouselPreviewDialog extends BaseDialog
addContent(getBackgroundPanel());
getButtonPanel().setVisible(false);
getBackgroundPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("F5"), "reload");
getBackgroundPanel().getActionMap().put("reload", reloadAction);
if (!Beans.isDesignTime())
{
uiModel.addPropertyChangeListener("selectedGamelistView", e -> modelChanged());

View File

@ -72,7 +72,6 @@ public class CoverPanel extends JPanel
{
model.addPropertyChangeListener(CarouselPreviewModel.SELECTED_GAME, e -> {
reloadScreens();
updateSelectedBorder();
});
model.addPropertyChangeListener(CarouselPreviewModel.CLEAR_SELECTION, e -> {
@ -246,6 +245,7 @@ public class CoverPanel extends JPanel
}
scrollToPosition();
panel.setVisible(true);
updateSelectedBorder();
}
private void updateSelectedBorder()
@ -301,8 +301,7 @@ public class CoverPanel extends JPanel
{
BufferedImage image = ImageIO.read(imagefile);
Image newImage = image.getScaledInstance(125, 175, Image.SCALE_SMOOTH);
BufferedImage copyOfImage =
new BufferedImage(125, 175, BufferedImage.TYPE_INT_ARGB);
BufferedImage copyOfImage = new BufferedImage(125, 175, BufferedImage.TYPE_INT_ARGB);
Graphics g = copyOfImage.createGraphics();
g.drawImage(newImage, 0, 0, null);
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");
if (mainModel.getCurrentGameViewGameCount() < 10)