mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-22 07:20:09 -08:00
Add documentation browsing to the abacus controller.
This commit is contained in:
parent
9d92d0eebb
commit
400e4578a0
|
@ -14,6 +14,8 @@ import javafx.util.Callback;
|
||||||
import javafx.util.StringConverter;
|
import javafx.util.StringConverter;
|
||||||
import org.nwapw.abacus.Abacus;
|
import org.nwapw.abacus.Abacus;
|
||||||
import org.nwapw.abacus.config.Configuration;
|
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.ComputationInterruptedException;
|
||||||
import org.nwapw.abacus.number.NumberInterface;
|
import org.nwapw.abacus.number.NumberInterface;
|
||||||
import org.nwapw.abacus.plugin.ClassFinder;
|
import org.nwapw.abacus.plugin.ClassFinder;
|
||||||
|
@ -24,7 +26,9 @@ import org.nwapw.abacus.tree.TreeNode;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,7 +101,7 @@ public class AbacusController implements PluginListener {
|
||||||
@FXML
|
@FXML
|
||||||
private TextField computationLimitField;
|
private TextField computationLimitField;
|
||||||
@FXML
|
@FXML
|
||||||
private ListView<String> functionListView;
|
private ListView<Documentation> functionListView;
|
||||||
@FXML
|
@FXML
|
||||||
private TextField functionListSearchField;
|
private TextField functionListSearchField;
|
||||||
|
|
||||||
|
@ -120,11 +124,11 @@ public class AbacusController implements PluginListener {
|
||||||
/**
|
/**
|
||||||
* The list of functions that are registered in the calculator.
|
* The list of functions that are registered in the calculator.
|
||||||
*/
|
*/
|
||||||
private ObservableList<String> functionList;
|
private ObservableList<Documentation> functionList;
|
||||||
/**
|
/**
|
||||||
* The filtered list displayed to the user.
|
* The filtered list displayed to the user.
|
||||||
*/
|
*/
|
||||||
private FilteredList<String> functionFilter;
|
private FilteredList<Documentation> functionFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The abacus instance used for changing the plugin configuration.
|
* The abacus instance used for changing the plugin configuration.
|
||||||
|
@ -227,12 +231,12 @@ public class AbacusController implements PluginListener {
|
||||||
return new ToggleablePlugin(true, string);
|
return new ToggleablePlugin(true, string);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
functionList = FXCollections.observableArrayList();
|
functionList = FXCollections.observableArrayList();
|
||||||
functionFilter = new FilteredList<>(functionList, (s) -> true);
|
functionFilter = new FilteredList<>(functionList, (s) -> true);
|
||||||
functionListView.setItems(functionFilter);
|
functionListView.setItems(functionFilter);
|
||||||
functionListSearchField.textProperty().addListener((observable, oldValue, newValue) ->
|
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();
|
historyData = FXCollections.observableArrayList();
|
||||||
historyTable.setItems(historyData);
|
historyTable.setItems(historyData);
|
||||||
numberImplementationOptions = FXCollections.observableArrayList();
|
numberImplementationOptions = FXCollections.observableArrayList();
|
||||||
|
@ -347,8 +351,15 @@ public class AbacusController implements PluginListener {
|
||||||
plugin.enabledProperty().addListener(e -> changesMade = true);
|
plugin.enabledProperty().addListener(e -> changesMade = true);
|
||||||
enabledPlugins.add(plugin);
|
enabledPlugins.add(plugin);
|
||||||
}
|
}
|
||||||
functionList.addAll(manager.getAllFunctions());
|
PluginManager pluginManager = abacus.getPluginManager();
|
||||||
functionList.sort(String::compareTo);
|
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
|
@Override
|
||||||
|
|
|
@ -2,6 +2,8 @@ package org.nwapw.abacus.fx;
|
||||||
|
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.ListCell;
|
import javafx.scene.control.ListCell;
|
||||||
|
import javafx.scene.control.TitledPane;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
import org.nwapw.abacus.function.Documentation;
|
import org.nwapw.abacus.function.Documentation;
|
||||||
|
|
||||||
public class DocumentationCell extends ListCell<Documentation> {
|
public class DocumentationCell extends ListCell<Documentation> {
|
||||||
|
@ -10,12 +12,30 @@ public class DocumentationCell extends ListCell<Documentation> {
|
||||||
private Label nameLabel;
|
private Label nameLabel;
|
||||||
private Label description;
|
private Label description;
|
||||||
private Label longDescription;
|
private Label longDescription;
|
||||||
|
private TitledPane titledPane;
|
||||||
|
|
||||||
public DocumentationCell(){
|
public DocumentationCell(){
|
||||||
|
VBox vbox = new VBox();
|
||||||
|
vbox.setSpacing(10);
|
||||||
|
titledPane = new TitledPane();
|
||||||
codeNameLabel = new Label();
|
codeNameLabel = new Label();
|
||||||
nameLabel = new Label();
|
nameLabel = new Label();
|
||||||
description = new Label();
|
description = new Label();
|
||||||
longDescription = 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
|
@Override
|
||||||
|
@ -26,11 +46,13 @@ public class DocumentationCell extends ListCell<Documentation> {
|
||||||
nameLabel.setText("");
|
nameLabel.setText("");
|
||||||
description.setText("");
|
description.setText("");
|
||||||
longDescription.setText("");
|
longDescription.setText("");
|
||||||
|
setGraphic(null);
|
||||||
} else {
|
} else {
|
||||||
codeNameLabel.setText(item.getCodeName());
|
codeNameLabel.setText(item.getCodeName());
|
||||||
nameLabel.setText(item.getName());
|
nameLabel.setText(item.getName());
|
||||||
description.setText(item.getDescription());
|
description.setText(item.getDescription());
|
||||||
longDescription.setText(item.getLongDescription());
|
longDescription.setText(item.getLongDescription());
|
||||||
|
setGraphic(titledPane);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user