org.geotools.styling.Style Java Examples

The following examples show how to use org.geotools.styling.Style. 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: ImageDataLoader.java    From gama with GNU General Public License v3.0 7 votes vote down vote up
private static Style createStyle(int band, double min, double max) {

		FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
		StyleFactory sf = CommonFactoryFinder.getStyleFactory();

		RasterSymbolizer sym = sf.getDefaultRasterSymbolizer();
		ColorMap cMap = sf.createColorMap();
		ColorMapEntry start = sf.createColorMapEntry();
		start.setColor(ff.literal("#ff0000"));
		start.setQuantity(ff.literal(min));
		ColorMapEntry end = sf.createColorMapEntry();
		end.setColor(ff.literal("#0000ff"));
		end.setQuantity(ff.literal(max));

		cMap.addColorMapEntry(start);
		cMap.addColorMapEntry(end);
		sym.setColorMap(cMap);
		Style style = SLD.wrapSymbolizers(sym);

		return style;
	}
 
Example #2
Source File: StyleDetails.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Populate.
 *
 * @param selectedSymbol the selected symbol
 */
/*
 * (non-Javadoc)
 *
 * @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.selectedsymbol.SelectedSymbol)
 */
@Override
public void populate(SelectedSymbol selectedSymbol) {

    if (selectedSymbol != null) {
        Style style = selectedSymbol.getStyle();

        populateStandardData(style);
        if (style != null) {
            fieldConfigVisitor.populateBooleanField(
                    FieldIdEnum.DEFAULT_STYLE, style.isDefault());
        }
    }
}
 
Example #3
Source File: ImportVectorDataNodeFromShapefileAction.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public VectorDataNode readVectorDataNode(File file, Product product, ProgressMonitor pm) throws IOException {

    DefaultFeatureCollection featureCollection = FeatureUtils.loadShapefileForProduct(file,
                                                                                      product,
                                                                                      crsProvider,
                                                                                      pm);
    Style[] styles = SLDUtils.loadSLD(file);
    ProductNodeGroup<VectorDataNode> vectorDataGroup = product.getVectorDataGroup();
    String name = VectorDataNodeImporter.findUniqueVectorDataNodeName(featureCollection.getSchema().getName().getLocalPart(),
                                                                      vectorDataGroup);
    if (styles.length > 0) {
        SimpleFeatureType featureType = SLDUtils.createStyledFeatureType(featureCollection.getSchema());


        VectorDataNode vectorDataNode = new VectorDataNode(name, featureType);
        DefaultFeatureCollection styledCollection = vectorDataNode.getFeatureCollection();
        String defaultCSS = vectorDataNode.getDefaultStyleCss();
        SLDUtils.applyStyle(styles[0], defaultCSS, featureCollection, styledCollection);
        return vectorDataNode;
    } else {
        return new VectorDataNode(name, featureCollection);
    }
}
 
Example #4
Source File: ShapefileAssistantPage3.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                                              boolean cellHasFocus) {
    JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    String text = null;
    if (value != null) {
        Style style = (Style) value;
        InternationalString title = style.getDescription().getTitle();
        if (title != null) {
            text = title.toString();
        }else {
            text = "Default Styler";
        }
    }
    label.setText(text);
    return label;
}
 
Example #5
Source File: RenderSymbol.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the render style.
 *
 * @param selectedSymbol the selected symbol
 * @return the render style
 */
public Style getRenderStyle(SelectedSymbol selectedSymbol) {
    List<StyledLayer> styledLayerList = selectedSymbol.getSld().layers();

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

        for (Style style : styleList) {
            FeatureTypeStyle ftsToRender = selectedSymbol.getFeatureTypeStyle();
            Rule ruleToRender = selectedSymbol.getRule();

            // Check to see if style contains the rule to render
            if (shouldRenderSymbol(style, ftsToRender, ruleToRender)) {
                return renderSymbol(style, ftsToRender, ruleToRender, renderOptions);
            }
        }
    }
    return null;
}
 
Example #6
Source File: ExtractValidFieldTypes.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Process styles.
 *
 * @param fieldsUpdated the fields updated
 * @param styleList the style list
 * @param featureList the feature list
 * @return true, if successful
 */
