net.sourceforge.jsxe.gui
Class GUIUtilities

java.lang.Object
  extended bynet.sourceforge.jsxe.gui.GUIUtilities

public class GUIUtilities
extends Object

Various GUI functions.

The most frequently used members of this class are:

Version:
$Id$
Author:
Slava Pestov, Ian Lewis (IanLewis@member.fsf.org)

Method Summary
static void adjustForScreenBounds(Rectangle desired)
          Gives a rectangle the specified bounds, ensuring it is within the screen bounds.
static int confirm(Component comp, String name, Object[] args, int buttons, int type)
          Displays a confirm dialog box and returns the button pushed by the user.
static JComponent createMultilineLabel(String str)
          Creates a component that displays a multiple line message.
static void error(Component comp, String name, Object[] args)
          Displays an error dialog box.
static String getColorHexString(Color c)
          Converts a color object to its hex value.
static Component getComponentParent(Component comp, Class clazz)
          Finds a parent of the specified component.
static JDialog getParentDialog(Component c)
          Traverses the given component's parent tree looking for an instance of JDialog, and return it.
static TabbedView getView(Component comp)
          Finds the view parent of the specified component.
static void hideSplashScreen()
          Ensures that the splash screen is not visible.
static String input(Component comp, String name, Object def)
          Displays an input dialog box and returns any text the user entered.
static String input(Component comp, String name, Object[] args, Object def)
          Displays an input dialog box and returns any text the user entered.
static String inputProperty(Component comp, String name, Object[] args, String def)
          Displays an input dialog box and returns any text the user entered.
static String inputProperty(Component comp, String name, String def)
          Displays an input dialog box and returns any text the user entered.
static boolean isAncestorOf(Component comp1, Component comp2)
          Returns if the first component is an ancestor of the second by traversing up the component hierarchy.
static boolean isMiddleButton(int modifiers)
           
static boolean isPopupTrigger(MouseEvent evt)
          Returns if the specified event is the popup trigger event.
static boolean isRightButton(int modifiers)
           
static void loadGeometry(Window win, String name)
          Loads a windows's geometry from the properties.
static Icon loadIcon(String iconName)
          Loads an icon.
static void message(Component comp, String name, Object[] args)
          Displays a dialog box.
static Color parseColor(String name)
          Converts a color name to a color object.
static Color parseColor(String name, Color defaultColor)
           
static void requestFocus(Window win, Component comp)
          Focuses on the specified component as soon as the window becomes active.
static void saveGeometry(Window win, String name)
          Saves a window's geometry to the properties.
static void setIconPath(String iconPath)
          Sets the path where jsXe looks for icons.
static void showPopupMenu(JPopupMenu popup, Component comp, int x, int y)
          Shows the specified popup menu, ensuring it is displayed within the bounds of the screen.
static void showPopupMenu(JPopupMenu popup, Component comp, int x, int y, boolean point)
          Shows the specified popup menu, ensuring it is displayed within the bounds of the screen.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setIconPath

public static void setIconPath(String iconPath)
Sets the path where jsXe looks for icons.


loadIcon

public static Icon loadIcon(String iconName)
Loads an icon.

Parameters:
iconName - The icon name

message

public static void message(Component comp,
                           String name,
                           Object[] args)
Displays a dialog box. The title of the dialog is fetched from the name.title property. The message is fetched from the name.message property. The message is formatted by the property manager with args as positional parameters.

Parameters:
comp - The component to display the dialog for
name - The name of the dialog
args - Positional parameters to be substituted into the message text

error

public static void error(Component comp,
                         String name,
                         Object[] args)
Displays an error dialog box. The title of the dialog is fetched from the name.title property. The message is fetched from the name.message property. The message is formatted by the property manager with args as positional parameters.

Parameters:
comp - The component to display the dialog for
name - The name of the dialog
args - Positional parameters to be substituted into the message text

input

public static String input(Component comp,
                           String name,
                           Object def)
Displays an input dialog box and returns any text the user entered. The title of the dialog is fetched from the name.title property. The message is fetched from the name.message property.

Parameters:
comp - The component to display the dialog for
name - The name of the dialog
def - The text to display by default in the input field

inputProperty

public static String inputProperty(Component comp,
                                   String name,
                                   String def)
Displays an input dialog box and returns any text the user entered. The title of the dialog is fetched from the name.title property. The message is fetched from the name.message property.

Parameters:
comp - The component to display the dialog for
name - The name of the dialog
def - The property whose text to display in the input field

input

public static String input(Component comp,
                           String name,
                           Object[] args,
                           Object def)
Displays an input dialog box and returns any text the user entered. The title of the dialog is fetched from the name.title property. The message is fetched from the name.message property.

