chemaxon.marvin.util
Class SwingUtil

java.lang.Object
  extended by chemaxon.marvin.util.SwingUtil
All Implemented Interfaces:
java.io.Serializable

public class SwingUtil
extends java.lang.Object
implements java.io.Serializable

Swing utility functions.

Since:
Marvin 3.3.1, 01/15/2004
Version:
5.2.6, 09/10/2009
Author:
Peter Csizmadia
See Also:
Serialized Form

Constructor Summary
SwingUtil()
           
 
Method Summary
static void addHyperlinkListener(javax.swing.JEditorPane editorPane)
          Adds HTML link handling to an editor pane.
static javax.swing.JMenu createMenu(java.util.ResourceBundle rc, java.lang.String key)
          Utility method to create a menu with a label specified as a resource.
static javax.swing.JMenu createMenu(java.util.ResourceBundle rc, java.lang.String key, boolean mnemo)
          Creates a menu with a label specified as a resource.
static javax.swing.JMenuItem createMenuItem(java.util.ResourceBundle rc, java.lang.String key)
          Creates a menu with a label specified as a resource.
static javax.swing.JMenuItem createMenuItem(java.util.ResourceBundle rc, java.lang.String key, boolean mnemo)
          Creates a menu with a label specified as a resource.
static javax.swing.JMenuItem createMenuItem(java.util.ResourceBundle rc, java.lang.String key, java.lang.Class what, boolean mnemo)
          Creates a menu item with a label specified as a resource.
static javax.swing.JEditorPane createMessagePane(java.lang.String text)
          Creates a message pane with HTML text content.
static javax.swing.JPanel createSubPanel(java.lang.String title)
          Creates a sub-panel with a title.
static java.awt.GridBagConstraints createTopLeftConstraints()
          Creates GridBagConstraints for the top left component.
static void decorateSubPanel(javax.swing.JPanel panel, java.lang.String title)
          Creates border and title for a panel.
static javax.swing.KeyStroke getCommandKeyStroke(int key)
          Gets the command keystroke preferred on the current platform.
static void initAction(javax.swing.Action action, java.util.ResourceBundle rc, java.lang.String key, javax.swing.KeyStroke accel)
          Initializes an action from information in a resource.
static void initButton(javax.swing.AbstractButton b, java.util.ResourceBundle rc, java.lang.String key)
          Utility method to initialize a button from information in a resource.
static void initButton(javax.swing.AbstractButton b, java.util.ResourceBundle rc, java.lang.String key, boolean mnemo)
          Utility method to initialize a button from information in a resource.
static void initCtrlShortcutForMac(javax.swing.JMenuItem mi)
          Deprecated. does nothing.
static void initInApplet()
          Deprecated. does nothing.
static
<T> T
invokeAndWait(java.util.concurrent.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> java.util.concurrent.FutureTask<T>
invokeLater(java.util.concurrent.Callable<T> callable)
          Calls SwingUtilities.invokeLater() for a Callable by wrapping it into a FutureTask object.
static void setDefaultFont(javax.swing.JEditorPane editorPane)
          Sets the SWING default font in the JEditorPane.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SwingUtil

public SwingUtil()
Method Detail

initInApplet

public static void initInApplet()
Deprecated. does nothing.


getCommandKeyStroke

public static javax.swing.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 javax.swing.JMenuItem createMenuItem(java.util.ResourceBundle rc,
                                                   java.lang.String key,
                                                   java.lang.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 resources
key - name of the label resource
what - menu item class
mnemo - use mnemonic or not
Returns:
the menu
Since:
Marvin 4.1, 11/10/2005

createMenuItem

public static javax.swing.JMenuItem createMenuItem(java.util.ResourceBundle rc,
                                                   java.lang.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 resources
key - name of the label resource
mnemo - set the mnemonic or not
Returns:
the menu item
Since:
Marvin 4.1, 11/10/2005

createMenuItem

public static javax.swing.JMenuItem createMenuItem(java.util.ResourceBundle rc,
                                                   java.lang.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 resources
key - name of the label resource
Returns:
the menu item
Since:
Marvin 4.1, 11/10/2005

createMenu

public static javax.swing.JMenu createMenu(java.util.ResourceBundle rc,
                                           java.lang.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 resources
key - name of the label resource
Returns:
the menu

createMenu

public static javax.swing.JMenu createMenu(java.util.ResourceBundle rc,
                                           java.lang.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 resources
key - name of the label resource
mnemo - set the mnemonic or not
Returns:
the menu
Since:
Marvin 4.1, 11/10/2005

initButton

public static void initButton(javax.swing.AbstractButton b,
                              java.util.ResourceBundle rc,
                              java.lang.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 button
rc - the resources
key - name of the resource

initButton

public static void initButton(javax.swing.AbstractButton b,
                              java.util.ResourceBundle rc,
                              java.lang.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 button
rc - the resources
key - name of the resource
mnemo - set the mnemonic or not

initAction

public static void initAction(javax.swing.Action action,
                              java.util.ResourceBundle rc,
                              java.lang.String key,
                              javax.swing.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 action
rc - the resources
key - name of the resource
accel - the accelerator or null

initCtrlShortcutForMac

public static void initCtrlShortcutForMac(javax.swing.JMenuItem mi)
Deprecated. does nothing.


decorateSubPanel

public static void decorateSubPanel(javax.swing.JPanel panel,
                                    java.lang.String title)
Creates border and title for a panel.

Parameters:
title - the panel title
Since:
Marvin 4.1, 11/10/2005

createSubPanel

public static javax.swing.JPanel createSubPanel(java.lang.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 java.awt.GridBagConstraints createTopLeftConstraints()
Creates GridBagConstraints for the top left component.

Returns:
the constraints
Since:
Marvin 4.1, 11/10/2005

createMessagePane

public static javax.swing.JEditorPane createMessagePane(java.lang.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(javax.swing.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(javax.swing.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> java.util.concurrent.FutureTask<T> invokeLater(java.util.concurrent.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(java.util.concurrent.Callable<T> callable)
                       throws java.lang.InterruptedException,
                              java.lang.reflect.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:
java.lang.InterruptedException
java.lang.reflect.InvocationTargetException