private static boolean processStyles(
        boolean fieldsUpdated,
        List<org.geotools.styling.Style> styleList,
        FeatureSource<SimpleFeatureType, SimpleFeature> featureList) {
    for (Style style : styleList) {
        for (FeatureTypeStyle fts : style.featureTypeStyles()) {
            for (Rule rule : fts.rules()) {
                Object drawMe = null;
                try {
                    drawMe = featureList.getFeatures().features().next();
                } catch (IOException | NoSuchElementException e) {
                    ConsoleManager.getInstance().exception(ExtractValidFieldTypes.class, e);
                }

                fieldsUpdated = processRule(fieldsUpdated, rule, drawMe);
            }
        }
    }
    return fieldsUpdated;
}
 
Example #7
Source File: Utils.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a default line style.
 *
 * @return the created style.
 */
public static Style createLineStyle() {
	final Stroke stroke = styleFactory.createStroke(filterFactory.literal(Color.BLUE), filterFactory.literal(1));

	/*
	 * Setting the geometryPropertyName arg to null signals that we want to draw the default geomettry of features
	 */
	final LineSymbolizer sym = styleFactory.createLineSymbolizer(stroke, null);

	final Rule rule = styleFactory.createRule();
	rule.symbolizers().add(sym);
	final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[] { rule });
	final Style style = styleFactory.createStyle();
	style.featureTypeStyles().add(fts);

	return style;
}
 
Example #8
Source File: MapUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates a feature layer based on a map object.
 */
public static Layer createFeatureLayerFromMapObject( InternalMapObject mapObject )
{
    Style style = mapObject.getStyle();
    
    SimpleFeatureType featureType = mapObject.getFeatureType();
    SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder( featureType );
    DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
    
    featureBuilder.add( mapObject.getGeometry() );
    SimpleFeature feature = featureBuilder.buildFeature( null );

    featureCollection.add( feature );

    return new FeatureLayer( featureCollection, style );
}
 
Example #9
Source File: StyleConverterServiceTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testFilters() throws LayerException {
	Style style = styleConverterService.convert(layerBeansMixedGeometryStyleInfoSld.getUserStyle());
	List<Rule> rules = style.featureTypeStyles().get(0).rules();
	assertThat(rules.get(0).getFilter()).isInstanceOf(BBOX.class);
	assertThat(rules.get(1).getFilter()).isInstanceOf(Contains.class);
	assertThat(rules.get(2).getFilter()).isInstanceOf(Crosses.class);
	assertThat(rules.get(3).getFilter()).isInstanceOf(Disjoint.class);
	assertThat(rules.get(4).getFilter()).isInstanceOf(Equals.class);
	assertThat(rules.get(5).getFilter()).isInstanceOf(Intersects.class);
	assertThat(rules.get(6).getFilter()).isInstanceOf(Overlaps.class);
	assertThat(rules.get(7).getFilter()).isInstanceOf(Touches.class);
	assertThat(rules.get(8).getFilter()).isInstanceOf(Within.class);
	NamedStyleInfo namedStyleInfo = styleConverterService.convert(
			layerBeansMixedGeometryStyleInfoSld.getUserStyle(), featureInfo);
	Assert.assertEquals(9, namedStyleInfo.getFeatureStyles().size());
}
 
Example #10
Source File: RasterReader.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates the rgb style.
 *
 * @param reader the reader
 * @param raster the raster
 * @return the style
 */
private Style createRGBStyle(AbstractGridCoverage2DReader reader, WritableRaster raster) {
    RasterSymbolizer sym = sf.getDefaultRasterSymbolizer();

    GridCoverage2D cov = null;
    try {
        cov = reader.read(null);
    } catch (IOException giveUp) {
        throw new RuntimeException(giveUp);
    }
    // We need at least three bands to create an RGB style
    int numBands = cov.getNumSampleDimensions();
    if (numBands < 3) {
        createRGBImageSymbol(sym, cov, raster);
    } else {
        createRGBChannelSymbol(sym, cov, numBands);
    }
    return SLD.wrapSymbolizers(sym);
}
 
Example #11
Source File: Utils.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a default polygon style.
 *
 * @return the created style.
 */
