ix.iface.ui.util
Class UIUtil

java.lang.Object
  extended by ix.iface.ui.util.UIUtil

public class UIUtil
extends java.lang.Object

Class for useful static methods.


Nested Class Summary
static class UIUtil.ToStringComparator
           
 
Field Summary
static java.lang.String lineSeparator
           
 
Constructor Summary
UIUtil()
           
 
Method Summary
static boolean addActionListener(javax.swing.JComponent c, java.awt.event.ActionListener al)
           
static void addListener(javax.swing.JComponent component, java.util.EventListener el)
           
static java.lang.String booleanToProperty(boolean value)
           
static java.lang.String[] breakStringAtFirst(java.lang.String s, java.lang.String separator)
          breakStringAtFirst takes a string containing fields separated by a (string) delimiter and returns a two-element string array containing the substring before the first occurrence of the char, and the substring after.
static java.lang.String ensureParenthesized(java.lang.String text)
          Makes sure that the given string is enclosed in parentheses.
static java.util.List enumerationToList(java.util.Enumeration e)
           
static java.lang.String fieldsToNames(java.lang.reflect.Field[] fields)
           
static int findNameField(java.util.ArrayList fieldNames)
          Looks for a field that sounds like a good name field and returns its index in the given list.
static javax.swing.AbstractButton getEventButton(java.awt.event.ActionEvent ae)
           
static IXEditorPanel getEventPanel(java.awt.event.ActionEvent ae)
           
static java.util.List getFlatValues(java.util.Map map)
           
static java.lang.Object getObjectFieldValue(java.lang.Object object, java.lang.String field)
           
static java.lang.String intToProperty(int value)
           
static boolean isEmptyThing(java.lang.Object thing)
          Returns true if the given thing is null, empty string, or empty collection, or map with no values
static boolean isEmptyValue(java.lang.Object value)
          Checks whether the given thing is empty.
static void listenToCB(javax.swing.JComboBox jcb, javax.swing.event.PopupMenuListener listener)
           
static java.lang.String listToDisplay(java.util.Collection l)
           
static java.lang.String listToText(java.util.Collection l)
           
static java.lang.String[] listToTextArray(java.util.Collection l)
           
static javax.swing.JMenuItem makeMenuItem(java.awt.event.ActionListener al, javax.swing.JComponent menu, java.lang.String command, java.lang.String label)
          Makes a menu item with the given label and command and adds it to the given (menu) parent.
static TypedList newTypedList(java.lang.Class listClass, java.util.Collection data)
           
static TypedList newTypedList(java.lang.Class listClass, java.lang.Object data)
           
static TypedList newTypedList(java.lang.Class listClass, java.lang.Object[] data)
           
static void notImplemented(java.awt.Component parent, java.lang.String item)
          Brings up a message that the given string item is not yet supported.
static void populateMenu(java.awt.event.ActionListener al, javax.swing.JMenu menu, java.lang.String command, java.util.List objects)
          Fills the given menu with the names of the given objects, attaching the given command.
static void populateMenu(java.awt.event.ActionListener al, javax.swing.JMenu menu, java.lang.String label, java.lang.String command, java.util.List objects)
          Fills the given menu with the names of the given objects, attaching the given command.
static void populateMenu(java.awt.event.ActionListener al, JObjectMenu menu, java.lang.Object obj, java.lang.String command, java.util.List objects)
          Fills the given menu with the names of the given objects, attaching the given command.
static boolean propertyToBoolean(java.lang.String sValue)
           
static int propertyToInt(java.lang.String sValue)
           
static Symbol propertyToSymbol(java.lang.String sValue)
           
static LList remove(java.lang.Object o, LList list)
           
static LList removeDuplicates(LList list)
           
static java.net.URL resourceURL(java.lang.String filename)
           
static void setObjectFieldValue(java.lang.Object object, java.lang.String field, java.lang.Class fieldClass, java.lang.Object value)
          Sets the object's field to the given value
static java.lang.String show(java.util.Collection l)
           
static java.lang.String show(java.util.Enumeration e)
           
static java.lang.String showClass(java.util.Collection l)
           
static java.lang.reflect.Field stringToField(java.lang.Class oClass, java.lang.String field)
           
static java.lang.String symbolToProperty(Symbol value)
           
static java.lang.String toCapitalised(java.lang.String inString)
          public static void clearMouseListeners(Component c) { MouseListener[] mls = c.getMouseListeners(); for (int i = 0; i < mls.length; i++) c.removeMouseListener(mls[i]); }
static java.lang.String toUncapitalised(java.lang.String inString)
           
static void warning(java.awt.Component parent, java.lang.String item)
          Brings up a message that the given string item is not yet supported.
static java.util.Collection without(java.util.Collection things, java.util.Collection notThings)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lineSeparator

public static final java.lang.String lineSeparator
Constructor Detail

UIUtil

public UIUtil()
Method Detail

notImplemented

public static void notImplemented(java.awt.Component parent,
                                  java.lang.String item)
Brings up a message that the given string item is not yet supported. e.g. "Editing AROs is not yet supported"


warning

public static void warning(java.awt.Component parent,
                           java.lang.String item)
Brings up a message that the given string item is not yet supported. e.g. "Editing AROs is not yet supported"


addListener

public static void addListener(javax.swing.JComponent component,
                               java.util.EventListener el)

addActionListener

public static boolean addActionListener(javax.swing.JComponent c,
                                        java.awt.event.ActionListener al)

getEventPanel

public static IXEditorPanel getEventPanel(java.awt.event.ActionEvent ae)

getEventButton

public static javax.swing.AbstractButton getEventButton(java.awt.event.ActionEvent ae)

populateMenu

public static void populateMenu(java.awt.event.ActionListener al,
                                javax.swing.JMenu menu,
                                java.lang.String command,
                                java.util.List objects)
