org.geotools.styling.Stroke Java Examples

The following examples show how to use org.geotools.styling.Stroke. 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: SymbolManager.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the stroke.
 *
 * @param jsonElementSymbol the json element symbol
 * @return the stroke list
 */
public List<Stroke> getStrokeList(JsonElement jsonElementSymbol) {
    List<Stroke> strokeList = null;

    if(jsonElementSymbol != null)
    {
        JsonObject jsonSymbol = jsonElementSymbol.getAsJsonObject();

        for(String lineSymbolType : lineSymbolMap.keySet())
        {
            JsonElement obj = jsonSymbol.get(lineSymbolType);

            if(obj != null)
            {
                EsriLineSymbolInterface esriLineSymbol = lineSymbolMap.get(lineSymbolType);
                strokeList = esriLineSymbol.convert(obj);
                break;
            }
        }
    }
    return strokeList;
}
 
Example #2
Source File: FieldConfigArrow.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the stroke value.
 *
 * @param fieldConfigManager the field config manager
 * @param strokeEnabled the stroke enabled
 * @return the stroke value
 */
private Stroke getStrokeValue(
        GraphicPanelFieldManager fieldConfigManager, boolean strokeEnabled) {
    FieldConfigBase field;
    Stroke stroke = null;

    if (strokeEnabled && (strokeFieldConfig != null)) {
        Expression expStrokeColour = null;
        Expression expStrokeColourOpacity = null;

        field = fieldConfigManager.get(strokeFieldConfig.getColour());
        if (field instanceof FieldConfigColour) {
            FieldConfigColour colourField = (FieldConfigColour) field;

            expStrokeColour = colourField.getColourExpression();
        }
        field = fieldConfigManager.get(strokeFieldConfig.getOpacity());
        if (field != null) {
            expStrokeColourOpacity = field.getExpression();
        }
        stroke = getStyleFactory().createStroke(expStrokeColour, expStrokeColourOpacity);
    }
    return stroke;
}
 
Example #3
Source File: SLDTreeLeafLine.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the stroke.
 *
 * @param symbolizer the symbolizer
 * @return the stroke
 */
/*
 * (non-Javadoc)
 *
 * @see com.sldeditor.ui.tree.SLDTreeLeafInterface#getStroke(org.opengis.style.Symbolizer)
 */
@Override
public Stroke getStroke(Symbolizer symbolizer) {
    Stroke stroke = null;

    if (symbolizer instanceof LineSymbolizer) {
        LineSymbolizer line = (LineSymbolizer) symbolizer;

        stroke = line.getStroke();
    }

    return stroke;
}
 
Example #4
Source File: FieldConfigMarker.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the geo server stroke value.
 *
 * @param fieldConfigManager the field config manager
 * @return the geo server stroke value
 */
private Stroke getGeoServerStrokeValue(GraphicPanelFieldManager fieldConfigManager) {
    Stroke stroke;
    Expression strokeColour = null;
    FieldConfigBase field = fieldConfigManager.get(fillFieldConfig.getColour());
    if (field != null) {
        strokeColour = ((FieldConfigColour) field).getColourExpression();
    }

    Expression strokeColourOpacity = null;
    field = fieldConfigManager.get(fillFieldConfig.getOpacity());
    if (field != null) {
        strokeColourOpacity = field.getExpression();
    }

    Expression strokeWidth = null;
    field = fieldConfigManager.get(fillFieldConfig.getWidth());
    if (field != null) {
        strokeWidth = field.getExpression();
    }

    stroke = getStyleFactory().createStroke(strokeColour, strokeWidth, strokeColourOpacity);
    return stroke;
}
 
Example #5
Source File: SLDTreeLeafFactory.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Update stroke.
 *
 * @param selected the selected
 * @param symbolizer the symbolizer
 * @return the stroke
 */
public Stroke updateStroke(boolean selected, Symbolizer symbolizer) {
    if (symbolizer == null) {
        return null;
    }

    boolean currentValue = hasStroke(symbolizer);

    if (currentValue != selected) {
        SLDTreeLeafInterface obj = map.get(symbolizer.getClass());
        if (obj != null) {
            if (selected) {
                logger.debug("Set stroke");
                obj.createStroke(symbolizer);
            } else {
                logger.debug("Clear stroke");
                obj.removeStroke(symbolizer);
            }
        }
    }
    return getStroke(symbolizer);
}
 
