org.gjt.sp.jedit
Class GUIUtilities

java.lang.Object
  extended byorg.gjt.sp.jedit.GUIUtilities

public class GUIUtilities
extends Object

Various GUI functions.

The most frequently used members of this class are:

Version:
$Id: GUIUtilities.java,v 1.81 2004/06/01 20:01:40 spestov Exp $
Author:
Slava Pestov

Field Summary
static Icon DIRTY_BUFFER_ICON
          Deprecated. Use GUIUtilities.loadIcon("dirty.gif"); instead.
static Icon NEW_BUFFER_ICON
          Deprecated. Use GUIUtilities.loadIcon("new.gif"); instead.
static Icon NORMAL_BUFFER_ICON
          Deprecated. Use GUIUtilities.loadIcon("normal.gif"); instead.
static Icon READ_ONLY_BUFFER_ICON
          Deprecated. Use GUIUtilities.loadIcon("readonly.gif"); instead.
static Icon WINDOW_ICON
          Deprecated. Use GUIUtilities.loadIcon("jedit-icon.gif"); instead.
 
Method Summary
static void adjustForScreenBounds(Rectangle desired)
          Gives a rectangle the specified bounds, ensuring it is within the screen bounds.
static void centerOnScreen(Window win)
          Centers the given window on the screen.
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 Image getEditorIcon()
          Returns the default editor window image.
static int getExtendedState(Frame frame)
          On Java 1.4, calls Frame.getExtendedState().
static JDialog getParentDialog(Component c)
          Traverses the given component's parent tree looking for an instance of JDialog, and return it.
static Image getPluginIcon()
          Returns the default plugin window image.
static String getStyleString(SyntaxStyle style)
          Converts a style into it's string representation.
static View 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 JMenu loadMenu(ActionContext context, String name)
          Creates a menu.
static JMenu loadMenu(String name)
          Creates a menu.
static JMenuBar loadMenuBar(ActionContext context, String name)
          Creates a menubar.
static JMenuBar loadMenuBar(String name)
          Creates a menubar.
static JMenuItem loadMenuItem(ActionContext context, String name, boolean setMnemonic)
          Creates a menu item.
static JMenuItem loadMenuItem(String name)
          Creates a menu item.
static JMenuItem loadMenuItem(String name, boolean setMnemonic)
          Creates a menu item.
static JPopupMenu loadPopupMenu(ActionContext context, String name)
          Creates a popup menu.
static JPopupMenu loadPopupMenu(String name)
          Creates a popup menu.
static SyntaxStyle[] loadStyles(String family, int size)
          Loads the syntax styles from the properties, giving them the specified base font family and size.
static SyntaxStyle[] loadStyles(String family, int size, boolean color)
          Loads the syntax styles from the properties, giving them the specified base font family and size.
static Box loadToolBar(ActionContext context, String name)
          Creates a toolbar.
static Box loadToolBar(String name)
          Creates a toolbar.
static EnhancedButton loadToolButton(ActionContext context, String name)
          Loads a tool bar button.
static EnhancedButton loadToolButton(String name)
          Loads a tool bar button.
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 SyntaxStyle parseStyle(String str, String family, int size)
          Converts a style string to a style object.
static SyntaxStyle parseStyle(String str, String family, int size, boolean color)
          Converts a style string to a style object.
static String prettifyMenuLabel(String label)
          `Prettifies' a menu item label by removing the `$' sign.
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 setExtendedState(Frame frame, int extState)
          On Java 1.4, calls Frame.setExtendedState().
static void setIconPath(String iconPath)
          Sets the path where jEdit 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.
static String[] showVFSFileDialog(View view, String path, int type, boolean multipleSelection)
          Displays a VFS file selection dialog box.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEW_BUFFER_ICON

public static Icon NEW_BUFFER_ICON
Deprecated. Use GUIUtilities.loadIcon("new.gif"); instead.


DIRTY_BUFFER_ICON

public static Icon DIRTY_BUFFER_ICON
Deprecated. Use GUIUtilities.loadIcon("dirty.gif"); instead.


