Skip to content

Commit

Permalink
Items in List editors now have a button to move them up in the list
Browse files Browse the repository at this point in the history
  • Loading branch information
hylkevds committed Jul 26, 2024
1 parent 9cba5e4 commit d46635b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> iterator() {
return value.iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;

/**
*
Expand Down Expand Up @@ -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++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d46635b

Please sign in to comment.