Skip to content

Commit 0a57e16

Browse files
ctruedenclaude
andcommitted
Fix the widget bugs the demos turned up, and fill in the gaps
The empty dialogs were not a widget bug: with no annotation index on the classpath no widget factory is discovered, and the dialog comes up with nothing but OK and Cancel. javac writes that index only when scijava-index is on the annotation processor path, and says nothing at all when it is not, so the harvester now says it -- naming the file -- and `WidgetPanels` warns about any parameter no factory accepted. Both through SLF4J, with slf4j-simple as a test dependency so the demos log: -Dorg.slf4j.simpleLogger.defaultLogLevel=debug The stale choices were real. A widget held the `ParameterNode` it was built from, but `ParameterModel` builds a new tree on every `set`; where the tree's shape was unchanged nothing rebuilt, so a chooser went on asking a dead node for its values while the model had already moved on. `SwingWidget.node()` now reads its node back out of the current tree. Dialog behavior, from watching one: it never moves and never shrinks after the first build -- it may grow for parameters that have just appeared, but re-centring or closing up around a collapsed group moves the controls out from under the pointer. The scroll pane's border is gone, and the widgets hug the top, a GridBagLayout having otherwise centered its rows in whatever height the dialog was dragged to. Gaps filled, all of them things SciJava Common had: - a scroll bar as well as a slider, and labelled tick marks (`style = "slider,ticks:4"`); - `softMin`/`softMax`, so the slider spans the useful range while the spinner still enforces the permitted one; - enums, whose constants are their choices -- resolved in `ParameterTree`, so every toolkit gets it and no annotation repeats what the enum already says; - `BigInteger` and `BigDecimal`, which go to the text widget and are parsed exactly, a spinner being unable to step them; - `char`, and boxed numbers alongside primitive ones; - message rows (`style = "message"`), whose value a callback may rewrite. And a seventh demo, the one worth having: width, height and a lock aspect ratio checkbox, with a message row showing the live ratio. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013gJpzGd3ksbME4CN6Tu2ni
1 parent 58fd161 commit 0a57e16

24 files changed

Lines changed: 599 additions & 59 deletions

File tree

‎docs/migration-plan.md‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -845,10 +845,30 @@ after it.
845845
- **MigLayout is gone**, replaced by `GridBagLayout`: two-column label-field
846846
layout is not worth a third-party dependency, still less an automatic
847847
module in a JPMS build.
848-
- **Six widgets so far** — number (spinner, with an optional slider), text
849-
(field, password, area), toggle, choice, file, and the panel itself. The
850-
button, color, date, file-list, message and radio-choice widgets are not
851-
ported; each earns its place when something asks for it.
848+
- **Seven widgets so far** — number (spinner, with an optional slider or
849+
scroll bar, and labelled tick marks), text (field, password, area, and the
850+
arbitrary-precision numbers a spinner cannot step), toggle, choice, file,
851+
message, and the panel itself. The button, color, date, file-list and
852+
radio-choice widgets are not ported; each earns its place when something
853+
asks for it.
854+
- **An enum needs no annotation**: its constants are its choices, resolved
855+
in `ParameterTree` so every toolkit gets it. `softMin`/`softMax` bound the
856+
slider where the permitted range is far wider than the useful one, while
857+
the spinner still enforces the hard `min`/`max`.
858+
- **A widget reads its node out of the current tree**, not the one it was
859+
built from. The tree is rebuilt on every `set`, so a captured node goes
860+
stale — and since `ParameterModel` rebuilds the widgets only when the
861+
tree's *shape* changes, a parameter whose computed choices changed while
862+
its shape did not would otherwise keep offering the old values.
863+
- **The dialog never moves and never shrinks.** After the first build it may
864+
grow, to make room for parameters that have just appeared, but a dialog
865+
that re-centred itself, or closed up around a group the user had just
866+
collapsed, would move the controls out from under the pointer.
867+
- **An empty dialog says why.** A missing annotation index — javac produces
868+
one only when scijava-index is on the annotation processor path, and says
869+
nothing when it is not — means no widget factories are discovered, and the
870+
dialog comes up with nothing but OK and Cancel. That is now a warning
871+
naming the missing index, as is a parameter no factory accepted.
852872
- **Style hints are advisory strings** (`@Parameter(style = "slider")`,
853873
`"format:0.00"`), which a toolkit is free to ignore, so a parameter styled
854874
for Swing still renders elsewhere. `min`, `max` and `stepSize` are strings

