org.jminor.common.ui
Class UiUtil

java.lang.Object
  extended by org.jminor.common.ui.UiUtil

public final class UiUtil
extends Object

A static utility class.


Nested Class Summary
static class UiUtil.DialogDisposeAction
           
 
Field Summary
static Cursor DEFAULT_CURSOR
           
static Dimension DIMENSION_TEXT_FIELD_SQUARE
          A square dimension which sides are the same as the preferred height of a JTextField.
static Cursor WAIT_CURSOR
           
 
Method Summary
static void addAcceptSingleFileDragAndDrop(JTextComponent textComponent)
          Makes the text component accept files during drag and drop operations and insert the absolute path of the dropped file (the first file in a list if more than one file is dropped)
static void addInitialFocusHack(JComponent component, Action onFocusAction)
          http://bugs.sun.com/bugdatabase/view_bug.do?
static void addKeyEvent(JComponent component, int keyEvent, Action action)
           
static void addKeyEvent(JComponent component, int keyEvent, int modifiers, Action action)
           
static void addKeyEvent(JComponent component, int keyEvent, int modifiers, int condition, Action action)
           
static void addKeyEvent(JComponent component, int keyEvent, int modifiers, int condition, boolean onKeyRelease, Action action)
           
static void addLookupDialog(JTextField txtField, ValueCollectionProvider valueListProvider)
           
static void centerWindow(Window window)
           
static File chooseFileToSave(JComponent dialogParent, String startDir, String defaultFileName)
           
static JFormattedTextField createFormattedField(SimpleDateFormat maskFormat, Object initialValue)
           
static JFormattedTextField createFormattedField(String mask)
           
static JFormattedTextField createFormattedField(String mask, boolean valueContainsLiteralCharacter)
           
static JFormattedTextField createFormattedField(String mask, boolean valueContainsLiteralCharacter, boolean charsAsUpper)
           
static JFrame createFrame(Image icon)
           
static JTextField createMemoryUsageField(int updateInterval)
           
static void expandAll(JTree tree, TreePath parent, boolean expand)
           
static TabbedPaneUI getBorderlessTabbedPaneUI()
           
static Action getBrowseAction(JTextField txtFilename)
           
static Date getDateFromUser(Date startDate, String message, Container parent)
           
static JDialog getParentDialog(Component container)
           
static JFrame getParentFrame(Component container)
           
static
<T> T
getParentOfType(Component container, Class<T> clazz)
           
static Window getParentWindow(Component container)
           
static int getPreferredScrollBarWidth()
           
static int getPreferredTextFieldHeight()
           
static Dimension getPreferredTextFieldSize()
           
static Dimension getScreenSizeRatio(double ratio)
           
static String getStartDir(String text)
           
static Action linkToEnabledState(StateObserver enabledState, Action action)
           
static JComponent linkToEnabledState(StateObserver enabledState, JComponent component)
           
static JTextComponent makeLowerCase(JTextComponent textField)
          Makes textField convert all upper case input to lower case
static JTextComponent makeUpperCase(JTextComponent textField)
          Makes textField convert all lower case input to upper case
static TextFieldPlus makeUpperCase(TextFieldPlus textField)
           
static void moveCaretToEndOnFocusGained(JTextComponent textComponent)
          Sets the caret position to the right of the last character in the given text component when it gains focus
static void moveCaretToStartOnFocusGained(JTextComponent textComponent)
          Sets the caret position to 0 in the given text component when it gains focus
static JPanel northCenterPanel(JComponent north, JComponent center)
           
static void resizeWindow(Window window, double screenSizeRatio)
           
static void resizeWindow(Window window, double screenSizeRatio, Dimension minimumSize)
           
static void selectAllOnFocusGained(JTextComponent textComponent)
          Selects all text in the given component when it gains focus and clears the selection when focus is lost
static File selectDirectory(JComponent dialogParent, String startDir)
           
static File selectDirectory(JComponent dialogParent, String startDir, String dialogTitle)
           
static File selectFile(JComponent dialogParent, String startDir)
           
static Object selectValue(JComponent dialogOwner, Collection<?> values)
           
static Object selectValue(JComponent dialogOwner, Collection<?> values, String dialogTitle)
           
static void setSizeWithinScreenBounds(Window window)
           
static void setWaitCursor(boolean on, JComponent component)
           
static void showImage(String imagePath, JComponent dialogParent)
           
static void showImage(String imagePath, JComponent dialogParent, Collection<String> acceptedFileTypes)
           
