Search in sources :

Example 1 with ExternalGraphicImpl

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

the class UpdateGraphicalSymbol method processGraphicalSymbol.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.common.data.ProcessGraphicSymbolInterface#processGraphicalSymbol(java.net.URL, java.util.List, java.util.List)
     */
@Override
public void processGraphicalSymbol(URL resourceLocator, List<GraphicalSymbol> graphicalSymbolList, List<String> externalImageList) {
    for (GraphicalSymbol symbol : graphicalSymbolList) {
        if (symbol instanceof ExternalGraphic) {
            ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) symbol;
            OnLineResourceImpl onlineResource = (OnLineResourceImpl) externalGraphic.getOnlineResource();
            String currentValue = null;
            URL currentValueURL = null;
            try {
                currentValueURL = onlineResource.getLinkage().toURL();
                currentValue = currentValueURL.toExternalForm();
            } catch (MalformedURLException e) {
                ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
            }
            if ((resourceLocator == null) || RelativePath.hasHost(currentValueURL)) {
                // Just report back the external image
                URI uri = null;
                try {
                    uri = new URI(currentValue);
                    externalImageList.add(uri.toASCIIString());
                } catch (URISyntaxException e) {
                    ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
                }
            } else {
                try {
                    File file = new File(currentValueURL.getFile());
                    File folder = new File(resourceLocator.getFile());
                    currentValue = RelativePath.getRelativePath(file, folder);
                    // If the backslashes are not converted to forward slashes
                    // creating the URI does not work
                    currentValue = currentValue.replace('\\', '/');
                    OnLineResourceImpl updatedOnlineResource = new OnLineResourceImpl();
                    URI uri = new URI(currentValue);
                    updatedOnlineResource.setLinkage(uri);
                    externalGraphic.setOnlineResource(updatedOnlineResource);
                    externalGraphic.setURI(uri.toASCIIString());
                    externalImageList.add(uri.toASCIIString());
                } catch (URISyntaxException e) {
                    ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
                }
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ExternalGraphicImpl(org.geotools.styling.ExternalGraphicImpl) GraphicalSymbol(org.opengis.style.GraphicalSymbol) OnLineResourceImpl(org.geotools.metadata.iso.citation.OnLineResourceImpl) URISyntaxException(java.net.URISyntaxException) ExternalGraphic(org.geotools.styling.ExternalGraphic) URI(java.net.URI) File(java.io.File) URL(java.net.URL)

Example 2 with ExternalGraphicImpl

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

the class FieldConfigFilename method setValue.

/**
 * Sets the value.
 *
 * @param symbolizerType the symbolizer type
 * @param fieldConfigManager the field config manager
 * @param multiOptionPanel the multi option panel
 * @param graphic the graphic
 * @param symbol the symbol
 */
@Override
public void setValue(Class<?> symbolizerType, GraphicPanelFieldManager fieldConfigManager, FieldConfigSymbolType multiOptionPanel, Graphic graphic, GraphicalSymbol symbol) {
    if (symbol instanceof ExternalGraphicImpl) {
        ExternalGraphicImpl markerSymbol = (ExternalGraphicImpl) symbol;
        if (externalGraphicPanel != null) {
            externalGraphicPanel.setValue(markerSymbol);
        }
        if (multiOptionPanel != null) {
            multiOptionPanel.setSelectedItem(EXTERNAL_SYMBOL_KEY);
        }
        FieldConfigBase opacity = fieldConfigManager.get(FieldIdEnum.OVERALL_OPACITY);
        if (opacity != null) {
            opacity.populate(graphic.getOpacity());
        }
    }
}
Also used : FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) ExternalGraphicImpl(org.geotools.styling.ExternalGraphicImpl)

Example 3 with ExternalGraphicImpl

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

the class StrokeDetails method populateStroke.

/**
 * Populate stroke.
 *
 * @param symbolizerType the symbolizer type
 * @param stroke the stroke
 */
private void populateStroke(Class<?> symbolizerType, Stroke stroke) {
    Expression expColour = null;
    Expression expStrokeColour = null;
    Expression expOpacity = null;
    Expression expStrokeWidth = null;
    Expression expStrokeOffset = null;
    Expression expStrokeLineCap = null;
    Expression expStrokeLineJoin = null;
    Expression expStrokeDashArray = null;
    Expression expAnchorPointX = null;
    Expression expAnchorPointY = null;
    Expression expDisplacementX = null;
    Expression expDisplacementY = null;
    Expression expGap = null;
    Expression expInitialGap = null;
    Expression expSymbolSize = null;
    Expression expSymbolRotation = null;
    if (stroke == null) {
        expColour = getFilterFactory().literal("#000000");
        expOpacity = getFilterFactory().literal(1.0);
        symbolTypeFactory.setSolidFill(fieldConfigManager, expColour, expOpacity);
        expStrokeWidth = getFilterFactory().literal(1.0);
        expStrokeOffset = getFilterFactory().literal(0.0);
        expStrokeLineCap = getFilterFactory().literal("round");
        expStrokeLineJoin = getFilterFactory().literal("round");
        expStrokeDashArray = getFilterFactory().literal("");
    } else {
        Graphic graphicFill = stroke.getGraphicFill();
        Graphic graphicStroke = stroke.getGraphicStroke();
        if ((graphicFill == null) && (graphicStroke == null)) {
            expOpacity = stroke.getOpacity();
            symbolTypeFactory.setSolidFill(fieldConfigManager, stroke.getColor(), stroke.getOpacity());
        }
        expOpacity = stroke.getOpacity();
        expStrokeWidth = stroke.getWidth();
        expStrokeOffset = stroke.getDashOffset();
        expStrokeLineCap = stroke.getLineCap();
        expStrokeLineJoin = stroke.getLineJoin();
        expColour = stroke.getColor();
        List<Float> dashesArray = getStrokeDashArray(stroke);
        expStrokeDashArray = getFilterFactory().literal(createDashArrayString(dashesArray));
        if (graphicStroke != null) {
            // Anchor points
            AnchorPoint anchorPoint = graphicStroke.getAnchorPoint();
            if (anchorPoint != null) {
                expAnchorPointX = anchorPoint.getAnchorPointX();
                expAnchorPointY = anchorPoint.getAnchorPointY();
            } else {
                expAnchorPointX = defaultAnchorPoint.getAnchorPointX();
                expAnchorPointY = defaultAnchorPoint.getAnchorPointY();
            }
            // Displacement
            Displacement displacement = graphicStroke.getDisplacement();
            if (displacement != null) {
                expDisplacementX = displacement.getDisplacementX();
                expDisplacementY = displacement.getDisplacementY();
            } else {
                expDisplacementX = defaultDisplacement.getDisplacementX();
                expDisplacementY = defaultDisplacement.getDisplacementY();
            }
            expGap = graphicStroke.getGap();
            expInitialGap = graphicStroke.getInitialGap();
            expSymbolSize = graphicStroke.getSize();
            expSymbolRotation = graphicStroke.getRotation();
            List<GraphicalSymbol> graphicSymbolList = graphicStroke.graphicalSymbols();
            for (GraphicalSymbol graphicSymbol : graphicSymbolList) {
                if (graphicSymbol instanceof MarkImpl) {
                    MarkImpl mark = (MarkImpl) graphicSymbol;
                    Mark defaultMark = getStyleFactory().getDefaultMark();
                    Fill markFill = mark.getFill();
                    if (markFill != null) {
                        expColour = markFill.getColor();
                    }
                    expStrokeColour = defaultMark.getStroke().getColor();
                    Stroke markStroke = mark.getStroke();
                    if (markStroke != null) {
                        expStrokeColour = markStroke.getColor();
                    }
                } else if (graphicSymbol instanceof ExternalGraphicImpl) {
                    @SuppressWarnings("unused") ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) graphicSymbol;
                }
                symbolTypeFactory.setValue(symbolizerType, this.fieldConfigManager, graphicStroke, graphicSymbol);
            }
        }
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_WIDTH, expStrokeWidth);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_OFFSET, expStrokeOffset);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_LINE_CAP, expStrokeLineCap);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_LINE_JOIN, expStrokeLineJoin);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_DASH_ARRAY, expStrokeDashArray);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_GAP, expGap);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_INITIAL_GAP, expInitialGap);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_SIZE, expSymbolSize);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANGLE, expSymbolRotation);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANCHOR_POINT_H, expAnchorPointX);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANCHOR_POINT_V, expAnchorPointY);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_DISPLACEMENT_X, expDisplacementX);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_DISPLACEMENT_Y, expDisplacementY);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_FILL_COLOUR, expColour);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_STROKE_COLOUR, expStrokeColour);
        if ((graphicFill == null) && (graphicStroke == null)) {
            GroupConfigInterface fillColourGroup = getGroup(GroupIdEnum.FILLCOLOUR);
            if (fillColourGroup != null) {
                fillColourGroup.enable(true);
            }
        }
    // 
    // GroupConfigInterface strokeColourGroup = getGroup(GroupIdEnum.STROKECOLOUR);
    // if (strokeColourGroup != null) {
    // strokeColourGroup.enable(strokeColourEnabled);
    // }
    }
}
Also used : Fill(org.geotools.styling.Fill) GraphicStroke(org.opengis.style.GraphicStroke) Stroke(org.geotools.styling.Stroke) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) Mark(org.geotools.styling.Mark) MarkImpl(org.geotools.styling.MarkImpl) Displacement(org.geotools.styling.Displacement) AnchorPoint(org.geotools.styling.AnchorPoint) ConstantExpression(org.geotools.filter.ConstantExpression) Expression(org.opengis.filter.expression.Expression) ExternalGraphicImpl(org.geotools.styling.ExternalGraphicImpl) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface)

