1818import qupath .lib .gui .prefs .PathPrefs ;
1919
2020import java .io .IOException ;
21+ import java .util .ResourceBundle ;
2122
2223
2324/**
3334 * </pre>
3435 */
3536public class DemoExtension implements QuPathExtension , GitHubProject {
36-
37+ // TODO: add and modify strings to this resource bundle as needed
38+ /**
39+ * A resource bundle containing all the text used by the extension. This may be useful for translation to other languages.
40+ * Note that this is optional and you can define the text within the code and FXML files that you use.
41+ */
42+ private static final ResourceBundle resources = ResourceBundle .getBundle ("qupath.ext.template.ui.strings" );
3743 private static final Logger logger = LoggerFactory .getLogger (DemoExtension .class );
3844
3945 /**
4046 * Display name for your extension
4147 * TODO: define this
4248 */
43- private static final String EXTENSION_NAME = "My Java extension" ;
49+ private static final String EXTENSION_NAME = resources . getString ( "name" ) ;
4450
4551 /**
4652 * Short description, used under 'Extensions > Installed extensions'
4753 * TODO: define this
4854 */
49- private static final String EXTENSION_DESCRIPTION = "This is just a demo to show how extensions work" ;
55+ private static final String EXTENSION_DESCRIPTION = resources . getString ( "description" ) ;
5056
5157 /**
5258 * QuPath version that the extension is designed to work with.
@@ -74,25 +80,24 @@ public class DemoExtension implements QuPathExtension, GitHubProject {
7480 * A 'persistent preference' - showing how to create a property that is stored whenever QuPath is closed.
7581 * This preference will be managed in the main QuPath GUI preferences window.
7682 */
77- private static BooleanProperty enableExtensionProperty = PathPrefs .createPersistentPreference (
83+ private static final BooleanProperty enableExtensionProperty = PathPrefs .createPersistentPreference (
7884 "enableExtension" , true );
7985
80-
8186 /**
8287 * Another 'persistent preference'.
8388 * This one will be managed using a GUI element created by the extension.
8489 * We use {@link Property<Integer>} rather than {@link IntegerProperty}
8590 * because of the type of GUI element we use to manage it.
8691 */
87- private static Property <Integer > numThreadsProperty = PathPrefs .createPersistentPreference (
88- "demo.num.threads " , 1 ).asObject ();
92+ private static final Property <Integer > integerOption = PathPrefs .createPersistentPreference (
93+ "demo.num.option " , 1 ).asObject ();
8994
9095 /**
9196 * An example of how to expose persistent preferences to other classes in your extension.
9297 * @return The persistent preference, so that it can be read or set somewhere else.
9398 */
94- public static Property <Integer > numThreadsProperty () {
95- return numThreadsProperty ;
99+ public static Property <Integer > integerOptionProperty () {
100+ return integerOption ;
96101 }
97102
98103 /**
@@ -107,7 +112,6 @@ public void installExtension(QuPathGUI qupath) {
107112 return ;
108113 }
109114 isInstalled = true ;
110- addPreference (qupath );
111115 addPreferenceToPane (qupath );
112116 addMenuItem (qupath );
113117 }
@@ -119,8 +123,8 @@ public void installExtension(QuPathGUI qupath) {
119123 * @param qupath The currently running QuPathGUI instance.
120124 */
121125 private void addPreferenceToPane (QuPathGUI qupath ) {
122- var propertyItem = new PropertyItemBuilder <>(enableExtensionProperty , Boolean .class )
123- .name ("Enable extension" )
126+ var propertyItem = new PropertyItemBuilder <>(enableExtensionProperty , Boolean .class )
127+ .name (resources . getString ( "menu.enable" ) )
124128 .category ("Demo extension" )
125129 .description ("Enable the demo extension" )
126130 .build ();
@@ -130,26 +134,10 @@ private void addPreferenceToPane(QuPathGUI qupath) {
130134 .add (propertyItem );
131135 }
132136
133- /**
134- * Demo showing how to add a persistent preference.
135- * This will be loaded whenever QuPath launches, with the value retained unless
136- * the preferences are reset.
137- * However, users will not be able to edit it unless you create a GUI
138- * element that corresponds with it
139- * @param qupath The currently running QuPathGUI instance.
140- */
141- private void addPreference (QuPathGUI qupath ) {
142- qupath .getPreferencePane ().addPropertyPreference (
143- enableExtensionProperty ,
144- Boolean .class ,
145- "Enable my extension" ,
146- EXTENSION_NAME ,
147- "Enable my extension" );
148- }
149137
150138 /**
151139 * Demo showing how a new command can be added to a QuPath menu.
152- * @param qupath
140+ * @param qupath The QuPath GUI
153141 */
154142 private void addMenuItem (QuPathGUI qupath ) {
155143 var menu = qupath .getMenu ("Extensions>" + EXTENSION_NAME , true );
@@ -167,15 +155,19 @@ private void createStage() {
167155 try {
168156 stage = new Stage ();
169157 Scene scene = new Scene (InterfaceController .createInstance ());
158+ stage .initOwner (QuPathGUI .getInstance ().getStage ());
159+ stage .setTitle (resources .getString ("stage.title" ));
170160 stage .setScene (scene );
161+ stage .setResizable (false );
171162 } catch (IOException e ) {
172- Dialogs .showErrorMessage ("Extension Error" , "GUI loading failed" );
163+ Dialogs .showErrorMessage (resources . getString ( "error" ), resources . getString ( "error.gui- loading- failed") );
173164 logger .error ("Unable to load extension interface FXML" , e );
174165 }
175166 }
176167 stage .show ();
177168 }
178169
170+
179171 @ Override
180172 public String getName () {
181173 return EXTENSION_NAME ;
0 commit comments