Example #6
Source File: SLDExternalImages.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Update stroke.
 *
 * @param resourceLocator the resource locator
 * @param stroke the stroke
 * @param externalImageList the external image list
 */
private static void updateStroke(
        URL resourceLocator,
        Stroke stroke,
        List<String> externalImageList,
        ProcessGraphicSymbolInterface process) {
    if (stroke != null) {
        if (stroke.getGraphicFill() != null) {
            process.processGraphicalSymbol(
                    resourceLocator,
                    stroke.getGraphicFill().graphicalSymbols(),
                    externalImageList);
        }

        if (stroke.getGraphicStroke() != null) {
            process.processGraphicalSymbol(
                    resourceLocator,
                    stroke.getGraphicStroke().graphicalSymbols(),
                    externalImageList);
        }
    }
}
 
Example #7
Source File: StrokeTreeItemTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.tree.item.StrokeTreeItem#getTreeString(java.lang.Object)}.
 */
@Test
public void testGetTreeString() {
    StrokeTreeItem item = new StrokeTreeItem();
    String actualValue = item.getTreeString(null, null);
    String expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.stroke");
    assertTrue(actualValue.compareTo(expectedValue) == 0);

    Stroke stroke = DefaultSymbols.createDefaultStroke();

    actualValue = item.getTreeString(null, stroke);
    assertTrue(actualValue.compareTo(expectedValue) == 0);

    actualValue = item.getTreeString(null, stroke);
    assertTrue(actualValue.compareTo(expectedValue) == 0);
}
 
Example #8
Source File: GetMinimumVersionTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/** Test method for StrokeDetails */
@Test
public void testStrokeGetMinimumVersion() {
    StrokeDetails details = new StrokeDetails();

    details.getMinimumVersion(null, null, null);

    Stroke stroke = styleFactory.createStroke(ff.literal("#654321"), ff.literal(3.2));
    Graphic graphicStroke = styleFactory.createDefaultGraphic();
    stroke.setGraphicStroke(graphicStroke);

    List<VendorOptionPresent> vendorOptionsPresentList = null;
    Object parentObj = null;
    details.getMinimumVersion(parentObj, stroke, vendorOptionsPresentList);

    vendorOptionsPresentList = new ArrayList<VendorOptionPresent>();
    details.getMinimumVersion(parentObj, stroke, vendorOptionsPresentList);

    assertTrue(vendorOptionsPresentList.size() == 0);
}
 
Example #9
Source File: MultiLayerLineSymbol.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<Stroke> convert(JsonElement element) {

    if(element == null) return null;

    List<Stroke> strokeList = null;

    JsonArray layerList = element.getAsJsonArray();
    if(layerList.size() > 0)
    {
        strokeList = new ArrayList<Stroke>();

        for(int index = 0; index < layerList.size(); index ++)
        {
            JsonObject obj = layerList.get(index).getAsJsonObject();

            List<Stroke> strokeSymbolList = SymbolManager.getInstance().getStrokeList(obj.get(MultiLayerLineSymbolKeys.LINE));
            if(strokeSymbolList != null)
            {
                strokeList.addAll(strokeSymbolList);
            }
        }
    }
    return strokeList;
}
 
Example #10
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 #11
Source File: StyleConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
private Stroke createStroke(FeatureStyleInfo featureStyle) throws LayerException {
	Stroke stroke = styleBuilder.createStroke(styleBuilder.literalExpression(featureStyle.getStrokeColor()),
			styleBuilder.literalExpression(featureStyle.getStrokeWidth()),
			styleBuilder.literalExpression(featureStyle.getStrokeOpacity()));
	if (featureStyle.getDashArray() != null) {
		String[] strings = featureStyle.getDashArray().split(",");
		float[] nrs = new float[strings.length];
		for (int i = 0; i < strings.length; i++) {
			try {
				nrs[i] = parseFloat(strings[i]);
			} catch (NumberFormatException e) {
				log.warn("Dash array cannot be parsed " + featureStyle.getDashArray(), e);
			}
		}
		stroke.setDashArray(nrs);
	}
	return stroke;
}
 
