feat: adds support for multiple selection in the game list.
-Delete multiple games at once -Mark/unmark as favorite for multiple games at once.
This commit is contained in:
parent
a2f57dbbc7
commit
791715b51b
|
@ -12,7 +12,6 @@ import java.awt.event.KeyEvent;
|
|||
import java.awt.image.BufferedImage;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
|
@ -433,7 +432,7 @@ public class GameDetailsBackgroundPanel extends JPanel
|
|||
{
|
||||
try
|
||||
{
|
||||
Locale locale = new Locale.Builder().setLanguageTag(language).build();
|
||||
Locale locale = new Locale.Builder().setLanguageTag(language).build();
|
||||
return locale.getISO3Language() != null;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.awt.event.KeyAdapter;
|
|||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
|
@ -169,6 +170,14 @@ public class ListPanel extends JPanel
|
|||
return listViewComboBox;
|
||||
}
|
||||
|
||||
List<GameListData> getSelectedGameListData()
|
||||
{
|
||||
return getList().getSelectedValuesList();
|
||||
}
|
||||
boolean isSingleGameSelected()
|
||||
{
|
||||
return getList().getSelectedIndices().length == 1;
|
||||
}
|
||||
int getSelectedIndexInList()
|
||||
{
|
||||
return getList().getSelectedIndex();
|
||||
|
@ -264,10 +273,20 @@ public class ListPanel extends JPanel
|
|||
super.removeSelectionInterval(start, end);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSelectionInterval(int anchor, int lead)
|
||||
{
|
||||
if (!uiModel.isDataChanged())
|
||||
{
|
||||
super.addSelectionInterval(anchor, lead);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectionInterval(int anchor, int lead)
|
||||
{
|
||||
System.out.println("anchor=" + anchor + ", lead=" + lead);
|
||||
if (!uiModel.isDataChanged())
|
||||
{
|
||||
super.setSelectionInterval(anchor, lead);
|
||||
|
@ -304,7 +323,7 @@ public class ListPanel extends JPanel
|
|||
}
|
||||
}
|
||||
};
|
||||
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||
|
||||
//If the user holds down "down" or "up" (scrolling in the list) the details is not
|
||||
//updated until the key is released
|
||||
|
@ -328,7 +347,7 @@ public class ListPanel extends JPanel
|
|||
e.consume();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP)
|
||||
{
|
||||
delayDetailsUpdate = true;
|
||||
|
@ -357,19 +376,20 @@ public class ListPanel extends JPanel
|
|||
}
|
||||
}
|
||||
});
|
||||
list.addMouseListener(new MouseAdapter() {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e)
|
||||
list.addMouseListener(new MouseAdapter()
|
||||
{
|
||||
if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2)
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e)
|
||||
{
|
||||
//trigger run game...
|
||||
MainWindow.getInstance().getMainPanel().runCurrentGame();
|
||||
if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2 && list.getSelectionModel().getSelectedItemsCount() == 1)
|
||||
{
|
||||
//trigger run game...
|
||||
MainWindow.getInstance().getMainPanel().runCurrentGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
list.addListSelectionListener(e -> {
|
||||
if (!e.getValueIsAdjusting() || pageButtonPressed)
|
||||
{
|
||||
|
@ -392,8 +412,10 @@ public class ListPanel extends JPanel
|
|||
|
||||
private void updateSelectedGame()
|
||||
{
|
||||
SwingUtilities
|
||||
.invokeLater(() -> mainPanel.getGameDetailsBackgroundPanel().updateSelectedGame(list.getSelectedValue()));
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
boolean singelSelected = list.getSelectionModel().getSelectedItemsCount() == 1;
|
||||
mainPanel.getGameDetailsBackgroundPanel().updateSelectedGame(singelSelected ? list.getSelectedValue() : null);
|
||||
});
|
||||
}
|
||||
|
||||
void checkSaveChangeStatus()
|
||||
|
@ -417,14 +439,17 @@ public class ListPanel extends JPanel
|
|||
{
|
||||
if (!uiModel.isDataChanged())
|
||||
{
|
||||
uiModel.toggleFavorite(list.getSelectedValue());
|
||||
for (GameListData glData : list.getSelectedValuesList())
|
||||
{
|
||||
uiModel.toggleFavorite(glData);
|
||||
}
|
||||
mainPanel.repaintAfterModifications();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void reloadCurrentGameView()
|
||||
{
|
||||
GameListData selectedData = getList().getSelectedValue();
|
||||
GameListData selectedData = getList().getSelectedValue();
|
||||
getList().clearSelection();
|
||||
uiModel.reloadCurrentGameView();
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
|
|
|
@ -8,6 +8,7 @@ import javax.swing.JPanel;
|
|||
import javax.swing.JSplitPane;
|
||||
|
||||
import se.lantz.model.MainViewModel;
|
||||
import se.lantz.model.data.GameListData;
|
||||
|
||||
public class MainPanel extends JPanel
|
||||
{
|
||||
|
@ -98,22 +99,38 @@ public class MainPanel extends JPanel
|
|||
|
||||
public void deleteCurrentGame()
|
||||
{
|
||||
List<GameListData> selectedGameListData = getListPanel().getSelectedGameListData();
|
||||
|
||||
|
||||
if (getListPanel().getSelectedIndexInList() > -1)
|
||||
{
|
||||
int value = showDeleteDialog();
|
||||
int value = showDeleteDialog(selectedGameListData.size());
|
||||
if (value == JOptionPane.YES_OPTION)
|
||||
{
|
||||
int currentSelectedIndex = getListPanel().getSelectedIndexInList();
|
||||
uiModel.deleteCurrentGame();
|
||||
for (GameListData gameListData : selectedGameListData)
|
||||
{
|
||||
getGameDetailsBackgroundPanel().updateSelectedGame(gameListData);
|
||||
uiModel.deleteCurrentGame();
|
||||
}
|
||||
repaintAfterModifications();
|
||||
getListPanel().setSelectedIndexInList(currentSelectedIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int showDeleteDialog()
|
||||
int showDeleteDialog(int numberOfGamesSelected)
|
||||
{
|
||||
String message = "Do you want to delete " + uiModel.getInfoModel().getTitle() + " from the database?";
|
||||
String message = "";
|
||||
if (numberOfGamesSelected == 1)
|
||||
{
|
||||
message = "Do you want to delete " + uiModel.getInfoModel().getTitle() + " from the database?";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "Do you want to delete " + numberOfGamesSelected + " games from the database?";
|
||||
}
|
||||
if (uiModel.isNewGameSelected())
|
||||
{
|
||||
message = "Do you want to delete the new game entry?";
|
||||
|
@ -157,7 +174,7 @@ public class MainPanel extends JPanel
|
|||
|
||||
public void runCurrentGame()
|
||||
{
|
||||
if (getListPanel().getSelectedIndexInList() > -1)
|
||||
if (getListPanel().isSingleGameSelected() && getListPanel().getSelectedIndexInList() > -1)
|
||||
{
|
||||
getGameDetailsBackgroundPanel().runCurrentGame();
|
||||
}
|
||||
|
|
|
@ -160,7 +160,7 @@ public class MenuManager
|
|||
|
||||
JMenuItem getAddGameMenuItem()
|
||||
{
|
||||
addGameItem = new JMenuItem("Add New Game");
|
||||
addGameItem = new JMenuItem("Add new game");
|
||||
KeyStroke keyStrokeToAddGame = KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_DOWN_MASK);
|
||||
addGameItem.setAccelerator(keyStrokeToAddGame);
|
||||
addGameItem.setMnemonic('N');
|
||||
|
@ -171,7 +171,7 @@ public class MenuManager
|
|||
|
||||
JMenuItem getDeleteGameMenuItem()
|
||||
{
|
||||
deleteGameItem = new JMenuItem("Delete Current Game");
|
||||
deleteGameItem = new JMenuItem("Delete selected game(s)");
|
||||
KeyStroke keyStrokeToAddGame = KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK);
|
||||
deleteGameItem.setAccelerator(keyStrokeToAddGame);
|
||||
deleteGameItem.setMnemonic('D');
|
||||
|
@ -190,7 +190,7 @@ public class MenuManager
|
|||
|
||||
JMenuItem getRunGameMenuItem()
|
||||
{
|
||||
runGameItem = new JMenuItem("Run Current Game");
|
||||
runGameItem = new JMenuItem("Run selected game");
|
||||
KeyStroke keyStrokeToRunGame = KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK);
|
||||
runGameItem.setAccelerator(keyStrokeToRunGame);
|
||||
runGameItem.setMnemonic('R');
|
||||
|
@ -221,7 +221,7 @@ public class MenuManager
|
|||
|
||||
private JMenuItem getExportItem()
|
||||
{
|
||||
exportItem = new JMenuItem("Export Games...");
|
||||
exportItem = new JMenuItem("Export games...");
|
||||
KeyStroke keyStrokeToExportGames = KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_DOWN_MASK);
|
||||
exportItem.setAccelerator(keyStrokeToExportGames);
|
||||
exportItem.setMnemonic('E');
|
||||
|
|
Loading…
Reference in New Issue