-
Notifications
You must be signed in to change notification settings - Fork 11
Using the style to format number in the swing UI. #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,11 @@ else if (model.isStyle(NumberWidget.SLIDER_STYLE)) { | |
final SpinnerNumberModel spinnerModel = | ||
new SpinnerNumberModelFactory().createModel(value, min, max, stepSize); | ||
spinner = new JSpinner(spinnerModel); | ||
String format = getFormat(model); | ||
if (format != null) { | ||
spinner.setEditor(new JSpinner.NumberEditor(spinner, format)); | ||
} | ||
|
||
Dimension spinnerSize = spinner.getSize(); | ||
spinnerSize.width = 50; | ||
spinner.setPreferredSize(spinnerSize); | ||
|
@@ -132,6 +137,17 @@ else if (model.isStyle(NumberWidget.SLIDER_STYLE)) { | |
syncSliders(); | ||
} | ||
|
||
private String getFormat(WidgetModel model) { | ||
final String widgetStyle = model.getItem().getWidgetStyle(); | ||
String format = null; | ||
for (final String s : widgetStyle.split(",")) { | ||
if (s.startsWith("format:")) { | ||
format = s.substring(s.indexOf(":") + 1).trim(); | ||
} | ||
} | ||
Comment on lines
+143
to
+147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With scijava/scijava-common#384, I tried to centralize parsing of the To keep the code base as DRY as possible, I suggest relying on that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @imagejan , basically that does sound like a good idea, but that PR has been open since April. We would rather have this be merged and available sometime soon and when your widget style becomes available, start using it as of then. We are however not sure what the release cycle is. Is there a chance we can get this code released earlier if we keep it contained to just ui-swing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I merged scijava/scijava-common#384 and released scijava-common 2.85.0. @sunsear @BoudewijnvanLangerak Could you please add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With scijava/scijava-common#405, it should be possible to replace this WidgetStyle.getStyleModifier(model.getItem().getWidgetStyle(), "format") |
||
return format; | ||
} | ||
|
||
// -- Typed methods -- | ||
|
||
@Override | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to have some sensible guessing on the format (based on
min
,max
and/or default value) in caseformat
isnull
here.