Skip to content

Commit 3f329e3

Browse files
ctruedenclaude
andcommitted
scijava-ui3 and scijava-swing: widgets, and dialogs to click on
The contracts first, toolkit-free: - `Widget` is a view of a `ParameterNode`, and that is all. There is no `WidgetModel`: SciJava Common needed one because a widget could not see the module, whereas a widget here reads the node for label, bounds, style and resolved choices, and writes through `ParameterModel`. Writing through the model is what runs callbacks and reshapes the dialog, so a widget earns the dynamic behavior by doing nothing clever. - `WidgetPanel` *is* a `Widget`, so a group nests in its parent's list with no special case, however deep. `WidgetPanels` walks the tree once for every toolkit; a binding supplies factories and nothing else. - `InputHarvester` is a `Preprocessor`. A dismissed dialog calls `Execution.decline`, an ordinary outcome the `ExecutionResult` reports, rather than a `canceled` flag on a stateful preprocessor. Then Swing: number (spinner, optional slider), text (field, password, area), toggle, choice, file, the panel and the dialog. MigLayout is gone in favor of `GridBagLayout` -- two columns of labels and fields are not worth a third-party dependency, still less an automatic module in a JPMS build. The button, color, date, file-list, message and radio-choice widgets are not ported; each earns its place when something asks. Three changes fell out of meeting a toolkit: - `@Parameter` gains `min`, `max`, `stepSize` and `style`. All strings, because metadata has to survive a script header; `Widgets` reads the bounds back in the parameter's own type, and style hints are advisory, so a parameter styled for Swing still renders elsewhere. - `Execution.executable()` returns `ExecutableInstance` rather than `Object`. Its one caller already cast it. - `Executables.executableOf` takes a lookup, so an object run through a container needs no `opens` beyond the one its module already declares. `Demos` in the test sources puts each tricky behavior on screen, with a launcher window and a `main` that takes a demo's name: mvn -o -pl scijava-swing test-compile exec:java \ -Dexec.classpathScope=test -Dexec.mainClass=org.scijava.swing.Demos The kitchen sink, an advanced toggle, a generated group, computed choices, live validation, and two values that keep each other in step. `SwingWidgetsTest` covers the same six headlessly. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013gJpzGd3ksbME4CN6Tu2ni
1 parent bd23694 commit 3f329e3

39 files changed

Lines changed: 3391 additions & 14 deletions

‎docs/migration-plan.md‎

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ unless it says there is no replacement at all, which it says explicitly.
693693
| Layer | Contents | Depends on |
694694
| --- | --- | --- |
695695
| **0. Foundation** (built) | `spi`, `common3`, `collections`, `priority`, `progress`, `concurrent`, `discovery`, `index`, `struct`, `io3`, `events`, `context`, `execute` | nothing above |
696-
| **1. Application model** (to build) | `scijava-command` (a struct plus presentation metadata), `scijava-menu` (the menu tree), `scijava-ui-api` (toolkit-agnostic contracts), `scijava-desktop` | layer 0 |
696+
| **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 |
697697
| **2. Toolkit bindings** | `scijava-ui-swing`, JavaFX, headless | layer 1 |
698698
| **3. Application** | Fiji: which menus exist, branding, update sites, defaults | layer 2 |
699699

@@ -825,8 +825,43 @@ after it.
825825
where its first member would, and a generated group needs an explicit
826826
`after` anchor); `ParameterModel` decides the tree changed by comparing
827827
`toString()`, which is right for correctness and wrong for a UI that should
828-
patch rather than rebuild; and nothing here has met a toolkit yet, which is
829-
where the prototype's `WidgetFactory`/`WidgetPanelFactory` return.
828+
patch rather than rebuild — the Swing dialog rebuilds its widgets whenever
829+
the tree changes, which is correct and loses focus on a parameter whose
830+
callback reshapes the dialog.
831+
832+
- **`scijava-ui3`** (`org.scijava.ui3`) and **`scijava-swing`**
833+
(`org.scijava.swing`): the contracts, and the first toolkit to meet them.
834+
**Built**, and the shape of the split is the point:
835+
- `Widget` is a view of a `ParameterNode`, and that is all it is. There is no
836+
`WidgetModel`: SciJava Common needed one because a widget could not see the
837+
module, whereas a widget here reads the node for label, description,
838+
bounds, style and resolved choices, and writes through `ParameterModel`.
839+
Writing through the model is what makes callbacks run and the dialog
840+
reshape itself, so a widget gets the dynamic behavior by not doing anything
841+
clever.
842+
- `WidgetPanel` **is a `Widget`**, so a group nests in its parent's list with
843+
no special case, however deep. `WidgetPanels` walks the tree the same way
844+
for every toolkit; a binding supplies factories and a panel factory, some
845+
150 lines of tree-walking it no longer writes.
846+
- `InputHarvester` is a `Preprocessor`. Dismissing the dialog is
847+
`Execution.decline`, an ordinary outcome that the `ExecutionResult`
848+
reports, rather than a `canceled` flag on a stateful preprocessor.
849+
- **MigLayout is gone**, replaced by `GridBagLayout`: two-column label-field
850+
layout is not worth a third-party dependency, still less an automatic
851+
module in a JPMS build.
852+
- **Six widgets so far** — number (spinner, with an optional slider), text
853+
(field, password, area), toggle, choice, file, and the panel itself. The
854+
button, color, date, file-list, message and radio-choice widgets are not
855+
ported; each earns its place when something asks for it.
856+
- **Style hints are advisory strings** (`@Parameter(style = "slider")`,
857+
`"format:0.00"`), which a toolkit is free to ignore, so a parameter styled
858+
for Swing still renders elsewhere. `min`, `max` and `stepSize` are strings
859+
too, read back in the parameter's own type — because metadata has to
860+
survive a script header.
861+
- **Demos with `main()`** (`Demos` in the test sources) put each tricky
862+
behavior on screen: the kitchen sink, the advanced toggle, the generated
863+
group, computed choices, live validation, and two values that keep each
864+
other in step.
830865

