mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
- allow spacebar to move cards in DualListBox and enter to select the OK button
- make color of listbox selection depend on listbox focus, not cell focus - avoid NPE when attempting to start a challenge when there isn't one to start
This commit is contained in:
@@ -6,6 +6,8 @@ import java.awt.Dimension;
|
|||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.KeyAdapter;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -265,14 +267,69 @@ public class DualListBox<T> extends FPanel {
|
|||||||
setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||||
sourceListModel = new UnsortedListModel<T>();
|
sourceListModel = new UnsortedListModel<T>();
|
||||||
sourceList = new FList(sourceListModel);
|
sourceList = new FList(sourceListModel);
|
||||||
|
destListModel = new UnsortedListModel<T>();
|
||||||
|
destList = new FList(destListModel);
|
||||||
|
|
||||||
|
final Runnable onAdd = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<T> selected = (List<T>) Arrays.asList(sourceList.getSelectedValues());
|
||||||
|
addDestinationElements(selected);
|
||||||
|
clearSourceSelected();
|
||||||
|
sourceList.validate();
|
||||||
|
setButtonState();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
final Runnable onRemove = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<T> selected = (List<T>) Arrays.asList(destList.getSelectedValues());
|
||||||
|
clearDestinationSelected();
|
||||||
|
addSourceElements(selected);
|
||||||
|
setButtonState();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ActionListener addListener = new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
onAdd.run();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ActionListener removeListener = new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
onRemove.run();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
sourceList.addKeyListener(new KeyAdapter() {
|
||||||
|
@Override
|
||||||
|
public void keyPressed(final KeyEvent e) {
|
||||||
|
if (e.getKeyChar() == ' ') { onAdd.run(); }
|
||||||
|
else if (e.getKeyCode() == 10) { okButton.doClick(); }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
destList.addKeyListener(new KeyAdapter() {
|
||||||
|
@Override
|
||||||
|
public void keyPressed(final KeyEvent e) {
|
||||||
|
if (e.getKeyChar() == ' ') { onRemove.run(); }
|
||||||
|
else if (e.getKeyCode() == 10) { okButton.doClick(); }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Dual List control buttons
|
// Dual List control buttons
|
||||||
addButton = new FButton(">");
|
addButton = new FButton(">");
|
||||||
addButton.addActionListener(new AddListener());
|
addButton.addActionListener(addListener);
|
||||||
addAllButton = new FButton(">>");
|
addAllButton = new FButton(">>");
|
||||||
addAllButton.addActionListener(new AddAllListener());
|
addAllButton.addActionListener(new AddAllListener());
|
||||||
removeButton = new FButton("<");
|
removeButton = new FButton("<");
|
||||||
removeButton.addActionListener(new RemoveListener());
|
removeButton.addActionListener(removeListener);
|
||||||
removeAllButton = new FButton("<<");
|
removeAllButton = new FButton("<<");
|
||||||
removeAllButton.addActionListener(new RemoveAllListener());
|
removeAllButton.addActionListener(new RemoveAllListener());
|
||||||
|
|
||||||
@@ -283,9 +340,6 @@ public class DualListBox<T> extends FPanel {
|
|||||||
autoButton = new FButton("Auto");
|
autoButton = new FButton("Auto");
|
||||||
autoButton.addActionListener(new AutoListener());
|
autoButton.addActionListener(new AutoListener());
|
||||||
|
|
||||||
destListModel = new UnsortedListModel<T>();
|
|
||||||
destList = new FList(destListModel);
|
|
||||||
|
|
||||||
FPanel leftPanel = new FPanel(new BorderLayout());
|
FPanel leftPanel = new FPanel(new BorderLayout());
|
||||||
selectOrder = new FLabel.Builder().build();
|
selectOrder = new FLabel.Builder().build();
|
||||||
selectOrder.setText("Select Order:");
|
selectOrder.setText("Select Order:");
|
||||||
@@ -318,18 +372,6 @@ public class DualListBox<T> extends FPanel {
|
|||||||
addCardViewListener(destList);
|
addCardViewListener(destList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AddListener implements ActionListener {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
List<T> selected = (List<T>) Arrays.asList(sourceList.getSelectedValues());
|
|
||||||
addDestinationElements(selected);
|
|
||||||
clearSourceSelected();
|
|
||||||
sourceList.validate();
|
|
||||||
setButtonState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addAll() {
|
private void addAll() {
|
||||||
addDestinationElements(sourceListModel);
|
addDestinationElements(sourceListModel);
|
||||||
clearSourceListModel();
|
clearSourceListModel();
|
||||||
@@ -344,17 +386,6 @@ public class DualListBox<T> extends FPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RemoveListener implements ActionListener {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
List<T> selected = (List<T>) Arrays.asList(destList.getSelectedValues());
|
|
||||||
clearDestinationSelected();
|
|
||||||
addSourceElements(selected);
|
|
||||||
setButtonState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RemoveAllListener implements ActionListener {
|
private class RemoveAllListener implements ActionListener {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ public class SSubmenuQuestUtil {
|
|||||||
|
|
||||||
/** */
|
/** */
|
||||||
public static void startGame() {
|
public static void startGame() {
|
||||||
if (!checkActiveQuest("Start a duel.")) {
|
if (!checkActiveQuest("Start a duel.") || null == event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final QuestController qData = Singletons.getModel().getQuest();
|
final QuestController qData = Singletons.getModel().getQuest();
|
||||||
@@ -362,6 +362,7 @@ public class SSubmenuQuestUtil {
|
|||||||
System.out.println(msg);
|
System.out.println(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String errorMessage = GameType.Quest.getDecksFormat().getDeckConformanceProblem(deck);
|
String errorMessage = GameType.Quest.getDecksFormat().getDeckConformanceProblem(deck);
|
||||||
if (null != errorMessage) {
|
if (null != errorMessage) {
|
||||||
JOptionPane.showMessageDialog(null, "Your deck " + errorMessage + " Please edit or choose a different deck.", "Invalid deck", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Your deck " + errorMessage + " Please edit or choose a different deck.", "Invalid deck", JOptionPane.ERROR_MESSAGE);
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public class FList extends JList {
|
|||||||
lst0, val0, i0, isSelected, cellHasFocus);
|
lst0, val0, i0, isSelected, cellHasFocus);
|
||||||
|
|
||||||
lblItem.setBorder(new EmptyBorder(4, 3, 4, 3));
|
lblItem.setBorder(new EmptyBorder(4, 3, 4, 3));
|
||||||
lblItem.setBackground(FSkin.getColor(cellHasFocus ? FSkin.Colors.CLR_ACTIVE : FSkin.Colors.CLR_INACTIVE));
|
lblItem.setBackground(FSkin.getColor(hasFocus() ? FSkin.Colors.CLR_ACTIVE : FSkin.Colors.CLR_INACTIVE));
|
||||||
lblItem.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
lblItem.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||||
lblItem.setFont(FSkin.getFont(13));
|
lblItem.setFont(FSkin.getFont(13));
|
||||||
lblItem.setOpaque(isSelected);
|
lblItem.setOpaque(isSelected);
|
||||||
|
|||||||
Reference in New Issue
Block a user