Example #12
Source File: StyleGenerator.java    From constellation with Apache License 2.0 6 votes vote down vote up
private static Rule makeFillRule() {
    final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory();
    final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();

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

    // create a partially opaque fill
    Fill fill = styleFactory.createFill(
            filterFactory.literal(COLORS.next()),
            filterFactory.literal(.5)
    );

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

    final Rule rule = styleFactory.createRule();
    rule.symbolizers().add(sym);

    return rule;
}
 
Example #13
Source File: CartographicLineSymbol.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Convert.
 *
 * @param rule the rule
 * @param element the element
 * @param layerName the layer name
 * @param transparency the transparency
 */
@Override
public void convert(Rule rule, JsonElement element, String layerName, int transparency) {
    if(rule == null) return;
    if(element == null) return;

    JsonObject obj = element.getAsJsonObject();

    List<Symbolizer> symbolizerList = rule.symbolizers();

    List<Stroke> strokeList = convert(obj);

    Stroke stroke = null;

    if(!strokeList.isEmpty())
    {
        stroke = strokeList.get(0);
    }

    LineSymbolizer lineSymbolizer = styleFactory.createLineSymbolizer(stroke, null);

    symbolizerList.add(lineSymbolizer);
}
 
Example #14
Source File: ShapefileLoader.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private static Style createPolygonStyle() {
    PolygonSymbolizer symbolizer = styleFactory.createPolygonSymbolizer();
    Fill fill = styleFactory.createFill(
            filterFactory.literal("#FFAA00"),
            filterFactory.literal(0.5)
    );
    final Stroke stroke = styleFactory.createStroke(filterFactory.literal(Color.BLACK),
                                                    filterFactory.literal(1));
    symbolizer.setFill(fill);
    symbolizer.setStroke(stroke);
    Rule rule = styleFactory.createRule();
    rule.symbolizers().add(symbolizer);
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    fts.rules().add(rule);

    Style style = styleFactory.createStyle();
    style.featureTypeStyles().add(fts);
    return style;
}
 
Example #15
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 #16
Source File: SimpleLineSymbol.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void convert(Rule rule, JsonElement element, String layerName, int transparency) {
    if(element == null) return;
    if(rule == null) return;

    JsonObject obj = element.getAsJsonObject();
    @SuppressWarnings("unused")
    int style = getInt(obj, CommonSymbolKeys.STYLE);

    List<Symbolizer> symbolizerList = rule.symbolizers();

    List<Stroke> strokeList = convert(obj);

    Stroke stroke = null;

    if(!strokeList.isEmpty())
    {
        stroke = strokeList.get(0);
    }

    LineSymbolizer lineSymbolizer = styleFactory.createLineSymbolizer(stroke, null);

    symbolizerList.add(lineSymbolizer);
}
 
Example #17
Source File: SLDTreeLeafPolygon.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Stroke getStroke(Symbolizer symbolizer) {
    Stroke stroke = null;
    if (symbolizer instanceof PolygonSymbolizer) {
        PolygonSymbolizer polygon = (PolygonSymbolizer) symbolizer;

        stroke = polygon.getStroke();
    }
    return stroke;
}
 
Example #18
Source File: DefaultSymbols.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the default point symbolizer.
 *
 * @return the point symbolizer
 */
public static PointSymbolizer createDefaultPointSymbolizer() {
    String geometryFieldName = null;
    Expression geometryField = ff.property(geometryFieldName);

    List<GraphicalSymbol> symbolList = new ArrayList<>();

    Stroke stroke = null;
    AnchorPoint anchorPoint = null;
    Displacement displacement = null;
    Fill fill = styleFactory.createFill(ff.literal(DEFAULT_MARKER_COLOUR));
    GraphicalSymbol symbol = styleFactory.mark(ff.literal(DEFAULT_MARKER_SYMBOL), fill, stroke);

    symbolList.add(symbol);
    Graphic graphic =
            styleFactory.graphic(
                    symbolList,
                    ff.literal(DEFAULT_COLOUR_OPACITY),
                    ff.literal(DEFAULT_MARKER_SYMBOL_SIZE),
                    ff.literal(0.0),
                    anchorPoint,
                    displacement);
    return styleFactory.pointSymbolizer(
            Localisation.getString(SLDTreeTools.class, "TreeItem.newMarker"),
            geometryField,
            null,
            null,
            graphic);
}
 
Example #19
Source File: DefaultSymbols.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the default polygon symbolizer.
 *
 * @return the polygon symbolizer
 */
