Search in sources :

Example 1 with Field

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

the class SwingUtil method newField.

@SuppressWarnings("unchecked")
static <T extends Field> T newField(final RecordDefinition recordDefinition, final String fieldName, final boolean editable) {
    Field field;
    final FieldDefinition fieldDefinition = recordDefinition.getField(fieldName);
    if (fieldDefinition == null) {
        throw new IllegalArgumentException("Cannot find field " + fieldName);
    } else {
        final boolean required = fieldDefinition.isRequired();
        final int length = fieldDefinition.getLength();
        CodeTable codeTable;
        if (recordDefinition.getIdFieldNames().contains(fieldName)) {
            codeTable = null;
        } else {
            codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
        }
        final DataType type = fieldDefinition.getDataType();
        int columns = length;
        if (columns <= 0) {
            columns = 10;
        } else if (columns > 50) {
            columns = 50;
        }
        final Class<?> javaClass = type.getJavaClass();
        if (codeTable != null) {
            if (editable) {
                final JComponent component = codeTable.getSwingEditor();
                if (component == null) {
                    field = newComboBox(fieldName, codeTable, required, -1, false);
                } else {
                    field = ((Field) component).clone();
                }
            } else {
                field = new ObjectLabelField(fieldName, columns, codeTable);
            }
        } else if (!editable) {
            final TextField textField = newTextField(fieldName, columns);
            textField.setEditable(false);
            field = textField;
        } else if (Number.class.isAssignableFrom(javaClass)) {
            final int scale = fieldDefinition.getScale();
            final Number minValue = fieldDefinition.getMinValue();
            final Number maxValue = fieldDefinition.getMaxValue();
            final NumberTextField numberTextField = new NumberTextField(fieldName, type, length, scale, minValue, maxValue);
            field = numberTextField;
        } else if (Date.class.isAssignableFrom(javaClass)) {
            field = newDateField(fieldName);
        } else if (Geometry.class.isAssignableFrom(javaClass)) {
            field = new ObjectLabelField(fieldName);
        } else {
            field = newTextField(fieldName, columns);
        }
    }
    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));
    }
    ((JComponent) field).setFont(FONT);
    return (T) field;
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) NumberTextField(com.revolsys.swing.field.NumberTextField) FieldDefinition(com.revolsys.record.schema.FieldDefinition) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) Point(java.awt.Point) Date(java.util.Date) NumberTextField(com.revolsys.swing.field.NumberTextField) DateField(com.revolsys.swing.field.DateField) JTextField(javax.swing.JTextField) Field(com.revolsys.swing.field.Field) TextField(com.revolsys.swing.field.TextField) ColorChooserField(com.revolsys.swing.field.ColorChooserField) ObjectLabelField(com.revolsys.swing.field.ObjectLabelField) DataType(com.revolsys.datatype.DataType) NumberTextField(com.revolsys.swing.field.NumberTextField) JTextField(javax.swing.JTextField) TextField(com.revolsys.swing.field.TextField) ObjectLabelField(com.revolsys.swing.field.ObjectLabelField)

Example 2 with Field

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

the class SwingUtil method setFieldValue.

static void setFieldValue(final JComponent field, final Object value) {
    Invoke.later(() -> {
        if (field instanceof Field) {
            final Field fieldObject = (Field) field;
            fieldObject.setFieldValue(value);
        } else if (field instanceof JLabel) {
            final JLabel label = (JLabel) field;
            String string;
            if (value == null) {
                string = "";
            } else {
                string = DataTypes.toString(value);
            }
            label.setText(string);
        } else if (field instanceof JTextField) {
            final JTextField textField = (JTextField) field;
            String string;
            if (value == null) {
                string = "";
            } else {
                string = DataTypes.toString(value);
            }
            textField.setText(string);
        } else if (field instanceof JTextArea) {
            final JTextArea textField = (JTextArea) field;
            String string;
            if (value == null) {
                string = "";
            } else {
                string = DataTypes.toString(value);
            }
            textField.setText(string);
        }
        final Container parent = field.getParent();
        if (parent != null) {
            final LayoutManager layout = parent.getLayout();
            if (layout != null) {
                layout.layoutContainer(parent);
            }
            field.revalidate();
        }
    });
}
Also used : NumberTextField(com.revolsys.swing.field.NumberTextField) DateField(com.revolsys.swing.field.DateField) JTextField(javax.swing.JTextField) Field(com.revolsys.swing.field.Field) TextField(com.revolsys.swing.field.TextField) ColorChooserField(com.revolsys.swing.field.ColorChooserField) ObjectLabelField(com.revolsys.swing.field.ObjectLabelField) Container(java.awt.Container) MenuContainer(java.awt.MenuContainer) JTextArea(javax.swing.JTextArea) LayoutManager(java.awt.LayoutManager) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField)

Example 3 with Field

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

the class Form method addNotify.

@Override
public void addNotify() {
    super.addNotify();
    for (final Entry<String, Field> entry : this.fieldByName.entrySet()) {
        final String fieldName = entry.getKey();
        final Field field = entry.getValue();
        Property.addListener(field, fieldName, this.propertyChangeSetValue);
    }
}
Also used : Field(com.revolsys.swing.field.Field)

Example 4 with Field

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

the class Form method getFieldValues.

public Map<String, Object> getFieldValues() {
    final Map<String, Object> values = new TreeMap<>();
    for (final Entry<String, Field> entry : this.fieldByName.entrySet()) {
        final String fieldName = entry.getKey();
        final Field field = entry.getValue();
        final Object fieldValue = field.getFieldValue();
        values.put(fieldName, fieldValue);
    }
    return values;
}
Also used : Field(com.revolsys.swing.field.Field) TreeMap(java.util.TreeMap)

Example 5 with Field

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

the class Form method addFields.

protected void addFields(final Component component) {
    if (component instanceof Field) {
        final Field field = (Field) component;
        setField(field);
    } else if (component instanceof Container) {
        final Container container = (Container) component;
        for (final Component childComponent : container.getComponents()) {
            addFields(childComponent);
        }
    }
}
Also used : Field(com.revolsys.swing.field.Field) Container(java.awt.Container) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Aggregations

Field (com.revolsys.swing.field.Field)43 NumberTextField (com.revolsys.swing.field.NumberTextField)15 ObjectLabelField (com.revolsys.swing.field.ObjectLabelField)15 Component (java.awt.Component)13 TextField (com.revolsys.swing.field.TextField)12 JComponent (javax.swing.JComponent)9 JTextField (javax.swing.JTextField)8 AbstractRecordQueryField (com.revolsys.swing.field.AbstractRecordQueryField)7 DateField (com.revolsys.swing.field.DateField)7 ColorChooserField (com.revolsys.swing.field.ColorChooserField)5 QueryWhereConditionField (com.revolsys.swing.field.QueryWhereConditionField)5 JXSearchField (org.jdesktop.swingx.JXSearchField)5 Container (java.awt.Container)4 JComboBox (javax.swing.JComboBox)4 RecordDefinition (com.revolsys.record.schema.RecordDefinition)3 FontChooserField (com.revolsys.swing.field.FontChooserField)3 LengthMeasureTextField (com.revolsys.swing.field.LengthMeasureTextField)3 MarkerField (com.revolsys.swing.map.component.MarkerField)3 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)3 BaseCloseable (com.revolsys.io.BaseCloseable)2