ucar.unidata.util
Class GuiUtils

java.lang.Object
  extended by ucar.unidata.util.MenuUtil
      extended by ucar.unidata.util.LayoutUtil
          extended by ucar.unidata.util.GuiUtils

public class GuiUtils
extends LayoutUtil

This is a vast catchall class to old various utilities for doing GUI things.

Author:
IDV development team

Nested Class Summary
static class GuiUtils.CardLayoutPanel
          Class CardLayoutPanel is a utility that does a card layou of its components.
static class GuiUtils.ColorSwatch
          A color swatch panel
static class GuiUtils.TreeSearchResults
          Class TreeSearchResults Holds state from a tree search
static class GuiUtils.VerticalLabelUI
          Class for a vertical label
 
Field Summary
static String ATTR_ACTION
          xml attribute name
static String ATTR_ICON
          xml attribute name
static String ATTR_ID
          xml attribute name
static String ATTR_TOOLTIP
          xml attribute name
static Font buttonFont
          Used by apps for having a common font for buttons
static String CMD_APPLY
          Action command used for the Apply button
static String CMD_CANCEL
          Action command used for the Cancel button
static String CMD_CLOSE
          Action command used for the Close button
static String CMD_EXPORT
          Action command used for the Export button
static String CMD_HELP
          Action command used for the Help button
static String CMD_IMPORT
          Action command used for the Import button
static String CMD_NEW
          Action command used for the New button
static String CMD_NO
          Action command used for the No button
static String CMD_OK
          Action command used for the OK button
static String CMD_OPEN
          Action command used for the Open button
static String CMD_REMOVE
          Action command used for the Remove button
static String CMD_RENAME
          Action command used for the Rename button
static String CMD_RESET
          Action command used for the Reset button
static String CMD_SAVE
          Action command used for the Save button
static String CMD_SAVEAS
          Action command used for the Saveas button
static String CMD_START
          Action command used for the Start button
static String CMD_STOP
          Action command used for the Stop button
static String CMD_SUBMIT
          Action command used for the Submit button
static String CMD_UPDATE
          Action command used for the Update button
static String CMD_YES
          Action command used for the Yes button
static String[] COLORNAMES
          Used to map named colors to color
static Color[] COLORS
          Used to map named colors to color
static int[] FONT_SIZES
          font sizes
static String MISSING_IMAGE
           
static Cursor normalCursor
          The normal cursor_
static Cursor waitCursor
          The cursor to use when waiting
 
Fields inherited from class ucar.unidata.util.LayoutUtil
INSETS_2, INSETS_5, tmpAnchor, tmpColFills, tmpFill, tmpInsets, WT_N, WT_NN, WT_NNN, WT_NNNY, WT_NNY, WT_NNYN, WT_NNYNY, WT_NNYNYNY, WT_NY, WT_NYN, WT_NYNY, WT_NYNYN, WT_NYY, WT_Y, WT_YN, WT_YNN, WT_YNY, WT_YNYN, WT_YY, WT_YYN, WT_YYY, ZERO_INSETS
 
Fields inherited from class ucar.unidata.util.MenuUtil
MENU_SEPARATOR
 
Method Summary
static JComponent addActionListener(JComponent comp, Object object, String methodName, Object arg)
          Adds an action listener to the button.
static void addKeyBindings(JTextComponent comp)
           
static void addKeyListenerRecurse(KeyListener listener, Container c)
          Add a key listener to all components of a container
static void addModalDialogComponent(Component comp)
          Add the model dialog to the list
static void addMouseListenerRecurse(MouseListener listener, Container c)
          Add a mouse listener to all components of a container
static boolean anySelected(JComboBox box)
          Check if there are any selected items in the combobox.
static void appendText(JTextComponent fld, String s, String delimiter)
           
static boolean askOkCancel(String title, Object question)
          Ask the user the question.
static boolean askYesNo(String title, Object question)
          Ask the user the question.
static ButtonGroup buttonGroup(JToggleButton b1, JToggleButton b2)
          Create a button group and add the two buttons to it.
static ButtonGroup buttonGroup(JToggleButton b1, JToggleButton b2, JToggleButton b3)
          Create a button group and add the three buttons to it.
static int charToKeyCode(char ch)
          Return the numeric key code of the given character.
static int charToKeyCode(String s)
          Take the first character of the string and return the numeric key code
static boolean checkHeight(int height)
           
static JLabel cLabel(String s)
          Create a center aligned JLabel
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.
static JDialog createDialog(String title, boolean modal)
          A utility to create a dialog.
static JDialog createDialog(Window parent, String title, boolean modal)
          Utility to create a JDialog with a parent component.
static JFrame createFrame(String title)
          A utility to create a frame.
static JComboBox createValueBox(ActionListener listener, String command, int initValue, List values, boolean editable)
          Create a combobx boxc that holds a set of integer values.
