Package jadex.common

Class SGUI

java.lang.Object
jadex.common.SGUI

public class SGUI extends Object
Static helper class with useful gui related methods.
  • Field Details

    • AUTO_ADJUST

      public static final String AUTO_ADJUST
      This property can be set on components to be automatically adjusted to equal sizes.
      See Also:
    • BROKEN_UI_IDS

      protected static final Set<String> BROKEN_UI_IDS
      IDs of potentially broken UIs that override behavior like setBackground().
  • Constructor Details

    • SGUI

      public SGUI()
  • Method Details

    • createMenuBar

      public static JMenuBar createMenuBar(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 JToolBar createToolBar(String name, 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 Action createAction(String name, Icon icon, 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(String title, JComponent content, JComponent comp)
      Create a dialog with a specific content panel.
    • createDialog

      public static boolean createDialog(String title, JComponent content, JComponent comp, boolean info)
      Create a dialog with a specific content panel.
    • makeIcon

      public static Object makeIcon(Class<?> baseclass, String imgloc)
      Utility method that creates a UIDefaults.LazyValue that creates an ImageIcon for the specified gifFile 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

      public static Point calculateMiddlePosition(Window win)
      Calculate the middle position of a window relativ to
    • calculateMiddlePosition

      public static Point calculateMiddlePosition(Window outer, Window win)
      Calculate the middle position of a window relativ to
    • getWindowParent

      public static Window getWindowParent(Component comp)
      Get the window parent if any.
      Parameters:
      comp - The component.
      Returns:
      The window if any.
    • showMessageDialog

      public static void showMessageDialog(Component parent, Object message, String title, int msgtype)
      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

      public static void adjustComponentSizes(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(JComponent[] components)
      Adjust components to equal sizes according to their miminum, maximum, and preferred sizes.
    • adjustComponentHorizontalSizes

      public static void adjustComponentHorizontalSizes(JComponent[] components)
      Adjust components to equal sizes according to their miminum, maximum, and preferred sizes horizontally.
    • adjustComponentVerticalSizes

      public static void adjustComponentVerticalSizes(JComponent[] components)
      Adjust components to equal sizes according to their miminum, maximum, and preferred sizes vertically.
    • adjustComponentSizes

      public static void adjustComponentSizes(Container parent)
      Adjust all marked components to equal sizes according to their miminum, maximum, and preferred sizes. The mark is given by setting the AUTO_ADJUST property to an arbitrary value.
    • setMinimumSize

      public static void setMinimumSize(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(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

      public static JTable createReadOnlyTable()
      Create a table that displays its contents using nto editable text fields.
    • getProportionalDividerLocation

      public static double getProportionalDividerLocation(JSplitPane pane)
      Get the proportional split location.
    • stringToColor

      public static Color stringToColor(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 String colorToHTML(Color color)
      Convert a color to an html representation.
      Parameters:
      color - The color.
      Returns:
      The html string representing the color.
    • fontToHTML

      public static String fontToHTML(Font font)
      Convert a font to an html representation.
      Parameters:
      font - The font.
      Returns:
      The html string representing the font.
    • scaleImage

      public static final BufferedImage scaleImage(Image src, int w, int h, int type)
      Scale an image.
      Parameters:
      w - The width.
      h - The height.
      type - The type (Image.SCALE_XYZ).
      scr - The src image.
    • convertBufferedImageType

      public static final BufferedImage convertBufferedImageType(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(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(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 BufferedImage scaleBufferedImage(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(Runnable runnable)
      Use SwingUtilities to put the given runnable in the AWT Event queue.
      Parameters:
      runnable -
    • getText

      public static final String getText(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(JTextArea area, 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.
    • colorToRgba

      public static double[] colorToRgba(Color color)
      Converts a color to RGBA array.
    • rgbaToColor

      public static Color rgbaToColor(double[] rgba)
      Converts a RGBA array to color.
    • openInBrowser

      public static void openInBrowser(String url)
      Open the url in the browser.
      Parameters:
      url - The url.