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 @interfaceAnnotation to specify the number of digits (value) displayed when showing numeric values in dialogs.static @interfaceAnnotation to hide the following parameter field in dialogs.static @interfaceAnnotation to specify a specific 'label' (value) to be shown for following parameter fields.static @interfaceAnnotation to specify the number of "columns" (value) displayed when showing string items in dialogs. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddToDialog(ParameterBundle<?> params, GenericDialog gd) Adds all qualified fields of the givenParameterBundleto the specifiedGenericDialoginstance, in the exact order of their definition.static booleanstatic booleanaskForSampleImage(ImageResource suggested) Opens a very specific dialog asking if the suggested sample image (resource) should be opened and made the active image.static booleanaskYesOrCancel(String title, String message) Deprecated.static StringformatText(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 booleangetFromDialog(ParameterBundle<?> params, GenericDialog gd) Retrieves the field values of the specifiedParameterBundlefrom theGenericDialoginstance.static StringmakeHtmlString(String... textLines) Creates a HTML string by formatting the supplied string(s) as individual text lines separated by <br>.static StringmakeLineSeparatedString(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 givenParameterBundleto the specifiedGenericDialoginstance, in the exact order of their definition. Qualified means that the field is of suitable type and noDialogUtils.DialogHideannotation is present. Allowed field types areboolean,int,long,float,double,enum, andString.- Parameters:
params- aParameterBundleinstancegd- a generic dialog
-
getFromDialog
Retrieves the field values of the specifiedParameterBundlefrom theGenericDialoginstance. TheParameterBundleis modified. Throws an exception if anything goes wrong.- Parameters:
params- aParameterBundleinstancegd- 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
-