Search in sources :

Example 31 with LineSymbolizer

use of org.geotools.styling.LineSymbolizer in project hale by halestudio.

the class StyledInstanceMarker method strokeStyle.

/**
 * retrieves the stroke for the map marker
 *
 * @param rule a certain rule to apply, maybe null
 * @param context the InstanceWayPoint, wich gets marked
 */
private synchronized void strokeStyle(Rule rule, InstanceWaypoint context) {
    // retrieve stroke
    Stroke stroke = null;
    for (int i = 0; rule != null && stroke == null && i < rule.getSymbolizers().length; i++) {
        if (rule.getSymbolizers()[i] instanceof LineSymbolizer) {
            stroke = SLD.stroke((LineSymbolizer) rule.getSymbolizers()[i]);
        } else if (rule.getSymbolizers()[i] instanceof PolygonSymbolizer) {
            stroke = SLD.stroke((PolygonSymbolizer) rule.getSymbolizers()[i]);
        } else if (rule.getSymbolizers()[i] instanceof PointSymbolizer) {
            stroke = SLD.stroke((PointSymbolizer) rule.getSymbolizers()[i]);
        }
    }
    // if we have a stroke now
    if (stroke != null) {
        // XXX is there any Geotools stroke to AWT stroke lib/code
        // somewhere?!
        // XXX have a look at the renderer code (StreamingRenderer)
        // stroke color
        Color sldColor = SLD.color(stroke);
        double opacity = SLD.opacity(stroke);
        if (Double.isNaN(opacity)) {
            // fall back to default opacity
            opacity = StyleHelper.DEFAULT_FILL_OPACITY;
        }
        if (sldColor != null) {
            styleStrokeColor = new Color(sldColor.getRed(), sldColor.getGreen(), sldColor.getBlue(), (int) (opacity * 255));
        } else {
            styleStrokeColor = super.getBorderColor(context);
        }
        // stroke width
        int strokeWidth = SLD.width(stroke);
        if (strokeWidth == SLD.NOTFOUND) {
            // fall back to default width
            strokeWidth = StylePreferences.getDefaultWidth();
        }
        styleStroke = new BasicStroke(strokeWidth);
    } else {
        styleStroke = null;
        styleStrokeColor = null;
    }
}
Also used : BasicStroke(java.awt.BasicStroke) PointSymbolizer(org.geotools.styling.PointSymbolizer) BasicStroke(java.awt.BasicStroke) Stroke(org.geotools.styling.Stroke) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) Color(java.awt.Color) SelectableWaypoint(de.fhg.igd.mapviewer.waypoints.SelectableWaypoint) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Example 32 with LineSymbolizer

use of org.geotools.styling.LineSymbolizer in project sldeditor by robward-scisys.

the class SelectedSymbolTest method testReplacment.

/**
 * Test method for
 * {@link com.sldeditor.common.data.SelectedSymbol#removeRule(org.geotools.styling.Rule)}.
 */
@Test
public void testReplacment() {
    SelectedSymbol.destroyInstance();
    SelectedSymbol instance = SelectedSymbol.getInstance();
    Rule rule = DefaultSymbols.createNewRule();
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    Style style = DefaultSymbols.createNewStyle();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    instance.createNewSLD(sld);
    instance.setSld(sld);
    instance.addNewStyledLayer(namedLayer);
    instance.setStyledLayer(namedLayer);
    instance.addNewStyle(style);
    instance.setStyle(style);
    instance.addNewFeatureTypeStyle(fts);
    instance.setFeatureTypeStyle(fts);
    instance.addNewRule(rule);
    instance.setRule(rule);
    instance.addSymbolizerToRule(polygonSymbolizer);
    instance.addNewRule(DefaultSymbols.createNewRule());
    instance.setSymbolizer(polygonSymbolizer);
    LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    DummySLDTreeUpdated dummyTreeUpdated = new DummySLDTreeUpdated();
    instance.setTreeUpdateListener(dummyTreeUpdated);
    instance.replaceSymbolizer(lineSymbolizer);
    assertEquals(lineSymbolizer, instance.getSymbolizer());
    assertEquals(dummyTreeUpdated.objectOld, polygonSymbolizer);
    assertEquals(dummyTreeUpdated.objectNew, lineSymbolizer);
    Rule newRule = DefaultSymbols.createNewRule();
    newRule.setTitle("Replacement rule");
    instance.replaceRule(newRule);
    assertEquals(newRule, instance.getRule());
    assertNull(instance.getSymbolizer());
    FeatureTypeStyle newFts = DefaultSymbols.createNewFeatureTypeStyle();
    newFts.setName("Replacement fts");
    instance.replaceFeatureTypeStyle(newFts);
    assertEquals(newFts, instance.getFeatureTypeStyle());
    assertNull(instance.getRule());
    Style newStyle = DefaultSymbols.createNewStyle();
    newStyle.setName("Replacement style");
    instance.replaceStyle(newStyle);
    assertEquals(newStyle, instance.getStyle());
    assertNull(instance.getRule());
    NamedLayer newNamedLayer = DefaultSymbols.createNewNamedLayer();
    newNamedLayer.setName("Replacement named layer");
    instance.replaceStyledLayer(newNamedLayer);
    assertEquals(newNamedLayer, instance.getStyledLayer());
    assertNull(instance.getStyle());
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Example 33 with LineSymbolizer

use of org.geotools.styling.LineSymbolizer in project sldeditor by robward-scisys.

the class SymbolDataTest method testSetSymbolizer.

@Test
public void testSetSymbolizer() {
    SymbolData symbolData = new SymbolData();
    LineSymbolizer symbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    symbolData.setSymbolizer(symbolizer);
    assertEquals(symbolizer, symbolData.getSymbolizer());
}
Also used : SymbolData(com.sldeditor.common.data.SymbolData) LineSymbolizer(org.geotools.styling.LineSymbolizer) Test(org.junit.Test)

Example 34 with LineSymbolizer

use of org.geotools.styling.LineSymbolizer in project sldeditor by robward-scisys.

the class SLDTreeLeafFactoryTest method testUpdateFill.

/**
 * 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());
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) Test(org.junit.Test)

Example 35 with LineSymbolizer

use of org.geotools.styling.LineSymbolizer in project sldeditor by robward-scisys.

the class SLDTreeLeafFactoryTest method testIsItemSelected.

/**
 * 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));
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) Test(org.junit.Test)

Aggregations

LineSymbolizer (org.geotools.styling.LineSymbolizer)51 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)24 PointSymbolizer (org.geotools.styling.PointSymbolizer)23 Test (org.junit.Test)18 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)17 Style (org.geotools.styling.Style)17 Rule (org.geotools.styling.Rule)16 Symbolizer (org.geotools.styling.Symbolizer)15 Stroke (org.geotools.styling.Stroke)12 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)10 TextSymbolizer (org.geotools.styling.TextSymbolizer)10 NamedLayer (org.geotools.styling.NamedLayer)9 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)7 StyledLayer (org.geotools.styling.StyledLayer)5 JsonObject (com.google.gson.JsonObject)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4 Graphic (org.geotools.styling.Graphic)4 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)4 SelectedSymbol (com.sldeditor.common.data.SelectedSymbol)3 SLDTreeLeafLine (com.sldeditor.common.tree.leaf.SLDTreeLeafLine)3