org.geotools.styling.StyledLayerDescriptor Java Examples

The following examples show how to use org.geotools.styling.StyledLayerDescriptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NewPolygonSLDTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/** Test new polygon sld. */
@Test
public void testNewPolygonSLD() {
    NewPolygonSLD newData = new NewPolygonSLD();

    StyledLayerDescriptor sld = newData.create();

    assertTrue(sld.layers().size() == 1);

    StyledLayer styledLayer = sld.layers().get(0);

    NamedLayer namedLayer = (NamedLayer) styledLayer;

    Symbolizer symbolizer =
            namedLayer
                    .styles()
                    .get(0)
                    .featureTypeStyles()
                    .get(0)
                    .rules()
                    .get(0)
                    .symbolizers()
                    .get(0);

    assertTrue(symbolizer instanceof PolygonSymbolizer);
}
 
Example #2
Source File: SLDWriterImpl.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Encode sld to a string
 *
 * @param sld the sld
 * @return the string
 */
public String encodeSLD(StyledLayerDescriptor sld)
{
    String xml = "";

    if(sld != null)
    {
        SLDTransformer transformer = new SLDTransformer();
        transformer.setIndentation(2);
        try {
            xml = transformer.transform(sld);
        } catch (TransformerException e) {
            ConsoleManager.getInstance().exception(this, e);
        }
    }

    return xml;
}
 
Example #3
Source File: BatchUpdateFontPanelTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
private Double getFontSize(SLDDataInterface sldData) {
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    NamedLayer namedLayer = (NamedLayer) sld.layers().get(0);
    TextSymbolizer text =
            (TextSymbolizer)
                    namedLayer
                            .styles()
                            .get(0)
                            .featureTypeStyles()
                            .get(0)
                            .rules()
                            .get(0)
                            .symbolizers()
                            .get(2);
    return Double.valueOf(text.getFont().getSize().toString());
}
 
Example #4
Source File: ExtractAttributesTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testMultiComparatorFilter() {
    DummyInternalSLDFile2 dummy = new DummyInternalSLDFile2();

    StyledLayerDescriptor sld = createTestSLD(dummy);
    List<Rule> ruleList = getRuleList(sld);

    Rule rule = DefaultSymbols.createNewRule();

    // Try with something complex
    Filter filter =
            ff.and(
                    ff.greater(ff.literal(42), ff.property("int")),
                    ff.less(ff.literal(12), ff.property("abc")));
    rule.setFilter(filter);
    ruleList.clear();
    ruleList.add(rule);
    ExtractAttributes extract = new ExtractAttributes();
    extract.extractDefaultFields(sld);

    // Check fields extracted ok
    List<DataSourceAttributeData> actualFieldnameList = extract.getFields();
    assertEquals(2, actualFieldnameList.size());
    DataSourceAttributeData dataSourceField = actualFieldnameList.get(0);
    assertEquals(Integer.class, dataSourceField.getType());
}
 
Example #5
Source File: SLDHandler.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
@Override
public StyledLayerDescriptor parse(
        Object input,
        Version version,
        ResourceLocator resourceLocator,
        EntityResolver entityResolver)
        throws IOException {
    if (version == null) {
        Object[] versionAndReader = getVersionAndReader(input);
        version = (Version) versionAndReader[0];
        input = versionAndReader[1];
    }

    if (VERSION_11.compareTo(version) == 0) {
        return parse11(input, resourceLocator, entityResolver);
    } else {
        return parse10(input, resourceLocator, entityResolver);
    }
}
 
Example #6
Source File: SLDWriterImpl.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Encode sld to a string.
 *
 * @param resourceLocator the resource locator
 * @param sld the sld
 * @return the string
 */
