Search in sources :

Example 26 with StyledLayerDescriptor

use of org.geotools.styling.StyledLayerDescriptor 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 StyledLayerDescriptor

use of org.geotools.styling.StyledLayerDescriptor 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 StyledLayerDescriptor

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

the class LegendManagerTest method testSLD1.

/**
 * Create test SLD
 *
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor testSLD1() {
    String sldContents = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<StyledLayerDescriptor version=\"1.0.0\" " + "    xsi:schemaLocation=\"http://www.opengis.net/sld StyledLayerDescriptor.xsd\" " + "    xmlns=\"http://www.opengis.net/sld\" " + "    xmlns:sld=\"http://www.opengis.net/sld\" " + "    xmlns:ogc=\"http://www.opengis.net/ogc\" " + "    xmlns:gml=\"http://www.opengis.net/gml\" " + "    xmlns:xlink=\"http://www.w3.org/1999/xlink\" " + "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "<sld:UserLayer>" + "<sld:Name>Inline</sld:Name>" + "<sld:InlineFeature>" + "  <FeatureCollection>" + "    <featureMember>" + "      <gml:_Feature>" + "        <geometryProperty>" + "          <Polygon>" + "            <outerBoundaryIs>" + "              <LinearRing>" + "              <coordinates>-127,51 -110,51 -110,41 -127,41 -127,51</coordinates>" + "              </LinearRing>" + "            </outerBoundaryIs>" + "          </Polygon>" + "        </geometryProperty>" + "        <title>Pacific NW</title>" + "      </gml:_Feature>" + "    </featureMember>" + "  </FeatureCollection>" + "</sld:InlineFeature>" + "<sld:LayerFeatureConstraints>" + "  <sld:FeatureTypeConstraint/>" + "</sld:LayerFeatureConstraints>" + "<sld:UserStyle>" + "  <sld:Name>Default Styler</sld:Name>" + "  <sld:FeatureTypeStyle>" + "    <sld:Name>name</sld:Name>" + "    <sld:Rule>" + "      <sld:PolygonSymbolizer>" + "        <sld:Stroke>" + "          <sld:CssParameter name=\"stroke\">#FF0000</sld:CssParameter>" + "          <sld:CssParameter name=\"stroke-width\">2</sld:CssParameter>" + "        </sld:Stroke>" + "      </sld:PolygonSymbolizer>" + "      <sld:TextSymbolizer>" + "        <sld:Label>" + "          <ogc:PropertyName>title</ogc:PropertyName>" + "        </sld:Label>" + "        <sld:LabelPlacement>" + "          <sld:PointPlacement>" + "            <sld:AnchorPoint>" + "              <sld:AnchorPointX>0.0</sld:AnchorPointX>" + "              <sld:AnchorPointY>0.5</sld:AnchorPointY>" + "            </sld:AnchorPoint>" + "          </sld:PointPlacement>" + "        </sld:LabelPlacement>" + "        <sld:Fill>" + "          <sld:CssParameter name=\"fill\">#FF0000</sld:CssParameter>" + "        </sld:Fill>" + "      </sld:TextSymbolizer>" + "    </sld:Rule>" + "  </sld:FeatureTypeStyle>" + "</sld:UserStyle>" + "</sld:UserLayer>" + "</StyledLayerDescriptor>";
    SLDData sldData = new SLDData(new StyleWrapper(null, "test.sld"), sldContents);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    return sld;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper)

Example 29 with StyledLayerDescriptor

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

the class LegendManagerTest method testUpdateLegendOptionData.

@Test
public void testUpdateLegendOptionData() {
    StyledLayerDescriptor sld = testSLD1();
    String heading = "Test Heading";
    LegendOptionData legendOption = new LegendOptionData();
    legendOption.setBackgroundColour(Color.CYAN);
    legendOption.setBorder(true);
    legendOption.setBandInformation(true);
    legendOption.setBorderColour(Color.GREEN);
    legendOption.setImageHeight(100);
    legendOption.setImageWidth(100);
    legendOption.setImageHeight(100);
    legendOption.setShowLabels(true);
    legendOption.setShowTitle(true);
    LegendManager.getInstance().SLDLoaded(legendOption);
    boolean actualResult = compareLegendImage(sld, heading);
    assertTrue(actualResult);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) LegendOptionData(com.sldeditor.ui.legend.option.LegendOptionData) Test(org.junit.Test)

Example 30 with StyledLayerDescriptor

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

the class SLDUtils method createSLDFromString.

/**
 * Creates a StyledLayerDescriptor object containing a SLD from a string.
 *
 * @param sldData the sld data
 * @return the styled layer descriptor
 */
public static StyledLayerDescriptor createSLDFromString(SLDDataInterface sldData) {
    if ((sldData == null) || (sldData.getSld() == null)) {
        return null;
    }
    StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
    InputStream stream = new ByteArrayInputStream(sldData.getSld().getBytes());
    SLDParser styleReader = new SLDParser(styleFactory, stream);
    URL resourceLocator = getResourceLocator(sldData);
    sldData.setResourceLocator(resourceLocator);
    setResourcelocator(styleReader, resourceLocator);
    StyledLayerDescriptor sld = null;
    try {
        sld = styleReader.parseSLD();
    } catch (RuntimeException e) {
        String errorMessage = String.format("SLD Parser error : %s", sldData.getStyle().toString());
        ConsoleManager.getInstance().error(SLDUtils.class, errorMessage);
        ConsoleManager.getInstance().error(SLDUtils.class, e.getMessage());
    }
    return sld;
}
Also used : StyleFactory(org.geotools.styling.StyleFactory) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SLDParser(org.geotools.styling.SLDParser) URL(java.net.URL)

Aggregations

StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)123 Test (org.junit.Test)73 Rule (org.geotools.styling.Rule)51 Style (org.geotools.styling.Style)49 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)47 NamedLayer (org.geotools.styling.NamedLayer)44 SLDData (com.sldeditor.common.data.SLDData)24 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)23 File (java.io.File)19 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)19 StyledLayer (org.geotools.styling.StyledLayer)19 SLDTreeTools (com.sldeditor.ui.tree.SLDTreeTools)17 PointSymbolizer (org.geotools.styling.PointSymbolizer)17 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)16 StyleWrapper (com.sldeditor.common.data.StyleWrapper)15 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)14 IOException (java.io.IOException)14 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)14 SLDDataInterface (com.sldeditor.common.SLDDataInterface)12 LineSymbolizer (org.geotools.styling.LineSymbolizer)12