Search in sources :

Example 11 with LegendOptionData

use of com.sldeditor.ui.legend.option.LegendOptionData in project sldeditor by robward-scisys.

the class LegendManager method createLegend.

/**
 * Creates the legend.
 *
 * @param sld the sld
 * @param heading the heading
 * @param filename the filename
 * @param separateSymbolizers the separate symbolizers
 * @return the map
 */
public Map<String, BufferedImage> createLegend(StyledLayerDescriptor sld, String heading, String filename, boolean separateSymbolizers) {
    Map<String, BufferedImage> imageMap = new HashMap<String, BufferedImage>();
    // 
    // Set legend options
    // 
    Map<String, Object> legendOptions = new HashMap<String, Object>();
    if (heading != null) {
        legendOptions.put("heading", heading);
    }
    if (filename != null) {
        legendOptions.put("filename", filename);
    }
    if (legendOptionData == null) {
        legendOptionData = new LegendOptionData();
    }
    GetLegendGraphicRequest request = new GetLegendGraphicRequest();
    request.setWidth(legendOptionData.getImageWidth());
    request.setHeight(legendOptionData.getImageHeight());
    request.setTransparent(legendOptionData.isTransparent());
    request.setStrict(false);
    legendOptions.put("bgColor", ColourUtils.fromColour(legendOptionData.getBackgroundColour()));
    legendOptions.put("fontColor", ColourUtils.fromColour(legendOptionData.getLabelFontColour()));
    // 
    // Label Font
    // 
    Font font = legendOptionData.getLabelFont();
    legendOptions.put("fontName", font.getFontName());
    String styleValue = null;
    if ((font.getStyle() & java.awt.Font.BOLD) == java.awt.Font.BOLD) {
        styleValue = "bold";
    }
    if ((font.getStyle() & java.awt.Font.ITALIC) == java.awt.Font.ITALIC) {
        styleValue = "italic";
    }
    if (styleValue != null) {
        legendOptions.put("fontStyle", styleValue);
    }
    legendOptions.put("fontSize", String.valueOf(font.getSize()));
    legendOptions.put("dpi", Integer.valueOf(legendOptionData.getDpi()));
    legendOptions.put("fontAntiAliasing", getBooleanValueOnOff(legendOptionData.isFontAntiAliasing()));
    legendOptions.put("forceLabels", getBooleanValueOnOff(legendOptionData.isShowLabels()));
    legendOptions.put("forceTitles", getBooleanValueOnOff(legendOptionData.isShowTitle()));
    legendOptions.put("bandInfo", getBooleanValueTrueFalse(legendOptionData.isBandInformation()));
    legendOptions.put("border", getBooleanValueTrueFalse(legendOptionData.isBorder()));
    legendOptions.put("borderColor", ColourUtils.fromColour(legendOptionData.getBorderColour()));
    legendOptions.put("imageSizeFactor", String.valueOf(legendOptionData.getImageSize() / 100.0));
    request.setLegendOptions(legendOptions);
    if (sld != null) {
        Map<String, Style> styleMap = new LinkedHashMap<String, Style>();
        StyledLayer selectedStyledLayer = SelectedSymbol.getInstance().getStyledLayer();
        Style selectedStyle = SelectedSymbol.getInstance().getStyle();
        if (selectedStyle != null) {
            createSingleStyleLegend(styleMap, selectedStyledLayer, selectedStyle);
        } else {
            createMultipleStyleLegend(sld, styleMap, selectedStyledLayer);
        }
        // Merge symbolizers into 1 image
        if (!separateSymbolizers) {
            for (String key : styleMap.keySet()) {
                Style style = styleMap.get(key);
                if (!style.featureTypeStyles().isEmpty()) {
                    FeatureTypeStyle featureTypeStyle = style.featureTypeStyles().get(0);
                    if (featureTypeStyle != null) {
                        if (!featureTypeStyle.rules().isEmpty()) {
                            LegendRequest legendEntryRequest = request.new LegendRequest();
                            request.getLegends().add(legendEntryRequest);
                            legendEntryRequest.setTitle(key);
                            legendEntryRequest.setStyle(style);
                        }
                    }
                }
            }
            BufferedImage legendGraphic = null;
            try {
                legendGraphic = legendBuilder.buildLegendGraphic(request);
            } catch (Exception e) {
            // Ignore
            }
            imageMap.put("", legendGraphic);
        } else {
            for (String key : styleMap.keySet()) {
                request.getLegends().clear();
                LegendRequest legendEntryRequest = request.new LegendRequest();
                legendEntryRequest.setStyle(styleMap.get(key));
                legendEntryRequest.setStyleName(key);
                request.getLegends().add(legendEntryRequest);
                BufferedImage legendGraphic = null;
                try {
                    legendGraphic = legendBuilder.buildLegendGraphic(request);
                } catch (Exception e) {
                // Ignore
                }
                imageMap.put(key, legendGraphic);
            }
        }
    }
    return imageMap;
}
Also used : GetLegendGraphicRequest(org.geoserver.wms.GetLegendGraphicRequest) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StyledLayer(org.geotools.styling.StyledLayer) LegendOptionData(com.sldeditor.ui.legend.option.LegendOptionData) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) IIOInvalidTreeException(javax.imageio.metadata.IIOInvalidTreeException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) LegendRequest(org.geoserver.wms.GetLegendGraphicRequest.LegendRequest)

