001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package net.refractions.udig.render.internal.feature.basic;
016:
017: import java.awt.Graphics2D;
018: import java.awt.Point;
019: import java.awt.Rectangle;
020: import java.awt.geom.AffineTransform;
021: import java.util.List;
022:
023: import javax.media.jai.util.Range;
024:
025: import net.refractions.udig.project.render.ILabelPainter;
026:
027: import org.geotools.feature.Feature;
028: import org.geotools.geometry.jts.JTS;
029: import org.geotools.referencing.FactoryFinder;
030: import org.geotools.referencing.operation.matrix.GeneralMatrix;
031: import org.geotools.referencing.operation.transform.IdentityTransform;
032: import org.geotools.renderer.lite.LabelCache;
033: import org.geotools.renderer.lite.LiteShape2;
034: import org.geotools.styling.TextSymbolizer;
035: import org.opengis.referencing.FactoryException;
036: import org.opengis.referencing.operation.MathTransform;
037: import org.opengis.referencing.operation.TransformException;
038:
039: import com.vividsolutions.jts.geom.Geometry;
040:
041: /**
042: * Wraps the context's {@link ILabelPainter} to allow labelling produced by the Streaming/Shapefile renderers to be combined
043: * with the labels from other labels. Streaming and Shapefile renderer both assume they are the start and end points of rendering
044: * so they start and finish the label cache, as well as assign their own layerIds and clear the cache. None of these are acceptable
045: * for uDig so this class intercepts the calls and handles these cases as well as translating the geometries so they are relative to
046: * the full display area.
047: *
048: * @author Jesse
049: * @since 1.1.0
050: */
051: public class LabelCacheDecorator implements LabelCache {
052: private final LabelCache wrapped;
053: private final Point origin;
054: private final String layerId;
055:
056: public LabelCacheDecorator(final LabelCache wrapped, Point origin,
057: String layerId) {
058: super ();
059: this .wrapped = wrapped;
060: this .origin = origin;
061: this .layerId = layerId;
062: }
063:
064: public void clear() {
065: // do nothing see doClear()
066: }
067:
068: public void end(Graphics2D graphics, Rectangle displayArea) {
069: // do nothing so that Geotools renderers don't trigger the rendering of the labels
070: }
071:
072: public void clear(String layerId) {
073: wrapped.clear(this .layerId);
074: }
075:
076: public void disableLayer(String layerId) {
077: wrapped.disableLayer(this .layerId);
078: }
079:
080: public void enableLayer(String layerId) {
081: wrapped.enableLayer(this .layerId);
082: }
083:
084: public void endLayer(String layerId, Graphics2D graphics,
085: Rectangle displayArea) {
086: // this is called by the frame work later. Geotools doesn't need to call this
087: }
088:
089: public List orderedLabels() {
090: return wrapped.orderedLabels();
091: }
092:
093: public void put(String layerId, TextSymbolizer symbolizer,
094: Feature feature, LiteShape2 shape, Range scaleRange) {
095:
096: wrapped.put(this .layerId, symbolizer, feature, shape,
097: scaleRange);
098: }
099:
100: public void start() {
101: wrapped.start();
102: }
103:
104: public void startLayer(String layerId) {
105: // this is called by the frame work earlier. Geotools doesn't need to call this
106: }
107:
108: public void stop() {
109: /*
110: * Vitalus:
111: * We should not stop label cache from one renderer while it is shared between many renderers.
112: * Fix for labels rendering when the layer is removed.
113: */
114: // wrapped.stop();
115: }
116:
117: }
|