Skip to content

Commit 19e9d00

Browse files
ctruedenclaude
andcommitted
scijava-javafx: a second binding, and what it proved
"Toolkit-agnostic" was an assertion. A second implementation makes it a measurement, and the measurement is good: the whole of scijava-ui3 survived JavaFX with two changes, both of them Swing keeping something that was never Swing's. - `Widget.isLabeled()` -- whether a parameter wants a label beside it is a statement about the parameter. Every toolkit would have answered it identically, so every toolkit should not have had to. - `WidgetPanel.showProblems(Map)` -- how a problem looks is a toolkit's business; that there is one, shown per parameter and cleared when fixed, is not. Nothing else moved. `Widget`, `WidgetFactory`, `WidgetPanelFactory`, `WidgetPanels`, `Widgets`, `InputHarvester`, `MenuCreator` and `Menus` were untouched, and the model layer never came into question. What JavaFX forced that Swing never would: - The toolkit must be started, exactly once, and there is no `invokeAndWait`. `FxThread` is that plumbing, and it avoids `Application.launch` on purpose: that method seizes the process and returns when the last window closes, which is wrong for a binding an application, a script or a test may drive. - `showAndWait` runs a nested event loop, so the dialog is built and shown in one visit to the JavaFX thread, where Swing wanted two. - JavaFX spinners do not preserve a parameter's type -- their value factories are Integer or Double and nothing else -- and an editable one discards what was typed unless Enter is pressed. Both are handled in `FxNumber`; neither has a Swing counterpart. - Some things are easier: a collapsible group is a `TitledPane`, and `KeyCombination.SHORTCUT_DOWN` says what Swing computes through a `Toolkit` call. And so that the two cannot drift, `scijava-ui3-test`: the sample commands both bindings render, and a conformance suite both extend -- eight assertions about widgets, three about menus. A binding's own tests now cover only what is genuinely its own. The Swing demos and shell moved onto the shared commands, which is why they look edited here. `FxShell` is the same small application as the Swing one: mvn -pl scijava-javafx test-compile exec:java -Denforcer.skip \ -Dexec.classpathScope=test -Dexec.mainClass=org.scijava.javafx.FxShell Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013gJpzGd3ksbME4CN6Tu2ni
1 parent 193a373 commit 19e9d00

36 files changed

Lines changed: 3636 additions & 728 deletions

‎docs/migration-plan.md‎

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,8 @@ unless it says there is no replacement at all, which it says explicitly.
689689
| Layer | Contents | Depends on |
690690
| --- | --- | --- |
691691
| **0. Foundation** (built) | `spi`, `common3`, `collections`, `priority`, `progress`, `concurrent`, `discovery`, `index`, `struct`, `io3`, `events`, `context`, `execute` | nothing above |
692-
| **1. Application model** (to build) | `scijava-command` (a struct plus presentation metadata), `scijava-menu` (the menu tree), `scijava-ui3` (toolkit-agnostic contracts), `scijava-desktop` | layer 0 |
693-
| **2. Toolkit bindings** | `scijava-ui-swing`, JavaFX, headless | layer 1 |
692+
| **1. Application model** (built, less `scijava-desktop`) | `scijava-command` (a struct plus presentation metadata, the menu tree and its walk), `scijava-ui3` (toolkit-agnostic contracts), `scijava-desktop` | layer 0 |
693+
| **2. Toolkit bindings** | `scijava-swing`, `scijava-javafx`, headless | layer 1 |
694694
| **3. Application** | Fiji: which menus exist, branding, update sites, defaults | layer 2 |
695695

696696
Only layer 2 imports AWT or Swing. Layer 0 never mentions a user interface, so
@@ -917,6 +917,45 @@ after it.
917917
search field**, and the search field is not an afterthought: a command
918918
that is in no menu is still reachable, which the demo shell shows.
919919

