Search in sources :

Example 71 with FeatureTypeStyle

use of org.geotools.styling.FeatureTypeStyle 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 72 with FeatureTypeStyle

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

the class SelectedSymbolTest method testGetSLD.

@Test
public void testGetSLD() {
    SelectedSymbol.destroyInstance();
    SelectedSymbol instance = SelectedSymbol.getInstance();
    // CHECKSTYLE:OFF
    Rule rule = DefaultSymbols.createNewRule();
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    Style style = DefaultSymbols.createNewStyle();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    PolygonSymbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    // CHECKSTYLE:ON
    instance.createNewSLD(sld);
    instance.setSld(sld);
    System.out.println("Select named layer");
    instance.addNewStyledLayer(namedLayer);
    instance.setStyledLayer(namedLayer);
    assertEquals(namedLayer, instance.getStyledLayer());
    assertNull(instance.getRule());
    assertNull(instance.getStyle());
    assertNull(instance.getFeatureTypeStyle());
    assertNull(instance.getSymbolizer());
    System.out.println("Select style");
    instance.addNewStyle(style);
    instance.setStyle(style);
    assertEquals(namedLayer, instance.getStyledLayer());
    assertEquals(style, instance.getStyle());
    assertNull(instance.getFeatureTypeStyle());
    assertNull(instance.getRule());
    assertNull(instance.getSymbolizer());
    System.out.println("Select feature type style");
    instance.addNewFeatureTypeStyle(fts);
    instance.setFeatureTypeStyle(fts);
    assertEquals(namedLayer, instance.getStyledLayer());
    assertEquals(style, instance.getStyle());
    assertEquals(fts, instance.getFeatureTypeStyle());
    assertNull(instance.getRule());
    assertNull(instance.getSymbolizer());
    System.out.println("Select rule");
    instance.addNewRule(rule);
    instance.setRule(rule);
    assertEquals(namedLayer, instance.getStyledLayer());
    assertEquals(style, instance.getStyle());
    assertEquals(fts, instance.getFeatureTypeStyle());
    assertEquals(rule, instance.getRule());
    assertNull(instance.getSymbolizer());
    assertTrue(instance.hasOnlyOneRule());
    System.out.println("Select symbolizer");
    instance.addSymbolizerToRule(symbolizer);
    instance.addNewRule(DefaultSymbols.createNewRule());
    assertFalse(instance.hasOnlyOneRule());
    assertEquals(-1, instance.getSymbolIndex());
    instance.setSymbolizer(symbolizer);
    assertEquals(namedLayer, instance.getStyledLayer());
    assertEquals(style, instance.getStyle());
    assertEquals(fts, instance.getFeatureTypeStyle());
    assertEquals(rule, instance.getRule());
    assertEquals(symbolizer, instance.getSymbolizer());
    assertEquals(0, instance.getSymbolIndex());
    // Get SLD structure
    StyledLayerDescriptor actualSLD = instance.getSld();
    assertEquals(sld, actualSLD);
    StyledLayer[] actualStyledLayers = actualSLD.getStyledLayers();
    assertEquals(1, actualStyledLayers.length);
    NamedLayer actualNamedLayer = (NamedLayer) actualStyledLayers[0];
    assertEquals(namedLayer, actualNamedLayer);
    Style[] actualStyle = actualNamedLayer.getStyles();
    assertEquals(1, actualStyle.length);
    assertEquals(style, actualStyle[0]);
    assertEquals(1, style.featureTypeStyles().size());
    FeatureTypeStyle actualFeatureTypeStyle = style.featureTypeStyles().get(0);
    assertEquals(fts, actualFeatureTypeStyle);
    List<Rule> actualRules = actualFeatureTypeStyle.rules();
    assertEquals(2, actualRules.size());
    Rule actualRule = actualRules.get(0);
    assertEquals(rule, actualRule);
    assertEquals(1, actualRule.symbolizers().size());
    assertEquals(symbolizer, actualRule.symbolizers().get(0));
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) StyledLayer(org.geotools.styling.StyledLayer) 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 73 with FeatureTypeStyle

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