public static PolygonSymbolizer createDefaultPolygonSymbolizer() {
    Stroke stroke = styleFactory.createStroke(ff.literal(DEFAULT_LINE_COLOUR), ff.literal(2));

    Fill fill = styleFactory.getDefaultFill();
    PolygonSymbolizer polygonSymbolizer = styleFactory.createPolygonSymbolizer();
    polygonSymbolizer.setStroke(stroke);
    polygonSymbolizer.setFill(fill);
    return polygonSymbolizer;
}
 
Example #20
Source File: SLDTreeLeafFactory.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the stroke.
 *
 * @param symbolizer the symbolizer
 * @return the stroke
 */
public Stroke getStroke(Symbolizer symbolizer) {
    Stroke stroke = null;
    if (symbolizer != null) {
        SLDTreeLeafInterface obj = map.get(symbolizer.getClass());
        if (obj != null) {
            stroke = obj.getStroke(symbolizer);
        }

        if (stroke == null) {
            stroke = styleFactory.getDefaultStroke();
        }
    }
    return stroke;
}
 
Example #21
Source File: FeatureLayer.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visit(PolygonSymbolizer poly) {
    super.visit(poly);
    PolygonSymbolizer polyCopy = (PolygonSymbolizer) pages.peek();
    Fill polyFill = polyCopy.getFill();
    if (polyFill != null) {
        polyFill.setOpacity(polyFillExp);
    }

    Stroke polyStroke = polyCopy.getStroke();
    if (polyStroke != null) {
        polyStroke.setOpacity(polyStrokeExp);
    }
}
 
Example #22
Source File: SLDTreeLeafFactory.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks if item is selected.
 *
 * @param userObject the user object
 * @param parentSymbolizer the parent symbolizer
 * @return true, if is item selected
 */
public boolean isItemSelected(Object userObject, Symbolizer parentSymbolizer) {
    boolean selectedItem = false;

    if (userObject instanceof Fill) {
        selectedItem = hasFill(parentSymbolizer);
    } else if (userObject instanceof Stroke) {
        selectedItem = hasStroke(parentSymbolizer);
    }

    return selectedItem;
}
 
Example #23
Source File: PolygonSymbolizerWrapper.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void setWkMarkWidthFill( String wkMarkWidthFill ) {
    this.wkMarkWidthFill = wkMarkWidthFill;
    checkMarkExists();
    if (wkMarkWidthFill != null) {
        Stroke markStroke = mark.getStroke();
        markStroke.setWidth(ff.literal(wkMarkWidthFill));
    }
}
 
Example #24
Source File: SLDTreeLeafLineTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.common.tree.leaf.SLDTreeLeafLine#getStroke(org.opengis.style.Symbolizer)}.
 */
@Test
public void testGetStroke() {
    SLDTreeLeafLine leaf = new SLDTreeLeafLine();
    assertNull(leaf.getStroke(null));

    PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    assertNull(leaf.getStroke(polygonSymbolizer));

    LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    Stroke stroke = leaf.getStroke(lineSymbolizer);

    assertEquals(stroke, lineSymbolizer.getStroke());
}
 
Example #25
Source File: StyleGenerator.java    From constellation with Apache License 2.0 5 votes vote down vote up
private static Style createLineStyle() {
    final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
    final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory();

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

    // create a partially opaque fill
    final Fill fill = styleFactory.createFill(
            filterFactory.literal(Color.RED),
            filterFactory.literal(.25)
    );

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

    // make rule
    final Rule rule = styleFactory.createRule();
    rule.symbolizers().add(sym);

    final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[]{rule});
    final Style style = styleFactory.createStyle();
    style.getDescription().setTitle("Line Style");
    style.featureTypeStyles().add(fts);

    return style;
}
 
Example #26
Source File: StrokeViewer.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * TODO summary sentence for setStroke ...
 *
 * @param line
 * @param mode
 * @param defaultColor
 */