public static Style createPolygonStyle() {

	// create a partially opaque outline stroke
	final Stroke stroke = styleFactory.createStroke(filterFactory.literal(Color.BLUE), filterFactory.literal(1),
			filterFactory.literal(0.5));

	// create a partial opaque fill
	final Fill fill = styleFactory.createFill(filterFactory.literal(Color.CYAN), filterFactory.literal(0.5));

	/*
	 * Setting the geometryPropertyName arg to null signals that we want to draw the default geomettry of features
	 */
	final PolygonSymbolizer sym = styleFactory.createPolygonSymbolizer(stroke, fill, null);

	final Rule rule = styleFactory.createRule();
	rule.symbolizers().add(sym);
	final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[] { rule });
	final Style style = styleFactory.createStyle();
	style.featureTypeStyles().add(fts);

	return style;
}
 
Example #12
Source File: FeatureLayer.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public FeatureLayer(LayerType layerType, final FeatureCollection<SimpleFeatureType, SimpleFeature> fc,
                    PropertySet configuration) {
    super(layerType, configuration);
    crs = fc.getSchema().getGeometryDescriptor().getCoordinateReferenceSystem();
    if (crs == null) {
        // todo - check me! Why can this happen??? (nf)
        crs = DefaultGeographicCRS.WGS84;
    }
    final ReferencedEnvelope envelope = new ReferencedEnvelope(fc.getBounds(), crs);
    modelBounds = new Rectangle2D.Double(envelope.getMinX(), envelope.getMinY(),
                                         envelope.getWidth(), envelope.getHeight());
    mapContext = new DefaultMapContext(crs);
    final Style style = (Style) configuration.getValue(FeatureLayerType.PROPERTY_NAME_SLD_STYLE);
    mapContext.addLayer(fc, style);
    renderer = new StreamingRenderer();
    workaroundLabelCacheBug();
    style.accept(new RetrievingStyleVisitor());
    renderer.setContext(mapContext);

}
 
Example #13
Source File: LegendManager.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates the legend for a single SLD style.
 *
 * @param styleMap the style map
 * @param selectedStyledLayer the selected styled layer
 * @param selectedStyle the selected style
 */
private void createSingleStyleLegend(
        Map<String, Style> styleMap, StyledLayer selectedStyledLayer, Style selectedStyle) {
    // A style has been selected
    List<Style> styleList = SLDUtils.getStylesList(selectedStyledLayer);

    String styleName;
    if (selectedStyle.getName() != null) {
        styleName = selectedStyle.getName();
    } else {
        styleName =
                String.format(
                        "Style %d", (styleList != null) ? styleList.indexOf(selectedStyle) : 0);
    }

    styleMap.put(styleName, selectedStyle);
}
 
Example #14
Source File: SymbolizerFilterVisitorTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testGeometries() throws IOException{
	SymbolizerFilterVisitor visitor = new SymbolizerFilterVisitor();
	visitor.setIncludeGeometry(true);
	visitor.setIncludeText(false);
	SLDParser parser = new SLDParser(styleFactory);
	parser.setInput(getClass().getResource("point_pointwithdefaultlabel.sld"));
	Style[] styles = parser.readXML();
	Assert.assertEquals(1, styles.length);
	visitor.visit(styles[0]);
	Style copy = (Style) visitor.getCopy();
	FeatureTypeStyle featureTypeStyle = copy.featureTypeStyles().iterator().next();
	Rule rule = featureTypeStyle.rules().iterator().next();
	Iterator<Symbolizer> it = rule.symbolizers().iterator();
	Assert.assertTrue(it.next() instanceof PointSymbolizer);
	Assert.assertFalse(it.hasNext());
}
 
