Skip to content

Commit

Permalink
fix: add option in preferences to launch the carousel preview in wind…
Browse files Browse the repository at this point in the history
…owed or fullscreen mode
  • Loading branch information
lantzelot-swe committed Oct 6, 2024
1 parent f4ebfb5 commit 5164188
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 31 deletions.
52 changes: 34 additions & 18 deletions src/main/java/se/lantz/gui/ListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import se.lantz.model.MainViewModel;
import se.lantz.model.data.GameListData;
import se.lantz.model.data.GameView;
import se.lantz.util.FileManager;

public class ListPanel extends JPanel
{
Expand Down Expand Up @@ -824,29 +825,44 @@ public void showCarouselPreview()
}
else
{
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] screenDevices = ge.getScreenDevices();
GraphicsDevice mainWindowDevice = MainWindow.getInstance().getGraphicsConfiguration().getDevice();
GraphicsDevice secondaryDevice = null;
for (GraphicsDevice graphicsDevice : screenDevices)
if (carouselPreviewDialog == null || !carouselPreviewDialog.isShowing())
{
if (!graphicsDevice.equals(mainWindowDevice))
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] screenDevices = ge.getScreenDevices();
GraphicsDevice mainWindowDevice = MainWindow.getInstance().getGraphicsConfiguration().getDevice();
GraphicsDevice secondaryDevice = null;
for (GraphicsDevice graphicsDevice : screenDevices)
{
secondaryDevice = graphicsDevice;
if (!graphicsDevice.equals(mainWindowDevice))
{
secondaryDevice = graphicsDevice;
}
}
if (secondaryDevice == null)
{
secondaryDevice = mainWindowDevice;
}
}
if (secondaryDevice == null)
{
secondaryDevice = mainWindowDevice;
}

GraphicsConfiguration[] graphicsConfigurations = secondaryDevice.getConfigurations();
Rectangle graphicsBounds = graphicsConfigurations[0].getBounds();
GraphicsConfiguration graphicsConfigurations = secondaryDevice.getDefaultConfiguration();
Rectangle graphicsBounds = graphicsConfigurations.getBounds();

if (carouselPreviewDialog == null || !carouselPreviewDialog.isShowing())
{
carouselPreviewDialog = new CarouselPreviewDialog(MainWindow.getInstance(), this.uiModel);
carouselPreviewDialog.setBounds(graphicsBounds);
if (FileManager.isLaunchCarouselPreviewInFullscreen())
{
carouselPreviewDialog = new CarouselPreviewDialog(MainWindow.getInstance(), this.uiModel, true);
carouselPreviewDialog.setBounds(graphicsBounds);
carouselPreviewDialog.setUndecorated(true);
}
else
{
carouselPreviewDialog = new CarouselPreviewDialog(MainWindow.getInstance(), this.uiModel, false);
carouselPreviewDialog.pack();
//Position centred over secondary monitor
carouselPreviewDialog
.setLocation(((graphicsBounds.width / 2) - (carouselPreviewDialog.getSize().width / 2)) + graphicsBounds.x,
((graphicsBounds.height / 2) - (carouselPreviewDialog.getSize().height / 2)) +
graphicsBounds.y);

}
carouselPreviewDialog.showDialog();
}
else
Expand Down
30 changes: 24 additions & 6 deletions src/main/java/se/lantz/gui/carousel/CarouselPreviewDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,30 @@ public void actionPerformed(ActionEvent e)
}
};

public CarouselPreviewDialog(final MainWindow owner, final MainViewModel uiModel)
private boolean fullscreen;

