chrriis.dj.swingsuite
Class SwingSuiteUtilities

java.lang.Object
  extended by chrriis.dj.swingsuite.SwingSuiteUtilities

public class SwingSuiteUtilities
extends Object

Author:
Christopher Deckers

Field Summary
static boolean IS_JAVA_6_OR_GREATER
           
 
Method Summary
static void adjustToolbarButtonFocus(AbstractButton toolBarButton)
          With certain look and feels, namely windows with XP style, the focus of a toolbar button is already indicated (border changes) and the focus indicator should not be drawn: this fixes the visual rendering.
static String applySedRegularExpression(String text, String regex)
          A "sed -e" like reg exp, of the form:
- /regexp/flags: find and output the matches.
static void autoFitTableColumn(JTable table, int columnIndex, int maxWidth)
          Auto fit the column of a table.
static void autoFitTableColumns(JTable table, int maxWidth)
          Auto fit the columns of a table.
static String convertWildcardsToRegExp(String wildcardString)
          Replace a string that contains wildcards (* and ?)
static String decodeURL(String s)
          Decode some text that was URL encoded.
static String encodeURL(String s)
          Encode some text to be used in a URL.
static String escapeXML(String s)
          Escape a string to be used in XML.
static boolean isSelectingAllOnFocus(JTextComponent textComponent)
          Indicate whether a text component selects all its text when it receives the focus.
static void setAutoScrollEnabled(JComponent component, boolean isEnabled)
          Set whether the auto-scroll feature is enabled.
static void setPreferredLookAndFeel()
          Set the look and feel that users tend to prefer for the current platform.
static void setSelectAllOnFocus(JTextComponent component, boolean isSelectingAllOnFocus)
          Set whether a text component selects all of its text when it acquires the focus.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IS_JAVA_6_OR_GREATER

public static final boolean IS_JAVA_6_OR_GREATER
Method Detail

setSelectAllOnFocus

public static void setSelectAllOnFocus(JTextComponent component,
                                       boolean isSelectingAllOnFocus)
Set whether a text component selects all of its text when it acquires the focus.

Parameters:
component - The component to set the select all status to.
isSelectingAllOnFocus - true if the text should be selected when focus is acquired, false otherwise.

isSelectingAllOnFocus

public static boolean isSelectingAllOnFocus(JTextComponent textComponent)
Indicate whether a text component selects all its text when it receives the focus.

Parameters:
textComponent - The text component for which to get the select all state.
Returns:
true if the text component selects all its text when gaining focus, false otherwise.

adjustToolbarButtonFocus

public static void adjustToolbarButtonFocus(AbstractButton toolBarButton)
With certain look and feels, namely windows with XP style, the focus of a toolbar button is already indicated (border changes) and the focus indicator should not be drawn: this fixes the visual rendering.

Parameters:
toolBarButton - the tool bar button for which to adjust the focus state.

setAutoScrollEnabled

public static void setAutoScrollEnabled(JComponent component,
                                        boolean isEnabled)
Set whether the auto-scroll feature is enabled. Auto-scoll is triggered when the user clicks with the middle mouse button and the component is a scroll pane or has a scroll pane ancestor.
Note that clicking on a descendant component activates the auto-scroll feature only if it has not registered a mouse listener. Otherwise, you need to activate auto scroll on these components as well.

Parameters:
component - The component for which to enable or disable the feature.
isEnabled - true if the feature is to be enabled, false otherwise.

autoFitTableColumns

public static void autoFitTableColumns(JTable table,
                                       int maxWidth)
Auto fit the columns of a table.

Parameters:
table - the table for which to auto fit the columns.
maxWidth - the maximum width that a column can take (like Integer.MAX_WIDTH).

autoFitTableColumn

public static void autoFitTableColumn(JTable table,
                                      int columnIndex,
                                      int maxWidth)
Auto fit the column of a table.

Parameters:
table - the table for which to auto fit the columns.
columnIndex - the index of the column to auto fit, in view index.
maxWidth - the maximum width that a column can take (like Integer.MAX_WIDTH).

decodeURL

public static String decodeURL(String s)
Decode some text that was URL encoded.

Parameters:
s - the string to decode.
Returns:
the string once decoded.

encodeURL

public static String encodeURL(String s)
Encode some text to be used in a URL.

Parameters:
s - the string to encode.
Returns:
the string once encoded.

escapeXML

public static String escapeXML(String s)
Escape a string to be used in XML.

Parameters:
s - the string to escape.
Returns:
the string after having been escaped.

applySedRegularExpression

public static String applySedRegularExpression(String text,
                                               String regex)
A "sed -e" like reg exp, of the form:
- /regexp/flags: find and output the matches.
- /regexp/replacement/flags: replace the matches and output the resulting string.
Flags can be left empty or any combinations of the characters 'gidmsux' (g perfoms a replace all instead of just the first match. For other flags, refer to the Javadoc of Pattern). It is also possible to chain the output using ';' to perform multiple replacements.
If the regexp contains capturing groups, a find operation would only retain those; for a replace operation, the replacement string can refer to capturing groups with a syntax like '$1'.


convertWildcardsToRegExp

public static String convertWildcardsToRegExp(String wildcardString)
Replace a string that contains wildcards (* and ?) to its regular expression equivalent.

Parameters:
wildcardString - the string to convert.
Returns:
the regular expression equivalent to the wildcard string.

setPreferredLookAndFeel

public static void setPreferredLookAndFeel()
Set the look and feel that users tend to prefer for the current platform.