Package org.geotools.swing.dialog
Class DialogUtils
- Object
-
- DialogUtils
-
public class DialogUtils extends Object
Static utility methods for common dialog and GUI related tasks.- Since:
- 2.7
- Author:
- Michael Bedward
-
-
Constructor Summary
Constructors Constructor Description DialogUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends JComponent>
List<T>getChildComponents(Class<T> clazz, Container parent, boolean includeNested)
Gets all child components that are, or derive from, the given class.static Dimension
getHtmlLabelTextExtent(String labelText, int fixedDimSize, boolean width)
Calculates the dimensions that a given text string requires when rendered as HTML text in a label component.static String
getString(String input, String fallback)
Returnsinput
if notnull
or empty, otherwise returnsfallback
.static void
showCentred(Window dialog)
Shows a dialog centred on the screen.static void
showCentredOnParent(Window parent, Window dialog)
Shows a dialog centred on its parent.
-
-
-
Method Detail
-
showCentred
public static void showCentred(Window dialog)
Shows a dialog centred on the screen. May be called safely from any thread.- Parameters:
dialog
- the dialog
-
showCentredOnParent
public static void showCentredOnParent(Window parent, Window dialog)
Shows a dialog centred on its parent. May be called safely from any thread. Ifparent
isnull
the dialog is centred on the screen.- Parameters:
parent
- the parent componentdialog
- the dialog
-
getChildComponents
public static <T extends JComponent> List<T> getChildComponents(Class<T> clazz, Container parent, boolean includeNested)
Gets all child components that are, or derive from, the given class. This method is adapted from the SwingUtils class written by Darryl Burke. (Accessed from: http://tips4java.wordpress.com/2008/11/13/swing-utils/).- Type Parameters:
T
- Swing type derived from JComponent- Parameters:
clazz
- the component classparent
- the parent containerincludeNested
- whether to recursively collect nested components- Returns:
- list of child components
-
getString
public static String getString(String input, String fallback)
Returnsinput
if notnull
or empty, otherwise returnsfallback
. This is handy for setting dialog titles etc. Note that the input string is considered empty ifinput.trim().length() == 0
.- Parameters:
input
- input stringfallback
- fallback string (may benull
)- Returns:
input
unless it isnull
or empty, in which casefallback
is returned
-
getHtmlLabelTextExtent
public static Dimension getHtmlLabelTextExtent(String labelText, int fixedDimSize, boolean width)
Calculates the dimensions that a given text string requires when rendered as HTML text in a label component.The method used is adapted from that described in a blog post by Morten Nobel:
http://blog.nobel-joergensen.com/2009/01/18/changing-preferred-size-of-a-html-jlabel/
- Parameters:
labelText
- the text to render, optionally enclosed in<html>...</html>
tagsfixedDimSize
- the size of the fixed dimension (either width or heightwidth
-true
if the fixed dimension is width;false
for height- Returns:
- the rendered label text extent
-
-