Search in sources :

Example 1 with TextField

use of com.revolsys.swing.field.TextField 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 TextField

use of com.revolsys.swing.field.TextField 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 TextField

use of com.revolsys.swing.field.TextField 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 4 with TextField

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

the class BaseStylePanel method addTextField.

protected void addTextField(final JPanel container, final Object object, final String fieldName, final int columns) {
    SwingUtil.addLabel(container, fieldName);
    final TextField field = new TextField(fieldName, columns);
    field.setFieldValue(Property.get(object, fieldName));
    Property.addListener(field, fieldName, this);
    container.add(field);
}
Also used : LengthMeasureTextField(com.revolsys.swing.field.LengthMeasureTextField) JTextField(javax.swing.JTextField) TextField(com.revolsys.swing.field.TextField)

Example 5 with TextField

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

the class BaseStylePanel method newField.

@SuppressWarnings("unchecked")
protected Field newField(final String fieldName, final Class<?> fieldClass, final Object value) {
    Field field;
    if (fieldName.equals("visible")) {
        this.visibleField = new CheckBox(fieldName, value);
        field = this.visibleField;
    } else if (fieldName.equals("textFaceName")) {
        field = new FontChooserField(fieldName, (String) value);
    } else if (fieldName.endsWith("HorizontalAlignment")) {
        field = newHorizontalAlignmentField(fieldName, (String) value);
    } else if (fieldName.endsWith("VerticalAlignment")) {
        field = newVerticalAlignmentField(fieldName, (String) value);
    } else if (fieldName.equals("lineCap")) {
        field = newLineCapField((LineCap) value);
    } else if (fieldName.equals("lineJoin")) {
        field = newLineJoinField((LineJoin) value);
    } else if (fieldName.equals("lineDashArray")) {
        field = new DashField(fieldName, (List<Quantity<Length>>) value);
    } else if (fieldName.equals("queryFilter")) {
        final AbstractRecordLayer layer = getLayer();
        field = new QueryFilterField(layer, fieldName, (String) value);
        field.setFieldValue(value);
        Property.addListener(field, fieldName, this);
    } else if (fieldName.equals("marker")) {
        field = new MarkerField(fieldName, value);
    } else if (fieldName.endsWith("OrientationType")) {
        final ComboBox<String> orientationTypeField = ComboBox.newComboBox(fieldName, "auto", "none");
        orientationTypeField.setFieldValue(value);
        field = orientationTypeField;
    } else if (fieldName.equals("markerPlacementType")) {
        final ComboBox<String> placementField = ComboBox.newComboBox(fieldName, "auto", "center", "vertex(0)", "vertex(n)", "vertices", "segment(0)", "segment(n)", "segments");
        placementField.setFieldValue(value);
        field = placementField;
    } else if (fieldName.equals("textPlacementType")) {
        final ComboBox<String> placementField = ComboBox.newComboBox(fieldName, "auto", "center", "vertex(0)", "vertex(n)", "segment(0)", "segment(n)");
        placementField.setFieldValue(value);
        field = placementField;
    } else if (fieldName.endsWith("Scale")) {
        field = newScaleField(fieldName, (Long) value);
    } else if (Color.class.equals(fieldClass)) {
        field = new ColorChooserField(fieldName, (Color) value);
    } else if (Boolean.TYPE.equals(fieldClass) || Boolean.class.equals(fieldClass)) {
        field = new CheckBox(fieldName, value);
    } else if (Quantity.class.equals(fieldClass)) {
        field = new LengthMeasureTextField(fieldName, (Quantity<Length>) value, CustomUnits.PIXEL);
    } else {
        field = new TextField(fieldName, value, 40);
    }
    return field;
}
Also used : FontChooserField(com.revolsys.swing.field.FontChooserField) ComboBox(com.revolsys.swing.field.ComboBox) ColorChooserField(com.revolsys.swing.field.ColorChooserField) Color(java.awt.Color) Quantity(javax.measure.Quantity) LengthMeasureTextField(com.revolsys.swing.field.LengthMeasureTextField) FontChooserField(com.revolsys.swing.field.FontChooserField) MarkerField(com.revolsys.swing.map.component.MarkerField) JTextField(javax.swing.JTextField) Field(com.revolsys.swing.field.Field) TextField(com.revolsys.swing.field.TextField) ColorChooserField(com.revolsys.swing.field.ColorChooserField) Length(javax.measure.quantity.Length) CheckBox(com.revolsys.swing.field.CheckBox) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) LengthMeasureTextField(com.revolsys.swing.field.LengthMeasureTextField) LengthMeasureTextField(com.revolsys.swing.field.LengthMeasureTextField) JTextField(javax.swing.JTextField) TextField(com.revolsys.swing.field.TextField) List(java.util.List) ArrayList(java.util.ArrayList) LineCap(com.revolsys.geometry.model.LineCap) MarkerField(com.revolsys.swing.map.component.MarkerField)

Aggregations

TextField (com.revolsys.swing.field.TextField)15 JTextField (javax.swing.JTextField)8 ValueField (com.revolsys.swing.component.ValueField)7 Field (com.revolsys.swing.field.Field)5 ColorChooserField (com.revolsys.swing.field.ColorChooserField)4 NumberTextField (com.revolsys.swing.field.NumberTextField)4 JComponent (javax.swing.JComponent)4 DateField (com.revolsys.swing.field.DateField)3 ObjectLabelField (com.revolsys.swing.field.ObjectLabelField)3 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 LinkedHashMapEx (com.revolsys.collection.map.LinkedHashMapEx)2 MapEx (com.revolsys.collection.map.MapEx)2 AbstractRecordQueryField (com.revolsys.swing.field.AbstractRecordQueryField)2 CheckBox (com.revolsys.swing.field.CheckBox)2 LengthMeasureTextField (com.revolsys.swing.field.LengthMeasureTextField)2 PasswordField (com.revolsys.swing.field.PasswordField)2 Color (java.awt.Color)2 Component (java.awt.Component)2 Dimension (java.awt.Dimension)2