static Color decodeColor(String value, Color dflt)
          This takes the given String and tries to convert it to a color.
static double distance(double[] p1, double[] p2)
          Get distance between
static double distance(double x1, double y1, double x2, double y2)
          Calculate distance between 2 points.
static double distance(double x, double y, Rectangle2D r)
          Calculate distance between point and rectangle.
static double distance(int[] p1, int[] p2)
          Get distance between
static JComboBox doMakeFontBox(Font f)
          Make a font selector box
static JComboBox doMakeFontSizeBox(int size)
          Make a box for setting the font size
static JComponent doMultiSplitPane(List comps, boolean hsplit)
          Make an evenly balanced group of split panes for the given components
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.
static GuiUtils.TreeSearchResults doTreeSearch(JTree tree, Object lastState, String nodeDesc, JComponent near, String originalPhrase)
          Search the given tree
static void empty(Container c)
          If non-null then removes all children and removes from parent.
static void enableComponents(List comps, boolean enable)
          Enable or disable the list of Components
static void enableTree(Component comp, boolean enable)
          Enable or disable a whole tree's worth of components
static void expandPathsAfterChange(JTree tree, Hashtable state, DefaultMutableTreeNode root)
          Call this after the structure of a JTree changes to re-expand the paths.
static void exportAsCsv(String header, TableModel model)
          Write out the given table model as a comma separated value (CSV) file prepending the header.
static void exportAsCsv(String header, TableModel model, String filename)
          _more_
static void exportAsCsv(TableModel model)
          Write out the given table model as a csv file
static List findChildren(Node parent, String tag)
           
static JPanel flow(Component[] comps)
          Create a panel and do flow layout of the components
static JPanel flowRight(Component[] comps)
          Create a panel and do a a right align flow layout of the components
static JComponent formLayout(Component[] comps)
          Do a 2 column layout.
static JComponent formLayout(Component[] comps, double[] widths, double[] heights)
          Do a 2 column layout.
static JComponent formLayout(List comps)
          Do a 2 column layout.
static JComponent formLayout(List comps, boolean rightAlignFirstColumn)
          Do a 2 column layout.
static JComponent formLayout(List comps, double[] widths, double[] heights)
          Do a 2 column layout.
static JComponent formLayout(List comps, double[] widths, double[] heights, boolean rightAlignFirstColumn)
          Do a 2 column layout.
static String getAttribute(NamedNodeMap attrs, String name)
           
static boolean getAttribute(NamedNodeMap attrs, String name, boolean dflt)
           
static String getAttribute(NamedNodeMap attrs, String name, String dflt)
           
static String getAttribute(Node element, String name, String dflt)
          Get the given name-d attribute from the given element.
static int getBoxValue(JComboBox box)
          Return the selected item in the given box as an integer.
static ObjectListener getCloseDialogListener(JDialog dialog)
          Create a listener that will close the given dialog.
static String getColorName(Color color)
          Return the name of the given color.
static JComboBox getEditableBox(List items, Object selected)
          Create an editable combobox with the given items.
static JLabel getFixedWidthLabel(String s)
          Create a JLabel with a fixed width font
static Vector getFontList()
          Get a list of fonts
static Vector getFontSizeList()
          Get a list of font sizes
static JFrame getFrame(Component component)
          This finds and returns the JFrame, or null if not found, that holds the given component.
static Component[] getHtmlComponent(String html, HyperlinkListener linkListener, int width, int height)
          Make a JTextEditor component and scroller for the given html
static Image getImage(Component component)
          Get the screen image from the component
static Image getImage(String file)
          Create an Image from the given image file name.
static Image getImage(String file, Class c)
          Create an Image from the given image file name.
static Image getImage(String file, Class c, boolean cache)
          Create an Image from the given image file name.
static Image getImage(String file, Class c, boolean cache, boolean returnNullIfNotFound)
          _more_
static JButton getImageButton(ImageIcon icon)
          Create a JButton that displays the given image icon
static JButton getImageButton(ImageIcon icon, int offset)
          Create a JButton that displays the given image icon
static JButton getImageButton(ImageIcon icon, int hinset, int vinset)
          Create a JButton that displays the given image icon
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).
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).
static ImageIcon getImageIcon(String file)
          Create an ImageIcon from the given image file name.
static ImageIcon getImageIcon(String file, boolean cache)
          Create an ImageIcon from the given image file name.
static ImageIcon getImageIcon(String file, Class c)
          Create an ImageIcon from the given image file name.
static ImageIcon getImageIcon(String file, Class c, boolean cache)
          Create an ImageIcon from the given image file name.
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).
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).
static String getInput(String question)
          Ask the user the question.
static String getInput(String question, String label, String initValue)
          Ask the user the question.
