MCPcopy Create free account
hub / github.com/FabricMC/Matcher / init

Method init

src/main/java/matcher/gui/menu/LoadProjectPane.java:40–101  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38 }
39
40 private void init() {
41 getChildren().add(new Label("Input directories:"));
42
43 ListView<Path> list = new ListView<>(FXCollections.observableList(paths));
44 getChildren().add(list);
45
46 list.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
47 list.setPrefWidth(320);
48 list.setPrefHeight(200);
49 VBox.setVgrow(list, Priority.ALWAYS);
50
51 HBox footer = new HBox(GuiConstants.padding);
52 getChildren().add(footer);
53
54 footer.setAlignment(Pos.CENTER_RIGHT);
55
56 Button button = new Button("add");
57 footer.getChildren().add(button);
58 button.setOnAction(event -> {
59 Path path = Gui.requestDir("Select directory to add", window);
60 if (path != null && !list.getItems().contains(path)) list.getItems().add(path);
61 });
62
63 Button removeButton = new Button("remove");
64 footer.getChildren().add(removeButton);
65 removeButton.setOnAction(event -> {
66 Set<Path> selected = new HashSet<>(list.getSelectionModel().getSelectedItems());
67 list.getItems().removeIf(selected::contains);
68 });
69
70 Button upButton = new Button("up");
71 footer.getChildren().add(upButton);
72 upButton.setOnAction(event -> GuiUtil.moveSelectionUp(list));
73
74 Button downButton = new Button("down");
75 footer.getChildren().add(downButton);
76 downButton.setOnAction(event -> GuiUtil.moveSelectionDown(list));
77
78 ListChangeListener<Path> itemChangeListener = change -> {
79 okButton.setDisable(paths.isEmpty());
80 };
81
82 list.getItems().addListener(itemChangeListener);
83
84 ListChangeListener<Path> selectChangeListener = change -> {
85 List<Integer> selectedIndices = list.getSelectionModel().getSelectedIndices();
86 boolean empty = selectedIndices.isEmpty();
87
88 removeButton.setDisable(empty);
89 upButton.setDisable(empty);
90 downButton.setDisable(empty);
91 };
92
93 list.getSelectionModel().getSelectedItems().addListener(selectChangeListener);
94
95 itemChangeListener.onChanged(null);
96 selectChangeListener.onChanged(null);
97

Callers 1

LoadProjectPaneMethod · 0.95

Calls 5

requestDirMethod · 0.95
moveSelectionUpMethod · 0.95
moveSelectionDownMethod · 0.95
getChildrenMethod · 0.80
addListenerMethod · 0.80

Tested by

no test coverage detected