920+
- **A second binding, `scijava-javafx`**, is what turns "toolkit-agnostic"
921+
from an assertion into a measurement. The whole of `scijava-ui3` survived it
922+
with **two changes**, both of which were Swing keeping something that was
923+
never Swing's:
924+
- `Widget.isLabeled()` - whether a parameter wants a label beside it is a
925+
statement about the parameter, and every toolkit would have answered it
926+
identically.
927+
- `WidgetPanel.showProblems(Map)` - how a problem *looks* is a toolkit's
928+
business, but that there is one, shown per parameter and cleared when
929+
fixed, is not.
930+
Everything else - `Widget`, `WidgetFactory`, `WidgetPanelFactory`,
931+
`WidgetPanels`, `Widgets`, `InputHarvester`, `MenuCreator`, `Menus` - was
932+
untouched, and `ParameterModel` and `ParameterTree` never came into
933+
question.
934+
935+
- **What the second binding had to do differently** is worth recording,
936+
because it is what a third will face too:
937+
- **The toolkit must be started, once**, and JavaFX has no `invokeAndWait`.
938+
`FxThread` is that plumbing, and it deliberately does not use
939+
`Application.launch`, which takes over the process and returns only when
940+
the last window closes - wrong for a binding that an application, a script
941+
or a test may use.
942+
- **`showAndWait` runs a nested event loop**, so the dialog must be built
943+
and shown in one visit to the JavaFX thread, where Swing wanted two.
944+
- **JavaFX spinners do not preserve a parameter's type** - their value
945+
factories are `Integer` or `Double` and nothing else - so the widget
946+
converts on the way out, and an editable spinner needs its editor watched
947+
or a typed value is silently lost when focus moves.
948+
- **Some things are simply easier**: a collapsible group is a `TitledPane`,
949+
where Swing needs a hand-rolled header button; `KeyCombination.SHORTCUT_DOWN`
950+
says what Swing needs a `Toolkit` call to compute.
951+
952+
- **`scijava-ui3-test` is the anti-drift mechanism**: the sample commands and
953+
a conformance suite that every binding extends - eight assertions about
954+
widgets, three about menus. Swing and JavaFX render the same declarations
955+
and are held to the same behavior, and a third binding starts by making the
956+
suite pass. A binding's own tests then cover only what is genuinely its own:
957+
which control it chose, how it parses an accelerator.
958+
920959
- **The application shell moves to layers 1 and 2**, it is not discarded:
921960
`ApplicationFrame`, `Desktop`, `StatusBar` and `ToolBar` are contracts in
922961
`scijava-ui3` and implementations in the toolkit bindings. What the core

‎docs/migration.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ A **dropped** row is a successful outcome, not a gap.
125125
| `command` | `org.scijava.command`: `Command` is a `Runnable` whose `@Parameter` fields are its struct; `@Menu` (repeatable) carries the presentation metadata, read from the annotation index without loading the class. `CommandInfo` replaces `ModuleInfo` and needs no `Context`; `MenuTree` replaces `ShadowMenu`. There is no `DynamicCommand`: see `choicesFrom` and `@Group(membersFrom)` | ported |
126126
| `script`, `script.process` | scripting facade + `javax.script` / GraalVM polyglot / Appose adapters (Phase 3) | planned |
127127
| `widget` (`InputWidget`, `InputPanel`, `InputHarvester`, `WidgetModel`, `WidgetStyle`) | `org.scijava.ui3`: `Widget` is a view of a `ParameterNode`, `WidgetFactory` a discoverable `@Plugin`, `WidgetPanel` a widget holding widgets (so a group nests with no special case), and `WidgetPanels` walks the tree for every toolkit. `WidgetModel` has no equivalent - a widget reads the `ParameterModel` and the node directly, and `WidgetStyle`'s parsing is `Widgets.isStyle`/`styleValue`. `InputHarvester` is a `Preprocessor` that declines the run when the user dismisses the dialog, rather than setting a `canceled` flag on itself | ported |
128+
| `ui.javafx` (satellite repo `scijava-ui-javafx`) | `org.scijava.javafx`: the same widget set as the Swing binding, plus `FxThread` for JavaFX's application thread. `JavaFXKeys`'s key-code mapping is worth keeping when the `input`/`tool` layer arrives; `JavaFXMenuCreator` is superseded by `FxMenus`, some 40 lines against `MenuCreator` | ported |
128129
| `ui.swing.widget` | `org.scijava.swing`: number (spinner, with an optional slider or scroll bar and labelled ticks), text (field, password, area, and `BigInteger`/`BigDecimal`, which a spinner cannot step), toggle, choice, file, message, and the panel and dialog. `SpinnerBigDecimalModel`, `SpinnerBigIntegerModel`, `SpinnerTypedNumberModel` and `SpinnerNumberModelFactory` have no equivalent: `SpinnerNumberModel` already steps in the type of the value it holds, and arbitrary precision goes to the text widget. MigLayout is gone, in favor of `GridBagLayout`: one fewer dependency, and one fewer automatic module. The button, color, date, file-list and radio-choice widgets are not ported yet - each earns its place when something asks for it | ported |
129130
| `menu` (`MenuCreator`, `AbstractMenuCreator`, `MenuService`, `ShadowMenu`) | `org.scijava.command`: `MenuTree` is the model and `MenuCreator`/`Menus` the toolkit-free walk, with `SwingMenus` the first implementation. `MenuService` has no equivalent: a menu bar is `MenuTree.of(Commands.discover(context))`, which is a line rather than a service | ported |
130131
| `ui`, `menu` | `scijava-ui3` (toolkit-agnostic contracts) and `scijava-menu` (the menu tree), with `ApplicationFrame`/`Desktop`/`StatusBar`/`ToolBar` as contracts there and implementations in the toolkit bindings. Dropped from the *core*, not from the stack — see the layering section of [migration-plan.md](migration-plan.md) | planned |

