Search in sources :

Example 11 with SelectedSymbol

use of com.sldeditor.common.data.SelectedSymbol in project sldeditor by robward-scisys.

the class SelectedSymbolTest method testIsRasterSymbol.

@Test
public void testIsRasterSymbol() {
    SelectedSymbol.destroyInstance();
    SelectedSymbol instance = SelectedSymbol.getInstance();
    // Create point symbolizer
    StyledLayerDescriptor sld = DefaultSymbols.createNewPoint();
    instance.createNewSLD(sld);
    instance.setSld(sld);
    // No selection made
    assertFalse(instance.isRasterSymbol());
    Style style = ((NamedLayer) sld.layers().get(0)).styles().get(0);
    instance.setStyle(style);
    assertFalse(instance.isRasterSymbol());
    // Create polygon symbolizer
    SelectedSymbol.destroyInstance();
    instance = SelectedSymbol.getInstance();
    sld = DefaultSymbols.createNewPolygon();
    instance.createNewSLD(sld);
    instance.setSld(sld);
    // No selection made
    assertFalse(instance.isRasterSymbol());
    style = ((NamedLayer) sld.layers().get(0)).styles().get(0);
    instance.setStyle(style);
    assertFalse(instance.isRasterSymbol());
    // Create line symbolizer
    SelectedSymbol.destroyInstance();
    instance = SelectedSymbol.getInstance();
    sld = DefaultSymbols.createNewLine();
    instance.createNewSLD(sld);
    instance.setSld(sld);
    // No selection made
    assertFalse(instance.isRasterSymbol());
    style = ((NamedLayer) sld.layers().get(0)).styles().get(0);
    instance.setStyle(style);
    assertFalse(instance.isRasterSymbol());
    // Create raster symbolizer
    SelectedSymbol.destroyInstance();
    instance = SelectedSymbol.getInstance();
    sld = DefaultSymbols.createNewRaster();
    instance.createNewSLD(sld);
    instance.setSld(sld);
    // No selection made
    assertFalse(instance.isRasterSymbol());
    style = ((NamedLayer) sld.layers().get(0)).styles().get(0);
    instance.setStyle(style);
    assertTrue(instance.isRasterSymbol());
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Example 12 with SelectedSymbol

use of com.sldeditor.common.data.SelectedSymbol in project sldeditor by robward-scisys.

the class SelectedSymbolTest method testGetSLD.

@Test
public void testGetSLD() {
    SelectedSymbol.destroyInstance();
    SelectedSymbol instance = SelectedSymbol.getInstance();
    // CHECKSTYLE:OFF
    Rule rule = DefaultSymbols.createNewRule();
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    Style style = DefaultSymbols.createNewStyle();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    PolygonSymbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    // CHECKSTYLE:ON
    instance.createNewSLD(sld);
    instance.setSld(sld);
    System.out.println("Select named layer");
    instance.addNewStyledLayer(namedLayer);
    instance.setStyledLayer(namedLayer);
    assertEquals(namedLayer, instance.getStyledLayer());
    assertNull(instance.getRule());
    assertNull(instance.getStyle());
    assertNull(instance.getFeatureTypeStyle());
    assertNull(instance.getSymbolizer());
    System.out.println("Select style");
    instance.addNewStyle(style);
    instance.setStyle(style);
    assertEquals(namedLayer, instance.getStyledLayer());
    assertEquals(style, instance.getStyle());
    assertNull(instance.getFeatureTypeStyle());
    assertNull(instance.getRule());
    assertNull(instance.getSymbolizer());
    System.out.println("Select feature type style");
    instance.addNewFeatureTypeStyle(fts);
    instance.setFeatureTypeStyle(fts);
    assertEquals(namedLayer, instance.getStyledLayer());
    assertEquals(style, instance.getStyle());
    assertEquals(fts, instance.getFeatureTypeStyle());
    assertNull(instance.getRule());
    assertNull(instance.getSymbolizer());
    System.out.println("Select rule");
    instance.addNewRule(rule);
    instance.setRule(rule);
    assertEquals(namedLayer, instance.getStyledLayer());
    assertEquals(style, instance.getStyle());
    assertEquals(fts, instance.getFeatureTypeStyle());
    assertEquals(rule, instance.getRule());
    assertNull(instance.getSymbolizer());
    assertTrue(instance.hasOnlyOneRule());
    System.out.println("Select symbolizer");
    instance.addSymbolizerToRule(symbolizer);
    instance.addNewRule(DefaultSymbols.createNewRule());
    assertFalse(instance.hasOnlyOneRule());
    assertEquals(-1, instance.getSymbolIndex());
    instance.setSymbolizer(symbolizer);
    assertEquals(namedLayer, instance.getStyledLayer());
    assertEquals(style, instance.getStyle());
    assertEquals(fts, instance.getFeatureTypeStyle());
    assertEquals(rule, instance.getRule());
    assertEquals(symbolizer, instance.getSymbolizer());
    assertEquals(0, instance.getSymbolIndex());
    // Get SLD structure
    StyledLayerDescriptor actualSLD = instance.getSld();
    assertEquals(sld, actualSLD);
    StyledLayer[] actualStyledLayers = actualSLD.getStyledLayers();
    assertEquals(1, actualStyledLayers.length);
    NamedLayer actualNamedLayer = (NamedLayer) actualStyledLayers[0];
    assertEquals(namedLayer, actualNamedLayer);
    Style[] actualStyle = actualNamedLayer.getStyles();
    assertEquals(1, actualStyle.length);
    assertEquals(style, actualStyle[0]);
    assertEquals(1, style.featureTypeStyles().size());
    FeatureTypeStyle actualFeatureTypeStyle = style.featureTypeStyles().get(0);
    assertEquals(fts, actualFeatureTypeStyle);
    List<Rule> actualRules = actualFeatureTypeStyle.rules();
    assertEquals(2, actualRules.size());
    Rule actualRule = actualRules.get(0);
    assertEquals(rule, actualRule);
    assertEquals(1, actualRule.symbolizers().size());
    assertEquals(symbolizer, actualRule.symbolizers().get(0));
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) StyledLayer(org.geotools.styling.StyledLayer) 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 13 with SelectedSymbol

use of com.sldeditor.common.data.SelectedSymbol in project sldeditor by robward-scisys.

the class SLDEditor method populate.

/**
 * Populate the application with the SLD.
 *
 * @param sldData the sld data
 */
protected void populate(SLDDataInterface sldData) {
    String layerName = sldData.getLayerName();
    File sldEditorFile = sldData.getSldEditorFile();
    if (sldEditorFile != null) {
        ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(getClass(), "SLDEditor.loadedSLDEditorFile"), sldEditorFile.getAbsolutePath()));
    }
    ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(getClass(), "SLDEditor.loadedSLDFile"), layerName));
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    SelectedSymbol selectedSymbolInstance = SelectedSymbol.getInstance();
    selectedSymbolInstance.setSld(sld);
    selectedSymbolInstance.setFilename(layerName);
    selectedSymbolInstance.setName(layerName);
    SLDEditorFile.getInstance().setSLDData(sldData);
    // Reload data source if sticky flag is set
    boolean isDataSourceSticky = SLDEditorFile.getInstance().isStickyDataSource();
    DataSourcePropertiesInterface previousDataSource = dataSource.getDataConnectorProperties();
    dataSource.reset();
    if (isDataSourceSticky) {
        SLDEditorFile.getInstance().setDataSource(previousDataSource);
    }
    dataSource.connect(ExternalFilenames.removeSuffix(layerName), SLDEditorFile.getInstance(), CheckAttributeFactory.getCheckList());
    VendorOptionManager.getInstance().loadSLDFile(uiMgr, sld, sldData);
    LegendManager.getInstance().SLDLoaded(sldData.getLegendOptions());
    SLDEditorFile.getInstance().fileOpenedSaved();
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Aggregations

SelectedSymbol (com.sldeditor.common.data.SelectedSymbol)13 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)7 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)6 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)6 Style (org.geotools.styling.Style)6 Test (org.junit.Test)6 LineSymbolizer (org.geotools.styling.LineSymbolizer)5 NamedLayer (org.geotools.styling.NamedLayer)5 Rule (org.geotools.styling.Rule)5 Symbolizer (org.geotools.styling.Symbolizer)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4 PointSymbolizer (org.geotools.styling.PointSymbolizer)4 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)4 PopulateDetailsInterface (com.sldeditor.ui.iface.PopulateDetailsInterface)2 StyledLayer (org.geotools.styling.StyledLayer)2 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)1 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)1 CardLayout (java.awt.CardLayout)1 File (java.io.File)1 Fill (org.geotools.styling.Fill)1