01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.project.internal.render.impl;
16:
17: import java.awt.Graphics2D;
18: import java.awt.Rectangle;
19: import java.util.HashSet;
20: import java.util.Set;
21:
22: import net.refractions.udig.project.render.ILabelPainter;
23:
24: import org.geotools.renderer.lite.SynchronizedLabelCache;
25:
26: /**
27: * Extends the Geotools default labeller so that the geotools renderer doesn't clear the cache when it runs.
28: * The comments in the geotools default label cache states this is ok.
29: * <p>
30: * Also over-rides end so that geotools renderers don't cause the rendering and we can do it once at the end.
31: * </p>
32: *
33: * @author Jesse
34: * @since 1.1.0
35: */
36: public class UDIGLabelCache extends SynchronizedLabelCache implements
37: ILabelPainter {
38:
39: Set<String> activeLayers = new HashSet<String>();
40:
41: public Object getAdapter(Class adapter) {
42: return null;
43: }
44:
45: @Override
46: public synchronized void startLayer(String layerId) {
47: activeLayers.add(layerId);
48: super .startLayer(layerId);
49: }
50:
51: @Override
52: public synchronized void stop() {
53: activeLayers.clear();
54: super .stop();
55: }
56:
57: @Override
58: public synchronized void end(Graphics2D graphics,
59: Rectangle displayArea) {
60: if (activeLayers.isEmpty())
61: super .end(graphics, displayArea);
62: }
63:
64: @Override
65: public synchronized void clear() {
66: if (activeLayers.isEmpty())
67: super .clear();
68: }
69:
70: @Override
71: public synchronized void clear(String layerId) {
72: if (!activeLayers.contains(layerId))
73: super .clear(layerId);
74: }
75:
76: @Override
77: public synchronized void endLayer(String layerId,
78: Graphics2D graphics, Rectangle displayArea) {
79: activeLayers.remove(layerId);
80: super.endLayer(layerId, graphics, displayArea);
81: }
82:
83: }
|