mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Prevent ListChooser getting caught in infinite loop of reprompting
This commit is contained in:
@@ -103,9 +103,24 @@ public class ListChooser<T> {
|
|||||||
this.lstChoices.setCellRenderer(new TransformedCellRenderer(display));
|
this.lstChoices.setCellRenderer(new TransformedCellRenderer(display));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.optionPane = new FOptionPane(null, title, null, new JScrollPane(this.lstChoices), options, 0);
|
this.optionPane = new FOptionPane(null, title, null, new JScrollPane(this.lstChoices), options, -1);
|
||||||
this.optionPane.setButtonEnabled(0, minChoices == 0);
|
this.optionPane.setButtonEnabled(0, minChoices == 0);
|
||||||
|
|
||||||
|
this.optionPane.addWindowFocusListener(new WindowFocusListener() {
|
||||||
|
@Override
|
||||||
|
public void windowGainedFocus(final WindowEvent e) {
|
||||||
|
ListChooser.this.lstChoices.grabFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowLostFocus(final WindowEvent e) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.minChoices != 0) {
|
||||||
|
this.optionPane.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||||
|
}
|
||||||
|
|
||||||
this.lstChoices.getSelectionModel().addListSelectionListener(new SelListener());
|
this.lstChoices.getSelectionModel().addListSelectionListener(new SelListener());
|
||||||
this.lstChoices.addKeyListener(new KeyAdapter() {
|
this.lstChoices.addKeyListener(new KeyAdapter() {
|
||||||
@Override
|
@Override
|
||||||
@@ -152,40 +167,23 @@ public class ListChooser<T> {
|
|||||||
}
|
}
|
||||||
int result;
|
int result;
|
||||||
do {
|
do {
|
||||||
if (this.minChoices != 0) {
|
|
||||||
this.optionPane.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (list.contains(item)) {
|
if (list.contains(item)) {
|
||||||
lstChoices.setSelectedValue(item, true);
|
lstChoices.setSelectedValue(item, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
lstChoices.setSelectedIndex(0);
|
lstChoices.setSelectedIndex(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.optionPane.addWindowFocusListener(new WindowFocusListener() {
|
|
||||||
@Override
|
|
||||||
public void windowGainedFocus(final WindowEvent e) {
|
|
||||||
ListChooser.this.lstChoices.grabFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void windowLostFocus(final WindowEvent e) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.optionPane.setVisible(true);
|
this.optionPane.setVisible(true);
|
||||||
result = this.optionPane.getResult();
|
result = this.optionPane.getResult();
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
this.lstChoices.clearSelection();
|
this.lstChoices.clearSelection();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
// can't stop closing by ESC, so repeat if cancelled
|
// can't stop closing by ESC, so repeat if cancelled
|
||||||
} while (this.minChoices != 0);
|
} while (this.minChoices != 0 && result != 0);
|
||||||
|
|
||||||
this.optionPane.dispose();
|
this.optionPane.dispose();
|
||||||
|
|
||||||
// this assert checks if we really don't return on a cancel if input is
|
// this assert checks if we really don't return on a cancel if input is mandatory
|
||||||
// mandatory
|
|
||||||
assert (this.minChoices == 0) || (result == 0);
|
assert (this.minChoices == 0) || (result == 0);
|
||||||
this.called = true;
|
this.called = true;
|
||||||
return (result == 0);
|
return (result == 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user