Search in sources :

Example 1 with LinearCandidate

use of org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate in project geotoolkit by Geomatys.

the class LinearLabelCandidateRenderer method generateCandidat.

@Override
public Candidate[] generateCandidat(final LinearLabelDescriptor descriptor) {
    try {
        final Shape[] shapes = descriptor.getGeometry().getDisplayShape();
        final Candidate[] candidates = new Candidate[shapes.length];
        for (int i = 0; i < shapes.length; i++) {
            candidates[i] = new LinearCandidate(descriptor, shapes[i]);
        }
        return candidates;
    } catch (TransformException ex) {
        Logger.getLogger("org.geotoolkit.display2d.style.labeling.decimate").log(Level.WARNING, null, ex);
    }
    return null;
}
Also used : Candidate(org.geotoolkit.display2d.style.labeling.candidate.Candidate) LinearCandidate(org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate) LinearCandidate(org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate) Shape(java.awt.Shape) TransformException(org.opengis.referencing.operation.TransformException)

Example 2 with LinearCandidate

use of org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate in project geotoolkit by Geomatys.

the class DecimationLabelRenderer method portrayLabels.

/**
 * {@inheritDoc }
 */
@Override
public boolean portrayLabels() {
    final Graphics2D g2 = context.getGraphics();
    // enable antialiasing for labels
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // paint the remaining candidates
    for (Candidate candidate : candidates) {
        if (candidate instanceof PointCandidate) {
            pointRenderer.render(candidate);
        } else if (candidate instanceof LinearCandidate) {
            LinearRenderer.render(candidate);
        }
    }
    layers.clear();
    return !candidates.isEmpty();
}
Also used : Candidate(org.geotoolkit.display2d.style.labeling.candidate.Candidate) PointCandidate(org.geotoolkit.display2d.style.labeling.candidate.PointCandidate) LinearCandidate(org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate) LinearCandidate(org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate) PointCandidate(org.geotoolkit.display2d.style.labeling.candidate.PointCandidate) Graphics2D(java.awt.Graphics2D)

Example 3 with LinearCandidate

use of org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate in project geotoolkit by Geomatys.

the class LinearLabelCandidateRenderer method render.

@Override
public void render(final Candidate candidate) {
    if (!(candidate instanceof LinearCandidate))
        return;
    LinearCandidate linearCandidate = (LinearCandidate) candidate;
    LinearLabelDescriptor label = linearCandidate.getDescriptor();
    context.switchToDisplayCRS();
    final TextStroke stroke = new TextStroke(label.getText(), label.getTextFont(), label.isRepeated(), label.getOffSet(), label.getInitialGap(), label.getGap(), context.getCanvasDisplayBounds());
    Shape shp = linearCandidate.getShape();
    if (shp == null) {
        return;
    }
    final Shape shape = stroke.createStrokedShape(shp);
    // paint halo
    if (label.getHaloWidth() > 0) {
        g2.setStroke(new BasicStroke(label.getHaloWidth(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        g2.setPaint(label.getHaloPaint());
        g2.draw(shape);
    }
    // paint text
    g2.setStroke(new BasicStroke(0));
    g2.setPaint(label.getTextPaint());
    g2.fill(shape);
}
Also used : LinearCandidate(org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate) BasicStroke(java.awt.BasicStroke) LinearLabelDescriptor(org.geotoolkit.display2d.style.labeling.LinearLabelDescriptor) Shape(java.awt.Shape) TextStroke(org.geotoolkit.display2d.style.j2d.TextStroke)

Example 4 with LinearCandidate

use of org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate in project geotoolkit by Geomatys.

the class DisplacementLabelRenderer method portrayLabels.

/**
 * {@inheritDoc }
 */
@Override
public boolean portrayLabels() {
    final Graphics2D g2 = context.getGraphics();
    // enable antialiasing for labels
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    List<Candidate> candidates = new ArrayList<Candidate>();
    // generate all the candidates
    // priority is in the order of the layers provided.
    int priority = layers.size();
    for (final LabelLayer layer : layers) {
        for (LabelDescriptor label : layer.labels()) {
            Candidate[] cs = null;
            if (label instanceof PointLabelDescriptor) {
                cs = pointRenderer.generateCandidat((PointLabelDescriptor) label);
            } else if (label instanceof LinearLabelDescriptor) {
                cs = LinearRenderer.generateCandidat((LinearLabelDescriptor) label);
            } else {
                cs = null;
            }
            if (cs != null) {
                for (Candidate c : cs) {
                    c.setPriority(priority);
                    candidates.add(c);
                }
            }
        }
        priority--;
    }
    // displace or remove the candidates
    candidates = optimize(candidates);
    // paint the remaining candidates
    for (Candidate candidate : candidates) {
        if (candidate instanceof PointCandidate) {
            pointRenderer.render(candidate);
        } else if (candidate instanceof LinearCandidate) {
            LinearRenderer.render(candidate);
        }
    }
    layers.clear();
    return !candidates.isEmpty();
}
Also used : Candidate(org.geotoolkit.display2d.style.labeling.candidate.Candidate) PointCandidate(org.geotoolkit.display2d.style.labeling.candidate.PointCandidate) LinearCandidate(org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate) LinearCandidate(org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate) LabelLayer(org.geotoolkit.display2d.style.labeling.LabelLayer) LinearLabelDescriptor(org.geotoolkit.display2d.style.labeling.LinearLabelDescriptor) ArrayList(java.util.ArrayList) PointCandidate(org.geotoolkit.display2d.style.labeling.candidate.PointCandidate) LabelDescriptor(org.geotoolkit.display2d.style.labeling.LabelDescriptor) LinearLabelDescriptor(org.geotoolkit.display2d.style.labeling.LinearLabelDescriptor) PointLabelDescriptor(org.geotoolkit.display2d.style.labeling.PointLabelDescriptor) Graphics2D(java.awt.Graphics2D) PointLabelDescriptor(org.geotoolkit.display2d.style.labeling.PointLabelDescriptor)

Aggregations

LinearCandidate (org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate)4 Candidate (org.geotoolkit.display2d.style.labeling.candidate.Candidate)3 Graphics2D (java.awt.Graphics2D)2 Shape (java.awt.Shape)2 LinearLabelDescriptor (org.geotoolkit.display2d.style.labeling.LinearLabelDescriptor)2 PointCandidate (org.geotoolkit.display2d.style.labeling.candidate.PointCandidate)2 BasicStroke (java.awt.BasicStroke)1 ArrayList (java.util.ArrayList)1 TextStroke (org.geotoolkit.display2d.style.j2d.TextStroke)1 LabelDescriptor (org.geotoolkit.display2d.style.labeling.LabelDescriptor)1 LabelLayer (org.geotoolkit.display2d.style.labeling.LabelLayer)1 PointLabelDescriptor (org.geotoolkit.display2d.style.labeling.PointLabelDescriptor)1 TransformException (org.opengis.referencing.operation.TransformException)1