public void setStroke(final Stroke aLine, final Mode mode, final Color defaultColor) {
	listen(false);
	try {
		boolean enabled = true;
		Stroke line = aLine;

		if (line == null) {
			final StyleBuilder builder = new StyleBuilder();
			line = builder.createStroke(defaultColor);
			enabled = false;
		}
		this.enabled = enabled && mode != Mode.NONE && line != null;
		this.color = SLD.color(line);
		this.width = SLD.width(line);
		this.opacity = SLD.opacity(line);

		// Stroke is used in line, point and polygon
		this.on.setEnabled(mode != Mode.NONE);
		this.chooser.setColor(this.color);

		String text = MessageFormat.format("{0,number,#0}", this.width); //$NON-NLS-1$
		this.size.setText(text);
		this.size.select(this.size.indexOf(text));

		text = MessageFormat.format("{0,number,#0%}", this.opacity); //$NON-NLS-1$
		this.percent.setText(text);
		this.percent.select(this.percent.indexOf(text));

		this.on.setSelection(this.enabled);
		this.chooser.setEnabled(this.enabled);
		this.size.setEnabled(this.enabled);
		this.percent.setEnabled(this.enabled);
	} finally {
		listen(true); // listen to user now
	}
}
 
Example #27
Source File: PolygonSymbolizerWrapper.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void setWkMarkColorFill( String wkMarkColorFill ) {
    this.wkMarkColorFill = wkMarkColorFill;
    checkMarkExists();
    if (wkMarkColorFill != null) {
        Stroke markStroke = mark.getStroke();
        markStroke.setColor(ff.literal(wkMarkColorFill));
    }
}
 
Example #28
Source File: StyleGenerator.java    From constellation with Apache License 2.0 5 votes vote down vote up
private static Style createPolygonStyle() {
    final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
    final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory();

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

    // create a partially opaque fill
    final Fill fill = styleFactory.createFill(
            filterFactory.literal(COLORS.next()),
            filterFactory.literal(.5)
    );

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

    // make rule
    final Rule rule = styleFactory.createRule();
    rule.symbolizers().add(sym);

    final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[]{rule});
    final Style style = styleFactory.createStyle();
    style.getDescription().setTitle("Polygon Style");
    style.featureTypeStyles().add(fts);

    return style;
}
 
Example #29
Source File: FieldConfigWKT.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the stroke value.
 *
 * @param fieldConfigManager the field config manager
 * @return the stroke value
 */
private Stroke getStrokeValue(GraphicPanelFieldManager fieldConfigManager) {
    Stroke stroke;
    FieldConfigBase field;
    Expression expStrokeColour = null;
    Expression expStrokeColourOpacity = null;
    field = fieldConfigManager.get(this.strokeFieldConfig.getColour());
    if (field instanceof FieldConfigColour) {
        FieldConfigColour colourField = (FieldConfigColour) field;

        expStrokeColour = colourField.getColourExpression();
    }

    // Stroke width
    Expression strokeWidth = null;
    field = fieldConfigManager.get(this.strokeFieldConfig.getWidth());
    if (field != null) {
        strokeWidth = field.getExpression();
    }

    // Opacity
    field = fieldConfigManager.get(this.strokeFieldConfig.getOpacity());
    if (field != null) {
        expStrokeColourOpacity = field.getExpression();
    }

    stroke =
            getStyleFactory()
                    .createStroke(expStrokeColour, strokeWidth, expStrokeColourOpacity);
    return stroke;
}
 
Example #30
Source File: SimpleFillSymbol.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void convert(Rule rule, JsonElement element, String layerName, int transparency) {
    if(element == null) return;
    if(rule == null) return;

    JsonObject obj = element.getAsJsonObject();
    @SuppressWarnings("unused")
    int style = getInt(obj, CommonSymbolKeys.STYLE);

    List<Symbolizer> symbolizerList = rule.symbolizers();

    JsonElement jsonOutlineElement = obj.get(SimpleFillSymbolKeys.OUTLINE);
    List<Stroke> strokeList = SymbolManager.getInstance().getStrokeList(jsonOutlineElement);

    Stroke stroke = null;

    if(strokeList != null)
    {
        if(!strokeList.isEmpty())
        {
            stroke = strokeList.get(0);
        }
    }

    Expression fillColour = getColour(obj.get(SimpleFillSymbolKeys.FILL_COLOUR));

    Fill fill = null;

    if(fillColour != null)
    {
        fill = styleFactory.createFill(fillColour, getTransparency(transparency));
    }

    PolygonSymbolizer polygonSymbolizer = styleFactory.createPolygonSymbolizer(stroke, fill, null);

    symbolizerList.add(polygonSymbolizer);
}