|
|
@@ -39,7 +39,7 @@ import javax.swing.JScrollPane;
|
|
|
@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
|
|
|
public class SelectSpellsPanel extends JPanel {
|
|
|
|
|
|
- private static final String NONE = "<none>";
|
|
|
+ static String NONE = "<none>";
|
|
|
|
|
|
@AllArgsConstructor
|
|
|
protected static class SelectSpellModel extends AbstractTableModel {
|
|
|
@@ -81,14 +81,14 @@ public class SelectSpellsPanel extends JPanel {
|
|
|
SelectSpellModel modelPrepared, modelKnown;
|
|
|
|
|
|
public SelectSpellsPanel(ChooseSpellTuple info, BoolGate.Handle gate, int level,
|
|
|
- Collection<DDSpell> prepared, int toPrepare,
|
|
|
- Collection<DDSpell> avail, boolean allowsDuplicates, IntValue sharedValue) {
|
|
|
+ Collection<DDSpell> prepared, Collection<DDSpell> avail,
|
|
|
+ boolean allowsDuplicates, IntValue sharedValue) {
|
|
|
this.allowsDuplicates = allowsDuplicates;
|
|
|
this.sharedValue = sharedValue;
|
|
|
this.prepared = new ArrayList<>(prepared);
|
|
|
final List<DDSpell> known = new ArrayList<>(avail);
|
|
|
- this.modelPrepared = new SelectSpellModel(createPrepareModel(prepared, toPrepare));
|
|
|
- this.modelKnown = new SelectSpellModel(known.stream().map(DDSpell::getName).toArray());
|
|
|
+ this.modelPrepared = new SelectSpellModel(createModel(prepared));
|
|
|
+ this.modelKnown = new SelectSpellModel(createModel(known));
|
|
|
gate.set(countNone() == 0);
|
|
|
sharedValue.value(sharedValue.value() - this.modelPrepared.data.length + countNone());
|
|
|
|
|
|
@@ -227,27 +227,15 @@ public class SelectSpellsPanel extends JPanel {
|
|
|
|
|
|
public SelectSpellsPanel(ChooseSpellTuple info, BoolGate.Handle gate, int level,
|
|
|
Collection<DDSpell> prepared, Collection<DDSpell> avail) {
|
|
|
- this(info, gate, level, prepared, 0, avail, true, new IntValue(-1));
|
|
|
+ this(info, gate, level, prepared, avail, true, new IntValue(-1));
|
|
|
}
|
|
|
|
|
|
private boolean wouldHaveIllegalDuplicate(int row) {
|
|
|
return !this.allowsDuplicates && Arrays.asList(modelPrepared.data).contains(modelKnown.data[row]);
|
|
|
}
|
|
|
|
|
|
- private String[] createPrepareModel(Collection<DDSpell> prepared, int toPrepare) {
|
|
|
- if (toPrepare <= prepared.size()) {
|
|
|
- return prepared.stream().map(DDSpell::getName).toArray(String[]::new);
|
|
|
- } else {
|
|
|
- String[] data = new String[toPrepare];
|
|
|
- int i = 0;
|
|
|
- for (DDSpell sp : prepared) {
|
|
|
- data[i++] = sp.getName();
|
|
|
- }
|
|
|
- for (; i < toPrepare; ++i) {
|
|
|
- data[i] = NONE;
|
|
|
- }
|
|
|
- return data;
|
|
|
- }
|
|
|
+ private String[] createModel(Collection<DDSpell> prepared) {
|
|
|
+ return prepared.stream().map(s -> s == null ? NONE : s.getName()).toArray(String[]::new);
|
|
|
}
|
|
|
|
|
|
private void replace(int[] rows) {
|