@Override
public String encodeSLD(URL resourceLocator, StyledLayerDescriptor sld) {
    String xml = "";

    if (sld != null) {
        InlineDatastoreVisitor duplicator = new InlineDatastoreVisitor();
        sld.accept(duplicator);
        StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicator.getCopy();

        if (resourceLocator != null) {
            SLDExternalImages.updateOnlineResources(resourceLocator, sldCopy);
        }

        SLDTransformer transformer = new SLDTransformer();
        transformer.setIndentation(2);
        try {
            xml = transformer.transform(sldCopy);
        } catch (TransformerException e) {
            ConsoleManager.getInstance().exception(this, e);
        }
    }

    return xml;
}
 
Example #7
Source File: BatchUpdateFontPanelTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
private String getFontName(SLDDataInterface sldData) {
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    NamedLayer namedLayer = (NamedLayer) sld.layers().get(0);
    TextSymbolizer text =
            (TextSymbolizer)
                    namedLayer
                            .styles()
                            .get(0)
                            .featureTypeStyles()
                            .get(0)
                            .rules()
                            .get(0)
                            .symbolizers()
                            .get(2);
    return text.getFont().getFamily().get(0).toString();
}
 
Example #8
Source File: ExtractAttributesTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testIsBetween() {
    DummyInternalSLDFile2 dummy = new DummyInternalSLDFile2();

    StyledLayerDescriptor sld = createTestSLD(dummy);
    List<Rule> ruleList = getRuleList(sld);

    Rule rule = DefaultSymbols.createNewRule();

    // Try isBetween
    Filter filter = ff.between(ff.property("test"), ff.literal("1.23"), ff.literal(4));
    rule.setFilter(filter);
    ruleList.clear();
    ruleList.add(rule);
    ExtractAttributes extract = new ExtractAttributes();
    extract.extractDefaultFields(sld);

    // Check fields extracted ok
    List<DataSourceAttributeData> actualFieldnameList = extract.getFields();
    assertEquals(1, actualFieldnameList.size());
    DataSourceAttributeData dataSourceField = actualFieldnameList.get(0);
    assertEquals(Double.class, dataSourceField.getType());
}
 
Example #9
Source File: ExtractValidFieldTypes.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Evaluate fields types.
 *
 * @return true, field types updated
 */
public static boolean fieldTypesUpdated() {
    boolean fieldsUpdated = false;

    StyledLayerDescriptor sld = SelectedSymbol.getInstance().getSld();

    if (sld != null) {
        List<StyledLayer> styledLayerList = sld.layers();

        for (StyledLayer styledLayer : styledLayerList) {
            List<org.geotools.styling.Style> styleList = SLDUtils.getStylesList(styledLayer);

            FeatureSource<SimpleFeatureType, SimpleFeature> featureList =
                    DataSourceFactory.getDataSource().getFeatureSource();

            if (featureList != null) {
                fieldsUpdated = processStyles(fieldsUpdated, styleList, featureList);
            }
        }
    }
    return fieldsUpdated;
}
 
Example #10
Source File: ExtractAttributesTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testFunctionExpression() {
    DummyInternalSLDFile2 dummy = new DummyInternalSLDFile2();

    StyledLayerDescriptor sld = createTestSLD(dummy);
    List<Rule> ruleList = getRuleList(sld);

    ExtractAttributes extract = new ExtractAttributes();
    Rule rule = DefaultSymbols.createNewRule();

    String expectedEnvVar = "testenvvar";
    Function function = ff.function("env", ff.property(expectedEnvVar));

    Filter filter = ff.equal(ff.literal("not equal"), function, true);
    rule.setFilter(filter);
    ruleList.clear();
    ruleList.add(rule);
    extract.extractDefaultFields(sld);

    // Check fields extracted ok
    List<DataSourceAttributeData> actualFieldnameList = extract.getFields();
    assertEquals(1, actualFieldnameList.size());
    DataSourceAttributeData dataSourceField = actualFieldnameList.get(0);
    assertEquals(String.class, dataSourceField.getType());
}
 
Example #11
Source File: LegendTool.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Save all legend to folder.
 *
 * @param destinationFolder the destination folder
 */
