feat: WIP of carousel preview

This commit is contained in:
lantzelot-swe 2023-11-22 16:41:15 +01:00
parent f21c2de42f
commit af6a4bbd38
7 changed files with 490 additions and 5 deletions

View File

@ -23,6 +23,7 @@ import javax.swing.event.HyperlinkEvent;
import se.lantz.gamebase.GamebaseImporter;
import se.lantz.gui.DeleteDialog.TYPE_OF_DELETE;
import se.lantz.gui.carousel.CarouselDialog;
import se.lantz.gui.dbbackup.BackupProgressDialog;
import se.lantz.gui.dbbackup.BackupWorker;
import se.lantz.gui.dbrestore.RestoreDbDialog;
@ -90,6 +91,8 @@ public class MenuManager
private JMenuItem refreshItem;
private JMenuItem refreshAllItem;
private JMenuItem carouselPreviewItem;
private JMenuItem toggleFavorite1Item;
private JMenuItem toggleFavorite2Item;
private JMenuItem toggleFavorite3Item;
@ -208,6 +211,9 @@ public class MenuManager
exportMenu.add(getExportFileLoaderItem());
exportMenu.add(getExportSavedStatesItem());
fileMenu.add(exportMenu);
fileMenu.addSeparator();
fileMenu.add(getCarouselPreviewMenuItem());
fileMenu.addSeparator();
fileMenu.add(getRefreshItem());
fileMenu.add(getRefreshAllItem());
@ -437,6 +443,14 @@ public class MenuManager
return runGameItem;
}
JMenuItem getCarouselPreviewMenuItem()
{
carouselPreviewItem = new JMenuItem("Carousel preview...");
carouselPreviewItem.addActionListener(e -> showCarouselPreview());
return carouselPreviewItem;
}
private JMenuItem getImportCarouselItem()
{
importCarouselItem = new JMenuItem("Import Carousel folder...");
@ -837,8 +851,7 @@ public class MenuManager
PrimaryJoystickDialog dialog = new PrimaryJoystickDialog(MainWindow.getInstance());
dialog.pack();
dialog.setLocationRelativeTo(this.mainWindow);
if (dialog.showDialog())
{
mainWindow.setWaitCursor(true);
@ -1530,9 +1543,10 @@ public class MenuManager
private void resetControllerConfigs()
{
String message = "Do you want to reset the controller configurations for all games in the current gamelist view?\n" +
"Only the mappings are reset to the default (defined in preferences), primary controller port is preserved.\n" +
"The second controller is also reset with the default mappings.";
String message =
"Do you want to reset the controller configurations for all games in the current gamelist view?\n" +
"Only the mappings are reset to the default (defined in preferences), primary controller port is preserved.\n" +
"The second controller is also reset with the default mappings.";
int option = JOptionPane.showConfirmDialog(MainWindow.getInstance().getMainPanel(),
message,
@ -1707,4 +1721,14 @@ public class MenuManager
{
installPCUAEManager.checkForNewVersionAtStartup();
}
private void showCarouselPreview()
{
//TEST
CarouselDialog prefDialog = new CarouselDialog(this.mainWindow);
prefDialog.pack();
prefDialog.setLocationRelativeTo(MainWindow.getInstance());
prefDialog.showDialog();
}
}

View File

@ -0,0 +1,94 @@
package se.lantz.gui.carousel;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import java.awt.Font;
import java.awt.Insets;
import java.awt.Color;
public class BackgroundPanel extends JPanel {
public BackgroundPanel() {
GridBagLayout gridBagLayout = new GridBagLayout();
setLayout(gridBagLayout);
GridBagConstraints gbc_coverPanel = new GridBagConstraints();
gbc_coverPanel.gridwidth = 2;
gbc_coverPanel.anchor = GridBagConstraints.NORTHWEST;
gbc_coverPanel.weighty = 1.0;
gbc_coverPanel.weightx = 1.0;
gbc_coverPanel.fill = GridBagConstraints.HORIZONTAL;
gbc_coverPanel.gridx = 0;
gbc_coverPanel.gridy = 1;
add(getCoverPanel(), gbc_coverPanel);
GridBagConstraints gbc_panel = new GridBagConstraints();
gbc_panel.insets = new Insets(27, 37, 22, 10);
gbc_panel.fill = GridBagConstraints.BOTH;
gbc_panel.anchor = GridBagConstraints.NORTHWEST;
gbc_panel.gridx = 0;
gbc_panel.gridy = 0;
add(getScreenshotLabel(), gbc_panel);
GridBagConstraints gbc_textPanel = new GridBagConstraints();
gbc_textPanel.weightx = 1.0;
gbc_textPanel.anchor = GridBagConstraints.NORTHWEST;
gbc_textPanel.fill = GridBagConstraints.BOTH;
gbc_textPanel.gridx = 1;
gbc_textPanel.gridy = 0;
add(getTextPanel(), gbc_textPanel);
setBackground("/se/lantz/carousel/Carousel1400x788-modified.png");
}
private Image background;
private JLabel lblNewLabel;
private JLabel screenShotLabel;
private TextPanel textPanel;
private CoverPanel coverPanel;
public void paintComponent(Graphics g) {
int width = this.getSize().width;
int height = this.getSize().height;
if (this.background != null) {
g.drawImage(this.background, 0, 0, width, height, null);
}
super.paintComponent(g);
}
public void setBackground(String imagePath) {
this.setOpaque(false);
this.background = new ImageIcon(getClass().getResource(imagePath)).getImage();
repaint();
}
private JLabel getScreenshotLabel() {
if (screenShotLabel == null) {
screenShotLabel = new JLabel();
screenShotLabel.setBackground(Color.YELLOW);
Image image = new ImageIcon(getClass().getResource("/se/lantz/carousel/test.png")).getImage();
Image scaledImage = image.getScaledInstance(694, 401, Image.SCALE_SMOOTH);
screenShotLabel.setIcon(new ImageIcon(scaledImage));
}
return screenShotLabel;
}
private TextPanel getTextPanel() {
if (textPanel == null) {
textPanel = new TextPanel();
}
return textPanel;
}
private CoverPanel getCoverPanel() {
if (coverPanel == null) {
coverPanel = new CoverPanel();
}
return coverPanel;
}
}

View File

@ -0,0 +1,30 @@
package se.lantz.gui.carousel;
import java.awt.Dimension;
import java.awt.Frame;
import se.lantz.gui.BaseDialog;
public class CarouselDialog extends BaseDialog
{
private BackgroundPanel panel;
public CarouselDialog(Frame owner)
{
super(owner);
setTitle("Carousel preview");
addContent(getPreferencesTabPanel());
getOkButton().setPreferredSize(null);
this.setPreferredSize(new Dimension(1400, 802));
this.setResizable(false);
}
private BackgroundPanel getPreferencesTabPanel()
{
if (panel == null)
{
panel = new BackgroundPanel();
}
return panel;
}
}

View File

@ -0,0 +1,165 @@
package se.lantz.gui.carousel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseWheelListener;
import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.KeyStroke;
import javax.swing.Timer;
import javax.swing.border.LineBorder;
public class CoverPanel extends JPanel
{
private JPanel panel;
private JScrollPane scrollPane;
private JLabel test1Label;
public CoverPanel()
{
// setBorder(new LineBorder(new Color(0, 0, 0)));
setBackground(new Color(138, 137, 138));
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.rowWeights = new double[] { 1.0 };
gridBagLayout.columnWeights = new double[] { 1.0 };
setLayout(gridBagLayout);
this.setPreferredSize(new Dimension(700, 187));
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
gbc_scrollPane.weighty = 1.0;
gbc_scrollPane.weightx = 1.0;
gbc_scrollPane.fill = GridBagConstraints.BOTH;
gbc_scrollPane.gridx = 0;
gbc_scrollPane.gridy = 0;
add(getScrollPane(), gbc_scrollPane);
addCovers(100);
}
private JPanel getPanel()
{
if (panel == null)
{
panel = new JPanel();
GridBagLayout gbl_panel = new GridBagLayout();
panel.setLayout(gbl_panel);
panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0),
"scrollRight");
panel.getActionMap().put("scrollRight", new AbstractAction()
{
@Override
public void actionPerformed(ActionEvent e)
{
scrollOneGame(true);
}
});
panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0),
"scrollLeft");
panel.getActionMap().put("scrollLeft", new AbstractAction()
{
@Override
public void actionPerformed(ActionEvent e)
{
scrollOneGame(false);
}
});
}
return panel;
}
int test = 0;
ActionListener timerListener = (e) -> {
scrollFromTimer();
};
Timer javaTimer = new Timer(10, timerListener);
boolean stopped = true;
boolean scrollDirectionRight = true;
private void scrollFromTimer()
{
int valueToScroll = scrollDirectionRight
? scrollPane.getHorizontalScrollBar().getValue() + 32
: scrollPane.getHorizontalScrollBar().getValue() - 32;
//Scroll
scrollPane.getHorizontalScrollBar().setValue(valueToScroll);
test++;
if (test > 4)
{
int lastScrollValue = scrollDirectionRight
? scrollPane.getHorizontalScrollBar().getValue() + 10
: scrollPane.getHorizontalScrollBar().getValue() - 10;
scrollPane.getHorizontalScrollBar().setValue(lastScrollValue);
test = 0;
javaTimer.stop();
stopped = true;
}
}
private JScrollPane getScrollPane()
{
if (scrollPane == null)
{
scrollPane = new JScrollPane();
scrollPane.setViewportView(getPanel());
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
scrollPane.getHorizontalScrollBar().setPreferredSize(new Dimension(0, 0));
scrollPane.getHorizontalScrollBar().setUnitIncrement(10);
scrollPane.getHorizontalScrollBar().setBlockIncrement(10);
for (MouseWheelListener listener : scrollPane.getMouseWheelListeners())
{
scrollPane.removeMouseWheelListener(listener);
}
scrollPane.addMouseWheelListener(a -> {
scrollOneGame(a.getWheelRotation() > 0);
});
}
return scrollPane;
}
private void addCovers(int converCount)
{
for (int i = 0; i < converCount; i++)
{
GridBagConstraints gbc_label = new GridBagConstraints();
gbc_label.fill = GridBagConstraints.BOTH;
gbc_label.insets = new Insets(5, 22, 5, 23);
gbc_label.weighty = 1.0;
gbc_label.gridx = i;
gbc_label.gridy = 0;
panel.add(getLabel(i), gbc_label);
}
}
private JLabel getLabel(int index)
{
JLabel label = new JLabel("Label");
label.setBorder(new LineBorder(new Color(0, 0, 0)));
label.setPreferredSize(new Dimension(125, 175));
return label;
}
private void scrollOneGame(boolean right)
{
if (stopped)
{
scrollDirectionRight = right;
stopped = false;
javaTimer.start();
}
}
}

