Search in sources :

Example 11 with FieldConfigInteger

use of com.sldeditor.ui.detail.config.FieldConfigInteger in project sldeditor by robward-scisys.

the class VOGeoServerLabelling method includeValue.

/**
 * Find out whether to include value based on the value of another field.
 *
 * @param field the field
 * @return true, if successful
 */
private boolean includeValue(FieldIdEnum field) {
    DefaultOverride override = overrideMap.get(field);
    if (override != null) {
        String value = null;
        FieldConfigBase fieldConfig = fieldConfigManager.get(override.getField());
        if (fieldConfig instanceof FieldConfigBoolean) {
            value = String.valueOf(fieldConfigVisitor.getBoolean(override.getField()));
        } else if (fieldConfig instanceof FieldConfigInteger) {
            value = String.valueOf(fieldConfigVisitor.getInteger(override.getField()));
        } else if (fieldConfig instanceof FieldConfigDouble) {
            value = String.valueOf(fieldConfigVisitor.getDouble(override.getField()));
        } else if (fieldConfig instanceof FieldConfigEnum) {
            value = String.valueOf(fieldConfigVisitor.getComboBox(override.getField()));
        } else {
            ConsoleManager.getInstance().error(this, "Unsupported field type : " + field + " " + fieldConfig.getClass().getName());
        }
        if (value != null) {
            for (String legalValue : override.getLegalValues()) {
                if (value.compareToIgnoreCase(legalValue) == 0) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FieldConfigInteger(com.sldeditor.ui.detail.config.FieldConfigInteger) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) FieldConfigDouble(com.sldeditor.ui.detail.config.FieldConfigDouble) FieldConfigEnum(com.sldeditor.ui.detail.config.FieldConfigEnum) FieldConfigBoolean(com.sldeditor.ui.detail.config.FieldConfigBoolean)

Example 12 with FieldConfigInteger

use of com.sldeditor.ui.detail.config.FieldConfigInteger in project sldeditor by robward-scisys.

the class FilterManager method convertParameters.

/**
 * Convert function parameters to ui components.
 *
 * @param panelId the panel id
 * @param functionName the function name
 * @return the list of ui components to display
 */
@Override
public List<GroupConfigInterface> convertParameters(Class<?> panelId, FunctionName functionName) {
    List<GroupConfigInterface> groupConfigList = new ArrayList<GroupConfigInterface>();
    if (functionName != null) {
        GroupConfig groupConfig = new GroupConfig();
        StringBuilder funcPrototypeStringBuilder = new StringBuilder();
        funcPrototypeStringBuilder.append(functionName.getName());
        funcPrototypeStringBuilder.append("(");
        int argCount = functionName.getArgumentCount();
        if (functionName.getArgumentCount() < 0) {
            argCount *= -1;
        }
        for (int index = 0; index < argCount; index++) {
            int argIndex = index;
            if (argIndex >= functionName.getArguments().size()) {
                argIndex = functionName.getArguments().size() - 1;
            }
            String label = functionName.getArgumentNames().get(argIndex);
            Parameter<?> parameterType = functionName.getArguments().get(argIndex);
            boolean valueOnly = false;
            FieldIdEnum id = FieldIdEnum.UNKNOWN;
            if (index > 0) {
                funcPrototypeStringBuilder.append(", ");
            }
            Class<?> type = parameterType.getType();
            funcPrototypeStringBuilder.append(type.getSimpleName());
            FieldConfigBase fieldConfig = null;
            FieldConfigCommonData commonData = new FieldConfigCommonData(panelId, id, label, valueOnly);
            if (type == java.lang.Number.class) {
                fieldConfig = new FieldConfigDouble(commonData);
            } else if (type == Double.class) {
                fieldConfig = new FieldConfigDouble(commonData);
            } else if (type == Float.class) {
                fieldConfig = new FieldConfigDouble(commonData);
            } else if (type == Integer.class) {
                fieldConfig = new FieldConfigInteger(commonData);
            } else if (type == Long.class) {
                fieldConfig = new FieldConfigInteger(commonData);
            } else if (type == String.class) {
                fieldConfig = new FieldConfigString(commonData, null);
            } else if (type == Object.class) {
                fieldConfig = new FieldConfigString(commonData, null);
            } else if (type == Boolean.class) {
                fieldConfig = new FieldConfigBoolean(commonData);
            } else if (type == Geometry.class) {
                fieldConfig = new FieldConfigGeometry(commonData, null);
            } else if (type == org.opengis.geometry.Geometry.class) {
                fieldConfig = new FieldConfigGeometry(commonData, null);
            } else if (type == LineString.class) {
                fieldConfig = new FieldConfigGeometry(commonData, null);
            } else if (type == Date.class) {
                fieldConfig = new FieldConfigDate(commonData);
            } else if (type == Class.class) {
                fieldConfig = new FieldConfigString(commonData, null);
            } else if (type == Classifier.class) {
                fieldConfig = new FieldConfigString(commonData, null);
            } else if (type == Unit.class) {
                fieldConfig = new FieldConfigMapUnits(commonData);
            } else if (type == Comparable.class) {
                fieldConfig = new FieldConfigString(commonData, null);
            } else if (type == Color.class) {
                fieldConfig = new FieldConfigColour(commonData);
            } else {
                ConsoleManager.getInstance().error(this, Localisation.getField(ExpressionPanelv2.class, "FilterManager.error1") + type.getName());
            }
            groupConfig.addField(fieldConfig);
        }
        funcPrototypeStringBuilder.append(")");
        groupConfig.setLabel(funcPrototypeStringBuilder.toString());
        groupConfigList.add(groupConfig);
    }
    return groupConfigList;
}
Also used : FieldConfigDate(com.sldeditor.ui.detail.config.FieldConfigDate) FieldConfigGeometry(com.sldeditor.ui.detail.config.FieldConfigGeometry) FieldConfigDouble(com.sldeditor.ui.detail.config.FieldConfigDouble) ArrayList(java.util.ArrayList) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) LineString(com.vividsolutions.jts.geom.LineString) Classifier(org.geotools.filter.function.Classifier) RangedClassifier(org.geotools.filter.function.RangedClassifier) FieldConfigMapUnits(com.sldeditor.ui.detail.config.FieldConfigMapUnits) GroupConfig(com.sldeditor.ui.detail.config.base.GroupConfig) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) FieldConfigBoolean(com.sldeditor.ui.detail.config.FieldConfigBoolean) FieldConfigInteger(com.sldeditor.ui.detail.config.FieldConfigInteger) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) FieldConfigBoolean(com.sldeditor.ui.detail.config.FieldConfigBoolean) FieldConfigDouble(com.sldeditor.ui.detail.config.FieldConfigDouble) Point(com.vividsolutions.jts.geom.Point) Disjoint(com.sldeditor.filter.v2.function.geometry.Disjoint) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Date(java.util.Date) FieldConfigDate(com.sldeditor.ui.detail.config.FieldConfigDate) FieldConfigInteger(com.sldeditor.ui.detail.config.FieldConfigInteger) Geometry(com.vividsolutions.jts.geom.Geometry) FieldConfigGeometry(com.sldeditor.ui.detail.config.FieldConfigGeometry) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum)

