Search in sources :

Example 26 with Rule

use of org.geotools.styling.Rule in project sldeditor by robward-scisys.

the class RasterSymbolizerDetailsTest method testRasterSymbolizerDetailsColourChannel.

/**
 * Test method for {@link com.sldeditor.ui.detail.RasterSymbolizerDetails#RasterSymbolizerDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 * Test method for {@link com.sldeditor.ui.detail.RasterSymbolizerDetails#isDataPresent()}.
 * Test method for {@link com.sldeditor.ui.detail.RasterSymbolizerDetails#populate(com.sldeditor.common.data.SelectedSymbol)}.
 * Test method for {@link com.sldeditor.ui.detail.RasterSymbolizerDetails#dataChanged(com.sldeditor.ui.detail.config.FieldId)}.
 * Test method for {@link com.sldeditor.ui.detail.RasterSymbolizerDetails#getFieldDataManager()}.
 * Test method for {@link com.sldeditor.ui.detail.RasterSymbolizerDetails#preLoadSymbol()}.
 */
@Test
public void testRasterSymbolizerDetailsColourChannel() {
    RasterSymbolizerDetails panel = new RasterSymbolizerDetails();
    panel.populate(null);
    // Set up test data
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    SelectedSymbol.getInstance().createNewSLD(sld);
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    String expectedNameLayerValue = "named layer test value";
    namedLayer.setName(expectedNameLayerValue);
    Style style = DefaultSymbols.createNewStyle();
    String expectedNameStyleValue = "style test value";
    style.setName(expectedNameStyleValue);
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedNameFTSValue = "feature type style test value";
    fts.setName(expectedNameFTSValue);
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    String expectedRuleValue = "rule test value";
    rule.setName(expectedRuleValue);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    ContrastEnhancement contrastEnhancement = (ContrastEnhancement) styleFactory.contrastEnhancement(ff.literal(.5), "ramp");
    SelectedChannelType redChannel = styleFactory.createSelectedChannelType("red", contrastEnhancement);
    SelectedChannelType greenChannel = styleFactory.createSelectedChannelType("green", contrastEnhancement);
    SelectedChannelType blueChannel = styleFactory.createSelectedChannelType("blue", contrastEnhancement);
    SelectedChannelType[] channels = new SelectedChannelType[3];
    channels[0] = redChannel;
    channels[1] = greenChannel;
    channels[2] = blueChannel;
    RasterSymbolizer symbolizer = DefaultSymbols.createDefaultRasterSymbolizer();
    symbolizer.setChannelSelection(styleFactory.createChannelSelection(channels));
    String expectedNameValue = "symbolizer test value";
    symbolizer.setName(expectedNameValue);
    rule.symbolizers().add(symbolizer);
    fts.rules().add(rule);
    sld.layers().add(namedLayer);
    SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyle(style);
    SelectedSymbol.getInstance().setFeatureTypeStyle(fts);
    SelectedSymbol.getInstance().setRule(rule);
    SelectedSymbol.getInstance().setSymbolizer(symbolizer);
    panel.populate(SelectedSymbol.getInstance());
    GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
    assertNotNull(fieldDataManager);
    panel.dataChanged(null);
    FieldConfigString nameField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.NAME);
    assertNull(nameField);
    assertTrue(panel.isDataPresent());
    // Reset to default value
    panel.preLoadSymbol();
}
Also used : FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) RasterSymbolizerDetails(com.sldeditor.ui.detail.RasterSymbolizerDetails) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) FilterFactory(org.opengis.filter.FilterFactory) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) SelectedChannelType(org.geotools.styling.SelectedChannelType) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) ContrastEnhancement(org.geotools.styling.ContrastEnhancement) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Example 27 with Rule

use of org.geotools.styling.Rule in project sldeditor by robward-scisys.

the class RuleDetailsTest method testRuleDetails.

/**
 * Test method for {@link com.sldeditor.ui.detail.RuleDetails#RuleDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 * Test method for {@link com.sldeditor.ui.detail.RuleDetails#populate(com.sldeditor.common.data.SelectedSymbol)}.
 * Test method for {@link com.sldeditor.ui.detail.RuleDetails#dataChanged(com.sldeditor.ui.detail.config.FieldId)}.
 * Test method for {@link com.sldeditor.ui.detail.RuleDetails#getFieldDataManager()}.
 * Test method for {@link com.sldeditor.ui.detail.RuleDetails#isDataPresent()}.
 * Test method for {@link com.sldeditor.ui.detail.RuleDetails#preLoadSymbol()}.
 */
@Test
public void testRuleDetails() {
    RuleDetails panel = new RuleDetails();
    panel.populate(null);
    // Set up test data
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    SelectedSymbol.getInstance().createNewSLD(sld);
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    String expectedNameLayerValue = "named layer test value";
    namedLayer.setName(expectedNameLayerValue);
    Style style = DefaultSymbols.createNewStyle();
    String expectedNameStyleValue = "style test value";
    style.setName(expectedNameStyleValue);
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedNameFTSValue = "feature type style test value";
    fts.setName(expectedNameFTSValue);
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    String expectedNameValue = "rule test value";
    rule.setName(expectedNameValue);
    Symbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    rule.symbolizers().add(symbolizer);
    fts.rules().add(rule);
    sld.layers().add(namedLayer);
    SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyle(style);
    SelectedSymbol.getInstance().setFeatureTypeStyle(fts);
    SelectedSymbol.getInstance().setRule(rule);
    panel.populate(SelectedSymbol.getInstance());
    GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
    assertNotNull(fieldDataManager);
    FieldConfigString filterField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.FILTER);
    String filterString = "STATE_ABBR >= 'B' AND STATE_ABBR <= 'O'";
    filterField.populateField(filterString);
    panel.dataChanged(null);
    FieldConfigString nameField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.NAME);
    String actualValue = nameField.getStringValue();
    assertTrue(expectedNameValue.compareTo(actualValue) == 0);
    assertTrue(panel.isDataPresent());
    // Reset to default value
    panel.preLoadSymbol();
    actualValue = nameField.getStringValue();
    assertTrue("".compareTo(actualValue) == 0);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer) Symbolizer(org.geotools.styling.Symbolizer) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) RuleDetails(com.sldeditor.ui.detail.RuleDetails) Test(org.junit.Test)

Example 28 with Rule

use of org.geotools.styling.Rule in project sldeditor by robward-scisys.

the class RuleTreeItemTest method testGetTreeString.

/**
 * Test method for
 * {@link com.sldeditor.ui.tree.item.RuleTreeItem#getTreeString(java.lang.Object)}.
 */
@Test
public void testGetTreeString() {
    RuleTreeItem item = new RuleTreeItem();
    String actualValue = item.getTreeString(null, null);
    String expectedValue = String.format("%s : %s", Localisation.getString(SLDTreeTools.class, "TreeItem.rule"), "");
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    Rule rule = DefaultSymbols.createNewRule();
    actualValue = item.getTreeString(null, rule);
    expectedValue = String.format("%s : %s", Localisation.getString(SLDTreeTools.class, "TreeItem.rule"), Localisation.getString(SLDTreeTools.class, "TreeItem.newRule"));
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    rule.setName(null);
    actualValue = item.getTreeString(null, rule);
    expectedValue = String.format("%s : %s", Localisation.getString(SLDTreeTools.class, "TreeItem.rule"), "");
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    String expectedName = "test name";
    rule.setName(expectedName);
    actualValue = item.getTreeString(null, rule);
    expectedValue = String.format("%s : %s", Localisation.getString(SLDTreeTools.class, "TreeItem.rule"), expectedName);
    assertTrue(actualValue.compareTo(expectedValue) == 0);
}
Also used : RuleTreeItem(com.sldeditor.ui.tree.item.RuleTreeItem) Rule(org.geotools.styling.Rule) SLDTreeTools(com.sldeditor.ui.tree.SLDTreeTools) Test(org.junit.Test)

Example 29 with Rule

use of org.geotools.styling.Rule in project sldeditor by robward-scisys.

the class SymbolizerTreeItemTest method testItemSelected.

/**
 * Test method for
 * {@link com.sldeditor.ui.tree.item.SymbolizerTreeItem#itemSelected(javax.swing.tree.DefaultMutableTreeNode, java.lang.Object)}.
 */
@Test
public void testItemSelected() {
    SymbolizerTreeItem item = new SymbolizerTreeItem();
    item.itemSelected(null, null);
    Symbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    Rule rule = DefaultSymbols.createNewRule();
    DefaultMutableTreeNode parentNode = new DefaultMutableTreeNode();
    parentNode.setUserObject(rule);
    DefaultMutableTreeNode node = new DefaultMutableTreeNode();
    parentNode.add(node);
    item.itemSelected(node, symbolizer);
    // Get the code coverage stats up
    item.itemSelected(parentNode, symbolizer);
    parentNode.setUserObject(item);
    item.itemSelected(node, null);
}
Also used : SymbolizerTreeItem(com.sldeditor.ui.tree.item.SymbolizerTreeItem) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Rule(org.geotools.styling.Rule) Symbolizer(org.geotools.styling.Symbolizer) Test(org.junit.Test)

Example 30 with Rule

use of org.geotools.styling.Rule in project sldeditor by robward-scisys.

the class SLDUtils method findRule.

/**
 * Find rule.
 *
 * @param sld the sld
 * @param ruleToFind the rule to find
 * @param otherSLD the other SLD
 * @return the rule
 */
public static Rule findRule(StyledLayerDescriptor sld, Rule ruleToFind, StyledLayerDescriptor otherSLD) {
    if (sld != null) {
        List<StyledLayer> styledLayerList = sld.layers();
        if (styledLayerList != null) {
            int styledLayerIndex = 0;
            int styleIndex = 0;
            int ftsIndex = 0;
            int ruleIndex = 0;
            boolean isNamedLayer = true;
            for (StyledLayer styledLayer : styledLayerList) {
                List<Style> styleList = null;
                if (styledLayer instanceof NamedLayerImpl) {
                    NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                    styleList = namedLayerImpl.styles();
                    isNamedLayer = true;
                } else if (styledLayer instanceof UserLayerImpl) {
                    UserLayerImpl userLayerImpl = (UserLayerImpl) styledLayer;
                    styleList = userLayerImpl.userStyles();
                    isNamedLayer = false;
                }
                if (styleList != null) {
                    styleIndex = 0;
                    for (Style style : styleList) {
                        ftsIndex = 0;
                        for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                            ruleIndex = 0;
                            for (Rule rule : fts.rules()) {
                                if (rule == ruleToFind) {
                                    return findEquivalentRule(otherSLD, styledLayerIndex, isNamedLayer, styleIndex, ftsIndex, ruleIndex);
                                }
                                ruleIndex++;
                            }
                            ftsIndex++;
                        }
                        styleIndex++;
                    }
                }
                styledLayerIndex++;
            }
        }
    }
    return null;
}
Also used : UserLayerImpl(org.geotools.styling.UserLayerImpl) StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Aggregations

Rule (org.geotools.styling.Rule)110 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)65 Style (org.geotools.styling.Style)60 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)51 Test (org.junit.Test)48 NamedLayer (org.geotools.styling.NamedLayer)38 PointSymbolizer (org.geotools.styling.PointSymbolizer)28 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)26 LineSymbolizer (org.geotools.styling.LineSymbolizer)24 Symbolizer (org.geotools.styling.Symbolizer)22 StyledLayer (org.geotools.styling.StyledLayer)19 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)16 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)16 TextSymbolizer (org.geotools.styling.TextSymbolizer)15 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)13 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)11 ArrayList (java.util.ArrayList)11 Filter (org.opengis.filter.Filter)11 UserLayerImpl (org.geotools.styling.UserLayerImpl)10 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)8