Java Code Examples for org.geotools.styling.Graphic#graphicalSymbols()

The following examples show how to use org.geotools.styling.Graphic#graphicalSymbols() . 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: SLDTreeLeafPoint.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Fill getFill(Symbolizer symbolizer) {
    if (symbolizer instanceof PointSymbolizer) {
        PointSymbolizer point = (PointSymbolizer) symbolizer;
        Graphic graphic = point.getGraphic();

        if (graphic != null) {
            List<GraphicalSymbol> symbolList = graphic.graphicalSymbols();

            if ((symbolList != null) && !symbolList.isEmpty()) {
                GraphicalSymbol obj = symbolList.get(0);

                if (obj instanceof MarkImpl) {
                    MarkImpl mark = (MarkImpl) obj;

                    return mark.getFill();
                }
            }
        }
    }
    return null;
}
 
Example 2
Source File: SLDTreeLeafPointTest.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.SLDTreeLeafPoint#getFill(org.opengis.style.Symbolizer)}.
 */
@Test
public void testGetFill() {
    SLDTreeLeafPoint leaf = new SLDTreeLeafPoint();
    assertNull(leaf.getFill(null));
    assertNull(leaf.getFill(DefaultSymbols.createDefaultPolygonSymbolizer()));

    PointSymbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();

    Fill expectedFill = null;
    Graphic graphic = pointSymbolizer.getGraphic();

    if (graphic != null) {
        List<GraphicalSymbol> symbolList = graphic.graphicalSymbols();

        if ((symbolList != null) && !symbolList.isEmpty()) {
            GraphicalSymbol obj = symbolList.get(0);

            if (obj != null) {
                if (obj instanceof MarkImpl) {
                    MarkImpl mark = (MarkImpl) obj;

                    expectedFill = mark.getFill();
                }
            }
        }
    }

    assertEquals(expectedFill, leaf.getFill(pointSymbolizer));
}
 
Example 3
Source File: GraphicViewer.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * TODO summary sentence for setGraphic ...
 *
 * @param graphic
 * @param mode
 * @param enabled
 */
public void setGraphic(final Graphic g, final Mode mode, final Color defaultColor) {
	Graphic graphic = g;
	boolean enabled = true;
	if (graphic == null) {
		final StyleBuilder builder = new StyleBuilder();
		graphic = builder.createGraphic(null, builder.createMark(StyleBuilder.MARK_SQUARE, defaultColor), null);
		enabled = true;
	}
	this.width = SLDs.size(graphic);
	final String text = MessageFormat.format("{0,number,#0}", this.width); //$NON-NLS-1$
	if (text != null) {
		this.size.setText(text);
		this.size.select(this.size.indexOf(text));
	}

	boolean marked = false;
	if (graphic != null && graphic.graphicalSymbols() != null && !graphic.graphicalSymbols().isEmpty()) {

		for (final GraphicalSymbol symbol : graphic.graphicalSymbols()) {
			if (symbol instanceof Mark) {
				final Mark mark = (Mark) symbol;
				setMark(mark, mode);
				marked = true;
				break;
			}
		}
	}
	if (!marked) {
		setMark(null, mode);
	}
	this.enabled = this.enabled && enabled;
}
 
Example 4
Source File: StyleUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Collect all {@link ExternalGraphic}s from the given {@link Graphic}.
 * 
 * @param graphic the graphic to check.
 * @return the extracted {@link ExternalGraphic}s.
 */
public static List<ExternalGraphic> externalGraphicsFromGraphic( Graphic graphic ) {
    List<ExternalGraphic> gList = new ArrayList<ExternalGraphic>();
    for( GraphicalSymbol gs : graphic.graphicalSymbols() ) {
        if ((gs != null) && (gs instanceof ExternalGraphic)) {
            ExternalGraphic externalGraphic = (ExternalGraphic) gs;
            gList.add(externalGraphic);
        }
    }
    return gList;
}
 
