|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.util.gui.FormHelper
public class FormHelper
provides convenience to handle common problems when dealing with forms and has generally useful utility methods for handling form fields
| Field Summary | |
|---|---|
static String |
COMMIT_VALUE_KEY
used to fire a PropertyChangeEvent that will directly commit a value |
| Constructor Summary | |
|---|---|
FormHelper()
|
|
| Method Summary | ||
|---|---|---|
void |
bind(JComponent field,
Object obj,
String property,
Runnable runOnUpdate,
String changePropertyKey)
|
|
JComponent |
createBoundField(Object obj,
String property,
Runnable runOnUpdate)
|
|
JComponent |
createComponentFor(Class<?> c)
creates and returns a component suitable for editing objects of the given class. |
|
static String |
enterMessage(Component parent,
String title)
opens a dialog allowing to enter a multi-line message |
|
static String |
enterMessage(Component parent,
String title,
boolean resizable)
opens a dialog allowing to enter a multi-line message |
|
static String |
enterMessage(Component parent,
String title,
int rows,
int columns)
opens a dialog allowing to enter a multi-line message |
|
static String |
enterMessage(Component parent,
String title,
int rows,
int columns,
boolean resizable,
int optionType)
opens a dialog allowing to enter a multi-line message |
|
static String |
enterMessage(Component parent,
String title,
int rows,
int columns,
boolean resizable,
int optionType,
Filter<String> filter,
String initialValue)
opens a dialog allowing to enter a multi-line message |
|
static Number |
enterNumber(Component parent,
String title,
Object message)
|
|
static Number |
enterNumber(Component parent,
String title,
Object message,
NumberFormat format,
Filter<? super Number> filter,
Object initialValue)
|
|
static char[] |
enterPassword(Component parent)
returns null on cancel |
|
static char[] |
enterPassword(Component parent,
String title,
Object message,
char[] initialValue)
returns null on cancel |
|
static char[] |
enterPassword(Component parent,
String title,
Object message,
char[] initialValue,
ImageIcon icon)
returns null on cancel; tries to set caps lock to false to avoid common mistakes |
|
static String |
enterString(Component parent,
String title,
Object message,
Filter<String> filter,
Object initialValue)
|
|
static
|
extractInterface(Component component,
Class<T> type)
|
|
protected Method |
findMethod(Class<?> type,
String name)
|
|
static void |
fixTabKeys(Component... cs)
enables the standard tab keys for focus traversal. |
|
static Object |
getFormValue(Form form,
Object defaultValue,
String dialogTitle)
|
|
static Object |
getFormValue(Form form,
ValueRetriever<?> retriever,
String dialogTitle)
convenience method that allows to retrieve a value from a form if applicable |
|
Number |
getNumberFor(JComponent field)
returns 0 if the field could not be parsed as a number (or was null) |
|
static String |
getText(JTextComponent comp)
convenience method - returns actually null if the component text is either empty or contains only whitespace |
|
Object |
getValueFor(JComponent field)
allows to specialize the way how the value for the given key is retrieved from the given component. |
|
void |
installChangeListener(Component comp,
Runnable r)
|
|
void |
installChangeListener(Component comp,
Runnable r,
String changeProperty)
|
|
void |
installChangeListener(Component comp,
Task<? extends RuntimeException> task)
this method creates and installs listeners for the given component that run the given task upon changes to the component |
|
void |
installChangeListener(Component comp,
Task<? extends RuntimeException> task,
String changeProperty)
additionally supports the option to use a PropertyChangeListener with the given property
if everything else fails. |
|
void |
installChangeListener(Runnable r,
Component... cs)
|
|
static boolean |
isNotEmpty(String str)
|
|
static void |
limitSize(JTextComponent c,
DBClassStore<?> store,
String column)
|
|
static void |
limitSize(JTextComponent c,
int chars)
limits the number of characters that can be entered into the given text component. |
|
static void |
limitSize(JTextComponent c,
MappingInfo mi,
String column)
|
|
static String |
nullForEmpty(String str)
|
|
void |
setEditable(boolean flag,
Component... comp)
|
|
void |
setEditable(Component c,
boolean flag)
|
|
void |
setValueFor(Object value,
JComponent field)
applies the given value to the given component. |
|
static
|
showSelectDialog(Component parent,
String title,
Component selectionComp,
ValueRetriever<T> retriever,
boolean resizable)
shows a dialog that lets you select a value with the given selectionComp and then retrieves the selected value via the given retriever. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String COMMIT_VALUE_KEY
PropertyChangeEvent that will directly commit a value
showSelectDialog(Component, String, Component, ValueRetriever, boolean),
Constant Field Values| Constructor Detail |
|---|
public FormHelper()
| Method Detail |
|---|
public static <T> T showSelectDialog(Component parent,
String title,
Component selectionComp,
ValueRetriever<T> retriever,
boolean resizable)
PropertyChangeListener on the selectionComp
to react on selection changes so that the dialog can update the 'ok'-button accordingly.
If you want to support a directly committed selection within the selectionComp then
simply fire a PropertyChangeEvent with the property name COMMIT_VALUE_KEY.
The selectionComp will receive the initial focus when the component is displayed.
parent - the parent component determining where the dialog is to be locatedtitle - the title of the dialog displayedselectionComp - the component that allows to select a value; this component should fire
a PropertyChangeEvent upon selection changes.
Also, this component will get the focus via Component.requestFocusInWindow(),
so make sure the given component acts appropriately to this call.retriever - provides a way for this method to retrieve the selected value from the componentresizable - determines whether the dialog is to be resizable
Component.requestFocusInWindow(),
COMMIT_VALUE_KEY
public static Number enterNumber(Component parent,
String title,
Object message)
public static Number enterNumber(Component parent,
String title,
Object message,
NumberFormat format,
Filter<? super Number> filter,
Object initialValue)
public static String enterString(Component parent,
String title,
Object message,
Filter<String> filter,
Object initialValue)
public static String enterMessage(Component parent,
String title)
public static String enterMessage(Component parent,
String title,
boolean resizable)
public static String enterMessage(Component parent,
String title,
int rows,
int columns)
public static String enterMessage(Component parent,
String title,
int rows,
int columns,
boolean resizable,
int optionType)
public static String enterMessage(Component parent,
String title,
int rows,
int columns,
boolean resizable,
int optionType,
Filter<String> filter,
String initialValue)
public static char[] enterPassword(Component parent)
public static char[] enterPassword(Component parent,
String title,
Object message,
char[] initialValue)
public static char[] enterPassword(Component parent,
String title,
Object message,
char[] initialValue,
ImageIcon icon)
public static String getText(JTextComponent comp)
public static void fixTabKeys(Component... cs)
public static void limitSize(JTextComponent c,
int chars)
throws ClassCastException
ClassCastException - if the component's document is not an AbstractDocumentDocumentSizeFilter
public static void limitSize(JTextComponent c,
DBClassStore<?> store,
String column)
public static void limitSize(JTextComponent c,
MappingInfo mi,
String column)
public JComponent createComponentFor(Class<?> c)
String (via JTextField),
Number (via JFormattedTextField),
Boolean (via JCheckBox),
Color (via JColorChooser),
File (via JFileField),
and Date (via JTimeChooser);
others are simply handled via JTextField.
setValueFor(Object, JComponent),
getValueFor(JComponent)
public Number getNumberFor(JComponent field)
throws IllegalArgumentException
IllegalArgumentException
public JComponent createBoundField(Object obj,
String property,
Runnable runOnUpdate)
throws IllegalArgumentException
IllegalArgumentExceptionbind(JComponent, Object, String, Runnable, String)
public void bind(JComponent field,
Object obj,
String property,
Runnable runOnUpdate,
String changePropertyKey)
throws IllegalArgumentException
IllegalArgumentException
protected Method findMethod(Class<?> type,
String name)
public Object getValueFor(JComponent field)
throws IllegalArgumentException
IllegalArgumentException - if the given keyField is not supportedJCheckBox,
JComboBox,
JSpinner,
JFormattedTextField,
JTextComponent,
JSlider,
JColorChooser,
ValueRetriever
public void setValueFor(Object value,
JComponent field)
throws IllegalArgumentException,
ClassCastException
getValueFor(JComponent)
plus ValueSetter.
IllegalArgumentException
ClassCastException
public void setEditable(boolean flag,
Component... comp)
public void setEditable(Component c,
boolean flag)
public void installChangeListener(Runnable r,
Component... cs)
public void installChangeListener(Component comp,
Runnable r)
public void installChangeListener(Component comp,
Task<? extends RuntimeException> task)
throws IllegalArgumentException
IllegalArgumentException - if the given component is not supported for this task
public void installChangeListener(Component comp,
Runnable r,
String changeProperty)
public void installChangeListener(Component comp,
Task<? extends RuntimeException> task,
String changeProperty)
throws IllegalArgumentException
PropertyChangeListener with the given property
if everything else fails.
changeProperty - the change property to be used as a fallback solution - provided it's non-null
IllegalArgumentException
public static <T> T extractInterface(Component component,
Class<T> type)
public static Object getFormValue(Form form,
Object defaultValue,
String dialogTitle)
throws IOException
IOException
public static Object getFormValue(Form form,
ValueRetriever<?> retriever,
String dialogTitle)
throws IOException
form - the form to be queried for the value if the form is indeed dirtyretriever - retrieves the value to be used if the form is either not given or not dirtydialogTitle - the title to be used in the dialog when asked to save changes
IOExceptionForm.performSaveAction(),
Form.isDirty()public static String nullForEmpty(String str)
public static boolean isNotEmpty(String str)
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||