Package adams.gui.core
Class GUIHelper
- java.lang.Object
-
- adams.gui.core.GUIHelper
-
public class GUIHelper extends Object
A "little" helper class for GUI related stuff.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGUIHelper.AbstractInputPanelAncestor for panels that allow the user to enter/select a value.static classGUIHelper.DialogCommunicationHelper class that allows external callers to communicate with input dialogs, enabling them to schedule closing of the dialog.static classGUIHelper.InputDialogMultiValueSelectionHow showInputDialog should display the multiple values to choose from.static classGUIHelper.InputPanelWithButtonsPanel that uses buttons for the values that the user can enter.static classGUIHelper.InputPanelWithComboBoxPanel that uses a combobox for the values that the user can enter.static classGUIHelper.InputPanelWithTextAreaPanel that uses a textarea for the value that the user can enter.
-
Field Summary
Fields Modifier and Type Field Description static StringALLOWED_MNEMONICSthe allowed mnemonics.static booleanAntiAliasingEnabledwhether anti-aliasing is enabled.static intAPPROVE_OPTIONthe approve option.static intCANCEL_OPTIONthe cancel option.static intDISCARD_OPTIONthe discard option.static StringFILENAMEthe name of the props file.static BooleanHeadlessModewhether we are running in headless mode.static intINPUT_DIALOG_COLSthe default columns for the input dialog.static intINPUT_DIALOG_ROWSthe default rows for the input dialog.protected static intm_DefaultHorizontalTextOffsetthe global horizontal offset for drawing text in boxes.protected static HashMap<String,String>m_KeystrokeReplacementsthe mappings for replacing keystrokes.protected static Propertiesm_Propertiesthe properties.static charMNEMONIC_INDICATORthe mnemonic character indicator.
-
Constructor Summary
Constructors Constructor Description GUIHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidadjustSize(Component window)Adjusts the size of the window, that it fits onto the screen.static intcalcLeftPosition(Component window, int left)Determines the left location for a window.static intcalcTopPosition(Component window, int top)Determines the top location for a window.static int[]calculateFontOffset(Graphics g, Rectangle box)Calculates the horizontal and vertical offsets for drawing text.static voidcloseParent(Container cont)Closes the parent dialog/frame of this container.static voidconfigureAntiAliasing(Graphics g, boolean enable)Enables/disables anti-aliasing in the Graphics context.static SwingWorkerdoInBackground(Runnable runnable)static Dimensionenlarge(Dimension size)Makes the rectangle taller/wider by 20%.static Dimensionenlarge(Dimension size, double percentage)Makes the rectangle taller/wider.static List<Component>findAllComponents(Container parent, Class type, boolean recursive, boolean exact)Retrieves all components of the specified type starting with the given parent container.protected static voidfindComponents(Container parent, Class type, boolean recursive, boolean exact, List<Component> list, boolean onlyFirst)Retrieves all components of the specified type starting with the given parent container.static ComponentfindFirstComponent(Container parent, Class type, boolean recursive, boolean exact)Retrieves the first component of the specified type starting with the given parent container.static voidfixPosition(Component window)Adjusts the position of the window, that it fits onto the screen.static BooleangetBoolean(Class cls, String key, Boolean defValue)Returns the boolean value listed in the props file, or the default value if not found.static BooleangetBoolean(String key, Boolean defValue)Returns the boolean value listed in the props file, or the default value if not found.static ColorgetColor(Class cls, String key, Color defValue)Returns the color value listed in the props file, or the default value if not found.static ColorgetColor(String key, Color defValue)Returns the color value listed in the props file, or the default value if not found.static DimensiongetDefaultDialogDimension()Returns the default dimensions for a dialog.intgetDefaultHorizontalTextOffset()Returns the default horizontal offset for drawing strings in boxes.static DimensiongetDefaultLargeDialogDimension()Returns the default dimensions for a large dialog.static DimensiongetDefaultSmallDialogDimension()Returns the default dimensions for a small dialog.static DimensiongetDefaultTinyDialogDimension()Returns the default dimensions for a tiny dialog.static doublegetDisplayScaleFactor()Returns the scale factor for the display.static DoublegetDouble(Class cls, String key, Double defValue)Returns the double value listed in the props file, or the default value if not found.static DoublegetDouble(String key, Double defValue)Returns the double value listed in the props file, or the default value if not found.static FontgetFont(Class cls, String key, Font defValue)Returns the Font value listed in the props file, or the default value if not found.static FontgetFont(String key, Font defValue)Returns the Font value listed in the props file, or the default value if not found.static GraphicsConfigurationgetGraphicsConfiguration(Component comp)Tries to determine theGraphicsConfigurationthat the specified component is located on.static GraphicsDevicegetGraphicsDevice(Component comp)Tries to determine theGraphicsDevicethat the specified component is located on.static IntegergetInteger(Class cls, String key, Integer defValue)Returns the integer value listed in the props file, or the default value if not found.static IntegergetInteger(String key, Integer defValue)Returns the integer value listed in the props file, or the default value if not found.static KeyStrokegetKeyStroke(String keystroke)Creates a keystroke from the string.protected static HashMap<String,String>getKeystrokeReplacements()Returns the replacements for the keystrokes.static intgetMaxTooltipWidth()Returns the maximum width for tool tips.static chargetMnemonic(String caption)Returns the mnemonic for this caption, preceded by an underscore "_".static char[]getMnemonics(String[] labels)Suggests mnemonics for the given labels.static OptionHandlergetOptionHandler(Class cls, String key, OptionHandler defValue)Returns the OptionHandler value listed in the props file, or the default value if not found.static OptionHandlergetOptionHandler(String key, OptionHandler defValue)Returns the OptionHandler value listed in the props file, or the default value if not found.static ObjectgetParent(Container cont, Class parentClass)Tries to determine the parent this panel is part of.static ChildgetParentChild(Component comp)Tries to determine the child window/frame this component is part of.static ChildgetParentChild(Container cont)Tries to determine the child window/frame this container is part of.static ComponentgetParentComponent(Component comp)Tries to determine the component this panel is part of in this order: 1. dialog, 2. child, 3. frame.static DialoggetParentDialog(Component comp)Tries to determine the dialog this component is part of.static DialoggetParentDialog(Container cont)Tries to determine the dialog this container is part of.static FramegetParentFrame(Component comp)Tries to determine the frame the component is part of.static FramegetParentFrame(Container cont)Tries to determine the frame the container is part of.static JInternalFramegetParentInternalFrame(Component comp)Tries to determine the internal frame this component is part of.static JInternalFramegetParentInternalFrame(Container cont)Tries to determine the internal frame this container is part of.static intgetPreferredButtonHeight()Returns the preferred button height.static intgetPreferredCheckBoxHeight()Returns the preferred checkbox height.static intgetPreferredComboBoxHeight()Returns the preferred combobox height.static intgetPreferredSpinnerHeight()Returns the preferred spinner height.static intgetPreferredTextFieldHeight()Returns the preferred textfield height.intgetRelativeLeft(Window window)Returns the relative left X position in its screen.intgetRelativeTop(Window window)Returns the relative top Y position in its screen.static RectanglegetScreenBounds(Component window)Returns the actual screen real estate bounds according to ScreenBorder.Top/Left/Bottom/Right in the props file.static RectanglegetScreenBounds(GraphicsConfiguration gc)Returns the actual screen real estate bounds according to ScreenBorder.Top/Left/Bottom/Right in the props file.static FilegetStartupScript(Component c)Returns the startup script, if any, for the given component.static StringgetString(Class cls, String key, String defValue)Returns the string value listed in the props file, or the default value if not found.static StringgetString(String key, String defValue)Returns the string value listed in the props file, or the default value if not found.static JMenugetTopLevelMenu(JMenuItem menuitem)Determines the top-level menu (the one sitting inside the JMenuBar) that is associated with a menu item.static booleanhasMnemonic(String caption)Checks the caption whether an underscore "_" is present to indicate that the following character is to act as mnemonic.protected static voidinitializeProperties()Initializes the properties if necessary.static booleanisHeadless()Returns whether we are running in headless mode.static booleanlaunchMenuItem(Container source, Class menuitem)Attempts to launch the specified menuitem.static booleanmakeAtLeast(Component window, Dimension min)Makes the window at least the specified size.static DimensionmakeAtLeast(Dimension current, Dimension min)Makes the dimensions at least the specified size.static booleanmakeAtMost(Component window, Dimension max)Makes the window at most the specified size.static DimensionmakeAtMost(Dimension current, Dimension max)Makes the dimensions at most the specified size.static DimensionmakeFit(Dimension current, Dimension min, Dimension max)Fits the dimensions between min/max.static voidmakeHalfScreenHeight(Component c)Changes the height of the window to half of the screen width.static voidmakeHalfScreenWidth(Component c)Changes the width of the window to half of the screen width.static DimensionmakeNarrower(Dimension size)Narrows the rectangle by 20%.static DimensionmakeNarrower(Dimension size, double percent)Narrows the rectangle by the specified percentage.static DimensionmakeSmaller(Dimension size)Makes the rectangle's height smaller by 20%.static DimensionmakeSmaller(Dimension size, double percent)Makes the rectangle's height smaller by the specified percentage.static DimensionmakeTaller(Dimension size)Males the rectangle taller by 20%.static DimensionmakeTaller(Dimension size, double percent)Makes the rectangle taller by the specified percentage.static DimensionmakeWider(Dimension size)Widens the rectangle by 20%.static DimensionmakeWider(Dimension size, double percent)Widens the rectangle by the specified percentage.static booleanpack(Window window, Dimension min, Dimension max)Packs the window, but ensures that it fits between min/max.static StringprocessKeyStroke(String keystroke)Processes the keystrokes.static StringprocessTipText(String text)Parses the tool tip and turns it into HTML if it contains line breaks.static StringprocessTipText(String text, int width)Parses the tool tip and breaks it up into multiple lines if longer than width characters.static StringprocessTipText(String text, int width, int maxLines)Parses the tool tip and breaks it up into multiple lines if longer than width characters.static Dimensionrotate(Dimension rect)Rotates the rectangle by 90 degrees.static doublescale(double size)Applies the global scale factor to the size.static intscale(int size)Applies the global scale factor to the size.static Dimensionscale(Dimension size)Applies the global scale factor to the size.static BufferedImagescreenshot(JComponent comp)Takes a screenshot of the component.static voidsetDefaultHorizontalTextOffset(int value)Sets the default horizontal offset for drawing strings in boxes.static voidsetHeadless(boolean value)Sets the headless mode.static voidsetSize(Component window, Component c)Sets size stored in the props file.static voidsetSizeAndLocation(Component window)Sets size and location stored in the props file.static voidsetSizeAndLocation(Component window, int top, int left)Sets size and location stored in the props file.static voidsetSizeAndLocation(Component window, int top, int left, Component c)Sets size and location stored in the props file.static voidsetSizeAndLocation(Component window, Component c)Sets size and location stored in the props file.static intshowConfirmMessage(Component parent, String msg)Displays a confirmation dialog (yes/no/cancel) with the default title "Confirm".static intshowConfirmMessage(Component parent, String msg, String title)Displays a confirmation dialog (yes/no/cancel).static intshowConfirmMessage(Component parent, String header, String msg, String title)Displays a confirmation dialog (yes/no/cancel).static intshowConfirmMessage(Component parent, String header, String msg, String title, String labelYes, String labelNo, String labelCancel)Displays a confirmation dialog (yes/no/cancel).static intshowConfirmMessage(Component parent, String header, String msg, String title, String labelYes, String labelNo, String labelCancel, GUIHelper.DialogCommunication comm)Displays a confirmation dialog (yes/no/cancel).static voidshowErrorMessage(Component parent, String msg)Displays an error message with the default title "Error".static voidshowErrorMessage(Component parent, String msg, String title)Displays an error message.static voidshowErrorMessage(Component parent, String msg, Throwable t)Displays an error message with the default title "Error".static voidshowErrorMessage(Component parent, String msg, Throwable t, String title)Displays an error message.static voidshowInformationMessage(Component parent, String msg)Displays an information message with the default title "Information".static voidshowInformationMessage(Component parent, String msg, String title)Displays an information message.static voidshowInformationMessage(Component parent, String msg, String title, boolean html, Dimension size)Displays an information message.static StringshowInputDialog(Component parent, String msg)A simple dialog for entering a string.static StringshowInputDialog(Component parent, String msg, String initial)A simple dialog for entering a string.static StringshowInputDialog(Component parent, String msg, String initial, String title)A simple dialog for entering a string.static StringshowInputDialog(Component parent, String msg, String initial, String[] options)A simple dialog for selecting a string.static StringshowInputDialog(Component parent, String msg, String initial, String[] options, GUIHelper.InputDialogMultiValueSelection view, String title)A simple dialog for entering a string.static StringshowInputDialog(Component parent, String msg, String initial, String[] options, GUIHelper.InputDialogMultiValueSelection view, String title, GUIHelper.DialogCommunication comm)A simple dialog for entering a string.static StringshowInputDialog(Component parent, String msg, String initial, String[] options, String title)A simple dialog for selecting a string.static StringshowInputDialog(Component parent, String msg, String initial, String title, StringHistory history)A simple dialog for entering a string.static StringshowInputDialog(Component parent, String msg, String initial, String title, GUIHelper.DialogCommunication comm)A simple dialog for entering a string.static StringshowInputDialog(Component parent, String msg, String initial, String title, GUIHelper.DialogCommunication comm, int minCols, int minRows)A simple dialog for entering a string.static StringshowInputDialog(Component parent, String msg, String initial, String title, GUIHelper.DialogCommunication comm, int minCols, int minRows, StringHistory history)A simple dialog for entering a string.protected static StringshowInputDialogButtons(Component parent, String msg, String initial, String[] options, String title, boolean horizontal, GUIHelper.DialogCommunication comm)A simple dialog for selecting a string by clicking on a button.protected static StringshowInputDialogComboBox(Component parent, String msg, String initial, String[] options, String title, GUIHelper.DialogCommunication comm)A simple dialog for selecting a string.static BasePasswordshowPasswordDialog(Component parent)Prompts the user for entering a password.static BasePasswordshowPasswordDialog(Component parent, String labelText)Prompts the user for entering a password.static BasePasswordshowPasswordDialog(Component parent, String labelText, String comments)Prompts the user for entering a password.static voidshowPopupMenu(JPopupMenu menu, Component invoker, int x, int y)Displays a popup menu.static voidshowPopupMenu(JPopupMenu menu, Component invoker, MouseEvent e)Displays a popup menu.static Dimensionshrink(Dimension size)Makes the rectangle smaller/narrower by 20%.static Dimensionshrink(Dimension size, double percentage)Makes the rectangle smaller/narrower.static StringstripMnemonic(String caption)Removes the mnemonic indicator in this caption.static voidtoFront(Component comp)Attempts to bring the enclosing window to the front.static voidtoFront(Container cont)Attempts to bring the enclosing window to the front.
-
-
-
Field Detail
-
FILENAME
public static final String FILENAME
the name of the props file.- See Also:
- Constant Field Values
-
MNEMONIC_INDICATOR
public static final char MNEMONIC_INDICATOR
the mnemonic character indicator.- See Also:
- Constant Field Values
-
ALLOWED_MNEMONICS
public static final String ALLOWED_MNEMONICS
the allowed mnemonics.- See Also:
- Constant Field Values
-
APPROVE_OPTION
public static final int APPROVE_OPTION
the approve option.- See Also:
- Constant Field Values
-
DISCARD_OPTION
public static final int DISCARD_OPTION
the discard option.- See Also:
- Constant Field Values
-
CANCEL_OPTION
public static final int CANCEL_OPTION
the cancel option.- See Also:
- Constant Field Values
-
INPUT_DIALOG_COLS
public static final int INPUT_DIALOG_COLS
the default columns for the input dialog.- See Also:
- Constant Field Values
-
INPUT_DIALOG_ROWS
public static final int INPUT_DIALOG_ROWS
the default rows for the input dialog.- See Also:
- Constant Field Values
-
m_Properties
protected static Properties m_Properties
the properties.
-
m_KeystrokeReplacements
protected static HashMap<String,String> m_KeystrokeReplacements
the mappings for replacing keystrokes.
-
AntiAliasingEnabled
public static boolean AntiAliasingEnabled
whether anti-aliasing is enabled.
-
HeadlessMode
public static Boolean HeadlessMode
whether we are running in headless mode.
-
m_DefaultHorizontalTextOffset
protected static int m_DefaultHorizontalTextOffset
the global horizontal offset for drawing text in boxes.
-
-
Method Detail
-
initializeProperties
protected static void initializeProperties()
Initializes the properties if necessary.
-
setSize
public static void setSize(Component window, Component c)
Sets size stored in the props file.- Parameters:
window- the frame to work onc- the component to use for lookup in the props file; null can be used to bypass the lookup in the props file
-
setSizeAndLocation
public static void setSizeAndLocation(Component window)
Sets size and location stored in the props file.- Parameters:
window- the frame to work on- See Also:
setSizeAndLocation(Component, Component)
-
calcLeftPosition
public static int calcLeftPosition(Component window, int left)
Determines the left location for a window.- Parameters:
window- the window to work onleft- the left position, -1: centered, -2: right-justified
-
calcTopPosition
public static int calcTopPosition(Component window, int top)
Determines the top location for a window.- Parameters:
window- the window to work ontop- the top position, -1: centered, -2: bottom-justified
-
setSizeAndLocation
public static void setSizeAndLocation(Component window, Component c)
Sets size and location stored in the props file.- Parameters:
window- the frame to work onc- the component to use for lookup in the props file; null can be used to bypass the lookup in the props file (in that case, "top" and "left" are initialized with 0)- See Also:
setSizeAndLocation(Component, int, int, Component)
-
setSizeAndLocation
public static void setSizeAndLocation(Component window, int top, int left)
Sets size and location stored in the props file.
Takes the following parameters from the props file into account as well: MaxPercentHeight, ScreenBorder.Bottom- Parameters:
window- the frame to work ontop- the y positionleft- the x position- See Also:
setSizeAndLocation(Component, int, int, Component)
-
setSizeAndLocation
public static void setSizeAndLocation(Component window, int top, int left, Component c)
Sets size and location stored in the props file.
Takes the following parameters from the props file into account as well: MaxPercentHeight, ScreenBorder.Bottom- Parameters:
window- the frame to work ontop- the y positionleft- the x positionc- the component to use for lookup in the props file; null can be used to bypass the lookup in the props file
-
getScreenBounds
public static Rectangle getScreenBounds(Component window)
Returns the actual screen real estate bounds according to ScreenBorder.Top/Left/Bottom/Right in the props file.+----------------------------+ physical screen | | | +--------------------+ | | | | | | | available screen | | | | | | | | | | | +--------------------+ | | | | | +----------------------------+
- Parameters:
window- the window to get the graphics config from- Returns:
- the "inner" rectangle where we can display stuff
-
getScreenBounds
public static Rectangle getScreenBounds(GraphicsConfiguration gc)
Returns the actual screen real estate bounds according to ScreenBorder.Top/Left/Bottom/Right in the props file.+----------------------------+ physical screen | | | +--------------------+ | | | | | | | available screen | | | | | | | | | | | +--------------------+ | | | | | +----------------------------+
- Parameters:
gc- the graphics config to use- Returns:
- the "inner" rectangle where we can display stuff
-
adjustSize
public static void adjustSize(Component window)
Adjusts the size of the window, that it fits onto the screen.- Parameters:
window- the window to adjust- See Also:
getScreenBounds(Component)
-
fixPosition
public static void fixPosition(Component window)
Adjusts the position of the window, that it fits onto the screen.- Parameters:
window- the window to adjust- See Also:
getScreenBounds(Component)
-
getRelativeTop
public int getRelativeTop(Window window)
Returns the relative top Y position in its screen.- Parameters:
window- the window to determine the top Y for- Returns:
- the top Y
-
getRelativeLeft
public int getRelativeLeft(Window window)
Returns the relative left X position in its screen.- Parameters:
window- the window to determine the left X for- Returns:
- the left X
-
getStartupScript
public static File getStartupScript(Component c)
Returns the startup script, if any, for the given component.- Parameters:
c- the component to look for a startup script for- Returns:
- the script file or null if none listed or none-existing
-
getString
public static String getString(String key, String defValue)
Returns the string value listed in the props file, or the default value if not found.- Parameters:
key- the key of the propertydefValue- the default value to return if property is not stored in props file- Returns:
- the value
-
getString
public static String getString(Class cls, String key, String defValue)
Returns the string value listed in the props file, or the default value if not found. The key used is this: classname + "." + key.- Parameters:
cls- the class to retrieve the key forkey- the key of the propertydefValue- the default value to return if property is not stored in props file- Returns:
- the value
-
getInteger
public static Integer getInteger(String key, Integer defValue)
Returns the integer value listed in the props file, or the default value if not found.- Parameters:
key- the key of the propertydefValue- the default value to return if property is not stored in props file- Returns:
- the value
-
getInteger
public static Integer getInteger(Class cls, String key, Integer defValue)
Returns the integer value listed in the props file, or the default value if not found. The key used is this: classname + "." + key.- Parameters:
cls- the class to retrieve the key forkey- the key of the propertydefValue- the default value to return if property is not stored in props file- Returns:
- the value
-
getColor
public static Color getColor(String key, Color defValue)
Returns the color value listed in the props file, or the default value if not found.- Parameters:
key- the key of the propertydefValue- the default value to return if property is not stored in props file- Returns:
- the value
-
getColor
public static Color getColor(Class cls, String key, Color defValue)
Returns the color value listed in the props file, or the default value if not found. The key used is this: classname + "." + key.- Parameters:
cls- the class to retrieve the key forkey- the key of the propertydefValue- the default value to return if property is not stored in props file- Returns:
- the value
-
getDouble
public static Double getDouble(String key, Double defValue)
Returns the double value listed in the props file, or the default value if not found.- Parameters:
key- the key of the propertydefValue- the default value to return if property is not stored in props file- Returns:
- the value
-
getDouble
public static Double getDouble(Class cls, String key, Double defValue)
Returns the double value listed in the props file, or the default value if not found. The key used is this: classname + "." + key.- Parameters:
cls- the class to retrieve the key forkey- the key of the propertydefValue- the default value to return if property is not stored in props file- Returns:
- the value
-
getBoolean
public static Boolean getBoolean(String key, Boolean defValue)
Returns the boolean value listed in the props file, or the default value if not found.- Parameters:
key- the key of the propertydefValue- the default value to return if property is not stored in props file- Returns:
- the value
-
getBoolean
public static Boolean getBoolean(Class cls, String key, Boolean defValue)
Returns the boolean value listed in the props file, or the default value if not found. The key used is this: classname + "." + key.- Parameters:
cls- the class to retrieve the key forkey- the key of the propertydefValue- the default value to return if property is not stored in props file- Returns:
- the value
-
getFont
public static Font getFont(String key, Font defValue)
Returns the Font value listed in the props file, or the default value if not found.- Parameters:
key- the key of the propertydefValue- the default value to return if property is not stored in props file- Returns:
- the value
-
getFont
public static Font getFont(Class cls, String key, Font defValue)
Returns the Font value listed in the props file, or the default value if not found. The key used is this: classname + "." + key.- Parameters:
cls- the class to retrieve the key forkey- the key of the propertydefValue- the default value to return if property is not stored in props file- Returns:
- the value
-
getOptionHandler
public static OptionHandler getOptionHandler(String key, OptionHandler defValue)
Returns the OptionHandler value listed in the props file, or the default value if not found.- Parameters:
key- the key of the propertydefValue- the default value to return if property is not stored in props file- Returns:
- the value
-
getOptionHandler
public static OptionHandler getOptionHandler(Class cls, String key, OptionHandler defValue)
Returns the OptionHandler value listed in the props file, or the default value if not found. The key used is this: classname + "." + key.- Parameters:
cls- the class to retrieve the key forkey- the key of the propertydefValue- the default value to return if property is not stored in props file- Returns:
- the value
-
getParent
public static Object getParent(Container cont, Class parentClass)
Tries to determine the parent this panel is part of.- Parameters:
cont- the container to get the parent forparentClass- the class of the parent to obtain- Returns:
- the parent if one exists or null if not
-
getParentFrame
public static Frame getParentFrame(Container cont)
Tries to determine the frame the container is part of.- Parameters:
cont- the container to get the frame for- Returns:
- the parent frame if one exists or null if not
-
getParentFrame
public static Frame getParentFrame(Component comp)
Tries to determine the frame the component is part of.- Parameters:
comp- the component to get the frame for- Returns:
- the parent frame if one exists or null if not
-
getParentDialog
public static Dialog getParentDialog(Container cont)
Tries to determine the dialog this container is part of.- Parameters:
cont- the container to get the dialog for- Returns:
- the parent dialog if one exists or null if not
-
getParentDialog
public static Dialog getParentDialog(Component comp)
Tries to determine the dialog this component is part of.- Parameters:
comp- the component to get the dialog for- Returns:
- the parent dialog if one exists or null if not
-
getParentInternalFrame
public static JInternalFrame getParentInternalFrame(Container cont)
Tries to determine the internal frame this container is part of.- Parameters:
cont- the container to start with- Returns:
- the parent internal frame if one exists or null if not
-
getParentInternalFrame
public static JInternalFrame getParentInternalFrame(Component comp)
Tries to determine the internal frame this component is part of.- Parameters:
comp- the component to start with- Returns:
- the parent internal frame if one exists or null if not
-
getParentChild
public static Child getParentChild(Container cont)
Tries to determine the child window/frame this container is part of.- Parameters:
cont- the container to get the child window/frame for- Returns:
- the parent child window/frame if one exists or null if not
-
getParentChild
public static Child getParentChild(Component comp)
Tries to determine the child window/frame this component is part of.- Parameters:
comp- the component to get the child window/frame for- Returns:
- the parent child window/frame if one exists or null if not
-
getParentComponent
public static Component getParentComponent(Component comp)
Tries to determine the component this panel is part of in this order: 1. dialog, 2. child, 3. frame.- Parameters:
comp- the component to get the parent component for, must be a container actually- Returns:
- the parent component if one exists or null if not
- See Also:
getParentDialog(Container),getParentChild(Container),getParentFrame(Container)
-
closeParent
public static void closeParent(Container cont)
Closes the parent dialog/frame of this container.- Parameters:
cont- the container to close the parent for
-
toFront
public static void toFront(Component comp)
Attempts to bring the enclosing window to the front. Note: does not work on all platforms.- Parameters:
comp- the container whose parent window to bring to front
-
toFront
public static void toFront(Container cont)
Attempts to bring the enclosing window to the front. Note: does not work on all platforms.- Parameters:
cont- the container whose parent window to bring to front
-
getMnemonics
public static char[] getMnemonics(String[] labels)
Suggests mnemonics for the given labels.- Parameters:
labels- the labels to set the mnemonics for- Returns:
- the mnemonics
-
hasMnemonic
public static boolean hasMnemonic(String caption)
Checks the caption whether an underscore "_" is present to indicate that the following character is to act as mnemonic.- Parameters:
caption- the caption to analyze- Returns:
- true if an underscore is present
- See Also:
MNEMONIC_INDICATOR
-
getMnemonic
public static char getMnemonic(String caption)
Returns the mnemonic for this caption, preceded by an underscore "_".- Parameters:
caption- the caption to extract- Returns:
- the extracted mnemonic, \0 if none available
- See Also:
MNEMONIC_INDICATOR
-
stripMnemonic
public static String stripMnemonic(String caption)
Removes the mnemonic indicator in this caption.- Parameters:
caption- the caption to process- Returns:
- the processed caption
- See Also:
MNEMONIC_INDICATOR
-
showErrorMessage
public static void showErrorMessage(Component parent, String msg, Throwable t)
Displays an error message with the default title "Error".- Parameters:
parent- the parent, to make the dialog modal; can be nullmsg- the error message to displayt- the exception to append to the message
-
showErrorMessage
public static void showErrorMessage(Component parent, String msg)
Displays an error message with the default title "Error".- Parameters:
parent- the parent, to make the dialog modal; can be nullmsg- the error message to display
-
showErrorMessage
public static void showErrorMessage(Component parent, String msg, Throwable t, String title)
Displays an error message.- Parameters:
parent- the parent, to make the dialog modal; can be nullmsg- the error message to displaytitle- the title of the error messaget- the exception to append to the message
-
showErrorMessage
public static void showErrorMessage(Component parent, String msg, String title)
Displays an error message.- Parameters:
parent- the parent, to make the dialog modal; can be nullmsg- the error message to displaytitle- the title of the error message
-
showInformationMessage
public static void showInformationMessage(Component parent, String msg)
Displays an information message with the default title "Information".- Parameters:
parent- the parent, to make the dialog modal; can be nullmsg- the information message to display
-
showInformationMessage
public static void showInformationMessage(Component parent, String msg, String title)
Displays an information message.- Parameters:
parent- the parent, to make the dialog modal; can be nullmsg- the information message to displaytitle- the title of the information message
-
showInformationMessage
public static void showInformationMessage(Component parent, String msg, String title, boolean html, Dimension size)
Displays an information message.- Parameters:
parent- the parent, to make the dialog modal; can be nullmsg- the information message to displaytitle- the title of the information messagehtml- whether to display HTML or plain textsize- the size of the dialog, can be null
-
showConfirmMessage
public static int showConfirmMessage(Component parent, String msg)
Displays a confirmation dialog (yes/no/cancel) with the default title "Confirm".- Parameters:
parent- the parent, to make the dialog modal; can be nullmsg- the error message to display- Returns:
- the selected option
- See Also:
ApprovalDialog.APPROVE_OPTION,ApprovalDialog.DISCARD_OPTION,ApprovalDialog.CANCEL_OPTION
-
showConfirmMessage
public static int showConfirmMessage(Component parent, String msg, String title)
Displays a confirmation dialog (yes/no/cancel).- Parameters:
parent- the parent, to make the dialog modal; can be nullmsg- the error message to displaytitle- the title of the error message- Returns:
- the selected option
- See Also:
ApprovalDialog.APPROVE_OPTION,ApprovalDialog.DISCARD_OPTION,ApprovalDialog.CANCEL_OPTION
-
showConfirmMessage
public static int showConfirmMessage(Component parent, String header, String msg, String title)
Displays a confirmation dialog (yes/no/cancel).- Parameters:
parent- the parent, to make the dialog modal; can be nullheader- the text explaining the message, null to ignoremsg- the error message to displaytitle- the title of the error message- Returns:
- the selected option
- See Also:
ApprovalDialog.APPROVE_OPTION,ApprovalDialog.DISCARD_OPTION,ApprovalDialog.CANCEL_OPTION
-
showConfirmMessage
public static int showConfirmMessage(Component parent, String header, String msg, String title, String labelYes, String labelNo, String labelCancel)
Displays a confirmation dialog (yes/no/cancel).- Parameters:
parent- the parent, to make the dialog modal; can be nullheader- the text explaining the message, null to ignoremsg- the error message to displaytitle- the title of the error messagelabelYes- the label for the "Yes" button, null to use defaultlabelNo- the label for the "No" button, null to use defaultlabelCancel- the label for the "Cancel" button, null to use default- Returns:
- the selected option
- See Also:
ApprovalDialog.APPROVE_OPTION,ApprovalDialog.DISCARD_OPTION,ApprovalDialog.CANCEL_OPTION
-
showConfirmMessage
public static int showConfirmMessage(Component parent, String header, String msg, String title, String labelYes, String labelNo, String labelCancel, GUIHelper.DialogCommunication comm)
Displays a confirmation dialog (yes/no/cancel).- Parameters:
parent- the parent, to make the dialog modal; can be nullheader- the text explaining the message, null to ignoremsg- the error message to displaytitle- the title of the error messagelabelYes- the label for the "Yes" button, null to use defaultlabelNo- the label for the "No" button, null to use defaultlabelCancel- the label for the "Cancel" button, null to use defaultcomm- for communicating with the dialog, can be null- Returns:
- the selected option
- See Also:
ApprovalDialog.APPROVE_OPTION,ApprovalDialog.DISCARD_OPTION,ApprovalDialog.CANCEL_OPTION
-
showInputDialog
public static String showInputDialog(Component parent, String msg)
A simple dialog for entering a string.- Parameters:
parent- the parent for this dialogmsg- the message to display, can be null (uses "Enter value" in that case)- Returns:
- the value entered, null if cancelled
-
showInputDialog
public static String showInputDialog(Component parent, String msg, String initial)
A simple dialog for entering a string.- Parameters:
parent- the parent for this dialogmsg- the message to display, can be null (uses "Enter value" in that case)initial- the initial selection, can be null- Returns:
- the value entered, null if cancelled
-
showInputDialog
public static String showInputDialog(Component parent, String msg, String initial, String title)
A simple dialog for entering a string.- Parameters:
parent- the parent for this dialogmsg- the message to display, can be null (uses "Enter value" in that case)initial- the initial selection, can be nulltitle- the title of the input dialog, can be null (uses "Enter value" in that case)- Returns:
- the value entered, null if cancelled
-
showInputDialog
public static String showInputDialog(Component parent, String msg, String initial, String title, StringHistory history)
A simple dialog for entering a string.- Parameters:
parent- the parent for this dialogmsg- the message to display, can be null (uses "Enter value" in that case)initial- the initial selection, can be nulltitle- the title of the input dialog, can be null (uses "Enter value" in that case)history- the history to use in the popup menu, can be null- Returns:
- the value entered, null if cancelled
-
showInputDialog
public static String showInputDialog(Component parent, String msg, String initial, String title, GUIHelper.DialogCommunication comm)
A simple dialog for entering a string. If "comm" is null simple modal dialogs are used, otherwise modeless ones with blocking till dialog closed (or closing requested via communication object).- Parameters:
parent- the parent for this dialogmsg- the message to display, can be null (uses "Enter value" in that case)initial- the initial selection, can be nulltitle- the title of the input dialog, can be null (uses "Enter value" in that case)comm- for communicating with the dialog, can be null- Returns:
- the value entered, null if cancelled
-
showInputDialog
public static String showInputDialog(Component parent, String msg, String initial, String title, GUIHelper.DialogCommunication comm, int minCols, int minRows)
A simple dialog for entering a string. If "comm" is null simple modal dialogs are used, otherwise modeless ones with blocking till dialog closed (or closing requested via communication object).- Parameters:
parent- the parent for this dialogmsg- the message to display, can be null (uses "Enter value" in that case)initial- the initial selection, can be nulltitle- the title of the input dialog, can be null (uses "Enter value" in that case)comm- for communicating with the dialog, can be nullminCols- the minimum number of columns in the text boxminRows- the minimum number of rows in the text box- Returns:
- the value entered, null if cancelled
-
showInputDialog
public static String showInputDialog(Component parent, String msg, String initial, String title, GUIHelper.DialogCommunication comm, int minCols, int minRows, StringHistory history)
A simple dialog for entering a string. If "comm" is null simple modal dialogs are used, otherwise modeless ones with blocking till dialog closed (or closing requested via communication object).- Parameters:
parent- the parent for this dialogmsg- the message to display, can be null (uses "Enter value" in that case)initial- the initial selection, can be nulltitle- the title of the input dialog, can be null (uses "Enter value" in that case)comm- for communicating with the dialog, can be nullminCols- the minimum number of columns in the text boxminRows- the minimum number of rows in the text boxhistory- history for recording the entered data, can be null- Returns:
- the value entered, null if cancelled
-
showInputDialog
public static String showInputDialog(Component parent, String msg, String initial, String[] options)
A simple dialog for selecting a string.- Parameters:
parent- the parent for this dialogmsg- the message to display, can be null (uses "Select value" in that case)initial- the initial selection, can be nulloptions- the available options- Returns:
- the value entered, null if cancelled
-
showInputDialog
public static String showInputDialog(Component parent, String msg, String initial, String[] options, String title)
A simple dialog for selecting a string.- Parameters:
parent- the parent for this dialogmsg- the message to display, can be null (uses "Select value" in that case)initial- the initial selection, can be nulloptions- the available optionstitle- the title of the input dialog, can be null (uses "Select value" in that case)- Returns:
- the value entered, null if cancelled
-
showInputDialogComboBox
protected static String showInputDialogComboBox(Component parent, String msg, String initial, String[] options, String title, GUIHelper.DialogCommunication comm)
A simple dialog for selecting a string. If "comm" is null simple modal dialogs are used, otherwise modeless ones with blocking till dialog closed (or closing requested via communication object).- Parameters:
parent- the parent for this dialogtitle- the title of the input dialog, can be null (uses "Select value" in that case)msg- the message to display, can be null (uses "Select value" in that case)initial- the initial selection, can be nulloptions- the available optionscomm- for communicating with the caller, can be null- Returns:
- the value entered, null if cancelled
-
showInputDialogButtons
protected static String showInputDialogButtons(Component parent, String msg, String initial, String[] options, String title, boolean horizontal, GUIHelper.DialogCommunication comm)
A simple dialog for selecting a string by clicking on a button. If "comm" is null simple modal dialogs are used, otherwise modeless ones with blocking till dialog closed (or closing requested via communication object).- Parameters:
parent- the parent for this dialogtitle- the title of the input dialog, can be null (uses "Select value" in that case)msg- the message to display, can be null (uses "Select value" in that case)initial- the initial selection, can be nulloptions- the available optionshorizontal- whether the buttons are horizontal or verticalcomm- for communicating with the caller, can be null- Returns:
- the value entered, null if cancelled
-
showInputDialog
public static String showInputDialog(Component parent, String msg, String initial, String[] options, GUIHelper.InputDialogMultiValueSelection view, String title)
A simple dialog for entering a string.- Parameters:
parent- the parent for this dialogtitle- the title of the input dialog, can be nullmsg- the message to displayinitial- the initial selection, can be nulloptions- the available optionsview- how to display the values- Returns:
- the value entered, null if cancelled
-
showInputDialog
public static String showInputDialog(Component parent, String msg, String initial, String[] options, GUIHelper.InputDialogMultiValueSelection view, String title, GUIHelper.DialogCommunication comm)
A simple dialog for entering a string. If "comm" is null simple modal dialogs are used, otherwise modeless ones with blocking till dialog closed (or closing requested via communication object).- Parameters:
parent- the parent for this dialogtitle- the title of the input dialog, can be nullmsg- the message to displayinitial- the initial selection, can be nulloptions- the available optionsview- how to display the valuescomm- for communicating with the dialog, can be null- Returns:
- the value entered, null if cancelled
-
showPasswordDialog
public static BasePassword showPasswordDialog(Component parent)
Prompts the user for entering a password.- Parameters:
parent- the parent component to use, can be null- Returns:
- the password, null if dialog canceled
-
showPasswordDialog
public static BasePassword showPasswordDialog(Component parent, String labelText)
Prompts the user for entering a password.- Parameters:
parent- the parent component to use, can be nulllabelText- the text for the label, ignored if null- Returns:
- the password, null if dialog canceled
-
showPasswordDialog
public static BasePassword showPasswordDialog(Component parent, String labelText, String comments)
Prompts the user for entering a password.- Parameters:
parent- the parent component to use, can be nulllabelText- the text for the label, ignored if nullcomments- the comments to display, ignored if null- Returns:
- the password, null if dialog canceled
-
processTipText
public static String processTipText(String text, int width)
Parses the tool tip and breaks it up into multiple lines if longer than width characters. No limit on number of rows.- Parameters:
text- the tiptext to parse, can be nullwidth- the maximum width- Returns:
- the processed tiptext
-
processTipText
public static String processTipText(String text, int width, int maxLines)
Parses the tool tip and breaks it up into multiple lines if longer than width characters.- Parameters:
text- the tiptext to parse, can be nullwidth- the maximum widthmaxLines- the maximum number of lines to allow, -1 for no limit- Returns:
- the processed tiptext
-
processTipText
public static String processTipText(String text)
Parses the tool tip and turns it into HTML if it contains line breaks.- Parameters:
text- the tiptext to parse, can be null- Returns:
- the processed tiptext
-
getKeystrokeReplacements
protected static HashMap<String,String> getKeystrokeReplacements()
Returns the replacements for the keystrokes.- Returns:
- the replacements
-
processKeyStroke
public static String processKeyStroke(String keystroke)
Processes the keystrokes. For Macs, "ctrl/control" is replaced by "meta". Also, if no "ctrl/control/alt" is present, a "meta" is prefix. All other platforms simply return the string.- Parameters:
keystroke- the keystroke string to process- Returns:
- the (potentially) processed keystroke definition
-
getKeyStroke
public static KeyStroke getKeyStroke(String keystroke)
Creates a keystroke from the string.- Parameters:
keystroke- the keystroke string to turn into a- Returns:
- the generated keystroke
- See Also:
processKeyStroke(String)
-
findComponents
protected static void findComponents(Container parent, Class type, boolean recursive, boolean exact, List<Component> list, boolean onlyFirst)
Retrieves all components of the specified type starting with the given parent container.- Parameters:
parent- the container to start the search inrecursive- whether to recurse into other containersexact- whether the class must be exactly this type of merely derivedonlyFirst- whether to stop search once the first component was found
-
findAllComponents
public static List<Component> findAllComponents(Container parent, Class type, boolean recursive, boolean exact)
Retrieves all components of the specified type starting with the given parent container.- Parameters:
parent- the container to start the search inrecursive- whether to recurse into other containersexact- whether the class must be exactly this type of merely derived- Returns:
- the list of located components
-
findFirstComponent
public static Component findFirstComponent(Container parent, Class type, boolean recursive, boolean exact)
Retrieves the first component of the specified type starting with the given parent container.- Parameters:
parent- the container to start the search inrecursive- whether to recurse into other containersexact- whether the class must be exactly this type of merely derived- Returns:
- the located component or null if none found
-
configureAntiAliasing
public static void configureAntiAliasing(Graphics g, boolean enable)
Enables/disables anti-aliasing in the Graphics context.- Parameters:
g- the graphics context to enable/disable anti-aliasing forenable- if true anti-aliasing gets enabled, otherwise disabled
-
getTopLevelMenu
public static JMenu getTopLevelMenu(JMenuItem menuitem)
Determines the top-level menu (the one sitting inside the JMenuBar) that is associated with a menu item.- Parameters:
menuitem- the menu item to get the menu bar for- Returns:
- the menu, null if not found
-
launchMenuItem
public static boolean launchMenuItem(Container source, Class menuitem)
Attempts to launch the specified menuitem. Requires to find the overall application frame in order to launch the menu item.- Parameters:
source- where the menuitem launch originated frommenuitem- the menuitem class to launch- Returns:
- true if successfully launched
-
showPopupMenu
public static void showPopupMenu(JPopupMenu menu, Component invoker, MouseEvent e)
Displays a popup menu.- Parameters:
menu- the menu to showinvoker- the invoking componente- the absolute positions on screen of the event are used
-
showPopupMenu
public static void showPopupMenu(JPopupMenu menu, Component invoker, int x, int y)
Displays a popup menu.- Parameters:
menu- the menu to showinvoker- the invoking componentx- the absolute X position on screeny- the absolute Y position on screen
-
getGraphicsConfiguration
public static GraphicsConfiguration getGraphicsConfiguration(Component comp)
Tries to determine theGraphicsConfigurationthat the specified component is located on.- Parameters:
comp- the component to determine the graphics config for- Returns:
- the config, null if failed to determine
-
getGraphicsDevice
public static GraphicsDevice getGraphicsDevice(Component comp)
Tries to determine theGraphicsDevicethat the specified component is located on.- Parameters:
comp- the component to determine the graphics device for- Returns:
- the device, null if failed to determine
-
getDefaultDialogDimension
public static Dimension getDefaultDialogDimension()
Returns the default dimensions for a dialog.- Returns:
- the default
-
getDefaultSmallDialogDimension
public static Dimension getDefaultSmallDialogDimension()
Returns the default dimensions for a small dialog.- Returns:
- the default
-
getDefaultTinyDialogDimension
public static Dimension getDefaultTinyDialogDimension()
Returns the default dimensions for a tiny dialog.- Returns:
- the default
-
getDefaultLargeDialogDimension
public static Dimension getDefaultLargeDialogDimension()
Returns the default dimensions for a large dialog.- Returns:
- the default
-
enlarge
public static Dimension enlarge(Dimension size)
Makes the rectangle taller/wider by 20%.- Parameters:
size- the current size- Returns:
- the taller/wider rectangle
-
enlarge
public static Dimension enlarge(Dimension size, double percentage)
Makes the rectangle taller/wider.- Parameters:
size- the current sizepercentage- the percentage to increase the size with- Returns:
- the taller/wider rectangle
-
shrink
public static Dimension shrink(Dimension size)
Makes the rectangle smaller/narrower by 20%.- Parameters:
size- the current size- Returns:
- the smaller/narrower rectangle
-
shrink
public static Dimension shrink(Dimension size, double percentage)
Makes the rectangle smaller/narrower.- Parameters:
size- the current sizepercentage- the percentage to decrease the size with- Returns:
- the smaller/narrower rectangle
-
makeWider
public static Dimension makeWider(Dimension size)
Widens the rectangle by 20%.- Parameters:
size- the current size- Returns:
- the widened rectangle
-
makeWider
public static Dimension makeWider(Dimension size, double percent)
Widens the rectangle by the specified percentage.- Parameters:
size- the current sizepercent- the percentage to make it wider (0-1)- Returns:
- the widened rectangle
-
makeNarrower
public static Dimension makeNarrower(Dimension size)
Narrows the rectangle by 20%.- Parameters:
size- the current size- Returns:
- the narrowed rectangle
-
makeNarrower
public static Dimension makeNarrower(Dimension size, double percent)
Narrows the rectangle by the specified percentage.- Parameters:
size- the current sizepercent- the percentage to make it narrower (0-1)- Returns:
- the narrowed rectangle
-
makeTaller
public static Dimension makeTaller(Dimension size)
Males the rectangle taller by 20%.- Parameters:
size- the current size- Returns:
- the taller rectangle
-
makeTaller
public static Dimension makeTaller(Dimension size, double percent)
Makes the rectangle taller by the specified percentage.- Parameters:
size- the current sizepercent- the percentage to make it taller (0-1)- Returns:
- the taller rectangle
-
makeSmaller
public static Dimension makeSmaller(Dimension size)
Makes the rectangle's height smaller by 20%.- Parameters:
size- the current size- Returns:
- the smaller rectangle
-
makeSmaller
public static Dimension makeSmaller(Dimension size, double percent)
Makes the rectangle's height smaller by the specified percentage.- Parameters:
size- the current sizepercent- the percentage to make it smaller (0-1)- Returns:
- the smaller rectangle
-
makeAtLeast
public static Dimension makeAtLeast(Dimension current, Dimension min)
Makes the dimensions at least the specified size.- Parameters:
current- the current dimensions to potentially resizemin- the minimum dimensions- Returns:
- null if no update necessary, otherwise the new dimensions
-
makeAtLeast
public static boolean makeAtLeast(Component window, Dimension min)
Makes the window at least the specified size.- Parameters:
window- the window to potentially resizemin- the minimum dimensions- Returns:
- true if updated
-
makeAtMost
public static Dimension makeAtMost(Dimension current, Dimension max)
Makes the dimensions at most the specified size.- Parameters:
current- the current dimensions to potentially resizemax- the maximum dimensions- Returns:
- null if no update necessary, otherwise the new dimensions
-
makeAtMost
public static boolean makeAtMost(Component window, Dimension max)
Makes the window at most the specified size.- Parameters:
window- the window to potentially resizemax- the maximum dimensions- Returns:
- true if updated
-
makeFit
public static Dimension makeFit(Dimension current, Dimension min, Dimension max)
Fits the dimensions between min/max.- Parameters:
current- the dimensions to adjustmin- the minimum size, ignored if nullmax- the maximum size, ignored if null- Returns:
- null if no need to update, otherwise the recommended dimensions
-
pack
public static boolean pack(Window window, Dimension min, Dimension max)
Packs the window, but ensures that it fits between min/max.- Parameters:
window- the window to adjustmin- the minimum size, ignored if nullmax- the maximum size, ignored if null- Returns:
- true if updated
-
makeHalfScreenWidth
public static void makeHalfScreenWidth(Component c)
Changes the width of the window to half of the screen width.- Parameters:
c- the component whose window to adjust
-
makeHalfScreenHeight
public static void makeHalfScreenHeight(Component c)
Changes the height of the window to half of the screen width.- Parameters:
c- the component whose window to adjust
-
rotate
public static Dimension rotate(Dimension rect)
Rotates the rectangle by 90 degrees.- Parameters:
rect- the rectangle- Returns:
- the rotated rectangle
-
getPreferredButtonHeight
public static int getPreferredButtonHeight()
Returns the preferred button height.- Returns:
- the button height
-
getPreferredTextFieldHeight
public static int getPreferredTextFieldHeight()
Returns the preferred textfield height.- Returns:
- the textfield height
-
getPreferredSpinnerHeight
public static int getPreferredSpinnerHeight()
Returns the preferred spinner height.- Returns:
- the spinner height
-
getPreferredCheckBoxHeight
public static int getPreferredCheckBoxHeight()
Returns the preferred checkbox height.- Returns:
- the checkbox height
-
getPreferredComboBoxHeight
public static int getPreferredComboBoxHeight()
Returns the preferred combobox height.- Returns:
- the combobox height
-
getDisplayScaleFactor
public static double getDisplayScaleFactor()
Returns the scale factor for the display.- Returns:
- the scale factor
-
scale
public static int scale(int size)
Applies the global scale factor to the size.- Parameters:
size- the size to scale- Returns:
- the scaled size
-
scale
public static double scale(double size)
Applies the global scale factor to the size.- Parameters:
size- the size to scale- Returns:
- the scaled size
-
scale
public static Dimension scale(Dimension size)
Applies the global scale factor to the size.- Parameters:
size- the size to scale- Returns:
- the scaled size
-
isHeadless
public static boolean isHeadless()
Returns whether we are running in headless mode.- Returns:
- true if in headless mode
-
setHeadless
public static void setHeadless(boolean value)
Sets the headless mode.- Parameters:
value- true if in headless mode
-
doInBackground
public static SwingWorker doInBackground(Runnable runnable)
- Parameters:
runnable- the code to execute- Returns:
- the SwingWorker instance
-
screenshot
public static BufferedImage screenshot(JComponent comp)
Takes a screenshot of the component.- Parameters:
comp- the component to take a screenshot of- Returns:
- the screenshot
-
getMaxTooltipWidth
public static int getMaxTooltipWidth()
Returns the maximum width for tool tips.- Returns:
- the maximum
-
calculateFontOffset
public static int[] calculateFontOffset(Graphics g, Rectangle box)
Calculates the horizontal and vertical offsets for drawing text.- Parameters:
g- the graphics context to get the font metrics frombox- the rectangle to draw the text int- Returns:
- hoff=0, voff=1
-
setDefaultHorizontalTextOffset
public static void setDefaultHorizontalTextOffset(int value)
Sets the default horizontal offset for drawing strings in boxes.- Parameters:
value- the offset- See Also:
calculateFontOffset(Graphics, Rectangle)
-
getDefaultHorizontalTextOffset
public int getDefaultHorizontalTextOffset()
Returns the default horizontal offset for drawing strings in boxes.- Returns:
- the offset
- See Also:
calculateFontOffset(Graphics, Rectangle)
-
-