Example 5
Source File: StrokeDetails.java    From sldeditor with GNU General Public License v3.0 4 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) {

    Stroke stroke = null;

    if (selectedSymbol != null) {
        symbolizer = selectedSymbol.getSymbolizer();
        if (symbolizer instanceof PointSymbolizer) {
            PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer;
            Graphic graphic = pointSymbolizer.getGraphic();

            List<GraphicalSymbol> graphicalSymbols = graphic.graphicalSymbols();

            if (!graphicalSymbols.isEmpty()) {
                GraphicalSymbol symbol = graphicalSymbols.get(0);

                if (symbol instanceof MarkImpl) {
                    MarkImpl markerSymbol = (MarkImpl) symbol;

                    stroke = markerSymbol.getStroke();
                }
            }
        } else if (symbolizer instanceof LineSymbolizer) {
            LineSymbolizer lineSymbol = (LineSymbolizer) symbolizer;
            stroke = lineSymbol.getStroke();
        } else if (symbolizer instanceof PolygonSymbolizer) {
            PolygonSymbolizer polygonSymbol = (PolygonSymbolizer) symbolizer;
            stroke = polygonSymbol.getStroke();
        }
    }

    Class<?> symbolizerClass = null;
    if (symbolizer != null) {
        symbolizerClass = symbolizer.getClass();
    }
    populateStroke(symbolizerClass, stroke);
}
 
Example 6
Source File: DefaultSymbols.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the arrow.
 *
 * @param angleFunction the angle function
 * @param locationFunction the location function
 * @param markerSymbol the marker symbol
 * @param isSourceArrow the is source arrow
 * @return the point symbolizer
 */
private static PointSymbolizer createArrow(
        FunctionName angleFunction,
        FunctionName locationFunction,
        String markerSymbol,
        boolean isSourceArrow) {
    String name =
            isSourceArrow
                    ? Localisation.getString(SLDTreeTools.class, "TreeItem.sourceArrow")
                    : Localisation.getString(SLDTreeTools.class, "TreeItem.destArrow");

    PointSymbolizer pointSymbolizer = createDefaultPointSymbolizer();

    pointSymbolizer.setName(name);
    Graphic graphic = pointSymbolizer.getGraphic();
    graphic.setSize(ff.literal(DEFAULT_ARROW_SIZE));
    List<GraphicalSymbol> graphicalSymbolList = graphic.graphicalSymbols();
    MarkImpl mark = (MarkImpl) graphicalSymbolList.get(0);

    Expression wellKnownName = ff.literal(markerSymbol);
    mark.setWellKnownName(wellKnownName);

    mark.getFill().setColor(ff.literal(DEFAULT_COLOUR));

    // Arrow rotation
    List<Expression> rotationArgumentList = new ArrayList<>();

    String geometryFieldName = "geom";
    DataSourceInterface dsInfo = DataSourceFactory.getDataSource();
    if (dsInfo != null) {
        geometryFieldName = dsInfo.getGeometryFieldName();
    }
    rotationArgumentList.add(ff.property(geometryFieldName));

    Expression rotation =
            FunctionManager.getInstance().createExpression(angleFunction, rotationArgumentList);
    if (isSourceArrow) {
        graphic.setRotation(ff.add(ff.literal(DEGREES_180), rotation));
    } else {
        graphic.setRotation(rotation);
    }

    AnchorPoint anchorPoint = styleFactory.anchorPoint(ff.literal(0.5), ff.literal(0.5));
    graphic.setAnchorPoint(anchorPoint);

    // Set location of the arrow head
    List<Expression> endPointArgumentList = new ArrayList<>();
    endPointArgumentList.add(ff.property(geometryFieldName));

    Expression geometry =
            FunctionManager.getInstance()
                    .createExpression(locationFunction, endPointArgumentList);
    pointSymbolizer.setGeometry(geometry);

    return pointSymbolizer;
}