Package org.gjt.sp.jedit
Class GUIUtilities
- java.lang.Object
-
- org.gjt.sp.jedit.GUIUtilities
-
public class GUIUtilities extends java.lang.ObjectVarious GUI utility functions related to icons, menus, toolbars, keyboard shortcuts, etc. The most frequently used members of this class are:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGUIUtilities.UnixWorkaround
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddSizeSaver(java.awt.Frame frame, java.awt.Container parent, java.lang.String name)Adds a SizeSaver to the specified Frame.static voidaddSizeSaver(java.awt.Frame frame, java.lang.String name)Adds a SizeSaver to the specified Frame.static voidapplyTextAreaColors(java.awt.Container win)experimental - applies the text area colors on a Component (such as a dockable window) and its children.static intconfirm(java.awt.Component comp, java.lang.String name, java.lang.Object[] args, int buttons, int type)Displays a confirm dialog box and returns the button pushed by the user.static javax.swing.JComponentcreateMultilineLabel(java.lang.String str)Creates a component that displays a multiple line message.static voiderror(java.awt.Component comp, java.lang.String name, java.lang.Object[] args)Displays an error dialog box.static java.awt.ComponentgetComponentParent(java.awt.Component comp, java.lang.Class clazz)Finds a parent of the specified component.static java.awt.ImagegetEditorIcon()static java.lang.StringgetPlatformShortcutLabel(java.lang.String label)Translates a shortcut description string (e.g.static java.awt.ImagegetPluginIcon()static java.util.List<javax.swing.JMenuItem>getServiceContextMenuItems(JEditTextArea textArea, java.awt.event.MouseEvent evt)static java.lang.StringgetShortcutLabel(java.lang.String action, java.lang.Boolean platform)Returns a label string to show users what shortcut are assigned to the action.static java.lang.StringgetStyleString(SyntaxStyle style)Converts a style into it's string representation.static ViewgetView(java.awt.Component comp)Finds the view parent of the specified component.static voidhideSplashScreen()Ensures that the splash screen is not visible.static java.lang.Stringinput(java.awt.Component comp, java.lang.String name, java.lang.Object def)Displays an input dialog box and returns any text the user entered.static java.lang.Stringinput(java.awt.Component comp, java.lang.String name, java.lang.Object[] args, java.lang.Object def)Displays an input dialog box and returns any text the user entered.static java.lang.StringinputProperty(java.awt.Component comp, java.lang.String name, java.lang.Object[] args, java.lang.String def)Displays an input dialog box and returns any text the user entered.static java.lang.StringinputProperty(java.awt.Component comp, java.lang.String name, java.lang.String def)Displays an input dialog box and returns any text the user entered.static intlistConfirm(java.awt.Component comp, java.lang.String name, java.lang.String[] args, java.lang.Object[] listModel)Displays a confirm dialog box and returns the button pushed by the user.static intlistConfirm(java.awt.Component comp, java.lang.String name, java.lang.String[] args, java.lang.Object[] listModel, java.util.List selectedItems)Displays a confirm dialog box and returns the button pushed by the user.static voidloadGeometry(java.awt.Window win, java.awt.Container parent, java.lang.String name)Loads a windows's geometry from the properties.static voidloadGeometry(java.awt.Window win, java.lang.String name)Loads a windows's geometry from the properties.static javax.swing.IconloadIcon(java.lang.String iconName)Loads an icon.static javax.swing.JMenuloadMenu(java.lang.String name)Creates a menu.static javax.swing.JMenuloadMenu(ActionContext context, java.lang.String name)Creates a menu.static javax.swing.JMenuBarloadMenuBar(java.lang.String name)Creates a menubar.static javax.swing.JMenuBarloadMenuBar(ActionContext context, java.lang.String name)Creates a menubar.static javax.swing.JMenuItemloadMenuItem(java.lang.String name)Creates a menu item.static javax.swing.JMenuItemloadMenuItem(java.lang.String name, boolean setMnemonic)Creates a menu item.static javax.swing.JMenuItemloadMenuItem(ActionContext context, java.lang.String name, boolean setMnemonic)Creates a menu item.static javax.swing.JMenuItemloadMenuItem(EditAction editAction, boolean setMnemonic)static javax.swing.JPopupMenuloadPopupMenu(java.lang.String name)static javax.swing.JPopupMenuloadPopupMenu(java.lang.String name, JEditTextArea textArea, java.awt.event.MouseEvent evt)Creates a popup menu.static javax.swing.JPopupMenuloadPopupMenu(ActionContext context, java.lang.String name)Creates a popup menu.static javax.swing.JPopupMenuloadPopupMenu(ActionContext context, java.lang.String name, JEditTextArea textArea, java.awt.event.MouseEvent evt)Creates a popup menu.static java.awt.ContainerloadToolBar(java.lang.String name)static java.awt.ContainerloadToolBar(ActionContext context, java.lang.String name)Creates a toolbar.static EnhancedButtonloadToolButton(java.lang.String name)Loads a tool bar button.static EnhancedButtonloadToolButton(ActionContext context, java.lang.String name)Loads a tool bar button.static java.awt.FontmenuAcceleratorFont()Menu accelerator font according to L&F defaults, with workarounds.static voidmessage(java.awt.Component comp, java.lang.String name, java.lang.Object[] args)Displays a dialog box.static intoption(java.awt.Component comp, java.lang.String name, java.lang.Object[] args, int type, java.lang.Object[] options, java.lang.Object initialValue)Displays an option dialog dialog box and returns the button pushed by the user.static voidsaveGeometry(java.awt.Window win, java.awt.Container parent, java.lang.String name)Saves a window's geometry to the properties.static voidsaveGeometry(java.awt.Window win, java.lang.String name)Saves a window's geometry to the properties.static voidsetIconPath(java.lang.String iconPath)Sets the path where jEdit looks for icons.static java.lang.String[]showVFSFileDialog(java.awt.Dialog parent, View view, java.lang.String path, int type, boolean multipleSelection)Displays a VFS file selection dialog box.static java.lang.String[]showVFSFileDialog(java.awt.Frame parent, View view, java.lang.String path, int type, boolean multipleSelection)Displays a VFS file selection dialog box.static java.lang.String[]showVFSFileDialog(View view, java.lang.String path, int type, boolean multipleSelection)Displays a VFS file selection dialog box.
-
-
-
Method Detail
-
setIconPath
public static void setIconPath(java.lang.String iconPath)
Sets the path where jEdit looks for icons.- Parameters:
iconPath- the icon path- Since:
- jEdit 4.2pre5
-
loadIcon
public static javax.swing.Icon loadIcon(java.lang.String iconName)
Loads an icon.- Parameters:
iconName- The icon name- Returns:
- the icon
- Since:
- jEdit 2.6pre7
-
getEditorIcon
public static java.awt.Image getEditorIcon()
- Returns:
- the default editor window image.
-
getPluginIcon
public static java.awt.Image getPluginIcon()
- Returns:
- the default plugin window image.
-
loadMenuBar
public static javax.swing.JMenuBar loadMenuBar(java.lang.String name)
Creates a menubar. Plugins should not need to call this method.- Parameters:
name- The menu bar name- Returns:
- the menu bar
- Since:
- jEdit 3.2pre5
-
loadMenuBar
public static javax.swing.JMenuBar loadMenuBar(ActionContext context, java.lang.String name)
Creates a menubar. Plugins should not need to call this method.- Parameters:
context- An action contextname- The menu bar name- Returns:
- the menu bar
- Since:
- jEdit 4.2pre1
-
loadMenu
public static javax.swing.JMenu loadMenu(java.lang.String name)
Creates a menu. The menu label is set from thename.labelproperty. The menu contents is taken from thenameproperty, which is a whitespace separated list of action names. An action name of-inserts a separator in the menu.- Parameters:
name- The menu name- Returns:
- a menu
- Since:
- jEdit 2.6pre2
- See Also:
loadMenuItem(String)
-
loadMenu
public static javax.swing.JMenu loadMenu(ActionContext context, java.lang.String name)
Creates a menu. The menu label is set from thename.labelproperty. The menu contents is taken from thenameproperty, which is a whitespace separated list of action names. An action name of-inserts a separator in the menu.- Parameters:
context- An action context; eitherjEdit.getActionContext()orVFSBrowser.getActionContext().name- The menu name- Returns:
- a menu
- Since:
- jEdit 4.2pre1
- See Also:
loadMenuItem(String)
-
loadPopupMenu
public static javax.swing.JPopupMenu loadPopupMenu(java.lang.String name, JEditTextArea textArea, java.awt.event.MouseEvent evt)Creates a popup menu.- Parameters:
name- The menu nameevt- mouse eventtextArea- the text area- Returns:
- a popup menu
- Since:
- jEdit 2.6pre2
-
loadPopupMenu
public static javax.swing.JPopupMenu loadPopupMenu(java.lang.String name)
- Parameters:
name- The menu name- Returns:
- a popup menu.
- Since:
- jEdit 2.6pre2
-
loadPopupMenu
public static javax.swing.JPopupMenu loadPopupMenu(ActionContext context, java.lang.String name)
Creates a popup menu.- Parameters:
context- An action context; eitherjEdit.getActionContext()orVFSBrowser.getActionContext().name- The menu name- Returns:
- a popup menu
- Since:
- jEdit 4.2pre1
-
loadPopupMenu
public static javax.swing.JPopupMenu loadPopupMenu(ActionContext context, java.lang.String name, JEditTextArea textArea, java.awt.event.MouseEvent evt)
Creates a popup menu.- Parameters:
context- An action context; eitherjEdit.getActionContext()orVFSBrowser.getActionContext().name- The menu nametextArea- the textArea wanting to show the popup. If not null, include context menu items defined by services.evt- additional context info about where the mouse was when menu was requested- Returns:
- the popup menu
- Since:
- jEdit 4.3pre15
-
getServiceContextMenuItems
public static java.util.List<javax.swing.JMenuItem> getServiceContextMenuItems(JEditTextArea textArea, java.awt.event.MouseEvent evt)
- Parameters:
textArea- the TextArea desiring to display these menu itemsevt- a mouse event- Returns:
- a list of menu items defined by services.
- Since:
- jEdit 4.3pre15
-
loadMenuItem
public static javax.swing.JMenuItem loadMenuItem(java.lang.String name)
Creates a menu item. The menu item is bound to the action named bynamewith label taken from the return value of theEditAction.getLabel()method.- Parameters:
name- The menu item name- Returns:
- the menu item
- Since:
- jEdit 2.6pre1
- See Also:
loadMenu(String)
-
loadMenuItem
public static javax.swing.JMenuItem loadMenuItem(java.lang.String name, boolean setMnemonic)Creates a menu item.- Parameters:
name- The menu item namesetMnemonic- True if the menu item should have a mnemonic- Returns:
- a menu item
- Since:
- jEdit 3.1pre1
-
loadMenuItem
public static javax.swing.JMenuItem loadMenuItem(ActionContext context, java.lang.String name, boolean setMnemonic)
Creates a menu item.- Parameters:
context- An action context; eitherjEdit.getActionContext()orVFSBrowser.getActionContext().name- The menu item namesetMnemonic- True if the menu item should have a mnemonic- Returns:
- the menu item
- Since:
- jEdit 4.2pre1
-
loadMenuItem
public static javax.swing.JMenuItem loadMenuItem(EditAction editAction, boolean setMnemonic)
-
loadToolBar
public static java.awt.Container loadToolBar(java.lang.String name)
- Parameters:
name- The toolbar name- Returns:
- a toolbar.
- Since:
- jEdit 4.2pre2
-
loadToolBar
public static java.awt.Container loadToolBar(ActionContext context, java.lang.String name)
Creates a toolbar.- Parameters:
context- An action context; eitherjEdit.getActionContext()orVFSBrowser.getActionContext().name- The toolbar name- Returns:
- the toolbar
- Since:
- jEdit 4.2pre2
-
loadToolButton
@Nonnull public static EnhancedButton loadToolButton(java.lang.String name)
Loads a tool bar button. The tooltip is constructed from thename.labelandname.shortcutproperties and the icon is loaded from the resource named '/org/gjt/sp/jedit/icons/' suffixed with the value of thename.iconproperty.- Parameters:
name- The name of the button- Returns:
- a button
-
loadToolButton
@Nonnull public static EnhancedButton loadToolButton(ActionContext context, java.lang.String name)
Loads a tool bar button. The tooltip is constructed from thename.labelandname.shortcutproperties and the icon is loaded from the resource named '/org/gjt/sp/jedit/icons/' suffixed with the value of thename.iconproperty.- Parameters:
context- An action context; eitherjEdit.getActionContext()orVFSBrowser.getActionContext().name- The name of the button- Returns:
- the button
- Since:
- jEdit 4.2pre1
-
getPlatformShortcutLabel
public static java.lang.String getPlatformShortcutLabel(java.lang.String label)
Translates a shortcut description string (e.g. "CS+SEMICOLON") to a platform-localized description. On OS X this puts in the pretty unicode characters for Shift, Cmd, etc.
-
getShortcutLabel
public static java.lang.String getShortcutLabel(java.lang.String action, java.lang.Boolean platform)Returns a label string to show users what shortcut are assigned to the action.- Parameters:
platform- if true, show fancy platform-specific label for the modifiers.
-
message
public static void message(java.awt.Component comp, java.lang.String name, java.lang.Object[] args)Displays a dialog box. The title of the dialog is fetched from thename.titleproperty. The message is fetched from thename.messageproperty. The message is formatted by the property manager withargsas positional parameters.- Parameters:
comp- The component to display the dialog forname- The name of the dialogargs- Positional parameters to be substituted into the message text
-
error
public static void error(java.awt.Component comp, java.lang.String name, java.lang.Object[] args)Displays an error dialog box. The title of the dialog is fetched from thename.titleproperty. The message is fetched from thename.messageproperty. The message is formatted by the property manager withargsas positional parameters.- Parameters:
comp- The component to display the dialog forname- The name of the dialogargs- Positional parameters to be substituted into the message text
-
input
public static java.lang.String input(java.awt.Component comp, java.lang.String name, java.lang.Object def)Displays an input dialog box and returns any text the user entered. The title of the dialog is fetched from thename.titleproperty. The message is fetched from thename.messageproperty.- Parameters:
comp- The component to display the dialog forname- The name of the dialogdef- The text to display by default in the input field
-
inputProperty
public static java.lang.String inputProperty(java.awt.Component comp, java.lang.String name, java.lang.String def)Displays an input dialog box and returns any text the user entered. The title of the dialog is fetched from thename.titleproperty. The message is fetched from thename.messageproperty.- Parameters:
comp- The component to display the dialog forname- The name of the dialogdef- The property whose text to display in the input field
-
input
public static java.lang.String input(java.awt.Component comp, java.lang.String name, java.lang.Object[] args, java.lang.Object def)Displays an input dialog box and returns any text the user entered. The title of the dialog is fetched from thename.titleproperty. The message is fetched from thename.messageproperty.- Parameters:
comp- The component to display the dialog forname- The name of the dialogdef- The text to display by default in the input fieldargs- Positional parameters to be substituted into the message text- Since:
- jEdit 3.1pre3
-
inputProperty
public static java.lang.String inputProperty(java.awt.Component comp, java.lang.String name, java.lang.Object[] args, java.lang.String def)Displays an input dialog box and returns any text the user entered. The title of the dialog is fetched from thename.titleproperty. The message is fetched from thename.messageproperty.- Parameters:
comp- The component to display the dialog forname- The name of the dialogargs- Positional parameters to be substituted into the message textdef- The property whose text to display in the input field- Since:
- jEdit 3.1pre3
-
confirm
public static int confirm(java.awt.Component comp, java.lang.String name, java.lang.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 thename.titleproperty. The message is fetched from thename.messageproperty.- Parameters:
comp- The component to display the dialog forname- The name of the dialogargs- Positional parameters to be substituted into the message textbuttons- The buttons to display - for example, JOptionPane.YES_NO_CANCEL_OPTIONtype- The dialog type - for example, JOptionPane.WARNING_MESSAGE- Since:
- jEdit 3.1pre3
-
option
public static int option(java.awt.Component comp, java.lang.String name, java.lang.Object[] args, int type, java.lang.Object[] options, java.lang.Object initialValue)Displays an option dialog dialog box and returns the button pushed by the user. The title of the dialog is fetched from thename.titleproperty. The message is fetched from thename.messageproperty.- Parameters:
comp- The component to display the dialog forname- The name of the dialogargs- Positional parameters to be substituted into the message texttype- The dialog type - for example, JOptionPane.WARNING_MESSAGEoptions- the buttonsinitialValue- the initial value- Since:
- jEdit 4.5pre1
-
listConfirm
public static int listConfirm(java.awt.Component comp, java.lang.String name, java.lang.String[] args, java.lang.Object[] listModel)Displays a confirm dialog box and returns the button pushed by the user. The title of the dialog is fetched from thename.titleproperty. The message is fetched from thename.messageproperty. The dialog also shows a list of entries given by thelistModelparameter.- Parameters:
comp- the parent componentname- the name of the confirm dialogargs- the for the messagelistModel- the items in the list- Returns:
- an integer indicating the option selected by the user
- Since:
- jEdit 4.3pre1
-
listConfirm
public static int listConfirm(java.awt.Component comp, java.lang.String name, java.lang.String[] args, java.lang.Object[] listModel, java.util.List selectedItems)Displays a confirm dialog box and returns the button pushed by the user. The title of the dialog is fetched from thename.titleproperty. The message is fetched from thename.messageproperty. The dialog also shows a list of entries given by thelistModelparameter.- Parameters:
comp- the parent componentname- the name of the confirm dialogargs- the for the messagelistModel- the items in the listselectedItems- give an empty list, it will contains in return the selected items- Returns:
- an integer indicating the option selected by the user
- Since:
- jEdit 4.3pre12
-
showVFSFileDialog
@Nonnull public static java.lang.String[] showVFSFileDialog(View view, java.lang.String path, int type, boolean multipleSelection)
Displays a VFS file selection dialog box.- Parameters:
view- The view, should be non-nullpath- The initial directory to display. May be nulltype- The dialog type. One ofVFSBrowser.OPEN_DIALOG,VFSBrowser.SAVE_DIALOG, orVFSBrowser.CHOOSE_DIRECTORY_DIALOG.multipleSelection- True if multiple selection should be allowed- Returns:
- The selected file(s)
- Since:
- jEdit 2.6pre2
-
showVFSFileDialog
@Nonnull public static java.lang.String[] showVFSFileDialog(java.awt.Dialog parent, View view, java.lang.String path, int type, boolean multipleSelection)Displays a VFS file selection dialog box. This version can specify a dialog as the parent instead of the view.- Parameters:
view- The view, should be non-nullpath- The initial directory to display. May be nulltype- The dialog type. One ofVFSBrowser.OPEN_DIALOG,VFSBrowser.SAVE_DIALOG, orVFSBrowser.CHOOSE_DIRECTORY_DIALOG.multipleSelection- True if multiple selection should be allowed- Returns:
- The selected file(s)
- Since:
- jEdit 4.3pre10
-
showVFSFileDialog
@Nonnull public static java.lang.String[] showVFSFileDialog(java.awt.Frame parent, View view, java.lang.String path, int type, boolean multipleSelection)Displays a VFS file selection dialog box. This version can specify a frame as the parent instead of the view.- Parameters:
parent- The parent frameview- The view, should be non-nullpath- The initial directory to display. May be nulltype- The dialog type. One ofVFSBrowser.OPEN_DIALOG,VFSBrowser.SAVE_DIALOG, orVFSBrowser.CHOOSE_DIRECTORY_DIALOG.multipleSelection- True if multiple selection should be allowed- Returns:
- The selected file(s)
- Since:
- jEdit 4.3pre10
-
menuAcceleratorFont
public static java.awt.Font menuAcceleratorFont()
Menu accelerator font according to L&F defaults, with workarounds.
-
getStyleString
public static java.lang.String getStyleString(SyntaxStyle style)
Converts a style into it's string representation.- Parameters:
style- The style
-
loadGeometry
public static void loadGeometry(java.awt.Window win, java.awt.Container parent, java.lang.String name)Loads a windows's geometry from the properties. The geometry is loaded from thename.x,name.y,name.widthandname.heightproperties.- Parameters:
win- The window to load geometry fromparent- The parent frame to be relative to.name- The name of the window
-
loadGeometry
public static void loadGeometry(java.awt.Window win, java.lang.String name)Loads a windows's geometry from the properties. The geometry is loaded from thename.x,name.y,name.widthandname.heightproperties.- Parameters:
win- The window to load geometry fromname- The name of the window
-
saveGeometry
public static void saveGeometry(java.awt.Window win, java.lang.String name)Saves a window's geometry to the properties. The geometry is saved to thename.x,name.y,name.widthandname.heightproperties.
For Frame's and descendents useaddSizeSaver(Frame,String)to save the sizes correct even if the Frame is in maximized or iconified state.- Parameters:
win- The window to load geometry fromname- The name of the window- See Also:
addSizeSaver(Frame,String)
-
saveGeometry
public static void saveGeometry(java.awt.Window win, java.awt.Container parent, java.lang.String name)Saves a window's geometry to the properties. The geometry is saved to thename.x,name.y,name.widthandname.heightproperties.
For Frame's and descendents useaddSizeSaver(Frame,Container,String)to save the sizes correct even if the Frame is in maximized or iconified state.- Parameters:
win- The window to load geometry fromparent- The parent frame to be relative to.name- The name of the window- See Also:
addSizeSaver(Frame,Container,String)
-
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.
-
applyTextAreaColors
public static void applyTextAreaColors(java.awt.Container win)
experimental - applies the text area colors on a Component (such as a dockable window) and its children.- Since:
- jEdit 5.0pre1
-
createMultilineLabel
public static javax.swing.JComponent createMultilineLabel(java.lang.String str)
Creates a component that displays a multiple line message. This is implemented by assembling a number ofJLabelsin aJPanel.- Parameters:
str- The string, with lines delimited by newline (\n) characters.- Since:
- jEdit 4.1pre3
-
getComponentParent
public static java.awt.Component getComponentParent(java.awt.Component comp, java.lang.Class clazz)Finds a parent of the specified component.- Parameters:
comp- The componentclazz- Looks for a parent with this class (exact match, not derived).- Since:
- jEdit 4.2pre1
-
getView
public static View getView(java.awt.Component comp)
Finds the view parent of the specified component.- Parameters:
comp- the component from which you want to get the parent view- Returns:
- the parent view, or null if the component was not in a View.
- Since:
- jEdit 4.0pre2
-
addSizeSaver
public static void addSizeSaver(@Nonnull java.awt.Frame frame, @Nonnull java.lang.String name)Adds a SizeSaver to the specified Frame. For non-Frame's usesaveGeometry(Window,String)- Parameters:
frame- The Frame for which to save the sizename- The prefix for the settings- Since:
- jEdit 4.3pre6
- See Also:
saveGeometry(Window,String)
-
addSizeSaver
public static void addSizeSaver(@Nonnull java.awt.Frame frame, java.awt.Container parent, @Nonnull java.lang.String name)Adds a SizeSaver to the specified Frame. For non-Frame's usesaveGeometry(Window,Container,String)- Parameters:
frame- The Frame for which to save the sizeparent- The parent to be relative toname- The prefix for the settings- Since:
- jEdit 4.3pre7
- See Also:
saveGeometry(Window,Container,String)
-
-