org.geotools.styling.LineSymbolizer Java Examples

The following examples show how to use org.geotools.styling.LineSymbolizer. 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: 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 #2
Source File: NewLineSLDTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/** Test new line sld. */
@Test
public void testNewLineSLD() {
    NewLineSLD newData = new NewLineSLD();

    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 LineSymbolizer);
}
 
Example #3
Source File: SLDTreeLeafFactoryTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.common.tree.leaf.SLDTreeLeafFactory#hasFill(org.opengis.style.Symbolizer)}.
 */
@Test
public void testHasFill() {
    PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    PointSymbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    // CHECKSTYLE:OFF
    LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    TextSymbolizer textSymbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    // CHECKSTYLE:ON

    assertFalse(SLDTreeLeafFactory.getInstance().hasFill(null));
    assertTrue(SLDTreeLeafFactory.getInstance().hasFill(polygonSymbolizer));
    assertTrue(SLDTreeLeafFactory.getInstance().hasFill(pointSymbolizer));
    assertFalse(SLDTreeLeafFactory.getInstance().hasFill(lineSymbolizer));
    assertFalse(SLDTreeLeafFactory.getInstance().hasFill(textSymbolizer));
}
 
Example #4
Source File: SLDTreeLeafFactoryTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.common.tree.leaf.SLDTreeLeafFactory#hasStroke(org.opengis.style.Symbolizer)}.
 */
@Test
public void testHasStroke() {
    PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    PointSymbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    // CHECKSTYLE:OFF
    LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    TextSymbolizer textSymbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    // CHECKSTYLE:ON

    assertFalse(SLDTreeLeafFactory.getInstance().hasStroke(null));
    assertTrue(SLDTreeLeafFactory.getInstance().hasStroke(polygonSymbolizer));
    assertFalse(SLDTreeLeafFactory.getInstance().hasStroke(pointSymbolizer));
    assertTrue(SLDTreeLeafFactory.getInstance().hasStroke(lineSymbolizer));
    assertFalse(SLDTreeLeafFactory.getInstance().hasStroke(textSymbolizer));
}
 
Example #5
Source File: SLDTreeLeafFactoryTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.common.tree.leaf.SLDTreeLeafFactory#getFill(org.opengis.style.Symbolizer)}.
 */
@Test
public void testGetFill() {
    PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    PointSymbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    // CHECKSTYLE:OFF
    LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    TextSymbolizer textSymbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    // CHECKSTYLE:ON

    assertNull(SLDTreeLeafFactory.getInstance().getFill(null));
    assertTrue(SLDTreeLeafFactory.getInstance().getFill(polygonSymbolizer) != null);
    assertTrue(SLDTreeLeafFactory.getInstance().getFill(pointSymbolizer) != null);

    // Returns default fill
    assertTrue(SLDTreeLeafFactory.getInstance().getFill(lineSymbolizer) != null);
    assertTrue(SLDTreeLeafFactory.getInstance().getFill(textSymbolizer) != null);
}
 
Example #6
Source File: SLDTreeLeafFactoryTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.common.tree.leaf.SLDTreeLeafFactory#getStroke(org.opengis.style.Symbolizer)}.
 */
@Test
public void testGetStroke() {
    PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    // CHECKSTYLE:OFF
    PointSymbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    TextSymbolizer textSymbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    // CHECKSTYLE:ON

    assertNull(SLDTreeLeafFactory.getInstance().getStroke(null));
    assertTrue(SLDTreeLeafFactory.getInstance().getStroke(polygonSymbolizer) != null);
    assertTrue(SLDTreeLeafFactory.getInstance().getStroke(lineSymbolizer) != null);

    // Returns default stroke
    assertTrue(SLDTreeLeafFactory.getInstance().getStroke(pointSymbolizer) != null);
    assertTrue(SLDTreeLeafFactory.getInstance().getStroke(textSymbolizer) != null);
}
 