831866
- **Input harvesting is a headline deliverable**, not a port. It is the
832867
workhorse that lets Fiji users write scripts without UI-specific concerns.
@@ -838,7 +873,7 @@ after it.
838873
`org.scijava.widget` as written.
839874
- **The application shell moves to layers 1 and 2**, it is not discarded:
840875
`ApplicationFrame`, `Desktop`, `StatusBar` and `ToolBar` are contracts in
841-
`scijava-ui-api` and implementations in the toolkit bindings. What the core
876+
`scijava-ui3` and implementations in the toolkit bindings. What the core
842877
drops is any knowledge that they exist.
843878
- **`input` and `tool`** are re-framed, not frozen: UI-agnostic facades over
844879
GUI concepts, layered on `scijava-events`, letting code listen for GUI
@@ -872,7 +907,7 @@ after it.
872907
| `module`, `command` | → execution layer (Phase 3) |
873908
| `script` | → scripting facade + adapters (Phase 3) |
874909
| `widget` | → input harvesting, redesigned (Phase 4) |
875-
| `ui`, `menu` | `scijava-ui-api` contracts and `scijava-menu` (layer 1), with toolkit bindings in layer 2 (Phase 4) |
910+
| `ui`, `menu` | `scijava-ui3` contracts and `scijava-menu` (layer 1), with toolkit bindings in layer 2 (Phase 4) |
876911
| `input`, `tool` | Re-framed as UI-agnostic facades (Phase 4) |
877912
| `display` | Overhauled, not ported (Phase 4) |
878913
| `platform`, `ui.dnd` | `scijava-desktop` modernization (Phase 4) |

