java.lang.Object
org.gjt.sp.jedit.GUIUtilities
Various GUI utility functions related to icons, menus, toolbars, keyboard shortcuts, etc.
The most frequently used members of this class are:
- Version:
- $Id: GUIUtilities.java 25221 2020-04-12 16:00:17Z kpouer $
- Author:
- Slava Pestov
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addSizeSaver
(Frame frame, Container parent, String name) Adds a SizeSaver to the specified Frame.static void
addSizeSaver
(Frame frame, String name) Adds a SizeSaver to the specified Frame.static void
adjustForScreenBounds
(Rectangle desired) Deprecated.static void
experimental - applies the text area colors on a Component (such as a dockable window) and its children.static int
Displays a confirm dialog box and returns the button pushed by the user.static JComponent
Creates a component that displays a multiple line message.static int
Deprecated.static int
Deprecated.static Dimension
Deprecated.static void
Displays an error dialog box.static Component
getComponentParent
(Component comp, Class clazz) Finds a parent of the specified component.static Image
static JDialog
Deprecated.static String
getPlatformShortcutLabel
(String label) Translates a shortcut description string (e.g.static Image
static Rectangle
Deprecated.getServiceContextMenuItems
(JEditTextArea textArea, MouseEvent evt) static String
getShortcutLabel
(String action, Boolean platform) Returns a label string to show users what shortcut are assigned to the action.static String
getStyleString
(SyntaxStyle style) Converts a style into it's string representation.static View
Finds the view parent of the specified component.static void
Ensures that the splash screen is not visible.static String
Displays an input dialog box and returns any text the user entered.static String
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) Deprecated.static boolean
isMiddleButton
(int modifiers) Deprecated.static boolean
isPopupTrigger
(MouseEvent evt) Deprecated.static boolean
isRightButton
(int modifiers) Deprecated.static int
listConfirm
(Component comp, String name, String[] args, Object[] listModel) Displays a confirm dialog box and returns the button pushed by the user.static int
Displays a confirm dialog box and returns the button pushed by the user.static void
loadGeometry
(Window win, Container parent, String name) Loads a windows's geometry from the properties.static void
loadGeometry
(Window win, String name) Loads a windows's geometry from the properties.static Icon
Loads an icon.static JMenu
Creates a menu.static JMenu
loadMenu
(ActionContext context, String name) Creates a menu.static JMenuBar
loadMenuBar
(String name) Creates a menubar.static JMenuBar
loadMenuBar
(ActionContext context, String name) Creates a menubar.static JMenuItem
loadMenuItem
(String name) Creates a menu item.static JMenuItem
loadMenuItem
(String name, boolean setMnemonic) Creates a menu item.static JMenuItem
loadMenuItem
(ActionContext context, String name, boolean setMnemonic) Creates a menu item.static JMenuItem
loadMenuItem
(EditAction editAction, boolean setMnemonic) static JPopupMenu
loadPopupMenu
(String name) static JPopupMenu
loadPopupMenu
(String name, JEditTextArea textArea, MouseEvent evt) Creates a popup menu.static JPopupMenu
loadPopupMenu
(ActionContext context, String name) Creates a popup menu.static JPopupMenu
loadPopupMenu
(ActionContext context, String name, JEditTextArea textArea, MouseEvent evt) Creates a popup menu.static Container
loadToolBar
(String name) static Container
loadToolBar
(ActionContext context, String name) Creates a toolbar.static EnhancedButton
loadToolButton
(String name) Loads a tool bar button.static EnhancedButton
loadToolButton
(ActionContext context, String name) Loads a tool bar button.static void
makeSameSize
(Component... components) Deprecated.static Font
Menu accelerator font according to L&F defaults, with workarounds.static void
Displays a dialog box.static int
Displays an option dialog dialog box and returns the button pushed by the user.static Color
parseColor
(String name) Deprecated.static SyntaxStyle
parseStyle
(String str, String family, int size) Deprecated.static String
prettifyMenuLabel
(String label) Deprecated.static void
requestFocus
(Window win, Component comp) Deprecated.static void
saveGeometry
(Window win, Container parent, String name) Saves a window's geometry to the properties.static void
saveGeometry
(Window win, String name) Saves a window's geometry to the properties.static void
setAutoMnemonic
(AbstractButton button) Deprecated.static void
setButtonContentMargin
(AbstractButton button, Insets margin) static void
setEnabledRecursively
(Container c, boolean enabled) Deprecated.static void
setIconPath
(String iconPath) Sets the path where jEdit looks for icons.static void
showPopupMenu
(JPopupMenu popup, Component comp, int x, int y) static void
showPopupMenu
(JPopupMenu popup, Component comp, int x, int y, boolean point) static String[]
showVFSFileDialog
(Dialog parent, View view, String path, int type, boolean multipleSelection) Displays a VFS file selection dialog box.static String[]
showVFSFileDialog
(Frame parent, View view, String path, int type, boolean multipleSelection) Displays a VFS file selection dialog box.static String[]
showVFSFileDialog
(View view, String path, int type, boolean multipleSelection) Displays a VFS file selection dialog box.static String[]
showVFSFileDialog
(View parent, View view, String path, int type, boolean multipleSelection)
-
Method Details
-
setIconPath
Sets the path where jEdit looks for icons.- Parameters:
iconPath
- the icon path- Since:
- jEdit 4.2pre5
-
loadIcon
Loads an icon.- Parameters:
iconName
- The icon name- Returns:
- the icon
- Since:
- jEdit 2.6pre7
-
getEditorIcon
- Returns:
- the default editor window image.
-
getPluginIcon
- Returns:
- the default plugin window image.
-
loadMenuBar
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
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
Creates a menu. The menu label is set from thename.label
property. The menu contents is taken from thename
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- Returns:
- a menu
- Since:
- jEdit 2.6pre2
- See Also:
-
loadMenu
Creates a menu. The menu label is set from thename.label
property. The menu contents is taken from thename
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; eitherjEdit.getActionContext()
orVFSBrowser.getActionContext()
.name
- The menu name- Returns:
- a menu
- Since:
- jEdit 4.2pre1
- See Also:
-
loadPopupMenu
Creates a popup menu.- Parameters:
name
- The menu nameevt
- mouse eventtextArea
- the text area- Returns:
- a popup menu
- Since:
- jEdit 2.6pre2
-
loadPopupMenu
- Parameters:
name
- The menu name- Returns:
- a popup menu.
- Since:
- jEdit 2.6pre2
-
loadPopupMenu
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 JPopupMenu loadPopupMenu(ActionContext context, String name, JEditTextArea textArea, 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
- 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
Creates a menu item. The menu item is bound to the action named byname
with 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:
-
loadMenuItem
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
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
-
loadToolBar
- Parameters:
name
- The toolbar name- Returns:
- a toolbar.
- Since:
- jEdit 4.2pre2
-
loadToolBar
Creates a toolbar.- Parameters:
context
- An action context; eitherjEdit.getActionContext()
orVFSBrowser.getActionContext()
.name
- The toolbar name- Returns:
- the toolbar
- Since:
- jEdit 4.2pre2
-
loadToolButton
Loads a tool bar button. The tooltip is constructed from thename.label
andname.shortcut
properties and the icon is loaded from the resource named '/org/gjt/sp/jedit/icons/' suffixed with the value of thename.icon
property.- Parameters:
name
- The name of the button- Returns:
- a button
-
loadToolButton
Loads a tool bar button. The tooltip is constructed from thename.label
andname.shortcut
properties and the icon is loaded from the resource named '/org/gjt/sp/jedit/icons/' suffixed with the value of thename.icon
property.- Parameters:
context
- An action context; eitherjEdit.getActionContext()
orVFSBrowser.getActionContext()
.name
- The name of the button- Returns:
- the button
- Since:
- jEdit 4.2pre1
-
prettifyMenuLabel
Deprecated.`Prettifies' a menu item label by removing the `$' sign. This can be used to process the contents of an action.label property.- Parameters:
label
- the label- Returns:
- a pretty label
-
getPlatformShortcutLabel
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
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.
-
setAutoMnemonic
Deprecated.Sets the mnemonic for the given button using jEdit convention, taking the letter after the dollar.- Parameters:
button
- The button to set the mnemonic for.- Since:
- jEdit 5.1
-
message
Displays a dialog box. The title of the dialog is fetched from thename.title
property. The message is fetched from thename.message
property. The message is formatted by the property manager withargs
as 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
Displays an error dialog box. The title of the dialog is fetched from thename.title
property. The message is fetched from thename.message
property. The message is formatted by the property manager withargs
as 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
Displays an input dialog box and returns any text the user entered. The title of the dialog is fetched from thename.title
property. The message is fetched from thename.message
property.- 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
Displays an input dialog box and returns any text the user entered. The title of the dialog is fetched from thename.title
property. The message is fetched from thename.message
property.- 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
Displays an input dialog box and returns any text the user entered. The title of the dialog is fetched from thename.title
property. The message is fetched from thename.message
property.- 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
Displays an input dialog box and returns any text the user entered. The title of the dialog is fetched from thename.title
property. The message is fetched from thename.message
property.- 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
Displays a confirm dialog box and returns the button pushed by the user. The title of the dialog is fetched from thename.title
property. The message is fetched from thename.message
property.- 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(Component comp, String name, Object[] args, int type, Object[] options, 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.title
property. The message is fetched from thename.message
property.- 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
Displays a confirm dialog box and returns the button pushed by the user. The title of the dialog is fetched from thename.title
property. The message is fetched from thename.message
property. The dialog also shows a list of entries given by thelistModel
parameter.- 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(Component comp, String name, String[] args, Object[] listModel, List selectedItems) Displays a confirm dialog box and returns the button pushed by the user. The title of the dialog is fetched from thename.title
property. The message is fetched from thename.message
property. The dialog also shows a list of entries given by thelistModel
parameter.- 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 String[] showVFSFileDialog(View view, 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 String[] showVFSFileDialog(Dialog parent, View view, 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 String[] showVFSFileDialog(Frame parent, View view, 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
-
showVFSFileDialog
-
parseColor
Deprecated.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 thejava.awt.Color
class) or a hex color value prefixed with `#', for example `#ff0088'.- Parameters:
name
- The color name
-
parseStyle
@Deprecated public static SyntaxStyle parseStyle(String str, String family, int size) throws IllegalArgumentException Deprecated.Converts a style string to a style object.- Parameters:
str
- The style stringfamily
- Style strings only specify font style, not font familysize
- Style strings only specify font style, not font family- Throws:
IllegalArgumentException
- if the style is invalid- Since:
- jEdit 3.2pre6
-
getStyleString
Converts a style into it's string representation.- Parameters:
style
- The style
-
loadGeometry
Loads a windows's geometry from the properties. The geometry is loaded from thename.x
,name.y
,name.width
andname.height
properties.- Parameters:
win
- The window to load geometry fromparent
- The parent frame to be relative to.name
- The name of the window
-
loadGeometry
Loads a windows's geometry from the properties. The geometry is loaded from thename.x
,name.y
,name.width
andname.height
properties.- Parameters:
win
- The window to load geometry fromname
- The name of the window
-
adjustForScreenBounds
Deprecated.Gives a rectangle the specified bounds, ensuring it is within the screen bounds.- Since:
- jEdit 4.2pre3
-
saveGeometry
Saves a window's geometry to the properties. The geometry is saved to thename.x
,name.y
,name.width
andname.height
properties.
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:
-
saveGeometry
Saves a window's geometry to the properties. The geometry is saved to thename.x
,name.y
,name.width
andname.height
properties.
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:
-
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
experimental - applies the text area colors on a Component (such as a dockable window) and its children.- Since:
- jEdit 5.0pre1
-
createMultilineLabel
Creates a component that displays a multiple line message. This is implemented by assembling a number ofJLabels
in aJPanel
.- Parameters:
str
- The string, with lines delimited by newline (\n
) characters.- Since:
- jEdit 4.1pre3
-
requestFocus
Deprecated.Focuses on the specified component as soon as the window becomes active.- Parameters:
win
- The windowcomp
- The component
-
isPopupTrigger
Deprecated.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
Deprecated.- Parameters:
modifiers
- The modifiers flag from a mouse event- Since:
- jEdit 4.1pre9
-
isRightButton
Deprecated.- Parameters:
modifiers
- The modifiers flag from a mouse event- Since:
- jEdit 4.1pre9
-
getScreenBounds
Deprecated.Returns the screen bounds, taking into account multi-screen environments.- Since:
- jEdit 4.3pre18
-
showPopupMenu
Shows the specified popup menu, ensuring it is displayed within the bounds of the screen.- Parameters:
popup
- The popup menucomp
- The component to show it forx
- The x co-ordinatey
- The y co-ordinate- Since:
- jEdit 4.0pre1
- See Also:
-
showPopupMenu
@Deprecated 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 menucomp
- The component to show it forx
- The x co-ordinatey
- The y co-ordinatepoint
- 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
Deprecated.Returns if the first component is an ancestor of the second by traversing up the component hierarchy.- Parameters:
comp1
- The ancestorcomp2
- The component to check- Since:
- jEdit 4.1pre5
-
getParentDialog
Deprecated.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
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
-
setEnabledRecursively
Deprecated.Call setEnabled() recursively on the container and its descendants.- Parameters:
c
- The containerenabled
- The enabled state to set- Since:
- jEdit 4.3pre17
-
getView
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
-
setButtonContentMargin
Sets the content margin of a button (for Nimbus L&F).- Parameters:
button
- the button to modifymargin
- the new margin- Since:
- jEdit 5.3
-
makeSameSize
Deprecated.Makes components the same size by finding the largest width and height of the given components then setting all components to that width and height. This is especially useful for making JButtons the same size.- Parameters:
components
- The components to make the same size.
-
defaultTableCellSize
Deprecated.JTable cell size, based on global defaults. -
defaultColumnWidth
Deprecated.Column width for JTable, based on global defaults. -
defaultRowHeight
Deprecated.Row height for JTable, based on global defaults. -
addSizeSaver
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:
-
addSizeSaver
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:
-
GenericGUIUtilities.adjustForScreenBounds(Rectangle)