util.ui

## Class UiUtilities

- java.lang.Object
- - util.ui.UiUtilities

-     public class UiUtilities
      extends java.lang.Object

  Provides utilities for UI stuff.
  Author:
    Til Schneider, www.murfman.de

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static javax.swing.border.Border` | `DIALOG_BORDER` The border to use for dialogs.
    `static java.awt.Insets` | `ZERO_INSETS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `UiUtilities()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `addSeparatorsAfterIndexes(javax.swing.JComboBox combo, int[] indexes)`
    `static void` | `addSeparatorsAfterIndexes(javax.swing.JComboBox combo, java.lang.Integer[] indexes)`
    `static void` | `centerAndShow(java.awt.Window win)` Centers a window to its parent frame and shows it.
    `static boolean` | `colorsInEqualRange(java.awt.Color c1, java.awt.Color c2, int maxDiff)` Tests if the given colors are equal in the given maximum difference.
    `static boolean` | `containsModalDialogChild(java.awt.Window parent)` Gets if a dialog child of the given window is modal.
    `static javax.swing.ImageIcon` | `createChannelIcon(javax.swing.Icon ic)` Creates a scaled Version of the Icon.
    `static javax.swing.JDialog` | `createDialog(java.awt.Component parent, boolean modal)`
    `static javax.swing.JTextArea` | `createHelpTextArea(java.lang.String msg)` Creates a text area that holds a help text.
    `static javax.swing.JEditorPane` | `createHtmlHelpTextArea(java.lang.String html)` Creates a Html EditorPane that holds a HTML-Help Text Links will be displayed and are clickable
    `static javax.swing.JEditorPane` | `createHtmlHelpTextArea(java.lang.String html, java.awt.Color background)` Creates a Html EditorPane that holds a HTML-Help Text Links will be displayed and are clickable
    `static javax.swing.JEditorPane` | `createHtmlHelpTextArea(java.lang.String html, java.awt.Color foreground, java.awt.Color background)` Creates a Html EditorPane that holds a HTML-Help Text Links will be displayed and are clickable
    `static javax.swing.JEditorPane` | `createHtmlHelpTextArea(java.lang.String html, javax.swing.event.HyperlinkListener listener)` Creates a Html EditorPane that holds a HTML-Help Text.
    `static javax.swing.JEditorPane` | `createHtmlHelpTextArea(java.lang.String html, javax.swing.event.HyperlinkListener listener, java.awt.Color background)` Creates a Html EditorPane that holds a HTML-Help Text.
    `static javax.swing.JEditorPane` | `createHtmlHelpTextArea(java.lang.String html, javax.swing.event.HyperlinkListener listener, java.awt.Color foreground, java.awt.Color background)` Creates a Html EditorPane that holds a HTML-Help Text.
    `static javax.swing.JFileChooser` | `createNewFileChooser(javax.swing.filechooser.FileFilter fileFilter)` creates a new file chooser.
    `static javax.swing.JPanel` | `createPersonaBackgroundPanel()` Creates a panel that has a semi-transparent background created of Persona colors.
    `static javax.swing.JButton` | `createToolBarButton(java.lang.String text, javax.swing.Icon icon)` Gibt einen Button mit Icon und Schrift zurï¿½ck, der so initialisiert ist, daï¿½ man ihn gut fï¿½r Symbolleisten nutzen kann (Rahmen nur bei Rollover sichtbar usw.).
    `static java.awt.Window` | `getBestDialogParent(java.awt.Component parent)` Gets the best dialog parent for a new JDialog.
    `static int` | `getChannelIconHeight()`
    `static int` | `getChannelIconWidth()`
    `static int` | `getCharsWidth(java.awt.Font font, char[] chars, int offset, int length)` Gets the width of the specified char array.
    `static java.lang.String` | `getDefaultLookAndFeelClassName(boolean excludeGTK)`
    `static java.lang.String` | `getHTMLColorCode(java.awt.Color color)` returns a color code as used in HTML, e.g.
    `static java.awt.Window` | `getLastModalChildOf(java.awt.Window parent)` Gets the last visible modal child dialog of the specified window.
    `static int` | `getStringWidth(java.awt.Font font, java.lang.String str)` Gets the width of the specified String.
    `static boolean` | `isGTKLookAndFeel()`
    `static boolean` | `isNimbusLookAndFeel()`
    `static void` | `moveSelectedItems(javax.swing.JList list, int nrRows)` Move selected Items in the JList
    `static void` | `moveSelectedItems(javax.swing.JList list, int row, boolean sort)` Move selected Items in the JList
    `static java.lang.Object[]` | `moveSelectedItems(javax.swing.JList fromList, javax.swing.JList toList)` Moves Selected Items from one List to another
    `static java.lang.Object[]` | `moveSelectedItems(javax.swing.JList fromList, javax.swing.JList toList, int row)` Moves Selected Items from one List to another
    `static void` | `registerForClosing(WindowClosingIf component)` Registers the escape key as close key for a component.
    `static javax.swing.Icon` | `scaleIcon(javax.swing.Icon icon, int newWidth)` Scale Icons to a specific width.
    `static javax.swing.Icon` | `scaleIcon(javax.swing.Icon icon, int width, int height)` Scales Icons to a specific size
    `static java.awt.image.BufferedImage` | `scaleIconToBufferedImage(java.awt.image.BufferedImage img, int width, int height)` Scales an image to a specific size and returns an BufferedImage
    `static java.awt.image.BufferedImage` | `scaleIconToBufferedImage(java.awt.image.BufferedImage img, int width, int height, int type)` Scales an image to a specific size and returns an BufferedImage
    `static java.awt.image.BufferedImage` | `scaleIconToBufferedImage(java.awt.image.BufferedImage img, int targetWidth, int targetHeight, int type, java.awt.Color backgroundColor)` Scales an image to a specific size and returns an BufferedImage
    `static void` | `setSize(javax.swing.JDialog dialog, int width, int height)` set the size of a dialog, but never sizes it smaller than the preferred size
    `static void` | `updateHtmlHelpTextArea(javax.swing.JEditorPane helpTextArea, java.lang.String description)`
    `static void` | `updateHtmlHelpTextArea(javax.swing.JEditorPane helpTextArea, java.lang.String html, java.awt.Color background)`
    `static void` | `updateHtmlHelpTextArea(javax.swing.JEditorPane helpTextArea, java.lang.String html, java.awt.Color foreground, java.awt.Color background)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DIALOG_BORDER

          public static final javax.swing.border.Border DIALOG_BORDER

      The border to use for dialogs.

    - #### ZERO_INSETS

          public static final java.awt.Insets ZERO_INSETS

  - ### Constructor Detail

    - #### UiUtilities

          public UiUtilities()

  - ### Method Detail

    - #### centerAndShow

          public static void centerAndShow(java.awt.Window win)

      Centers a window to its parent frame and shows it.

      If the window has no parent frame it will be centered to the screen.

      Parameters:
        `win` - The window to center and show.

    - #### createDialog

          public static javax.swing.JDialog createDialog(java.awt.Component parent,
                                         boolean modal)

      Parameters:
        `parent` - A component in the component tree where the dialog should be created for.
        `modal` - Should the new dialog be modal?
      Returns:
        A new JDialog.

    - #### getBestDialogParent

          public static java.awt.Window getBestDialogParent(java.awt.Component parent)

      Gets the best dialog parent for a new JDialog. The best parent is the last visible modal dialog in the component tree.

      If there is no visible modal dialog the root frame will be returned.

      Parameters:
        `parent` - One component of the component tree.
      Returns:
        the best dialog parent for a new JDialog.

    - #### getLastModalChildOf

          public static java.awt.Window getLastModalChildOf(java.awt.Window parent)

      Gets the last visible modal child dialog of the specified window.

      If there is no visible modal child the window itself will be returned.

      Parameters:
        `parent` - The window to get the child from.
      Returns:
        the last visible modal child dialog of the specified window.

    - #### containsModalDialogChild

          public static boolean containsModalDialogChild(java.awt.Window parent)

      Gets if a dialog child of the given window is modal.
      Parameters:
        `parent` - The window to check the children of.
      Returns:
        `True` if a child is modal, `false` otherwise.
      Since:
        2.7

    - #### createToolBarButton

          public static javax.swing.JButton createToolBarButton(java.lang.String text,
                                                javax.swing.Icon icon)

      Gibt einen Button mit Icon und Schrift zurï¿½ck, der so initialisiert ist, daï¿½ man ihn gut fï¿½r Symbolleisten nutzen kann (Rahmen nur bei Rollover sichtbar usw.).

      Wenn text und iconDateiname angegeben sind, dann wird text als TooltipText gesetzt.

      Parameters:
        `text` - Der Text des Buttons (Kann null sein, wenn der Button keinen Text enthalten soll)
        `icon` - Das Icon des Buttons (Kann ebenfalls null sein, wenn der Button kein Icon enthalten soll).
      Returns:
        button

    - #### getStringWidth

          public static int getStringWidth(java.awt.Font font,
                           java.lang.String str)

      Gets the width of the specified String.
      Parameters:
        `str` - The String to get the width for.
        `font` - The font being the base of the measure.
      Returns:
        the width of the specified String.

    - #### getCharsWidth

          public static int getCharsWidth(java.awt.Font font,
                          char[] chars,
                          int offset,
                          int length)

      Gets the width of the specified char array.
      Parameters:
        `chars` - The char array to get the width for.
        `offset` - The offset where to start.
        `length` - The length of the measure.
        `font` - The font being the base of the measure.
      Returns:
        the width of the specified char array.

    - #### createHelpTextArea

          public static javax.swing.JTextArea createHelpTextArea(java.lang.String msg)

      Creates a text area that holds a help text.
      Parameters:
        `msg` - The help text.
      Returns:
        A text area containing the help text.

    - #### createHtmlHelpTextArea

          public static javax.swing.JEditorPane createHtmlHelpTextArea(java.lang.String html)

      Creates a Html EditorPane that holds a HTML-Help Text Links will be displayed and are clickable
      Parameters:
        `html` - HTML-Text to display
      Returns:
        EditorPane that holds a Help Text
      Since:
        2.2

    - #### createHtmlHelpTextArea

          public static javax.swing.JEditorPane createHtmlHelpTextArea(java.lang.String html,
                                                       java.awt.Color background)

      Creates a Html EditorPane that holds a HTML-Help Text Links will be displayed and are clickable
      Parameters:
        `html` - HTML-Text to display
        `background` - The color for the background.
      Returns:
        EditorPane that holds a Help Text
      Since:
        2.7.2

    - #### createHtmlHelpTextArea

          public static javax.swing.JEditorPane createHtmlHelpTextArea(java.lang.String html,
                                                       java.awt.Color foreground,
                                                       java.awt.Color background)

      Creates a Html EditorPane that holds a HTML-Help Text Links will be displayed and are clickable
      Parameters:
        `html` - HTML-Text to display
        `foreground` - The color of the text.
        `background` - The color for the background.
      Returns:
        EditorPane that holds a Help Text
      Since:
        3.3.4

    - #### createHtmlHelpTextArea

          public static javax.swing.JEditorPane createHtmlHelpTextArea(java.lang.String html,
                                                       javax.swing.event.HyperlinkListener listener)

      Creates a Html EditorPane that holds a HTML-Help Text. Add a Listener if you want to have clickable Links
      Parameters:
        `html` - HTML-Text to display
        `listener` - Link-Listener for this HelpText
      Returns:
        EditorPane that holds a Help Text
      Since:
        2.2

    - #### createHtmlHelpTextArea

          public static javax.swing.JEditorPane createHtmlHelpTextArea(java.lang.String html,
                                                       javax.swing.event.HyperlinkListener listener,
                                                       java.awt.Color background)

      Creates a Html EditorPane that holds a HTML-Help Text. Add a Listener if you want to have clickable Links
      Parameters:
        `html` - HTML-Text to display
        `listener` - Link-Listener for this HelpText
        `background` - The color for the background.
      Returns:
        EditorPane that holds a Help Text
      Since:
        2.7.2

    - #### createHtmlHelpTextArea

          public static javax.swing.JEditorPane createHtmlHelpTextArea(java.lang.String html,
                                                       javax.swing.event.HyperlinkListener listener,
                                                       java.awt.Color foreground,
                                                       java.awt.Color background)

      Creates a Html EditorPane that holds a HTML-Help Text. Add a Listener if you want to have clickable Links
      Parameters:
        `html` - HTML-Text to display
        `listener` - Link-Listener for this HelpText
        `foreground` - The color of the text.
        `background` - The color for the background.
      Returns:
        EditorPane that holds a Help Text
      Since:
        3.3.4

    - #### updateHtmlHelpTextArea

          public static void updateHtmlHelpTextArea(javax.swing.JEditorPane helpTextArea,
                                    java.lang.String html,
                                    java.awt.Color foreground,
                                    java.awt.Color background)

      Parameters:
        `helpTextArea` - The editor pane to update.
        `html` - The text for the editor pane.
        `foreground` - The foreground color.
        `background` - The background color.
      Since:
        3.3.4

    - #### updateHtmlHelpTextArea

          public static void updateHtmlHelpTextArea(javax.swing.JEditorPane helpTextArea,
                                    java.lang.String html,
                                    java.awt.Color background)

      Parameters:
        `helpTextArea` -
        `html` -
        `background` -
      Since:
        3.0.2

    - #### updateHtmlHelpTextArea

          public static void updateHtmlHelpTextArea(javax.swing.JEditorPane helpTextArea,
                                    java.lang.String description)

    - #### getHTMLColorCode

          public static java.lang.String getHTMLColorCode(java.awt.Color color)

      returns a color code as used in HTML, e.g. #FF0000 for pure red
      Parameters:
        `color` -
      Returns:
        HTML color code

    - #### moveSelectedItems

          public static java.lang.Object[] moveSelectedItems(javax.swing.JList fromList,
                                             javax.swing.JList toList)

      Moves Selected Items from one List to another
      Parameters:
        `fromList` - Move from this List
        `toList` - Move into this List
      Returns:
        Moved Elements

    - #### moveSelectedItems

          public static java.lang.Object[] moveSelectedItems(javax.swing.JList fromList,
                                             javax.swing.JList toList,
                                             int row)

      Moves Selected Items from one List to another
      Parameters:
        `fromList` - Move from this List
        `toList` - Move into this List
        `row` - The target row where to insert
      Returns:
        Moved Elements

    - #### moveSelectedItems

          public static void moveSelectedItems(javax.swing.JList list,
                               int row,
                               boolean sort)

      Move selected Items in the JList
      Parameters:
        `list` - Move Items in this List
        `row` - The target row where to insert
        `sort` - Dummy parameter, does nothing

    - #### moveSelectedItems

          public static void moveSelectedItems(javax.swing.JList list,
                               int nrRows)

      Move selected Items in the JList
      Parameters:
        `list` - Move Items in this List
        `nrRows` - Move Items nrRows up/down

    - #### scaleIcon

          public static javax.swing.Icon scaleIcon(javax.swing.Icon icon,
                                   int newWidth)

      Scale Icons to a specific width. The aspect ratio is kept.
      Parameters:
        `icon` - The icon to scale.
        `newWidth` - The new width of the icon.
      Returns:
        The scaled Icon.

    - #### scaleIcon

          public static javax.swing.Icon scaleIcon(javax.swing.Icon icon,
                                   int width,
                                   int height)

      Scales Icons to a specific size
      Parameters:
        `icon` - Icon that should be scaled
        `width` - scaled width
        `height` - scaled height
      Returns:
        Scaled Icon

    - #### scaleIconToBufferedImage

          public static java.awt.image.BufferedImage scaleIconToBufferedImage(java.awt.image.BufferedImage img,
                                                              int width,
                                                              int height)

      Scales an image to a specific size and returns an BufferedImage
      Parameters:
        `img` - Scale this IMage
        `width` - new width
        `height` - new height
      Returns:
        Scaled BufferedImage
      Since:
        2.5

    - #### scaleIconToBufferedImage

          public static java.awt.image.BufferedImage scaleIconToBufferedImage(java.awt.image.BufferedImage img,
                                                              int width,
                                                              int height,
                                                              int type)

      Scales an image to a specific size and returns an BufferedImage
      Parameters:
        `img` - Scale this image
        `width` - new width
        `height` - new height
        `type` - The type of the image.
      Returns:
        Scaled BufferedImage
      Since:
        2.7

    - #### scaleIconToBufferedImage

          public static java.awt.image.BufferedImage scaleIconToBufferedImage(java.awt.image.BufferedImage img,
                                                              int targetWidth,
                                                              int targetHeight,
                                                              int type,
                                                              java.awt.Color backgroundColor)

      Scales an image to a specific size and returns an BufferedImage
      Parameters:
        `img` - Scale this image
        `targetWidth` - new width
        `targetHeight` - new height
        `type` - The type of the image.
      Returns:
        Scaled BufferedImage
      Since:
        3.0

    - #### createChannelIcon

          public static javax.swing.ImageIcon createChannelIcon(javax.swing.Icon ic)

      Creates a scaled Version of the Icon. The scaled Version will have a Background and a Border.
      Parameters:
        `ic` -
      Returns:
        ImageIcon
      Since:
        2.1

    - #### getChannelIconHeight

          public static int getChannelIconHeight()

    - #### getChannelIconWidth

          public static int getChannelIconWidth()

    - #### registerForClosing

          public static void registerForClosing(WindowClosingIf component)

      Registers the escape key as close key for a component.
      Parameters:
        `component` - The component to close on pressing escape key.

    - #### setSize

          public static void setSize(javax.swing.JDialog dialog,
                     int width,
                     int height)

      set the size of a dialog, but never sizes it smaller than the preferred size
      Parameters:
        `dialog` - dialog to be sized
        `width` - wanted width
        `height` - wanted height

    - #### addSeparatorsAfterIndexes

          public static void addSeparatorsAfterIndexes(javax.swing.JComboBox combo,
                                       int[] indexes)

    - #### addSeparatorsAfterIndexes

          public static void addSeparatorsAfterIndexes(javax.swing.JComboBox combo,
                                       java.lang.Integer[] indexes)

    - #### createNewFileChooser

          public static javax.swing.JFileChooser createNewFileChooser(javax.swing.filechooser.FileFilter fileFilter)

      creates a new file chooser. It is guaranteed that this happens in the UI thread.
      Parameters:
        `fileFilter` - file filter or `null`
      Returns:
        file chooser

    - #### colorsInEqualRange

          public static boolean colorsInEqualRange(java.awt.Color c1,
                                   java.awt.Color c2,
                                   int maxDiff)

      Tests if the given colors are equal in the given maximum difference.

      Parameters:
        `c1` - The first color.
        `c2` - The second color.
        `maxDiff` - The maximum difference that counts as equal range.
      Returns:
        `true` if both colors are in the equal range.

    - #### createPersonaBackgroundPanel

          public static javax.swing.JPanel createPersonaBackgroundPanel()

      Creates a panel that has a semi-transparent background created of Persona colors.

      Returns:
        The created JPanel.
      Since:
        3.2

    - #### isNimbusLookAndFeel

          public static boolean isNimbusLookAndFeel()

      Returns:
        If the current LookAndFeel is Nimbus.
      Since:
        3.2

    - #### isGTKLookAndFeel

          public static boolean isGTKLookAndFeel()

      Returns:
        If the current LookAndFeel is GTK+.
      Since:
        3.2

    - #### getDefaultLookAndFeelClassName

          public static java.lang.String getDefaultLookAndFeelClassName(boolean excludeGTK)

      Parameters:
        `excludeGTK` - `true` if the GTK+ look and feel should not be considered to be the default look and feel.
      Returns:
        The default LookAndFeel class name
      Since:
        3.4.2

TV-Browser 3.4.3, Copyright (C) 2004-2008 TV-Browser Team (dev@tvbrowser.org)