01: package com.vividsolutions.jump.workbench.ui.renderer;
02:
03: import java.awt.Graphics2D;
04: import java.awt.RenderingHints;
05: import java.util.*;
06: import java.util.ArrayList;
07: import java.util.Collection;
08: import java.util.Iterator;
09: import java.util.Map;
10:
11: import com.vividsolutions.jump.feature.Feature;
12: import com.vividsolutions.jump.workbench.model.Layer;
13: import com.vividsolutions.jump.workbench.ui.LayerViewPanel;
14: import com.vividsolutions.jump.workbench.ui.renderer.style.Style;
15:
16: /**
17: * @see SimpleFeatureCollectionRenderer
18: * @see FeatureCollectionRenderer
19: */
20: public class ImageCachingFeatureCollectionRenderer extends
21: ImageCachingRenderer {
22:
23: public ImageCachingFeatureCollectionRenderer(Object contentID,
24: LayerViewPanel panel) {
25: super (contentID, panel);
26: }
27:
28: private Collection styles = new ArrayList();
29:
30: private Map layerToFeaturesMap = new HashMap();
31:
32: protected void setLayerToFeaturesMap(Map layerToFeaturesMap) {
33: this .layerToFeaturesMap = layerToFeaturesMap;
34: }
35:
36: protected void setStyles(Collection styles) {
37: this .styles = styles;
38: }
39:
40: protected void renderHook(ThreadSafeImage image,
41: Collection features, Layer layer, final Style style)
42: throws Exception {
43: if (!layer.isVisible()) {
44: return;
45: }
46: if (!style.isEnabled()) {
47: return;
48: }
49: style.initialize(layer);
50: //new ArrayList to avoid ConcurrentModificationException. [Jon Aquino]
51:
52: // Revert to the original list, as the features may be a LazyList
53: // containing a huge number of features from a database. Monitor the
54: // frequency of ConcurrentModificationException errors. [Jon Aquino
55: // 2005-03-02]
56: for (Iterator i = features.iterator(); i.hasNext();) {
57: final Feature feature = (Feature) i.next();
58: if (cancelled) {
59: break;
60: }
61: if (feature.getGeometry() == null
62: || feature.getGeometry().isEmpty()) {
63: continue;
64: }
65: //Because image.draw is synchronized, it might be faster to do
66: //several paints inside #draw. [Jon Aquino]
67: image.draw(new ThreadSafeImage.Drawer() {
68: public void draw(Graphics2D g) throws Exception {
69: style.paint(feature, g, panel.getViewport());
70: }
71: });
72: }
73: }
74:
75: protected void renderHook(ThreadSafeImage image) throws Exception {
76: for (Iterator i = styles.iterator(); i.hasNext();) {
77: Style style = (Style) i.next();
78: for (Iterator j = layerToFeaturesMap.keySet().iterator(); j
79: .hasNext();) {
80: Layer layer = (Layer) j.next();
81: Collection features = (Collection) layerToFeaturesMap
82: .get(layer);
83: renderHook(image, features, layer, style);
84: }
85: }
86: }
87:
88: }
|