Example 13 with FieldConfigInteger

use of com.sldeditor.ui.detail.config.FieldConfigInteger in project sldeditor by robward-scisys.

the class ColourRampPanel method populateValue.

/**
 * Populate value.
 *
 * @param spinner the spinner
 * @param colorMapEntry the color map entry
 */
private void populateValue(FieldConfigInteger spinner, ColorMapEntry colorMapEntry) {
    if (spinner == null) {
        return;
    }
    if (colorMapEntry == null) {
        return;
    }
    int quantity = 1;
    Expression quantityExpression = colorMapEntry.getQuantity();
    if (quantityExpression != null) {
        Object quantityValue = ((LiteralExpressionImpl) quantityExpression).getValue();
        if (quantityValue instanceof Integer) {
            quantity = ((Integer) quantityValue).intValue();
        } else if (quantityValue instanceof Double) {
            quantity = ((Double) quantityValue).intValue();
        } else if (quantityValue instanceof String) {
            quantity = Double.valueOf((String) quantityValue).intValue();
        }
    }
    spinner.populateField(quantity);
}
Also used : FieldConfigInteger(com.sldeditor.ui.detail.config.FieldConfigInteger) Expression(org.opengis.filter.expression.Expression) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl)

Example 14 with FieldConfigInteger

use of com.sldeditor.ui.detail.config.FieldConfigInteger in project sldeditor by robward-scisys.