Example #15
Source File: StyleConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Style convert(UserStyleInfo userStyleInfo) throws LayerException {
	IBindingFactory bindingFactory;
	try {
		// create a dummy SLD root
		StyledLayerDescriptorInfo sld = new StyledLayerDescriptorInfo();
		sld.setVersion(SLD_VERSION);
		StyledLayerDescriptorInfo.ChoiceInfo choice = new StyledLayerDescriptorInfo.ChoiceInfo();
		NamedLayerInfo namedLayerInfo = new NamedLayerInfo();
		namedLayerInfo.setName(DUMMY_NAMED_LAYER);
		NamedLayerInfo.ChoiceInfo userChoice = new NamedLayerInfo.ChoiceInfo();
		userChoice.setUserStyle(userStyleInfo);
		namedLayerInfo.getChoiceList().add(userChoice);
		choice.setNamedLayer(namedLayerInfo);
		sld.getChoiceList().add(choice);

		// force through Geotools parser
		bindingFactory = BindingDirectory.getFactory(StyledLayerDescriptorInfo.class);
		IMarshallingContext marshallingContext = bindingFactory.createMarshallingContext();
		StringWriter sw = new StringWriter();
		marshallingContext.setOutput(sw);
		marshallingContext.marshalDocument(sld);

		SLDParser parser = new SLDParser(styleFactory, filterService.getFilterFactory());
		parser.setOnLineResourceLocator(new ResourceServiceBasedLocator());
		parser.setInput(new StringReader(sw.toString()));

		Style[] styles = parser.readXML();
		if (styles.length != 0) {
			return styles[0];
		} else {
			throw new LayerException(ExceptionCode.INVALID_USER_STYLE, userStyleInfo.getName());
		}
	} catch (Exception e) {
		throw new LayerException(e, ExceptionCode.INVALID_USER_STYLE, userStyleInfo.getName());
	}
}
 
Example #16
Source File: SimpleConfigurator.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Construct <code>SimpleStyleConfigurator</code>.
 */
public SimpleConfigurator(final Shell parent, final SimpleFeatureCollection featureCollection, final Style style) {
	super(parent);
	this.featureCollection = featureCollection;
	this.style = style;
	this.line.addListener(this.synchronize);
	this.fill.addListener(this.synchronize);
	this.point.addListener(this.synchronize);
}
 
Example #17
Source File: SLDUtils.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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();

        int styledLayerIndex = 0;
        int styleIndex = 0;
        int ftsIndex = 0;
        int ruleIndex = 0;

        for (StyledLayer styledLayer : styledLayerList) {
            List<Style> styleList = getStylesList(styledLayer);

            styleIndex = 0;
            for (Style style : styleList) {
                ftsIndex = 0;
                for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                    ruleIndex = fts.rules().indexOf(ruleToFind);
                    if (ruleIndex > -1) {
                        return findEquivalentRule(
                                otherSLD, styledLayerIndex, styleIndex, ftsIndex, ruleIndex);
                    }
                    ftsIndex++;
                }
                styleIndex++;
            }
            styledLayerIndex++;
        }
    }
    return null;
}
 
Example #18
Source File: ShapefileAssistantPage3.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void done() {
    final LayerSourcePageContext context = getContext();
    context.getWindow().setCursor(Cursor.getDefaultCursor());
    final ProductSceneView sceneView = SnapApp.getDefault().getSelectedProductSceneView();
    try {
        final Layer layer = get();
        final LayerCanvas layerCanvas = new LayerCanvas(layer);
        layerCanvas.getViewport().setModelYAxisDown(sceneView.getLayerCanvas().getViewport().isModelYAxisDown());
        addToMapPanel(layerCanvas);
        final Rectangle2D bounds = layer.getModelBounds();
        infoLabel.setText(String.format("Model bounds [%.3f : %.3f, %.3f : %.3f]",
                                        bounds.getMinX(), bounds.getMinY(),
                                        bounds.getMaxX(), bounds.getMaxY()));

        Style[] styles = (Style[]) context.getPropertyValue(ShapefileLayerSource.PROPERTY_NAME_STYLES);
        Style selectedStyle = (Style) context.getPropertyValue(ShapefileLayerSource.PROPERTY_NAME_SELECTED_STYLE);
        styleList.setModel(new DefaultComboBoxModel(styles));
        styleList.setSelectedItem(selectedStyle);
        shapeFileLoaded = true;
    } catch (ExecutionException e) {
        final String errorMessage = MessageFormat.format("<html><b>Error:</b> <i>{0}</i></html>",
                                                         e.getMessage());
        e.printStackTrace();
        mapLabel.setText(errorMessage);
        addToMapPanel(mapLabel);
    } catch (InterruptedException ignore) {
        // ok
    } finally {
        context.updateState();
    }
}
 
Example #19
Source File: StyleConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Rule convert(RuleInfo ruleInfo) throws LayerException {
	UserStyleInfo styleInfo = new UserStyleInfo();
	FeatureTypeStyleInfo fts = new FeatureTypeStyleInfo();
	fts.getRuleList().add(ruleInfo);
	styleInfo.getFeatureTypeStyleList().add(fts);
	Style style = convert(styleInfo);
	return style.featureTypeStyles().get(0).rules().get(0);
}
 