protected void saveAllLegendToFolder(File destinationFolder) {
    if (!destinationFolder.exists()) {
        destinationFolder.mkdirs();
    }

    logger.info(Localisation.getString(LegendTool.class, "LegendTool.saveAllLayerLegends"));

    for (SLDDataInterface sldData : sldDataList) {
        StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);

        if (sld != null) {
            String heading = null;
            String filename = null;

            String layerName = sldData.getLayerNameWithOutSuffix();

            List<String> filenameList = new ArrayList<>();

            LegendManager.getInstance()
                    .saveLegendImage(
                            sld, destinationFolder, layerName, heading, filename, filenameList);
        }
    }
}
 
Example #12
Source File: MapBoxWriterImpl.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Encode sld to a string.
 *
 * @param resourceLocator the resource locator
 * @param sld the sld
 * @return the MppBox string
 */
@Override
public String encodeSLD(URL resourceLocator, StyledLayerDescriptor sld) {

    SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
    if (sldData.getOriginalFormat() == SLDOutputFormatEnum.MAPBOX) {
        File f = sldData.getSLDFile();
        if ((cachedFile == null) || !cachedFile.equals(f)) {
            cachedFile = f;

            try {
                StringBuilder data = new StringBuilder();
                Stream<String> lines = Files.lines(f.toPath());
                lines.forEach(line -> data.append(line).append("\n"));
                lines.close();

                cachedString = data.toString();
            } catch (IOException e) {
                ConsoleManager.getInstance().exception(this, e);
            }
        }
        return cachedString;
    }

    return Localisation.getString(MapBoxWriterImpl.class, "MapBoxWriterImpl.notSupported");
}
 
Example #13
Source File: InlineFeatureUtilsTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InlineFeatureUtils#getInlineFeaturesText(org.geotools.styling.UserLayer)}.
 */
@Test
public void testGetInlineFeaturesText() {
    String actualResult = InlineFeatureUtils.getInlineFeaturesText(null);
    assertTrue(actualResult.compareTo("") == 0);

    // Test 1
    SLDData sldData = new SLDData(null, testInline1a);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);

    UserLayer userLayer1 = (UserLayer) sld.layers().get(0);

    actualResult = InlineFeatureUtils.getInlineFeaturesText(userLayer1);
    assertTrue(actualResult.startsWith("<FeatureCollection>"));
    assertTrue(actualResult.endsWith("</FeatureCollection>"));

    // Test 2
    sldData = new SLDData(null, testInline1b);
    sld = SLDUtils.createSLDFromString(sldData);

    UserLayer userLayer2 = (UserLayer) sld.layers().get(0);

    actualResult = InlineFeatureUtils.getInlineFeaturesText(userLayer2);
    assertTrue(actualResult.startsWith("<FeatureCollection>"));
    assertTrue(actualResult.endsWith("</FeatureCollection>"));
}
 
Example #14
Source File: SLDUtils.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a StyledLayerDescriptor object containing a SLD by reading the contents of a file.
 *
 * @param file the file
 * @return the styled layer descriptor
 */
public static StyledLayerDescriptor readSLDFile(File file) {
    StyledLayerDescriptor sld = null;

    if (file != null) {
        StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
        try {
            // By using URL here allows external graphics to loaded properly
            URL url = file.toURI().toURL();
            SLDParser styleReader = new SLDParser(styleFactory, url);
            setResourcelocator(styleReader, file.toURI().toURL());
            sld = styleReader.parseSLD();
        } catch (IOException e) {
            ConsoleManager.getInstance().exception(SLDUtils.class, e);
        }
    }
    return sld;
}
 
Example #15
Source File: NewRasterSLDTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/** Test new point sld. */
@Test
public void testNewRasterSLD() {
    NewRasterSLD newData = new NewRasterSLD();

    StyledLayerDescriptor sld = newData.create();

    assertTrue(sld.layers().size() == 1);

    StyledLayer styledLayer = sld.layers().get(0);

    NamedLayer namedLayer = (NamedLayer) styledLayer;

    Symbolizer symbolizer =
            namedLayer
                    .styles()
                    .get(0)
                    .featureTypeStyles()
                    .get(0)
                    .rules()
                    .get(0)
                    .symbolizers()
                    .get(0);

    assertTrue(symbolizer instanceof RasterSymbolizer);
}
 
