java.lang.Object
imagingbook.common.ij.DialogUtils
Utility methods and annotations related to ImageJ's
GenericDialog
class.- Version:
- 2022/09/14
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interface
Annotation to specify the number of digits (value) displayed when showing numeric values in dialogs.static @interface
Annotation to hide the following parameter field in dialogs.static @interface
Annotation to specify a specific 'label' (value) to be shown for following parameter fields.static @interface
Annotation to specify the number of "columns" (value) displayed when showing string items in dialogs. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addToDialog
(ParameterBundle<?> params, GenericDialog gd) Adds all qualified fields of the givenParameterBundle
to the specifiedGenericDialog
instance, in the exact order of their definition.static boolean
static boolean
askForSampleImage
(ImageResource suggested) Opens a very specific dialog asking if the suggested sample image (resource) should be opened and made the active image.static boolean
askYesOrCancel
(String title, String message) Deprecated.static String
formatText
(int columns, String... textChunks) Splits a long string into multiple lines of the specified maximum length and builds a new string with newline (\n) characters separating successive lines.static boolean
getFromDialog
(ParameterBundle<?> params, GenericDialog gd) Retrieves the field values of the specifiedParameterBundle
from theGenericDialog
instance.static String
makeHtmlString
(String... textLines) Creates a HTML string by formatting the supplied string(s) as individual text lines separated by <br>.static String
makeLineSeparatedString
(String... lines) Creates a string by formatting the supplied strings as individual text lines separated by newline.static String[]
splitTextToLines
(int columns, String input) Splits a long string into multiple lines of the specified maximum length.
-
Method Details
-
splitTextToLines
Splits a long string into multiple lines of the specified maximum length. The result is returned as aString[]
with one element per text line. Multiple input strings are first joined into a single string using blank spaces as separators. Inspired by: https://stackoverflow.com/a/21002193- Parameters:
columns
- the maximum number of characters per lineinput
- the input text to be decomposed- Returns:
- a
String[]
with one element per text line
-
formatText
Splits a long string into multiple lines of the specified maximum length and builds a new string with newline (\n) characters separating successive lines. Multiple input strings are first joined into a single string using blank spaces as separators. Intended mainly to format message texts of plugin dialogs.- Parameters:
columns
- the maximum number of characters per linetextChunks
- one or more strings which are joined- Returns:
- a new string with newline characters separating successive lines
-
makeLineSeparatedString
Creates a string by formatting the supplied strings as individual text lines separated by newline. Mainly to be used withGenericDialog.addMessage(String)
.- Parameters:
lines
- a sequence of strings interpreted as text lines- Returns:
- a newline-separated string
-
makeHtmlString
Creates a HTML string by formatting the supplied string(s) as individual text lines separated by <br>. The complete text is wrapped by <html>...</html>. Mainly used to format HTML-texts before being passed toGenericDialog.addHelp(String)
, which requires text lines to be separated by <br>. The supplied text lines may contain any text (including HTML formatting code), they are not processed or split.- Parameters:
textLines
- a sequence of strings interpreted as text lines- Returns:
- a HTML string with input lines separated by <br>
-
addToDialog
Adds all qualified fields of the givenParameterBundle
to the specifiedGenericDialog
instance, in the exact order of their definition. Qualified means that the field is of suitable type and noDialogUtils.DialogHide
annotation is present. Allowed field types areboolean
,int
,long
,float
,double
,enum
, andString
.- Parameters:
params
- aParameterBundle
instancegd
- a generic dialog
-
getFromDialog
Retrieves the field values of the specifiedParameterBundle
from theGenericDialog
instance. TheParameterBundle
is modified. Throws an exception if anything goes wrong.- Parameters:
params
- aParameterBundle
instancegd
- a generic dialog- Returns:
- true if successful
-
askYesOrCancel
Deprecated.Opens a simple dialog with the specified title and message that allows only a "Yes" or "Cancel" response.- Parameters:
title
- the text displayed in the dialog's title barmessage
- the dialog message (may be multiple lines separated by newlines)- Returns:
- true if "yes" was selected, false otherwise
-
askForSampleImage
Opens a very specific dialog asking if the suggested sample image (resource) should be opened and made the active image. If the answer is YES, the suggested image is opened, otherwise not. This if typically used in the (otherwise empty) constructor of demo plugins when no (or no suitable) image is currently open. Does nothing and returns false if invoked from outside ImageJ (e.g., during testing) and in IJ batch mode.- Parameters:
suggested
- a sample image (ImageResource
)- Returns:
- true if user accepted, false otherwise
-
askForSampleImage
-