diff --git a/src/main/java/se/lantz/gui/carousel/CarouselPreviewDialog.java b/src/main/java/se/lantz/gui/carousel/CarouselPreviewDialog.java index 16dc99e..a23ec7b 100644 --- a/src/main/java/se/lantz/gui/carousel/CarouselPreviewDialog.java +++ b/src/main/java/se/lantz/gui/carousel/CarouselPreviewDialog.java @@ -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()); diff --git a/src/main/java/se/lantz/gui/carousel/CoverPanel.java b/src/main/java/se/lantz/gui/carousel/CoverPanel.java index fc74b00..81d9385 100644 --- a/src/main/java/se/lantz/gui/carousel/CoverPanel.java +++ b/src/main/java/se/lantz/gui/carousel/CoverPanel.java @@ -72,9 +72,8 @@ public class CoverPanel extends JPanel { model.addPropertyChangeListener(CarouselPreviewModel.SELECTED_GAME, e -> { reloadScreens(); - updateSelectedBorder(); }); - + model.addPropertyChangeListener(CarouselPreviewModel.CLEAR_SELECTION, e -> { clearSelectedBorder(); }); @@ -179,32 +178,32 @@ public class CoverPanel extends JPanel { label.setBorder(BorderFactory.createLineBorder(Color.YELLOW, 5)); 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 - mainWindow.getMainPanel().runCurrentGame(); + if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) + { + //trigger run game + mainWindow.getMainPanel().runCurrentGame(); + } } - } - }); + }); } else { 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; } @@ -218,13 +217,13 @@ public class CoverPanel extends JPanel scrolingTimer.start(); } } - + protected void pageUpTriggered() { String gameId = model.getGameIdForPageUp(); this.mainWindow.setSelectedGameInGameList(gameId); } - + protected void pageDownTriggered() { String gameId = model.getGameIdForPageDown(); @@ -246,6 +245,7 @@ public class CoverPanel extends JPanel } scrollToPosition(); panel.setVisible(true); + updateSelectedBorder(); } private void updateSelectedBorder() @@ -267,7 +267,7 @@ public class CoverPanel extends JPanel } } } - + private void clearSelectedBorder() { for (int i = 0; i < panel.getComponentCount(); i++) @@ -292,7 +292,7 @@ public class CoverPanel extends JPanel (label).setIcon(null); } } - + private void loadScreenForBorder(GameLabel label, GameDetails game) { String filename = game.getCover(); @@ -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))); diff --git a/src/main/java/se/lantz/model/carousel/CarouselPreviewModel.java b/src/main/java/se/lantz/model/carousel/CarouselPreviewModel.java index 8c98188..0320125 100644 --- a/src/main/java/se/lantz/model/carousel/CarouselPreviewModel.java +++ b/src/main/java/se/lantz/model/carousel/CarouselPreviewModel.java @@ -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)