only highlight next item if no other items have been removed since the callback started

This commit is contained in:
myk
2013-02-16 07:12:24 +00:00
parent 9ddcab70fd
commit 585ffc4e00

View File

@@ -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;