Example #7
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 #8
Source File: LineSymbolizerDetails.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/** Update symbol. */
private void updateSymbol() {
    if (!Controller.getInstance().isPopulating()) {
        Expression perpendicularOffset =
                fieldConfigVisitor.getExpression(FieldIdEnum.PERPENDICULAR_OFFSET);
        Expression geometryField = ExtractGeometryField.getGeometryField(fieldConfigVisitor);

        StandardData standardData = getStandardData();

        LineSymbolizer lineSymbolizer =
                (LineSymbolizer) SelectedSymbol.getInstance().getSymbolizer();

        if (lineSymbolizer != null) {
            lineSymbolizer.setName(standardData.getName());
            lineSymbolizer.setDescription(standardData.getDescription());
            lineSymbolizer.setUnitOfMeasure(
                    (standardData.getUnit() != null) ? standardData.getUnit().getUnit() : null);

            lineSymbolizer.setGeometry(geometryField);

            lineSymbolizer.setPerpendicularOffset(perpendicularOffset);

            this.fireUpdateSymbol();
        }
    }
}
 
Example #9
Source File: LineSymbolizerDetails.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(SelectedSymbol selectedSymbol) {

    if (selectedSymbol != null) {
        LineSymbolizer lineSymbolizer = (LineSymbolizer) selectedSymbol.getSymbolizer();
        if (lineSymbolizer != null) {
            populateStandardData(lineSymbolizer);

            fieldConfigVisitor.populateField(
                    FieldIdEnum.PERPENDICULAR_OFFSET, lineSymbolizer.getPerpendicularOffset());

            fieldConfigVisitor.populateField(
                    FieldIdEnum.GEOMETRY, lineSymbolizer.getGeometry());
        }
    }
}
 
Example #10
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 #11
Source File: RuleWrapper.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private SymbolizerWrapper getWrapper( Symbolizer symbolizer ) {
    SymbolizerWrapper symbolizerWrapper = null;
    if (symbolizer instanceof PointSymbolizer) {
        symbolizerWrapper = new PointSymbolizerWrapper(symbolizer, this);
    } else if (symbolizer instanceof LineSymbolizer) {
        symbolizerWrapper = new LineSymbolizerWrapper(symbolizer, this);
    } else if (symbolizer instanceof PolygonSymbolizer) {
        symbolizerWrapper = new PolygonSymbolizerWrapper(symbolizer, this);
    } else if (symbolizer instanceof TextSymbolizer) {
        symbolizerWrapper = new TextSymbolizerWrapper(symbolizer, this, getType());
    } else if (symbolizer instanceof RasterSymbolizer) {
        symbolizerWrapper = new RasterSymbolizerWrapper(symbolizer, this);
    }

    return symbolizerWrapper;
}
 
Example #12
Source File: RuleWrapper.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the type of geometry/raster that the {@link SymbolizerWrapper} represents.
 * 
 * @return the symbolizer type.
 */
public EGeometryType getType() {
    SymbolizerWrapper geometrySymbolizersWrapper = getGeometrySymbolizersWrapper();
    if (geometrySymbolizersWrapper == null) {
        return null;
    }
    Symbolizer symbolizer = geometrySymbolizersWrapper.getSymbolizer();
    if (symbolizer instanceof PointSymbolizer) {
        return EGeometryType.POINT;
    } else if (symbolizer instanceof LineSymbolizer) {
        return EGeometryType.LINESTRING;
    } else if (symbolizer instanceof PolygonSymbolizer) {
        return EGeometryType.POLYGON;
    } else if (symbolizer instanceof RasterSymbolizer) {
        throw new RuntimeException("Not implemented yet!");
    }
    return null;
}
 
Example #13
Source File: SLDTree.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Populate symbolizer.
 *
 * @param ruleTreeNode the rule tree node
 * @param symbolizer the symbolizer
 */
private void populateSymbolizer(DefaultMutableTreeNode ruleTreeNode, Symbolizer symbolizer) {
    DefaultMutableTreeNode symbolizerTreeNode = addObject(ruleTreeNode, symbolizer, true);

    if ((symbolizer instanceof PointSymbolizer) || (symbolizer instanceof PolygonSymbolizer)) {
        addObject(
                symbolizerTreeNode, SLDTreeLeafFactory.getInstance().getFill(symbolizer), true);
    }

    if ((symbolizer instanceof PolygonSymbolizer) || (symbolizer instanceof LineSymbolizer)) {
        addObject(
                symbolizerTreeNode,
                SLDTreeLeafFactory.getInstance().getStroke(symbolizer),
                true);
    }

    if (symbolizer instanceof RasterSymbolizer) {
        handleRasterSymbolizer(symbolizer, symbolizerTreeNode);
    }
}
 
Example #14
Source File: SymbolizerTreeItem.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Default string.
 *
 * @param symbol the symbol
 * @return the string
 */
