org.xnap.commons.gui.util
Class GUIHelper

java.lang.Object
  extended by org.xnap.commons.gui.util.GUIHelper

public class GUIHelper
extends Object

Helps with gui related tasks.


Field Summary
static int POPUP_MENU_HEIGHT_INSET
          Kicker offset.
 
Constructor Summary
GUIHelper()
           
 
Method Summary
static void bindEmacsKeysToTable(JTable jta)
          Adds some Emacs like keybindings to a table for moving between rows.
static boolean bindEnterKey(JComponent c, Action action)
          Adds a mapping between the enter key and action to the input map of c.
static boolean bindEnterKeyLocally(JComponent c, Action action)
          Does the same as bindEnterKey(JComponent, Action)but uses the default input map and not the window input map.
static boolean bindEscapeKey(JComponent c, Action action)
          Adds a mapping between the escape key and action to the input map of c.
static void bindExpandCollapseKeysToTree(JTree tree)
           
static boolean bindKey(JComponent c, KeyStroke ks, Action action, boolean whenInFocusedWindow)
          Adds a mapping between ks and action to the input map of c.
static Border createDefaultBorder(String title)
          Returns an etched default border.
static Border createEmptyBorder()
          Returns an empty border.
static Border createEmptyBorder(int inset)
          Returns an empty border.
static Border createEtchedBorder()
          Returns an empty border.
static JComponent createHeader(String title)
          Returns a component that displays title in a bold font.
static Border createLoweredBorder()
           
static Border createRaisedBorder()
           
static Border createTitledBorder(String title, int inset)
          Returns a titled border.
static void expandAllNodes(JTree tree, boolean expand)
           
static void expandAllNodes(JTree tree, TreePath path, boolean expand)
           
static KeyStroke getMenuKeyStroke(int keyCode)
           
static KeyStroke getMenuShortcut(int keyCode)
           
static String label(String text)
          Wraps HTML tags around text so the maximum width is limited to a senseful value.
static void limitSize(JComponent c)
           
static void restrictWidth(JComponent jc)
           
static void scrollToEnd(JTextComponent jt)
           
static void setAccelerator(JMenuItem jmi, int keyCode)
           
static void setMnemonics(Container c)
           
static void setMnemonics(Container c, HashSet<Integer> l)
           
static void setMnemonics(JTabbedPane pane)
           
static boolean shouldScroll(JScrollBar jsb)
          Returns true, if jsb is at the maximum value.
static void showFile(JTextComponent jtc, String filename, String altText)
          Loads text from file and sets it to jtc.
static void showPopupMenu(JPopupMenu jpm, Component source, int x, int y)
           
static void showPopupMenu(JPopupMenu jpm, Component source, int x, int y, int yOffset)
           
static String tableRow(String key, String value)
          Formats key, value as a HTML table row, the key is highlighted as bold.
static String tt(String text)
          Wraps HTML tags around text so the maximum width is limited to a sensible value.
static String tt(String text, int width)
          Wraps HTML tags around text so the maximum width is limited to a senseful value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POPUP_MENU_HEIGHT_INSET

public static final int POPUP_MENU_HEIGHT_INSET
Kicker offset.

See Also:
Constant Field Values
Constructor Detail

GUIHelper

public GUIHelper()
Method Detail

bindEnterKey

public static boolean bindEnterKey(JComponent c,
                                   Action action)
Adds a mapping between the enter key and action to the input map of c.

Returns:
true, if successful; false, otherwise

bindEnterKeyLocally

public static boolean bindEnterKeyLocally(JComponent c,
                                          Action action)
Does the same as bindEnterKey(JComponent, Action)but uses the default input map and not the window input map.

Returns:
true, if successful; false, otherwise

bindEscapeKey

public static boolean bindEscapeKey(JComponent c,
                                    Action action)
Adds a mapping between the escape key and action to the input map of c.

Returns:
true, if successful; false, otherwise

bindKey

public static boolean bindKey(JComponent c,
                              KeyStroke ks,
                              Action action,
                              boolean whenInFocusedWindow)
Adds a mapping between ks and action to the input map of c.

Returns:
true, if successful; false, otherwise

createDefaultBorder

public static Border createDefaultBorder(String title)
Returns an etched default border. TODO move this to builder?


createEmptyBorder

public static Border createEmptyBorder(int inset)
Returns an empty border.


createEmptyBorder

public static Border createEmptyBorder()
Returns an empty border.


createEtchedBorder

public static Border createEtchedBorder()
Returns an empty border.


createLoweredBorder

public static Border createLoweredBorder()

createRaisedBorder

public static Border createRaisedBorder()

createHeader

public static JComponent createHeader(String title)
Returns a component that displays title in a bold font.


createTitledBorder

public static Border createTitledBorder(String title,
                                        int inset)
Returns a titled border.


expandAllNodes

public static void expandAllNodes(JTree tree,
                                  boolean expand)

expandAllNodes

public static void expandAllNodes(JTree tree,
                                  TreePath path,
                                  boolean expand)

restrictWidth

public static void restrictWidth(JComponent jc)

scrollToEnd

public static void scrollToEnd(JTextComponent jt)

shouldScroll

public static boolean shouldScroll(JScrollBar jsb)
Returns true, if jsb is at the maximum value.


getMenuKeyStroke

public static KeyStroke getMenuKeyStroke(int keyCode)

setAccelerator

public static void setAccelerator(JMenuItem jmi,
                                  int keyCode)

setMnemonics

public static void setMnemonics(JTabbedPane pane)

setMnemonics

public static void setMnemonics(Container c)

setMnemonics

public static void setMnemonics(Container c,
                                HashSet<Integer> l)

showFile

public static void showFile(JTextComponent jtc,
                            String filename,
                            String altText)
Loads text from file and sets it to jtc.

If file is not found or could not be read, sets altText instead.


showPopupMenu

public static void showPopupMenu(JPopupMenu jpm,
                                 Component source,
                                 int x,
                                 int y,
                                 int yOffset)

showPopupMenu

public static void showPopupMenu(JPopupMenu jpm,
                                 Component source,
                                 int x,
                                 int y)

label

public static String label(String text)
Wraps HTML tags around text so the maximum width is limited to a senseful value.

Returns:
text, enclosed in table html tags

tt

public static String tt(String text,
                        int width)
Wraps HTML tags around text so the maximum width is limited to a senseful value.

Returns:
text, enclosed in table html tags

getMenuShortcut

public static KeyStroke getMenuShortcut(int keyCode)

tt

public static String tt(String text)
Wraps HTML tags around text so the maximum width is limited to a sensible value.

Returns:
text, enclosed in table html tags

tableRow

public static String tableRow(String key,
                              String value)
Formats key, value as a HTML table row, the key is highlighted as bold.


limitSize

public static void limitSize(JComponent c)

bindExpandCollapseKeysToTree

public static void bindExpandCollapseKeysToTree(JTree tree)

bindEmacsKeysToTable

public static void bindEmacsKeysToTable(JTable jta)
Adds some Emacs like keybindings to a table for moving between rows.



Copyright © 2004-2007 XNap Commons Team. All Rights Reserved.