‎docs/migration.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ A **dropped** row is a successful outcome, not a gap.
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 |
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.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 |
128+
| `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 |
129129
| `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 |
130130
| `input`, `tool` | UI-agnostic facades on `scijava-events` (Phase 4) | planned |
131131
| `display` | overhauled, not ported (Phase 4) | open |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ public Map<String, String> attrs() {
136136
put(attrs, MIN, parameter.min());
137137
put(attrs, MAX, parameter.max());
138138
put(attrs, STEP_SIZE, parameter.stepSize());
139+
put(attrs, SOFT_MIN, parameter.softMin());
140+
put(attrs, SOFT_MAX, parameter.softMax());
139141
put(attrs, STYLE, parameter.style());
140142
return attrs;
141143
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@
132132
/** How far one step moves a numeric parameter, in a spinner or slider. */
133133
String stepSize() default "";
134134

135+
/**
136+
* The smallest value a slider should span, where the useful range is
137+
* narrower than the permitted one.
138+
* <p>
139+
* A slider between 0 and {@link Integer#MAX_VALUE} is unusable, so a
140+
* parameter may say that its interesting values stop at 100 while still
141+
* accepting a larger one typed into the spinner.
142+
* </p>
143+
*/
144+
String softMin() default "";
145+
146+
/** The largest value a slider should span. @see #softMin() */
147+
String softMax() default "";
148+
135149
/**
136150
* A hint about how to display this parameter, for a user interface to
137151
* interpret: {@code "slider"}, {@code "password"}, {@code "directory"}.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ public interface ParameterMember<T> extends Member<T> {
8181
/** Metadata key: how far one step moves a numeric parameter. */
8282
String STEP_SIZE = "stepSize";
8383

84+
/** Metadata key: the smallest value a slider should span. */
85+
String SOFT_MIN = "softMin";
86+
87+
/** Metadata key: the largest value a slider should span. */
88+
String SOFT_MAX = "softMax";
89+
8490
/** Metadata key: a hint about how to display this parameter. */
8591
String STYLE = "style";
8692

‎scijava-harvest/pom.xml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,17 @@
8686
<license.copyrightOwners>SciJava developers.</license.copyrightOwners>
8787

8888
<!-- Note: These versions must match across all component POMs! -->
89+
<scijava-common3.version>1.0.1-SNAPSHOT</scijava-common3.version>
8990
<scijava-execute.version>1.0.0-SNAPSHOT</scijava-execute.version>
9091
<scijava-struct.version>1.0.1-SNAPSHOT</scijava-struct.version>
9192
</properties>
9293

9394
<dependencies>
95+
<dependency>
96+
<groupId>org.scijava</groupId>
97+
<artifactId>scijava-common3</artifactId>
98+
<version>${scijava-common3.version}</version>
99+
</dependency>
94100
<dependency>
95101
<groupId>org.scijava</groupId>
96102
<artifactId>scijava-execute</artifactId>

‎scijava-harvest/src/main/java/module-info.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@
3333

3434
requires transitive org.scijava.execute;
3535
requires transitive org.scijava.struct;
36+
requires org.scijava.common3;
3637

3738
}

‎scijava-harvest/src/main/java/org/scijava/harvest/ParameterTree.java‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,18 @@ private List<Object> choices(final MemberInstance<?> member) {
208208
final Optional<Behavior> behavior = executable.behavior(from.get());
209209
if (behavior.isPresent()) return asList(behavior.get().invoke());
210210
}
211-
return attr(member, ParameterMember.CHOICES) //
212-
.map(csv -> (List<Object>) new ArrayList<Object>(List.of(csv.split(
213-
",")))) //
214-
.orElse(List.of());
211+
final Optional<String> declared = attr(member, ParameterMember.CHOICES);
212+
if (declared.isPresent()) {
213+
return new ArrayList<>(List.of(declared.get().split(",")));
214+
}
215+
// NB: an enum declares its own values, so asking for them again in an
216+
// annotation would only be a chance to get them wrong.
217+
final Class<?> type = org.scijava.common3.Types.raw(member.member()
218+
.type());
219+
if (type != null && type.isEnum()) {
220+
return new ArrayList<>(List.of(type.getEnumConstants()));
221+
}
222+
return List.of();
215223
}
216224

217225
private static List<Object> asList(final Object result) {

‎scijava-swing/pom.xml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,22 @@
144144
<version>${scijava-struct.version}</version>
145145
</dependency>
146146

147+
<!-- Third-party dependencies -->
148+
<dependency>
149+
<groupId>org.slf4j</groupId>
150+
<artifactId>slf4j-api</artifactId>
151+
</dependency>
152+
147153
<!-- Test scope dependencies -->
154+
<!--
155+
NB: so that the demos can say what they are doing. Turn it up with
156+
-Dorg.slf4j.simpleLogger.defaultLogLevel=debug
157+
-->
158+
<dependency>
159+
<groupId>org.slf4j</groupId>
160+
<artifactId>slf4j-simple</artifactId>
161+
<scope>test</scope>
162+
</dependency>
148163
<dependency>
149164
<groupId>org.junit.jupiter</groupId>
150165
<artifactId>junit-jupiter-api</artifactId>

‎scijava-swing/src/main/java/module-info.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@
4040
requires transitive org.scijava.context;
4141
requires org.scijava.discovery;
4242
requires org.scijava.priority;
43+
requires org.slf4j;
4344

4445
}

0 commit comments

Comments
 (0)