com.ccg.swing
Class TextUtils

java.lang.Object
  extended by com.ccg.swing.TextUtils

public class TextUtils
extends Object

General utility methods for working with text components.

This class provides some static helper methods that provide some convienent "wrappers" dealing with the setting and retrieving of values from text fields. In particular these methods provide a consistent manner for dealing with 'null' values.

Since:
1.0
Version:
$Revision: 1.2 $
Author:
$Author: pkb $

Constructor Summary
TextUtils()
           
 
Method Summary
static File getFileOrNull(JTextComponent c)
          Get a File object from the text of a component (or null if text is blank).
static String getStringOrNull(JTextComponent c)
          Get a text string from a component (or null if text is blank).
static void setFileOrNull(JTextComponent c, File val)
          Set the text value of a component from a file (which might be null).
static void setStringOrNull(JTextComponent c, String val)
          Set the text value of a component from a string (which might be null).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextUtils

public TextUtils()
Method Detail

setStringOrNull

public static void setStringOrNull(JTextComponent c,
                                   String val)
Set the text value of a component from a string (which might be null).

This method is designed to work in conjustion with the getStringOrNull(javax.swing.text.JTextComponent) method. It allows one to set/retrieve 'null' string values from components. If you pass null to this method as the value, we will change it to the zero length string "".

Parameters:
c - The component to set the text value on (you can pass null - and we'll handle it)
val - String value to assign - if you pass null, we'll set the text to "".
See Also:
getStringOrNull(javax.swing.text.JTextComponent)

getStringOrNull

public static String getStringOrNull(JTextComponent c)
Get a text string from a component (or null if text is blank).

This method is the counter part to the setStringOrNull(javax.swing.text.JTextComponent, java.lang.String) method. It retrieves the current text setting from the component. If the current setting is just white space, then this method return null - otherwise it returns the value of the text shown in the component.

Parameters:
c - The component to get the text value from (you can pass null - and we'll handle it)
Returns:
Text from the component - or null if component's text is just white space.
See Also:
setStringOrNull(javax.swing.text.JTextComponent, java.lang.String)

setFileOrNull

public static void setFileOrNull(JTextComponent c,
                                 File val)
Set the text value of a component from a file (which might be null).

This method is designed to work in conjuction with the getFileOrNull(javax.swing.text.JTextComponent) method. It allows one to set/retrieve 'null' file values from components.

This method will set the text value of the component to the string representation of the File object you pass. If you pass null to this method as the value, we will change it to the zero length file "".

Parameters:
c - The component to set the text value on (you can pass null - and we'll handle it)
val - File object to get the text from - if you pass null, we'll set the text to "".
See Also:
getFileOrNull(javax.swing.text.JTextComponent)

getFileOrNull

public static File getFileOrNull(JTextComponent c)
Get a File object from the text of a component (or null if text is blank).

This method is the counter part to the setFileOrNull(javax.swing.text.JTextComponent, java.io.File) method. It retrieves the current text setting from the component as a File object. If the current setting is just white space, then this method returns null - otherwise it returns a File object with the value of the text shown in the component.

Parameters:
c - The component to fetch the text from (you can pass null - and we'll handle it)
Returns:
A File object formed from the text of the component - or null if component's text is just white space.
See Also:
setFileOrNull(javax.swing.text.JTextComponent, java.io.File)


Copyright 1998-1998-2006 null. All Rights Reserved.