Search in sources :

Example 1 with TextArea

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

the class FieldCalculator method initFieldPanel.

@Override
protected JPanel initFieldPanel() {
    final FieldDefinition fieldDefinition = this.getFieldDefinition();
    final String fieldName = fieldDefinition.getName();
    final JPanel fieldPanel = new JPanel(new VerticalLayout());
    final ToolBar toolBar = new ToolBar();
    fieldPanel.add(toolBar);
    this.expressionField = new TextArea("script", 8, 1);
    fieldPanel.add(new JScrollPane(this.expressionField));
    this.expressionField.getDocument().addDocumentListener(this);
    final AbstractRecordLayer layer = getLayer();
    final List<String> fieldNames = layer.getFieldNames();
    final ComboBox<String> fieldNamesField = ComboBox.newComboBox("fieldNames", fieldNames, (final Object name) -> {
        return layer.getFieldTitle((String) name);
    });
    toolBar.addComponent("fieldName", fieldNamesField);
    toolBar.add(fieldNamesField);
    fieldNamesField.setMaximumSize(new Dimension(250, 30));
    final Runnable addFieldAction = () -> {
        final String selectedFieldName = fieldNamesField.getFieldValue();
        insertText(selectedFieldName);
    };
    toolBar.addButton("fieldName", "Add field name", "add", addFieldAction);
    for (final String text : Arrays.asList("+", "-", "*", "/")) {
        addTextButton("operators", toolBar, text, text);
    }
    addTextButton("condition", toolBar, "if", "if (expression) {\n  newValue;\n} else {\n  " + fieldName + ";\n}");
    addTextButton("codeTable", toolBar, "Code ID", "codeId('codeFieldName', codeValue)");
    addTextButton("codeTable", toolBar, "Code Value", "codeValue('codeFieldName', codeValue)");
    return fieldPanel;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) TextArea(com.revolsys.swing.field.TextArea) JTextArea(javax.swing.JTextArea) FieldDefinition(com.revolsys.record.schema.FieldDefinition) Dimension(java.awt.Dimension) ToolBar(com.revolsys.swing.toolbar.ToolBar) VerticalLayout(org.jdesktop.swingx.VerticalLayout) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer)

Example 2 with TextArea

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

the class FieldCalculator method initErrorsPanel.

@Override
protected JComponent initErrorsPanel() {
    final Color background = new JPanel().getBackground();
    this.errorsField = new TextArea("errors", 5, 1);
    this.errorsField.setEditable(false);
    this.errorsField.setForeground(WebColors.Red);
    this.errorsField.setBackground(background);
    final JScrollPane errorScroll = new JScrollPane(this.errorsField);
    errorScroll.setBorder(BorderFactory.createTitledBorder("Errors"));
    errorScroll.setBackground(background);
    return errorScroll;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) TextArea(com.revolsys.swing.field.TextArea) JTextArea(javax.swing.JTextArea) Color(java.awt.Color)

Aggregations

TextArea (com.revolsys.swing.field.TextArea)2 JPanel (javax.swing.JPanel)2 JScrollPane (javax.swing.JScrollPane)2 JTextArea (javax.swing.JTextArea)2 FieldDefinition (com.revolsys.record.schema.FieldDefinition)1 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)1 ToolBar (com.revolsys.swing.toolbar.ToolBar)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 VerticalLayout (org.jdesktop.swingx.VerticalLayout)1