static String getInput(String question, String label, String initValue, String trailingLabel)
          Ask the user the question.
static String getInput(String question, String label, String initValue, String trailingLabel, Object underLabel)
          Ask the user the question.
static String getInput(String question, String label, String initValue, String trailingLabel, Object underLabel, String title)
          Ask the user the question.
static String getInput(String question, String label, String initValue, String trailingLabel, Object underLabel, String title, int fieldWidth)
          Ask the user the question.
static String getInput(String question, String label, String initValue, String trailingLabel, Object underLabel, String title, int fieldWidth, JComponent nearComponent)
          Ask the user the question.
static List getItems(JComboBox box)
          return the list of items held by the combo box.
static List getItems(JList list)
           
static String getLocalName(String n, boolean local)
           
static String getLocalName(String n, boolean local, boolean addHtml)
           
static Point getLocation(Component src)
          Find the location of the given componet on the screen.
static JTabbedPane getNestedTabbedPane()
          Make a JTabbedPane without some of its border
static JTabbedPane getNestedTabbedPane(int orient)
          Make a JTabbedPane without some of its border
static JTabbedPane getNestedTabbedPane(int orient, int top, int left, int bottom, int right)
          Make a JTabbedPane without some of its border
static double getSliderPercent(JSlider s)
          Return the slider value as a percentage between its min and max
static JToggleButton getToggleButton(ImageIcon icon, int hinset, int vinset)
          Create a toggle button with the given image.
static JToggleButton getToggleButton(String iconPath, int hinset, int vinset)
          Create a toggle button with the given image.
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.
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.
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.
static int getValueFromBox(JComboBox box)
          Get the integer value from a JComboBox of integer items
static Window getWindow(Component component)
          This finds and returns the Window, or null if not found, that contains the given component.
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.
static JComponent hspace(int w, int h)
          Create a a minimally sized spacer
static JSplitPane hsplit(Component left, Component right)
          Create a basic horizontally aligned JSplitPane
static JSplitPane hsplit(Component left, Component right, double resizeWeight)
          Create a horizontally aligned JSplitPane
static JSplitPane hsplit(Component left, Component right, int leftSpace)
          Create a horizontally aligned JSplitPane
static JSplitPane hsplit(Component left, Component right, int leftSpace, double resizeWeight)
          Create a horizontally aligned JSplitPane.
static Hashtable initializeExpandedPathsBeforeChange(JTree tree, DefaultMutableTreeNode root)
          Call this before a JTree changes.
static void initLabels()
          Init the fixed labels
static void insertText(JTextComponent comp, String s)
          _more_
static boolean isShowing(JDialog f)
          Is the dialog showing
static boolean isShowing(JFrame f)
          Is the frame showing
static Component italicizeFont(Component comp)
          Italicize the font on the given component
static JPanel label(Component widget, String label)
          Create a JPanel that holds a the given widget/JLabel
static JPanel label(String label, Component widget)
          Create a JPanel that holds a JLabel/the given widget
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.
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.
static JLabel lLabel(String s)
          Create a left aligned JLabel
static void main(String[] args)
          test
static ActionListener makeActionListener(Object object, String methodName, Object arg)
          Make an ActionListener.
static JButton makeApplyButton(ActionListener l)
          Utility to make apply button panel
static JPanel makeApplyCancelButtons(ActionListener l)
          Utility to make apply/cancel button panel
static JPanel makeApplyOkCancelButtons(ActionListener l)
          Utility to make apply/ok/cancel button panel
static JPanel makeApplyOkHelpCancelButtons(ActionListener l)
          Utility to make apply/ok/help/cancel button panel
static JPanel makeApplyOkResetCancelButtons(ActionListener l)
          Utility to make apply/ok/reset/cancel button panel
static JButton makeButton(String label, Object object, String methodName)
          Make a JButton.
static JButton makeButton(String label, Object object, String methodName, Object arg)
          Make a JButton.
static JButton makeButton(String label, Object object, String methodName, Object arg, String tooltip)
          Make a JButton.
static JPanel makeButtons(ActionListener l, String[] cmds)
          Make a set of JButtons, each with a label and action command from the given cmds array.
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.
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.
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.
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.
static JCheckBox makeCheckbox(String label, Object object, String property)
          Make a checkbox.
static JCheckBox makeCheckbox(String label, Object object, String property, Object arg)
          Make a checkbox.
static JComboBox makeColorNameComboBox(Color dflt)
          A helper to make a color selector combo box
static JComponent[] makeColorSwatchWidget(Color color, String label)
          This makes a color swatch and a 'Set' button that is used to set the color.
static JComboBox makeComboBox(int[] values, String[] labels, int current)
          Make a combo box from a set of values and labels
static JComboBox makeComboBox(List items, Object selected, boolean editable, Object listener, String methodName)