Package jadex.commons.gui
Class SGUI
- java.lang.Object
-
- jadex.commons.gui.SGUI
-
public class SGUI extends java.lang.Object
Static helper class with useful gui related methods.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SGUI.TextCopyPasteMouseListener
Listener for copy-paste menu.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
AUTO_ADJUST
This property can be set on components to be automatically adjusted to equal sizes.protected static java.util.Set<java.lang.String>
BROKEN_UI_IDS
IDs of potentially broken UIs that override behavior like setBackground().
-
Constructor Summary
Constructors Constructor Description SGUI()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addCopyPasteMenu(javax.swing.text.JTextComponent textcomponent)
Adds a copy & paste menu to a text component.static void
adjustComponentHorizontalSizes(javax.swing.JComponent[] components)
Adjust components to equal sizes according to their miminum, maximum, and preferred sizes horizontally.static void
adjustComponentSizes(java.awt.Component[] components)
Adjust components to equal sizes according to their miminum, maximum, and preferred sizes.static void
adjustComponentSizes(java.awt.Container parent)
Adjust all marked components to equal sizes according to their miminum, maximum, and preferred sizes.static void
adjustComponentSizes(javax.swing.JComponent[] components)
Adjust components to equal sizes according to their miminum, maximum, and preferred sizes.static void
adjustComponentVerticalSizes(javax.swing.JComponent[] components)
Adjust components to equal sizes according to their miminum, maximum, and preferred sizes vertically.static java.awt.Point
calculateMiddlePosition(java.awt.Window win)
Calculate the middle position of a window relativ tostatic java.awt.Point
calculateMiddlePosition(java.awt.Window outer, java.awt.Window win)
Calculate the middle position of a window relativ tostatic java.lang.String
colorToHTML(java.awt.Color color)
Convert a color to an html representation.static double[]
colorToRgba(java.awt.Color color)
Converts a color to RGBA array.static java.awt.image.BufferedImage
convertBufferedImageType(java.awt.image.BufferedImage original, int type)
Converts a buffered image to a new image type.static javax.swing.Action
createAction(java.lang.String name, javax.swing.Icon icon, java.awt.event.ActionListener listener)
Create an action.static boolean
createDialog(java.lang.String title, javax.swing.JComponent content, javax.swing.JComponent comp)
Create a dialog with a specific content panel.static boolean
createDialog(java.lang.String title, javax.swing.JComponent content, javax.swing.JComponent comp, boolean info)
Create a dialog with a specific content panel.static void
createEdgelessHorizontalGroupLayout(java.awt.Container container, javax.swing.JComponent[] components, boolean fixedsize)
Creates a simple edgeless, vertical arrangement using group layout.static void
createEdgelessHorizontalGroupLayout(java.awt.Container container, javax.swing.JComponent[] components, boolean fixedsize, boolean rightalign)
Creates a simple edgeless, vertical arrangement using group layout.static void
createHorizontalGroupLayout(java.awt.Container container, javax.swing.JComponent[] components, boolean fixedsize)
Creates a simple vertical arrangement using group layout with gaps.static javax.swing.JMenuBar
createMenuBar(javax.swing.Action[] actions)
Create a menu bar, given a list of actions.static javax.swing.JTable
createReadOnlyTable()
Create a table that displays its contents using nto editable text fields.static javax.swing.JToolBar
createToolBar(java.lang.String name, javax.swing.Action[] actions)
Create a tool bar, given a list of actions.static void
createVerticalGroupLayout(java.awt.Container container, javax.swing.JComponent[] components, boolean fixedsize)
Creates a simple vertical arrangement using group layout with gaps.static java.lang.String
fontToHTML(java.awt.Font font)
Convert a font to an html representation.static double
getProportionalDividerLocation(javax.swing.JSplitPane pane)
Get the proportional split location.static int
getSelectedButton(javax.swing.ButtonGroup bg)
Gets the index of the selected button in a button group.static java.lang.String
getText(javax.swing.JTextArea area)
Shortcut method.static java.awt.Window
getWindowParent(java.awt.Component comp)
Get the window parent if any.static void
invokeLater(java.lang.Runnable runnable)
Use SwingUtilities to put the given runnable in the AWT Event queue.static void
invokeLaterSimBlock(java.lang.Runnable runnable)
Invoke on swing thread and sync with simulation if any.static java.lang.Object
makeIcon(java.lang.Class baseclass, java.lang.String imgloc)
Utility method that creates a UIDefaults.LazyValue that creates an ImageIcon for the specifiedgifFile
filename.static void
removeCopyPasteMenu(javax.swing.text.JTextComponent textcomponent)
Removes copy & paste menu from a text component.static void
renderObject(java.awt.Graphics g, java.awt.Component comp, double cellw, double cellh, int x, int y, int gridwidth)
Render an object on a grid.static java.awt.Color
rgbaToColor(double[] rgba)
Converts a RGBA array to color.static java.awt.image.BufferedImage
scaleBufferedImage(java.awt.image.BufferedImage original, int w, int h)
Scales a buffered image.static java.awt.image.BufferedImage
scaleImage(java.awt.Image src, int w, int h, int type)
Scale an image.static void
setAllEnabled(javax.swing.ButtonGroup bg, boolean enabled)
Sets the enabled state of all buttons in a button group.static void
setMinimumSize(javax.swing.JComponent c, int w, int h)
Sets the minimum size along with the preferred size.static void
setText(javax.swing.JTextArea area, java.lang.String text)
Shortcut method.static void
showError(java.awt.Component parent, java.lang.String errortitle, java.lang.String errormessage, java.lang.Exception exception)
Display an error dialog.static void
showMessageDialog(java.awt.Component parent, java.lang.Object message, java.lang.String title, int msgtype)
Show an non-model message dialog.static java.awt.Color
stringToColor(java.lang.String str)
Color conversion method for "web-style" color definitions.
-
-
-
Field Detail
-
AUTO_ADJUST
public static final java.lang.String AUTO_ADJUST
This property can be set on components to be automatically adjusted to equal sizes.- See Also:
- Constant Field Values
-
BROKEN_UI_IDS
protected static final java.util.Set<java.lang.String> BROKEN_UI_IDS
IDs of potentially broken UIs that override behavior like setBackground().
-
-
Method Detail
-
createMenuBar
public static javax.swing.JMenuBar createMenuBar(javax.swing.Action[] actions)
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
public static javax.swing.JToolBar createToolBar(java.lang.String name, javax.swing.Action[] actions)
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
public static javax.swing.Action createAction(java.lang.String name, javax.swing.Icon icon, java.awt.event.ActionListener listener)
Create an action.- Parameters:
name
- The name.icon
- The path to the icon.listener
- The action listener.- Returns:
- The action.
-
createDialog
public static boolean createDialog(java.lang.String title, javax.swing.JComponent content, javax.swing.JComponent comp)
Create a dialog with a specific content panel.
-
createDialog
public static boolean createDialog(java.lang.String title, javax.swing.JComponent content, javax.swing.JComponent comp, boolean info)
Create a dialog with a specific content panel.
-
makeIcon
public static java.lang.Object makeIcon(java.lang.Class baseclass, java.lang.String imgloc)
Utility method that creates a UIDefaults.LazyValue that creates an ImageIcon for the specifiedgifFile
filename.
-
renderObject
public static void renderObject(java.awt.Graphics g, java.awt.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
public static java.awt.Point calculateMiddlePosition(java.awt.Window win)
Calculate the middle position of a window relativ to
-
calculateMiddlePosition
public static java.awt.Point calculateMiddlePosition(java.awt.Window outer, java.awt.Window win)
Calculate the middle position of a window relativ to
-
getWindowParent
public static java.awt.Window getWindowParent(java.awt.Component comp)
Get the window parent if any.- Parameters:
comp
- The component.- Returns:
- The window if any.
-
showMessageDialog
public static void showMessageDialog(java.awt.Component parent, java.lang.Object message, java.lang.String title, int msgtype)
Show an non-model message dialog.
-
showError
public static void showError(java.awt.Component parent, java.lang.String errortitle, java.lang.String errormessage, java.lang.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
public static void adjustComponentSizes(java.awt.Component[] components)
Adjust components to equal sizes according to their miminum, maximum, and preferred sizes. All components must be JComponents, this performs automatic array conversion.
-
adjustComponentSizes
public static void adjustComponentSizes(javax.swing.JComponent[] components)
Adjust components to equal sizes according to their miminum, maximum, and preferred sizes.
-
adjustComponentHorizontalSizes
public static void adjustComponentHorizontalSizes(javax.swing.JComponent[] components)
Adjust components to equal sizes according to their miminum, maximum, and preferred sizes horizontally.
-
adjustComponentVerticalSizes
public static void adjustComponentVerticalSizes(javax.swing.JComponent[] components)
Adjust components to equal sizes according to their miminum, maximum, and preferred sizes vertically.
-
adjustComponentSizes
public static void adjustComponentSizes(java.awt.Container parent)
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
public static void setMinimumSize(javax.swing.JComponent c, int w, int h)
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(java.awt.Container container, javax.swing.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(java.awt.Container container, javax.swing.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(java.awt.Container container, javax.swing.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(java.awt.Container container, javax.swing.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
public static javax.swing.JTable createReadOnlyTable()
Create a table that displays its contents using nto editable text fields.
-
getProportionalDividerLocation
public static double getProportionalDividerLocation(javax.swing.JSplitPane pane)
Get the proportional split location.
-
stringToColor
public static java.awt.Color stringToColor(java.lang.String str)
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
public static java.lang.String colorToHTML(java.awt.Color color)
Convert a color to an html representation.- Parameters:
color
- The color.- Returns:
- The html string representing the color.
-
fontToHTML
public static java.lang.String fontToHTML(java.awt.Font font)
Convert a font to an html representation.- Parameters:
font
- The font.- Returns:
- The html string representing the font.
-
scaleImage
public static final java.awt.image.BufferedImage scaleImage(java.awt.Image src, int w, int h, int type)
Scale an image.- Parameters:
scr
- The src image.w
- The width.h
- The height.type
- The type (Image.SCALE_XYZ).
-
convertBufferedImageType
public static final java.awt.image.BufferedImage convertBufferedImageType(java.awt.image.BufferedImage original, int type)
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
public static int getSelectedButton(javax.swing.ButtonGroup bg)
Gets the index of the selected button in a button group.- Parameters:
bg
- The button group.- Returns:
- The selected index.
-
setAllEnabled
public static void setAllEnabled(javax.swing.ButtonGroup bg, boolean enabled)
Sets the enabled state of all buttons in a button group.- Parameters:
bg
- The button group.enabled
- True, if enabled
-
scaleBufferedImage
public static final java.awt.image.BufferedImage scaleBufferedImage(java.awt.image.BufferedImage original, int w, int h)
Scales a buffered image.- Parameters:
original
- Original image.w
- New width.h
- New height.- Returns:
- Scaled image.
-
invokeLater
public static void invokeLater(java.lang.Runnable runnable)
Use SwingUtilities to put the given runnable in the AWT Event queue.- Parameters:
runnable
-
-
invokeLaterSimBlock
public static void invokeLaterSimBlock(java.lang.Runnable runnable)
Invoke on swing thread and sync with simulation if any.
-
getText
public static final java.lang.String getText(javax.swing.JTextArea area)
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
public static final void setText(javax.swing.JTextArea area, java.lang.String text)
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.
-
addCopyPasteMenu
public static void addCopyPasteMenu(javax.swing.text.JTextComponent textcomponent)
Adds a copy & paste menu to a text component.- Parameters:
textcomponent
- The text component.
-
removeCopyPasteMenu
public static void removeCopyPasteMenu(javax.swing.text.JTextComponent textcomponent)
Removes copy & paste menu from a text component.- Parameters:
textcomponent
- The text component.
-
colorToRgba
public static double[] colorToRgba(java.awt.Color color)
Converts a color to RGBA array.
-
rgbaToColor
public static java.awt.Color rgbaToColor(double[] rgba)
Converts a RGBA array to color.
-
-