one.gui
Class GuiUtilities

java.lang.Object
  |
  +--one.gui.GuiUtilities

public final class GuiUtilities
extends Object

Implementation of utility methods for creating and managing user interfaces.

Version:
$Revision: 1.7 $

Field Summary
static String ACTION_CANCEL
          The cancel action command.
static String ACTION_OK
          The OK action command.
static int ENTRY_COMBO_BOX
          The entry code for a combo box.
static int ENTRY_PASSWORD_FIELD
          The entry code for a password field.
static int ENTRY_TEXT_FIELD
          The entry code for a text field.
static Icon FLAG_ICON
          The flag icon.
 
Method Summary
static void addUserPopup(Component c, Environment env)
          Add a user popup to the specified component.
static void beep()
          Emit an audible beep.
static JLabel createLocationSource(Guid id)
          Create a label that serves as the drag and drop source for location changes of the environment with the specified ID.
static JComponent[] createSimpleGrid(String[] labels, int[] types, int columns)
          Create a simple grid.
static void layout(JDialog dialog, Component content, ActionListener okListener, ActionListener cancelListener)
          Create the layout for the specified dialog.
static void place(Component component, int x, int y)
          Place the specified component at the specified location on the default screen.
static void turnIntoEnvironmentSource(Component c, Guid id)
          Turn the specified component into a drag and drop source for environment selections for the environment with the specified ID.
static void turnIntoEnvironmentTarget(JLabel label, EventHandler handler)
          Turn the specified label into a drag and drop target for environment selections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACTION_OK

public static final String ACTION_OK
The OK action command.

ACTION_CANCEL

public static final String ACTION_CANCEL
The cancel action command.

FLAG_ICON

public static final Icon FLAG_ICON
The flag icon. The flag icon shows a little flag within a box. Its background is transparent.

ENTRY_TEXT_FIELD

public static final int ENTRY_TEXT_FIELD
The entry code for a text field.

ENTRY_PASSWORD_FIELD

public static final int ENTRY_PASSWORD_FIELD
The entry code for a password field.

ENTRY_COMBO_BOX

public static final int ENTRY_COMBO_BOX
The entry code for a combo box.
Method Detail

createLocationSource

public static JLabel createLocationSource(Guid id)
Create a label that serves as the drag and drop source for location changes of the environment with the specified ID. The returned label displays the FLAG_ICON and transfers environment selections for the specified environment.
Parameters:
id - The environment ID.
Returns:
The corresponding label.
Throws:
NullPointerException - Signals that id is null.
See Also:
addUserPopup(java.awt.Component, one.world.core.Environment)

turnIntoEnvironmentSource

public static void turnIntoEnvironmentSource(Component c,
                                             Guid id)
Turn the specified component into a drag and drop source for environment selections for the environment with the specified ID.
Parameters:
c - The component.
id - The environment ID.
Throws:
NullPointerException - Signals that c or id is null.
See Also:
EnvironmentSelection

turnIntoEnvironmentTarget

public static void turnIntoEnvironmentTarget(JLabel label,
                                             EventHandler handler)
Turn the specified label into a drag and drop target for environment selections. Upon accepting an environment selection, the label sends an environment drop event to the specified event handler.

Note that this method adds a border to the specified label, which must not be changed.

Parameters:
label - The label.
handler - The environment drop event handler.
Throws:
NullPointerException - Signals that label or handler is null.
See Also:
turnIntoEnvironmentSource(java.awt.Component, one.util.Guid), EnvironmentSelection, EnvironmentDropEvent

addUserPopup

public static void addUserPopup(Component c,
                                Environment env)
Add a user popup to the specified component. This method adds a popup menu to the specified component, which displays the name of the user the application is running for. To determine the current user, the popup menu dynamically interprets the name of the parent environment of the specified environment as the user's local root environment.

By user interface convention, this method should be invoked on the label returned by {link #createLocationSource} before adding the label to the application's UI.

Parameters:
c - The component to add the user popup to.
env - The environment in which the component's application is running in.
Throws:
NullPointerException - Signals that env is null.

createSimpleGrid

public static JComponent[] createSimpleGrid(String[] labels,
                                            int[] types,
                                            int columns)
Create a simple grid. A simple grid for the purposes of this method is a grid-like panel with essentially two columns: The first column contains labels, and the second column contains entries with either a text field, password field, or combo box.

The layout created by this method adds some filler space between the labels and the entries. It aligns the first column to the left. Entries in the second column are stretched across the entire column. If columns is positive, test fields and password fields are set to the specified number of character columns.

labels and types must be valid arrays of the same length. Each entry of types must be ENTRY_TEXT_FIELD, ENTRY_PASSWORD_FIELD, or ENTRY_COMBO_BOX.

Parameters:
labels - The labels.
types - The entry types.
columns - The positive minimum number of character columns for text and password fields, or a non-positive number if text and password fields should be arbitrarily stretched.
Returns:
An array of components; the first being the overall panel, followed in order by the text fields, password fields, and combo boxes as specified by types.

layout

public static void layout(JDialog dialog,
                          Component content,
                          ActionListener okListener,
                          ActionListener cancelListener)
Create the layout for the specified dialog. This method adds the specified content to the dialog and adds a row of two additional buttons underneath the content. The first button is the "OK" button. It is the default button for the dialog and notifies the specified OK listener with the ACTION_OK command. The second button is the "Cancel" button. It notifies the specified cancel listener with the ACTION_CANCEL command.
Parameters:
dialog - The dialog.
content - The main dialog contents.
okListener - The action listener for the OK button.
cancelListener - The action listener for the cancel button.

place

public static void place(Component component,
                         int x,
                         int y)
Place the specified component at the specified location on the default screen. This method adjusts the location to fit as much as possible of the component onto the screen.
Parameters:
component - The component to place.
x - The x coordinate of the location.
y - The y coordinate of the location.

beep

public static void beep()
Emit an audible beep.


(C) Copyright 2001 UW CSE