the class FieldConfigIntegerTest method testGenerateExpression.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigInteger#generateExpression()}. Test method
 * for
 * {@link com.sldeditor.ui.detail.config.FieldConfigInteger#populateExpression(java.lang.Object, org.opengis.filter.expression.Expression)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigInteger#setTestValue(com.sldeditor.ui.detail.config.FieldId, int)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigInteger#populateField(java.lang.Integer)}.
 * Test method for {@link com.sldeditor.ui.detail.config.FieldConfigInteger#getIntValue()}.
 */
@Test
public void testGenerateExpression() {
    boolean valueOnly = true;
    FieldConfigInteger field = new FieldConfigInteger(new FieldConfigCommonData(Integer.class, FieldIdEnum.NAME, "label", valueOnly));
    int expectedValue = 1;
    field.populateField(expectedValue);
    assertEquals(0, field.getIntValue());
    field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue);
    assertEquals(0, field.getIntValue());
    field.populateExpression(null);
    assertEquals(0, field.getIntValue());
    field.createUI();
    field.createUI();
    field.populateField(expectedValue);
    assertEquals(expectedValue, field.getIntValue());
    int expectedValue2 = 134;
    field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue2);
    assertEquals(expectedValue2, field.getIntValue());
    Integer expectedValue3a = Integer.valueOf(42);
    field.populateExpression(expectedValue3a);
    assertEquals(expectedValue3a.intValue(), field.getIntValue());
    Long expectedValue3b = Long.valueOf(4567);
    field.populateExpression(expectedValue3b);
    assertEquals(expectedValue3b.intValue(), field.getIntValue());
    Double expectedValue3c = Double.valueOf(42.12);
    field.populateExpression(expectedValue3c);
    assertEquals(expectedValue3c.intValue(), field.getIntValue());
    String expectedValue3d = String.valueOf(6987);
    field.populateExpression(expectedValue3d);
    assertEquals(Integer.valueOf(expectedValue3d).intValue(), field.getIntValue());
    String expectedValue3e = String.valueOf(6987.0);
    field.populateExpression(expectedValue3e);
    int intValue = Double.valueOf(expectedValue3e).intValue();
    assertEquals(intValue, field.getIntValue());
}
Also used : FieldConfigInteger(com.sldeditor.ui.detail.config.FieldConfigInteger) FieldConfigInteger(com.sldeditor.ui.detail.config.FieldConfigInteger) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) Test(org.junit.Test)

Example 15 with FieldConfigInteger

use of com.sldeditor.ui.detail.config.FieldConfigInteger in project sldeditor by robward-scisys.

the class FieldConfigIntegerTest method testCreateCopy.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigInteger#createCopy(com.sldeditor.ui.detail.config.FieldConfigBase)}.
 */
@Test
public void testCreateCopy() {
    boolean valueOnly = true;
    class TestFieldConfigInteger extends FieldConfigInteger {

        public TestFieldConfigInteger(FieldConfigCommonData commonData) {
            super(commonData);
        }

        public FieldConfigPopulate callCreateCopy(FieldConfigBase fieldConfigBase) {
            return createCopy(fieldConfigBase);
        }
    }
    TestFieldConfigInteger field = new TestFieldConfigInteger(new FieldConfigCommonData(Integer.class, FieldIdEnum.NAME, "label", valueOnly));
    FieldConfigInteger copy = (FieldConfigInteger) field.callCreateCopy(null);
    assertNull(copy);
    copy = (FieldConfigInteger) field.callCreateCopy(field);
    assertEquals(field.getFieldId(), copy.getFieldId());
    assertTrue(field.getLabel().compareTo(copy.getLabel()) == 0);
    assertEquals(field.isValueOnly(), copy.isValueOnly());
}
Also used : FieldConfigInteger(com.sldeditor.ui.detail.config.FieldConfigInteger) FieldConfigInteger(com.sldeditor.ui.detail.config.FieldConfigInteger) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) Test(org.junit.Test)

Aggregations

FieldConfigInteger (com.sldeditor.ui.detail.config.FieldConfigInteger)16 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)14 Test (org.junit.Test)11 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)4 Geometry (com.vividsolutions.jts.geom.Geometry)4 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)3 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)3 FieldConfigPopulation (com.sldeditor.ui.detail.config.FieldConfigPopulation)3 FieldConfigBoolean (com.sldeditor.ui.detail.config.FieldConfigBoolean)2 FieldConfigDouble (com.sldeditor.ui.detail.config.FieldConfigDouble)2 BoxLayout (javax.swing.BoxLayout)2 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)2 FeatureTypeConstraint (org.geotools.styling.FeatureTypeConstraint)2 Expression (org.opengis.filter.expression.Expression)2 ColourRamp (com.sldeditor.colourramp.ColourRamp)1 ColourRampConfigPanel (com.sldeditor.colourramp.ColourRampConfigPanel)1 UndoEvent (com.sldeditor.common.undo.UndoEvent)1 XMLTwoColourRamp (com.sldeditor.common.xml.ui.XMLTwoColourRamp)1 Disjoint (com.sldeditor.filter.v2.function.geometry.Disjoint)1 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)1