From ed4b11d9ef39c3ba51acdae7a8c9c1525cbc2047 Mon Sep 17 00:00:00 2001 From: drdev Date: Sat, 7 Dec 2013 19:10:16 +0000 Subject: [PATCH] Prevent focusing OK button if DualListBox has no specified count needed --- .../src/main/java/forge/gui/DualListBox.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/forge-gui/src/main/java/forge/gui/DualListBox.java b/forge-gui/src/main/java/forge/gui/DualListBox.java index 9cdd4196e37..1a744fb2f65 100644 --- a/forge-gui/src/main/java/forge/gui/DualListBox.java +++ b/forge-gui/src/main/java/forge/gui/DualListBox.java @@ -74,7 +74,7 @@ public class DualListBox extends FPanel { sourceList = new FList(sourceListModel); destListModel = new UnsortedListModel(); destList = new FList(destListModel); - + setPreferredSize(new Dimension(650, 300)); setLayout(new GridLayout(0, 3)); this.skin.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); @@ -119,7 +119,7 @@ public class DualListBox extends FPanel { if (MouseEvent.BUTTON1 == e.getButton() && 2 == e.getClickCount()) { onAdd.run(); } } }); - + destList.addKeyListener(new KeyAdapter() { @Override public void keyPressed(final KeyEvent e) { _handleListKey(e, onRemove, sourceList); @@ -130,7 +130,7 @@ public class DualListBox extends FPanel { if (MouseEvent.BUTTON1 == e.getButton() && 2 == e.getClickCount()) { onRemove.run(); } } }); - + // Dual List control buttons addButton = new FButton(">"); addButton.addActionListener(new ActionListener() {@Override public void actionPerformed(ActionEvent e) { onAdd.run(); } }); @@ -176,10 +176,10 @@ public class DualListBox extends FPanel { _addListListeners(sourceList); _addListListeners(destList); - + if (destElements != null && !destElements.isEmpty()) { addDestinationElements(destElements); - + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { @@ -187,10 +187,10 @@ public class DualListBox extends FPanel { } }); } - + if (sourceElements != null && !sourceElements.isEmpty()) { addSourceElements(sourceElements); - + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { @@ -198,14 +198,14 @@ public class DualListBox extends FPanel { } }); } - + _setButtonState(); } - + public void setSecondColumnLabelText(String label) { orderedLabel.setText(label); } - + public void setSideboardMode( boolean isSideboardMode) { sideboardingMode = isSideboardMode; if (sideboardingMode) { @@ -222,12 +222,12 @@ public class DualListBox extends FPanel { case KeyEvent.VK_SPACE: onSpace.run(); break; - + case KeyEvent.VK_LEFT: case KeyEvent.VK_RIGHT: arrowFocusTarget.requestFocusInWindow(); break; - + case KeyEvent.VK_ENTER: if (okButton.isEnabled()) { okButton.doClick(); @@ -236,7 +236,7 @@ public class DualListBox extends FPanel { autoButton.doClick(); } break; - + default: break; } @@ -342,13 +342,13 @@ public class DualListBox extends FPanel { // don't run stale callbacks return; } - + ListModel model = list.getModel(); if (0 == model.getSize()) { // nothing left to show return; } - + int cardIdx = e.getIndex0(); if (model.getSize() <= cardIdx) { // the last element got removed, get the one above it @@ -364,7 +364,7 @@ public class DualListBox extends FPanel { } }); } - + @Override public void intervalAdded(final ListDataEvent e) { SwingUtilities.invokeLater(new Runnable() { @@ -387,19 +387,19 @@ public class DualListBox extends FPanel { } }); } - + @Override public void contentsChanged(ListDataEvent e) { } }); - + list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent ev) { showSelectedCard(list.getSelectedValue()); } }); - + list.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { @@ -413,7 +413,7 @@ public class DualListBox extends FPanel { clearSourceListModel(); _setButtonState(); } - + private void _removeAll() { addSourceElements(destListModel); clearDestinationListModel(); @@ -427,7 +427,7 @@ public class DualListBox extends FPanel { selectOrder.setText(String.format("Sideboard (%d):", sourceListModel.getSize())); orderedLabel.setText(String.format("Main Deck (%d):", destListModel.getSize())); } - + if (targetRemainingSources != -1) { okButton.setEnabled(sourceListModel.getSize() == targetRemainingSources); } @@ -443,8 +443,8 @@ public class DualListBox extends FPanel { addButton.setEnabled(sourceListModel.getSize() != 0); addAllButton.setEnabled(sourceListModel.getSize() != 0); - if (okButton.isEnabled()) { - okButton.requestFocusInWindow(); + if (sourceListModel.getSize() == targetRemainingSources) { + okButton.requestFocusInWindow(); //focus OK button if reached specific number of sources needed } }