private String defaultString(Symbolizer symbol) {
    String name = "";

    if (symbol instanceof PointSymbolizer) {
        name = DEFAULT_MARKER_NAME;
    } else if (symbol instanceof TextSymbolizer) {
        name = DEFAULT_TEXT_NAME;
    } else if (symbol instanceof LineSymbolizer) {
        name = DEFAULT_LINE_NAME;
    } else if (symbol instanceof PolygonSymbolizer) {
        name = DEFAULT_POLYGON_NAME;
    } else if (symbol instanceof RasterSymbolizer) {
        name = DEFAULT_RASTER_NAME;
    }
    return name;
}
 
Example #15
Source File: RuleRenderVisitor.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * (non-Javadoc)
 *
 * @see
 *     org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.LineSymbolizer)
 */
public void visit(LineSymbolizer line) {
    LineSymbolizer copy = sf.getDefaultLineSymbolizer();

    copy.setGeometry(copy(line.getGeometry()));

    copy.setUnitOfMeasure(line.getUnitOfMeasure());
    copy.setStroke(copy(line.getStroke()));
    copy.getOptions().putAll(line.getOptions());
    copy.setPerpendicularOffset(line.getPerpendicularOffset());

    if (STRICT && !copy.equals(line)) {
        throw new IllegalStateException(
                "Was unable to duplicate provided LineSymbolizer:" + line);
    }
    pages.push(copy);
}
 
Example #16
Source File: ExtractAttributes.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * (non-Javadoc)
 *
 * @see
 *     org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.LineSymbolizer)
 */
@Override
public void visit(LineSymbolizer line) {
    LineSymbolizer copy = sf.getDefaultLineSymbolizer();

    copy.setGeometry(copy(LineString.class, line.getGeometry()));

    copy.setUnitOfMeasure(line.getUnitOfMeasure());
    copy.setStroke(copy(line.getStroke()));
    copy.getOptions().putAll(line.getOptions());
    copy.setPerpendicularOffset(line.getPerpendicularOffset());

    if (STRICT && !copy.equals(line)) {
        throw new IllegalStateException(
                "Was unable to duplicate provided LineSymbolizer:" + line);
    }
    pages.push(copy);
}
 
Example #17
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 #18
Source File: SymbolizerFilterVisitor.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
protected boolean skipSymbolizer(Symbolizer symbolizer) {
	if (symbolizer instanceof TextSymbolizer) {
		if (!isIncludeText()) {
			return true;
		}
	} else if (symbolizer instanceof LineSymbolizer) {
		if (!isIncludeGeometry()) {
			return true;
		}
	} else if (symbolizer instanceof PointSymbolizer) {
		if (!isIncludeGeometry()) {
			return true;
		}
	} else if (symbolizer instanceof PolygonSymbolizer) {
		if (!isIncludeGeometry()) {
			return true;
		}
	} else if (symbolizer instanceof RasterSymbolizer) {
		if (!isIncludeGeometry()) {
			return true;
		}
	}
	return false;
}
 
Example #19
Source File: SLDEditorBufferedImageLegendGraphicBuilder.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a sample feature for the given rule, with the following criteria: - if a sample is
 * given in input is returned in output - if a sample is not given in input, scan the rule
 * symbolizers to find the one with the max dimensionality, and return a sample for that
 * dimensionality.
 *
 * @param featureType featureType used to create a sample, if none is given as input
 * @param sample feature sample to be returned as is in output, if defined
 * @param rule rule containing symbolizers to scan for max dimensionality
 */
private Feature getSampleFeatureForRule(
        FeatureType featureType, Feature sample, final Rule rule) {
    Symbolizer[] symbolizers = rule.getSymbolizers();
    // if we don't have a sample as input, we need to create a sampleFeature
    // looking at the requested symbolizers (we chose the one with the max
    // dimensionality and create a congruent sample)
    if (sample == null) {
        int dimensionality = 1;
        for (int sIdx = 0; sIdx < symbolizers.length; sIdx++) {
            final Symbolizer symbolizer = symbolizers[sIdx];
            if (LineSymbolizer.class.isAssignableFrom(symbolizer.getClass())) {
                dimensionality = 2;
            }
            if (PolygonSymbolizer.class.isAssignableFrom(symbolizer.getClass())) {
                dimensionality = 3;
            }
        }
        return createSampleFeature(featureType, dimensionality);
    } else {
        return sample;
    }
}
 