READ_ONLY_BUFFER_ICON

public static Icon READ_ONLY_BUFFER_ICON
Deprecated. Use GUIUtilities.loadIcon("readonly.gif"); instead.


NORMAL_BUFFER_ICON

public static Icon NORMAL_BUFFER_ICON
Deprecated. Use GUIUtilities.loadIcon("normal.gif"); instead.


WINDOW_ICON

public static Icon WINDOW_ICON
Deprecated. Use GUIUtilities.loadIcon("jedit-icon.gif"); instead.

Method Detail

setIconPath

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

Since:
jEdit 4.2pre5

loadIcon

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

Parameters:
iconName - The icon name
Since:
jEdit 2.6pre7

getEditorIcon

public static Image getEditorIcon()
Returns the default editor window image.


getPluginIcon

public static Image getPluginIcon()
Returns the default plugin window image.


loadMenuBar

public static JMenuBar loadMenuBar(String name)
Creates a menubar. Plugins should not need to call this method.

Parameters:
name - The menu bar name
Since:
jEdit 3.2pre5

loadMenuBar

public static JMenuBar loadMenuBar(ActionContext context,
                                   String name)
Creates a menubar. Plugins should not need to call this method.

Parameters:
context - An action context
name - The menu bar name
Since:
jEdit 4.2pre1

loadMenu

public static JMenu loadMenu(String name)
Creates a menu. The menu label is set from the name.label property. The menu contents is taken from the name property, which is a whitespace separated list of action names. An action name of - inserts a separator in the menu.

Parameters:
name - The menu name
Since:
jEdit 2.6pre2
See Also:
loadMenuItem(String)

loadMenu

public static JMenu loadMenu(ActionContext context,
                             String name)
Creates a menu. The menu label is set from the name.label property. The menu contents is taken from the name property, which is a whitespace separated list of action names. An action name of - inserts a separator in the menu.

Parameters:
context - An action context; either jEdit.getActionContext() or VFSBrowser.getActionContext().
name - The menu name
Since:
jEdit 4.2pre1
See Also:
loadMenuItem(String)

loadPopupMenu

public static JPopupMenu loadPopupMenu(String name)
Creates a popup menu.

Parameters:
name - The menu name
Since:
jEdit 2.6pre2

loadPopupMenu

public static JPopupMenu loadPopupMenu(ActionContext context,
                                       String name)
Creates a popup menu.

Parameters:
context - An action context; either jEdit.getActionContext() or VFSBrowser.getActionContext().
name - The menu name
Since:
jEdit 4.2pre1

loadMenuItem

public static JMenuItem loadMenuItem(String name)
Creates a menu item. The menu item is bound to the action named by name with label taken from the return value of the EditAction.getLabel() method.

Parameters:
name - The menu item name
Since:
jEdit 2.6pre1
See Also:
loadMenu(String)

loadMenuItem

public static JMenuItem loadMenuItem(String name,
                                     boolean setMnemonic)
Creates a menu item.

Parameters:
name - The menu item name
setMnemonic - True if the menu item should have a mnemonic
Since:
jEdit 3.1pre1

loadMenuItem

public static JMenuItem loadMenuItem(ActionContext context,
                                     String name,
                                     boolean setMnemonic)
Creates a menu item.

Parameters:
context - An action context; either jEdit.getActionContext() or VFSBrowser.getActionContext().
name - The menu item name
setMnemonic - True if the menu item should have a mnemonic
Since:
jEdit 4.2pre1

loadToolBar

public static Box loadToolBar(String name)
Creates a toolbar.

Parameters:
name - The toolbar name
Since:
jEdit 4.2pre2

loadToolBar

public static Box loadToolBar(ActionContext context,
                              String name)
Creates a toolbar.

Parameters:
context - An action context; either jEdit.getActionContext() or VFSBrowser.getActionContext().
name - The toolbar name
Since:
jEdit 4.2pre2

loadToolButton

