feat: carousel preview WIP 2
This commit is contained in:
parent
af6a4bbd38
commit
13e83218dc
|
@ -23,7 +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.carousel.CarouselPreviewDialog;
|
||||
import se.lantz.gui.dbbackup.BackupProgressDialog;
|
||||
import se.lantz.gui.dbbackup.BackupWorker;
|
||||
import se.lantz.gui.dbrestore.RestoreDbDialog;
|
||||
|
@ -1725,7 +1725,7 @@ public class MenuManager
|
|||
private void showCarouselPreview()
|
||||
{
|
||||
//TEST
|
||||
CarouselDialog prefDialog = new CarouselDialog(this.mainWindow);
|
||||
CarouselPreviewDialog prefDialog = new CarouselPreviewDialog(this.mainWindow, this.uiModel);
|
||||
prefDialog.pack();
|
||||
prefDialog.setLocationRelativeTo(MainWindow.getInstance());
|
||||
prefDialog.showDialog();
|
||||
|
|
|
@ -3,17 +3,32 @@ package se.lantz.gui.carousel;
|
|||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import se.lantz.model.MainViewModel;
|
||||
import se.lantz.model.carousel.CarouselPreviewModel;
|
||||
import se.lantz.model.data.GameDetails;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Font;
|
||||
import java.awt.Insets;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.beans.Beans;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.awt.Color;
|
||||
|
||||
public class BackgroundPanel extends JPanel {
|
||||
public BackgroundPanel() {
|
||||
private CarouselPreviewModel model;
|
||||
|
||||
public BackgroundPanel(final MainViewModel uiModel) {
|
||||
model = new CarouselPreviewModel(uiModel);
|
||||
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
setLayout(gridBagLayout);
|
||||
GridBagConstraints gbc_coverPanel = new GridBagConstraints();
|
||||
|
@ -41,10 +56,43 @@ public class BackgroundPanel extends JPanel {
|
|||
add(getTextPanel(), gbc_textPanel);
|
||||
|
||||
setBackground("/se/lantz/carousel/Carousel1400x788-modified.png");
|
||||
|
||||
if (!Beans.isDesignTime())
|
||||
{
|
||||
model.addPropertyChangeListener(CarouselPreviewModel.SELECTED_GAME, e -> reloadScreens());
|
||||
//trigger once at startup
|
||||
reloadScreens();
|
||||
}
|
||||
}
|
||||
|
||||
private void reloadScreens()
|
||||
{
|
||||
String filename = model.getSelectedGame().getScreen1();
|
||||
BufferedImage image = null;
|
||||
if (!filename.isEmpty())
|
||||
{
|
||||
File imagefile = new File("./screens/" + filename);
|
||||
try
|
||||
{
|
||||
image = ImageIO.read(imagefile);
|
||||
Image newImage = image.getScaledInstance(694, 401, Image.SCALE_SMOOTH);
|
||||
getScreenshotLabel().setIcon(new ImageIcon(newImage));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
getScreenshotLabel().setIcon(null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
getScreenshotLabel().setIcon(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private Image background;
|
||||
private JLabel lblNewLabel;
|
||||
private JLabel screenShotLabel;
|
||||
private TextPanel textPanel;
|
||||
private CoverPanel coverPanel;
|
||||
|
@ -72,16 +120,16 @@ public class BackgroundPanel extends JPanel {
|
|||
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));
|
||||
|
||||
// Image image = new ImageIcon(getClass().getResource(selectedGame.getScreen1())).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();
|
||||
textPanel = new TextPanel(model);
|
||||
}
|
||||
return textPanel;
|
||||
}
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package se.lantz.gui.carousel;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.beans.Beans;
|
||||
|
||||
import se.lantz.gui.BaseDialog;
|
||||
import se.lantz.model.MainViewModel;
|
||||
|
||||
public class CarouselPreviewDialog extends BaseDialog
|
||||
{
|
||||
private BackgroundPanel panel;
|
||||
private MainViewModel uiModel;
|
||||
|
||||
public CarouselPreviewDialog(final Frame owner, final MainViewModel uiModel)
|
||||
{
|
||||
super(owner);
|
||||
this.uiModel = uiModel;
|
||||
addContent(getBackgroundPanel());
|
||||
getOkButton().setPreferredSize(null);
|
||||
getOkButton().setText("Close");
|
||||
getCancelButton().setVisible(false);
|
||||
this.setPreferredSize(new Dimension(1400, 802));
|
||||
this.setResizable(false);
|
||||
this.setModal(false);
|
||||
if (!Beans.isDesignTime())
|
||||
{
|
||||
uiModel.addPropertyChangeListener("selectedGamelistView", e -> modelChanged());
|
||||
//trigger once at startup
|
||||
modelChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void modelChanged()
|
||||
{
|
||||
setTitle("Carousel preview - " + uiModel.getSelectedGameView().getName());
|
||||
}
|
||||
|
||||
private BackgroundPanel getBackgroundPanel()
|
||||
{
|
||||
if (panel == null)
|
||||
{
|
||||
panel = new BackgroundPanel(uiModel);
|
||||
}
|
||||
return panel;
|
||||
}
|
||||
}
|
|
@ -23,12 +23,18 @@ public class CoverPanel extends JPanel
|
|||
{
|
||||
private JPanel panel;
|
||||
private JScrollPane scrollPane;
|
||||
private JLabel test1Label;
|
||||
|
||||
int scrollingTimerIndex = 0;
|
||||
boolean scrolingStopped = true;
|
||||
boolean scrollDirectionRight = true;
|
||||
|
||||
private ActionListener timerListener = e -> scrollFromTimer();
|
||||
|
||||
private Timer scrolingTimer = new Timer(10, timerListener);
|
||||
|
||||
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 };
|
||||
|
@ -73,37 +79,26 @@ public class CoverPanel extends JPanel
|
|||
scrollOneGame(false);
|
||||
}
|
||||
});
|
||||
panel.setBackground(new Color(138, 137, 138));
|
||||
}
|
||||
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;
|
||||
int currentScrollValue = scrollPane.getHorizontalScrollBar().getValue();
|
||||
int newScrollValue = scrollDirectionRight ? currentScrollValue + 32 : currentScrollValue - 32;
|
||||
//Scroll
|
||||
scrollPane.getHorizontalScrollBar().setValue(valueToScroll);
|
||||
test++;
|
||||
if (test > 4)
|
||||
scrollPane.getHorizontalScrollBar().setValue(newScrollValue);
|
||||
scrollingTimerIndex++;
|
||||
if (scrollingTimerIndex > 5)
|
||||
{
|
||||
int lastScrollValue = scrollDirectionRight
|
||||
? scrollPane.getHorizontalScrollBar().getValue() + 10
|
||||
: scrollPane.getHorizontalScrollBar().getValue() - 10;
|
||||
//Scroll one last time
|
||||
int lastScrollValue = scrollDirectionRight ? currentScrollValue + 10 : currentScrollValue - 10;
|
||||
scrollPane.getHorizontalScrollBar().setValue(lastScrollValue);
|
||||
test = 0;
|
||||
javaTimer.stop();
|
||||
stopped = true;
|
||||
scrollingTimerIndex = 0;
|
||||
scrolingTimer.stop();
|
||||
scrolingStopped = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,14 +113,12 @@ public class CoverPanel extends JPanel
|
|||
scrollPane.getHorizontalScrollBar().setUnitIncrement(10);
|
||||
scrollPane.getHorizontalScrollBar().setBlockIncrement(10);
|
||||
|
||||
//Remove all previously registered mouse wheel listeners to not interfere
|
||||
for (MouseWheelListener listener : scrollPane.getMouseWheelListeners())
|
||||
{
|
||||
scrollPane.removeMouseWheelListener(listener);
|
||||
}
|
||||
|
||||
scrollPane.addMouseWheelListener(a -> {
|
||||
scrollOneGame(a.getWheelRotation() > 0);
|
||||
});
|
||||
scrollPane.addMouseWheelListener(a -> scrollOneGame(a.getWheelRotation() > 0));
|
||||
}
|
||||
return scrollPane;
|
||||
}
|
||||
|
@ -150,16 +143,18 @@ public class CoverPanel extends JPanel
|
|||
JLabel label = new JLabel("Label");
|
||||
label.setBorder(new LineBorder(new Color(0, 0, 0)));
|
||||
label.setPreferredSize(new Dimension(125, 175));
|
||||
// label.setBackground(Color.red);
|
||||
// label.setOpaque(true);
|
||||
return label;
|
||||
}
|
||||
|
||||
private void scrollOneGame(boolean right)
|
||||
{
|
||||
if (stopped)
|
||||
if (scrolingStopped)
|
||||
{
|
||||
scrollDirectionRight = right;
|
||||
stopped = false;
|
||||
javaTimer.start();
|
||||
scrolingStopped = false;
|
||||
scrolingTimer.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@ import java.awt.GridBagConstraints;
|
|||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.LayoutManager;
|
||||
import java.beans.Beans;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
@ -16,6 +19,9 @@ import javax.swing.text.MutableAttributeSet;
|
|||
import javax.swing.text.SimpleAttributeSet;
|
||||
import javax.swing.text.StyleConstants;
|
||||
|
||||
import se.lantz.model.carousel.CarouselPreviewModel;
|
||||
import se.lantz.model.data.GameDetails;
|
||||
|
||||
public class TextPanel extends JPanel
|
||||
{
|
||||
private JLabel titleLabel;
|
||||
|
@ -24,11 +30,14 @@ public class TextPanel extends JPanel
|
|||
private JLabel composerLabel;
|
||||
private JLabel genreLabel;
|
||||
private JLabel yearLabel;
|
||||
private CarouselPreviewModel model;
|
||||
|
||||
Map<String, String> genreMap = new HashMap<>();
|
||||
|
||||
public TextPanel()
|
||||
public TextPanel(final CarouselPreviewModel model)
|
||||
{
|
||||
this.model = model;
|
||||
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);
|
||||
|
@ -48,7 +57,7 @@ public class TextPanel extends JPanel
|
|||
gbc_textArea.fill = GridBagConstraints.BOTH;
|
||||
gbc_textArea.gridx = 0;
|
||||
gbc_textArea.gridy = 1;
|
||||
add(getTextArea(), gbc_textArea);
|
||||
add(getTextPane(), gbc_textArea);
|
||||
GridBagConstraints gbc_authorLabel = new GridBagConstraints();
|
||||
gbc_authorLabel.gridwidth = 2;
|
||||
gbc_authorLabel.insets = new Insets(6, 145, 0, 0);
|
||||
|
@ -77,8 +86,40 @@ public class TextPanel extends JPanel
|
|||
gbc_yearLabel.gridx = 1;
|
||||
gbc_yearLabel.gridy = 4;
|
||||
add(getYearLabel(), gbc_yearLabel);
|
||||
// TODO Auto-generated constructor stub
|
||||
if (!Beans.isDesignTime())
|
||||
{
|
||||
model.addPropertyChangeListener(CarouselPreviewModel.SELECTED_GAME, e -> selectedGameChanged());
|
||||
//trigger once at startup
|
||||
selectedGameChanged();
|
||||
}
|
||||
|
||||
//TODO Centralize this. look at GenreComboBox
|
||||
genreMap.put("", "----");
|
||||
genreMap.put("adventure", "Adventure");
|
||||
genreMap.put("driving", "Driving");
|
||||
genreMap.put("maze", "Maze");
|
||||
genreMap.put("platform", "Platform");
|
||||
genreMap.put("programming", "Programming");
|
||||
genreMap.put("puzzle", "Puzzle");
|
||||
genreMap.put("shoot", "Shoot'em up");
|
||||
genreMap.put("simulation", "Simulation");
|
||||
genreMap.put("sport", "Sport");
|
||||
}
|
||||
|
||||
private void selectedGameChanged()
|
||||
{
|
||||
GameDetails selectedGame = model.getSelectedGame();
|
||||
if (selectedGame != null)
|
||||
{
|
||||
getTitleLabel().setText(selectedGame.getTitle());
|
||||
getTextPane().setText(selectedGame.getDescription());
|
||||
getAuthorLabel().setText(selectedGame.getAuthor().isEmpty() ? " " : selectedGame.getAuthor());
|
||||
getComposerLabel().setText(selectedGame.getComposer().isEmpty() ? " " : selectedGame.getComposer());
|
||||
getGenreLabel().setText(genreMap.get(selectedGame.getGenre()));
|
||||
getYearLabel().setText(selectedGame.getYear() + "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public TextPanel(LayoutManager layout)
|
||||
{
|
||||
|
@ -103,19 +144,17 @@ public class TextPanel extends JPanel
|
|||
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()
|
||||
private JTextPane getTextPane()
|
||||
{
|
||||
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);
|
||||
|
@ -124,6 +163,8 @@ public class TextPanel extends JPanel
|
|||
textPane
|
||||
.setText(text512);
|
||||
changeLineSpacing(textPane, -0.12f, true);
|
||||
textPane.setEditable(false);
|
||||
textPane.setFocusable(false);
|
||||
textPane.setPreferredSize(new Dimension(100, 275));
|
||||
}
|
||||
return textPane;
|
||||
|
|
|
@ -349,6 +349,16 @@ public class MainViewModel extends AbstractModel
|
|||
List<GameListData> gamesList = dbConnector.fetchGamesByView(gameView);
|
||||
return readGameDetailsForExport(worker, gamesList);
|
||||
}
|
||||
|
||||
public List<GameDetails> readGameDetailsForCarouselPreview()
|
||||
{
|
||||
List<GameDetails> returnList = new ArrayList<>();
|
||||
for (GameListData game : dbConnector.fetchGamesByView(getSelectedGameView()))
|
||||
{
|
||||
returnList.add(dbConnector.getGameDetails(game.getGameId()));
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
public void exportGameInfoFile(GameDetails gameDetails, File targetDir, PublishWorker worker, boolean fileLoader)
|
||||
{
|
||||
|
@ -502,6 +512,7 @@ public class MainViewModel extends AbstractModel
|
|||
}
|
||||
}
|
||||
this.disableChangeNotification(false);
|
||||
this.notifyChange("selectedGamelistView", null, null);
|
||||
logger.debug("...done.");
|
||||
}
|
||||
|
||||
|
@ -1167,4 +1178,9 @@ public class MainViewModel extends AbstractModel
|
|||
g.drawString(title, imgWidth / 2 - (int) textWidth / 2, imgHeight / 2 + (int) textHeight / 2);
|
||||
g.dispose();
|
||||
}
|
||||
|
||||
public GameDetails getCurrentGameDetails()
|
||||
{
|
||||
return this.currentGameDetails;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package se.lantz.model.carousel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import se.lantz.model.AbstractModel;
|
||||
import se.lantz.model.MainViewModel;
|
||||
import se.lantz.model.data.GameDetails;
|
||||
|
||||
public class CarouselPreviewModel extends AbstractModel
|
||||
{
|
||||
public static final String SELECTED_GAME = "selectedGame";
|
||||
public static final String RELOAD_CAROUSEL = "reloadCarousel";
|
||||
private MainViewModel mainModel;
|
||||
private List<GameDetails> dataList = new ArrayList<>();
|
||||
|
||||
private GameDetails selectedGame = null;
|
||||
|
||||
public CarouselPreviewModel(MainViewModel mainModel)
|
||||
{
|
||||
this.mainModel = mainModel;
|
||||
mainModel.addPropertyChangeListener("selectedGamelistView", e -> reloadCarousel());
|
||||
mainModel.addPropertyChangeListener("gameSelected", e -> setSelectedGame(mainModel.getCurrentGameDetails()));
|
||||
dataList = mainModel.readGameDetailsForCarouselPreview();
|
||||
//Just to start with something
|
||||
selectedGame = dataList.get(0);
|
||||
}
|
||||
|
||||
private void reloadCarousel()
|
||||
{
|
||||
this.dataList = mainModel.readGameDetailsForCarouselPreview();
|
||||
this.notifyChange(RELOAD_CAROUSEL, null, null);
|
||||
}
|
||||
|
||||
public List<GameDetails> getGameDetails()
|
||||
{
|
||||
return dataList;
|
||||
}
|
||||
|
||||
public GameDetails getSelectedGame()
|
||||
{
|
||||
return selectedGame;
|
||||
}
|
||||
|
||||
public void setSelectedGame(GameDetails selectedGame)
|
||||
{
|
||||
this.selectedGame = selectedGame;
|
||||
this.notifyChange(SELECTED_GAME, null, null);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue