Search in sources :

Example 1 with OptionGroup

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

the class BasePanel method populateGroup.

/**
 * Populate group.
 *
 * @param parent the parent
 * @param parentBox the parent box
 * @param groupConfig the group config
 * @param parentField the parent field
 */
private void populateGroup(UpdateSymbolInterface parent, Box parentBox, GroupConfigInterface groupConfig, FieldConfigBase parentField) {
    groupConfig.createTitle(parentBox, parent);
    if (groupConfig instanceof GroupConfig) {
        GroupConfig group = (GroupConfig) groupConfig;
        List<FieldConfigBase> fieldList = group.getFieldConfigList();
        fieldConfigManager.addGroup(group);
        // Register for notifications when data has changed
        registerForSymbolUpdates(fieldList, parent);
        // Create field user interface
        for (FieldConfigBase field : fieldList) {
            field.setParent(parentField);
            addField(parentBox, parentField, field);
        }
        for (GroupConfigInterface subGroup : group.getSubGroupList()) {
            populateGroup(parent, parentBox, subGroup, parentField);
        }
    } else if (groupConfig instanceof MultiOptionGroup) {
        MultiOptionGroup multiOption = (MultiOptionGroup) groupConfig;
        fieldConfigManager.addMultiOptionGroup(multiOption);
        multiOption.createUI(fieldConfigManager, parentBox, parent, parent.getClass());
        for (OptionGroup optionGroup : multiOption.getGroupList()) {
            for (GroupConfigInterface optionGroupConfig : optionGroup.getGroupList()) {
                if (optionGroupConfig instanceof GroupConfig) {
                    populateOptionGroup(parent, (GroupConfig) optionGroupConfig);
                }
            }
        }
    }
}
Also used : OptionGroup(com.sldeditor.ui.detail.config.base.OptionGroup) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) GroupConfig(com.sldeditor.ui.detail.config.base.GroupConfig) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup)

Example 2 with OptionGroup

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

the class VOGeoServerContrastEnhancementNormalize method updateSymbol.

/*
     * (non-Javadoc)
     * 
     * @see
     * com.sldeditor.ui.detail.vendor.geoserver.VendorOptionInterface#updateSymbol(org.geotools.
     * styling.RasterSymbolizer)
     */
@Override
public void updateSymbol(RasterSymbolizer rasterSymbolizer) {
    if (parentPanel != null) {
        GroupConfigInterface group = parentPanel.getGroup(GroupIdEnum.RASTER_CHANNELSELECTION);
        if (group != null) {
            if (group.isPanelEnabled()) {
                MultiOptionGroup contrastEnhancementGroup = (MultiOptionGroup) group;
                ChannelSelection channelSelection = rasterSymbolizer.getChannelSelection();
                OptionGroup selectedOption = contrastEnhancementGroup.getSelectedOptionGroup();
                ContrastEnhancement contrastEnhancement = getContrastEnhancement(selectedOption.getId(), channelSelection);
                if (contrastEnhancement != null) {
                    extractNormalizeVendorOption(contrastEnhancement);
                }
            }
        }
    }
}
Also used : OptionGroup(com.sldeditor.ui.detail.config.base.OptionGroup) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) ContrastEnhancement(org.geotools.styling.ContrastEnhancement) ChannelSelection(org.geotools.styling.ChannelSelection) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup)

Example 3 with OptionGroup

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

the class SLDTestRunner method runTest.

/**
 * Run the test.
 *
 * @param folder the folder
 * @param testConfig the test config
 */
public void runTest(String folder, String testConfig) {
    // read JSON file data as String
    String fullPath = "/" + folder + "/test/" + testConfig;
    SldEditorTest testSuite = (SldEditorTest) ParseXML.parseFile("", fullPath, SCHEMA_RESOURCE, SldEditorTest.class);
    Assert.assertNotNull("Failed to read test config file : " + fullPath, testSuite);
    String testsldfile = testSuite.getTestsldfile();
    if (!testsldfile.startsWith("/")) {
        testsldfile = "/" + testsldfile;
    }
    System.out.println("Opening : " + testsldfile);
    List<XMLVendorOption> xmlVendorOptionList = testSuite.getVendorOption();
    List<VersionData> versionDataList = new ArrayList<VersionData>();
    if ((xmlVendorOptionList != null) && !xmlVendorOptionList.isEmpty()) {
        for (XMLVendorOption vo : xmlVendorOptionList) {
            VersionData versionData = ReadPanelConfig.decodeVersionData(vo);
            versionDataList.add(versionData);
        }
    }
    // If in doubt revert to strict SLD
    if (versionDataList.isEmpty()) {
        versionDataList.add(VendorOptionManager.getInstance().getDefaultVendorOptionVersionData());
    }
    sldEditor.setVendorOptions(versionDataList);
    InputStream inputStream = SLDTestRunner.class.getResourceAsStream(testsldfile);
    if (inputStream == null) {
        Assert.assertNotNull("Failed to find sld test file : " + testsldfile, inputStream);
    } else {
        File f = null;
        try {
            f = stream2file(inputStream);
            int noOfRetries = 3;
            int attempt = 0;
            while (attempt < noOfRetries) {
                try {
                    sldEditor.openFile(f.toURI().toURL());
                    break;
                } catch (NullPointerException nullException) {
                    nullException.printStackTrace();
                    StackTraceElement[] stackTraceElements = nullException.getStackTrace();
                    System.out.println(stackTraceElements[0].getMethodName());
                    System.out.println("Attempt : " + attempt + 1);
                    attempt++;
                }
            }
            f.delete();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        GraphicPanelFieldManager mgr = sldEditor.getFieldDataManager();
        for (XMLPanelTest test : testSuite.getPanelTests()) {
            XMLSetup selectedItem = test.getSetup();
            TreeSelectionData selectionData = new TreeSelectionData();
            selectionData.setLayerIndex(getXMLValue(selectedItem.getLayer()));
            selectionData.setStyleIndex(getXMLValue(selectedItem.getStyle()));
            selectionData.setFeatureTypeStyleIndex(getXMLValue(selectedItem.getFeatureTypeStyle()));
            selectionData.setRuleIndex(getXMLValue(selectedItem.getRule()));
            selectionData.setSymbolizerIndex(getXMLValue(selectedItem.getSymbolizer()));
            selectionData.setSymbolizerDetailIndex(getXMLValue(selectedItem.getSymbolizerDetail()));
            try {
                selectionData.setSelectedPanel(Class.forName(selectedItem.getExpectedPanel()));
            } catch (ClassNotFoundException e1) {
                Assert.fail("Unknown class : " + selectedItem.getExpectedPanel());
            }
            boolean result = sldEditor.selectTreeItem(selectionData);
            Assert.assertTrue("Failed to select tree item", result);
            PopulateDetailsInterface panel = sldEditor.getSymbolPanel();
            String panelClassName = panel.getClass().getName();
            Assert.assertEquals(panelClassName, selectedItem.getExpectedPanel());
            Assert.assertEquals("Check panel data present", panel.isDataPresent(), selectedItem.getEnabled());
            Class<?> panelId = null;
            try {
                panelId = Class.forName(selectedItem.getExpectedPanel());
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            if (test.getFieldTests() != null) {
                for (XMLFieldTest testItem : test.getFieldTests()) {
                    if (testItem != null) {
                        if (testItem.getDisabledOrLiteralStringOrLiteralInt() != null) {
                            for (Object xmlTestValueObj : testItem.getDisabledOrLiteralStringOrLiteralInt()) {
                                if (xmlTestValueObj instanceof XMLSetMultiOptionGroup) {
                                    XMLSetMultiOptionGroup testValue = (XMLSetMultiOptionGroup) xmlTestValueObj;
                                    GroupIdEnum groupId = testValue.getMultiOptionGroupId();
                                    String outputText = "Checking multioption group : " + groupId;
                                    System.out.println(outputText);
                                    Assert.assertNotNull(outputText, groupId);
                                    MultiOptionGroup multiOptionGroup = mgr.getMultiOptionGroup(panelId, groupId);
                                    Assert.assertNotNull(panelId.getName() + "/" + groupId + " multi option group should exist", multiOptionGroup);
                                    multiOptionGroup.setOption(testValue.getOption());
                                    OptionGroup optionGroupSelected = multiOptionGroup.getSelectedOptionGroup();
                                    Assert.assertTrue(groupId + " should be set", optionGroupSelected.getId() == testValue.getOption());
                                } else if (xmlTestValueObj instanceof XMLSetGroup) {
                                    XMLSetGroup testValue = (XMLSetGroup) xmlTestValueObj;
                                    GroupIdEnum groupId = testValue.getGroupId();
                                    String outputText = "Checking group : " + groupId;
                                    System.out.println(outputText);
                                    Assert.assertNotNull(outputText, groupId);
                                    GroupConfigInterface groupConfig = mgr.getGroup(panelId, groupId);
                                    Assert.assertNotNull(panelId.getName() + "/" + groupId + " group should exist", groupConfig);
                                    groupConfig.enable(testValue.getEnable());
                                    Assert.assertTrue(groupId + " should be set", groupConfig.isPanelEnabled() == testValue.getEnable());
                                } else {
                                    XMLFieldBase testValue = (XMLFieldBase) xmlTestValueObj;
                                    FieldIdEnum fieldId = testValue.getField();
                                    String outputText = "Checking : " + fieldId;
                                    System.out.println(outputText);
                                    Assert.assertNotNull(outputText, fieldId);
                                    try {
                                        Thread.sleep(100);
                                    } catch (InterruptedException e) {
                                        e.printStackTrace();
                                    }
                                    FieldConfigBase fieldConfig = mgr.getData(panelId, fieldId);
                                    Assert.assertNotNull(String.format("Failed to field panel %s field %s", selectedItem.getExpectedPanel(), fieldId), fieldConfig);
                                    if (testValue instanceof XMLSetFieldLiteralBase) {
                                        XMLSetFieldLiteralInterface testInterface = (XMLSetFieldLiteralInterface) testValue;
                                        testInterface.accept(fieldConfig, fieldId);
                                        if (!((XMLSetFieldLiteralBase) testValue).getIgnoreCheck()) {
                                            String sldContentString = sldEditor.getSLDString();
                                            boolean actualResult = testOutput.testValue(sldContentString, selectionData, testValue.getField(), testValue);
                                            Assert.assertTrue(fieldId + " should be set", actualResult);
                                        }
                                    } else if (testValue instanceof XMLSetFieldAttribute) {
                                        XMLSetFieldLiteralInterface testInterface = (XMLSetFieldLiteralInterface) testValue;
                                        testInterface.accept(fieldConfig, fieldId);
                                        String sldContentString = sldEditor.getSLDString();
                                        boolean actualResult = testOutput.testAttribute(sldContentString, selectionData, testValue.getField(), (XMLSetFieldAttribute) testValue);
                                        Assert.assertTrue(fieldId + " should be set", actualResult);
                                    } else if (testValue instanceof XMLFieldDisabled) {
                                        Assert.assertFalse(fieldId + " should be disabled", fieldConfig.isEnabled());
                                    } else {
                                        Assert.assertTrue(fieldId + " should be enabled", fieldConfig.isEnabled());
                                        Expression expression = null;
                                        if (fieldConfig.isValueOnly()) {
                                            String expectedValue = "";
                                            if (testValue instanceof XMLFieldLiteralBase) {
                                                Object literalValue = getLiteralValue((XMLFieldLiteralBase) testValue);
                                                expectedValue = String.valueOf(literalValue);
                                                if (fieldId == FieldIdEnum.TTF_SYMBOL) {
                                                    expectedValue = processTTFField(expectedValue).toString();
                                                }
                                            } else if (testValue instanceof XMLFieldAttribute) {
                                                expectedValue = ((XMLFieldAttribute) testValue).getAttribute();
                                            // CHECKSTYLE:OFF
                                            } else if (testValue instanceof XMLFieldExpression) {
                                                expectedValue = ((XMLFieldExpression) testValue).getExpression();
                                            } else if (testValue instanceof XMLColourMapEntries) {
                                                expectedValue = EncodeColourMap.encode(((XMLColourMapEntries) testValue).getEntry());
                                            // CHECKSTYLE:ON
                                            } else {
                                                Assert.fail(fieldId + " has unsupported type " + testValue.getClass().getName());
                                            }
                                            String actualValue = fieldConfig.getStringValue();
                                            String msg = String.format("%s Expected : '%s' Actual : '%s'", outputText, expectedValue, actualValue);
                                            boolean condition;
                                            if (comparingFilename(fieldId)) {
                                                File actualFile = new File(actualValue);
                                                File expectedFile = new File(expectedValue);
                                                String actualFileString = actualFile.getAbsolutePath();
                                                String expectedFileString = expectedFile.getAbsolutePath();
                                                expectedFileString = expectedFileString.substring(expectedFileString.length() - expectedValue.length());
                                                condition = actualFileString.endsWith(expectedFileString);
                                            } else {
                                                condition = (expectedValue.compareTo(actualValue) == 0);
                                            }
                                            Assert.assertTrue(msg, condition);
                                        } else {
                                            if (colourFieldsList.contains(fieldId)) {
                                                FieldConfigColour fieldColour = (FieldConfigColour) fieldConfig;
                                                expression = fieldColour.getColourExpression();
                                            } else {
                                                expression = fieldConfig.getExpression();
                                                if (fieldId == FieldIdEnum.SYMBOL_TYPE) {
                                                    String string = expression.toString();
                                                    expression = ff.literal(string.replace(File.separatorChar, '/'));
                                                } else if (fieldId == FieldIdEnum.FONT_FAMILY) {
                                                    // Handle the case where a font is not
                                                    // available on all operating systems
                                                    String string = expression.toString();
                                                    if (string.compareToIgnoreCase(DEFAULT_FONT) != 0) {
                                                        expression = ff.literal(getFontForOS());
                                                        // CHECKSTYLE:OFF
                                                        System.out.println("Updated font family to test for : " + expression.toString());
                                                    // CHECKSTYLE:ON
                                                    }
                                                } else if (fieldId == FieldIdEnum.TTF_SYMBOL) {
                                                    expression = processTTFField(expression.toString());
                                                }
                                            }
                                            if (expression != null) {
                                                if (testValue instanceof XMLFieldLiteralBase) {
                                                    Object literalValue = getLiteralValue((XMLFieldLiteralBase) testValue);
                                                    if (literalValue.getClass() == Double.class) {
                                                        checkLiteralValue(outputText, expression, (Double) literalValue);
                                                    } else if (literalValue.getClass() == Integer.class) {
                                                        checkLiteralValue(outputText, expression, (Integer) literalValue);
                                                    } else if (literalValue.getClass() == String.class) {
                                                        // CHECKSTYLE:OFF
                                                        if (fieldId == FieldIdEnum.FONT_FAMILY) {
                                                            // Handle the case where a font is not
                                                            // available on all operating systems
                                                            // CHECKSTYLE:ON
                                                            checkLiteralValue(outputText, expression, getFontForOS());
                                                        } else {
                                                            checkLiteralValue(outputText, expression, (String) literalValue);
                                                        }
                                                    }
                                                }
                                            } else {
                                                String actualValue;
                                                String expectedValue = fieldConfig.getStringValue();
                                                Object literalValue = getLiteralValue((XMLFieldLiteralBase) testValue);
                                                if (literalValue.getClass() == Double.class) {
                                                    actualValue = String.valueOf((Double) literalValue);
                                                } else if (literalValue.getClass() == Integer.class) {
                                                    actualValue = String.valueOf((Integer) literalValue);
                                                } else if (literalValue.getClass() == String.class) {
                                                    actualValue = (String) literalValue;
                                                } else {
                                                    actualValue = "";
                                                }
                                                String msg = String.format("%s Expected : '%s' Actual : '%s'", outputText, expectedValue, actualValue);
                                                boolean condition = (expectedValue.compareTo(actualValue) == 0);
                                                Assert.assertTrue(msg, condition);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    JFrame frame = sldEditor.getApplicationFrame();
    frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
}
Also used : XMLPanelTest(com.sldeditor.common.xml.ui.XMLPanelTest) XMLFieldDisabled(com.sldeditor.common.xml.ui.XMLFieldDisabled) XMLSetFieldLiteralBase(com.sldeditor.common.xml.ui.XMLSetFieldLiteralBase) SldEditorTest(com.sldeditor.common.xml.ui.SldEditorTest) ArrayList(java.util.ArrayList) XMLFieldLiteralString(com.sldeditor.common.xml.ui.XMLFieldLiteralString) XMLSetFieldLiteralInterface(com.sldeditor.common.xml.ui.XMLSetFieldLiteralInterface) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) PopulateDetailsInterface(com.sldeditor.ui.iface.PopulateDetailsInterface) XMLFieldBase(com.sldeditor.common.xml.ui.XMLFieldBase) OptionGroup(com.sldeditor.ui.detail.config.base.OptionGroup) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) XMLSetMultiOptionGroup(com.sldeditor.common.xml.ui.XMLSetMultiOptionGroup) JFrame(javax.swing.JFrame) XMLSetFieldAttribute(com.sldeditor.common.xml.ui.XMLSetFieldAttribute) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) XMLSetMultiOptionGroup(com.sldeditor.common.xml.ui.XMLSetMultiOptionGroup) XMLSetup(com.sldeditor.common.xml.ui.XMLSetup) GroupIdEnum(com.sldeditor.common.xml.ui.GroupIdEnum) XMLFieldAttribute(com.sldeditor.common.xml.ui.XMLFieldAttribute) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) XMLVendorOption(com.sldeditor.common.xml.ui.XMLVendorOption) InputStream(java.io.InputStream) XMLColourMapEntries(com.sldeditor.common.xml.ui.XMLColourMapEntries) IOException(java.io.IOException) XMLSetMultiOptionGroup(com.sldeditor.common.xml.ui.XMLSetMultiOptionGroup) XMLFieldLiteralDouble(com.sldeditor.common.xml.ui.XMLFieldLiteralDouble) XMLFieldExpression(com.sldeditor.common.xml.ui.XMLFieldExpression) Expression(org.opengis.filter.expression.Expression) XMLFieldExpression(com.sldeditor.common.xml.ui.XMLFieldExpression) XMLFieldLiteralBase(com.sldeditor.common.xml.ui.XMLFieldLiteralBase) VersionData(com.sldeditor.common.vendoroption.VersionData) XMLFieldTest(com.sldeditor.common.xml.ui.XMLFieldTest) TreeSelectionData(com.sldeditor.TreeSelectionData) WindowEvent(java.awt.event.WindowEvent) XMLSetGroup(com.sldeditor.common.xml.ui.XMLSetGroup) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) File(java.io.File)

Example 4 with OptionGroup

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

the class TextSymbolizerDetails method updateSymbol.

/**
 * Update symbol.
 */
private void updateSymbol() {
    if (!Controller.getInstance().isPopulating()) {
        Expression haloRadius = fieldConfigVisitor.getExpression(FieldIdEnum.HALO_RADIUS);
        // Label placement
        LabelPlacement labelPlacement = null;
        MultiOptionGroup labelPlacementPanel = (MultiOptionGroup) getGroup(GroupIdEnum.PLACEMENT);
        OptionGroup labelPlacementOption = labelPlacementPanel.getSelectedOptionGroup();
        if (labelPlacementOption.getId() == GroupIdEnum.POINTPLACEMENT) {
            AnchorPoint anchor = null;
            GroupConfigInterface anchorPointPanel = getGroup(GroupIdEnum.ANCHORPOINT);
            if (anchorPointPanel == null) {
                String errorMessage = String.format("%s : %s", Localisation.getString(TextSymbolizerDetails.class, "TextSymbol.error1"), GroupIdEnum.ANCHORPOINT);
                ConsoleManager.getInstance().error(this, errorMessage);
            } else if (anchorPointPanel.isPanelEnabled()) {
                Expression anchorPointH = fieldConfigVisitor.getExpression(FieldIdEnum.ANCHOR_POINT_H);
                Expression anchorPointV = fieldConfigVisitor.getExpression(FieldIdEnum.ANCHOR_POINT_V);
                anchor = (AnchorPoint) getStyleFactory().anchorPoint(anchorPointH, anchorPointV);
            }
            // 
            // Displacement
            // 
            Displacement displacement = null;
            GroupConfigInterface displacementPanel = getGroup(GroupIdEnum.DISPLACEMENT);
            if (displacementPanel == null) {
                ConsoleManager.getInstance().error(this, String.format("%s : %s", Localisation.getString(TextSymbolizerDetails.class, "TextSymbol.error1"), GroupIdEnum.DISPLACEMENT));
            } else if (displacementPanel.isPanelEnabled()) {
                displacement = getStyleFactory().displacement(fieldConfigVisitor.getExpression(FieldIdEnum.DISPLACEMENT_X), fieldConfigVisitor.getExpression(FieldIdEnum.DISPLACEMENT_Y));
            }
            // 
            // Rotation
            // 
            Expression rotation = null;
            GroupConfigInterface rotationPanel = getGroup(GroupIdEnum.ROTATION);
            if (rotationPanel == null) {
                ConsoleManager.getInstance().error(this, String.format("%s : %s", Localisation.getString(TextSymbolizerDetails.class, "TextSymbol.error1"), GroupIdEnum.ROTATION));
            } else if (rotationPanel.isPanelEnabled()) {
                rotation = fieldConfigVisitor.getExpression(FieldIdEnum.ANGLE);
            }
            labelPlacement = getStyleFactory().pointPlacement(anchor, displacement, rotation);
        } else if (labelPlacementOption.getId() == GroupIdEnum.LINEPLACEMENT) {
            Expression offset = fieldConfigVisitor.getExpression(FieldIdEnum.PERPENDICULAR_OFFSET);
            Expression initialGap = fieldConfigVisitor.getExpression(FieldIdEnum.INITIAL_GAP);
            Expression gap = fieldConfigVisitor.getExpression(FieldIdEnum.GAP);
            boolean repeated = fieldConfigVisitor.getBoolean(FieldIdEnum.REPEATED);
            boolean aligned = fieldConfigVisitor.getBoolean(FieldIdEnum.ALIGN);
            boolean generalizedLine = fieldConfigVisitor.getBoolean(FieldIdEnum.GENERALISED_LINE);
            labelPlacement = getStyleFactory().linePlacement(offset, initialGap, gap, repeated, aligned, generalizedLine);
        }
        FieldConfigColour fdmFillColour = (FieldConfigColour) fieldConfigManager.get(FieldIdEnum.FILL_COLOUR);
        Expression fillColour = fdmFillColour.getColourExpression();
        Expression fillColourOpacity = fieldConfigVisitor.getExpression(FieldIdEnum.TEXT_OPACITY);
        Fill fill = getStyleFactory().createFill(fillColour, fillColourOpacity);
        FieldConfigColour fdmHaloColour = (FieldConfigColour) fieldConfigManager.get(FieldIdEnum.HALO_COLOUR);
        Expression haloFillColour = fdmHaloColour.getColourExpression();
        Expression haloFillColourOpacity = fdmHaloColour.getColourOpacityExpression();
        Fill haloFill = getStyleFactory().fill(null, haloFillColour, haloFillColourOpacity);
        // 
        // Halo
        // 
        Halo halo = null;
        GroupConfigInterface haloPanel = getGroup(GroupIdEnum.HALO);
        if (haloPanel.isPanelEnabled()) {
            halo = (Halo) getStyleFactory().halo(haloFill, haloRadius);
        }
        // 
        // Font
        // 
        Font font = extractFont();
        // Any changes made to the font details need to be reflected
        // back to the FieldConfigFontPreview field
        fieldConfigVisitor.populateFontField(FieldIdEnum.FONT_PREVIEW, font);
        StandardData standardData = getStandardData();
        Expression label = fieldConfigVisitor.getExpression(FieldIdEnum.LABEL);
        Expression geometryField = fieldConfigVisitor.getExpression(FieldIdEnum.GEOMETRY);
        String geometryFieldName = null;
        Expression defaultGeometryField = getFilterFactory().property(geometryFieldName);
        TextSymbolizer textSymbolizer = (TextSymbolizer) getStyleFactory().textSymbolizer(standardData.name, defaultGeometryField, standardData.description, standardData.unit, label, font, labelPlacement, halo, fill);
        if ((geometryField != null) && !geometryField.toString().isEmpty()) {
            textSymbolizer.setGeometry(geometryField);
        }
        if (vendorOptionTextFactory != null) {
            vendorOptionTextFactory.updateSymbol(textSymbolizer);
        }
        SelectedSymbol.getInstance().replaceSymbolizer(textSymbolizer);
        this.fireUpdateSymbol();
    }
}
Also used : Fill(org.opengis.style.Fill) Displacement(org.geotools.styling.Displacement) Font(org.geotools.styling.Font) OptionGroup(com.sldeditor.ui.detail.config.base.OptionGroup) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) AnchorPoint(org.geotools.styling.AnchorPoint) LabelPlacement(org.geotools.styling.LabelPlacement) Expression(org.opengis.filter.expression.Expression) TextSymbolizer(org.geotools.styling.TextSymbolizer) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) Halo(org.geotools.styling.Halo)

Example 5 with OptionGroup

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

the class UserLayerDetails method updateSymbol.

/**
 * Update symbol.
 *
 * @param changedField the changed field
 */
private void updateSymbol(FieldIdEnum changedField) {
    if (!Controller.getInstance().isPopulating()) {
        UserLayer userLayer = getStyleFactory().createUserLayer();
        String name = fieldConfigVisitor.getText(FieldIdEnum.NAME);
        userLayer.setName(name);
        // Feature type constraints
        List<FeatureTypeConstraint> ftcList = fieldConfigVisitor.getFeatureTypeConstraint(FieldIdEnum.LAYER_FEATURE_CONSTRAINTS);
        if ((ftcList != null) && !ftcList.isEmpty()) {
            FeatureTypeConstraint[] ftcArray = new FeatureTypeConstraint[ftcList.size()];
            userLayer.setLayerFeatureConstraints(ftcList.toArray(ftcArray));
        }
        // Source
        GroupConfigInterface group = getGroup(GroupIdEnum.USER_LAYER_SOURCE);
        if (group != null) {
            MultiOptionGroup userLayerSourceGroup = (MultiOptionGroup) group;
            OptionGroup selectedOption = userLayerSourceGroup.getSelectedOptionGroup();
            switch(selectedOption.getId()) {
                case REMOTE_OWS_OPTION:
                    {
                        RemoteOWS remoteOWS = new RemoteOWSImpl();
                        String service = fieldConfigVisitor.getText(FieldIdEnum.REMOTE_OWS_SERVICE);
                        remoteOWS.setService(service);
                        String onlineResource = fieldConfigVisitor.getText(FieldIdEnum.REMOTE_OWS_ONLINERESOURCE);
                        remoteOWS.setOnlineResource(onlineResource);
                        userLayer.setRemoteOWS(remoteOWS);
                    }
                    break;
                case INLINE_FEATURE_OPTION:
                    {
                        String inlineFeatures = fieldConfigVisitor.getText(FieldIdEnum.INLINE_FEATURE);
                        if ((inlineFeatures != null) && (!inlineFeatures.isEmpty())) {
                            InlineFeatureUtils.setInlineFeatures(userLayer, inlineFeatures);
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        StyledLayer existingStyledLayer = SelectedSymbol.getInstance().getStyledLayer();
        if (existingStyledLayer instanceof UserLayerImpl) {
            UserLayerImpl existingUserLayer = (UserLayerImpl) existingStyledLayer;
            for (Style style : existingUserLayer.userStyles()) {
                userLayer.addUserStyle(style);
            }
        }
        SelectedSymbol.getInstance().replaceStyledLayer(userLayer);
        // reduces creation of datasources
        if (changedField != null) {
            if (changedField == FieldIdEnum.INLINE_FEATURE) {
                DataSourceInterface dataSource = DataSourceFactory.getDataSource();
                if (dataSource != null) {
                    dataSource.updateUserLayers();
                }
            }
        }
        this.fireUpdateSymbol();
    }
}
Also used : RemoteOWS(org.geotools.styling.RemoteOWS) StyledLayer(org.geotools.styling.StyledLayer) RemoteOWSImpl(org.geotools.styling.RemoteOWSImpl) DataSourceInterface(com.sldeditor.datasource.DataSourceInterface) FeatureTypeConstraint(org.geotools.styling.FeatureTypeConstraint) OptionGroup(com.sldeditor.ui.detail.config.base.OptionGroup) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) UserLayerImpl(org.geotools.styling.UserLayerImpl) Style(org.geotools.styling.Style) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) UserLayer(org.geotools.styling.UserLayer) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup)

Aggregations

MultiOptionGroup (com.sldeditor.ui.detail.config.base.MultiOptionGroup)10 OptionGroup (com.sldeditor.ui.detail.config.base.OptionGroup)10 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)9 Expression (org.opengis.filter.expression.Expression)4 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)3 GroupConfig (com.sldeditor.ui.detail.config.base.GroupConfig)3 ContrastEnhancement (org.geotools.styling.ContrastEnhancement)3 GroupIdEnum (com.sldeditor.common.xml.ui.GroupIdEnum)2 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)2 SelectedChannelType (org.geotools.styling.SelectedChannelType)2 TreeSelectionData (com.sldeditor.TreeSelectionData)1 VersionData (com.sldeditor.common.vendoroption.VersionData)1 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)1 SldEditorTest (com.sldeditor.common.xml.ui.SldEditorTest)1 XMLColourMapEntries (com.sldeditor.common.xml.ui.XMLColourMapEntries)1 XMLFieldAttribute (com.sldeditor.common.xml.ui.XMLFieldAttribute)1 XMLFieldBase (com.sldeditor.common.xml.ui.XMLFieldBase)1 XMLFieldDisabled (com.sldeditor.common.xml.ui.XMLFieldDisabled)1 XMLFieldExpression (com.sldeditor.common.xml.ui.XMLFieldExpression)1 XMLFieldLiteralBase (com.sldeditor.common.xml.ui.XMLFieldLiteralBase)1