Search in sources :

Example 21 with Field

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

Example 22 with Field

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

the class RecordTableCellEditor method stopCellEditing.

@Override
public boolean stopCellEditing() {
    boolean stopped = false;
    try {
        if (this.editorComponent instanceof Field) {
            final Field field = (Field) this.editorComponent;
            field.updateFieldValue();
        }
        stopped = super.stopCellEditing();
    } catch (final IndexOutOfBoundsException e) {
        return true;
    } catch (final Throwable t) {
        final int result = JOptionPane.showConfirmDialog(this.editorComponent, "<html><p><b>'" + getCellEditorValue() + "' is not a valid " + this.dataType.getValidationName() + ".</b></p><p>Discard changes (Yes) or edit field (No).</p></html>", "Invalid value", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE);
        if (result == JOptionPane.YES_OPTION) {
            cancelCellEditing();
            return true;
        } else {
            return false;
        }
    } finally {
        if (stopped) {
            if (this.editorComponent != null) {
                this.editorComponent.removeMouseListener(this.mouseListeners);
                this.editorComponent.removeKeyListener(this);
                if (this.editorComponent instanceof JComboBox) {
                    final JComboBox<?> comboBox = (JComboBox<?>) this.editorComponent;
                    final ComboBoxEditor editor = comboBox.getEditor();
                    final Component comboEditorComponent = editor.getEditorComponent();
                    comboEditorComponent.removeKeyListener(this);
                    comboEditorComponent.removeMouseListener(this.mouseListeners);
                } else if (this.editorComponent instanceof AbstractRecordQueryField) {
                    final AbstractRecordQueryField queryField = (AbstractRecordQueryField) this.editorComponent;
                    final TextField searchField = queryField.getSearchField();
                    searchField.removeKeyListener(this);
                    searchField.removeMouseListener(this.mouseListeners);
                }
                if (this.popupMenuListener != null) {
                    this.popupMenuListener.close();
                    this.popupMenuListener = null;
                }
            }
        }
    }
    return stopped;
}
Also used : JTextField(javax.swing.JTextField) Field(com.revolsys.swing.field.Field) TextField(com.revolsys.swing.field.TextField) AbstractRecordQueryField(com.revolsys.swing.field.AbstractRecordQueryField) JComboBox(javax.swing.JComboBox) JTextField(javax.swing.JTextField) TextField(com.revolsys.swing.field.TextField) AbstractRecordQueryField(com.revolsys.swing.field.AbstractRecordQueryField) JComponent(javax.swing.JComponent) Component(java.awt.Component) ComboBoxEditor(javax.swing.ComboBoxEditor)

Example 23 with Field

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

the class BaseTableCellEditor method stopCellEditing.

@Override
public boolean stopCellEditing() {
    boolean stopped = false;
    try {
        if (this.editorComponent instanceof Field) {
            final Field field = (Field) this.editorComponent;
            field.updateFieldValue();
        }
        stopped = super.stopCellEditing();
    } catch (final IndexOutOfBoundsException e) {
        return true;
    } catch (final Throwable t) {
        final int result = JOptionPane.showConfirmDialog(this.editorComponent, "<html><p><b>'" + getCellEditorValue() + "' is not a valid " + this.dataType.getValidationName() + ".</b></p><p>Discard changes (Yes) or edit field (No).</p></html>", "Invalid value", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE);
        if (result == JOptionPane.YES_OPTION) {
            cancelCellEditing();
            return true;
        } else {
            return false;
        }
    } finally {
        if (stopped) {
            if (this.editorComponent != null) {
                this.editorComponent.removeMouseListener(this.mouseListeners);
                this.editorComponent.removeKeyListener(this);
                if (this.editorComponent instanceof JComboBox) {
                    final JComboBox<?> comboBox = (JComboBox<?>) this.editorComponent;
                    final ComboBoxEditor editor = comboBox.getEditor();
                    final Component comboEditorComponent = editor.getEditorComponent();
                    comboEditorComponent.removeKeyListener(this);
                    comboEditorComponent.removeMouseListener(this.mouseListeners);
                }
            }
        }
    }
    return stopped;
}
Also used : JTextField(javax.swing.JTextField) Field(com.revolsys.swing.field.Field) JComboBox(javax.swing.JComboBox) JComponent(javax.swing.JComponent) Component(java.awt.Component) ComboBoxEditor(javax.swing.ComboBoxEditor)