public CarouselPreviewDialog(final MainWindow owner, final MainViewModel uiModel, final boolean fullscreen)
{
super(owner);
this.setUndecorated(true);
this.fullscreen = fullscreen;

this.model = new CarouselPreviewModel(uiModel);
this.uiModel = uiModel;
this.mainWindow = owner;
this.setPreferredSize(new Dimension(1400, 760));

this.setResizable(false);
this.setModal(false);

addContent(getBackgroundCenterPanel());
if (fullscreen)
{
this.setPreferredSize(new Dimension(1400, 760));
addContent(getBackgroundCenterPanel());
}
else
{
addContent(getBackgroundPanel());
}

getButtonPanel().setVisible(false);

getBackgroundPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("F5"), "reload");
Expand All @@ -96,8 +108,14 @@ public CarouselPreviewDialog(final MainWindow owner, final MainViewModel uiModel

private void modelChanged()
{
// setTitle("Carousel preview - " + uiModel.getSelectedGameView().getName());
gameListInfoLabel.setText("Carousel preview - " + uiModel.getSelectedGameView().getName());
if (fullscreen)
{
gameListInfoLabel.setText("Carousel preview - " + uiModel.getSelectedGameView().getName());
}
else
{
setTitle("Carousel preview - " + uiModel.getSelectedGameView().getName());
}
}

private BackgroundPanel getBackgroundPanel()
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/se/lantz/gui/preferences/CarouselPreviewPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package se.lantz.gui.preferences;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.beans.Beans;

import javax.swing.JCheckBox;
import javax.swing.JPanel;

import se.lantz.model.PreferencesModel;
import java.awt.Insets;

public class CarouselPreviewPanel extends JPanel
{
private JCheckBox fullscreenCheckBox;
private PreferencesModel model;

public CarouselPreviewPanel(PreferencesModel model)
{
this.model = model;
GridBagLayout gridBagLayout = new GridBagLayout();
setLayout(gridBagLayout);
GridBagConstraints gbc_fullscreenCheckBox = new GridBagConstraints();
gbc_fullscreenCheckBox.insets = new Insets(5, 0, 5, 5);
gbc_fullscreenCheckBox.weighty = 1.0;
gbc_fullscreenCheckBox.weightx = 1.0;
gbc_fullscreenCheckBox.anchor = GridBagConstraints.NORTHWEST;
gbc_fullscreenCheckBox.gridx = 0;
gbc_fullscreenCheckBox.gridy = 0;
add(getFullscreenCheckBox(), gbc_fullscreenCheckBox);
if (!Beans.isDesignTime())
{
model.addPropertyChangeListener(e -> modelChanged());
//Trigger an initial read from the model
modelChanged();
}
}

private void modelChanged()
{
getFullscreenCheckBox().setSelected(model.isStartCarouselInFullscreen());
}

private JCheckBox getFullscreenCheckBox()
{
if (fullscreenCheckBox == null)
{
fullscreenCheckBox = new JCheckBox("Launch Carousel Preview dialog in fullscreen mode.");
fullscreenCheckBox
.addItemListener((e) -> model.setStartCarouselInFullscreen(fullscreenCheckBox.isSelected()));
}
return fullscreenCheckBox;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private JTabbedPane getTabbedPane()
tabbedPane.addTab("Favorites", null, getFavPanel(), null);
tabbedPane.addTab("Controller", null, getJoystickBackgroundPanel(), null);
tabbedPane.addTab("Infoslot", null, getInfoSlotBackgroundPanel(), null);
tabbedPane.addTab("Vice", null, getVicePanel(), null);
tabbedPane.addTab("Vice/Carousel", null, getVicePanel(), null);
}
return tabbedPane;
}
Expand Down
28 changes: 27 additions & 1 deletion src/main/java/se/lantz/gui/preferences/VicePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class VicePanel extends JPanel
{
private ViceDetailsPanel mainWindowPanel;
private ViceDetailsPanel carouselPanel;
private CarouselPreviewPanel carouselPreviewPanel;
private PreferencesModel model;

public VicePanel(PreferencesModel model)
Expand All @@ -34,12 +35,22 @@ public VicePanel(PreferencesModel model)
GridBagConstraints gbc_carouselPanel = new GridBagConstraints();
gbc_carouselPanel.insets = new Insets(5, 5, 0, 5);
gbc_carouselPanel.anchor = GridBagConstraints.NORTH;
gbc_carouselPanel.weighty = 1.0;
gbc_carouselPanel.weighty = 0.0;
gbc_carouselPanel.weightx = 1.0;
gbc_carouselPanel.fill = GridBagConstraints.HORIZONTAL;
gbc_carouselPanel.gridx = 0;
gbc_carouselPanel.gridy = 1;
add(getCarouselPanel(), gbc_carouselPanel);

GridBagConstraints gbc_carouselLaunchPanel = new GridBagConstraints();
gbc_carouselLaunchPanel.insets = new Insets(5, 5, 0, 5);
gbc_carouselLaunchPanel.anchor = GridBagConstraints.NORTH;
gbc_carouselLaunchPanel.weighty = 1.0;
gbc_carouselLaunchPanel.weightx = 1.0;
gbc_carouselLaunchPanel.fill = GridBagConstraints.HORIZONTAL;
gbc_carouselLaunchPanel.gridx = 0;
gbc_carouselLaunchPanel.gridy = 2;
add(getCarouselLaunchPanel(), gbc_carouselLaunchPanel);
}

private ViceDetailsPanel getMainWindowPanel()
Expand Down Expand Up @@ -74,4 +85,19 @@ private ViceDetailsPanel getCarouselPanel()
}
return carouselPanel;
}

private CarouselPreviewPanel getCarouselLaunchPanel()
{
if (carouselPreviewPanel == null)
{
carouselPreviewPanel = new CarouselPreviewPanel(model);
carouselPreviewPanel.setBorder(new TitledBorder(null,
"Carousel Preview dialog",
TitledBorder.LEADING,
TitledBorder.TOP,
null,
null));
}
return carouselPreviewPanel;
}
}
33 changes: 28 additions & 5 deletions src/main/java/se/lantz/model/PreferencesModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class PreferencesModel extends AbstractModel implements CommonInfoModel
public static final String MAIN_WINDOW_SECONDARY_INPUT = "mainWindowSecondaryInput";
public static final String CAROUSEL_PRIMARY_INPUT = "carouselPrimaryInput";
public static final String CAROUSEL_SECONDARY_INPUT = "carouselSecondaryInput";