‎pom.xml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<module>scijava-harvest</module>
7272
<module>scijava-index</module>
7373
<module>scijava-io3</module>
74+
<module>scijava-javafx</module>
7475
<module>scijava-legacy</module>
7576
<module>scijava-meta</module>
7677
<module>scijava-ops-api</module>
@@ -89,6 +90,7 @@
8990
<module>scijava-testutil</module>
9091
<module>scijava-types</module>
9192
<module>scijava-ui3</module>
93+
<module>scijava-ui3-test</module>
9294
</modules>
9395

9496
<scm>

‎scijava-javafx/pom.xml‎

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.scijava</groupId>
7+
<artifactId>pom-scijava</artifactId>
8+
<version>44.0.0</version>
9+
<relativePath />
10+
</parent>
11+
12+
<artifactId>scijava-javafx</artifactId>
13+
<version>1.0.0-SNAPSHOT</version>
14+
15+
<name>SciJava JavaFX</name>
16+
<description>JavaFX widgets, and a dialog to harvest inputs with them.</description>
17+
<url>https://github.com/scijava/scijava</url>
18+
<inceptionYear>2026</inceptionYear>
19+
<organization>
20+
<name>SciJava</name>
21+
<url>https://scijava.org/</url>
22+
</organization>
23+
<licenses>
24+
<license>
25+
<name>Simplified BSD License</name>
26+
<distribution>repo</distribution>
27+
</license>
28+
</licenses>
29+
30+
<developers>
31+
<developer>
32+
<id>ctrueden</id>
33+
<name>Curtis Rueden</name>
34+
<roles>
35+
<role>founder</role>
36+
<role>lead</role>
37+
<role>reviewer</role>
38+
<role>support</role>
39+
<role>maintainer</role>
40+
</roles>
41+
</developer>
42+
<developer>
43+
<id>gselzer</id>
44+
<name>Gabriel Selzer</name>
45+
<roles>
46+
<role>founder</role>
47+
<role>debugger</role>
48+
<role>reviewer</role>
49+
<role>support</role>
50+
</roles>
51+
</developer>
52+
</developers>
53+
<contributors>
54+
<contributor>
55+
<name>Johannes Schindelin</name>
56+
<properties><id>dscho</id></properties>
57+
</contributor>
58+
</contributors>
59+
60+
<mailingLists>
61+
<mailingList>
62+
<name>Image.sc Forum</name>
63+
<archive>https://forum.image.sc/tag/scijava</archive>
64+
</mailingList>
65+
</mailingLists>
66+
67+
<scm>
68+
<connection>scm:git:https://github.com/scijava/scijava</connection>
69+
<developerConnection>scm:git:git@github.com:scijava/scijava</developerConnection>
70+
<tag>HEAD</tag>
71+
<url>https://github.com/scijava/scijava</url>
72+
</scm>
73+
<issueManagement>
74+
<system>GitHub Issues</system>
75+
<url>https://github.com/scijava/scijava/issues</url>
76+
</issueManagement>
77+
<ciManagement>
78+
<system>GitHub Actions</system>
79+
<url>https://github.com/scijava/scijava/actions</url>
80+
</ciManagement>
81+
82+
<properties>
83+
<package-name>org.scijava.javafx</package-name>
84+
85+
<license.licenseName>bsd_2</license.licenseName>
86+
<license.copyrightOwners>SciJava developers.</license.copyrightOwners>
87+
88+
<!-- NB: JavaFX 18+ requires Java 17+, but this component targets Java 11. -->
89+
<javafx.version>17.0.21</javafx.version>
90+
91+
<!-- Note: These versions must match across all component POMs! -->
92+
<scijava-command.version>1.0.0-SNAPSHOT</scijava-command.version>
93+
<scijava-context.version>1.0.0-SNAPSHOT</scijava-context.version>
94+
<scijava-discovery.version>1.0.1-SNAPSHOT</scijava-discovery.version>
95+
<scijava-index.version>1.0.0-SNAPSHOT</scijava-index.version>
96+
<scijava-ui3.version>3.0.0-SNAPSHOT</scijava-ui3.version>
97+
<scijava-ui3-test.version>3.0.0-SNAPSHOT</scijava-ui3-test.version>
98+
<scijava-common3.version>1.0.1-SNAPSHOT</scijava-common3.version>
99+
<scijava-execute.version>1.0.0-SNAPSHOT</scijava-execute.version>
100+
<scijava-harvest.version>1.0.0-SNAPSHOT</scijava-harvest.version>
101+
<scijava-priority.version>1.0.1-SNAPSHOT</scijava-priority.version>
102+
<scijava-struct.version>1.0.1-SNAPSHOT</scijava-struct.version>
103+
</properties>
104+
105+
<dependencies>
106+
<dependency>
107+
<groupId>org.scijava</groupId>
108+
<artifactId>scijava-common3</artifactId>
109+
<version>${scijava-common3.version}</version>
110+
</dependency>
111+
<dependency>
112+
<groupId>org.scijava</groupId>
113+
<artifactId>scijava-command</artifactId>
114+
<version>${scijava-command.version}</version>
115+
</dependency>
116+
<dependency>
117+
<groupId>org.scijava</groupId>
118+
<artifactId>scijava-context</artifactId>
119+
<version>${scijava-context.version}</version>
120+
</dependency>
121+
<dependency>
122+
<groupId>org.scijava</groupId>
123+
<artifactId>scijava-discovery</artifactId>
124+
<version>${scijava-discovery.version}</version>
125+
</dependency>
126+
<dependency>
127+
<groupId>org.scijava</groupId>
128+
<artifactId>scijava-index</artifactId>
129+
<version>${scijava-index.version}</version>
130+
</dependency>
131+
<dependency>
132+
<groupId>org.scijava</groupId>
133+
<artifactId>scijava-ui3</artifactId>
134+
<version>${scijava-ui3.version}</version>
135+
</dependency>
136+
<dependency>
137+
<groupId>org.scijava</groupId>
138+
<artifactId>scijava-execute</artifactId>
139+
<version>${scijava-execute.version}</version>
140+
</dependency>
141+
<dependency>
142+
<groupId>org.scijava</groupId>
143+
<artifactId>scijava-harvest</artifactId>
144+
<version>${scijava-harvest.version}</version>
145+
</dependency>
146+
<dependency>
147+
<groupId>org.scijava</groupId>
148+
<artifactId>scijava-priority</artifactId>
149+
<version>${scijava-priority.version}</version>
150+
</dependency>
151+
<dependency>
152+
<groupId>org.scijava</groupId>
153+
<artifactId>scijava-struct</artifactId>
154+
<version>${scijava-struct.version}</version>
155+
</dependency>
156+
157+
<!-- Third-party dependencies -->
158+
<dependency>
159+
<groupId>org.openjfx</groupId>
160+
<artifactId>javafx-base</artifactId>
161+
<version>${javafx-base.version}</version>
162+
</dependency>
163+
<dependency>
164+
<groupId>org.openjfx</groupId>
165+
<artifactId>javafx-graphics</artifactId>
166+
<version>${javafx-graphics.version}</version>
167+
</dependency>
168+
<dependency>
169+
<groupId>org.openjfx</groupId>
170+
<artifactId>javafx-controls</artifactId>
171+
<version>${javafx-controls.version}</version>
172+
</dependency>
173+
<dependency>
174+
<groupId>org.slf4j</groupId>
175+
<artifactId>slf4j-api</artifactId>
176+
</dependency>
177+
178+
<!-- Test scope dependencies -->
179+
<dependency>
180+
<groupId>org.scijava</groupId>
181+
<artifactId>scijava-ui3-test</artifactId>
182+
<version>${scijava-ui3-test.version}</version>
183+
<scope>test</scope>
184+
</dependency>
185+
<!--
186+
NB: so that the demos can say what they are doing. Turn it up with
187+
-Dorg.slf4j.simpleLogger.defaultLogLevel=debug
188+
-->
189+
<dependency>
190+
<groupId>org.slf4j</groupId>
191+
<artifactId>slf4j-simple</artifactId>
192+
<scope>test</scope>
193+
</dependency>
194+
<dependency>
195+
<groupId>org.junit.jupiter</groupId>
196+
<artifactId>junit-jupiter-api</artifactId>
197+
<scope>test</scope>
198+
</dependency>
199+
</dependencies>
200+
201+
<build>
202+
<plugins>
203+
<!--
204+
NB: the annotation index comes from scijava-index's annotation
205+
processor, which must be on the processor path: javac will not find
206+
it on the module path, and says nothing when it finds no processor at
207+
all, so the build would simply produce no index.
208+
-->
209+
<plugin>
210+
<artifactId>maven-compiler-plugin</artifactId>
211+
<configuration>
212+
<annotationProcessorPaths>
213+
<path>
214+
<groupId>org.scijava</groupId>
215+
<artifactId>scijava-index</artifactId>
216+
<version>${scijava-index.version}</version>
217+
</path>
218+
</annotationProcessorPaths>
219+
</configuration>
220+
</plugin>
221+
<plugin>
222+
<artifactId>maven-enforcer-plugin</artifactId>
223+
<executions>
224+
<execution>
225+
<id>enforce-package-rules</id>
226+
<goals>
227+
<goal>enforce</goal>
228+
</goals>
229+
<phase>test</phase>
230+
<configuration>
231+
<rules>
232+
<NoPackageCyclesRule implementation="org.scijava.maven.plugin.enforcer.NoPackageCyclesRule" />
233+
<NoSubpackageDependenceRule implementation="org.scijava.maven.plugin.enforcer.NoSubpackageDependenceRule" />
234+
</rules>
235+
</configuration>
236+
</execution>
237+
</executions>
238+
</plugin>
239+
<plugin>
240+
<artifactId>maven-javadoc-plugin</artifactId>
241+
<configuration>
242+
<links>
243+
<link>https://javadoc.scijava.org/Java11/</link>
244+
</links>
245+
</configuration>
246+
</plugin>
247+
</plugins>
248+
</build>
249+
</project>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* #%L
3+
* JavaFX widgets, and a dialog to harvest inputs with them.
4+
* %%
5+
* Copyright (C) 2026 SciJava developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
30+
module org.scijava.javafx {
31+
32+
exports org.scijava.javafx;
33+
34+
// NB: one opens, to the container alone, so that it can inject and
35+
// construct these plugins. `opens` is not `exports`.
36+
opens org.scijava.javafx to org.scijava.context;
37+
38+
requires transitive javafx.base;
39+
requires transitive javafx.controls;
40+
requires transitive javafx.graphics;
41+
requires transitive org.scijava.ui3;
42+
requires transitive org.scijava.command;
43+
requires transitive org.scijava.context;
44+
requires org.scijava.discovery;
45+
requires org.scijava.priority;
46+
requires org.slf4j;
47+
48+
}

0 commit comments

Comments
 (0)