public static EnhancedButton loadToolButton(String name)
Loads a tool bar button. The tooltip is constructed from the name.label and name.shortcut properties and the icon is loaded from the resource named '/org/gjt/sp/jedit/icons/' suffixed with the value of the name.icon property.

Parameters:
name - The name of the button

loadToolButton

public static EnhancedButton loadToolButton(ActionContext context,
                                            String name)
Loads a tool bar button. The tooltip is constructed from the name.label and name.shortcut properties and the icon is loaded from the resource named '/org/gjt/sp/jedit/icons/' suffixed with the value of the name.icon property.

Parameters:
context - An action context; either jEdit.getActionContext() or VFSBrowser.getActionContext().
name - The name of the button
Since:
jEdit 4.2pre1

prettifyMenuLabel

public static String prettifyMenuLabel(String label)
`Prettifies' a menu item label by removing the `$' sign. This can be used to process the contents of an action.label property.


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
Since:
jEdit 3.1pre3

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
Since:
jEdit 3.1pre3

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
Since:
jEdit 3.1pre3

showVFSFileDialog

public static String[] showVFSFileDialog(View view,
                                         String path,
                                         int type,
                                         boolean multipleSelection)
Displays a VFS file selection dialog box.

Parameters:
view - The view, should be non-null
path - The initial directory to display. May be null
type - The dialog type. One of VFSBrowser.OPEN_DIALOG, VFSBrowser.SAVE_DIALOG, or VFSBrowser.CHOOSE_DIRECTORY_DIALOG.
multipleSelection - True if multiple selection should be allowed
Returns:
The selected file(s)
Since:
jEdit 2.6pre2

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

parseStyle

public static SyntaxStyle parseStyle(String str,
                                     String family,
                                     int size)
                              throws IllegalArgumentException
Converts a style string to a style object.

Parameters:
str - The style string
family - Style strings only specify font style, not font family
size - Style strings only specify font style, not font family
Throws:
IllegalArgumentException - if the style is invalid
Since:
jEdit 3.2pre6

parseStyle

public static SyntaxStyle parseStyle(String str,
                                     String family,
                                     int size,
                                     boolean color)
                              throws IllegalArgumentException
Converts a style string to a style object.

Parameters:
str - The style string
family - Style strings only specify font style, not font family
size - Style strings only specify font style, not font family
color - If false, the styles will be monochrome
Throws:
IllegalArgumentException - if the style is invalid
Since:
jEdit 4.0pre4

getStyleString

public static String getStyleString(SyntaxStyle style)
Converts a style into it's string representation.

Parameters:
style - The style

loadStyles

public static SyntaxStyle[] loadStyles(String family,
                                       int size)
Loads the syntax styles from the properties, giving them the specified base font family and size.

Parameters:
family - The font family
size - The font size
Since:
jEdit 3.2pre6

loadStyles

public static SyntaxStyle[] loadStyles(String family,
                                       int size,
                                       boolean color)
Loads the syntax styles from the properties, giving them the specified base font family and size.

Parameters:
family - The font family
size - The font size
color - If false, the styles will be monochrome
Since:
jEdit 4.0pre4

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.

Since:
jEdit 4.2pre3

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

getExtendedState

public static int getExtendedState(Frame frame)
On Java 1.4, calls Frame.getExtendedState(). On Java 1.3, returns 0.

Since:
jEdit 4.2pre1

setExtendedState

public static void setExtendedState(Frame frame,
                                    int extState)
On Java 1.4, calls Frame.setExtendedState(). On Java 1.3, does nothing.

Since:
jEdit 4.2pre1

centerOnScreen

public static void centerOnScreen(Window win)
Centers the given window on the screen. This method is needed because JDK 1.3 does not have a JWindow.setLocationRelativeTo() method.

Since:
jEdit 4.2pre3

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.
Since:
jEdit 4.1pre3

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
Since:
jEdit 3.2pre8

isMiddleButton

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

isRightButton

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

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
Since:
jEdit 4.0pre1

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.
Since:
jEdit 4.1pre1

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
Since:
jEdit 4.1pre5

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:
jEdit 4.2pre1

getView

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

Since:
jEdit 4.0pre2