use of com.revolsys.swing.field.NumberTextField 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;
}
use of com.revolsys.swing.field.NumberTextField 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;
}
use of com.revolsys.swing.field.NumberTextField in project com.revolsys.open by revolsys.
the class LayerRecordForm method addDoubleField.
protected void addDoubleField(final String fieldName, final int length, final int scale, final Double minimumValie, final Double maximumValue) {
final DataType dataType = DataTypes.DOUBLE;
final NumberTextField field = new NumberTextField(fieldName, dataType, length, scale, minimumValie, maximumValue);
addField(fieldName, field);
}
use of com.revolsys.swing.field.NumberTextField in project com.revolsys.open by revolsys.
the class LayerRecordForm method addNumberField.
protected void addNumberField(final String fieldName, final DataType dataType, final int length, final Number minimumValue, final Number maximumValue) {
final NumberTextField field = new NumberTextField(fieldName, dataType, length, 0, minimumValue, maximumValue);
addField(fieldName, field);
}
use of com.revolsys.swing.field.NumberTextField in project com.revolsys.open by revolsys.
the class GeometryCoordinatesTableModel method getEditorField.
@Override
public JComponent getEditorField(final int rowIndex, final int columnIndex, final Object value) {
if (columnIndex < this.numIndexItems) {
return null;
} else {
final int axisIndex = columnIndex - this.numIndexItems;
final int scale;
if (this.geometryFactory.isFloating()) {
scale = 7;
} else {
scale = (int) Math.ceil(Math.log10(this.geometryFactory.getScale(axisIndex)));
}
final NumberTextField field = new NumberTextField(DataTypes.DOUBLE, 20, scale);
field.setFieldValue(value);
field.setUndoManager(getForm().getUndoManager());
return field;
}
}
Aggregations