Class CommonUI

java.lang.Object
com.inductiveautomation.ignition.designer.gui.CommonUI

public class CommonUI extends Object
A collection of static methods and constants to make the UI uniform.
  • Field Details

  • Constructor Details

    • CommonUI

      public CommonUI()
  • Method Details

    • getTooltipPrefix

      public static final String getTooltipPrefix(int width)
    • getTooltipPrefixInline

      public static final String getTooltipPrefixInline(int width)
    • wrapInTitledPanel

      public static JPanel wrapInTitledPanel(JComponent component, String bundleKey)
    • createLabel

      public static JLabel createLabel(String text, int mnemonic, Component comp)
      Creates a label which will be displayed.
      Parameters:
      text - Text for the label
      mnemonic - Hot key
      comp - Component that this label represents.
    • createLabel

      public static JLabel createLabel(String text)
    • createAccessoryButton

      public static JButton createAccessoryButton(Action action)
      Creates a small button for the given action with a 2px margin.
    • createToolbarButton

      public static AbstractButton createToolbarButton(Action action, String componentTestName)
      Returns a minimalized toolbar button with no text. The componentTestName parameter is used to set the component name for automated testing. It can be anything unique.
    • createTextField

      public static JTextField createTextField(String text, KeyListener listener, boolean numbers)
      Creates a text field
      Parameters:
      text - Text for the field
      listener - KeyListener
      numbers - Indicates that this field represents numbers only
    • createTextField

      public static JTextField createTextField(String text, boolean numbers)
    • createTextField

      public static JTextField createTextField(String text, KeyListener listener)
    • createTextField

      public static JTextField createTextField(String text)
    • createRadioButton

      public static JRadioButton createRadioButton(String text, int mnemonic, ActionListener listener, boolean selected)
      Creates a Radio Button
      Parameters:
      text - Text to display
      mnemonic - Hot key
      listener - ActionListener
      selected - Flag to indicate if button should be selected
    • createRadioButton

      public static JRadioButton createRadioButton(String text, int mnemonic, boolean selected)
    • createRadioButton

      public static JRadioButton createRadioButton(String text, int mnemonic, ActionListener listener)
    • createRadioButton

      public static JRadioButton createRadioButton(String text, int mnemonic)
    • createRadioButton

      public static JRadioButton createRadioButton(String text)
    • initButtonGroup

      public static void initButtonGroup(JRadioButton... buttons)
    • createCheckBox

      public static JCheckBox createCheckBox(String text, int mnemonic, ActionListener listener, boolean selected)
      Create a checkbox
      Parameters:
      text - to display
      mnemonic - Hot key
      listener - ActionListener
      selected - Flag to indicate if button should be selected
    • createCheckBox

      public static JCheckBox createCheckBox(String text, int mnemonic, ActionListener listener)
    • createCheckBox

      public static JCheckBox createCheckBox(String text, int mnemonic, boolean selected)
    • createCheckBox

      public static JCheckBox createCheckBox(String text, int mnemonic)
    • createCheckBox

      public static JCheckBox createCheckBox(String text)
    • createComboBox

      public static JComboBox createComboBox(Object[] items, ActionListener listener, boolean editable)
      Creates a JComboBox
      Parameters:
      items - Object array
      listener - The action listener which handles events
      editable - Flag that indicates if this combo box is editable
    • createComboBox

      public static JComboBox createComboBox(Object[] items, boolean editable)
    • createButton

      public static JButton createButton(String text, ActionListener listener, String mnemonic)
      Creates a JButton
      Parameters:
      text - to display
      listener - The action listener which handles events
      mnemonic - Letter combination
    • createButton

      public static JButton createButton(String text, ActionListener listener, String mnemonic, String actionCommand)
    • createButton

      public static JButton createButton(String text, ActionListener listener)
    • createSmallButton

      public static JButton createSmallButton(String text, ActionListener listener, String mnemonic)
      Creates a Smaller JButton
      Parameters:
      text - to display
      listener - The action listener which handles events
      mnemonic - Letter combination
    • createSmallButton

      public static JButton createSmallButton(String text, ActionListener listener)
    • createBorder

      public static Border createBorder(String text)
      Creates an etched border with the displayed text
    • createBorder

      public static Border createBorder()
      Creates an blank border with the displayed text
    • createListPane

      public static JScrollPane createListPane(JList list, String text)
      Wraps a scrollpane with and etched border and a title around a JList.
      Parameters:
      list - JList to wrap.
      text - Text to display in the border.
    • centerComponent

      public static void centerComponent(Component source, Component parent)
      Centers a component (source) in it's parent component. If parent is null then the window is centered in screen.

      The source and parent components should be correctly sized

    • centerComponent

      public static void centerComponent(Component source)
      Centers the Component on the screen.
    • sizeAndCenterOnDisplay

      public static Dimension sizeAndCenterOnDisplay(Window window, Dimension preferred)
      Sizes a window to at most the usable area of the display it is on, and centers it there.

      For a window whose preferred size can exceed the display it opens on. centerComponent(Component) centers against the whole primary screen and doesn't bound the size at all, so an oversized window ends up with its top and bottom pushed off-screen. Note that this bounds rather than fits: a window taller than the display still has to find the height from somewhere of its own, typically by scrolling.

      Both the size and the location come from the same rectangle. Clamping against the usable area while centering against the whole screen would offset the window by half the difference between them — which is exactly the reserved strip it is meant to stay clear of.

      Returns:
      the size actually applied, which the caller may need if it re-applies the size later
    • usableBounds

      public static Rectangle usableBounds(Window window)
      The usable area of the display the given window is on: that display's bounds, less the strips the OS reserves for a taskbar, Dock or menu bar.

      Deliberately not GraphicsEnvironment.getMaximumWindowBounds(), which answers for the primary display however many are attached — a window on a secondary display would be measured by the dimensions of a display it isn't on, either overflowing a smaller one or being clamped needlessly on a larger one.

    • setupCancelButton

      public static void setupCancelButton(JButton btn)
      Sets up the ESC-key binding for a cancel button
    • getParentFrame

      public static JFrame getParentFrame(Component source)
      Retrieves the parent JFrame for a component. This is handy when you want the frame as an owner for modal dialogs.
      Parameters:
      source - - Source component.
      Returns:
      The JFrame which contains the component or null if not found.
    • msToSec

      public static Integer msToSec(Integer ms)
      Converts miliseconds to seconds
    • secToMs

      public static Integer secToMs(Integer sec)
      Converts seconds to miliseconds
    • stringFromStringArray

      public static String stringFromStringArray(String[] strings, String delim)
      Takes an array of strings and returns a concatenation

      Parameters:
      strings - - Array to concatenate
      delim - - Delimiter to use. If this is null or empty then then a space will be used
    • stringFromStringArray

      public static String stringFromStringArray(String[] strings)
    • stringArrayFromString

      public static String[] stringArrayFromString(String string, String delim)
      Parses the string into an array of strings

      Parameters:
      string - - String to parse
      delim - - Delimiter to use. If this is null or empty then then the set [ ' ', '\t', '\n', '\r' ] is used.
    • stringArrayFromString

      public static String[] stringArrayFromString(String string)
    • setWaitCursor

      public static void setWaitCursor(Component comp)
    • setDefaultCursor

      public static void setDefaultCursor(Component comp)
    • setDropCursor

      public static void setDropCursor(Component comp)
    • adjustPopupLocationToFitScreen

      public static Point adjustPopupLocationToFitScreen(int xposition, int yposition, JComponent component, Component invoker)
      Adjusts a desired popup location to fit within the screen, given the component's preferred size. Implementation copied from JPopupMenu.
    • eventModifiersToString

      public static String eventModifiersToString(int event)