Example 4 with ExternalGraphicImpl

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

the class FieldConfigMarkerTest method testAccept.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.symboltype.FieldConfigMarker#accept(org.opengis.style.GraphicalSymbol)}.
 */
@Test
public void testAccept() {
    boolean valueOnly = true;
    FieldConfigMarker field = new FieldConfigMarker(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), null, null, null);
    assertFalse(field.accept(null));
    StyleBuilder styleBuilder = new StyleBuilder();
    ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) styleBuilder.createExternalGraphic("test.tmp", "png");
    assertFalse(field.accept(externalGraphic));
    Mark marker = styleBuilder.createMark("triangle");
    assertFalse(field.accept(marker));
    List<ValueComboBoxData> dataList = new ArrayList<ValueComboBoxData>();
    dataList.add(new ValueComboBoxData("star", "Star", this.getClass()));
    dataList.add(new ValueComboBoxData("square", "Square", this.getClass()));
    dataList.add(new ValueComboBoxData("triangle", "Triangle", this.getClass()));
    List<ValueComboBoxDataGroup> groupList = new ArrayList<ValueComboBoxDataGroup>();
    groupList.add(new ValueComboBoxDataGroup(dataList));
    field.populateSymbolList(String.class, groupList);
    field.populateSymbolList(PointFillDetails.class, groupList);
    assertTrue(field.accept(marker));
    field.populateSymbolList(PointFillDetails.class, groupList);
    assertTrue(field.accept(marker));
}
Also used : ValueComboBoxDataGroup(com.sldeditor.ui.widgets.ValueComboBoxDataGroup) FieldConfigMarker(com.sldeditor.ui.detail.config.symboltype.FieldConfigMarker) ExternalGraphicImpl(org.geotools.styling.ExternalGraphicImpl) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) StyleBuilder(org.geotools.styling.StyleBuilder) ArrayList(java.util.ArrayList) Mark(org.geotools.styling.Mark) ValueComboBoxData(com.sldeditor.ui.widgets.ValueComboBoxData) Test(org.junit.Test)