the class SLDEditorBufferedImageLegendGraphicBuilder method buildLegendGraphic.

/**
 * Takes a GetLegendGraphicRequest and produces a BufferedImage that then can be used by a
 * subclass to encode it to the appropriate output format.
 *
 * @param request the "parsed" request, where "parsed" means that it's values are already
 *        validated so this method must not take care of verifying the requested layer exists
 *        and the like.
 *
 * @throws ServiceException if there are problems creating a "sample" feature instance for the
 *         FeatureType <code>request</code> returns as the required layer (which should not
 *         occur).
 */
public BufferedImage buildLegendGraphic(GetLegendGraphicRequest request) throws ServiceException {
    // list of images to be rendered for the layers (more than one if
    // a layer group is given)
    List<RenderedImage> layersImages = new ArrayList<RenderedImage>();
    List<LegendRequest> layers = request.getLegends();
    boolean forceLabelsOn = false;
    boolean forceLabelsOff = false;
    if (request.getLegendOptions().get("forceLabels") instanceof String) {
        String forceLabelsOpt = (String) request.getLegendOptions().get("forceLabels");
        if (forceLabelsOpt.equalsIgnoreCase("on")) {
            forceLabelsOn = true;
        } else if (forceLabelsOpt.equalsIgnoreCase("off")) {
            forceLabelsOff = true;
        }
    }
    boolean forceTitlesOff = false;
    if (request.getLegendOptions().get("forceTitles") instanceof String) {
        String forceTitlesOpt = (String) request.getLegendOptions().get("forceTitles");
        if (forceTitlesOpt.equalsIgnoreCase("off")) {
            forceTitlesOff = true;
        }
    }
    double imageSizeFactor = 1.0;
    if (request.getLegendOptions().get("imageSizeFactor") instanceof String) {
        String imageSizeFactorOpt = (String) request.getLegendOptions().get("imageSizeFactor");
        imageSizeFactor = Double.valueOf(imageSizeFactorOpt);
    }
    FeatureCountProcessor countProcessor = null;
    if (Boolean.TRUE.equals(request.getLegendOption(GetLegendGraphicRequest.COUNT_MATCHED_KEY, Boolean.class))) {
        countProcessor = new FeatureCountProcessor(request);
    }
    for (LegendRequest legend : layers) {
        FeatureType layer = legend.getFeatureType();
        // style and rule to use for the current layer
        Style gt2Style = legend.getStyle();
        if (gt2Style == null) {
            throw new NullPointerException("request.getStyle()");
        }
        // get rule corresponding to the layer index
        // normalize to null for NO RULE
        // was null
        String ruleName = legend.getRule();
        // width and height, we might have to rescale those in case of DPI usage
        int w = request.getWidth();
        int h = request.getHeight();
        // apply dpi rescale
        double dpi = RendererUtilities.getDpi(request.getLegendOptions());
        double standardDpi = RendererUtilities.getDpi(Collections.emptyMap());
        if (dpi != standardDpi) {
            double scaleFactor = dpi / standardDpi;
            w = (int) Math.round(w * scaleFactor);
            h = (int) Math.round(h * scaleFactor);
            DpiRescaleStyleVisitor dpiVisitor = new DpiRescaleStyleVisitor(scaleFactor);
            dpiVisitor.visit(gt2Style);
            gt2Style = (Style) dpiVisitor.getCopy();
        }
        // apply UOM rescaling if we have a scale
        if (request.getScale() > 0) {
            double pixelsPerMeters = RendererUtilities.calculatePixelsPerMeterRatio(request.getScale(), request.getLegendOptions());
            UomRescaleStyleVisitor rescaleVisitor = new UomRescaleStyleVisitor(pixelsPerMeters);
            rescaleVisitor.visit(gt2Style);
            gt2Style = (Style) rescaleVisitor.getCopy();
        }
        boolean strict = request.isStrict();
        final boolean transparent = request.isTransparent();
        RenderedImage titleImage = null;
        // if we have more than one layer, we put a title on top of each layer legend
        if (layers.size() > 1 && !forceTitlesOff) {
            titleImage = getLayerTitle(legend, w, h, transparent, request);
        }
        // Check for rendering transformation
        boolean hasVectorTransformation = false;
        boolean hasRasterTransformation = false;
        List<FeatureTypeStyle> ftsList = gt2Style.featureTypeStyles();
        for (int i = 0; i < ftsList.size(); i++) {
            FeatureTypeStyle fts = ftsList.get(i);
            Expression exp = fts.getTransformation();
            if (exp != null) {
                ProcessFunction processFunction = (ProcessFunction) exp;
                Name processName = processFunction.getProcessName();
                Map<String, Parameter<?>> outputs = Processors.getResultInfo(processName, null);
                if (outputs.isEmpty()) {
                    continue;
                }
                // we assume there is
                Parameter<?> output = outputs.values().iterator().next();
                // only one output
                if (SimpleFeatureCollection.class.isAssignableFrom(output.getType())) {
                    hasVectorTransformation = true;
                    break;
                } else if (GridCoverage2D.class.isAssignableFrom(output.getType())) {
                    hasRasterTransformation = true;
                    break;
                }
            }
        }
        final boolean buildRasterLegend = (!strict && layer == null && LegendUtils.checkRasterSymbolizer(gt2Style)) || (LegendUtils.checkGridLayer(layer) && !hasVectorTransformation) || hasRasterTransformation;
        // Just checks LegendInfo currently, should check gtStyle
        final boolean useProvidedLegend = layer != null && legend.getLayerInfo() != null;
        RenderedImage legendImage = null;
        if (useProvidedLegend) {
            legendImage = getLayerLegend(legend, w, h, transparent, request);
        }
        if (buildRasterLegend) {
            final RasterLayerLegendHelper rasterLegendHelper = new RasterLayerLegendHelper(request, gt2Style, ruleName);
            final BufferedImage image = rasterLegendHelper.getLegend();
            if (image != null) {
                if (titleImage != null) {
                    layersImages.add(titleImage);
                }
                layersImages.add(image);
            }
        } else if (useProvidedLegend && legendImage != null) {
            if (titleImage != null) {
                layersImages.add(titleImage);
            }
            layersImages.add(legendImage);
        } else {
            final Feature sampleFeature;
            if (layer == null || hasVectorTransformation) {
                sampleFeature = createSampleFeature();
            } else {
                sampleFeature = createSampleFeature(layer);
            }
            final FeatureTypeStyle[] ftStyles = gt2Style.featureTypeStyles().toArray(new FeatureTypeStyle[0]);
            final double scaleDenominator = request.getScale();
            Rule[] applicableRules;
            if (ruleName != null) {
                Rule rule = LegendUtils.getRule(ftStyles, ruleName);
                if (rule == null) {
                    throw new ServiceException("Specified style does not contains a rule named " + ruleName);
                }
                applicableRules = new Rule[] { rule };
            } else {
                applicableRules = LegendUtils.getApplicableRules(ftStyles, scaleDenominator);
            }
            // do we have to alter the style to do context sensitive feature counts?
            if (countProcessor != null && !forceLabelsOff) {
                applicableRules = updateRuleTitles(countProcessor, legend, applicableRules);
            }
            final NumberRange<Double> scaleRange = NumberRange.create(scaleDenominator, scaleDenominator);
            final int ruleCount = applicableRules.length;
            /**
             * A legend graphic is produced for each applicable rule. They're being held here
             * until the process is done and then painted on a "stack" like legend.
             */
            final List<RenderedImage> legendsStack = new ArrayList<RenderedImage>(ruleCount);
            final SLDStyleFactory styleFactory = new SLDStyleFactory();
            double minimumSymbolSize = MINIMUM_SYMBOL_SIZE;
            // get minSymbolSize from LEGEND_OPTIONS, if defined
            if (request.getLegendOptions().get("minSymbolSize") instanceof String) {
                String minSymbolSizeOpt = (String) request.getLegendOptions().get("minSymbolSize");
                try {
                    minimumSymbolSize = Double.parseDouble(minSymbolSizeOpt);
                } catch (NumberFormatException e) {
                    throw new IllegalArgumentException("Invalid minSymbolSize value: should be a number");
                }
            }
            // calculate the symbols rescaling factor necessary for them to be
            // drawn inside the icon box
            double symbolScale = calcSymbolScale(w, h, layer, sampleFeature, applicableRules, minimumSymbolSize);
            for (int i = 0; i < ruleCount; i++) {
                final RenderedImage image = ImageUtils.createImage(w, h, (IndexColorModel) null, transparent);
                final Map<RenderingHints.Key, Object> hintsMap = new HashMap<RenderingHints.Key, Object>();
                final Graphics2D graphics = ImageUtils.prepareTransparency(transparent, LegendUtils.getBackgroundColor(request), image, hintsMap);
                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                Feature sample = getSampleFeatureForRule(layer, sampleFeature, applicableRules[i]);
                FilterFactory ff = CommonFactoryFinder.getFilterFactory();
                final Symbolizer[] symbolizers = applicableRules[i].getSymbolizers();
                final GraphicLegend graphic = applicableRules[i].getLegend();
                // If this rule has a legend graphic defined in the SLD, use it
                if (graphic != null) {
                    if (this.samplePoint == null) {
                        Coordinate coord = new Coordinate(w / 2, h / 2);
                        try {
                            this.samplePoint = new LiteShape2(geomFac.createPoint(coord), null, null, false);
                        } catch (Exception e) {
                            this.samplePoint = null;
                        }
                    }
                    shapePainter.paint(graphics, this.samplePoint, graphic, scaleDenominator, false);
                } else {
                    for (int sIdx = 0; sIdx < symbolizers.length; sIdx++) {
                        Symbolizer symbolizer = symbolizers[sIdx];
                        if (symbolizer instanceof RasterSymbolizer) {
                        // skip it
                        } else {
                            // rescale symbols if needed
                            if (symbolScale > 1.0 && symbolizer instanceof PointSymbolizer) {
                                PointSymbolizer pointSymbolizer = (PointSymbolizer) cloneSymbolizer(symbolizer);
                                if (pointSymbolizer.getGraphic() != null) {
                                    double size = getGraphicSize(sample, pointSymbolizer.getGraphic(), Math.min(w, h) - 4);
                                    pointSymbolizer.getGraphic().setSize(ff.literal(size / symbolScale + minimumSymbolSize));
                                    symbolizer = pointSymbolizer;
                                }
                            }
                            if (!(Math.abs(imageSizeFactor - 1.0) < 0.0001)) {
                                if (symbolizer instanceof PointSymbolizer) {
                                    PointSymbolizer pointSymbolizer2 = (PointSymbolizer) cloneSymbolizer(symbolizer);
                                    if (pointSymbolizer2.getGraphic() != null) {
                                        double size = getGraphicSize(sample, pointSymbolizer2.getGraphic(), Math.min(w, h) - 4);
                                        pointSymbolizer2.getGraphic().setSize(ff.literal(size * imageSizeFactor + minimumSymbolSize));
                                        symbolizer = pointSymbolizer2;
                                    }
                                } else if (symbolizer instanceof PolygonSymbolizer) {
                                    PolygonSymbolizer polygonSymbolizer2 = (PolygonSymbolizer) cloneSymbolizer(symbolizer);
                                    if (polygonSymbolizer2.getFill() != null) {
                                        // Fill
                                        double size = 0.0;
                                        if (polygonSymbolizer2.getFill().getGraphicFill() != null) {
                                            size = getGraphicSize(sample, polygonSymbolizer2.getFill().getGraphicFill(), Math.min(w, h) - 4);
                                            polygonSymbolizer2.getFill().getGraphicFill().setSize(ff.literal(size * imageSizeFactor + minimumSymbolSize));
                                        }
                                    }
                                    if (polygonSymbolizer2.getStroke() != null) {
                                        // Stroke
                                        double size = getGraphicSize(sample, polygonSymbolizer2.getStroke().getGraphicFill(), Math.min(w, h) - 4);
                                        polygonSymbolizer2.getStroke().getGraphicFill().setSize(ff.literal(size * imageSizeFactor + minimumSymbolSize));
                                        if (polygonSymbolizer2.getStroke().getGraphicStroke() != null) {
                                            size = getGraphicSize(sample, polygonSymbolizer2.getStroke().getGraphicStroke(), Math.min(w, h) - 4);
                                            polygonSymbolizer2.getStroke().getGraphicStroke().setSize(ff.literal(size * imageSizeFactor + minimumSymbolSize));
                                        }
                                    }
                                    symbolizer = polygonSymbolizer2;
                                } else if (symbolizer instanceof LineSymbolizer) {
                                    LineSymbolizer lineSymbolizer2 = (LineSymbolizer) cloneSymbolizer(symbolizer);
                                    if (lineSymbolizer2.getStroke() != null) {
                                        // Stroke
                                        double size = 0.0;
                                        if (lineSymbolizer2.getStroke().getGraphicFill() != null) {
                                            size = getGraphicSize(sample, lineSymbolizer2.getStroke().getGraphicFill(), Math.min(w, h) - 4);
                                            lineSymbolizer2.getStroke().getGraphicFill().setSize(ff.literal(size * imageSizeFactor + minimumSymbolSize));
                                        }
                                        if (lineSymbolizer2.getStroke().getGraphicStroke() != null) {
                                            size = getGraphicSize(sample, lineSymbolizer2.getStroke().getGraphicStroke(), Math.min(w, h) - 4);
                                            lineSymbolizer2.getStroke().getGraphicStroke().setSize(ff.literal(size * imageSizeFactor + minimumSymbolSize));
                                        }
                                        if (lineSymbolizer2.getStroke().getWidth() != null) {
                                            size = getWidthSize(sample, lineSymbolizer2.getStroke().getWidth(), 1);
                                            lineSymbolizer2.getStroke().setWidth(ff.literal(size * imageSizeFactor));
                                        }
                                    }
                                    symbolizer = lineSymbolizer2;
                                }
                            }
                        }
                        Style2D style2d = styleFactory.createStyle(sample, symbolizer, scaleRange);
                        LiteShape2 shape = getSampleShape(symbolizer, w, h);
                        if (style2d != null) {
                            shapePainter.paint(graphics, shape, style2d, scaleDenominator);
                        }
                    }
                }
                if (image != null && titleImage != null) {
                    layersImages.add(titleImage);
                    titleImage = null;
                }
                legendsStack.add(image);
                graphics.dispose();
            }
            int labelMargin = 3;
            if (!StringUtils.isEmpty(request.getLegendOptions().get("labelMargin"))) {
                labelMargin = Integer.parseInt(request.getLegendOptions().get("labelMargin").toString());
            }
            LegendMerger.MergeOptions options = LegendMerger.MergeOptions.createFromRequest(legendsStack, 0, 0, 0, labelMargin, request, forceLabelsOn, forceLabelsOff, forceTitlesOff);
            if (ruleCount > 0) {
                BufferedImage image = LegendMerger.mergeLegends(applicableRules, request, options);
                if (image != null) {
                    layersImages.add(image);
                }
            }
        }
    }
    // all legend graphics are merged if we have a layer group
    BufferedImage finalLegend = mergeGroups(layersImages, null, request, forceLabelsOn, forceLabelsOff, forceTitlesOff);
    if (finalLegend == null) {
        throw new IllegalArgumentException("no legend passed");
    }
    return finalLegend;
}
Also used : PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) ArrayList(java.util.ArrayList) LineString(com.vividsolutions.jts.geom.LineString) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) FilterFactory(org.opengis.filter.FilterFactory) Name(org.opengis.feature.type.Name) List(java.util.List) ArrayList(java.util.ArrayList) GraphicLegend(org.opengis.style.GraphicLegend) UomRescaleStyleVisitor(org.geotools.styling.visitor.UomRescaleStyleVisitor) ProcessFunction(org.geotools.process.function.ProcessFunction) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) ServiceException(org.geoserver.platform.ServiceException) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineSymbolizer(org.geotools.styling.LineSymbolizer) Rule(org.geotools.styling.Rule) Map(java.util.Map) HashMap(java.util.HashMap) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureType(org.opengis.feature.type.FeatureType) BufferedImage(java.awt.image.BufferedImage) RenderingHints(java.awt.RenderingHints) Style2D(org.geotools.renderer.style.Style2D) DpiRescaleStyleVisitor(org.geotools.styling.visitor.DpiRescaleStyleVisitor) SLDStyleFactory(org.geotools.renderer.style.SLDStyleFactory) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) LiteShape2(org.geotools.geometry.jts.LiteShape2) IndexColorModel(java.awt.image.IndexColorModel) PointSymbolizer(org.geotools.styling.PointSymbolizer) GridCoverage2D(org.geotools.coverage.grid.GridCoverage2D) Point(com.vividsolutions.jts.geom.Point) ServiceException(org.geoserver.platform.ServiceException) SchemaException(org.geotools.feature.SchemaException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IllegalAttributeException(org.opengis.feature.IllegalAttributeException) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) Graphics2D(java.awt.Graphics2D) NumberRange(org.geotools.util.NumberRange) Expression(org.opengis.filter.expression.Expression) Parameter(org.geotools.data.Parameter) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) RenderedImage(java.awt.image.RenderedImage) LegendRequest(org.geoserver.wms.GetLegendGraphicRequest.LegendRequest)