View File

@ -0,0 +1,172 @@
package se.lantz.gui.carousel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.LayoutManager;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.border.LineBorder;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
public class TextPanel extends JPanel
{
private JLabel titleLabel;
private JTextPane textPane;
private JLabel authorLabel;
private JLabel composerLabel;
private JLabel genreLabel;
private JLabel yearLabel;
public TextPanel()
{
setFont(new Font("Microsoft Sans Serif", Font.BOLD, 20));
// setBorder(new LineBorder(new Color(0, 0, 0)));
setOpaque(false);
GridBagLayout gridBagLayout = new GridBagLayout();
setLayout(gridBagLayout);
GridBagConstraints gbc_titleLabel = new GridBagConstraints();
gbc_titleLabel.gridwidth = 2;
gbc_titleLabel.weightx = 1.0;
gbc_titleLabel.insets = new Insets(17, 20, 5, 0);
gbc_titleLabel.anchor = GridBagConstraints.NORTHWEST;
gbc_titleLabel.fill = GridBagConstraints.HORIZONTAL;
gbc_titleLabel.gridx = 0;
gbc_titleLabel.gridy = 0;
add(getTitleLabel(), gbc_titleLabel);
GridBagConstraints gbc_textArea = new GridBagConstraints();
gbc_textArea.gridwidth = 2;
gbc_textArea.anchor = GridBagConstraints.NORTHWEST;
gbc_textArea.insets = new Insets(5, 25, 5, 40);
gbc_textArea.fill = GridBagConstraints.BOTH;
gbc_textArea.gridx = 0;
gbc_textArea.gridy = 1;
add(getTextArea(), gbc_textArea);
GridBagConstraints gbc_authorLabel = new GridBagConstraints();
gbc_authorLabel.gridwidth = 2;
gbc_authorLabel.insets = new Insets(6, 145, 0, 0);
gbc_authorLabel.anchor = GridBagConstraints.NORTHWEST;
gbc_authorLabel.gridx = 0;
gbc_authorLabel.gridy = 2;
add(getAuthorLabel(), gbc_authorLabel);
GridBagConstraints gbc_composerLabel = new GridBagConstraints();
gbc_composerLabel.gridwidth = 2;
gbc_composerLabel.insets = new Insets(-2, 145, 0, 0);
gbc_composerLabel.anchor = GridBagConstraints.NORTHWEST;
gbc_composerLabel.gridx = 0;
gbc_composerLabel.gridy = 3;
add(getComposerLabel(), gbc_composerLabel);
GridBagConstraints gbc_genreLabel = new GridBagConstraints();
gbc_genreLabel.weightx = 1.0;
gbc_genreLabel.insets = new Insets(-2, 145, 0, 0);
gbc_genreLabel.weighty = 1.0;
gbc_genreLabel.anchor = GridBagConstraints.NORTHWEST;
gbc_genreLabel.gridx = 0;
gbc_genreLabel.gridy = 4;
add(getGenreLabel(), gbc_genreLabel);
GridBagConstraints gbc_yearLabel = new GridBagConstraints();
gbc_yearLabel.anchor = GridBagConstraints.NORTHWEST;
gbc_yearLabel.insets = new Insets(-2, 0, 0, 45);
gbc_yearLabel.gridx = 1;
gbc_yearLabel.gridy = 4;
add(getYearLabel(), gbc_yearLabel);
// TODO Auto-generated constructor stub
}
public TextPanel(LayoutManager layout)
{
super(layout);
// TODO Auto-generated constructor stub
}
public TextPanel(boolean isDoubleBuffered)
{
super(isDoubleBuffered);
// TODO Auto-generated constructor stub
}
public TextPanel(LayoutManager layout, boolean isDoubleBuffered)
{
super(layout, isDoubleBuffered);
// TODO Auto-generated constructor stub
}
private JLabel getTitleLabel()
{
if (titleLabel == null)
{
titleLabel = new JLabel("California Games");
// titleLabel.setBorder(new LineBorder(new Color(0, 0, 0)));
titleLabel.setBackground(Color.ORANGE);
titleLabel.setFont(new Font("Microsoft Sans Serif", Font.BOLD, 37));
}
return titleLabel;
}
private JTextPane getTextArea()
{
if (textPane == null)
{
textPane = new JTextPane();
// textPane.setBorder(new LineBorder(new Color(0, 0, 0)));
textPane.setForeground(Color.WHITE);
textPane.setFont(new Font("Verdana", Font.PLAIN, 21));
textPane.setOpaque(false);
String text512 = "In Monty on the run the intrepid coal thief Monty Mole fled to the rocky island of Gibraltar. However, the Intermole agency is on to him, and his only hope of escape is to trek across Europe, collecting enough cash to buy the Greek island of Montos and live there in luxury.This is Monty's third game, and the structure is similar to the previous three. There are 80 screens each representing some area of Europe.There are many items to collect, the most important are Eurocheques for money and airplane tickets.";
String textCalGames = "Welcome to California. Hit the beaches, parks and streets, and go for trophies in half-pipe skateboarding, footbag, roller skating, surfing, BMX, bike racing and flying disk throwing. Read the full online instructions on how to compete in the most totally awesome games in the world.";
textPane
.setText(text512);
changeLineSpacing(textPane, -0.12f, true);
textPane.setPreferredSize(new Dimension(100, 275));
}
return textPane;
}
/**
* Select all the text of a <code>JTextPane</code> first and then set the line spacing.
* @param the <code>JTextPane</code> to apply the change
* @param factor the factor of line spacing. For example, <code>1.0f</code>.
* @param replace whether the new <code>AttributeSet</code> should replace the old set. If set to <code>false</code>, will merge with the old one.
*/
private void changeLineSpacing(JTextPane pane, float factor, boolean replace) {
pane.selectAll();
MutableAttributeSet set = new SimpleAttributeSet(pane.getParagraphAttributes());
StyleConstants.setLineSpacing(set, factor);
pane.setParagraphAttributes(set, replace);
}
private JLabel getAuthorLabel() {
if (authorLabel == null) {
authorLabel = new JLabel("Epyx Games");
authorLabel.setFont(new Font("Microsoft Sans Serif", Font.BOLD, 22));
}
return authorLabel;
}
private JLabel getComposerLabel() {
if (composerLabel == null) {
composerLabel = new JLabel("Epyx Games testing testing!");
composerLabel.setFont(new Font("Microsoft Sans Serif", Font.BOLD, 22));
}
return composerLabel;
}
private JLabel getGenreLabel() {
if (genreLabel == null) {
genreLabel = new JLabel("Shoot'em Up");
genreLabel.setFont(new Font("Microsoft Sans Serif", Font.BOLD, 22));
}
return genreLabel;
}
private JLabel getYearLabel() {
if (yearLabel == null) {
yearLabel = new JLabel("1987");
yearLabel.setFont(new Font("Microsoft Sans Serif", Font.BOLD, 22));
}
return yearLabel;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 814 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB