From d46635bf4d3089e643a925ba6cd0b1a45d827d95 Mon Sep 17 00:00:00 2001 From: Hylke van der Schaaf Date: Fri, 26 Jul 2024 21:16:11 +0200 Subject: [PATCH] Items in List editors now have a button to move them up in the list --- CHANGELOG.md | 1 + .../iosb/ilt/configurable/editor/EditorList.java | 9 +++++++++ .../ilt/configurable/editor/fx/FactoryListFx.java | 14 ++++++++++++-- .../editor/swing/FactoryListSwing.java | 14 ++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54fc104..f26289f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Development Version 0.36 **Updates** +* Items in List editors now have a button to move them up in the list. # Release Version 0.35 diff --git a/Configurable/src/main/java/de/fraunhofer/iosb/ilt/configurable/editor/EditorList.java b/Configurable/src/main/java/de/fraunhofer/iosb/ilt/configurable/editor/EditorList.java index b873614..244413e 100644 --- a/Configurable/src/main/java/de/fraunhofer/iosb/ilt/configurable/editor/EditorList.java +++ b/Configurable/src/main/java/de/fraunhofer/iosb/ilt/configurable/editor/EditorList.java @@ -324,6 +324,15 @@ public void removeItem(T item) { fillComponent(); } + public void upItem(int idx) { + if (idx == 0 || idx >= value.size()) { + return; + } + T item = value.remove(idx); + value.add(idx - 1, item); + fillComponent(); + } + @Override public Iterator iterator() { return value.iterator(); diff --git a/Configurable/src/main/java/de/fraunhofer/iosb/ilt/configurable/editor/fx/FactoryListFx.java b/Configurable/src/main/java/de/fraunhofer/iosb/ilt/configurable/editor/fx/FactoryListFx.java index 05d297f..5a600ce 100644 --- a/Configurable/src/main/java/de/fraunhofer/iosb/ilt/configurable/editor/fx/FactoryListFx.java +++ b/Configurable/src/main/java/de/fraunhofer/iosb/ilt/configurable/editor/fx/FactoryListFx.java @@ -31,6 +31,7 @@ import javafx.scene.layout.GridPane; import javafx.scene.layout.Pane; import javafx.scene.layout.Priority; +import javafx.scene.layout.VBox; /** * @@ -107,14 +108,23 @@ public void fillComponent() { vertical ? row : 0, 1, 1, HPos.LEFT, VPos.BASELINE, Priority.ALWAYS, Priority.SOMETIMES); if (parentEditor.canEdit()) { + VBox buttonBox = new VBox(); Button removeButton = new Button("-"); removeButton.setOnAction((event) -> parentEditor.removeItem(item)); + buttonBox.getChildren().add(removeButton); + + if (row > 0) { + final int myRow = row; + Button upButton = new Button("↑"); + upButton.setOnAction((event) -> parentEditor.upItem(myRow)); + buttonBox.getChildren().add(upButton); + } GridPane.setConstraints( - removeButton, + buttonBox, vertical ? 1 : row, vertical ? row : 1, 1, 1, HPos.RIGHT, VPos.TOP, Priority.NEVER, Priority.NEVER); - fxPaneList.getChildren().addAll(pane, removeButton); + fxPaneList.getChildren().addAll(pane, buttonBox); } row++; } diff --git a/Configurable/src/main/java/de/fraunhofer/iosb/ilt/configurable/editor/swing/FactoryListSwing.java b/Configurable/src/main/java/de/fraunhofer/iosb/ilt/configurable/editor/swing/FactoryListSwing.java index e246850..37a9e72 100644 --- a/Configurable/src/main/java/de/fraunhofer/iosb/ilt/configurable/editor/swing/FactoryListSwing.java +++ b/Configurable/src/main/java/de/fraunhofer/iosb/ilt/configurable/editor/swing/FactoryListSwing.java @@ -23,6 +23,8 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; +import javax.swing.Box; +import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; @@ -104,9 +106,21 @@ public void fillComponent() { swListHolder.add(item.getGuiFactorySwing().getComponent(), gbc); if (parentEditor.canEdit()) { + Box buttonBox = new Box(BoxLayout.Y_AXIS); + JButton removeButton = new JButton("❌"); removeButton.setMargin(new Insets(1, 1, 1, 1)); removeButton.addActionListener((event) -> parentEditor.removeItem(item)); + buttonBox.add(removeButton); + + if (row > 0) { + final int myRow = row; + JButton upButton = new JButton("↑"); + upButton.setMargin(new Insets(1, 1, 1, 1)); + upButton.addActionListener((event) -> parentEditor.upItem(myRow)); + buttonBox.add(upButton); + } + gbc = new GridBagConstraints(); gbc.gridx = vertical ? 1 : row; gbc.gridy = vertical ? row : 1;