Search in sources :

Example 11 with FieldConfigDouble

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

the class FieldConfigDoubleTest method testCreateCopy.

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

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

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

Example 12 with FieldConfigDouble

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

the class FieldConfigDoubleTest method testGenerateExpression.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigDouble#generateExpression()}. Test method
 * for
 * {@link com.sldeditor.ui.detail.config.FieldConfigDouble#populateExpression(java.lang.Object, org.opengis.filter.expression.Expression)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigDouble#populateField(java.lang.Double)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigDouble#setTestValue(com.sldeditor.ui.detail.config.FieldId, double)}.
 * Test method for {@link com.sldeditor.ui.detail.config.FieldConfigDouble#getDoubleValue()}.
 */
@Test
public void testGenerateExpression() {
    boolean valueOnly = true;
    FieldConfigDouble field = new FieldConfigDouble(new FieldConfigCommonData(Double.class, FieldIdEnum.NAME, "label", valueOnly));
    double expectedValue = 1.0;
    field.populateField(expectedValue);
    double actualValue = field.getDoubleValue();
    assertTrue(Math.abs(actualValue - 0.0) < 0.001);
    field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue);
    actualValue = field.getDoubleValue();
    assertTrue(Math.abs(actualValue - 0.0) < 0.001);
    field.populateExpression(null);
    actualValue = field.getDoubleValue();
    assertTrue(Math.abs(actualValue - 0.0) < 0.001);
    field.createUI();
    field.populateField(expectedValue);
    actualValue = field.getDoubleValue();
    assertTrue(Math.abs(actualValue - expectedValue) < 0.001);
    double expectedValue2 = 0.134;
    field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue2);
    actualValue = field.getDoubleValue();
    assertTrue(Math.abs(actualValue - expectedValue2) < 0.001);
    Integer expectedValue3a = Integer.valueOf(42);
    field.populateExpression(expectedValue3a);
    actualValue = field.getDoubleValue();
    assertTrue(Math.abs(actualValue - expectedValue3a) < 0.001);
    Long expectedValue3b = Long.valueOf(4567);
    field.populateExpression(expectedValue3b);
    actualValue = field.getDoubleValue();
    assertTrue(Math.abs(actualValue - expectedValue3b) < 0.001);
    Double expectedValue3c = Double.valueOf(42.12);
    field.populateExpression(expectedValue3c);
    actualValue = field.getDoubleValue();
    assertTrue(Math.abs(actualValue - expectedValue3c) < 0.001);
    double expectedValue3d = 698.7;
    String expectedValue3dString = String.valueOf(expectedValue3d);
    field.populateExpression(expectedValue3dString);
    actualValue = field.getDoubleValue();
    assertTrue(Math.abs(actualValue - expectedValue3d) < 0.001);
}
Also used : FieldConfigDouble(com.sldeditor.ui.detail.config.FieldConfigDouble) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigDouble(com.sldeditor.ui.detail.config.FieldConfigDouble) Test(org.junit.Test)

Example 13 with FieldConfigDouble

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

the class ColourMapEntryPanel method createUI.

/**
 * Creates the UI.
 *
 * @param panelId the panel id
 */
private void createUI(Class<?> panelId) {
    TitledBorder title = BorderFactory.createTitledBorder(Localisation.getString(FieldConfigBase.class, "ColourMapEntryPanel.title"));
    setBorder(title);
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    label = new FieldConfigString(new FieldConfigCommonData(panelId, FieldIdEnum.RASTER_COLOURMAP_ENTRY_LABEL, Localisation.getField(FieldConfigBase.class, "ColourMapEntryPanel.label"), true, true, true), null);
    label.createUI();
    label.addDataChangedListener(this);
    fieldList.add(label);
    add(label.getPanel());
    colour = new FieldConfigColour(new FieldConfigCommonData(panelId, FieldIdEnum.RASTER_COLOURMAP_ENTRY_COLOUR, Localisation.getField(FieldConfigBase.class, "ColourMapEntryPanel.colour"), false, true, true));
    colour.createUI();
    colour.addDataChangedListener(this);
    fieldList.add(colour);
    add(colour.getPanel());
    opacity = new FieldConfigSlider(new FieldConfigCommonData(panelId, FieldIdEnum.RASTER_COLOURMAP_ENTRY_OPACITY, Localisation.getField(FieldConfigBase.class, "ColourMapEntryPanel.opacity"), false, true, true));
    opacity.createUI();
    opacity.addDataChangedListener(this);
    fieldList.add(opacity);
    add(opacity.getPanel());
    quantity = new FieldConfigDouble(new FieldConfigCommonData(panelId, FieldIdEnum.RASTER_COLOURMAP_ENTRY_QUANTITY, Localisation.getField(FieldConfigBase.class, "ColourMapEntryPanel.quantity"), false, true, true));
    quantity.createUI();
    quantity.addDataChangedListener(this);
    fieldList.add(quantity);
    add(quantity.getPanel());
    JPanel buttonPanel = new JPanel();
    // 
    // Apply button
    // 
    applyButton = new JButton(Localisation.getString(FieldConfigBase.class, "common.apply"));
    applyButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (parentObj != null) {
                ColourMapData data = new ColourMapData();
                data.setLabel(label.getStringValue());
                data.setColour(colour.getColourExpression());
                data.setOpacity(opacity.getExpression());
                data.setQuantity(quantity.getExpression());
                parentObj.colourMapEntryUpdated(data);
            }
        }
    });
    buttonPanel.add(applyButton);
    // 
    // Cancel button
    // 
    cancelButton = new JButton(Localisation.getString(FieldConfigBase.class, "common.cancel"));
    cancelButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setVisible(false);
        }
    });
    buttonPanel.add(cancelButton);
    add(buttonPanel);
}
Also used : JPanel(javax.swing.JPanel) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) FieldConfigDouble(com.sldeditor.ui.detail.config.FieldConfigDouble) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) FieldConfigSlider(com.sldeditor.ui.detail.config.FieldConfigSlider) TitledBorder(javax.swing.border.TitledBorder) ActionListener(java.awt.event.ActionListener) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour)

Example 14 with FieldConfigDouble

use of com.sldeditor.ui.detail.config.FieldConfigDouble 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 15 with FieldConfigDouble

use of com.sldeditor.ui.detail.config.FieldConfigDouble 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)

Aggregations

FieldConfigDouble (com.sldeditor.ui.detail.config.FieldConfigDouble)18 Test (org.junit.Test)15 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)12 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)7 FieldConfigSlider (com.sldeditor.ui.detail.config.FieldConfigSlider)6 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)6 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)5 NamedLayer (org.geotools.styling.NamedLayer)5 Rule (org.geotools.styling.Rule)5 Style (org.geotools.styling.Style)5 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)5 StrokeDetails (com.sldeditor.ui.detail.StrokeDetails)4 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)4 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)3 PointFillDetails (com.sldeditor.ui.detail.PointFillDetails)2 FieldConfigBoolean (com.sldeditor.ui.detail.config.FieldConfigBoolean)2 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)2 FieldConfigInteger (com.sldeditor.ui.detail.config.FieldConfigInteger)2 FieldConfigSymbolType (com.sldeditor.ui.detail.config.FieldConfigSymbolType)2 Geometry (com.vividsolutions.jts.geom.Geometry)2