public static final String LAUNCH_CAROUSEL_PREVIEW_FULLSCREEN = "launchCarouselInFullScreen";

private boolean checkPCUAEVersionAtStartup = true;
private boolean checkManagerVersionAtStartup = true;
Expand Down Expand Up @@ -85,6 +85,7 @@ public class PreferencesModel extends AbstractModel implements CommonInfoModel
private int mainWindowSecondaryInput = 0;
private int carouselPrimaryInput = 1;
private int carouselSecondaryInput = 0;
private boolean startCarouselInFullscreen = true;

public PreferencesModel()
{
Expand Down Expand Up @@ -124,10 +125,16 @@ public PreferencesModel()
.parseBoolean(configuredProperties.getProperty(LAUNCH_VICE_FULLSCREEN_FROM_MAIN_WINDOW, "false")));
setLaunchViceFromCarouselFullScreen(Boolean
.parseBoolean(configuredProperties.getProperty(LAUNCH_VICE_FULLSCREEN_FROM_CAROUSEL, "true")));
setMainWindowPrimaryInput(Integer.parseInt(configuredProperties.getProperty(MAIN_WINDOW_PRIMARY_INPUT, Integer.toString(mainWindowPrimaryInput))));
setMainWindowSecondaryInput(Integer.parseInt(configuredProperties.getProperty(MAIN_WINDOW_SECONDARY_INPUT, Integer.toString(mainWindowSecondaryInput))));
setCarouselPrimaryInput(Integer.parseInt(configuredProperties.getProperty(CAROUSEL_PRIMARY_INPUT, Integer.toString(carouselPrimaryInput))));
setCarouselSecondaryInput(Integer.parseInt(configuredProperties.getProperty(CAROUSEL_SECONDARY_INPUT, Integer.toString(carouselSecondaryInput))));
setMainWindowPrimaryInput(Integer
.parseInt(configuredProperties.getProperty(MAIN_WINDOW_PRIMARY_INPUT, Integer.toString(mainWindowPrimaryInput))));
setMainWindowSecondaryInput(Integer.parseInt(configuredProperties
.getProperty(MAIN_WINDOW_SECONDARY_INPUT, Integer.toString(mainWindowSecondaryInput))));
setCarouselPrimaryInput(Integer
.parseInt(configuredProperties.getProperty(CAROUSEL_PRIMARY_INPUT, Integer.toString(carouselPrimaryInput))));
setCarouselSecondaryInput(Integer
.parseInt(configuredProperties.getProperty(CAROUSEL_SECONDARY_INPUT, Integer.toString(carouselSecondaryInput))));
setStartCarouselInFullscreen(Boolean
.parseBoolean(configuredProperties.getProperty(LAUNCH_CAROUSEL_PREVIEW_FULLSCREEN, "true")));
}

public boolean isCheckPCUAEVersionAtStartup()
Expand Down Expand Up @@ -645,6 +652,21 @@ public boolean isLaunchViceFromCarouselFullScreen()
return launchViceFromCarouselFullScreen;
}

public void setStartCarouselInFullscreen(boolean fullscreen)
{
boolean old = isStartCarouselInFullscreen();
this.startCarouselInFullscreen = fullscreen;
if ((Boolean.compare(old, startCarouselInFullscreen) != 0))
{
notifyChange();
}
}

public boolean isStartCarouselInFullscreen()
{
return startCarouselInFullscreen;
}

public void savePreferences()
{
Properties configuredProperties = FileManager.getConfiguredProperties();
Expand Down Expand Up @@ -683,6 +705,7 @@ public void savePreferences()
configuredProperties.put(MAIN_WINDOW_SECONDARY_INPUT, Integer.toString(mainWindowSecondaryInput));
configuredProperties.put(CAROUSEL_PRIMARY_INPUT, Integer.toString(carouselPrimaryInput));
configuredProperties.put(CAROUSEL_SECONDARY_INPUT, Integer.toString(carouselSecondaryInput));
configuredProperties.put(LAUNCH_CAROUSEL_PREVIEW_FULLSCREEN, Boolean.toString(startCarouselInFullscreen));
FileManager.storeProperties();
}
}
5 changes: 5 additions & 0 deletions src/main/java/se/lantz/util/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,11 @@ public static boolean isShowCropDialogForCover()
}
return Boolean.parseBoolean(showCropDialogForCover);
}

public static boolean isLaunchCarouselPreviewInFullscreen()
{
return Boolean.parseBoolean(FileManager.getConfiguredProperties().getProperty(PreferencesModel.LAUNCH_CAROUSEL_PREVIEW_FULLSCREEN, "true"));
}

private static String getBackupFolderName(String targetFolderName)
{
Expand Down

0 comments on commit 5164188

Please sign in to comment.