Example 24 with Field

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

the class RecordTableCellEditor method getTableCellEditorComponent.

@Override
public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, int rowIndex, int columnIndex) {
    rowIndex = table.convertRowIndexToModel(rowIndex);
    columnIndex = table.convertColumnIndexToModel(columnIndex);
    this.oldValue = value;
    final AbstractRecordTableModel model = getTableModel();
    this.fieldName = model.getColumnFieldName(rowIndex, columnIndex);
    final RecordDefinition recordDefinition = model.getRecordDefinition();
    this.dataType = recordDefinition.getFieldType(this.fieldName);
    final Field field = newField(this.fieldName);
    this.editorComponent = (JComponent) field;
    if (this.editorComponent instanceof JTextField) {
        final JTextField textField = (JTextField) this.editorComponent;
        textField.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(WebColors.LightSteelBlue), BorderFactory.createEmptyBorder(1, 2, 1, 2)));
    } else if (this.editorComponent instanceof AbstractRecordQueryField) {
        final AbstractRecordQueryField queryField = (AbstractRecordQueryField) this.editorComponent;
        queryField.setSearchFieldBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(WebColors.LightSteelBlue), BorderFactory.createEmptyBorder(1, 2, 1, 2)));
    }
    this.editorComponent.setOpaque(false);
    SwingUtil.setFieldValue(this.editorComponent, value);
    this.rowIndex = rowIndex;
    this.columnIndex = columnIndex;
    this.editorComponent.addKeyListener(this);
    this.editorComponent.addMouseListener(this.mouseListeners);
    if (this.editorComponent instanceof JComboBox) {
        final JComboBox<?> comboBox = (JComboBox<?>) this.editorComponent;
        final ComboBoxEditor editor = comboBox.getEditor();
        final Component comboEditorComponent = editor.getEditorComponent();
        comboEditorComponent.addKeyListener(this);
        comboEditorComponent.addMouseListener(this.mouseListeners);
    } else if (this.editorComponent instanceof AbstractRecordQueryField) {
        final AbstractRecordQueryField queryField = (AbstractRecordQueryField) this.editorComponent;
        final TextField searchField = queryField.getSearchField();
        searchField.addKeyListener(this);
        searchField.addMouseListener(this.mouseListeners);
    }
    this.popupMenuListener = ShowMenuMouseListener.addListener(this.editorComponent, this.popupMenuFactory);
    return this.editorComponent;
}
Also used : JTextField(javax.swing.JTextField) Field(com.revolsys.swing.field.Field) TextField(com.revolsys.swing.field.TextField) AbstractRecordQueryField(com.revolsys.swing.field.AbstractRecordQueryField) AbstractRecordTableModel(com.revolsys.swing.table.record.model.AbstractRecordTableModel) JComboBox(javax.swing.JComboBox) JTextField(javax.swing.JTextField) TextField(com.revolsys.swing.field.TextField) AbstractRecordQueryField(com.revolsys.swing.field.AbstractRecordQueryField) JTextField(javax.swing.JTextField) JComponent(javax.swing.JComponent) Component(java.awt.Component) ComboBoxEditor(javax.swing.ComboBoxEditor) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 25 with Field

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

the class MenuFactory method getPopupMenuFactory.

public static MenuFactory getPopupMenuFactory(final JComponent component) {
    synchronized (component) {
        MenuFactory menuFactory = (MenuFactory) component.getClientProperty(KEY_POPUP_MENU);
        if (menuFactory == null) {
            String name = "Field";
            if (component instanceof Field) {
                final Field field = (Field) component;
                name += " " + field.getFieldName();
            }
            menuFactory = new MenuFactory(name);
            addToComponent(component, menuFactory);
        }
        return menuFactory;
    }
}
Also used : Field(com.revolsys.swing.field.Field)

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