static JDialog showInDialog(Container owner, JComponent componentToShow, boolean modal, String title, Dimension size, JButton defaultButton, EventObserver closeEvent)
           
static JDialog showInDialog(Window owner, JComponent componentToShow, boolean modal, String title, boolean includeButtonPanel, boolean disposeOnOk, Action okAction)
           
static JDialog showInDialog(Window owner, JComponent componentToShow, boolean modal, String title, boolean includeButtonPanel, boolean disposeOnOk, Action okAction, Dimension size)
           
static JDialog showInDialog(Window owner, JComponent componentToShow, boolean modal, String title, boolean includeButtonPanel, boolean disposeOnOk, Action okAction, Dimension size, Point location, Action closeAction)
           
static void showToolTip(JComponent component)
           
static void transferFocusOnEnter(JComponent component)
          Attaches a key listener to the component which transfers focus on enter, and backwards if shift is down
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WAIT_CURSOR

public static final Cursor WAIT_CURSOR

DEFAULT_CURSOR

public static final Cursor DEFAULT_CURSOR

DIMENSION_TEXT_FIELD_SQUARE

public static final Dimension DIMENSION_TEXT_FIELD_SQUARE
A square dimension which sides are the same as the preferred height of a JTextField. This comes in handy when f.ex. adding "..." lookup buttons next to text fields.

Method Detail

createMemoryUsageField

public static JTextField createMemoryUsageField(int updateInterval)

selectDirectory

public static File selectDirectory(JComponent dialogParent,
                                   String startDir)
                            throws CancelException
Throws:
CancelException

selectDirectory

public static File selectDirectory(JComponent dialogParent,
                                   String startDir,
                                   String dialogTitle)
                            throws CancelException
Throws:
CancelException

selectFile

public static File selectFile(JComponent dialogParent,
                              String startDir)
                       throws CancelException
Throws:
CancelException

chooseFileToSave

public static File chooseFileToSave(JComponent dialogParent,
                                    String startDir,
                                    String defaultFileName)
                             throws CancelException
Throws:
CancelException

getDateFromUser

public static Date getDateFromUser(Date startDate,
                                   String message,
                                   Container parent)

createFormattedField

public static JFormattedTextField createFormattedField(SimpleDateFormat maskFormat,
                                                       Object initialValue)

createFormattedField

public static JFormattedTextField createFormattedField(String mask)

createFormattedField

public static JFormattedTextField createFormattedField(String mask,
                                                       boolean valueContainsLiteralCharacter)

createFormattedField

public static JFormattedTextField createFormattedField(String mask,
                                                       boolean valueContainsLiteralCharacter,
                                                       boolean charsAsUpper)

linkToEnabledState

public static Action linkToEnabledState(StateObserver enabledState,
                                        Action action)

linkToEnabledState

public static JComponent linkToEnabledState(StateObserver enabledState,
                                            JComponent component)

createFrame

public static JFrame createFrame(Image icon)

getScreenSizeRatio

public static Dimension getScreenSizeRatio(double ratio)
Parameters:
ratio - a ratio, 0.0 - 1.0
Returns:
a Dimension which is the size of the available screen times ratio

setSizeWithinScreenBounds

public static void setSizeWithinScreenBounds(Window window)

resizeWindow

public static void resizeWindow(Window window,
                                double screenSizeRatio)

resizeWindow

public static void resizeWindow(Window window,
                                double screenSizeRatio,
                                Dimension minimumSize)

getParentWindow

public static Window getParentWindow(Component container)

getParentFrame

public static JFrame getParentFrame(Component container)

getParentDialog

public static JDialog getParentDialog(Component container)

getParentOfType

public static <T> T getParentOfType(Component container,
                                    Class<T> clazz)

centerWindow

public static void centerWindow(Window window)

expandAll

public static void expandAll(JTree tree,
                             TreePath parent,
                             boolean expand)

setWaitCursor

public static void setWaitCursor(boolean on,
                                 JComponent component)

getPreferredScrollBarWidth

public static int getPreferredScrollBarWidth()

getPreferredTextFieldSize

public static Dimension getPreferredTextFieldSize()

getPreferredTextFieldHeight

public static int getPreferredTextFieldHeight()

getBorderlessTabbedPaneUI

public static TabbedPaneUI getBorderlessTabbedPaneUI()

northCenterPanel

public static JPanel northCenterPanel(JComponent north,
                                      JComponent center)

showToolTip

public static void showToolTip(JComponent component)

makeUpperCase

public static JTextComponent makeUpperCase(JTextComponent textField)
Makes textField convert all lower case input to upper case

