TV-Browser 2.7.5 API

util.ui
Class UiUtilities

java.lang.Object
  extended by util.ui.UiUtilities

public class UiUtilities
extends Object

Provides utilities for UI stuff.

Author:
Til Schneider, www.murfman.de

Field Summary
static Border DIALOG_BORDER
          The border to use for dialogs.
static Insets ZERO_INSETS
           
 
Constructor Summary
UiUtilities()
           
 
Method Summary
static void centerAndShow(Window win)
          Centers a window to its parent frame and shows it.
static boolean containsModalDialogChild(Window parent)
          Gets if a dialog child of the given window is modal.
static ImageIcon createChannelIcon(Icon ic)
          Creates a scaled Version of the Icon.
static JDialog createDialog(Component parent, boolean modal)
          Der JDialog hat einen Riesennachteil: er hat zwei verschiedenen Konstrukturen: einer f�r einen Frame als Besitzer und einer f�r einen Dialog als Besitzer.
static JTextArea createHelpTextArea(String msg)
          Creates a text area that holds a help text.
static JEditorPane createHtmlHelpTextArea(String html)
          Creates a Html EditorPane that holds a HTML-Help Text Links will be displayed and are clickable
static JEditorPane createHtmlHelpTextArea(String html, Color background)
          Creates a Html EditorPane that holds a HTML-Help Text Links will be displayed and are clickable
static JEditorPane createHtmlHelpTextArea(String html, HyperlinkListener listener)
          Creates a Html EditorPane that holds a HTML-Help Text.
static JEditorPane createHtmlHelpTextArea(String html, HyperlinkListener listener, Color background)
          Creates a Html EditorPane that holds a HTML-Help Text.
static JButton createToolBarButton(String text, 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 Window getBestDialogParent(Component parent)
          Gets the best dialog parent for a new JDialog.
static int getCharsWidth(Font font, char[] chars, int offset, int length)
          Gets the width of the specified char array.
static Window getLastModalChildOf(Window parent)
          Gets the last visible modal child dialog of the specified window.
static int getStringWidth(Font font, String str)
          Gets the width of the specified String.
static void moveSelectedItems(JList list, int nrRows)
          Move selected Items in the JList
static void moveSelectedItems(JList list, int row, boolean sort)
          Move selected Items in the JList
static Object[] moveSelectedItems(JList fromList, JList toList)
          Moves Selected Items from one List to another
static Object[] moveSelectedItems(JList fromList, 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 Icon scaleIcon(Icon icon, int newWidth)
          Scale Icons to a specific width.
static Icon scaleIcon(Icon icon, int x, int y)
          Scales Icons to a specific size
static BufferedImage scaleIconToBufferedImage(BufferedImage img, int x, int y)
          Scales an image to a specific size and returns an BufferedImage
static BufferedImage scaleIconToBufferedImage(BufferedImage img, int x, int y, int type)
          Scales an image to a specific size and returns an BufferedImage
static void setSize(JDialog dialog, int width, int height)
          set the size of a dialog, but never sizes it smaller than the preferred size
 
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 Border DIALOG_BORDER
The border to use for dialogs.


ZERO_INSETS

public static final Insets ZERO_INSETS
Constructor Detail

UiUtilities

public UiUtilities()
Method Detail

centerAndShow

public static void centerAndShow(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 JDialog createDialog(Component parent,
                                   boolean modal)
Der JDialog hat einen Riesennachteil: er hat zwei verschiedenen Konstrukturen: einer f�r einen Frame als Besitzer und einer f�r einen Dialog als Besitzer. Wenn man nun das �berliegende Fenster gar nicht kennt, dann hat man ein Problem (Z.B. Wenn man einen Button schreibt, der manchmal eine Fehlermeldung zeigt). Bisher habe ich einfach den Component-Pfad bis zum obersten Frame verfolgt (@link UiToolkit#getFrameFor(Component)). Das ganze wird dann zum Problem, wenn man in einem modalen Dialog einen nicht-modalen Dialog zeigt. Denn dann kann man den nicht-modalen Dialog n�mlich erst dann wieder bedienen, wenn der modale zu ist.

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 Window getBestDialogParent(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 Window getLastModalChildOf(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(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 JButton createToolBarButton(String text,
                                          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(Font font,
                                 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(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 JTextArea createHelpTextArea(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 JEditorPane createHtmlHelpTextArea(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 JEditorPane createHtmlHelpTextArea(String html,
                                                 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 JEditorPane createHtmlHelpTextArea(String html,
                                                 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 JEditorPane createHtmlHelpTextArea(String html,
                                                 HyperlinkListener listener,
                                                 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

moveSelectedItems

public static Object[] moveSelectedItems(JList fromList,
                                         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 Object[] moveSelectedItems(JList fromList,
                                         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(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(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 Icon scaleIcon(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 Icon scaleIcon(Icon icon,
                             int x,
                             int y)
Scales Icons to a specific size

Parameters:
icon - Icon that should be scaled
x - new X-Value
y - new Y-Value
Returns:
Scaled Icon

scaleIconToBufferedImage

public static BufferedImage scaleIconToBufferedImage(BufferedImage img,
                                                     int x,
                                                     int y)
Scales an image to a specific size and returns an BufferedImage

Parameters:
img - Scale this IMage
x - new X-Value
y - new Y-Value
Returns:
Scaled BufferedImage
Since:
2.5

scaleIconToBufferedImage

public static BufferedImage scaleIconToBufferedImage(BufferedImage img,
                                                     int x,
                                                     int y,
                                                     int type)
Scales an image to a specific size and returns an BufferedImage

Parameters:
img - Scale this IMage
x - new X-Value
y - new Y-Value
type - The type of the image.
Returns:
Scaled BufferedImage
Since:
2.7

createChannelIcon

public static ImageIcon createChannelIcon(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

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(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

TV-Browser 2.7.5 API

TV-Browser 2.7.5, Copyright (C) 04-2003 Martin Oberhauser (martin@tvbrowser.org)