Example 5 with ExternalGraphicImpl

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

the class ExternalGraphicDetailsTest method testSetValueExternalGraphicImpl.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.symboltype.externalgraphic.ExternalGraphicDetails#setValue(org.geotools.styling.ExternalGraphicImpl)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.symboltype.externalgraphic.ExternalGraphicDetails#getSymbol()}.
 */
@Test
public void testSetValueExternalGraphicImpl() {
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    ExternalGraphicImpl externalGraphic = null;
    DummyExternalGraphicUpdate callback = new DummyExternalGraphicUpdate();
    ExternalGraphicDetails panel = new ExternalGraphicDetails(callback);
    assertNull(panel.getSymbol());
    panel.setValue(externalGraphic);
    String expectedString = "a/b/c/test.png";
    URL expectedURL = null;
    try {
        expectedURL = new File(expectedString).toURI().toURL();
        externalGraphic = (ExternalGraphicImpl) styleFactory.createExternalGraphic(expectedURL, "image/png");
    } catch (MalformedURLException e) {
        e.printStackTrace();
        fail();
    }
    assertFalse(callback.isCalled());
    panel.setValue(externalGraphic);
    ExternalGraphicImpl actual = (ExternalGraphicImpl) panel.getSymbol();
    try {
        assertEquals(expectedURL.toExternalForm(), actual.getLocation().toExternalForm());
    } catch (MalformedURLException e) {
        e.printStackTrace();
        fail();
    }
    assertTrue(callback.isCalled());
    expectedString = "http://example.com/test.png";
    externalGraphic = (ExternalGraphicImpl) styleFactory.createExternalGraphic(expectedString, "image/png");
    assertFalse(callback.isCalled());
    panel.setValue(externalGraphic);
    actual = (ExternalGraphicImpl) panel.getSymbol();
    assertTrue(callback.isCalled());
    try {
        assertEquals(externalGraphic.getLocation().toExternalForm(), actual.getLocation().toExternalForm());
    } catch (MalformedURLException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) ExternalGraphicImpl(org.geotools.styling.ExternalGraphicImpl) ExternalGraphicDetails(com.sldeditor.ui.detail.config.symboltype.externalgraphic.ExternalGraphicDetails) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Aggregations

ExternalGraphicImpl (org.geotools.styling.ExternalGraphicImpl)13 Mark (org.geotools.styling.Mark)10 Test (org.junit.Test)10 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)9 StyleBuilder (org.geotools.styling.StyleBuilder)9 File (java.io.File)6 MalformedURLException (java.net.MalformedURLException)6 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)4 IOException (java.io.IOException)4 PointFillDetails (com.sldeditor.ui.detail.PointFillDetails)3 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)3 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)2 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)2 FieldConfigSlider (com.sldeditor.ui.detail.config.FieldConfigSlider)2 FieldConfigSymbolType (com.sldeditor.ui.detail.config.FieldConfigSymbolType)2 FieldConfigFilename (com.sldeditor.ui.detail.config.symboltype.externalgraphic.FieldConfigFilename)2 FieldConfigWindBarbs (com.sldeditor.ui.detail.vendor.geoserver.marker.windbarb.FieldConfigWindBarbs)2 FieldConfigWKT (com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.FieldConfigWKT)2 URL (java.net.URL)2 GraphicalSymbol (org.opengis.style.GraphicalSymbol)2