Example #16
Source File: NewSLDPanel.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the selected SLD.
 *
 * @return the selected SLD
 */
protected List<SLDDataInterface> getSelectedSLD() {
    List<SLDDataInterface> newSLDList = null;
    if (selected != null) {
        newSLDList = new ArrayList<>();

        StyledLayerDescriptor sld = selected.create();

        if (sldWriter == null) {
            sldWriter = SLDWriterFactory.createWriter(null);
        }

        newSLDList.add(
                new SLDData(
                        new StyleWrapper(selected.getName()), sldWriter.encodeSLD(null, sld)));
    }
    return newSLDList;
}
 
Example #17
Source File: ExtractAttributesTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testIsNull() {
    DummyInternalSLDFile2 dummy = new DummyInternalSLDFile2();

    StyledLayerDescriptor sld = createTestSLD(dummy);
    List<Rule> ruleList = getRuleList(sld);

    Rule rule = DefaultSymbols.createNewRule();

    // Try isNull
    Filter filter = ff.isNull(ff.property("test"));
    rule.setFilter(filter);
    ruleList.clear();
    ruleList.add(rule);
    ExtractAttributes extract = new ExtractAttributes();
    extract.extractDefaultFields(sld);

    // Check fields extracted ok
    List<DataSourceAttributeData> actualFieldnameList = extract.getFields();
    assertEquals(1, actualFieldnameList.size());
    DataSourceAttributeData dataSourceField = actualFieldnameList.get(0);
    assertEquals(String.class, dataSourceField.getType());
}
 
Example #18
Source File: ExtractAttributesTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testIsLike() {
    DummyInternalSLDFile2 dummy = new DummyInternalSLDFile2();

    StyledLayerDescriptor sld = createTestSLD(dummy);
    List<Rule> ruleList = getRuleList(sld);

    Rule rule = DefaultSymbols.createNewRule();

    // Try isLike
    Filter filter = ff.like(ff.property("test"), "abcd1");
    rule.setFilter(filter);
    ruleList.clear();
    ruleList.add(rule);
    ExtractAttributes extract = new ExtractAttributes();
    extract.extractDefaultFields(sld);

    // Check fields extracted ok
    List<DataSourceAttributeData> actualFieldnameList = extract.getFields();
    assertEquals(1, actualFieldnameList.size());
    DataSourceAttributeData dataSourceField = actualFieldnameList.get(0);
    assertEquals(String.class, dataSourceField.getType());
}
 
Example #19
Source File: ScaleSLDData.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param sld the sld
 * @param sldData the sld data
 */
public ScaleSLDData(StyledLayerDescriptor sld, SLDDataInterface sldData) {
    super();
    this.sld = sld;
    this.sldData = sldData;
    if (sldData != null) {
        this.workspace = this.sldData.getStyle().getWorkspace();
        this.name = this.sldData.getLayerName();
    }
}
 
Example #20
Source File: SldUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public static Style getDefaultStyle( StyledLayerDescriptor sld ) {
    Style[] styles = SLD.styles(sld);
    for( int i = 0; i < styles.length; i++ ) {
        Style style = styles[i];
        List<FeatureTypeStyle> ftStyles = style.featureTypeStyles();
        genericizeftStyles(ftStyles);
        if (style.isDefault()) {
            return style;
        }
    }
    // no default, so just grab the first one
    return styles[0];
}
 
Example #21
Source File: YSLDFileHandler.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Internal open file.
 *
 * @param f the file
 * @param list the list
 */
