Class GuiUtils


public class GuiUtils extends LayoutUtil
This is a vast catchall class to old various utilities for doing GUI things.
Author:
IDV development team
  • Field Details

    • MISSING_IMAGE

      public static String MISSING_IMAGE
      missing image path
    • ATTR_ACTION

      public static final String ATTR_ACTION
      xml attribute name
      See Also:
    • ATTR_TOOLTIP

      public static final String ATTR_TOOLTIP
      xml attribute name
      See Also:
    • ATTR_ICON

      public static final String ATTR_ICON
      xml attribute name
      See Also:
    • ATTR_ID

      public static final String ATTR_ID
      xml attribute name
      See Also:
    • waitCursor

      public static final Cursor waitCursor
      The cursor to use when waiting
    • normalCursor

      public static final Cursor normalCursor
      The normal cursor_
    • FONT_SIZES

      public static final int[] FONT_SIZES
      font sizes
    • COLORNAMES

      public static final String[] COLORNAMES
      Used to map named colors to color
    • COLORS

      public static final Color[] COLORS
      Used to map named colors to color
    • HEX_COLOR_PATTERN

      public static final String HEX_COLOR_PATTERN
      hex color string without leading #
      See Also:
    • CMD_APPLY

      public static String CMD_APPLY
      Action command used for the Apply button
    • CMD_CANCEL

      public static String CMD_CANCEL
      Action command used for the Cancel button
    • CMD_CLOSE

      public static String CMD_CLOSE
      Action command used for the Close button
    • CMD_IMPORT

      public static String CMD_IMPORT
      Action command used for the Import button
    • CMD_EXPORT

      public static String CMD_EXPORT
      Action command used for the Export button
    • CMD_SUBMIT

      public static String CMD_SUBMIT
      Action command used for the Submit button
    • CMD_RENAME

      public static String CMD_RENAME
      Action command used for the Rename button
    • CMD_REMOVE

      public static String CMD_REMOVE
      Action command used for the Remove button
    • CMD_NEW

      public static String CMD_NEW
      Action command used for the New button
    • CMD_YES

      public static String CMD_YES
      Action command used for the Yes button
    • CMD_NO

      public static String CMD_NO
      Action command used for the No button
    • CMD_OK

      public static String CMD_OK
      Action command used for the OK button
    • CMD_OPEN

      public static String CMD_OPEN
      Action command used for the Open button
    • CMD_RESET

      public static String CMD_RESET
      Action command used for the Reset button
    • CMD_HELP

      public static String CMD_HELP
      Action command used for the Help button
    • CMD_SAVE

      public static String CMD_SAVE
      Action command used for the Save button
    • CMD_SAVEAS

      public static String CMD_SAVEAS
      Action command used for the Saveas button
    • CMD_UPDATE

      public static String CMD_UPDATE
      Action command used for the Update button
    • CMD_START

      public static String CMD_START
      Action command used for the Start button
    • CMD_STOP

      public static String CMD_STOP
      Action command used for the Stop button
    • buttonFont

      public static Font buttonFont
      Used by apps for having a common font for buttons
    • TIMEZONE_UTC

      public static final TimeZone TIMEZONE_UTC
      _more_
  • Method Details

    • initLabels

      public static void initLabels()
      Init the fixed labels
    • setTimeZone

      public static void setTimeZone(TimeZone tz)
      Set the default timezone used for formatting
      Parameters:
      tz - timezone
    • getTimeZone

      public static TimeZone getTimeZone()
      Get the default timezone used for formatting
      Returns:
      timezone
    • setDefaultDateFormat

      public static void setDefaultDateFormat(String fmt)
      Set the default date format
      Parameters:
      fmt - date format string
    • formatDate

      public static String formatDate(Date dttm)
      Format the date with the default date format and timezone
      Parameters:
      dttm - date
      Returns:
      formatted date
    • setDefaultIconSize

      public static void setDefaultIconSize(int size)
      Set the default icon size
      Parameters:
      size - new size
    • getDefaultIconSize

      public static int getDefaultIconSize()
      Get the default icon size
      Returns:
      the default icon size
    • setDefaultFont

      public static void setDefaultFont(Font font)
      Set the default font
      Parameters:
      font - the default font
    • getDefaultFont

      public static Font getDefaultFont()
      Get the default font
      Returns:
      the default font
    • applyDefaultFont

      public static void applyDefaultFont(Component comp)
      _more_
      Parameters:
      comp - _more_
    • getFixedWidthLabel

      public static JLabel getFixedWidthLabel(String s)
      Create a JLabel with a fixed width font
      Parameters:
      s - Initial label string
      Returns:
      label
    • setFixedWidthFont

      public static void setFixedWidthFont(Component comp)
      Set the font on the component to be monospaced
      Parameters:
      comp - The component
    • setCursor

      public static void setCursor(Component component, Cursor cursor)
      This finds the Window the given component c is in and, if it is found, sets the cursor of the Window to the given cursor.
      Parameters:
      component - The component to look for the window from
      cursor - The cursor
    • getFrame

      public static JFrame getFrame(Component component)
      This finds and returns the JFrame, or null if not found, that holds the given component.
      Parameters:
      component - The component to look for the frame
      Returns:
      The JFrame
    • showComponentInTabs

      public static void showComponentInTabs(Component comp)
      Show the component in any contained tabs
      Parameters:
      comp - The component to look for the window from
    • showComponentInTabs

      public static void showComponentInTabs(Component comp, boolean andShowWindow)
      Show the component in any containing tabs
      Parameters:
      comp - Component to show
      andShowWindow - If we get to a window do we also show it
    • toFront

      public static void toFront(Window window)
      Move the window to the front
      Parameters:
      window - the window
    • getWindow

      public static Window getWindow(Component component)
      This finds and returns the Window, or null if not found, that contains the given component.
      Parameters:
      component - The component to look for the window from
      Returns:
      The window the component is on or null if not found
    • empty

      public static void empty(Container c)
      If non-null then removes all children and removes from parent.
      Parameters:
      c - The component to empty
    • empty

      public static void empty(Container c, boolean doItInSwingThread)
      If non-null then removes all children and removes from parent.
      Parameters:
      c - The component to empty
      doItInSwingThread - If true then do the emptying in the Swing thread
    • decodeColor

      public static Color decodeColor(String value, Color dflt)
      This takes the given String and tries to convert it to a color. The string may be a space or comma separated triple of RGB integer values. It may be an integer or it may be a color name defined in the COLORNAMES array
      Parameters:
      value - String value
      dflt - This is returned if the value cannot be converted
      Returns:
      Color defined by the String value or the dflt
    • getColorName

      public static String getColorName(Color color)
      Return the name of the given color.
      Parameters:
      color - The color
      Returns:
      name of the color
    • checkHeight

      public static boolean checkHeight(int height)
      Check the height against a value
      Parameters:
      height - the value to check
      Returns:
      return height > 100;
    • setPreferredWidth

      public static void setPreferredWidth(JComponent comp, int width)
      Set the preferred width on a component
      Parameters:
      comp - component
      width - width
    • makeColorSwatchWidget

      public static JComponent[] makeColorSwatchWidget(Color color, String label)
      This makes a color swatch and a 'Set' button that is used to set the color. It returns a 2 element array holding the swatch and the button.
      Parameters:
      color - The initial color
      label - The label to use when popping up the color dialog
      Returns:
      3 element array that holds the swatch and the set button and the clear button
    • makeColorNameComboBox

      public static JComboBox makeColorNameComboBox(Color dflt)
      A helper to make a color selector combo box
      Parameters:
      dflt - The default color value
      Returns:
      The color selector combo box
    • getImageIcon

      public static ImageIcon getImageIcon(String file)
      Create an ImageIcon from the given image file name. The filename may be a file, a java resource or a url.
      Parameters:
      file - The image file
      Returns:
      The ImageIcon or null if it could not be created
    • getImageIcon

      public static ImageIcon getImageIcon(String file, boolean cache)
      Create an ImageIcon from the given image file name. The filename may be a file, a java resource or a url.
      Parameters:
      file - The image file
      cache - Should the local in memory cache be checked
      Returns:
      The ImageIcon or null if it could not be created
    • getImageIcon

      public static ImageIcon getImageIcon(String file, Class c)
      Create an ImageIcon from the given image file name. The filename may be a file, a java resource or a url.
      Parameters:
      file - The image file
      c - The class to use when looking up the image as a resource
      Returns:
      The ImageIcon or null if it could not be created
    • getImageIcon

      public static ImageIcon getImageIcon(String file, Class c, boolean cache)
      Create an ImageIcon from the given image file name. The filename may be a file, a java resource or a url.
      Parameters:
      file - The image file
      c - The class to use when looking up the image as a resource
      cache - Should the local in memory cache be checked
      Returns:
      The ImageIcon or null if it could not be created
    • getScaledImageIcon

      public static ImageIcon getScaledImageIcon(String file, Class c, boolean cache)
      Get a scaled image icon
      Parameters:
      file - location of the image
      c - relative class
      cache - true to cache result
      Returns:
      the icon or null
    • scaleImageIcon

      public static ImageIcon scaleImageIcon(ImageIcon icon)
      This scales the image icon up to the minimum icon size if it is defined
      Parameters:
      icon - The icon
      Returns:
      The scaled icon
    • getImage

      public static Image getImage(String file)
      Create an Image from the given image file name. The filename may be a file, a java resource or a url.
      Parameters:
      file - The image file
      Returns:
      The Image or null if it could not be created
    • getImage

      public static Image getImage(String file, Class c)
      Create an Image from the given image file name. The filename may be a file, a java resource or a url.
      Parameters:
      file - The image file
      c - Used to lookup the image as a java resource
      Returns:
      The Image or null if it could not be created
    • getImage

      public static Image getImage(String file, Class c, boolean cache)
      Create an Image from the given image file name. The filename may be a file, a java resource or a url.
      Parameters:
      file - The image file
      c - Used to lookup the image as a java resource
      cache - Should the local cache of Images be checked
      Returns:
      The Image or null if it could not be created
    • getImage

      public static Image getImage(String file, Class c, boolean cache, boolean returnNullIfNotFound)
      Get an image
      Parameters:
      file - location of the image
      c - relative class
      cache - true to cache result
      returnNullIfNotFound - true to return null;
      Returns:
      image or null (if returnNullIfNotFound is true);
    • showDialogNearSrc

      public static void showDialogNearSrc(Component src, Component theWindow)
      This will set the location of the theWindow component (might be A JDialog or a JFrame) at the screen location of the given src component. It will then show the theWindow.
      Parameters:
      src - Where we locate
      theWindow - What we locate
    • showWidget

      public static void showWidget(Component c)
      This will show and/or deiconify the given component. The component needs to be a Window or a Frame
      Parameters:
      c - The thing to show.
    • makeJButton

      public static JButton makeJButton(String label, ActionListener listener)
      Utility to make a JButton, adding the given listener as an ActionListener
      Parameters:
      label - The button label
      listener - The ActionListener
      Returns:
      The newly created button
    • makeJButton

      public static JButton makeJButton(String label, Object[] args)
      Utility method for creating and setting various properties of a JButton args array holds a set of key value pairs: -tooltip <The tooltip text> -bg <Background color> -listener <Action listener> -command <Action command>
      Parameters:
      label - The button label
      args - The argname/value array
      Returns:
      The newly created button
    • getSliderPercent

      public static double getSliderPercent(JSlider s)
      Return the slider value as a percentage between its min and max
      Parameters:
      s - The slider
      Returns:
      The percent value
    • setSliderPercent

      public static void setSliderPercent(JSlider s, double percent)
      Set the slider value as a percentage between its min and max
      Parameters:
      s - The slider
      percent - The percent value
    • setBackgroundOnTree

      public static void setBackgroundOnTree(Container c, Color bgColor)
      Recurse the Component hierarchy, setting the background color of each component.
      Parameters:
      c - The component
      bgColor - The color
    • setToolTipOnTree

      public static void setToolTipOnTree(Container c, String tooltip)
      Recurse the Component hierarchy, setting the tooltip of each component.
      Parameters:
      c - The component
      tooltip - The tooltip
    • setFontOnTree

      public static void setFontOnTree(JComponent c, Font f)
      Recurse the Component hierarchy, setting the font.
      Parameters:
      c - The component
      f - The font
    • setForegroundOnTree

      public static void setForegroundOnTree(Component comp, Color fgColor)
      Recurse the Component hierarchy, setting the foreground color of each component.
      Parameters:
      comp - The component
      fgColor - The color
    • setForegroundOnTree

      public static void setForegroundOnTree(Component comp, Color fgColor, Color ifEquals)
      Recurse the Component hierarchy, setting the foreground color of each component.
      Parameters:
      comp - The component
      fgColor - The color
      ifEquals - If non null then only set the foreground color on the component its current color equals the given fgColor
    • enableTree

      public static void enableTree(Component comp, boolean enable)
      Enable or disable a whole tree's worth of components
      Parameters:
      comp - The component
      enable - The enable flag
    • enableComponents

      public static void enableComponents(List comps, boolean enable)
      Enable or disable the list of Components
      Parameters:
      comps - List of components
      enable - Enable or disable
    • enablePanel

      public static void enablePanel(JPanel panel, boolean enable)
      _more_
      Parameters:
      panel - _more_
      enable - _more_
    • makeScrollPane

      public static JScrollPane makeScrollPane(Component c, int xdim, int ydim)
      Make a scroll pane for the input box which may be used to hold selection buttons later; size is given; text for a title in box.
      Parameters:
      c - The component to put in the scroll pane
      xdim - The x dimension
      ydim - The y dimension
      Returns:
      The new scroll pane
    • setSize

      public static JComponent setSize(JComponent comp, int w, int h)
      Set the size and preferred size of the component and return it
      Parameters:
      comp - component
      w - width
      h - height_
      Returns:
      The component
    • buttonGroup

      public static ButtonGroup buttonGroup(JToggleButton b1, JToggleButton b2)
      Create a button group and add the two buttons to it.
      Parameters:
      b1 - Button 1
      b2 - Button 2
      Returns:
      The created button group.
    • buttonGroup

      public static ButtonGroup buttonGroup(JToggleButton b1, JToggleButton b2, JToggleButton b3)
      Create a button group and add the three buttons to it.
      Parameters:
      b1 - Button 1
      b2 - Button 2
      b3 - Button 3
      Returns:
      The created button group.
    • buttonGroup

      public static ButtonGroup buttonGroup(JToggleButton b1, JToggleButton b2, JToggleButton b3, JToggleButton b4)
      Create a button group and add the three buttons to it.
      Parameters:
      b1 - Button 1
      b2 - Button 2
      b3 - Button 3
      b4 - Button 3
      Returns:
      The created button group.
    • valignLabel

      public static JComponent valignLabel(String s)
      This makes a component that contains a jlabel. The jlabel is inset with some padding at the top and the outer component is aligned to the top. It is intended to be used when doing a form layout and the component on the right it a tall one
      Parameters:
      s - The string to create the label with
      Returns:
      the component
    • formLayout

      public static JComponent formLayout(List objects)
      Layout as a 2 column form
      Parameters:
      objects - objects to lay out
      Returns:
      the form
    • formLayout

      public static JComponent formLayout(List objects, Insets insets)
      Do a 2 column layout of the objects with the given insets for spacing
      Parameters:
      objects - May be components or strings. If strings this method will create jlabels
      insets - spacing
      Returns:
      component
    • formLayout

      public static JComponent formLayout(Object[] objects, Insets insets)
      This does a doLayout with 2 columns. If any of the objects are not a Component then it creates a rLabel(object.toString)
      Parameters:
      objects - array of components to layout
      insets - The spacing
      Returns:
      component
    • formLayout

      public static JComponent formLayout(Object[] objects)
      This does a doLayout with 2 columns. If any of the objects are not a Component then it creates a rLabel(object.toString)
      Parameters:
      objects - array of components to layout
      Returns:
      component
    • flowRight

      public static JPanel flowRight(Component[] comps)
      Create a panel and do a a right align flow layout of the components
      Parameters:
      comps - The components to add
      Returns:
      The new panel
    • flow

      public static JPanel flow(Component[] comps)
      Create a panel and do flow layout of the components
      Parameters:
      comps - The components to add
      Returns:
      The new panel
    • makeButtons

      public static JPanel makeButtons(ActionListener l, String[] cmds)
      Make a set of JButtons, each with a label and action command from the given cmds array. Add the buttons into a new JPanel and return it.
      Parameters:
      l - Listener
      cmds - Button labels.action commands
      Returns:
      JPanel that contains the buttons
    • makeButtons

      public static JPanel makeButtons(ActionListener l, String[] cmds, Hashtable buttonMap)
      Make a set of JButtons, each with a label and action command from the given cmds array. Add the buttons into a new JPanel and return it.
      Parameters:
      l - Listener
      cmds - Button labels.action commands
      buttonMap - If non-null will hold a mapping from (String) command to JButton
      Returns:
      JPanel that contains the buttons
    • makeButtons

      public static JPanel makeButtons(ActionListener l, String[] labels, String[] cmds)
      Make a set of JButtons, each with a label and action command from the given cmds and labels arrays. Add the buttons into a new JPanel and return it.
      Parameters:
      l - Listener
      labels - Button labels
      cmds - Button action commands
      Returns:
      JPanel that contains the buttons
    • makeButtons

      public static JPanel makeButtons(ActionListener l, String[] labels, String[] cmds, Hashtable buttonMap)
      Make a set of JButtons, each with a label and action command from the given cmds and labels arrays. Add the buttons into a new JPanel and return it.
      Parameters:
      l - Listener
      labels - Button labels
      cmds - Button action commands
      buttonMap - If non-null will hold a mapping from (String) command to JButton
      Returns:
      JPanel that contains the buttons
    • makeButtons

      public static JPanel makeButtons(ActionListener l, String[] labels, String[] cmds, String[] tooltips, Hashtable buttonMap)
      Make a set of JButtons, each with a label and action command from the given cmds and labels arrays. Add the buttons into a new JPanel and return it.
      Parameters:
      l - Listener
      labels - Button labels. If a label starts with icon: then we make an image button, the image path is the rest of the label
      cmds - Button action commands
      tooltips - If non-null then set te tooltip on the button
      buttonMap - If non-null will hold a mapping from (String) command to JButton
      Returns:
      JPanel that contains the buttons
    • makeApplyCancelButtons

      public static JPanel makeApplyCancelButtons(ActionListener l)
      Utility to make apply/cancel button panel
      Parameters:
      l - The listener to add to the buttons
      Returns:
      The button panel
    • makeApplyButton

      public static JButton makeApplyButton(ActionListener l)
      Utility to make apply button panel
      Parameters:
      l - The listener to add to the buttons
      Returns:
      The button panel
    • makeOkCancelButtons

      public static JPanel makeOkCancelButtons(ActionListener l)
      Utility to make ok/cancel button panel
      Parameters:
      l - The listener to add to the buttons
      Returns:
      The button panel
    • makeNewOkCancelButtons

      public static JPanel makeNewOkCancelButtons(ActionListener l)
      Utility to make new/ok/cancel button panel
      Parameters:
      l - The listener to add to the buttons
      Returns:
      The button panel
    • makeNewOkCancelHelpButtons

      public static JPanel makeNewOkCancelHelpButtons(ActionListener l)
      Utility to make new/ok/cancel/help button panel
      Parameters:
      l - The listener to add to the buttons
      Returns:
      The button panel
    • makeNewOkCancelButtons

      public static JPanel makeNewOkCancelButtons(ActionListener l, String newLabel, String okLabel, String cancelLabel)
      Utility to make new/ok/cancel button panel
      Parameters:
      l - The listener to add to the buttons
      newLabel - Label to use for the new button
      okLabel - Label to use for the ok button
      cancelLabel - Label to use for the cancel button
      Returns:
      Button panel
    • makeOkCancelButtons

      public static JPanel makeOkCancelButtons(ActionListener l, String okLabel, String cancelLabel)
      Utility to make ok/cancel button panel
      Parameters:
      l - The listener to add to the buttons
      okLabel - Label to use for the ok button
      cancelLabel - Label to use for the cancel button
      Returns:
      Button panel
    • makeApplyOkCancelButtons

      public static JPanel makeApplyOkCancelButtons(ActionListener l)
      Utility to make apply/ok/cancel button panel
      Parameters:
      l - The listener to add to the buttons
      Returns:
      Button panel
    • makeOkHelpCancelButtons

      public static JPanel makeOkHelpCancelButtons(ActionListener l)
      Utility to make ok/help/cancel button panel
      Parameters:
      l - The listener to add to the buttons
      Returns:
      Button panel
    • makeApplyOkHelpCancelButtons

      public static JPanel makeApplyOkHelpCancelButtons(ActionListener l)
      Utility to make apply/ok/help/cancel button panel
      Parameters:
      l - The listener to add to the buttons
      Returns:
      Button panel
    • makeApplyOkResetCancelButtons

      public static JPanel makeApplyOkResetCancelButtons(ActionListener l)
      Utility to make apply/ok/reset/cancel button panel
      Parameters:
      l - The listener to add to the buttons
      Returns:
      Button panel
    • showYesNoDialog

      public static boolean showYesNoDialog(Window frame, String message, String title)
      Show a modeful dialog, attached to the given frame, with the given message. Ask the user Yes or No.
      Parameters:
      frame - Frame to attach to.
      message - Message to show
      title - Window title
      Returns:
      True if user selects Yes, false if No
    • showYesNoDialog

      public static boolean showYesNoDialog(Window frame, String message, String title, String yes, String no)
      Show a modeful dialog, attached to the given frame, with the given message. Ask the user Yes or No.
      Parameters:
      frame - Frame to attach to.
      message - Message to show
      title - Window title
      yes - The Yes text
      no - The No text
      Returns:
      True if user selects Yes, false if No
    • insertText

      public static void insertText(JTextComponent comp, String s)
      Insert text into the component
      Parameters:
      comp - component
      s - text to insert
    • showYesNoCancelDialog

      public static int showYesNoCancelDialog(Window frame, String message, String title)
      Show a modeful dialog, attached to the given frame, with the given message. Ask the user Yes or No or Cancel
      Parameters:
      frame - Frame to attach to.
      message - Message to show
      title - Window title
      Returns:
      0 if Yes, 1 if No, 2 if Cancel
    • showYesNoCancelDialog

      public static int showYesNoCancelDialog(Window frame, String message, String title, String defaultCmd)
      Show a modeful dialog, attached to the given frame, with the given message. Ask the user Yes or No or Cancel
      Parameters:
      frame - Frame to attach to.
      message - Message to show
      title - Window title
      defaultCmd - default for the dialog (CMD_YES, CMD_NO, CMD_CANCEL)
      Returns:
      0 if Yes, 1 if No, 2 if Cancel
    • showYesNoDialog

      public static boolean showYesNoDialog(Window frame, String title, Component contents, Component src)
      Show a modeful dialog, attached to the given frame, with the given message. Ask the user Yes or No.
      Parameters:
      frame - Frame to attach to.
      title - Window title
      contents - GUI contents
      src - Where to show window
      Returns:
      True if user selects Yes, false if No
    • showOkCancelDialog

      public static boolean showOkCancelDialog(Window f, String title, Component contents, Component src)
      Show a modeful Ok/Cancel dialog.
      Parameters:
      f - The frame to attach to
      title - The window title
      contents - The gui contents to show
      src - Where should the window popup
      Returns:
      True if Ok was pressed, false otherwise
    • showOkCancelDialog

      public static boolean showOkCancelDialog(Window f, String title, Component contents, Component src, List actionComponents)
      Show a modeful Ok/Cancel dialog.
      Parameters:
      f - The frame to attach to
      title - The window title
      contents - The gui contents to show
      src - Where should the window popup
      actionComponents - If non-null then these are components in the contents (e.g., JTextField) that an action listener is added to to do the Ok on an action event
      Returns:
      True if Ok was pressed, false otherwise
    • createFrame

      public static JFrame createFrame(String title)
      A utility to create a frame. This also registers the frame with the LogUtil facility that tracks the recently active windows.
      Parameters:
      title - Frame title
      Returns:
      The frame
    • createDialog

      public static JDialog createDialog(String title, boolean modal)
      A utility to create a dialog. If modal then this method uses the LogUtil.getCurrentWindow as the parent window of the dialog.
      Parameters:
      title - Dialog title
      modal - Is modal
      Returns:
      THe dialog
    • popup

      public static Component[] popup(String text, int x, int y, boolean modal)
      Popup an html widget at the given x/y that shows the text (or, if the text is a URI will read the URI).
      Parameters:
      text - text or uri
      x - x
      y - y
      modal - modal
      Returns:
      2 element array holding the html component and the dialog
    • createDialog

      public static JDialog createDialog(Window parent, String title, boolean modal)
      Utility to create a JDialog with a parent component. If not modal this method also registers the JDialog with the LogUtil last active window facility.
      Parameters:
      parent - The parent window. May be null, a Dialog or a Frame
      title - Dialog title
      modal - Is modal
      Returns:
      The dialog
    • showOkCancelDialog

      public static boolean showOkCancelDialog(Window f, String title, Component contents, Component src, List actionComponents, String okLabel)
      Show a modeful Ok/Cancel dialog.
      Parameters:
      f - The frame to attach to
      title - The window title
      contents - The gui contents to show
      src - Where should the window popup
      actionComponents - If non-null then these are components in the contents (e.g., JTextField) that an action listener is added to to do the Ok on an action event
      okLabel - text for the OK button
      Returns:
      True if Ok was pressed, false otherwise
    • showOkCancelDialog

      public static boolean showOkCancelDialog(Window f, String title, Component contents, Component src, List actionComponents, String okLabel, boolean resizable, Dimension dialogPrefSize)
      Show a modal Ok/Cancel dialog.
      Parameters:
      f - The frame to attach to
      title - The window title
      contents - The gui contents to show
      src - Where should the window popup
      actionComponents - If non-null then these are components in the contents (e.g., JTextField) that an action listener is added to to do the Ok on an action event
      okLabel - text for the OK button
      resizable - Whether or not the dialog can be resized.
      dialogPrefSize - If not null, use as preferred size of resulting dialog.
      Returns:
      True if Ok was pressed, false otherwise
    • showOkDialog

      public static void showOkDialog(Window f, String title, Component contents, Component src)
      Show OK dialog
      Parameters:
      f - relative window
      title - title for the dialog
      contents - dialog contents
      src - src component
    • makeDialog

      public static int makeDialog(Window f, String title, Component contents, Component src, String[] buttonLabels)
      Make and show a modeful dialog with the given collection of buttons. Return the index of the button that was pushed
      Parameters:
      f - Frame to attach to
      title - Window title
      contents - GUI contents
      src - Where to show window
      buttonLabels - Buttons
      Returns:
      Which button was pushed
    • configureStepSelection

      public static void configureStepSelection(JList list)
      Add a listener to the JList that pops up a menu on a right click that allos for the selection of different strides.
      Parameters:
      list - list to popup on
    • showIntervalSelectionDialog

      public static void showIntervalSelectionDialog(JList list)
      Show the list interval selection dialog
      Parameters:
      list - list
    • getConfigureStepSelectionItems

      public static void getConfigureStepSelectionItems(JList list, List items)
      popup a menu to select strides
      Parameters:
      list - JList
      items - menu items
    • formLayout

      public static JComponent formLayout(List comps, boolean rightAlignFirstColumn)
      Do a 2 column layout. Right align the first column. Make the width of the first column non-stretcy, second column stretchy.
      Parameters:
      comps - Components to layout
      rightAlignFirstColumn - If true then right align the first column
      Returns:
      Panel containing form
    • formLayout

      public static JComponent formLayout(Component[] comps)
      Do a 2 column layout. Right align the first column. Make the width of the first column non-stretcy, second column stretchy.
      Parameters:
      comps - Components to layout
      Returns:
      Panel containing form
    • formLayout

      public static JComponent formLayout(Component[] comps, double[] widths, double[] heights)
      Do a 2 column layout. Right align the first column. Use the given stretchy flags.
      Parameters:
      comps - Components to layout
      widths - WT_
      heights - WT_
      Returns:
      Panel containing form
    • formLayout

      public static JComponent formLayout(List comps, double[] widths, double[] heights)
      Do a 2 column layout. Right align the first column. Use the given stretchy flags.
      Parameters:
      comps - Components to layout
      widths - WT_
      heights - WT_
      Returns:
      Panel containing form
    • formLayout

      public static JComponent formLayout(List comps, double[] widths, double[] heights, boolean rightAlignFirstColumn)
      Do a 2 column layout. Use the given stretchy flags.
      Parameters:
      comps - Components to layout
      widths - WT_
      heights - WT_
      rightAlignFirstColumn - If true then right align the first column.
      Returns:
      Panel containing form
    • label

      public static JPanel label(String label, Component widget)
      Create a JPanel that holds a JLabel/the given widget
      Parameters:
      label - The label text to use
      widget - The widget to label
      Returns:
      The panel
    • label

      public static JPanel label(Component widget, String label)
      Create a JPanel that holds a the given widget/JLabel
      Parameters:
      widget - The widget to label
      label - The label text to use
      Returns:
      The panel
    • packWindow

      public static JFrame packWindow(JFrame f, Component contents)
      Add the given contents into the given frame
      Parameters:
      f - The frame
      contents - The contents
      Returns:
      The given frame
    • packWindow

      public static JFrame packWindow(JFrame f, Component contents, boolean andShow)
      Add the given contents into the given frame
      Parameters:
      f - The frame
      contents - The contents
      andShow - If true then show the window.
      Returns:
      The given frame
    • packDialog

      public static JDialog packDialog(JDialog f, Component contents)
      Add the given contents into the given dialog
      Parameters:
      f - The dialog
      contents - The contents
      Returns:
      The dialog
    • makeWindow

      public static JFrame makeWindow(String title, Component contents, int x, int y)
      Create a new JFrame, add the contents to it, set its location and return it.
      Parameters:
      title - The window title
      contents - The contents
      x - x location
      y - y location
      Returns:
      The new JFrame
    • makeMenuBar

      public static JMenuBar makeMenuBar(List menus)
      Create a JMenuBar and add the menus contained with the menus list If no menus then return null.
      Parameters:
      menus - List if JMenu-s
      Returns:
      The JMenuBar
    • getCloseDialogListener

      public static ObjectListener getCloseDialogListener(JDialog dialog)
      Create a listener that will close the given dialog.
      Parameters:
      dialog - The dialog to close
      Returns:
      The listener that closes the dialog on an action event
    • getImageLabel

      public static JLabel getImageLabel(String icon, Class origin)
      Create a JLabel that displays an image icon create from the given icon path (may be a file, resource or url).
      Parameters:
      icon - The image file
      origin - Used to lookup java resources
      Returns:
      New JLabel showing image
    • getImageLabel

      public static JLabel getImageLabel(String icon)
      Create a JLabel that displays an image icon create from the given icon path (may be a file, resource or url).
      Parameters:
      icon - The image file
      Returns:
      New JLabel showing image
    • getImageButton

      public static JButton getImageButton(String icon, Class origin)
      Create a JButton that displays an image icon create from the given icon path (may be a file, resource or url).
      Parameters:
      icon - The image file
      origin - Used to lookup java resources
      Returns:
      New JButton showing image
    • getImageButton

      public static JButton getImageButton(String icon, Class origin, int hInset, int vInset)
      Create a JButton that displays an image icon create from the given icon path (may be a file, resource or url).
      Parameters:
      icon - The image file
      origin - Used to lookup java resources
      hInset - Horizontal inset
      vInset - Vertical inset
      Returns:
      New JButton showing image
    • getScaledImageButton

      public static JButton getScaledImageButton(String icon, Class origin, int hInset, int vInset)
      Get a scaled image button
      Parameters:
      icon - path to icon for the button
      origin - relative class
      hInset - horizontal inset
      vInset - vertical inset
      Returns:
      the button
    • getImageButton

      public static JButton getImageButton(ImageIcon icon)
      Create a JButton that displays the given image icon
      Parameters:
      icon - The image icon
      Returns:
      New JButton showing image
    • getImageButton

      public static JButton getImageButton(ImageIcon icon, int offset)
      Create a JButton that displays the given image icon
      Parameters:
      icon - The image icon
      offset - The spacing around the image in the JButton
      Returns:
      New JButton showing image
    • getImageButton

      public static JButton getImageButton(ImageIcon icon, int hinset, int vinset)
      Create a JButton that displays the given image icon
      Parameters:
      icon - The image icon
      hinset - The hor. spacing around the image in the JButton
      vinset - The vert. spacing around the image in the JButton
      Returns:
      New JButton showing image
    • getToggleImageButton

      public static JToggleButton getToggleImageButton(String icon, String selectedIcon, int hinset, int vinset, boolean addMouseOverBorder)
      Create a JToggleButton with the given image and, if non-null, the given selected image.
      Parameters:
      icon - Image for button
      selectedIcon - Image to use when selected
      hinset - Hor. inset
      vinset - Vert. inset
      addMouseOverBorder - add a mouseover border
      Returns:
      New button
    • getToggleImageButton

      public static JToggleButton getToggleImageButton(ImageIcon icon, ImageIcon selectedIcon, int hinset, int vinset)
      Create a JToggleButton with the given image and, if non-null, the given selected image.
      Parameters:
      icon - Image for button
      selectedIcon - Image to use when selected
      hinset - Hor. inset
      vinset - Vert. inset
      Returns:
      New button
    • getToggleImageButton

      public static JToggleButton getToggleImageButton(ImageIcon icon, ImageIcon selectedIcon, int hinset, int vinset, boolean addMouseOverBorder)
      Create a JToggleButton with the given image and, if non-null, the given selected image.
      Parameters:
      icon - Image for button
      selectedIcon - Image to use when selected
      hinset - Hor. inset
      vinset - Vert. inset
      addMouseOverBorder - add a mouseover border
      Returns:
      New button
    • makeMouseOverBorder

      public static void makeMouseOverBorder(JComponent b)
      Make a mouse over border
      Parameters:
      b - the component
    • getToggleButton

      public static JToggleButton getToggleButton(String iconPath, int hinset, int vinset)
      Create a toggle button with the given image.
      Parameters:
      iconPath - path to image
      hinset - hor. inset
      vinset - vert inset
      Returns:
      button
    • getToggleButton

      public static JToggleButton getToggleButton(ImageIcon icon, int hinset, int vinset)
      Create a toggle button with the given image.
      Parameters:
      icon - The icon to use
      hinset - hor.inset
      vinset - vert. inset
      Returns:
      The new button
    • getLocation

      public static Point getLocation(Component src)
      Find the location of the given componet on the screen. If any errors then return the screen center - 100
      Parameters:
      src - Source component
      Returns:
      Location on screen
    • showInCenter

      public static void showInCenter(JDialog dialog)
      pack and show the dialog in the center of the screen
      Parameters:
      dialog - The dialog
    • packInCenter

      public static void packInCenter(JDialog dialog)
      pack the dialog in the center of the screen
      Parameters:
      dialog - The dialog
    • vsplit

      public static JSplitPane vsplit(Component top, Component bottom, int topSpace, double resizeWeight)
      Create a JSplitPane in vertical mode.
      Parameters:
      top - Top component
      bottom - Bottom component
      topSpace - How much space to give the top
      resizeWeight - How much weight to give the top when resizing
      Returns:
      The split pane
    • vsplit

      public static JSplitPane vsplit(Component top, Component bottom, int topSpace)
      Create a JSplitPane in vertical mode.
      Parameters:
      top - Top component
      bottom - Bottom component
      topSpace - How much space to give the top
      Returns:
      The split pane
    • vsplit

      public static JSplitPane vsplit(Component top, Component bottom, double resizeWeight)
      Create a JSplitPane in vertical mode.
      Parameters:
      top - Top component
      bottom - Bottom component
      resizeWeight - How much weight to give the top when resizing
      Returns:
      The split pane
    • vsplit

      public static JSplitPane vsplit(Component top, Component bottom)
      Create a JSplitPane in vertical mode.
      Parameters:
      top - Top component
      bottom - Bottom component
      Returns:
      The split pane
    • hsplit

      public static JSplitPane hsplit(Component left, Component right, int leftSpace, double resizeWeight)
      Create a horizontally aligned JSplitPane. Give the left component the specified space.
      Parameters:
      left - The left component
      right - The right component
      leftSpace - Where to put the divider
      resizeWeight - The resize weight
      Returns:
      The split pane
    • hsplit

      public static JSplitPane hsplit(Component left, Component right, int leftSpace)
      Create a horizontally aligned JSplitPane
      Parameters:
      left - The left component
      right - The right component
      leftSpace - Where to put the divider
      Returns:
      The split pane
    • hsplit

      public static JSplitPane hsplit(Component left, Component right, double resizeWeight)
      Create a horizontally aligned JSplitPane
      Parameters:
      left - The left component
      right - The right component
      resizeWeight - How much resize weight to use
      Returns:
      The split pane
    • hsplit

      public static JSplitPane hsplit(Component left, Component right)
      Create a basic horizontally aligned JSplitPane
      Parameters:
      left - The left component
      right - The right component
      Returns:
      The split pane
    • rLabel

      public static JLabel rLabel(String s)
      Create a right aligned JLabel
      Parameters:
      s - The String to use for the label
      Returns:
      The label
    • cLabel

      public static JLabel cLabel(String s)
      Create a center aligned JLabel
      Parameters:
      s - The String to use for the label
      Returns:
      The label
    • lLabel

      public static JLabel lLabel(String s)
      Create a left aligned JLabel
      Parameters:
      s - The String to use for the label
      Returns:
      The label
    • hspace

      public static JComponent hspace(int w, int h)
      Create a a minimally sized spacer
      Parameters:
      w - The min width
      h - The min height
      Returns:
      The spacer
    • getInput

      public static String getInput(String question, String label, String initValue)
      Ask the user the question. Return their response or null.
      Parameters:
      question - The question.
      label - Extra label.
      initValue - Initial value of answer
      Returns:
      The user's response
    • getInput

      public static String getInput(String question, String label, String initValue, String trailingLabel)
      Ask the user the question. Return their response or null.
      Parameters:
      question - The question.
      label - Extra label.
      initValue - Initial value of answer
      trailingLabel - Label after the text field.
      Returns:
      The user's response
    • getInput

      public static String getInput(String question, String label, String initValue, String trailingLabel, Object underLabel)
      Ask the user the question. Return their response or null.
      Parameters:
      question - The question.
      label - Extra label.
      initValue - Initial value of answer
      trailingLabel - Label after the text field.
      underLabel - Label under the text field.
      Returns:
      The user's response
    • getInput

      public static String getInput(String question, String label, String initValue, String trailingLabel, Object underLabel, String title)
      Ask the user the question. Return their response or null.
      Parameters:
      question - The question.
      label - Extra label.
      initValue - Initial value of answer
      trailingLabel - Label after the text field.
      underLabel - Label under the text field.
      title - for the dialog box.
      Returns:
      The user's response
    • getInput

      public static String getInput(String question, String label, String initValue, String trailingLabel, Object underLabel, String title, int fieldWidth)
      Ask the user the question. Return their response or null.
      Parameters:
      question - The question.
      label - Extra label.
      initValue - Initial value of answer
      trailingLabel - Label after the text field.
      underLabel - Label under the text field.
      title - for the dialog box.
      fieldWidth - Field width
      Returns:
      The user's response
    • getInput

      public static String getInput(String question, String label, String initValue, String trailingLabel, Object underLabel, String title, int fieldWidth, JComponent nearComponent)
      Ask the user the question. Return their response or null.
      Parameters:
      question - The question.
      label - Extra label.
      initValue - Initial value of answer
      trailingLabel - Label after the text field.
      underLabel - Label under the text field.
      title - for the dialog box.
      fieldWidth - Field width
      nearComponent - If non-null then show the dialog near this component
      Returns:
      The user's response
    • getInput

      public static String getInput(String question)
      Ask the user the question. Return the answer.
      Parameters:
      question - The question
      Returns:
      The answer
    • askYesNo

      public static boolean askYesNo(String title, Object question)
      Ask the user the question. Return yes or no.
      Parameters:
      title - The window title.
      question - The question.
      Returns:
      True if they say yes
    • askOkCancel

      public static boolean askOkCancel(String title, Object question)
      Ask the user the question. Return ok or cancel.
      Parameters:
      title - The window title.
      question - The question.
      Returns:
      True if they say ok, false otherwise
    • showDialog

      public static void showDialog(String title, Component comp)
      Show the given component in a dialog.
      Parameters:
      title - The title
      comp - The component to show
    • addModalDialogComponent

      public static void addModalDialogComponent(Component comp)
      Add the model dialog to the list
      Parameters:
      comp - The component in the model dialog
    • removeModalDialogComponent

      public static void removeModalDialogComponent(Component comp)
      Remove the model dialog from the list
      Parameters:
      comp - The component in the model dialog
    • showDialog

      public static void showDialog(String title, Component comp, Component parentComponent)
      Show the given component in a dialog.
      Parameters:
      title - The title
      comp - The component to show
      parentComponent - The parent component of the dialog.
    • toFrontModalDialogs

      public static void toFrontModalDialogs()
      Move to the front any modal dialogs
    • setListData

      public static void setListData(JComboBox box, Object[] items)
      Procedure to set the list of items in a ComboBox
      Parameters:
      box - Combobox to fill
      items - Items to add
    • anySelected

      public static boolean anySelected(JComboBox box)
      Check if there are any selected items in the combobox. We have this as a method because if the box as no items a getSelectedItem causes an error.
      Parameters:
      box - The box to check
      Returns:
      Any selected items.
    • setListData

      public static void setListData(JComboBox box, List items)
      Procedure to set the list of items in a ComboBox
      Parameters:
      box - Combobox to fill
      items - Items to add
    • getEditableBox

      public static JComboBox getEditableBox(List items, Object selected)
      Create an editable combobox with the given items. Preselect the selected item if non-null.
      Parameters:
      items - Items in the box
      selected - Selected item
      Returns:
      New JComboBox
    • getBoxValue

      public static int getBoxValue(JComboBox box)
      Return the selected item in the given box as an integer. Do a new Double(selected.toString()):
      Parameters:
      box - The box
      Returns:
      The int value of the selected item.
    • createValueBox

      public static JComboBox createValueBox(ActionListener listener, String command, int initValue, List values, boolean editable)
      Create a combobx boxc that holds a set of integer values.
      Parameters:
      listener - The action listener
      command - Action command for box
      initValue - Initial value
      values - List of Integers
      editable - Is box editable
      Returns:
      The combobox
    • processXmlMenuItem

      public static JMenuItem processXmlMenuItem(Node node, ActionListener listener, Hashtable menuItems) throws Exception
      Create the JMenuItem defined by the given xml
      Parameters:
      node - Xml menu item node
      listener - Action listener to add to the menu item
      menuItems - Mapping from id (from xml) to JMenuItem
      Returns:
      The menu item
      Throws:
      Exception
    • processXmlMenuItem

      public static JMenuItem processXmlMenuItem(Node node, ActionListener listener, Hashtable menuItems, Hashtable<String,ImageIcon> actionIcons) throws Exception
      Create the JMenuItem defined by the given xml
      Parameters:
      node - Xml menu item node
      listener - Action listener to add to the menu item
      menuItems - Mapping from id (from xml) to JMenuItem
      actionIcons - mapping of string action to imageicon to use in the menu item
      Returns:
      The menu item
      Throws:
      Exception
    • charToKeyCode

      public static int charToKeyCode(String s)
      Take the first character of the string and return the numeric key code
      Parameters:
      s - The string
      Returns:
      The key code of the first char of the string
    • charToKeyCode

      public static int charToKeyCode(char ch)
      Return the numeric key code of the given character.
      Parameters:
      ch - The character
      Returns:
      Its key code
    • processXmlMenu

      public static JMenu processXmlMenu(Node menuNode, ActionListener listener, Hashtable menuItems) throws Exception
      Create the JMenu from the given xml.
      Parameters:
      menuNode - The menu xml node
      listener - The action listener
      menuItems - Mapping from id to menu items
      Returns:
      New JMenu
      Throws:
      Exception
    • processXmlMenu

      public static JMenu processXmlMenu(Node menuNode, ActionListener listener, Hashtable menuItems, Hashtable<String,ImageIcon> actionIcons) throws Exception
      Create the JMenu from the given xml.
      Parameters:
      menuNode - The menu xml node
      listener - The action listener
      menuItems - Mapping from id to menu items
      actionIcons - mapping of string action to imageicon to use in the menu item
      Returns:
      New JMenu
      Throws:
      Exception
    • processXmlMenuBar

      public static JMenuBar processXmlMenuBar(Element root, JMenuBar menuBar, ActionListener listener, Hashtable menuItems)
      Create, if null, and ddd to the JMenuBar from the xml
      Parameters:
      root - Xml root
      menuBar - The menu bar
      listener - The action listener
      menuItems - Mapping from id to menu items
      Returns:
      The JMenuBar
    • processXmlMenuBar

      public static JMenuBar processXmlMenuBar(Element root, JMenuBar menuBar, ActionListener listener, Hashtable menuItems, Hashtable<String,ImageIcon> actionIcons)
      Create, if null, and ddd to the JMenuBar from the xml
      Parameters:
      root - Xml root
      menuBar - The menu bar
      listener - The action listener
      menuItems - Mapping from id to menu items
      actionIcons - mapping of string action to imageicon to use in the menu item
      Returns:
      The JMenuBar
    • getItems

      public static List getItems(JComboBox box)
      return the list of items held by the combo box.
      Parameters:
      box - The box
      Returns:
      List of items
    • isShowing

      public static boolean isShowing(JFrame f)
      Is the frame showing
      Parameters:
      f - The frame
      Returns:
      Is it showing
    • isShowing

      public static boolean isShowing(JDialog f)
      Is the dialog showing
      Parameters:
      f - The dialog
      Returns:
      Is it showing
    • getImage

      public static Image getImage(Component component) throws Exception
      Get the screen image from the component
      Parameters:
      component - The component.
      Returns:
      Its image
      Throws:
      Exception
    • showHtmlDialog

      public static Component[] showHtmlDialog(String html, HyperlinkListener linkListener)
      Show the given html in a window. If linkListener is non-null then add itinto the html viewer to listen for hyper link clicks.
      Parameters:
      html - The html
      linkListener - The listener
      Returns:
      A 2-tuple. First element is the JDialog. Second is the JEditorPane
    • showHtmlDialog

      public static Component[] showHtmlDialog(String html, String title, HyperlinkListener linkListener)
      Show the given html in a window with the given title. If linkListener is non-null then add itinto the html viewer to listen for hyper link clicks.
      Parameters:
      html - The html
      title - The title of the window
      linkListener - The listener
      Returns:
      A 2-tuple. First element is the JFrame. Second is the JEditorPane
    • getHtmlComponent

      public static Component[] getHtmlComponent(String html, HyperlinkListener linkListener, int width, int height)
      Make a JTextEditor component and scroller for the given html
      Parameters:
      html - html
      linkListener - Listener
      width - height
      height - width
      Returns:
      2 component array. First is the editor. Second is the scroller its in
    • showHtmlDialog

      public static Component[] showHtmlDialog(String html, String title, String label, HyperlinkListener linkListener, boolean modal)
      Show a dialog window that contains an html editor
      Parameters:
      html - html
      title - window title
      label - label
      linkListener - Listener
      modal - is window modal
      Returns:
      2 component array. First is the editor. Second is the scroller its in
    • initializeExpandedPathsBeforeChange

      public static Hashtable initializeExpandedPathsBeforeChange(JTree tree, DefaultMutableTreeNode root)
      Call this before a JTree changes. It stores into the returned hashtable state that it uses later to re-expand the paths of the jtree after its structure changes.
      Parameters:
      tree - The jtree
      root - Its tree root
      Returns:
      Holds the state for later expansion
    • expandPathsAfterChange

      public static void expandPathsAfterChange(JTree tree, Hashtable state, DefaultMutableTreeNode root)
      Call this after the structure of a JTree changes to re-expand the paths.
      Parameters:
      tree - The tree
      state - The state. From initializeExpandedPathsBeforeChange
      root - The tree root
    • doTreeSearch

      public static GuiUtils.TreeSearchResults doTreeSearch(JTree tree, Object lastState, String nodeDesc, JComponent near)
      Popup a dialog and search the given tree for a tree node that matches the user provided string.
      Parameters:
      tree - Tree to search
      lastState - For successive searches, this keeps state around
      nodeDesc - A descriptive term for the node for when we tell something to the user
      near - If non-null then show the input dialog near this component
      Returns:
      Some state for successive searches
    • limitMenuSize

      public static void limitMenuSize(List items, String name, int size)
      This takes the list of JMenuItems and, for each JMenu, will ensure that there are no more than size number of items in any sub menu. It uses name (e.g., Group) to make the sub-menus, e.g., Group 1, Group 2, ...
      Parameters:
      items - List of JMenuItems
      name - The name suffix to use
      size - Max size of a menu
    • limitMenuSize

      public static void limitMenuSize(JMenu menu, String name, int size)
      This ensures that there are no more than size number of items in any sub menu. It uses name (e.g., Group) to make the sub-menus, e.g., Group 1, Group 2, ...
      Parameters:
      menu - The menu
      name - The name suffix to use
      size - Max size of a menu
    • limitMenuSize

      public static void limitMenuSize(JMenu menu, String name, int size, boolean recurse)
      This ensures that there are no more than size number of items in any sub menu. It uses name (e.g., Group) to make the sub-menus, e.g., Group 1, Group 2, ...
      Parameters:
      menu - The menu
      name - The name suffix to use
      size - Max size of a menu
      recurse - If true then limit the size of all sub menus
    • doTreeSearch

      public static GuiUtils.TreeSearchResults doTreeSearch(JTree tree, Object lastState, String nodeDesc, JComponent near, String originalPhrase)
      Search the given tree
      Parameters:
      tree - the tree
      lastState - last state
      nodeDesc - the node description
      near - the near component
      originalPhrase - the search phrase
      Returns:
      the results
    • toCsv

      public static String toCsv(TableModel model)
      Convert the given table model to comma separated string
      Parameters:
      model - The table model to write
      Returns:
      CSV representation of the given table model
    • toCsv

      public static String toCsv(TableModel model, boolean includeColumnNames)
      Convert the given table model to comma separated string
      Parameters:
      model - The table model to write
      includeColumnNames - true to include the column names
      Returns:
      CSV representation of the given table model
    • exportAsCsv

      public static void exportAsCsv(TableModel model)
      Write out the given table model as a csv file
      Parameters:
      model - The table model to write
    • exportAsCsv

      public static void exportAsCsv(String header, TableModel model)
      Write out the given table model as a comma separated value (CSV) file prepending the header.
      Parameters:
      header - a header to prepend to the table
      model - The table model to write
    • exportAsCsv

      public static void exportAsCsv(String header, TableModel model, boolean includeColumnNames)
      Write out the given table model as a comma separated value (CSV) file prepending the header.
      Parameters:
      header - a header to prepend to the table
      model - The table model to write
      includeColumnNames - true to include the column names
    • exportAsCsv

      public static void exportAsCsv(String header, TableModel model, String filename)
      Export a table as csv
      Parameters:
      header - header for the output
      model - table model
      filename - file name to export to
    • exportAsCsv

      public static void exportAsCsv(String header, TableModel model, String filename, boolean includeColumnNames)
      Export a table as csv
      Parameters:
      header - header for the output
      model - table model
      filename - file name to export to
      includeColumnNames - true to include the column names
    • setupDirectoryChooser

      public static void setupDirectoryChooser(JButton btn, JTextField directoryFld)
      Set up a directory chooser
      Parameters:
      btn - button for choosing directory
      directoryFld - directory field
    • setupFileChooser

      public static void setupFileChooser(JButton btn, JTextField directoryFld, boolean justDirectories)
      Set up a directory chooser
      Parameters:
      btn - button for choosing directory
      directoryFld - directory field
      justDirectories - flag for just looking at directories
    • makeCheckbox

      public static JCheckBox makeCheckbox(String label, Object object, String property)
      Make a checkbox. Automatically call the set'property' method on the object
      Parameters:
      label - Label
      object - Object to call
      property - Name of property to get/set value
      Returns:
      The checkbox
    • makeCheckbox

      public static JCheckBox makeCheckbox(String label, Object object, String property, Object arg)
      Make a checkbox. Automatically call the set'property' method on the object
      Parameters:
      label - Label
      object - Object to call
      property - Name of property to get/set value
      arg - Optional arg to pass to method
      Returns:
      The checkbox
    • makeRadioButtons

      public static JRadioButton[] makeRadioButtons(List labels, int selectedIndex, Object object, String methodName)
      Make a set of radio buttons
      Parameters:
      labels - labels
      selectedIndex - which one is on
      object - Object to call
      methodName - The method
      Returns:
      The radio buttons
    • makeButton

      public static JButton makeButton(String label, Object object, String methodName)
      Make a JButton. Call methodName on object when button pressed.
      Parameters:
      label - Label
      object - Object to call
      methodName - Method name to call
      Returns:
      The button
    • makeButton

      public static JButton makeButton(String label, Object object, String methodName, Object arg)
      Make a JButton. Call methodName on object when button pressed. Pass in given arg if non-null.
      Parameters:
      label - Label
      object - Object to call
      methodName - Method name to call
      arg - Pass this to method name if non-null.
      Returns:
      The button
    • makeButton

      public static JButton makeButton(String label, Object object, String methodName, Object arg, String tooltip)
      Make a JButton. Call methodName on object when button pressed. Pass in given arg if non-null.
      Parameters:
      label - Label
      object - Object to call
      methodName - Method name to call
      arg - Pass this to method name if non-null.
      tooltip - if non-null then set the tooltip on the button
      Returns:
      The button
    • makeActionListener

      public static ActionListener makeActionListener(Object object, String methodName, Object arg)
      Make an ActionListener. Call methodName on object when button pressed. Pass in given arg if non-null.
      Parameters:
      object - Object to call
      methodName - Method name to call
      arg - Pass this to method name if non-null.
      Returns:
      The action listener
    • invokeInSwingThread

      public static void invokeInSwingThread(Runnable runnable)
      RUn the given runnable in the swing event dispatch thread
      Parameters:
      runnable - runnable to run
    • makeImageButton

      public static JButton makeImageButton(String label, Object object, String methodName)
      Make a JButton. Call methodName on object when button pressed.
      Parameters:
      label - Label
      object - Object to call
      methodName - Method name to call
      Returns:
      The button
    • makeImageButton

      public static JButton makeImageButton(String label, Object object, String methodName, Object arg)
      Make a JButton. Call methodName on object when button pressed. Pass in given arg if non-null.
      Parameters:
      label - Label
      object - Object to call
      methodName - Method name to call
      arg - Pass this to method name if non-null.
      Returns:
      The button
    • makeImageButton

      public static JButton makeImageButton(String label, Object object, String methodName, Object arg, boolean addMouseOverBorder)
      Make a JButton. Call methodName on object when button pressed. Pass in given arg if non-null.
      Parameters:
      label - Label
      object - Object to call
      methodName - Method name to call
      arg - Pass this to method name if non-null.
      addMouseOverBorder - add a mouse-over border
      Returns:
      The button
    • addActionListener

      public static JComponent addActionListener(JComponent comp, Object object, String methodName, Object arg)
      Adds an action listener to the button. Call methodName on object when button pressed. Pass in given arg if non-null.
      Parameters:
      comp - The component
      object - Object to call
      methodName - Method name to call
      arg - Pass this to method name if non-null.
      Returns:
      The button
    • makeDynamicMenu

      public static JMenu makeDynamicMenu(String name, Object object, String methodName)
      Create a menu and add a listener to it that removes all items and calls the given method on te given object with the menu as an argument.
      Parameters:
      name - Menu name
      object - Object to call
      methodName - method to invoke
      Returns:
      The menu
    • makeDynamicMenu

      public static JMenu makeDynamicMenu(String name, Object object, String methodName, boolean doRemoveAll)
      Create a menu and add a listener to it that removes all items and calls the given method on te given object with the menu as an argument.
      Parameters:
      name - Menu name
      object - Object to call
      methodName - method to invoke
      doRemoveAll - true to remove all first
      Returns:
      The menu
    • makeComboBox

      public static JComboBox makeComboBox(List items, Object selected, boolean editable, Object listener, String methodName)
      Make a JComboBox
      Parameters:
      items - items for the box
      selected - the selected item
      editable - flag for whether this is editable or not
      listener - Listener for changes
      methodName - method to call when item changes
      Returns:
      the combo box
    • makeComboBox

      public static JComboBox makeComboBox(List items, Object selected, boolean editable, Object listener, String methodName, boolean inAThread)
      Make a JComboBox
      Parameters:
      items - items for the box
      selected - the selected item
      editable - flag for whether this is editable or not
      listener - Listener for changes
      methodName - method to call when item changes
      inAThread - Call the method in a thread
      Returns:
      the combo box
    • makeComboBox

      public static JComboBox makeComboBox(int[] values, String[] labels, int current)
      Make a combo box from a set of values and labels
      Parameters:
      values - integer values
      labels - labels for values
      current - current one to select
      Returns:
      the JComboBox
    • setValueOfBox

      public static void setValueOfBox(JComboBox box, int value, int[] values, String[] labels)
      Set the value of the box
      Parameters:
      box - the box to set
      value - the default value
      values - the values
      labels - labels for the values
    • getValueFromBox

      public static int getValueFromBox(JComboBox box)
      Get the integer value from a JComboBox of integer items
      Parameters:
      box - the box to use
      Returns:
      the integer value
    • makeSlider

      public static JSlider makeSlider(int min, int max, int value, Object listener, String methodName)
      Make a JSlider
      Parameters:
      min - minimum value
      max - maximum value
      value - initial value
      listener - listener for changes
      methodName - method to call when change occurs
      Returns:
      JSlider
    • makeSlider

      public static JSlider makeSlider(int min, int max, int value, Object listener, String methodName, boolean updateAsMove)
      Make a JSlider
      Parameters:
      min - minimum value
      max - maximum value
      value - initial value
      listener - listener for changes
      methodName - method to call when change occurs
      updateAsMove - If true we call the listener as the slider moves.
      Returns:
      JSlider
    • getFontSizeList

      public static Vector getFontSizeList()
      Get a list of font sizes
      Returns:
      list of font sizes
    • getFontList

      public static Vector getFontList()
      Get a list of fonts
      Returns:
      vector of fonts
    • makeTwoFacedFont

      public static TwoFacedObject makeTwoFacedFont(Font f)
      Make a TwoFacedObject from a font for displaying in a combobox.
      Parameters:
      f - Font to use
      Returns:
      corresponding TwoFacedObject
    • makeRowVisible

      public static void makeRowVisible(JTable table, int row)
      Make the given row in the table visible
      Parameters:
      table - The table
      row - The row
    • scrollToTop

      public static void scrollToTop(JEditorPane editor)
      Scroll the given component to the top
      Parameters:
      editor - editor to scroll
    • addMouseListenerRecurse

      public static void addMouseListenerRecurse(MouseListener listener, Container c)
      Add a mouse listener to all components of a container
      Parameters:
      listener - the mouse listener
      c - the container
    • addKeyListenerRecurse

      public static void addKeyListenerRecurse(KeyListener listener, Container c)
      Add a key listener to all components of a container
      Parameters:
      listener - the key listener
      c - the container
    • distance

      public static double distance(double x1, double y1, double x2, double y2)
      Calculate distance between 2 points.
      Parameters:
      x1 - x1
      y1 - y1
      x2 - x2
      y2 - y2
      Returns:
      distance
    • distance

      public static double distance(double[] p1, double[] p2)
      Get distance between
      Parameters:
      p1 - From
      p2 - To
      Returns:
      Distance
    • distance

      public static double distance(int[] p1, int[] p2)
      Get distance between
      Parameters:
      p1 - From
      p2 - To
      Returns:
      Distance
    • distance

      public static double distance(double x, double y, Rectangle2D r)
      Calculate distance between point and rectangle. This will give the min distance from the 4 corners and the sides.
      Parameters:
      x - x
      y - y
      r - rect
      Returns:
      distance_
    • makeVerticalLabel

      public static JLabel makeVerticalLabel(String text)
      Make a vertical label
      Parameters:
      text - text
      Returns:
      vertical label
    • doMultiSplitPane

      public static JComponent doMultiSplitPane(List comps, boolean hsplit)
      Make an evenly balanced group of split panes for the given components
      Parameters:
      comps - List of components
      hsplit - horizontal or vertical
      Returns:
      split panes
    • getNestedTabbedPane

      public static JTabbedPane getNestedTabbedPane()
      Make a JTabbedPane without some of its border
      Returns:
      Tabbed pane
    • getNestedTabbedPane

      public static JTabbedPane getNestedTabbedPane(int orient)
      Make a JTabbedPane without some of its border
      Parameters:
      orient - tab orientation
      Returns:
      Tabbed pane
    • getNestedTabbedPane

      public static JTabbedPane getNestedTabbedPane(int orient, int top, int left, int bottom, int right)
      Make a JTabbedPane without some of its border
      Parameters:
      orient - tab orientation
      top - top border
      left - left border
      bottom - bottom border
      right - right border
      Returns:
      Tabbed pane
    • makeSliderPopup

      public static JComponent[] makeSliderPopup(int min, int max, int value, ChangeListener listener)
      This creates a JButton and a JSlider. The intent is that the button can be placed in some GUI. On click a small, decorationless modeful dialog that contains the slider is popped up. Focus is set on the slider and a return or escape or press of the close button closes the dialog. slider events are routed to the change listener.
      Parameters:
      min - slider min value
      max - slider max value
      value - slider value
      listener - slider change listener
      Returns:
      a 2 element array containing the button and the slider
    • positionAndFitToScreen

      public static void positionAndFitToScreen(Window window, Rectangle bounds)
      Position and fit a window to the screen
      Parameters:
      window - window to fit
      bounds - new bounds
    • toggleHeavyWeightComponents

      public static void toggleHeavyWeightComponents(Component comp, boolean visible)
      Walk the tree and set any heavyweight components visibility. Note: We don't turn off any component that is under the javax.swing package If we encounter a JTabbedPane then only show the components that are in the selected tab
      Parameters:
      comp - Component
      visible - On/off
    • checkHeavyWeightComponents

      public static void checkHeavyWeightComponents(JTabbedPane tab)
      Walk the components of the tab and toggle the heavyweight components visiblity
      Parameters:
      tab - tab
    • resetHeavyWeightComponents

      public static void resetHeavyWeightComponents(JTabbedPane tab)
      Walk the components of the tab and toggle the heavyweight components visiblity
      Parameters:
      tab - tab
    • handleHeavyWeightComponentsInTabs

      public static void handleHeavyWeightComponentsInTabs(JTabbedPane tab)
      Add a change listener to the tab that toggles on any heavy weight components in the selected tab and turns off any in the non-selected tabs.
      Parameters:
      tab - tab
    • main

      public static void main(String[] args) throws Exception
      test
      Parameters:
      args - args
      Throws:
      Exception - on badness
    • makeFileBrowseButton

      public static JButton makeFileBrowseButton(JTextComponent fld)
      Make a button that pops up a file browser and sets the text of the given field with the selected file
      Parameters:
      fld - Field to set
      Returns:
      The button
    • makeFileBrowseButton

      public static JButton makeFileBrowseButton(JTextComponent fld, List filters)
      Make a button that pops up a file browser and sets the text of the given field with the selected file
      Parameters:
      fld - Field to set
      filters - File filters. May be null.
      Returns:
      The button
    • makeFileBrowseButton

      public static JButton makeFileBrowseButton(JTextComponent fld, boolean chooseDirectory, List filters)
      Make a button that pops up a file browser and sets the text of the given field with the selected file
      Parameters:
      fld - Field to set
      chooseDirectory - Select a directory
      filters - File filters. May be null.
      Returns:
      The button
    • doMakeFontBox

      public static JComboBox doMakeFontBox(Font f)
      Make a font selector box
      Parameters:
      f - Font to select in the box
      Returns:
      The box
    • doMakeFontSizeBox

      public static JComboBox doMakeFontSizeBox(int size)
      Make a box for setting the font size
      Parameters:
      size - Selected size
      Returns:
      The box
    • italicizeFont

      public static Component italicizeFont(Component comp)
      Italicize the font on the given component
      Parameters:
      comp - The component
      Returns:
      the component
    • popupUnitMenu

      public static void popupUnitMenu(JTextField fld, JComponent comp)
      This pops up a menu near the given comp and allows the user to select a unit name which gets put into the given fld
      Parameters:
      fld - The fld to set
      comp - THe component to popup the menu near
    • getIconsInMenus

      public static boolean getIconsInMenus()
      Do we show icons in the menus
      Returns:
      show icons in menus
    • setIconsInMenus

      public static void setIconsInMenus(boolean doIcons)
      Do we show icons in the menus
      Parameters:
      doIcons - show icons
    • setIcon

      public static AbstractButton setIcon(AbstractButton button, String iconPath)
      Set the icon on the button. This button is usually a JMenu or JMenuItem If the setIconsInMenus flag is false then don't do this
      Parameters:
      button - The button
      iconPath - The icon path
      Returns:
      Just return the button so you can do something like menu.add(GuiUtils.setIcon(menuItem,"/icon path"));
    • setSelectedItems

      public static void setSelectedItems(JList list, List selected)
      _more_
      Parameters:
      list - _more_
      selected - _more_
    • getItems

      public static List getItems(JList list)
      _more_
      Parameters:
      list - _more_
      Returns:
      _more_
    • getLocalName

      public static String getLocalName(String n, boolean local)
      _more_
      Parameters:
      n - _more_
      local - _more_
      Returns:
      _more_
    • getLocalName

      public static String getLocalName(String n, boolean local, boolean addHtml)
      _more_
      Parameters:
      n - _more_
      local - _more_
      addHtml - _more_
      Returns:
      _more_
    • appendText

      public static void appendText(JTextComponent fld, String s, String delimiter)
      _more_
      Parameters:
      fld - _more_
      s - _more_
      delimiter - _more_
    • addKeyBindings

      public static void addKeyBindings(JTextComponent comp)
      _more_
      Parameters:
      comp - _more_
    • moveSubtreesToTop

      public static void moveSubtreesToTop(DefaultMutableTreeNode parent)
      _more_
      Parameters:
      parent - _more_
    • makeHeader

      public static JComponent makeHeader(String label)
      Utility to create a header that is a label and a line.
      Parameters:
      label - Header label
      Returns:
      Header
    • getAttribute

      public static String getAttribute(Node element, String name, String dflt)
      Get the given name-d attribute from the given element. If not found return the dflt argument.
      Parameters:
      element - The xml element to look within.
      name - The attribute name.
      dflt - The default value.
      Returns:
      The attribute value or the dflt if not found.
    • getAttribute

      public static String getAttribute(NamedNodeMap attrs, String name, String dflt)
      _more_
      Parameters:
      attrs - _more_
      name - _more_
      dflt - _more_
      Returns:
      _more_
    • getAttribute

      public static boolean getAttribute(NamedNodeMap attrs, String name, boolean dflt)
      _more_
      Parameters:
      attrs - _more_
      name - _more_
      dflt - _more_
      Returns:
      _more_
    • getAttribute

      public static String getAttribute(NamedNodeMap attrs, String name)
      _more_
      Parameters:
      attrs - _more_
      name - _more_
      Returns:
      _more_
    • findChildren

      public static List findChildren(Node parent, String tag)
      _more_
      Parameters:
      parent - _more_
      tag - _more_
      Returns:
      _more_
    • getInt

      public static int getInt(JTextField fld)
      Get an integer value from the text field
      Parameters:
      fld - text field
      Returns:
      integer value shown
    • getValue

      public static double getValue(JTextField fld)
      Get an double value from the text field
      Parameters:
      fld - text field
      Returns:
      double value shown
    • setApplicationTitle

      public static void setApplicationTitle(String title)
      _more_
      Parameters:
      title - _more_
    • getApplicationTitle

      public static String getApplicationTitle()
      _more_
      Returns:
      _more_
    • doMacMenubar

      public static boolean doMacMenubar()
      _more_
      Returns:
      _more_
    • isControlKey

      public static boolean isControlKey(InputEvent event)
      Is the given event a control (or meta for the mac) key
      Parameters:
      event - _more_
      Returns:
      _more_
    • isControlKey

      public static boolean isControlKey(KeyEvent event, int keyCode)
      _more_
      Parameters:
      event - _more_
      keyCode - _more_
      Returns:
      _more_
    • isMac

      public static boolean isMac()
      Is this running on a Mac?
      Returns:
      true if running on Mac
    • isDeleteEvent

      public static boolean isDeleteEvent(KeyEvent e)
      _more_
      Parameters:
      e - _more_
      Returns:
      _more_
    • decorateFrame

      public static void decorateFrame(JFrame frame, JMenuBar menuBar)
      _more_
      Parameters:
      frame - _more_
      menuBar - _more_
    • showUrl

      public static void showUrl(String s) throws Exception
      _more_
      Parameters:
      s - _more_
      Throws:
      Exception - _more_
    • addLinkListener

      public static void addLinkListener(JEditorPane editor)
      _more_
      Parameters:
      editor - _more_
    • showFrameAsDialog

      public static void showFrameAsDialog(Component parentComponent, JFrame frame)
      popup but a modal dialog with input Jframe