-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from qupath/strings-options
Add examples of setting preferences in QuPath pane and in extension GUI
- Loading branch information
Showing
5 changed files
with
155 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/qupath/ext/template/ui/InterfaceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package qupath.ext.template.ui; | ||
|
||
import javafx.fxml.FXML; | ||
import javafx.fxml.FXMLLoader; | ||
import javafx.scene.control.ChoiceBox; | ||
import javafx.scene.control.Spinner; | ||
import javafx.scene.control.TextField; | ||
import javafx.scene.layout.VBox; | ||
import qupath.ext.template.DemoExtension; | ||
import qupath.fx.dialogs.Dialogs; | ||
|
||
import java.io.IOException; | ||
import java.util.ResourceBundle; | ||
|
||
/** | ||
* Controller for UI pane contained in interface.fxml | ||
*/ | ||
|
||
public class InterfaceController extends VBox { | ||
private static final ResourceBundle resources = ResourceBundle.getBundle("qupath.ext.template.ui.strings"); | ||
|
||
@FXML | ||
private Spinner<Integer> threadSpinner; | ||
|
||
public static InterfaceController createInstance() throws IOException { | ||
return new InterfaceController(); | ||
} | ||
|
||
private InterfaceController() throws IOException { | ||
var url = InterfaceController.class.getResource("interface.fxml"); | ||
FXMLLoader loader = new FXMLLoader(url, resources); | ||
loader.setRoot(this); | ||
loader.setController(this); | ||
loader.load(); | ||
|
||
// For extensions with a small number of options, | ||
// or with options that are very important for how the extension works, | ||
// it may be better to present them all to the user in the main extension GUI, | ||
// binding them to GUI elements, so they are updated when the user interacts with | ||
// the GUI, and so that the GUI elements are updated if the preference changes | ||
threadSpinner.getValueFactory().valueProperty().bindBidirectional(DemoExtension.numThreadsProperty()); | ||
threadSpinner.getValueFactory().valueProperty().addListener((observableValue, oldValue, newValue) -> { | ||
Dialogs.showInfoNotification( | ||
resources.getString("title"), | ||
String.format(resources.getString("threads"), newValue)); | ||
}); | ||
} | ||
|
||
@FXML | ||
private void runDemoExtension() { | ||
System.out.println("Demo extension run"); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import java.lang.*?> | ||
<?import java.util.*?> | ||
<?import javafx.scene.*?> | ||
<?import javafx.scene.control.*?> | ||
<?import javafx.scene.layout.*?> | ||
|
||
<fx:root type="VBox" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/20" xmlns:fx="http://javafx.com/fxml/1"> | ||
<Button onAction="#runDemoExtension" text="Run"/> | ||
<Spinner fx:id="threadSpinner" prefWidth="75.0"> | ||
<valueFactory> | ||
<SpinnerValueFactory.IntegerSpinnerValueFactory max="96" min="1" /> | ||
</valueFactory> | ||
</Spinner> | ||
</fx:root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
title = Demo extension | ||
|
||
threads = Threads set to %d |