Prevent focusing OK button if DualListBox has no specified count needed

This commit is contained in:
drdev
2013-12-07 19:10:16 +00:00
parent c115f01edf
commit ed4b11d9ef

View File

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