Example #20
Source File: SLDTreeLeafFactoryTest.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.SLDTreeLeafFactory#updateFill(boolean,
 * org.opengis.style.Symbolizer)}.
 */
@Test
public void testUpdateFill() {
    assertNull(SLDTreeLeafFactory.getInstance().updateFill(true, null));

    PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    assertEquals(
            SLDTreeLeafFactory.getInstance().updateFill(false, polygonSymbolizer),
            styleFactory.getDefaultFill());
    assertTrue(SLDTreeLeafFactory.getInstance().updateFill(true, polygonSymbolizer) != null);

    PointSymbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    assertEquals(
            SLDTreeLeafFactory.getInstance().updateFill(false, pointSymbolizer),
            styleFactory.getDefaultFill());
    assertTrue(SLDTreeLeafFactory.getInstance().updateFill(true, pointSymbolizer) != null);

    LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    assertEquals(
            SLDTreeLeafFactory.getInstance().updateFill(false, lineSymbolizer),
            styleFactory.getDefaultFill());
    assertEquals(
            SLDTreeLeafFactory.getInstance().updateFill(true, lineSymbolizer),
            styleFactory.getDefaultFill());

    TextSymbolizer textSymbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    assertEquals(
            SLDTreeLeafFactory.getInstance().updateFill(false, textSymbolizer),
            styleFactory.getDefaultFill());
    assertEquals(
            SLDTreeLeafFactory.getInstance().updateFill(true, textSymbolizer),
            styleFactory.getDefaultFill());
}
 
Example #21
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#removeStroke(org.opengis.style.Symbolizer)}.
 */
@Test
public void testRemoveStroke() {
    SLDTreeLeafLine leaf = new SLDTreeLeafLine();

    LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    leaf.removeStroke(lineSymbolizer);

    assertNull(lineSymbolizer.getStroke());
}
 
Example #22
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#createStroke(org.opengis.style.Symbolizer)}.
 */
@Test
public void testCreateStroke() {
    SLDTreeLeafLine leaf = new SLDTreeLeafLine();

    LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    lineSymbolizer.setStroke(null);
    leaf.createStroke(lineSymbolizer);

    assertTrue(lineSymbolizer.getStroke() != null);
}
 
Example #23
Source File: LegendGraphicServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private LiteShape2 getSampleShape(Symbolizer symbolizer, int width, int height) {
	MetaBufferEstimator estimator = new MetaBufferEstimator();
	estimator.visit(symbolizer);
	// add an extra pixel to the margin (odd line widths were not always shown)
	int margin = estimator.getBuffer() + 1;
	// we define a shape in WKT of size 1 x 1 and transform it to a rectangle of (width-margin) x (height-margin),
	// to make sure we capture thick strokes
	MathTransform transform = new AffineTransform2D(width - margin, 0, 0, height - margin, 0.5 * margin,
			0.5 * margin);
	try {
		WKTReader wktReader = new WKTReader();
		if (symbolizer instanceof LineSymbolizer) {
			return new LiteShape2(wktReader.read("LINESTRING (0 0, 0.66 0.33, 0.33 0.66, 1 1)"), transform, null,
					false);
		} else if (symbolizer instanceof PolygonSymbolizer) {
			return new LiteShape2(wktReader.read("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))"), transform, null, false);
		} else if (symbolizer instanceof PointSymbolizer) {
			return new LiteShape2(wktReader.read("POINT (0.5 0.5)"), transform, null, false);
		} else {
			return null;
		}
	} catch (Exception e) { // NOSONAR
		// should not happen
		log.warn("Could not create sample shapes", e);
		return null;
	}
}
 
Example #24
Source File: ShapefileLoader.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static Style createLineStyle() {
    LineSymbolizer symbolizer = styleFactory.createLineSymbolizer();
    SLD.setLineColour(symbolizer, Color.BLUE);
    symbolizer.getStroke().setWidth(filterFactory.literal(1));
    symbolizer.getStroke().setColor(filterFactory.literal(Color.BLUE));

    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 #25
Source File: SLDTreeLeafFactoryTest.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.SLDTreeLeafFactory#updateStroke(boolean,
 * org.opengis.style.Symbolizer)}.
 */