Parameters:
comp - The component to display the dialog for
name - The name of the dialog
def - The text to display by default in the input field
args - Positional parameters to be substituted into the message text

inputProperty

public static String inputProperty(Component comp,
                                   String name,
                                   Object[] args,
                                   String def)
Displays an input dialog box and returns any text the user entered. The title of the dialog is fetched from the name.title property. The message is fetched from the name.message property.

Parameters:
comp - The component to display the dialog for
name - The name of the dialog
args - Positional parameters to be substituted into the message text
def - The property whose text to display in the input field

confirm

public static int confirm(Component comp,
                          String name,
                          Object[] args,
                          int buttons,
                          int type)
Displays a confirm dialog box and returns the button pushed by the user. The title of the dialog is fetched from the name.title property. The message is fetched from the name.message property.

Parameters:
comp - The component to display the dialog for
name - The name of the dialog
args - Positional parameters to be substituted into the message text
buttons - The buttons to display - for example, JOptionPane.YES_NO_CANCEL_OPTION
type - The dialog type - for example, JOptionPane.WARNING_MESSAGE

parseColor

public static Color parseColor(String name)
Converts a color name to a color object. The name must either be a known string, such as `red', `green', etc (complete list is in the java.awt.Color class) or a hex color value prefixed with `#', for example `#ff0088'.

Parameters:
name - The color name

parseColor

public static Color parseColor(String name,
                               Color defaultColor)

getColorHexString

public static String getColorHexString(Color c)
Converts a color object to its hex value. The hex value prefixed is with `#', for example `#ff0088'.

Parameters:
c - The color object

loadGeometry

public static void loadGeometry(Window win,
                                String name)
Loads a windows's geometry from the properties. The geometry is loaded from the name.x, name.y, name.width and name.height properties.

Parameters:
win - The window
name - The window name

adjustForScreenBounds

public static void adjustForScreenBounds(Rectangle desired)
Gives a rectangle the specified bounds, ensuring it is within the screen bounds.


saveGeometry

public static void saveGeometry(Window win,
                                String name)
Saves a window's geometry to the properties. The geometry is saved to the name.x, name.y, name.width and name.height properties.

Parameters:
win - The window
name - The window name

hideSplashScreen

public static void hideSplashScreen()
Ensures that the splash screen is not visible. This should be called before displaying any dialog boxes or windows at startup.


createMultilineLabel

public static JComponent createMultilineLabel(String str)
Creates a component that displays a multiple line message. This is implemented by assembling a number of JLabels in a JPanel.

Parameters:
str - The string, with lines delimited by newline (\n) characters.

requestFocus

public static void requestFocus(Window win,
                                Component comp)
Focuses on the specified component as soon as the window becomes active.

Parameters:
win - The window
comp - The component

isPopupTrigger

public static boolean isPopupTrigger(MouseEvent evt)
Returns if the specified event is the popup trigger event. This implements precisely defined behavior, as opposed to MouseEvent.isPopupTrigger().

Parameters:
evt - The event

isMiddleButton

public static boolean isMiddleButton(int modifiers)
Parameters:
modifiers - The modifiers flag from a mouse event

isRightButton

public static boolean isRightButton(int modifiers)
Parameters:
modifiers - The modifiers flag from a mouse event

showPopupMenu

public static void showPopupMenu(JPopupMenu popup,
                                 Component comp,
                                 int x,
                                 int y)
Shows the specified popup menu, ensuring it is displayed within the bounds of the screen.

Parameters:
popup - The popup menu
comp - The component to show it for
x - The x co-ordinate
y - The y co-ordinate

showPopupMenu

public static void showPopupMenu(JPopupMenu popup,
                                 Component comp,
                                 int x,
                                 int y,
                                 boolean point)
Shows the specified popup menu, ensuring it is displayed within the bounds of the screen.

Parameters:
popup - The popup menu
comp - The component to show it for
x - The x co-ordinate
y - The y co-ordinate
point - If true, then the popup originates from a single point; otherwise it will originate from the component itself. This affects positioning in the case where the popup does not fit onscreen.

isAncestorOf

public static boolean isAncestorOf(Component comp1,
                                   Component comp2)
Returns if the first component is an ancestor of the second by traversing up the component hierarchy.

Parameters:
comp1 - The ancestor
comp2 - The component to check

getParentDialog

public static JDialog getParentDialog(Component c)
Traverses the given component's parent tree looking for an instance of JDialog, and return it. If not found, return null.

Parameters:
c - The component

getComponentParent

public static Component getComponentParent(Component comp,
                                           Class clazz)
Finds a parent of the specified component.

Parameters:
comp - The component
clazz - Looks for a parent with this class (exact match, not derived).
Since:
jsXe 0.5 pre1

getView

public static TabbedView getView(Component comp)
Finds the view parent of the specified component.