‎docs/migration.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ A **dropped** row is a successful outcome, not a gap.
124124
| `module`, `module.process` | `org.scijava.execute`: `@Parameter` on fields, `Executables` for the plain case, and `Runner` for the processor chain. `ModuleService.run` becomes `Runner.run`, still returning a future, but of an `ExecutionResult` that reports a declined run with its reason and its author rather than through `ModulePreprocessor.isCanceled()` | ported |
125125
| `command` | still to come: a command is a struct plus menu metadata plus `run` | planned |
126126
| `script`, `script.process` | scripting facade + `javax.script` / GraalVM polyglot / Appose adapters (Phase 3) | planned |
127-
| `widget` | input harvesting on `scijava-struct`, with dynamic subgroups (Phase 4) | planned |
128-
| `ui`, `menu` | `scijava-ui-api` (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 |
127+
| `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.swing.widget` | `org.scijava.swing`: number (spinner, optional slider), text (field, password, area), toggle, choice, file, and the panel and dialog. MigLayout is gone, in favor of `GridBagLayout`: one fewer dependency, and one fewer automatic module. The button, color, date, file-list, message and radio-choice widgets are not ported yet - each earns its place when something asks for it | ported |
129+
| `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 |
129130
| `input`, `tool` | UI-agnostic facades on `scijava-events` (Phase 4) | planned |
130131
| `display` | overhauled, not ported (Phase 4) | open |
131132
| `platform`, `ui.dnd` | `scijava-desktop` modernization (Phase 4) | planned |

‎pom.xml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@
8686
<module>scijava-progress</module>
8787
<module>scijava-spi</module>
8888
<module>scijava-struct</module>
89+
<module>scijava-swing</module>
8990
<module>scijava-testutil</module>
9091
<module>scijava-types</module>
92+
<module>scijava-ui3</module>
9193
</modules>
9294

9395
<scm>

‎scijava-execute/src/main/java/org/scijava/execute/Executables.java‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,23 @@ public static Executable of(final Class<? extends Runnable> type,
9494
* </p>
9595
*/
9696
public static Executable executableOf(final Runnable object) {
97-
final Struct struct = struct(object.getClass());
97+
return executableOf(object, null);
98+
}
99+
100+
/**
101+
* Describes an already-constructed object as an {@link Executable},
102+
* reflecting into it through the given lookup.
103+
*
104+
* @param object the object to run
105+
* @param lookup a lookup with private access to its class, as
106+
* {@code Access.lookupIn} provides, or null to reflect with this
107+
* module's own access
108+
* @see #executableOf(Runnable)
109+
*/
110+
public static Executable executableOf(final Runnable object,
111+
final java.lang.invoke.MethodHandles.Lookup lookup)
112+
{
113+
final Struct struct = struct(object.getClass(), lookup);
98114
return new Executable() {
99115

100116
@Override
@@ -114,7 +130,7 @@ public ExecutableInstance create() {
114130

115131
@Override
116132
public Executable executable() {
117-
return Executables.executableOf(object);
133+
return Executables.executableOf(object, lookup);
118134
}
119135

120136
@Override
@@ -129,7 +145,7 @@ public void run() {
129145

130146
@Override
131147
public java.util.Optional<Behavior> behavior(final String name) {
132-
return JavaExecutable.behaviorOf(object.getClass(), null, object,
148+
return JavaExecutable.behaviorOf(object.getClass(), lookup, object,
133149
name);
134150
}
135151
};

‎scijava-execute/src/main/java/org/scijava/execute/Execution.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
*/
4343
public interface Execution {
4444

45-
/** Gets the object being run. */
46-
Object executable();
45+
/** Gets the thing being run, whose parameters and behaviors it carries. */
46+
ExecutableInstance executable();
4747

4848
/** Gets its parameters, bound to their values. */
4949
StructInstance<?> instance();

‎scijava-execute/src/main/java/org/scijava/execute/FieldParameterMember.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ public Map<String, String> attrs() {
133133
put(attrs, GROUP, parameter.group());
134134
put(attrs, CHOICES, String.join(",", parameter.choices()));
135135
put(attrs, CHOICES_FROM, parameter.choicesFrom());
136+
put(attrs, MIN, parameter.min());
137+
put(attrs, MAX, parameter.max());
138+
put(attrs, STEP_SIZE, parameter.stepSize());
139+
put(attrs, STYLE, parameter.style());
136140
return attrs;
137141
}
138142

‎scijava-execute/src/main/java/org/scijava/execute/Parameter.java‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,25 @@
122122
* </p>
123123
*/
124124
String choicesFrom() default "";
125+
126+
/** The smallest value this parameter may take, for a numeric parameter. */
127+
String min() default "";
128+
129+
/** The largest value this parameter may take, for a numeric parameter. */
130+
String max() default "";
131+
132+
/** How far one step moves a numeric parameter, in a spinner or slider. */
133+
String stepSize() default "";
134+
135+
/**
136+
* A hint about how to display this parameter, for a user interface to
137+
* interpret: {@code "slider"}, {@code "password"}, {@code "directory"}.
138+
* <p>
139+
* Several hints are separated by commas, and one may carry a value after a
140+
* colon: {@code "slider,format:0.00"}. A user interface ignores hints it
141+
* does not recognize, so a parameter styled for one toolkit still renders
142+
* in another.
143+
* </p>
144+
*/
145+
String style() default "";
125146
}

‎scijava-execute/src/main/java/org/scijava/execute/ParameterMember.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ public interface ParameterMember<T> extends Member<T> {
7272
/** Metadata key: the behavior producing the values it may take. */
7373
String CHOICES_FROM = "choicesFrom";
7474

75+
/** Metadata key: the smallest value a numeric parameter may take. */
76+
String MIN = "min";
77+
78+
/** Metadata key: the largest value a numeric parameter may take. */
79+
String MAX = "max";
80+
81+
/** Metadata key: how far one step moves a numeric parameter. */
82+
String STEP_SIZE = "stepSize";
83+
84+
/** Metadata key: a hint about how to display this parameter. */
85+
String STYLE = "style";
86+
7587
/** Gets this parameter's metadata. */
7688
Map<String, String> attrs();
7789

‎scijava-execute/src/main/java/org/scijava/execute/Runner.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ void complete(final Map<String, Object> outputs) {
215215
}
216216

217217
@Override
218-
public Object executable() {
218+
public ExecutableInstance executable() {
219219
return instance;
220220
}
221221

‎scijava-execute/src/test/java/org/scijava/execute/ScriptLikeExecutableTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public void testAScriptShapedExecutableRuns() throws Exception {
182182
public void testProcessorsApplyToScriptsToo() throws Exception {
183183
final List<String> seen = new ArrayList<>();
184184
final Preprocessor filler = execution -> {
185-
seen.add(((ExecutableInstance) execution.executable()).executable()
185+
seen.add(execution.executable().executable()
186186
.name());
187187
execution.instance().member("name").set("grace");
188188
};

0 commit comments

Comments
 (0)