@Test
public void testUpdateStroke() {
    assertNull(SLDTreeLeafFactory.getInstance().updateStroke(true, null));

    PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    assertEquals(
            SLDTreeLeafFactory.getInstance().updateStroke(false, polygonSymbolizer),
            styleFactory.getDefaultStroke());
    assertTrue(SLDTreeLeafFactory.getInstance().updateStroke(true, polygonSymbolizer) != null);

    PointSymbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    assertEquals(
            SLDTreeLeafFactory.getInstance().updateStroke(false, pointSymbolizer),
            styleFactory.getDefaultStroke());
    assertTrue(SLDTreeLeafFactory.getInstance().updateStroke(true, pointSymbolizer) != null);

    LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    assertEquals(
            SLDTreeLeafFactory.getInstance().updateStroke(false, lineSymbolizer),
            styleFactory.getDefaultStroke());
    assertEquals(
            SLDTreeLeafFactory.getInstance().updateStroke(true, lineSymbolizer),
            styleFactory.getDefaultStroke());

    TextSymbolizer textSymbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    assertEquals(
            SLDTreeLeafFactory.getInstance().updateStroke(false, textSymbolizer),
            styleFactory.getDefaultStroke());
    assertEquals(
            SLDTreeLeafFactory.getInstance().updateStroke(true, textSymbolizer),
            styleFactory.getDefaultStroke());
}
 
Example #26
Source File: StyleUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a default {@link Rule} for a line.
 * 
 * @return the default rule.
 */
public static Rule createDefaultLineRule() {
    LineSymbolizer lineSymbolizer = sf.createLineSymbolizer();
    lineSymbolizer.setStroke(createDefaultStroke());

    Rule rule = sf.createRule();
    rule.setName("New rule");
    rule.symbolizers().add(lineSymbolizer);

    return rule;
}
 
Example #27
Source File: SLDTreeLeafFactoryTest.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.SLDTreeLeafFactory#isItemSelected(java.lang.Object,
 * org.geotools.styling.Symbolizer)}.
 */
@Test
public void testIsItemSelected() {
    assertFalse(SLDTreeLeafFactory.getInstance().isItemSelected(null, null));

    PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    assertTrue(
            SLDTreeLeafFactory.getInstance()
                    .isItemSelected(styleFactory.getDefaultFill(), polygonSymbolizer));
    assertTrue(
            SLDTreeLeafFactory.getInstance()
                    .isItemSelected(styleFactory.getDefaultStroke(), polygonSymbolizer));

    PointSymbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    assertTrue(
            SLDTreeLeafFactory.getInstance()
                    .isItemSelected(styleFactory.getDefaultFill(), pointSymbolizer));
    assertFalse(
            SLDTreeLeafFactory.getInstance()
                    .isItemSelected(styleFactory.getDefaultStroke(), pointSymbolizer));

    LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    assertFalse(
            SLDTreeLeafFactory.getInstance()
                    .isItemSelected(styleFactory.getDefaultFill(), lineSymbolizer));
    assertTrue(
            SLDTreeLeafFactory.getInstance()
                    .isItemSelected(styleFactory.getDefaultStroke(), lineSymbolizer));

    TextSymbolizer textSymbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    assertFalse(
            SLDTreeLeafFactory.getInstance()
                    .isItemSelected(styleFactory.getDefaultFill(), textSymbolizer));
    assertFalse(
            SLDTreeLeafFactory.getInstance()
                    .isItemSelected(styleFactory.getDefaultStroke(), textSymbolizer));
}
 
Example #28
Source File: SymbolDataTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testSetSymbolizer() {
    SymbolData symbolData = new SymbolData();
    LineSymbolizer symbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    symbolData.setSymbolizer(symbolizer);
    assertEquals(symbolizer, symbolData.getSymbolizer());
}
 
Example #29
Source File: SimpleStyleUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a simple {@link Rule} for a line.
 * 
 * @param color
 *            the color.
 * @param width
 *            the line width.
 * @return the rule.
 */
public static Rule createSimpleLineRule( Color color, float width ) {
    LineSymbolizer lineSymbolizer = StyleUtilities.sf.createLineSymbolizer();
    lineSymbolizer.setStroke(
            StyleUtilities.sf.createStroke(StyleUtilities.ff.literal("#" + Integer.toHexString(color.getRGB() & 0xffffff)),
                    StyleUtilities.ff.literal(width)));

    Rule rule = StyleUtilities.sf.createRule();
    rule.setName("New rule");
    rule.symbolizers().add(lineSymbolizer);

    return rule;
}
 
Example #30
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());
}