|
|
@@ -43,18 +43,6 @@ public class AutoGrowPanel extends JPanel {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private class GrowAction implements AnyActionDocumentListener {
|
|
|
- @Override
|
|
|
- public void update(DocumentEvent e) {
|
|
|
- final DocumentListenable back = getBack();
|
|
|
- back.removeDocumentListener(this);
|
|
|
- back.addDocumentListener(new DeleteOnEmpty(back));
|
|
|
- extend();
|
|
|
- getBack().addDocumentListener(this);
|
|
|
- getParent().getParent().validate();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@RequiredArgsConstructor
|
|
|
private class ExtendAction<T, C extends Component & DocumentListenable> implements AnyActionDocumentListener {
|
|
|
final Function<T, C> factory;
|
|
|
@@ -87,31 +75,6 @@ public class AutoGrowPanel extends JPanel {
|
|
|
AnyActionDocumentListener grow;
|
|
|
List<DocumentListenable> members = new ArrayList<>();
|
|
|
|
|
|
- /**
|
|
|
- * @wbp.parser.constructor
|
|
|
- */
|
|
|
- public AutoGrowPanel(Supplier<DocumentListenable> prod) {
|
|
|
- this(i -> prod.get(), 1);
|
|
|
- }
|
|
|
-
|
|
|
- public AutoGrowPanel(IntFunction<DocumentListenable> prod, int create) {
|
|
|
- this.prod = prod;
|
|
|
- this.grow = new GrowAction();
|
|
|
-
|
|
|
- setLayout(new VerticalLayout(5));
|
|
|
- if (create == 0) return; // TODO
|
|
|
- while (create-- > 1) {
|
|
|
- extend();
|
|
|
- getBack().addDocumentListener(new DeleteOnEmpty(getBack()));
|
|
|
- }
|
|
|
- extend();
|
|
|
- getBack().addDocumentListener(grow);
|
|
|
- }
|
|
|
-
|
|
|
- public <T> AutoGrowPanel(Function<T, DocumentListenable> function, List<T> list) {
|
|
|
- this(i -> list.size() > i ? function.apply(list.get(i)) : null, list.size());
|
|
|
- }
|
|
|
-
|
|
|
@SafeVarargs
|
|
|
public <T, C extends Component & DocumentListenable> AutoGrowPanel(Function<T, C> function,
|
|
|
Supplier<T> newItem, Consumer<? super T> onData, Consumer<Integer> onDelete, T...ts) {
|
|
|
@@ -133,14 +96,6 @@ public class AutoGrowPanel extends JPanel {
|
|
|
empty.addDocumentListener(this.grow);
|
|
|
}
|
|
|
|
|
|
- private void extend() {
|
|
|
- DocumentListenable value = prod.apply(members.size());
|
|
|
- if (value != null) {
|
|
|
- members.add(value);
|
|
|
- add((Component) getBack());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private DocumentListenable getBack() {
|
|
|
return members.get(members.size() - 1);
|
|
|
}
|