diff --git a/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/src/main/java/org/nwapw/abacus/fx/AbacusController.java index 976f8c7..96f155e 100644 --- a/src/main/java/org/nwapw/abacus/fx/AbacusController.java +++ b/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -14,6 +14,8 @@ import javafx.util.Callback; import javafx.util.StringConverter; import org.nwapw.abacus.Abacus; import org.nwapw.abacus.config.Configuration; +import org.nwapw.abacus.function.Documentation; +import org.nwapw.abacus.function.DocumentationType; import org.nwapw.abacus.number.ComputationInterruptedException; import org.nwapw.abacus.number.NumberInterface; import org.nwapw.abacus.plugin.ClassFinder; @@ -24,7 +26,9 @@ import org.nwapw.abacus.tree.TreeNode; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Set; +import java.util.stream.Collectors; /** @@ -97,7 +101,7 @@ public class AbacusController implements PluginListener { @FXML private TextField computationLimitField; @FXML - private ListView functionListView; + private ListView functionListView; @FXML private TextField functionListSearchField; @@ -120,11 +124,11 @@ public class AbacusController implements PluginListener { /** * The list of functions that are registered in the calculator. */ - private ObservableList functionList; + private ObservableList functionList; /** * The filtered list displayed to the user. */ - private FilteredList functionFilter; + private FilteredList functionFilter; /** * The abacus instance used for changing the plugin configuration. @@ -227,12 +231,12 @@ public class AbacusController implements PluginListener { return new ToggleablePlugin(true, string); } }); - functionList = FXCollections.observableArrayList(); functionFilter = new FilteredList<>(functionList, (s) -> true); functionListView.setItems(functionFilter); functionListSearchField.textProperty().addListener((observable, oldValue, newValue) -> - functionFilter.setPredicate((newValue.length() == 0) ? ((s) -> true) : ((s) -> s.contains(newValue)))); + functionFilter.setPredicate((newValue.length() == 0) ? ((s) -> true) : ((s) -> s.matches(newValue)))); + functionListView.setCellFactory(param -> new DocumentationCell()); historyData = FXCollections.observableArrayList(); historyTable.setItems(historyData); numberImplementationOptions = FXCollections.observableArrayList(); @@ -347,8 +351,15 @@ public class AbacusController implements PluginListener { plugin.enabledProperty().addListener(e -> changesMade = true); enabledPlugins.add(plugin); } - functionList.addAll(manager.getAllFunctions()); - functionList.sort(String::compareTo); + PluginManager pluginManager = abacus.getPluginManager(); + functionList.addAll(manager.getAllFunctions().stream().map(name -> pluginManager.documentationFor(name, DocumentationType.FUNCTION)) + .collect(Collectors.toCollection(ArrayList::new))); + functionList.sort((a, b) -> { + if(a == null && b == null) return 0; + else if(a == null) return -1; + else if(b == null) return 1; + else return a.getCodeName().compareTo(b.getCodeName()); + }); } @Override diff --git a/src/main/java/org/nwapw/abacus/fx/DocumentationCell.java b/src/main/java/org/nwapw/abacus/fx/DocumentationCell.java index 73bdbd7..bc68fb7 100644 --- a/src/main/java/org/nwapw/abacus/fx/DocumentationCell.java +++ b/src/main/java/org/nwapw/abacus/fx/DocumentationCell.java @@ -2,6 +2,8 @@ package org.nwapw.abacus.fx; import javafx.scene.control.Label; import javafx.scene.control.ListCell; +import javafx.scene.control.TitledPane; +import javafx.scene.layout.VBox; import org.nwapw.abacus.function.Documentation; public class DocumentationCell extends ListCell { @@ -10,12 +12,30 @@ public class DocumentationCell extends ListCell { private Label nameLabel; private Label description; private Label longDescription; + private TitledPane titledPane; public DocumentationCell(){ + VBox vbox = new VBox(); + vbox.setSpacing(10); + titledPane = new TitledPane(); codeNameLabel = new Label(); nameLabel = new Label(); description = new Label(); longDescription = new Label(); + codeNameLabel.setWrapText(true); + nameLabel.setWrapText(true); + description.setWrapText(true); + longDescription.setWrapText(true); + vbox.getChildren().add(codeNameLabel); + vbox.getChildren().add(nameLabel); + vbox.getChildren().add(description); + vbox.getChildren().add(longDescription); + titledPane.textProperty().bindBidirectional(codeNameLabel.textProperty()); + titledPane.setContent(vbox); + titledPane.setExpanded(false); + titledPane.maxWidthProperty().bind(widthProperty()); + + visibleProperty().addListener((a, b, c) -> titledPane.setExpanded(false)); } @Override @@ -26,11 +46,13 @@ public class DocumentationCell extends ListCell { nameLabel.setText(""); description.setText(""); longDescription.setText(""); + setGraphic(null); } else { codeNameLabel.setText(item.getCodeName()); nameLabel.setText(item.getName()); description.setText(item.getDescription()); longDescription.setText(item.getLongDescription()); + setGraphic(titledPane); } } }