mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
only highlight next item if no other items have been removed since the callback started
This commit is contained in:
@@ -199,26 +199,31 @@ public class DualListBox<T> extends FPanel {
|
|||||||
|
|
||||||
private void addCardViewListener(final FList list) {
|
private void addCardViewListener(final FList list) {
|
||||||
list.getModel().addListDataListener(new ListDataListener() {
|
list.getModel().addListDataListener(new ListDataListener() {
|
||||||
|
int callCount = 0;
|
||||||
@Override
|
@Override
|
||||||
public void intervalRemoved(ListDataEvent e) {
|
public void intervalRemoved(final ListDataEvent e) {
|
||||||
final ListModel model = list.getModel();
|
final int callNum = ++callCount;
|
||||||
if (0 == model.getSize()) {
|
|
||||||
// nothing left to show
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int cardIdxPre = e.getIndex0();
|
|
||||||
if (model.getSize() <= cardIdxPre) {
|
|
||||||
// the last element got removed, get the one above it
|
|
||||||
--cardIdxPre;
|
|
||||||
}
|
|
||||||
final int cardIdx = cardIdxPre;
|
|
||||||
|
|
||||||
// invoke this later since the list is out of sync with the model
|
// invoke this later since the list is out of sync with the model
|
||||||
// at this moment.
|
// at this moment.
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
if (callNum != callCount) {
|
||||||
|
// 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
|
||||||
|
cardIdx = model.getSize() - 1;
|
||||||
|
}
|
||||||
showCard = false;
|
showCard = false;
|
||||||
list.setSelectedIndex(cardIdx);
|
list.setSelectedIndex(cardIdx);
|
||||||
showCard = true;
|
showCard = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user