Package jadex.common
Class SGUI
java.lang.Object
jadex.common.SGUI
Static helper class with useful gui related methods.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
This property can be set on components to be automatically adjusted to equal sizes.IDs of potentially broken UIs that override behavior like setBackground(). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
adjustComponentHorizontalSizes
(JComponent[] components) Adjust components to equal sizes according to their miminum, maximum, and preferred sizes horizontally.static void
adjustComponentSizes
(Component[] components) Adjust components to equal sizes according to their miminum, maximum, and preferred sizes.static void
adjustComponentSizes
(Container parent) Adjust all marked components to equal sizes according to their miminum, maximum, and preferred sizes.static void
adjustComponentSizes
(JComponent[] components) Adjust components to equal sizes according to their miminum, maximum, and preferred sizes.static void
adjustComponentVerticalSizes
(JComponent[] components) Adjust components to equal sizes according to their miminum, maximum, and preferred sizes vertically.static Point
Calculate the middle position of a window relativ tostatic Point
calculateMiddlePosition
(Window outer, Window win) Calculate the middle position of a window relativ tostatic String
colorToHTML
(Color color) Convert a color to an html representation.static double[]
colorToRgba
(Color color) Converts a color to RGBA array.static final BufferedImage
convertBufferedImageType
(BufferedImage original, int type) Converts a buffered image to a new image type.static Action
createAction
(String name, Icon icon, ActionListener listener) Create an action.static boolean
createDialog
(String title, JComponent content, JComponent comp) Create a dialog with a specific content panel.static boolean
createDialog
(String title, JComponent content, JComponent comp, boolean info) Create a dialog with a specific content panel.static void
createEdgelessHorizontalGroupLayout
(Container container, JComponent[] components, boolean fixedsize) Creates a simple edgeless, vertical arrangement using group layout.static void
createEdgelessHorizontalGroupLayout
(Container container, JComponent[] components, boolean fixedsize, boolean rightalign) Creates a simple edgeless, vertical arrangement using group layout.static void
createHorizontalGroupLayout
(Container container, JComponent[] components, boolean fixedsize) Creates a simple vertical arrangement using group layout with gaps.static JMenuBar
createMenuBar
(Action[] actions) Create a menu bar, given a list of actions.static JTable
Create a table that displays its contents using nto editable text fields.static JToolBar
createToolBar
(String name, Action[] actions) Create a tool bar, given a list of actions.static void
createVerticalGroupLayout
(Container container, JComponent[] components, boolean fixedsize) Creates a simple vertical arrangement using group layout with gaps.static String
fontToHTML
(Font font) Convert a font to an html representation.static double
Get the proportional split location.static int
Gets the index of the selected button in a button group.static final String
Shortcut method.static Window
getWindowParent
(Component comp) Get the window parent if any.static void
invokeLater
(Runnable runnable) Use SwingUtilities to put the given runnable in the AWT Event queue.static Object
Utility method that creates a UIDefaults.LazyValue that creates an ImageIcon for the specifiedgifFile
filename.static void
openInBrowser
(String url) Open the url in the browser.static void
renderObject
(Graphics g, Component comp, double cellw, double cellh, int x, int y, int gridwidth) Render an object on a grid.static Color
rgbaToColor
(double[] rgba) Converts a RGBA array to color.static final BufferedImage
scaleBufferedImage
(BufferedImage original, int w, int h) Scales a buffered image.static final BufferedImage
scaleImage
(Image src, int w, int h, int type) Scale an image.static void
setAllEnabled
(ButtonGroup bg, boolean enabled) Sets the enabled state of all buttons in a button group.static void
setMinimumSize
(JComponent c, int w, int h) Sets the minimum size along with the preferred size.static final void
Shortcut method.static void
Display an error dialog.static void
showMessageDialog
(Component parent, Object message, String title, int msgtype) Show an non-model message dialog.static Color
stringToColor
(String str) Color conversion method for "web-style" color definitions.
-
Field Details
-
AUTO_ADJUST
This property can be set on components to be automatically adjusted to equal sizes.- See Also:
-
BROKEN_UI_IDS
IDs of potentially broken UIs that override behavior like setBackground().
-
-
Constructor Details
-
SGUI
public SGUI()
-
-
Method Details
-
createMenuBar
Create a menu bar, given a list of actions.- Parameters:
actions
- The actions (null is mapped to separator).- Returns:
- A menu bar with a menu containing the actions.
-
createToolBar
Create a tool bar, given a list of actions.- Parameters:
name
- The name of the toolbar.actions
- The actions (null is mapped to separator).- Returns:
- A tool bar containing the actions.
-
createAction
Create an action.- Parameters:
name
- The name.icon
- The path to the icon.listener
- The action listener.- Returns:
- The action.
-
createDialog
Create a dialog with a specific content panel. -
createDialog
Create a dialog with a specific content panel. -
makeIcon
Utility method that creates a UIDefaults.LazyValue that creates an ImageIcon for the specifiedgifFile
filename. -
renderObject
public static void renderObject(Graphics g, Component comp, double cellw, double cellh, int x, int y, int gridwidth) Render an object on a grid.- Parameters:
g
- The graphics object.comp
- The object to render.cellw
- The cell width.cellh
- The cell height.
-
calculateMiddlePosition
Calculate the middle position of a window relativ to -
calculateMiddlePosition
Calculate the middle position of a window relativ to -
getWindowParent
Get the window parent if any.- Parameters:
comp
- The component.- Returns:
- The window if any.
-
showMessageDialog
Show an non-model message dialog. -
showError
public static void showError(Component parent, String errortitle, String errormessage, Exception exception) Display an error dialog.- Parameters:
errortitle
- The title to use for an error dialog (required).errormessage
- An optional error message displayed before the exception.exception
- The exception (if any).
-
adjustComponentSizes
Adjust components to equal sizes according to their miminum, maximum, and preferred sizes. All components must be JComponents, this performs automatic array conversion. -
adjustComponentSizes
Adjust components to equal sizes according to their miminum, maximum, and preferred sizes. -
adjustComponentHorizontalSizes
Adjust components to equal sizes according to their miminum, maximum, and preferred sizes horizontally. -
adjustComponentVerticalSizes
Adjust components to equal sizes according to their miminum, maximum, and preferred sizes vertically. -
adjustComponentSizes
Adjust all marked components to equal sizes according to their miminum, maximum, and preferred sizes. The mark is given by setting theAUTO_ADJUST
property to an arbitrary value. -
setMinimumSize
Sets the minimum size along with the preferred size. Negative values will remain the same.- Parameters:
c
- Component.w
- Width.h
- Height.
-
createVerticalGroupLayout
public static void createVerticalGroupLayout(Container container, JComponent[] components, boolean fixedsize) Creates a simple vertical arrangement using group layout with gaps. Automatically adds the components.- Parameters:
container
- The container.components
- The components.
-
createHorizontalGroupLayout
public static void createHorizontalGroupLayout(Container container, JComponent[] components, boolean fixedsize) Creates a simple vertical arrangement using group layout with gaps. Automatically adds the components.- Parameters:
container
- The container.components
- The components.
-
createEdgelessHorizontalGroupLayout
public static void createEdgelessHorizontalGroupLayout(Container container, JComponent[] components, boolean fixedsize) Creates a simple edgeless, vertical arrangement using group layout. Automatically adds the components.- Parameters:
container
- The container.components
- The components.
-
createEdgelessHorizontalGroupLayout
public static void createEdgelessHorizontalGroupLayout(Container container, JComponent[] components, boolean fixedsize, boolean rightalign) Creates a simple edgeless, vertical arrangement using group layout. Automatically adds the components.- Parameters:
container
- The container.components
- The components.
-
createReadOnlyTable
Create a table that displays its contents using nto editable text fields. -
getProportionalDividerLocation
Get the proportional split location. -
stringToColor
Color conversion method for "web-style" color definitions. This method is needed because CSS.stringToColor() is protected and StyleSheet.stringToColor() may be unavailable without a GUI. -
colorToHTML
Convert a color to an html representation.- Parameters:
color
- The color.- Returns:
- The html string representing the color.
-
fontToHTML
Convert a font to an html representation.- Parameters:
font
- The font.- Returns:
- The html string representing the font.
-
scaleImage
Scale an image.- Parameters:
w
- The width.h
- The height.type
- The type (Image.SCALE_XYZ).scr
- The src image.
-
convertBufferedImageType
Converts a buffered image to a new image type. E.g. BufferedImage.TYPE_4BYTE_ABGR_PRE.- Parameters:
original
- Original image.type
- New type.- Returns:
- Converted image.
-
getSelectedButton
Gets the index of the selected button in a button group.- Parameters:
bg
- The button group.- Returns:
- The selected index.
-
setAllEnabled
Sets the enabled state of all buttons in a button group.- Parameters:
bg
- The button group.enabled
- True, if enabled
-
scaleBufferedImage
Scales a buffered image.- Parameters:
original
- Original image.w
- New width.h
- New height.- Returns:
- Scaled image.
-
invokeLater
Use SwingUtilities to put the given runnable in the AWT Event queue.- Parameters:
runnable
-
-
getText
Shortcut method. Text extraction from the Java "Document" class used by JTextArea is braindead, it throws checked exception, lots of parameters: Bloat, bloat, bloat.- Parameters:
doc
- The text area.- Returns:
- The extracted String.
-
setText
Shortcut method. Setting text the Java "Document" class used by JTextArea is braindead, it throws non-RuntimeException, multiple invocations, many parameters: Bloat, bloat, bloat.- Parameters:
doc
- The document.
-
colorToRgba
Converts a color to RGBA array. -
rgbaToColor
Converts a RGBA array to color. -
openInBrowser
Open the url in the browser.- Parameters:
url
- The url.
-