feat: adds 4 new favorite views, color coded and toggleable with menu options
CTRL+F1-F5 toggles favorites for the different lists.
This commit is contained in:
parent
1640b8d7b8
commit
6a057a7cb4
|
@ -1005,9 +1005,9 @@ public class DbConnector
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleFavorite(String gameId, int currentFavoriteValue)
|
public void toggleFavorite(String gameId, int currentFavoriteValue, int newFavorite)
|
||||||
{
|
{
|
||||||
int newValue = currentFavoriteValue == 0 ? 1 : 0;
|
int newValue = currentFavoriteValue == newFavorite ? 0: newFavorite;
|
||||||
String sql = "UPDATE gameinfo SET Favorite = " + newValue + " WHERE rowId = " + gameId + ";";
|
String sql = "UPDATE gameinfo SET Favorite = " + newValue + " WHERE rowId = " + gameId + ";";
|
||||||
try (Connection conn = this.connect(); PreparedStatement favoritestmt = conn.prepareStatement(sql))
|
try (Connection conn = this.connect(); PreparedStatement favoritestmt = conn.prepareStatement(sql))
|
||||||
{
|
{
|
||||||
|
@ -1020,9 +1020,9 @@ public class DbConnector
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearFavorites()
|
public void clearFavorites(int favoriteNumber)
|
||||||
{
|
{
|
||||||
String sql = "UPDATE gameinfo SET Favorite = 0 where Favorite = 1;";
|
String sql = "UPDATE gameinfo SET Favorite = 0 where Favorite = " + favoriteNumber + ";";
|
||||||
try (Connection conn = this.connect(); PreparedStatement favoritestmt = conn.prepareStatement(sql))
|
try (Connection conn = this.connect(); PreparedStatement favoritestmt = conn.prepareStatement(sql))
|
||||||
{
|
{
|
||||||
int value = favoritestmt.executeUpdate();
|
int value = favoritestmt.executeUpdate();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package se.lantz.gui;
|
package se.lantz.gui;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
|
||||||
|
@ -7,11 +8,28 @@ import javax.swing.DefaultListCellRenderer;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
|
|
||||||
import se.lantz.model.data.GameListData;
|
import se.lantz.model.data.GameListData;
|
||||||
|
import se.lantz.model.data.GameView;
|
||||||
|
|
||||||
public class GameListDataRenderer extends DefaultListCellRenderer
|
public class GameListDataRenderer extends DefaultListCellRenderer
|
||||||
{
|
{
|
||||||
|
private Color fav1Color = Color.BLACK;
|
||||||
|
private Color fav1ColorSelected = Color.WHITE;
|
||||||
|
//Orange
|
||||||
|
private Color fav2Color = new Color(255, 106, 0);
|
||||||
|
private Color fav2ColorSelected = new Color(255, 163, 132);
|
||||||
|
//Blue
|
||||||
|
private Color fav3Color = new Color(0, 38, 255);
|
||||||
|
private Color fav3ColorSelected = new Color(186, 202, 255);
|
||||||
|
//Red
|
||||||
|
private Color fav4Color = Color.RED;
|
||||||
|
private Color fav4ColorSelected = Color.PINK;
|
||||||
|
//Green
|
||||||
|
private Color fav5Color = Color.GREEN.darker();
|
||||||
|
private Color fav5ColorSelected = Color.GREEN;
|
||||||
|
|
||||||
private final Font bold;
|
private final Font bold;
|
||||||
private final Font plain;
|
private final Font plain;
|
||||||
|
|
||||||
public GameListDataRenderer()
|
public GameListDataRenderer()
|
||||||
{
|
{
|
||||||
this.plain = getFont().deriveFont(Font.PLAIN);
|
this.plain = getFont().deriveFont(Font.PLAIN);
|
||||||
|
@ -25,16 +43,85 @@ public class GameListDataRenderer extends DefaultListCellRenderer
|
||||||
boolean isSelected,
|
boolean isSelected,
|
||||||
boolean cellHasFocus)
|
boolean cellHasFocus)
|
||||||
{
|
{
|
||||||
Component listCellRendererComponent = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
Component listCellRendererComponent =
|
||||||
|
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||||
|
if (value instanceof GameListData)
|
||||||
|
{
|
||||||
|
handleGameListData(value, isSelected);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
handleGameListView(value, isSelected);
|
||||||
|
}
|
||||||
|
return listCellRendererComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleGameListData(Object value, boolean isSelected)
|
||||||
|
{
|
||||||
GameListData listData = (GameListData) value;
|
GameListData listData = (GameListData) value;
|
||||||
if (listData.isFavorite())
|
if (listData.isFavorite())
|
||||||
{
|
{
|
||||||
this.setFont(bold);
|
this.setFont(bold);
|
||||||
|
|
||||||
|
switch (listData.getFavoriteNumber())
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
this.setForeground(isSelected ? fav1ColorSelected : fav1Color);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
this.setForeground(isSelected ? fav2ColorSelected : fav2Color);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
this.setForeground(isSelected ? fav3ColorSelected : fav3Color);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
this.setForeground(isSelected ? fav4ColorSelected : fav4Color);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
this.setForeground(isSelected ? fav5ColorSelected : fav5Color);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.setFont(plain);
|
this.setFont(plain);
|
||||||
}
|
}
|
||||||
return listCellRendererComponent;
|
}
|
||||||
|
|
||||||
|
private void handleGameListView(Object value, boolean isSelected)
|
||||||
|
{
|
||||||
|
GameView view = (GameView) value;
|
||||||
|
if (view.getGameViewId() == GameView.FAVORITES_ID)
|
||||||
|
{
|
||||||
|
this.setFont(bold);
|
||||||
|
this.setForeground(isSelected ? fav1ColorSelected : fav1Color);
|
||||||
|
}
|
||||||
|
else if (view.getGameViewId() == GameView.FAVORITES_2_ID)
|
||||||
|
{
|
||||||
|
this.setFont(bold);
|
||||||
|
this.setForeground(isSelected ? fav2ColorSelected : fav2Color);
|
||||||
|
}
|
||||||
|
else if (view.getGameViewId() == GameView.FAVORITES_3_ID)
|
||||||
|
{
|
||||||
|
this.setFont(bold);
|
||||||
|
this.setForeground(isSelected ? fav3ColorSelected : fav3Color);
|
||||||
|
}
|
||||||
|
else if (view.getGameViewId() == GameView.FAVORITES_4_ID)
|
||||||
|
{
|
||||||
|
this.setFont(bold);
|
||||||
|
this.setForeground(isSelected ? fav4ColorSelected : fav4Color);
|
||||||
|
}
|
||||||
|
else if (view.getGameViewId() == GameView.FAVORITES_5_ID)
|
||||||
|
{
|
||||||
|
this.setFont(bold);
|
||||||
|
this.setForeground(isSelected ? fav5ColorSelected : fav5Color);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.setFont(plain);
|
||||||
|
this.setForeground(isSelected ? fav1ColorSelected : fav1Color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import javax.swing.JPopupMenu;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.ListSelectionModel;
|
import javax.swing.ListSelectionModel;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.ToolTipManager;
|
||||||
|
|
||||||
import se.lantz.gui.gameview.GameViewManager;
|
import se.lantz.gui.gameview.GameViewManager;
|
||||||
import se.lantz.model.MainViewModel;
|
import se.lantz.model.MainViewModel;
|
||||||
|
@ -166,6 +167,7 @@ public class ListPanel extends JPanel
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
listViewComboBox.setModel(uiModel.getGameViewModel());
|
listViewComboBox.setModel(uiModel.getGameViewModel());
|
||||||
|
listViewComboBox.setRenderer(new GameListDataRenderer());
|
||||||
}
|
}
|
||||||
return listViewComboBox;
|
return listViewComboBox;
|
||||||
}
|
}
|
||||||
|
@ -401,6 +403,8 @@ public class ListPanel extends JPanel
|
||||||
});
|
});
|
||||||
list.setModel(uiModel.getGameListModel());
|
list.setModel(uiModel.getGameListModel());
|
||||||
list.setCellRenderer(new GameListDataRenderer());
|
list.setCellRenderer(new GameListDataRenderer());
|
||||||
|
//Remove from tootlipManager to avoid throwing a nullpointer for CTRL+F1
|
||||||
|
ToolTipManager.sharedInstance().unregisterComponent(list);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -447,6 +451,56 @@ public class ListPanel extends JPanel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void toggleFavorite2()
|
||||||
|
{
|
||||||
|
if (!uiModel.isDataChanged())
|
||||||
|
{
|
||||||
|
for (GameListData glData : list.getSelectedValuesList())
|
||||||
|
{
|
||||||
|
uiModel.toggleFavorite2(glData);
|
||||||
|
}
|
||||||
|
mainPanel.repaintAfterModifications();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleFavorite3()
|
||||||
|
{
|
||||||
|
if (!uiModel.isDataChanged())
|
||||||
|
{
|
||||||
|
for (GameListData glData : list.getSelectedValuesList())
|
||||||
|
{
|
||||||
|
uiModel.toggleFavorite3(glData);
|
||||||
|
}
|
||||||
|
mainPanel.repaintAfterModifications();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void toggleFavorite4()
|
||||||
|
{
|
||||||
|
if (!uiModel.isDataChanged())
|
||||||
|
{
|
||||||
|
for (GameListData glData : list.getSelectedValuesList())
|
||||||
|
{
|
||||||
|
uiModel.toggleFavorite4(glData);
|
||||||
|
}
|
||||||
|
mainPanel.repaintAfterModifications();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void toggleFavorite5()
|
||||||
|
{
|
||||||
|
if (!uiModel.isDataChanged())
|
||||||
|
{
|
||||||
|
for (GameListData glData : list.getSelectedValuesList())
|
||||||
|
{
|
||||||
|
uiModel.toggleFavorite5(glData);
|
||||||
|
}
|
||||||
|
mainPanel.repaintAfterModifications();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void reloadCurrentGameView()
|
public void reloadCurrentGameView()
|
||||||
{
|
{
|
||||||
GameListData selectedData = getList().getSelectedValue();
|
GameListData selectedData = getList().getSelectedValue();
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
package se.lantz.gui;
|
package se.lantz.gui;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.event.InputEvent;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.swing.InputMap;
|
||||||
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JSplitPane;
|
import javax.swing.JSplitPane;
|
||||||
|
import javax.swing.KeyStroke;
|
||||||
|
import javax.swing.ToolTipManager;
|
||||||
|
|
||||||
import se.lantz.model.MainViewModel;
|
import se.lantz.model.MainViewModel;
|
||||||
import se.lantz.model.data.GameListData;
|
import se.lantz.model.data.GameListData;
|
||||||
|
@ -172,6 +178,26 @@ public class MainPanel extends JPanel
|
||||||
getListPanel().toggleFavorite();
|
getListPanel().toggleFavorite();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void toggleFavorite2()
|
||||||
|
{
|
||||||
|
getListPanel().toggleFavorite2();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleFavorite3()
|
||||||
|
{
|
||||||
|
getListPanel().toggleFavorite3();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleFavorite4()
|
||||||
|
{
|
||||||
|
getListPanel().toggleFavorite4();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleFavorite5()
|
||||||
|
{
|
||||||
|
getListPanel().toggleFavorite5();
|
||||||
|
}
|
||||||
|
|
||||||
public void runCurrentGame()
|
public void runCurrentGame()
|
||||||
{
|
{
|
||||||
if (getListPanel().isSingleGameSelected() && getListPanel().getSelectedIndexInList() > -1)
|
if (getListPanel().isSingleGameSelected() && getListPanel().getSelectedIndexInList() > -1)
|
||||||
|
|
|
@ -7,10 +7,8 @@ import javax.swing.ImageIcon;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JMenu;
|
import javax.swing.JMenu;
|
||||||
import javax.swing.JMenuBar;
|
import javax.swing.JMenuBar;
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import javax.swing.WindowConstants;
|
import javax.swing.WindowConstants;
|
||||||
|
|
||||||
import se.lantz.gui.scraper.MobyGamesOptionsPanel;
|
|
||||||
import se.lantz.model.MainViewModel;
|
import se.lantz.model.MainViewModel;
|
||||||
import se.lantz.util.FileManager;
|
import se.lantz.util.FileManager;
|
||||||
|
|
||||||
|
@ -40,11 +38,11 @@ public final class MainWindow extends JFrame
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isInitialized() {
|
public static boolean isInitialized()
|
||||||
|
{
|
||||||
return instance != null;
|
return instance != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private MainWindow()
|
private MainWindow()
|
||||||
{
|
{
|
||||||
this.setIconImage(new ImageIcon(getClass().getResource("/se/lantz/FrameIcon.png")).getImage());
|
this.setIconImage(new ImageIcon(getClass().getResource("/se/lantz/FrameIcon.png")).getImage());
|
||||||
|
@ -62,7 +60,6 @@ public final class MainWindow extends JFrame
|
||||||
});
|
});
|
||||||
getContentPane().add(getMainPanel(), BorderLayout.CENTER);
|
getContentPane().add(getMainPanel(), BorderLayout.CENTER);
|
||||||
|
|
||||||
|
|
||||||
this.setJMenuBar(getMainMenuBar());
|
this.setJMenuBar(getMainMenuBar());
|
||||||
|
|
||||||
//Update title with version if available
|
//Update title with version if available
|
||||||
|
|
|
@ -59,8 +59,16 @@ public class MenuManager
|
||||||
private JMenuItem exportItem;
|
private JMenuItem exportItem;
|
||||||
private JMenuItem refreshItem;
|
private JMenuItem refreshItem;
|
||||||
|
|
||||||
private JMenuItem toggleFavoriteItem;
|
private JMenuItem toggleFavorite1Item;
|
||||||
private JMenuItem clearFavoritesItem;
|
private JMenuItem toggleFavorite2Item;
|
||||||
|
private JMenuItem toggleFavorite3Item;
|
||||||
|
private JMenuItem toggleFavorite4Item;
|
||||||
|
private JMenuItem toggleFavorite5Item;
|
||||||
|
private JMenuItem clearFavorites1Item;
|
||||||
|
private JMenuItem clearFavorites2Item;
|
||||||
|
private JMenuItem clearFavorites3Item;
|
||||||
|
private JMenuItem clearFavorites4Item;
|
||||||
|
private JMenuItem clearFavorites5Item;
|
||||||
|
|
||||||
private JMenuItem backupDbItem;
|
private JMenuItem backupDbItem;
|
||||||
private JMenuItem restoreDbItem;
|
private JMenuItem restoreDbItem;
|
||||||
|
@ -118,8 +126,17 @@ public class MenuManager
|
||||||
fileMenu.addSeparator();
|
fileMenu.addSeparator();
|
||||||
fileMenu.add(getExitItem());
|
fileMenu.add(getExitItem());
|
||||||
editMenu = new JMenu("Edit");
|
editMenu = new JMenu("Edit");
|
||||||
editMenu.add(getToggleFavoriteItem());
|
editMenu.add(getToggleFavorite1Item());
|
||||||
editMenu.add(getClearFavoritesItem());
|
editMenu.add(getToggleFavorite2Item());
|
||||||
|
editMenu.add(getToggleFavorite3Item());
|
||||||
|
editMenu.add(getToggleFavorite4Item());
|
||||||
|
editMenu.add(getToggleFavorite5Item());
|
||||||
|
editMenu.addSeparator();
|
||||||
|
editMenu.add(getClearFavorites1Item());
|
||||||
|
editMenu.add(getClearFavorites2Item());
|
||||||
|
editMenu.add(getClearFavorites3Item());
|
||||||
|
editMenu.add(getClearFavorites4Item());
|
||||||
|
editMenu.add(getClearFavorites5Item());
|
||||||
toolsMenu = new JMenu("Tools");
|
toolsMenu = new JMenu("Tools");
|
||||||
toolsMenu.add(getBackupDbItem());
|
toolsMenu.add(getBackupDbItem());
|
||||||
toolsMenu.add(getRestoreDbItem());
|
toolsMenu.add(getRestoreDbItem());
|
||||||
|
@ -142,7 +159,7 @@ public class MenuManager
|
||||||
importCarouselItem.setEnabled(okToEnable);
|
importCarouselItem.setEnabled(okToEnable);
|
||||||
importGamebaseItem.setEnabled(okToEnable);
|
importGamebaseItem.setEnabled(okToEnable);
|
||||||
exportItem.setEnabled(okToEnable);
|
exportItem.setEnabled(okToEnable);
|
||||||
toggleFavoriteItem.setEnabled(okToEnable);
|
toggleFavorite1Item.setEnabled(okToEnable);
|
||||||
runGameItem.setEnabled(!uiModel.getInfoModel().getGamesFile().isEmpty());
|
runGameItem.setEnabled(!uiModel.getInfoModel().getGamesFile().isEmpty());
|
||||||
refreshItem.setEnabled(okToEnable);
|
refreshItem.setEnabled(okToEnable);
|
||||||
});
|
});
|
||||||
|
@ -276,26 +293,109 @@ public class MenuManager
|
||||||
return exitItem;
|
return exitItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JMenuItem getToggleFavoriteItem()
|
private JMenuItem getToggleFavorite1Item()
|
||||||
{
|
{
|
||||||
toggleFavoriteItem = new JMenuItem("Add/remove from favorites");
|
toggleFavorite1Item = new JMenuItem("Add/remove from favorites 1");
|
||||||
KeyStroke keyStrokeToToggleFav = KeyStroke.getKeyStroke(KeyEvent.VK_F12, InputEvent.CTRL_DOWN_MASK);
|
KeyStroke keyStrokeToToggleFav = KeyStroke.getKeyStroke(KeyEvent.VK_F1, InputEvent.CTRL_DOWN_MASK);
|
||||||
toggleFavoriteItem.setAccelerator(keyStrokeToToggleFav);
|
toggleFavorite1Item.setAccelerator(keyStrokeToToggleFav);
|
||||||
toggleFavoriteItem.setMnemonic('F');
|
toggleFavorite1Item.setMnemonic('1');
|
||||||
toggleFavoriteItem.addActionListener(e -> {
|
toggleFavorite1Item.addActionListener(e -> {
|
||||||
mainWindow.getMainPanel().toggleFavorite();
|
mainWindow.getMainPanel().toggleFavorite();
|
||||||
});
|
});
|
||||||
return toggleFavoriteItem;
|
return toggleFavorite1Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JMenuItem getClearFavoritesItem()
|
private JMenuItem getToggleFavorite2Item()
|
||||||
{
|
{
|
||||||
clearFavoritesItem = new JMenuItem("Clear all favorites");
|
toggleFavorite2Item = new JMenuItem("Add/remove from favorites 2");
|
||||||
clearFavoritesItem.setMnemonic('C');
|
KeyStroke keyStrokeToToggleFav = KeyStroke.getKeyStroke(KeyEvent.VK_F2, InputEvent.CTRL_DOWN_MASK);
|
||||||
clearFavoritesItem.addActionListener(e -> {
|
toggleFavorite2Item.setAccelerator(keyStrokeToToggleFav);
|
||||||
|
toggleFavorite2Item.setMnemonic('2');
|
||||||
|
toggleFavorite2Item.addActionListener(e -> {
|
||||||
|
mainWindow.getMainPanel().toggleFavorite2();
|
||||||
|
});
|
||||||
|
return toggleFavorite2Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JMenuItem getToggleFavorite3Item()
|
||||||
|
{
|
||||||
|
toggleFavorite3Item = new JMenuItem("Add/remove from favorites 3");
|
||||||
|
KeyStroke keyStrokeToToggleFav = KeyStroke.getKeyStroke(KeyEvent.VK_F3, InputEvent.CTRL_DOWN_MASK);
|
||||||
|
toggleFavorite3Item.setAccelerator(keyStrokeToToggleFav);
|
||||||
|
toggleFavorite3Item.setMnemonic('3');
|
||||||
|
toggleFavorite3Item.addActionListener(e -> {
|
||||||
|
mainWindow.getMainPanel().toggleFavorite3();
|
||||||
|
});
|
||||||
|
return toggleFavorite3Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JMenuItem getToggleFavorite4Item()
|
||||||
|
{
|
||||||
|
toggleFavorite4Item = new JMenuItem("Add/remove from favorites 4");
|
||||||
|
KeyStroke keyStrokeToToggleFav = KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.CTRL_DOWN_MASK);
|
||||||
|
toggleFavorite4Item.setAccelerator(keyStrokeToToggleFav);
|
||||||
|
toggleFavorite4Item.setMnemonic('4');
|
||||||
|
toggleFavorite4Item.addActionListener(e -> {
|
||||||
|
mainWindow.getMainPanel().toggleFavorite4();
|
||||||
|
});
|
||||||
|
return toggleFavorite4Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JMenuItem getToggleFavorite5Item()
|
||||||
|
{
|
||||||
|
toggleFavorite5Item = new JMenuItem("Add/remove from favorites 5");
|
||||||
|
KeyStroke keyStrokeToToggleFav = KeyStroke.getKeyStroke(KeyEvent.VK_F5, InputEvent.CTRL_DOWN_MASK);
|
||||||
|
toggleFavorite5Item.setAccelerator(keyStrokeToToggleFav);
|
||||||
|
toggleFavorite5Item.setMnemonic('5');
|
||||||
|
toggleFavorite5Item.addActionListener(e -> {
|
||||||
|
mainWindow.getMainPanel().toggleFavorite5();
|
||||||
|
});
|
||||||
|
return toggleFavorite5Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JMenuItem getClearFavorites1Item()
|
||||||
|
{
|
||||||
|
clearFavorites1Item = new JMenuItem("Clear favorites 1");
|
||||||
|
clearFavorites1Item.addActionListener(e -> {
|
||||||
clearFavorites();
|
clearFavorites();
|
||||||
});
|
});
|
||||||
return clearFavoritesItem;
|
return clearFavorites1Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JMenuItem getClearFavorites2Item()
|
||||||
|
{
|
||||||
|
clearFavorites2Item = new JMenuItem("Clear favorites 2");
|
||||||
|
clearFavorites2Item.addActionListener(e -> {
|
||||||
|
clearFavorites2();
|
||||||
|
});
|
||||||
|
return clearFavorites2Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JMenuItem getClearFavorites3Item()
|
||||||
|
{
|
||||||
|
clearFavorites3Item = new JMenuItem("Clear favorites 3");
|
||||||
|
clearFavorites3Item.addActionListener(e -> {
|
||||||
|
clearFavorites3();
|
||||||
|
});
|
||||||
|
return clearFavorites3Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JMenuItem getClearFavorites4Item()
|
||||||
|
{
|
||||||
|
clearFavorites4Item = new JMenuItem("Clear favorites 4");
|
||||||
|
clearFavorites4Item.addActionListener(e -> {
|
||||||
|
clearFavorites4();
|
||||||
|
});
|
||||||
|
return clearFavorites4Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JMenuItem getClearFavorites5Item()
|
||||||
|
{
|
||||||
|
clearFavorites5Item = new JMenuItem("Clear favorites 5");
|
||||||
|
clearFavorites5Item.addActionListener(e -> {
|
||||||
|
clearFavorites5();
|
||||||
|
});
|
||||||
|
return clearFavorites5Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JMenuItem getBackupDbItem()
|
private JMenuItem getBackupDbItem()
|
||||||
|
@ -537,12 +637,56 @@ public class MenuManager
|
||||||
|
|
||||||
private void clearFavorites()
|
private void clearFavorites()
|
||||||
{
|
{
|
||||||
String message = "Are you sure you want to clear all games marked as favorites?";
|
String message = "Are you sure you want to clear all games marked as favorites 1?";
|
||||||
int option = JOptionPane.showConfirmDialog(MainWindow.getInstance()
|
int option = JOptionPane.showConfirmDialog(MainWindow.getInstance()
|
||||||
.getMainPanel(), message, "Clear all favorites", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
.getMainPanel(), message, "Clear all favorites 1", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||||
if (option == JOptionPane.YES_OPTION)
|
if (option == JOptionPane.YES_OPTION)
|
||||||
{
|
{
|
||||||
uiModel.clearFavorites();
|
uiModel.clearFavorites(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearFavorites2()
|
||||||
|
{
|
||||||
|
String message = "Are you sure you want to clear all games marked as favorites 2?";
|
||||||
|
int option = JOptionPane.showConfirmDialog(MainWindow.getInstance()
|
||||||
|
.getMainPanel(), message, "Clear all favorites 2", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||||
|
if (option == JOptionPane.YES_OPTION)
|
||||||
|
{
|
||||||
|
uiModel.clearFavorites(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearFavorites3()
|
||||||
|
{
|
||||||
|
String message = "Are you sure you want to clear all games marked as favorites 3?";
|
||||||
|
int option = JOptionPane.showConfirmDialog(MainWindow.getInstance()
|
||||||
|
.getMainPanel(), message, "Clear all favorites 3", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||||
|
if (option == JOptionPane.YES_OPTION)
|
||||||
|
{
|
||||||
|
uiModel.clearFavorites(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearFavorites4()
|
||||||
|
{
|
||||||
|
String message = "Are you sure you want to clear all games marked as favorites 4?";
|
||||||
|
int option = JOptionPane.showConfirmDialog(MainWindow.getInstance()
|
||||||
|
.getMainPanel(), message, "Clear all favorites 4", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||||
|
if (option == JOptionPane.YES_OPTION)
|
||||||
|
{
|
||||||
|
uiModel.clearFavorites(4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearFavorites5()
|
||||||
|
{
|
||||||
|
String message = "Are you sure you want to clear all games marked as favorites 5?";
|
||||||
|
int option = JOptionPane.showConfirmDialog(MainWindow.getInstance()
|
||||||
|
.getMainPanel(), message, "Clear all favorites 5", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||||
|
if (option == JOptionPane.YES_OPTION)
|
||||||
|
{
|
||||||
|
uiModel.clearFavorites(5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,16 @@ public class MainViewModel extends AbstractModel
|
||||||
private GameView selectedGameView;
|
private GameView selectedGameView;
|
||||||
private int allGamesCount = 0;
|
private int allGamesCount = 0;
|
||||||
private int favoritesCount = 0;
|
private int favoritesCount = 0;
|
||||||
|
private int favorites2Count = 0;
|
||||||
|
private int favorites3Count = 0;
|
||||||
|
private int favorites4Count = 0;
|
||||||
|
private int favorites5Count = 0;
|
||||||
private GameView allGameView;
|
private GameView allGameView;
|
||||||
private GameView favoritesView;
|
private GameView favoritesView;
|
||||||
|
private GameView favorites2View;
|
||||||
|
private GameView favorites3View;
|
||||||
|
private GameView favorites4View;
|
||||||
|
private GameView favorites5View;
|
||||||
|
|
||||||
private InfoModel infoModel = new InfoModel();
|
private InfoModel infoModel = new InfoModel();
|
||||||
private JoystickModel joy1Model = new JoystickModel(true);
|
private JoystickModel joy1Model = new JoystickModel(true);
|
||||||
|
@ -102,13 +110,33 @@ public class MainViewModel extends AbstractModel
|
||||||
allGameView.setSqlQuery("");
|
allGameView.setSqlQuery("");
|
||||||
selectedGameView = allGameView;
|
selectedGameView = allGameView;
|
||||||
|
|
||||||
//Add favorites view
|
//Add favorites views
|
||||||
favoritesView = new GameView(GameView.FAVORITES_ID);
|
favoritesView = new GameView(GameView.FAVORITES_ID);
|
||||||
favoritesView.setName("Favorites");
|
favoritesView.setName("Favorites 1");
|
||||||
favoritesView.setSqlQuery(" WHERE Favorite = 1");
|
favoritesView.setSqlQuery(" WHERE Favorite = 1");
|
||||||
|
|
||||||
|
favorites2View = new GameView(GameView.FAVORITES_2_ID);
|
||||||
|
favorites2View.setName("Favorites 2");
|
||||||
|
favorites2View.setSqlQuery(" WHERE Favorite = 2");
|
||||||
|
|
||||||
|
favorites3View = new GameView(GameView.FAVORITES_3_ID);
|
||||||
|
favorites3View.setName("Favorites 3");
|
||||||
|
favorites3View.setSqlQuery(" WHERE Favorite = 3");
|
||||||
|
|
||||||
|
favorites4View = new GameView(GameView.FAVORITES_4_ID);
|
||||||
|
favorites4View.setName("Favorites 4");
|
||||||
|
favorites4View.setSqlQuery(" WHERE Favorite = 4");
|
||||||
|
|
||||||
|
favorites5View = new GameView(GameView.FAVORITES_5_ID);
|
||||||
|
favorites5View.setName("Favorites 5");
|
||||||
|
favorites5View.setSqlQuery(" WHERE Favorite = 5");
|
||||||
|
|
||||||
gameViewModel.addElement(allGameView);
|
gameViewModel.addElement(allGameView);
|
||||||
gameViewModel.addElement(favoritesView);
|
gameViewModel.addElement(favoritesView);
|
||||||
|
gameViewModel.addElement(favorites2View);
|
||||||
|
gameViewModel.addElement(favorites3View);
|
||||||
|
gameViewModel.addElement(favorites4View);
|
||||||
|
gameViewModel.addElement(favorites5View);
|
||||||
|
|
||||||
List<GameView> gameViewList = dbConnector.loadGameViews();
|
List<GameView> gameViewList = dbConnector.loadGameViews();
|
||||||
Collections.sort(gameViewList);
|
Collections.sort(gameViewList);
|
||||||
|
@ -259,14 +287,41 @@ public class MainViewModel extends AbstractModel
|
||||||
this.allGamesCount = gamesList.size();
|
this.allGamesCount = gamesList.size();
|
||||||
//Update favorites count
|
//Update favorites count
|
||||||
favoritesCount = 0;
|
favoritesCount = 0;
|
||||||
|
favorites2Count = 0;
|
||||||
|
favorites3Count = 0;
|
||||||
|
favorites4Count = 0;
|
||||||
|
favorites5Count = 0;
|
||||||
for (GameListData gameListData : gamesList)
|
for (GameListData gameListData : gamesList)
|
||||||
{
|
{
|
||||||
if (gameListData.isFavorite())
|
if (gameListData.isFavorite())
|
||||||
{
|
{
|
||||||
|
switch (gameListData.getFavoriteNumber())
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
favoritesCount++;
|
favoritesCount++;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
favorites2Count++;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
favorites3Count++;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
favorites4Count++;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
favorites5Count++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
favoritesView.setGameCount(favoritesCount);
|
favoritesView.setGameCount(favoritesCount);
|
||||||
|
favorites2View.setGameCount(favorites2Count);
|
||||||
|
favorites3View.setGameCount(favorites3Count);
|
||||||
|
favorites4View.setGameCount(favorites4Count);
|
||||||
|
favorites5View.setGameCount(favorites5Count);
|
||||||
}
|
}
|
||||||
this.disableChangeNotification(false);
|
this.disableChangeNotification(false);
|
||||||
logger.debug("...done.");
|
logger.debug("...done.");
|
||||||
|
@ -391,6 +446,26 @@ public class MainViewModel extends AbstractModel
|
||||||
//Mark as favorites
|
//Mark as favorites
|
||||||
toggleFavorite(selectedData);
|
toggleFavorite(selectedData);
|
||||||
}
|
}
|
||||||
|
else if (getSelectedGameView().getGameViewId() == GameView.FAVORITES_2_ID)
|
||||||
|
{
|
||||||
|
//Mark as favorites
|
||||||
|
toggleFavorite2(selectedData);
|
||||||
|
}
|
||||||
|
else if (getSelectedGameView().getGameViewId() == GameView.FAVORITES_3_ID)
|
||||||
|
{
|
||||||
|
//Mark as favorites
|
||||||
|
toggleFavorite3(selectedData);
|
||||||
|
}
|
||||||
|
else if (getSelectedGameView().getGameViewId() == GameView.FAVORITES_4_ID)
|
||||||
|
{
|
||||||
|
//Mark as favorites
|
||||||
|
toggleFavorite4(selectedData);
|
||||||
|
}
|
||||||
|
else if (getSelectedGameView().getGameViewId() == GameView.FAVORITES_5_ID)
|
||||||
|
{
|
||||||
|
//Mark as favorites
|
||||||
|
toggleFavorite5(selectedData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -474,9 +549,9 @@ public class MainViewModel extends AbstractModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearFavorites()
|
public void clearFavorites(int number)
|
||||||
{
|
{
|
||||||
dbConnector.clearFavorites();
|
dbConnector.clearFavorites(number);
|
||||||
//Reload the current view
|
//Reload the current view
|
||||||
reloadCurrentGameView();
|
reloadCurrentGameView();
|
||||||
}
|
}
|
||||||
|
@ -526,15 +601,41 @@ public class MainViewModel extends AbstractModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void reduceFavoriteCount(int previousFavorite)
|
||||||
|
{
|
||||||
|
switch (previousFavorite)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
favoritesView.setGameCount(--favoritesCount);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
favorites2View.setGameCount(--favorites2Count);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
favorites3View.setGameCount(--favorites3Count);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
favorites4View.setGameCount(--favorites4Count);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
favorites5View.setGameCount(--favorites5Count);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void toggleFavorite(GameListData data)
|
public void toggleFavorite(GameListData data)
|
||||||
{
|
{
|
||||||
if (data != null && !data.getGameId().isEmpty())
|
if (data != null && !data.getGameId().isEmpty())
|
||||||
{
|
{
|
||||||
dbConnector.toggleFavorite(data.getGameId(), data.getFavorite());
|
int previousFavorite = data.getFavorite();
|
||||||
|
dbConnector.toggleFavorite(data.getGameId(), previousFavorite, 1);
|
||||||
data.toggleFavorite();
|
data.toggleFavorite();
|
||||||
if (data.isFavorite())
|
if (data.isFavorite())
|
||||||
{
|
{
|
||||||
favoritesView.setGameCount(++favoritesCount);
|
favoritesView.setGameCount(++favoritesCount);
|
||||||
|
reduceFavoriteCount(previousFavorite);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -544,6 +645,86 @@ public class MainViewModel extends AbstractModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void toggleFavorite2(GameListData data)
|
||||||
|
{
|
||||||
|
if (data != null && !data.getGameId().isEmpty())
|
||||||
|
{
|
||||||
|
int previousFavorite = data.getFavorite();
|
||||||
|
dbConnector.toggleFavorite(data.getGameId(), previousFavorite, 2);
|
||||||
|
data.toggleFavorite2();
|
||||||
|
if (data.isFavorite())
|
||||||
|
{
|
||||||
|
favorites2View.setGameCount(++favorites2Count);
|
||||||
|
reduceFavoriteCount(previousFavorite);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
favorites2View.setGameCount(--favorites2Count);
|
||||||
|
}
|
||||||
|
gameListModel.notifyChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleFavorite3(GameListData data)
|
||||||
|
{
|
||||||
|
if (data != null && !data.getGameId().isEmpty())
|
||||||
|
{
|
||||||
|
int previousFavorite = data.getFavorite();
|
||||||
|
dbConnector.toggleFavorite(data.getGameId(), previousFavorite, 3);
|
||||||
|
data.toggleFavorite3();
|
||||||
|
if (data.isFavorite())
|
||||||
|
{
|
||||||
|
favorites3View.setGameCount(++favorites3Count);
|
||||||
|
reduceFavoriteCount(previousFavorite);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
favorites3View.setGameCount(--favorites3Count);
|
||||||
|
}
|
||||||
|
gameListModel.notifyChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleFavorite4(GameListData data)
|
||||||
|
{
|
||||||
|
if (data != null && !data.getGameId().isEmpty())
|
||||||
|
{
|
||||||
|
int previousFavorite = data.getFavorite();
|
||||||
|
dbConnector.toggleFavorite(data.getGameId(), previousFavorite, 4);
|
||||||
|
data.toggleFavorite4();
|
||||||
|
if (data.isFavorite())
|
||||||
|
{
|
||||||
|
favorites4View.setGameCount(++favorites4Count);
|
||||||
|
reduceFavoriteCount(previousFavorite);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
favorites4View.setGameCount(--favorites4Count);
|
||||||
|
}
|
||||||
|
gameListModel.notifyChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleFavorite5(GameListData data)
|
||||||
|
{
|
||||||
|
if (data != null && !data.getGameId().isEmpty())
|
||||||
|
{
|
||||||
|
int previousFavorite = data.getFavorite();
|
||||||
|
dbConnector.toggleFavorite(data.getGameId(), previousFavorite, 5);
|
||||||
|
data.toggleFavorite5();
|
||||||
|
if (data.isFavorite())
|
||||||
|
{
|
||||||
|
favorites5View.setGameCount(++favorites5Count);
|
||||||
|
reduceFavoriteCount(previousFavorite);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
favorites5View.setGameCount(--favorites5Count);
|
||||||
|
}
|
||||||
|
gameListModel.notifyChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void runGameInVice()
|
public void runGameInVice()
|
||||||
{
|
{
|
||||||
fileManager.runVice(true);
|
fileManager.runVice(true);
|
||||||
|
|
|
@ -41,13 +41,35 @@ public class GameListData implements Comparable
|
||||||
|
|
||||||
public void toggleFavorite()
|
public void toggleFavorite()
|
||||||
{
|
{
|
||||||
this.favorite = favorite == 0 ? 1 : 0;
|
this.favorite = favorite == 1 ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleFavorite2()
|
||||||
|
{
|
||||||
|
this.favorite = favorite == 2 ? 0 : 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleFavorite3()
|
||||||
|
{
|
||||||
|
this.favorite = favorite == 3 ? 0 : 3;
|
||||||
|
}
|
||||||
|
public void toggleFavorite4()
|
||||||
|
{
|
||||||
|
this.favorite = favorite == 4 ? 0 : 4;
|
||||||
|
}
|
||||||
|
public void toggleFavorite5()
|
||||||
|
{
|
||||||
|
this.favorite = favorite == 5 ? 0 : 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFavorite()
|
public boolean isFavorite()
|
||||||
{
|
{
|
||||||
//For now "1" means favorite and "0 means no favorite. Possible to add support for multiple favorite lists later on.
|
return favorite > 0;
|
||||||
return favorite == 1;
|
}
|
||||||
|
|
||||||
|
public int getFavoriteNumber()
|
||||||
|
{
|
||||||
|
return favorite;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFavorite(int favorite)
|
public void setFavorite(int favorite)
|
||||||
|
|
|
@ -10,6 +10,10 @@ public class GameView implements Comparable
|
||||||
{
|
{
|
||||||
public static final int ALL_GAMES_ID = -1;
|
public static final int ALL_GAMES_ID = -1;
|
||||||
public static final int FAVORITES_ID = -2;
|
public static final int FAVORITES_ID = -2;
|
||||||
|
public static final int FAVORITES_2_ID = -3;
|
||||||
|
public static final int FAVORITES_3_ID = -4;
|
||||||
|
public static final int FAVORITES_4_ID = -5;
|
||||||
|
public static final int FAVORITES_5_ID = -6;
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GameView.class);
|
private static final Logger logger = LoggerFactory.getLogger(GameView.class);
|
||||||
private String name = "";
|
private String name = "";
|
||||||
private List<ViewFilter> viewFilters = new ArrayList<>();
|
private List<ViewFilter> viewFilters = new ArrayList<>();
|
||||||
|
|
Loading…
Reference in New Issue