Search in sources :

Example 1 with DateField

use of com.revolsys.swing.field.DateField in project com.revolsys.open by revolsys.

the class SwingUtil method newField.

@SuppressWarnings("unchecked")
static <T extends JComponent> T newField(final Class<?> fieldClass, final String fieldName, final Object fieldValue) {
    JComponent field;
    if (Number.class.isAssignableFrom(fieldClass)) {
        final NumberTextField numberTextField = new NumberTextField(fieldName, DataTypes.DOUBLE, 10, 2);
        if (fieldValue instanceof Number) {
            final Number number = (Number) fieldValue;
            numberTextField.setFieldValue(number);
        }
        field = numberTextField;
    } else if (Date.class.isAssignableFrom(fieldClass)) {
        final DateField dateField = newDateField(fieldName);
        if (fieldValue instanceof Date) {
            final Date date = (Date) fieldValue;
            dateField.setDate(date);
        }
        field = dateField;
    } else if (Geometry.class.isAssignableFrom(fieldClass)) {
        final ObjectLabelField objectField = new ObjectLabelField(fieldName);
        objectField.setFieldValue(fieldValue);
        field = objectField;
    } else if (Color.class.isAssignableFrom(fieldClass)) {
        field = new ColorChooserField(fieldName, (Color) fieldValue);
    } else if (Boolean.class.isAssignableFrom(fieldClass)) {
        field = new CheckBox(fieldName, fieldValue);
    } else {
        final TextField textField = new TextField(fieldName, fieldValue);
        textField.setColumns(50);
        MenuFactory.getPopupMenuFactory(textField);
        field = textField;
    }
    if (field instanceof JTextField) {
        final JTextField textField = (JTextField) field;
        final int preferedWidth = textField.getPreferredSize().width;
        textField.setMinimumSize(new Dimension(preferedWidth, 0));
        textField.setMaximumSize(new Dimension(preferedWidth, Integer.MAX_VALUE));
        textField.setText(DataTypes.toString(fieldValue));
    }
    field.setFont(FONT);
    return (T) field;
}
Also used : NumberTextField(com.revolsys.swing.field.NumberTextField) ColorChooserField(com.revolsys.swing.field.ColorChooserField) Color(java.awt.Color) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) Date(java.util.Date) Point(java.awt.Point) CheckBox(com.revolsys.swing.field.CheckBox) JCheckBox(javax.swing.JCheckBox) NumberTextField(com.revolsys.swing.field.NumberTextField) JTextField(javax.swing.JTextField) TextField(com.revolsys.swing.field.TextField) DateField(com.revolsys.swing.field.DateField) ObjectLabelField(com.revolsys.swing.field.ObjectLabelField)

Example 2 with DateField

use of com.revolsys.swing.field.DateField in project com.revolsys.open by revolsys.

the class FieldFilterPanel method removeListeners.

@SuppressWarnings("rawtypes")
private void removeListeners(final JComponent component) {
    if (component instanceof AbstractRecordQueryField) {
        final AbstractRecordQueryField queryField = (AbstractRecordQueryField) component;
        queryField.removePropertyChangeListener("selectedRecord", this);
    } else if (component instanceof JXSearchField) {
        final JXSearchField searchTextField = (JXSearchField) component;
        searchTextField.removeActionListener(this);
    } else if (component instanceof JComboBox) {
        final JComboBox comboField = (JComboBox) component;
        comboField.removeActionListener(this);
    } else if (component instanceof DateField) {
        final DateField dateField = (DateField) component;
        dateField.removeActionListener(this);
    }
    if (component instanceof Field) {
        final Field field = (Field) component;
        final String fieldName = field.getFieldName();
        Property.removeListener(field, fieldName, this);
    }
}
Also used : JXSearchField(org.jdesktop.swingx.JXSearchField) DateField(com.revolsys.swing.field.DateField) AbstractRecordQueryField(com.revolsys.swing.field.AbstractRecordQueryField) Field(com.revolsys.swing.field.Field) TextField(com.revolsys.swing.field.TextField) QueryWhereConditionField(com.revolsys.swing.field.QueryWhereConditionField) JXSearchField(org.jdesktop.swingx.JXSearchField) JComboBox(javax.swing.JComboBox) AbstractRecordQueryField(com.revolsys.swing.field.AbstractRecordQueryField) DateField(com.revolsys.swing.field.DateField)

Example 3 with DateField

use of com.revolsys.swing.field.DateField in project com.revolsys.open by revolsys.

the class FieldFilterPanel method addListeners.

private void addListeners(final JComponent component) {
    if (component instanceof AbstractRecordQueryField) {
        final AbstractRecordQueryField queryField = (AbstractRecordQueryField) component;
        queryField.addPropertyChangeListener("selectedRecord", this);
    } else if (component instanceof JXSearchField) {
        final JXSearchField searchTextField = (JXSearchField) component;
        searchTextField.addActionListener(this);
    } else if (component instanceof JTextComponent) {
        final JTextComponent searchTextField = (JTextComponent) component;
        searchTextField.getDocument().addDocumentListener(this);
    } else if (component instanceof DateField) {
        final DateField dateField = (DateField) component;
        dateField.addActionListener(this);
    }
    if (component instanceof Field) {
        final Field field = (Field) component;
        final String fieldName = field.getFieldName();
        Property.addListener(field, fieldName, this);
    }
}
Also used : JXSearchField(org.jdesktop.swingx.JXSearchField) DateField(com.revolsys.swing.field.DateField) AbstractRecordQueryField(com.revolsys.swing.field.AbstractRecordQueryField) Field(com.revolsys.swing.field.Field) TextField(com.revolsys.swing.field.TextField) QueryWhereConditionField(com.revolsys.swing.field.QueryWhereConditionField) JXSearchField(org.jdesktop.swingx.JXSearchField) JTextComponent(javax.swing.text.JTextComponent) AbstractRecordQueryField(com.revolsys.swing.field.AbstractRecordQueryField) DateField(com.revolsys.swing.field.DateField)

Example 4 with DateField

use of com.revolsys.swing.field.DateField in project com.revolsys.open by revolsys.

the class SwingUtil method newDateField.

static DateField newDateField(final String fieldName) {
    final DateField dateField = new DateField(fieldName);
    dateField.setFormats("yyyy-MM-dd", "yyyy/MM/dd", "yyyy-MMM-dd", "yyyy/MMM/dd");
    MenuFactory.getPopupMenuFactory(dateField.getEditor());
    return dateField;
}
Also used : DateField(com.revolsys.swing.field.DateField)

Aggregations

DateField (com.revolsys.swing.field.DateField)4 TextField (com.revolsys.swing.field.TextField)3 AbstractRecordQueryField (com.revolsys.swing.field.AbstractRecordQueryField)2 Field (com.revolsys.swing.field.Field)2 QueryWhereConditionField (com.revolsys.swing.field.QueryWhereConditionField)2 JXSearchField (org.jdesktop.swingx.JXSearchField)2 CheckBox (com.revolsys.swing.field.CheckBox)1 ColorChooserField (com.revolsys.swing.field.ColorChooserField)1 NumberTextField (com.revolsys.swing.field.NumberTextField)1 ObjectLabelField (com.revolsys.swing.field.ObjectLabelField)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 Point (java.awt.Point)1 Date (java.util.Date)1 JCheckBox (javax.swing.JCheckBox)1 JComboBox (javax.swing.JComboBox)1 JComponent (javax.swing.JComponent)1 JTextField (javax.swing.JTextField)1 JTextComponent (javax.swing.text.JTextComponent)1