private void internalOpenFile(File f, List<SLDDataInterface> list) {
    if (f.isFile() && FileSystemUtils.isFileExtensionSupported(f, getFileExtensionList())) {
        try {
            Charset fileEncoding = PrefManager.getInstance().getPrefData().getFileEncoding();

            String contents = readFile(f, fileEncoding);

            StyledLayerDescriptor sld = Ysld.parse(contents);

            // Convert YSLD to SLD string
            if (sldWriter == null) {
                sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
            }

            String sldContents = sldWriter.encodeSLD(null, sld);

            SLDDataInterface sldData = new SLDData(new StyleWrapper(f.getName()), sldContents);
            sldData.setSLDFile(f);
            sldData.setReadOnly(false);
            sldData.setOriginalFormat(SLDOutputFormatEnum.YSLD);

            list.add(sldData);
        } catch (IOException e) {
            ConsoleManager.getInstance().exception(this, e);
        }
    }
}
 
Example #22
Source File: LegendManager.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the legend.
 *
 * @param sld the sld
 * @param heading the heading
 * @param filename the filename
 * @return the buffered image
 */
public BufferedImage createLegend(StyledLayerDescriptor sld, String heading, String filename) {
    Map<String, BufferedImage> map = createLegend(sld, heading, filename, false);

    if ((map != null) && (map.size() == 1)) {
        String firstKey = map.keySet().iterator().next();

        return map.get(firstKey);
    }

    return null;
}
 
Example #23
Source File: StyleWrapper.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts a style to its string representation to be written to file.
 * 
 * @param style the style to convert.
 * @return the style string.
 * @throws Exception
 */
public String toXml() throws Exception {
    StyledLayerDescriptor sld = sf.createStyledLayerDescriptor();
    UserLayer layer = sf.createUserLayer();
    layer.setLayerFeatureConstraints(new FeatureTypeConstraint[] { null });
    sld.addStyledLayer(layer);
    layer.addUserStyle(style);

    SLDTransformer aTransformer = new SLDTransformer();
    aTransformer.setIndentation(4);
    String xml = aTransformer.transform(sld);
    return xml;
}
 
Example #24
Source File: RenderPanelImpl.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Render symbol. */
/*
 * (non-Javadoc)
 *
 * @see com.sldeditor.marker.iface.RenderSymbolInterface#renderSymbol()
 */
@Override
public void renderSymbol() {

    validSymbol = SelectedSymbol.getInstance().isValid();

    if (validSymbol) {
        StyledLayerDescriptor sld = SelectedSymbol.getInstance().getSld();
        SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();

        if (sld != null) {
            for (SLDOutputInterface sldOutput : sldOutputList) {
                sldOutput.updatedSLD(sldData, sld);
            }

            renderSymbol((Style) renderSymbol.getRenderStyle(SelectedSymbol.getInstance()));
        } else {
            renderSymbol(null);
        }
    } else {
        repaint();
    }
}
 
Example #25
Source File: SLDUtilsTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testReadSLDFile() {
    try {
        File tmpFile = File.createTempFile(getClass().getSimpleName(), ".sld");

        FileWriter fileWriter = new FileWriter(tmpFile);
        fileWriter.write(expectedSld);
        fileWriter.flush();
        fileWriter.close();

        StyledLayerDescriptor sld = SLDUtils.readSLDFile(null);

        assertNull(sld);
        sld = SLDUtils.readSLDFile(tmpFile);
        StyledLayer[] styledLayers = sld.getStyledLayers();
        NamedLayer namedLayer = (NamedLayer) styledLayers[0];
        Style[] actualStyles = namedLayer.getStyles();
        PointSymbolizer pointSymbolizer =
                (PointSymbolizer)
                        actualStyles[0]
                                .featureTypeStyles()
                                .get(0)
                                .rules()
                                .get(0)
                                .symbolizers()
                                .get(0);

        MarkImpl mark = (MarkImpl) pointSymbolizer.getGraphic().graphicalSymbols().get(0);
        assertEquals("circle", mark.getWellKnownName().toString());

        tmpFile.delete();
    } catch (IOException e) {
        e.printStackTrace();
        fail("Failed to create test file");
    }
}
 
Example #26
Source File: StyleUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Generates a style based on a graphic.
 * 
 * @param graphicsPath the graphic.
 * @return the generated style.
 * @throws IOException
 */