Fills the given menu with the names of the given objects, attaching the given command. Always clears the menu first and disables it. Only enables it if there are items in it. Sets the label to the given command if the menu has no label.

Parameters:
al - the ActionListener that will process menu selections
menu - the menu to be filled
command - attached to each new menu item
objects - an ArrayList of named objects to be put in the menu

populateMenu

public static void populateMenu(java.awt.event.ActionListener al,
                                javax.swing.JMenu menu,
                                java.lang.String label,
                                java.lang.String command,
                                java.util.List objects)
Fills the given menu with the names of the given objects, attaching the given command. Always clears the menu first and disables it. Only enables it if there are items in it.

Parameters:
menu - the menu to be filled
command - attached to each new menu item
label - sets the label of the menu unless it is null (leaves label alone if it is null)
objects - an ArrayList of named objects to be put in the menu

populateMenu

public static void populateMenu(java.awt.event.ActionListener al,
                                JObjectMenu menu,
                                java.lang.Object obj,
                                java.lang.String command,
                                java.util.List objects)
Fills the given menu with the names of the given objects, attaching the given command. Always clears the menu first and disables it. Only enables it if there are items in it.

Parameters:
menu - the menu to be filled
command - attached to each new menu item
objects - an ArrayList of named objects to be put in the menu

makeMenuItem

public static javax.swing.JMenuItem makeMenuItem(java.awt.event.ActionListener al,
                                                 javax.swing.JComponent menu,
                                                 java.lang.String command,
                                                 java.lang.String label)
Makes a menu item with the given label and command and adds it to the given (menu) parent.

Parameters:
al - the action listener that is interested in the item's selection
menu - the menu that the item should be added to
command - attached to the item for recognising actions
label - displayed in the menu

toCapitalised

public static java.lang.String toCapitalised(java.lang.String inString)
public static void clearMouseListeners(Component c) { MouseListener[] mls = c.getMouseListeners(); for (int i = 0; i < mls.length; i++) c.removeMouseListener(mls[i]); }


toUncapitalised

public static java.lang.String toUncapitalised(java.lang.String inString)

ensureParenthesized

public static java.lang.String ensureParenthesized(java.lang.String text)
Makes sure that the given string is enclosed in parentheses.

Returns:
the given string if it is already in parentheses, the given string with added ( and ) if not.

breakStringAtFirst

public static java.lang.String[] breakStringAtFirst(java.lang.String s,
                                                    java.lang.String separator)
breakStringAtFirst takes a string containing fields separated by a (string) delimiter and returns a two-element string array containing the substring before the first occurrence of the char, and the substring after. Neither substring contains the delimiter. If the delimiter does not appear in the string at all, the values are the string and "".


propertyToSymbol

public static Symbol propertyToSymbol(java.lang.String sValue)

propertyToInt

public static int propertyToInt(java.lang.String sValue)

propertyToBoolean

public static boolean propertyToBoolean(java.lang.String sValue)

booleanToProperty

public static java.lang.String booleanToProperty(boolean value)

symbolToProperty

public static java.lang.String symbolToProperty(Symbol value)

intToProperty

public static java.lang.String intToProperty(int value)

isEmptyThing

public static boolean isEmptyThing(java.lang.Object thing)
Returns true if the given thing is null, empty string, or empty collection, or map with no values


stringToField

public static java.lang.reflect.Field stringToField(java.lang.Class oClass,
                                                    java.lang.String field)
                                             throws java.lang.NoSuchFieldException,
                                                    java.lang.IllegalAccessException
Throws:
java.lang.NoSuchFieldException
java.lang.IllegalAccessException

findNameField

public static int findNameField(java.util.ArrayList fieldNames)
Looks for a field that sounds like a good name field and returns its index in the given list.


getObjectFieldValue

public static java.lang.Object getObjectFieldValue(java.lang.Object object,
                                                   java.lang.String field)

setObjectFieldValue

public static void setObjectFieldValue(java.lang.Object object,
                                       java.lang.String field,
                                       java.lang.Class fieldClass,
                                       java.lang.Object value)
Sets the object's field to the given value


isEmptyValue

public static boolean isEmptyValue(java.lang.Object value)
Checks whether the given thing is empty. Checks for null, empty string, and empty list. If in doubt, say it is not empty.


show

public static java.lang.String show(java.util.Collection l)

showClass

public static java.lang.String showClass(java.util.Collection l)

show

public static java.lang.String show(java.util.Enumeration e)

listToDisplay

public static java.lang.String listToDisplay(java.util.Collection l)

listToText

public static java.lang.String listToText(java.util.Collection l)

listToTextArray

public static java.lang.String[] listToTextArray(java.util.Collection l)

fieldsToNames

public static java.lang.String fieldsToNames(java.lang.reflect.Field[] fields)

removeDuplicates

public static LList removeDuplicates(LList list)

without

public static java.util.Collection without(java.util.Collection things,
                                           java.util.Collection notThings)

remove

public static LList remove(java.lang.Object o,
                           LList list)

getFlatValues

public static java.util.List getFlatValues(java.util.Map map)

enumerationToList

public static java.util.List enumerationToList(java.util.Enumeration e)

newTypedList

public static TypedList newTypedList(java.lang.Class listClass,
                                     java.util.Collection data)

newTypedList

public static TypedList newTypedList(java.lang.Class listClass,
                                     java.lang.Object[] data)

newTypedList

public static TypedList newTypedList(java.lang.Class listClass,
                                     java.lang.Object data)

resourceURL

public static java.net.URL resourceURL(java.lang.String filename)

listenToCB

public static void listenToCB(javax.swing.JComboBox jcb,
                              javax.swing.event.PopupMenuListener listener)