Example 12 with LegendOptionData

use of com.sldeditor.ui.legend.option.LegendOptionData in project sldeditor by robward-scisys.

the class LegendManagerTest method testUpdateLegendOptionData2.

@Test
public void testUpdateLegendOptionData2() {
    StyledLayerDescriptor sld = testSLD2();
    String heading = "Test Heading";
    LegendOptionData legendOption = new LegendOptionData();
    legendOption.setBackgroundColour(Color.CYAN);
    legendOption.setBorder(true);
    legendOption.setBandInformation(true);
    legendOption.setBorderColour(Color.GREEN);
    legendOption.setImageHeight(100);
    legendOption.setImageWidth(100);
    legendOption.setImageHeight(100);
    legendOption.setShowLabels(false);
    legendOption.setShowTitle(false);
    LegendManager.getInstance().SLDLoaded(legendOption);
    boolean actualResult = compareLegendImage(sld, heading);
    assertTrue(actualResult);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) LegendOptionData(com.sldeditor.ui.legend.option.LegendOptionData) Test(org.junit.Test)

Example 13 with LegendOptionData

use of com.sldeditor.ui.legend.option.LegendOptionData in project sldeditor by robward-scisys.

the class LegendOptionDataTest method testLabels.

/**
 * Test method for {@link com.sldeditor.ui.legend.option.LegendOptionData#isShowLabels()}.
 * Test method for {@link com.sldeditor.ui.legend.option.LegendOptionData#setShowLabels(boolean)}.
 */
@Test
public void testLabels() {
    LegendOptionData data = new LegendOptionData();
    data.setShowLabels(true);
    assertTrue(data.isShowLabels());
    data.setShowLabels(false);
    assertFalse(data.isShowLabels());
}
Also used : LegendOptionData(com.sldeditor.ui.legend.option.LegendOptionData) Test(org.junit.Test)

Example 14 with LegendOptionData

use of com.sldeditor.ui.legend.option.LegendOptionData in project sldeditor by robward-scisys.

the class LegendOptionDataTest method testDpi.

/**
 * Test method for {@link com.sldeditor.ui.legend.option.LegendOptionData#getDpi()}.
 * Test method for {@link com.sldeditor.ui.legend.option.LegendOptionData#setDpi(int)}.
 */
@Test
public void testDpi() {
    LegendOptionData data = new LegendOptionData();
    int dpi = 201;
    data.setDpi(dpi);
    assertEquals(dpi, data.getDpi());
}
Also used : LegendOptionData(com.sldeditor.ui.legend.option.LegendOptionData) Test(org.junit.Test)

Example 15 with LegendOptionData

use of com.sldeditor.ui.legend.option.LegendOptionData in project sldeditor by robward-scisys.

the class LegendOptionDataTest method testSplitSymbolizers.

/**
 * Test method for {@link com.sldeditor.ui.legend.option.LegendOptionData#splitSymbolizers()}.
 * Test method for {@link com.sldeditor.ui.legend.option.LegendOptionData#setSplitSymbolizers(boolean)}.
 */
@Test
public void testSplitSymbolizers() {
    LegendOptionData data = new LegendOptionData();
    data.setSplitSymbolizers(true);
    assertTrue(data.splitSymbolizers());
    data.setSplitSymbolizers(false);
    assertFalse(data.splitSymbolizers());
}
Also used : LegendOptionData(com.sldeditor.ui.legend.option.LegendOptionData) Test(org.junit.Test)

Aggregations

LegendOptionData (com.sldeditor.ui.legend.option.LegendOptionData)24 Test (org.junit.Test)21 Color (java.awt.Color)3 IOException (java.io.IOException)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 Document (org.w3c.dom.Document)3 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)2 SLDData (com.sldeditor.common.data.SLDData)2 VersionData (com.sldeditor.common.vendoroption.VersionData)2 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)2 EnvVar (com.sldeditor.filter.v2.envvar.EnvVar)2 Font (java.awt.Font)2 File (java.io.File)2 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)2 Element (org.w3c.dom.Element)2 SLDDataInterface (com.sldeditor.common.SLDDataInterface)1 StyleWrapper (com.sldeditor.common.data.StyleWrapper)1 VendorOptionVersion (com.sldeditor.common.vendoroption.VendorOptionVersion)1