Package chemaxon.marvin.util
Class SwingUtil
- java.lang.Object
-
- chemaxon.marvin.util.SwingUtil
-
- All Implemented Interfaces:
Serializable
@PublicAPI public class SwingUtil extends Object implements Serializable
Swing utility functions.- Since:
- Marvin 3.3.1, 01/15/2004
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SwingUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
addHyperlinkListener(JEditorPane editorPane)
Adds HTML link handling to an editor pane.static JMenu
createMenu(ResourceBundle rc, String key)
Utility method to create a menu with a label specified as a resource.static JMenu
createMenu(ResourceBundle rc, String key, boolean mnemo)
Creates a menu with a label specified as a resource.static JMenuItem
createMenuItem(ResourceBundle rc, String key)
Creates a menu with a label specified as a resource.static JMenuItem
createMenuItem(ResourceBundle rc, String key, boolean mnemo)
Creates a menu with a label specified as a resource.static JMenuItem
createMenuItem(ResourceBundle rc, String key, Class<?> what, boolean mnemo)
Creates a menu item with a label specified as a resource.static JEditorPane
createMessagePane(String text)
Creates a message pane with HTML text content.static JPanel
createSubPanel(String title)
Creates a sub-panel with a title.static GridBagConstraints
createTopLeftConstraints()
Creates GridBagConstraints for the top left component.static void
decorateSubPanel(JPanel panel, String title)
Creates border and title for a panel.static KeyStroke
getCommandKeyStroke(int key)
Gets the command keystroke preferred on the current platform.static void
initAction(Action action, ResourceBundle rc, String key, KeyStroke accel)
Initializes an action from information in a resource.static void
initButton(AbstractButton b, ResourceBundle rc, String key)
Utility method to initialize a button from information in a resource.static void
initButton(AbstractButton b, ResourceBundle rc, String key, boolean mnemo)
Utility method to initialize a button from information in a resource.static void
initCtrlShortcutForMac(JMenuItem mi)
Deprecated.does nothing.static void
initInApplet()
Deprecated.does nothing.static <T> T
invokeAndWait(Callable<T> callable)
Calls SwingUtilities.invokeLater() for a Callable by wrapping it into a FutureTask object, blocks until it is finished and returns the result (calling FutureTask.get()).static <T> FutureTask<T>
invokeLater(Callable<T> callable)
Calls SwingUtilities.invokeLater() for a Callable by wrapping it into a FutureTask object.static void
setDefaultFont(JEditorPane editorPane)
Sets the SWING default font in the JEditorPane.
-
-
-
Method Detail
-
initInApplet
@Deprecated public static void initInApplet()
Deprecated.does nothing.
-
getCommandKeyStroke
public static KeyStroke getCommandKeyStroke(int key)
Gets the command keystroke preferred on the current platform. Ctrl+key on Linux and Windows, Command+key on Mac.- Parameters:
key
- the key- Returns:
- keystroke for the specified key and meta (for Mac) or control (for other platforms)
-
createMenuItem
public static JMenuItem createMenuItem(ResourceBundle rc, String key, Class<?> what, boolean mnemo)
Creates a menu item with a label specified as a resource. If the label string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.- Parameters:
rc
- the resourceskey
- name of the label resourcewhat
- menu item classmnemo
- use mnemonic or not- Returns:
- the menu
- Since:
- Marvin 4.1, 11/10/2005
-
createMenuItem
public static JMenuItem createMenuItem(ResourceBundle rc, String key, boolean mnemo)
Creates a menu with a label specified as a resource. If the label string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.- Parameters:
rc
- the resourceskey
- name of the label resourcemnemo
- set the mnemonic or not- Returns:
- the menu item
- Since:
- Marvin 4.1, 11/10/2005
-
createMenuItem
public static JMenuItem createMenuItem(ResourceBundle rc, String key)
Creates a menu with a label specified as a resource. If the label string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.- Parameters:
rc
- the resourceskey
- name of the label resource- Returns:
- the menu item
- Since:
- Marvin 4.1, 11/10/2005
-
createMenu
public static JMenu createMenu(ResourceBundle rc, String key)
Utility method to create a menu with a label specified as a resource. If the label string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.- Parameters:
rc
- the resourceskey
- name of the label resource- Returns:
- the menu
-
createMenu
public static JMenu createMenu(ResourceBundle rc, String key, boolean mnemo)
Creates a menu with a label specified as a resource. If the label string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.- Parameters:
rc
- the resourceskey
- name of the label resourcemnemo
- set the mnemonic or not- Returns:
- the menu
- Since:
- Marvin 4.1, 11/10/2005
-
initButton
public static void initButton(AbstractButton b, ResourceBundle rc, String key)
Utility method to initialize a button from information in a resource. If the resource string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.- Parameters:
b
- the buttonrc
- the resourceskey
- name of the resource
-
initButton
public static void initButton(AbstractButton b, ResourceBundle rc, String key, boolean mnemo)
Utility method to initialize a button from information in a resource. If the resource string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.- Parameters:
b
- the buttonrc
- the resourceskey
- name of the resourcemnemo
- set the mnemonic or not
-
initAction
public static void initAction(Action action, ResourceBundle rc, String key, KeyStroke accel)
Initializes an action from information in a resource. If the resource string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.- Parameters:
action
- the actionrc
- the resourceskey
- name of the resourceaccel
- the accelerator or null
-
initCtrlShortcutForMac
@Deprecated public static void initCtrlShortcutForMac(JMenuItem mi)
Deprecated.does nothing.
-
decorateSubPanel
public static void decorateSubPanel(JPanel panel, String title)
Creates border and title for a panel.- Parameters:
title
- the panel title- Since:
- Marvin 4.1, 11/10/2005
-
createSubPanel
public static JPanel createSubPanel(String title)
Creates a sub-panel with a title.- Parameters:
title
- the panel title- Returns:
- the panel
- Since:
- Marvin 4.1, 11/10/2005
- See Also:
decorateSubPanel(JPanel, String)
-
createTopLeftConstraints
public static GridBagConstraints createTopLeftConstraints()
Creates GridBagConstraints for the top left component.- Returns:
- the constraints
- Since:
- Marvin 4.1, 11/10/2005
-
createMessagePane
public static JEditorPane createMessagePane(String text)
Creates a message pane with HTML text content. HTML links are handled, referred pages are displayed in the default browser.- Parameters:
text
- the content, may contain HTML links- Returns:
- the message pane
-
setDefaultFont
public static void setDefaultFont(JEditorPane editorPane)
Sets the SWING default font in the JEditorPane. This is necessary because originally the font is read from a style sheet. This method adds a CSS rule to force body tags to use the default label font instead of the value in javax.swing.text.html.default.css. Code is copied from: http://explodingpixels.wordpress.com/2008/10/28/make-jeditorpane-use-the-system-font/- Parameters:
editorPane
- the JEditorPane
-
addHyperlinkListener
public static void addHyperlinkListener(JEditorPane editorPane)
Adds HTML link handling to an editor pane. The referred content will be displayed in the default browser.- Parameters:
editorPane
- the JEditorPane
-
invokeLater
public static <T> FutureTask<T> invokeLater(Callable<T> callable)
Calls SwingUtilities.invokeLater() for a Callable by wrapping it into a FutureTask object. Written by Karl Schaefer. Source: http://weblogs.java.net/blog/kschaefe/archive/2010/11/15/returns-values-swingutilitiesinvoke- Parameters:
callable
- the Callable object to be invoked on the event dispatch thread- Returns:
- the wrapper FutureTask
-
invokeAndWait
public static <T> T invokeAndWait(Callable<T> callable) throws InterruptedException, InvocationTargetException
Calls SwingUtilities.invokeLater() for a Callable by wrapping it into a FutureTask object, blocks until it is finished and returns the result (calling FutureTask.get()). Written by Karl Schaefer. Source: http://weblogs.java.net/blog/kschaefe/archive/2010/11/15/returns-values-swingutilitiesinvoke- Parameters:
callable
- the Callable object to be invoked on the event dispatch thread- Returns:
- the return value of the callable returned in FutureTask.get()
- Throws:
InterruptedException
InvocationTargetException
-
-