Package jadex.commons.gui
Class SGUI
- java.lang.Object
- 
- jadex.commons.gui.SGUI
 
- 
 public class SGUI extends java.lang.ObjectStatic helper class with useful gui related methods.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classSGUI.TextCopyPasteMouseListenerListener for copy-paste menu.
 - 
Field SummaryFields Modifier and Type Field Description static java.lang.StringAUTO_ADJUSTThis property can be set on components to be automatically adjusted to equal sizes.protected static java.util.Set<java.lang.String>BROKEN_UI_IDSIDs of potentially broken UIs that override behavior like setBackground().
 - 
Constructor SummaryConstructors Constructor Description SGUI()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddCopyPasteMenu(javax.swing.text.JTextComponent textcomponent)Adds a copy & paste menu to a text component.static voidadjustComponentHorizontalSizes(javax.swing.JComponent[] components)Adjust components to equal sizes according to their miminum, maximum, and preferred sizes horizontally.static voidadjustComponentSizes(java.awt.Component[] components)Adjust components to equal sizes according to their miminum, maximum, and preferred sizes.static voidadjustComponentSizes(java.awt.Container parent)Adjust all marked components to equal sizes according to their miminum, maximum, and preferred sizes.static voidadjustComponentSizes(javax.swing.JComponent[] components)Adjust components to equal sizes according to their miminum, maximum, and preferred sizes.static voidadjustComponentVerticalSizes(javax.swing.JComponent[] components)Adjust components to equal sizes according to their miminum, maximum, and preferred sizes vertically.static java.awt.PointcalculateMiddlePosition(java.awt.Window win)Calculate the middle position of a window relativ tostatic java.awt.PointcalculateMiddlePosition(java.awt.Window outer, java.awt.Window win)Calculate the middle position of a window relativ tostatic java.lang.StringcolorToHTML(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.BufferedImageconvertBufferedImageType(java.awt.image.BufferedImage original, int type)Converts a buffered image to a new image type.static javax.swing.ActioncreateAction(java.lang.String name, javax.swing.Icon icon, java.awt.event.ActionListener listener)Create an action.static booleancreateDialog(java.lang.String title, javax.swing.JComponent content, javax.swing.JComponent comp)Create a dialog with a specific content panel.static booleancreateDialog(java.lang.String title, javax.swing.JComponent content, javax.swing.JComponent comp, boolean info)Create a dialog with a specific content panel.static voidcreateEdgelessHorizontalGroupLayout(java.awt.Container container, javax.swing.JComponent[] components, boolean fixedsize)Creates a simple edgeless, vertical arrangement using group layout.static voidcreateEdgelessHorizontalGroupLayout(java.awt.Container container, javax.swing.JComponent[] components, boolean fixedsize, boolean rightalign)Creates a simple edgeless, vertical arrangement using group layout.static voidcreateHorizontalGroupLayout(java.awt.Container container, javax.swing.JComponent[] components, boolean fixedsize)Creates a simple vertical arrangement using group layout with gaps.static javax.swing.JMenuBarcreateMenuBar(javax.swing.Action[] actions)Create a menu bar, given a list of actions.static javax.swing.JTablecreateReadOnlyTable()Create a table that displays its contents using nto editable text fields.static javax.swing.JToolBarcreateToolBar(java.lang.String name, javax.swing.Action[] actions)Create a tool bar, given a list of actions.static voidcreateVerticalGroupLayout(java.awt.Container container, javax.swing.JComponent[] components, boolean fixedsize)Creates a simple vertical arrangement using group layout with gaps.static java.lang.StringfontToHTML(java.awt.Font font)Convert a font to an html representation.static doublegetProportionalDividerLocation(javax.swing.JSplitPane pane)Get the proportional split location.static intgetSelectedButton(javax.swing.ButtonGroup bg)Gets the index of the selected button in a button group.static java.lang.StringgetText(javax.swing.JTextArea area)Shortcut method.static java.awt.WindowgetWindowParent(java.awt.Component comp)Get the window parent if any.static voidinvokeLater(java.lang.Runnable runnable)Use SwingUtilities to put the given runnable in the AWT Event queue.static voidinvokeLaterSimBlock(java.lang.Runnable runnable)Invoke on swing thread and sync with simulation if any.static java.lang.ObjectmakeIcon(java.lang.Class baseclass, java.lang.String imgloc)Utility method that creates a UIDefaults.LazyValue that creates an ImageIcon for the specifiedgifFilefilename.static voidremoveCopyPasteMenu(javax.swing.text.JTextComponent textcomponent)Removes copy & paste menu from a text component.static voidrenderObject(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.ColorrgbaToColor(double[] rgba)Converts a RGBA array to color.static java.awt.image.BufferedImagescaleBufferedImage(java.awt.image.BufferedImage original, int w, int h)Scales a buffered image.static java.awt.image.BufferedImagescaleImage(java.awt.Image src, int w, int h, int type)Scale an image.static voidsetAllEnabled(javax.swing.ButtonGroup bg, boolean enabled)Sets the enabled state of all buttons in a button group.static voidsetMinimumSize(javax.swing.JComponent c, int w, int h)Sets the minimum size along with the preferred size.static voidsetText(javax.swing.JTextArea area, java.lang.String text)Shortcut method.static voidshowError(java.awt.Component parent, java.lang.String errortitle, java.lang.String errormessage, java.lang.Exception exception)Display an error dialog.static voidshowMessageDialog(java.awt.Component parent, java.lang.Object message, java.lang.String title, int msgtype)Show an non-model message dialog.static java.awt.ColorstringToColor(java.lang.String str)Color conversion method for "web-style" color definitions.
 
- 
- 
- 
Field Detail- 
AUTO_ADJUSTpublic 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_IDSprotected static final java.util.Set<java.lang.String> BROKEN_UI_IDS IDs of potentially broken UIs that override behavior like setBackground().
 
- 
 - 
Method Detail- 
createMenuBarpublic 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.
 
 - 
createToolBarpublic 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.
 
 - 
createActionpublic 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.
 
 - 
createDialogpublic static boolean createDialog(java.lang.String title, javax.swing.JComponent content, javax.swing.JComponent comp)Create a dialog with a specific content panel.
 - 
createDialogpublic 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.
 - 
makeIconpublic 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 specifiedgifFilefilename.
 - 
renderObjectpublic 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.
 
 - 
calculateMiddlePositionpublic static java.awt.Point calculateMiddlePosition(java.awt.Window win) Calculate the middle position of a window relativ to
 - 
calculateMiddlePositionpublic static java.awt.Point calculateMiddlePosition(java.awt.Window outer, java.awt.Window win)Calculate the middle position of a window relativ to
 - 
getWindowParentpublic static java.awt.Window getWindowParent(java.awt.Component comp) Get the window parent if any.- Parameters:
- comp- The component.
- Returns:
- The window if any.
 
 - 
showMessageDialogpublic static void showMessageDialog(java.awt.Component parent, java.lang.Object message, java.lang.String title, int msgtype)Show an non-model message dialog.
 - 
showErrorpublic 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).
 
 - 
adjustComponentSizespublic 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.
 - 
adjustComponentSizespublic static void adjustComponentSizes(javax.swing.JComponent[] components) Adjust components to equal sizes according to their miminum, maximum, and preferred sizes.
 - 
adjustComponentHorizontalSizespublic static void adjustComponentHorizontalSizes(javax.swing.JComponent[] components) Adjust components to equal sizes according to their miminum, maximum, and preferred sizes horizontally.
 - 
adjustComponentVerticalSizespublic static void adjustComponentVerticalSizes(javax.swing.JComponent[] components) Adjust components to equal sizes according to their miminum, maximum, and preferred sizes vertically.
 - 
adjustComponentSizespublic 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_ADJUSTproperty to an arbitrary value.
 - 
setMinimumSizepublic 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.
 
 - 
createVerticalGroupLayoutpublic 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.
 
 - 
createHorizontalGroupLayoutpublic 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.
 
 - 
createEdgelessHorizontalGroupLayoutpublic 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.
 
 - 
createEdgelessHorizontalGroupLayoutpublic 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.
 
 - 
createReadOnlyTablepublic static javax.swing.JTable createReadOnlyTable() Create a table that displays its contents using nto editable text fields.
 - 
getProportionalDividerLocationpublic static double getProportionalDividerLocation(javax.swing.JSplitPane pane) Get the proportional split location.
 - 
stringToColorpublic 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.
 - 
colorToHTMLpublic 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.
 
 - 
fontToHTMLpublic 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.
 
 - 
scaleImagepublic 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).
 
 - 