public static StyleWrapper createStyleFromGraphic( File graphicsPath ) throws IOException {
    String name = graphicsPath.getName();
    ExternalGraphic exGraphic = null;
    if (name.toLowerCase().endsWith(".png")) {
        exGraphic = sf.createExternalGraphic(graphicsPath.toURI().toURL(), "image/png");
    } else if (name.toLowerCase().endsWith(".svg")) {
        exGraphic = sf.createExternalGraphic(graphicsPath.toURI().toURL(), "image/svg+xml");
    } else if (name.toLowerCase().endsWith(".sld")) {
        StyledLayerDescriptor sld = readStyle(graphicsPath);
        Style style = SldUtilities.getDefaultStyle(sld);
        return new StyleWrapper(style);
    }

    if (exGraphic == null) {
        throw new IOException("Style could not be created!");
    }

    Graphic gr = sf.createDefaultGraphic();
    gr.graphicalSymbols().clear();
    gr.graphicalSymbols().add(exGraphic);
    Expression size = ff.literal(20);
    gr.setSize(size);

    Rule rule = sf.createRule();
    PointSymbolizer pointSymbolizer = sf.createPointSymbolizer(gr, null);
    rule.symbolizers().add(pointSymbolizer);

    FeatureTypeStyle featureTypeStyle = sf.createFeatureTypeStyle();
    featureTypeStyle.rules().add(rule);

    Style namedStyle = sf.createStyle();
    namedStyle.featureTypeStyles().add(featureTypeStyle);
    namedStyle.setName(FilenameUtils.removeExtension(name));

    return new StyleWrapper(namedStyle);
}
 
Example #27
Source File: NewLineSLD.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the symbol.
 *
 * @return the styled layer descriptor
 */
/* (non-Javadoc)
 * @see com.sldeditor.create.NewSLDInterface#create()
 */
@Override
public StyledLayerDescriptor create() {
    return DefaultSymbols.createNewLine();
}
 
Example #28
Source File: LegendPanelImage.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the legend icon.
 *
 * @param sld the sld
 * @param styleNameHeading the style name heading
 * @param filename the filename
 */
private void createLegendIcon(
        StyledLayerDescriptor sld, String styleNameHeading, String filename) {
    BufferedImage bImage = legend.createLegend(sld, styleNameHeading, filename);

    if (bImage != null) {
        imageIcon = new ImageIcon(bImage);
    } else {
        imageIcon = null;
    }

    this.setIcon(imageIcon);
}
 
Example #29
Source File: LegendPanelImage.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Render symbol. */
public void renderSymbol() {
    if (SelectedSymbol.getInstance().isValid()) {
        StyledLayerDescriptor sld = SelectedSymbol.getInstance().getSld();

        if (sld != null) {
            // Style name
            String styleNameHeading = null;

            if (showStyleName) {
                styleNameHeading = showStyleName(sld);
            }

            // Filename
            String filename = null;

            if (showFilename) {
                filename = SelectedSymbol.getInstance().getFilename();
                if (filename == null) {
                    filename = "";
                }
            }

            createLegendIcon(sld, styleNameHeading, filename);
        } else {
            this.setIcon(null);
        }
    } else {
        this.setIcon(null);
    }
    repaint();
}
 
Example #30
Source File: InlineFeatureUtilsTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InlineFeatureUtils#containsInLineFeatures(org.geotools.styling.StyledLayerDescriptor)}.
 */
@Test
public void testContainsInLineFeatures() {
    assertFalse(InlineFeatureUtils.containsInLineFeatures(null));

    // Contains inline data
    SLDData sldData = new SLDData(null, testInline1a);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    assertTrue(InlineFeatureUtils.containsInLineFeatures(sld));

    // Contains no inline data
    sldData = new SLDData(null, testNoInline);
    sld = SLDUtils.createSLDFromString(sldData);
    assertFalse(InlineFeatureUtils.containsInLineFeatures(sld));
}