Example #20
Source File: StyleWrapper.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public StyleWrapper(Style style) {
    this.style = style;
    name = style.getName();

    List<FeatureTypeStyle> featureTypeStyles = style.featureTypeStyles();
    for (FeatureTypeStyle featureTypeStyle : featureTypeStyles) {
        FeatureTypeStyleWrapper fstW = new FeatureTypeStyleWrapper(featureTypeStyle, this);
        featureTypeStylesWrapperList.add(fstW);
    }
}
 
Example #21
Source File: SimpleStyleUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return
 */
public static Style createSimpleLineStyle( Color color, float width ) {
    FeatureTypeStyle featureTypeStyle = StyleUtilities.sf.createFeatureTypeStyle();
    featureTypeStyle.rules().add(createSimpleLineRule(color, width));

    Style style = StyleUtilities.sf.createStyle();
    style.featureTypeStyles().add(featureTypeStyle);

    return style;
}
 
Example #22
Source File: RasterizedSpatialiteLayer.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
private static GTRenderer getRenderer( ASpatialDb db, String tableName, int featureLimit, Style style ) {
    MapContent mapContent = new MapContent();

    // read data and convert it to featurecollection
    try {
        long t1 = System.currentTimeMillis();
        System.out.println("STARTED READING: " + tableName);

        String databasePath = db.getDatabasePath();
        File dbFile = new File(databasePath);
        File parentFolder = dbFile.getParentFile();
        if (style == null) {
            File sldFile = new File(parentFolder, tableName + ".sld");
            if (sldFile.exists()) {
                style = SldUtilities.getStyleFromFile(sldFile);
            }
        }

        DefaultFeatureCollection fc = SpatialDbsImportUtils.tableToFeatureFCollection(db, tableName, featureLimit,
                NwwUtilities.GPS_CRS_SRID, null);
        long t2 = System.currentTimeMillis();
        System.out.println("FINISHED READING: " + tableName + " -> " + ((t2 - t1) / 1000) + "sec");
        if (style == null) {
            style = SLD.createSimpleStyle(fc.getSchema());
        }
        FeatureLayer layer = new FeatureLayer(fc, style);

        long t3 = System.currentTimeMillis();
        System.out.println("FINISHED BUILDING: " + tableName + " -> " + ((t3 - t2) / 1000) + "sec");

        mapContent.addLayer(layer);
    } catch (Exception e) {
        e.printStackTrace();
    }
    GTRenderer renderer = new StreamingRenderer();
    renderer.setMapContent(mapContent);
    return renderer;
}
 
Example #23
Source File: SldUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public static Style getStyleFromRasterFile( File file ) throws Exception {
    String coveragePath = file.getAbsolutePath();
    if (CoverageUtilities.isGrass(coveragePath)) {
        return getGrassStyle(coveragePath);
    } else {
        RasterSymbolizer sym = sf.getDefaultRasterSymbolizer();
        return SLD.wrapSymbolizers(sym);
    }
}
 
Example #24
Source File: SLDUtils.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public static Style[] createFromSLD(File sld) {
    try {
        SLDParser stylereader = new SLDParser(styleFactory, sld.toURI().toURL());
        return stylereader.readXML();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new Style[0];
}
 
Example #25
Source File: NamedLayerDetails.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Update symbol. */
private void updateSymbol() {
    if (!Controller.getInstance().isPopulating()) {
        String name = fieldConfigVisitor.getText(FieldIdEnum.NAME);
        NamedLayer namedLayer = getStyleFactory().createNamedLayer();
        namedLayer.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()];
            namedLayer.setLayerFeatureConstraints(ftcList.toArray(ftcArray));
        }

        StyledLayer existingStyledLayer = SelectedSymbol.getInstance().getStyledLayer();
        if (existingStyledLayer instanceof NamedLayerImpl) {
            NamedLayerImpl existingNamedLayer = (NamedLayerImpl) existingStyledLayer;

            for (Style style : existingNamedLayer.styles()) {
                namedLayer.addStyle(style);
            }
        }
        SelectedSymbol.getInstance().replaceStyledLayer(namedLayer);

        this.fireUpdateSymbol();
    }
}
 