Example 74 with FeatureTypeStyle

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

the class SLDTreeTools method moveItem.

/**
 * Move item within a list. The direction parameter determines which way the item is moved.
 *
 * @param moveUp the move up flags (true), or down (false)
 */
public void moveItem(boolean moveUp) {
    if (symbolTree == null) {
        return;
    }
    if (treeModel == null) {
        return;
    }
    if (sldTree == null) {
        return;
    }
    TreePath path = symbolTree.getSelectionPath();
    if (path == null) {
        return;
    }
    DefaultMutableTreeNode lastNode = (DefaultMutableTreeNode) path.getLastPathComponent();
    if (lastNode == null) {
        return;
    }
    Object obj = lastNode.getUserObject();
    if (obj == null) {
        return;
    }
    DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) lastNode.getParent();
    if (parentNode == null) {
        return;
    }
    Object parentObj = parentNode.getUserObject();
    if (parentObj == null) {
        return;
    }
    // Calculate index offset value based on direction
    int direction = moveUp ? -1 : 1;
    // Store current state of the SLD before the move
    // CHECKSTYLE:OFF
    Object oldValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
    if (obj instanceof StyledLayer) {
        StyledLayerDescriptor sld = (StyledLayerDescriptor) parentObj;
        // NamedLayerImpl.equals() doesn't work in the way I
        // want it to, so indexOf() does not work
        boolean found = false;
        int index = 0;
        for (StyledLayer styledLayer : sld.layers()) {
            if (styledLayer == obj) {
                found = true;
                break;
            } else {
                index++;
            }
        }
        if (found && ((index + direction) >= 0) && (index + direction) < sld.layers().size()) {
            StyledLayer styledLayer = sld.layers().remove(index);
            sld.layers().add(index + direction, styledLayer);
            treeModel.removeNodeFromParent(lastNode);
            treeModel.insertNodeInto(lastNode, parentNode, index + direction);
        } else {
            return;
        }
    } else if (obj instanceof Style) {
        if (parentObj instanceof NamedLayerImpl) {
            NamedLayerImpl namedLayer = (NamedLayerImpl) parentObj;
            int index = namedLayer.styles().indexOf(obj);
            if (((index + direction) >= 0) && (index + direction) < namedLayer.styles().size()) {
                Style style = namedLayer.styles().remove(index);
                namedLayer.styles().add(index + direction, style);
                treeModel.removeNodeFromParent(lastNode);
                treeModel.insertNodeInto(lastNode, parentNode, index + direction);
            } else {
                return;
            }
        }
    } else if (obj instanceof FeatureTypeStyle) {
        Style style = (Style) parentObj;
        int index = style.featureTypeStyles().indexOf(obj);
        if (((index + direction) >= 0) && (index + direction) < style.featureTypeStyles().size()) {
            FeatureTypeStyle fts = style.featureTypeStyles().remove(index);
            style.featureTypeStyles().add(index + direction, fts);
            treeModel.removeNodeFromParent(lastNode);
            treeModel.insertNodeInto(lastNode, parentNode, index + direction);
        } else {
            return;
        }
    } else if (obj instanceof Rule) {
        FeatureTypeStyle fts = (FeatureTypeStyle) parentObj;
        int index = fts.rules().indexOf(obj);
        if (((index + direction) >= 0) && (index + direction) < fts.rules().size()) {
            Rule rule = fts.rules().remove(index);
            fts.rules().add(index + direction, rule);
            treeModel.removeNodeFromParent(lastNode);
            treeModel.insertNodeInto(lastNode, parentNode, index + direction);
        } else {
            return;
        }
    } else if (obj instanceof Symbolizer) {
        Rule rule = (Rule) parentObj;
        int index = rule.symbolizers().indexOf(obj);
        if (((index + direction) >= 0) && (index + direction) < rule.symbolizers().size()) {
            Symbolizer symbolizer = rule.symbolizers().remove(index);
            rule.symbolizers().add(index + direction, symbolizer);
            treeModel.removeNodeFromParent(lastNode);
            treeModel.insertNodeInto(lastNode, parentNode, index + direction);
        } else {
            return;
        }
    }
    // Refresh the tree structure. Not very efficient but gets result wanted.
    // The node has been moved in the tree above. Now going to refresh model.
    treeModel.nodeStructureChanged(lastNode);
    // Get path for item moved
    TreePath newNodePath = getPath(lastNode);
    int[] selectedRows = new int[1];
    selectedRows[0] = symbolTree.getRowForPath(newNodePath);
    // Find the row of item moved
    // Now clear tree structure and re-populate, inefficient but it means
    // that all items are expanded as required.
    SLDTreeManager.getInstance().rebuildTree((SLDTree) sldTree);
    // Make item moved selected again
    symbolTree.setSelectionRows(selectedRows);
    // Re-render the symbol
    if (renderList != null) {
        for (RenderSymbolInterface render : renderList) {
            render.renderSymbol();
        }
    }
    // Store current state of the SLD after the move
    Object newValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
    UndoManager.getInstance().addUndoEvent(new UndoEvent(sldTree.getUndoObject(), getClass().getName(), oldValueObj, newValueObj));
}
Also used : UndoEvent(com.sldeditor.common.undo.UndoEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) LineSymbolizer(org.geotools.styling.LineSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TreePath(javax.swing.tree.TreePath) RenderSymbolInterface(com.sldeditor.datasource.RenderSymbolInterface) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Example 75 with FeatureTypeStyle

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

the class FeatureTypeStyleTreeItem method getTreeString.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.tree.item.SLDTreeItemInterface#getTreeString(javax.swing.tree.DefaultMutableTreeNode, java.lang.Object)
     */
@Override
public String getTreeString(DefaultMutableTreeNode node, Object nodeObject) {
    FeatureTypeStyle fts = (FeatureTypeStyle) nodeObject;
    String name = "";
    if (fts != null) {
        if (fts.getName() != null) {
            name = fts.getName();
        }
    }
    return String.format("%s : %s", TITLE, name);
}
Also used : FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle)

Aggregations

FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)110 Style (org.geotools.styling.Style)81 Rule (org.geotools.styling.Rule)65 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)43 Test (org.junit.Test)42 NamedLayer (org.geotools.styling.NamedLayer)38 PointSymbolizer (org.geotools.styling.PointSymbolizer)24 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)22 StyledLayer (org.geotools.styling.StyledLayer)21 LineSymbolizer (org.geotools.styling.LineSymbolizer)20 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)17 Symbolizer (org.geotools.styling.Symbolizer)16 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)15 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)14 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)12 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)12 TextSymbolizer (org.geotools.styling.TextSymbolizer)12 UserLayerImpl (org.geotools.styling.UserLayerImpl)12 ArrayList (java.util.ArrayList)11 LineStyle (org.polymap.core.style.model.feature.LineStyle)11