convertBufferedImageTypepublic 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.
 
 - 
getSelectedButtonpublic 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.
 
 - 
setAllEnabledpublic 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
 
 - 
scaleBufferedImagepublic 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.
 
 - 
invokeLaterpublic static void invokeLater(java.lang.Runnable runnable) Use SwingUtilities to put the given runnable in the AWT Event queue.- Parameters:
- runnable-
 
 - 
invokeLaterSimBlockpublic static void invokeLaterSimBlock(java.lang.Runnable runnable) Invoke on swing thread and sync with simulation if any.
 - 
getTextpublic 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.
 
 - 
setTextpublic 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.
 
 - 
addCopyPasteMenupublic static void addCopyPasteMenu(javax.swing.text.JTextComponent textcomponent) Adds a copy & paste menu to a text component.- Parameters:
- textcomponent- The text component.
 
 - 
removeCopyPasteMenupublic static void removeCopyPasteMenu(javax.swing.text.JTextComponent textcomponent) Removes copy & paste menu from a text component.- Parameters:
- textcomponent- The text component.
 
 - 
colorToRgbapublic static double[] colorToRgba(java.awt.Color color) Converts a color to RGBA array.
 - 
rgbaToColorpublic static java.awt.Color rgbaToColor(double[] rgba) Converts a RGBA array to color.
 
- 
 
-