Parameters:
textField - the text field
Returns:
the text field

makeUpperCase

public static TextFieldPlus makeUpperCase(TextFieldPlus textField)

makeLowerCase

public static JTextComponent makeLowerCase(JTextComponent textField)
Makes textField convert all upper case input to lower case

Parameters:
textField - the text field
Returns:
the text field

transferFocusOnEnter

public static void transferFocusOnEnter(JComponent component)
Attaches a key listener to the component which transfers focus on enter, and backwards if shift is down

Parameters:
component - the component

selectAllOnFocusGained

public static void selectAllOnFocusGained(JTextComponent textComponent)
Selects all text in the given component when it gains focus and clears the selection when focus is lost

Parameters:
textComponent - the text component

moveCaretToStartOnFocusGained

public static void moveCaretToStartOnFocusGained(JTextComponent textComponent)
Sets the caret position to 0 in the given text component when it gains focus

Parameters:
textComponent - the text component

moveCaretToEndOnFocusGained

public static void moveCaretToEndOnFocusGained(JTextComponent textComponent)
Sets the caret position to the right of the last character in the given text component when it gains focus

Parameters:
textComponent - the text component

showInDialog

public static JDialog showInDialog(Window owner,
                                   JComponent componentToShow,
                                   boolean modal,
                                   String title,
                                   boolean includeButtonPanel,
                                   boolean disposeOnOk,
                                   Action okAction)

showInDialog

public static JDialog showInDialog(Window owner,
                                   JComponent componentToShow,
                                   boolean modal,
                                   String title,
                                   boolean includeButtonPanel,
                                   boolean disposeOnOk,
                                   Action okAction,
                                   Dimension size)

showInDialog

public static JDialog showInDialog(Window owner,
                                   JComponent componentToShow,
                                   boolean modal,
                                   String title,
                                   boolean includeButtonPanel,
                                   boolean disposeOnOk,
                                   Action okAction,
                                   Dimension size,
                                   Point location,
                                   Action closeAction)

showInDialog

public static JDialog showInDialog(Container owner,
                                   JComponent componentToShow,
                                   boolean modal,
                                   String title,
                                   Dimension size,
                                   JButton defaultButton,
                                   EventObserver closeEvent)

addAcceptSingleFileDragAndDrop

public static void addAcceptSingleFileDragAndDrop(JTextComponent textComponent)
Makes the text component accept files during drag and drop operations and insert the absolute path of the dropped file (the first file in a list if more than one file is dropped)

Parameters:
textComponent - the text component

addKeyEvent

public static void addKeyEvent(JComponent component,
                               int keyEvent,
                               Action action)

addKeyEvent

public static void addKeyEvent(JComponent component,
                               int keyEvent,
                               int modifiers,
                               Action action)

addKeyEvent

public static void addKeyEvent(JComponent component,
                               int keyEvent,
                               int modifiers,
                               int condition,
                               Action action)

addKeyEvent

public static void addKeyEvent(JComponent component,
                               int keyEvent,
                               int modifiers,
                               int condition,
                               boolean onKeyRelease,
                               Action action)

addLookupDialog

public static void addLookupDialog(JTextField txtField,
                                   ValueCollectionProvider valueListProvider)

selectValue

public static Object selectValue(JComponent dialogOwner,
                                 Collection<?> values)

selectValue

public static Object selectValue(JComponent dialogOwner,
                                 Collection<?> values,
                                 String dialogTitle)

getBrowseAction

public static Action getBrowseAction(JTextField txtFilename)

getStartDir

public static String getStartDir(String text)

showImage

public static void showImage(String imagePath,
                             JComponent dialogParent)
                      throws IOException
Parameters:
imagePath - the path to the image to show
dialogParent - the component to use as dialog parent
Throws:
IOException - in case of an IO exception

showImage

public static void showImage(String imagePath,
                             JComponent dialogParent,
                             Collection<String> acceptedFileTypes)
                      throws IOException
Parameters:
imagePath - the path to the image to show, if the file has a file type suffix it is checked against the acceptedFileTypes collection.
dialogParent - the component to use as dialog parent
acceptedFileTypes - a collection of lower case file type suffixes, "gif", "jpeg"...
Throws:
IOException - in case of an IO exception
IllegalArgumentException - in case the file type is not accepted

addInitialFocusHack

public static void addInitialFocusHack(JComponent component,
                                       Action onFocusAction)
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5018574

Parameters:
component - the component, in case of text fields the caret is moved to the end of the text
onFocusAction - the action to run when the focus has been requested