Example #26
Source File: RenderSymbolTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Test method for {@link com.sldeditor.render.RenderSymbol#RenderSymbol()}. */
@Test
public void testRenderSymbol() {
    RenderSymbol symbol = new RenderSymbol();

    StyledLayerDescriptor sld = createSLD();

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

    if (styledLayer instanceof NamedLayerImpl) {
        NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;

        Style expectedStyle = namedLayerImpl.styles().get(0);

        SelectedSymbol.getInstance().setSld(sld);
        Style actualStyle = symbol.getRenderStyle(SelectedSymbol.getInstance());

        assertNull(actualStyle.featureTypeStyles().get(0).rules().get(0).getFilter());
        assertEquals(expectedStyle.getName(), actualStyle.getName());

        Rule expectedRule = expectedStyle.featureTypeStyles().get(0).rules().get(1);
        SelectedSymbol.getInstance()
                .setFeatureTypeStyle(expectedStyle.featureTypeStyles().get(0));
        SelectedSymbol.getInstance().setRule(expectedRule);
        actualStyle = symbol.getRenderStyle(SelectedSymbol.getInstance());
        assertNull(actualStyle.featureTypeStyles().get(0).rules().get(0).getFilter());
        assertEquals(
                expectedRule.getName(),
                actualStyle.featureTypeStyles().get(0).rules().get(0).getName());
    }
}
 
Example #27
Source File: StandardPanel.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Populate standard data.
 *
 * @param style the style
 */
protected void populateStandardData(Style style) {
    StandardData standardData = new StandardData();

    if (style != null) {
        standardData.name = style.getName();
        standardData.description = style.getDescription();
    }

    populateStandardData(standardData);
}
 
Example #28
Source File: StyleTreeItemTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.tree.item.StyleTreeItem#getTreeString(java.lang.Object)}.
 */
@Test
public void testGetTreeString() {
    StyleTreeItem item = new StyleTreeItem();
    String actualValue = item.getTreeString(null, null);
    String expectedValue =
            String.format(
                    "%s : %s",
                    Localisation.getString(SLDTreeTools.class, "TreeItem.style"), "");
    assertTrue(actualValue.compareTo(expectedValue) == 0);

    Style style = DefaultSymbols.createNewStyle();

    actualValue = item.getTreeString(null, style);
    expectedValue =
            String.format(
                    "%s : %s",
                    Localisation.getString(SLDTreeTools.class, "TreeItem.style"),
                    Localisation.getString(SLDTreeTools.class, "TreeItem.newStyle"));
    assertTrue(actualValue.compareTo(expectedValue) == 0);

    style.setName(null);
    actualValue = item.getTreeString(null, style);
    expectedValue =
            String.format(
                    "%s : %s",
                    Localisation.getString(SLDTreeTools.class, "TreeItem.style"), "");
    assertTrue(actualValue.compareTo(expectedValue) == 0);

    String expectedName = "test name";
    style.setName(expectedName);
    actualValue = item.getTreeString(null, style);
    expectedValue =
            String.format(
                    "%s : %s",
                    Localisation.getString(SLDTreeTools.class, "TreeItem.style"), expectedName);
    assertTrue(actualValue.compareTo(expectedValue) == 0);
}
 
Example #29
Source File: SLDUtils.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public static Style[] loadSLD(File shapeFile) {
    File sld = getSLDFile(shapeFile);
    if (sld.exists()) {
        return createFromSLD(sld);
    } else {
        return new Style[0];
    }
}
 
Example #30
Source File: SelectedSymbol.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Replace style.
 *
 * @param newStyle the new style
 */
public void replaceStyle(Style newStyle) {

    List<Style> styleList = SLDUtils.getStylesList(this.symbolData.getStyledLayer());

    Style oldStyle = null;
    int indexFound = -1;
    int index = 0;
    for (Style style : styleList) {
        if (style == this.symbolData.getStyle()) {
            oldStyle = style;
            indexFound = index;
            break;
        } else {
            index++;
        }
    }

    if (indexFound > -1) {
        styleList.remove(indexFound);
        styleList.add(indexFound, newStyle);
        setStyle(newStyle);
    }

    for (SLDTreeUpdatedInterface listener : treeUpdateListenerList) {
        listener.updateNode(oldStyle, newStyle);
    }
}