01: package com.vividsolutions.jump.workbench.ui.renderer;
02:
03: import java.awt.Graphics2D;
04: import java.util.*;
05: import java.util.ArrayList;
06: import java.util.Collection;
07: import java.util.Iterator;
08: import java.util.Map;
09:
10: import com.vividsolutions.jump.feature.Feature;
11: import com.vividsolutions.jump.workbench.model.Layer;
12: import com.vividsolutions.jump.workbench.ui.LayerViewPanel;
13: import com.vividsolutions.jump.workbench.ui.renderer.style.Style;
14:
15: /**
16: * @see ImageCachingFeatureCollectionRenderer
17: * @see FeatureCollectionRenderer
18: */
19: public class SimpleFeatureCollectionRenderer extends SimpleRenderer {
20:
21: public SimpleFeatureCollectionRenderer(Object contentID,
22: LayerViewPanel panel) {
23: super (contentID, panel);
24: }
25:
26: private void paint(Graphics2D g, Collection features, Layer layer,
27: Style style) throws Exception {
28: if (!layer.isVisible()) {
29: return;
30: }
31: if (!style.isEnabled()) {
32: return;
33: }
34: style.initialize(layer);
35: //new ArrayList to avoid ConcurrentModificationException. [Jon Aquino]
36: for (Iterator i = new ArrayList(features).iterator(); i
37: .hasNext();) {
38: final Feature feature = (Feature) i.next();
39: if (cancelled) {
40: return;
41: }
42: if (feature.getGeometry().isEmpty()) {
43: continue;
44: }
45: style.paint(feature, g, panel.getViewport());
46: }
47: }
48:
49: protected void paint(Graphics2D g) throws Exception {
50: for (Iterator i = styles.iterator(); i.hasNext();) {
51: Style style = (Style) i.next();
52: if (cancelled) {
53: return;
54: }
55: for (Iterator j = layerToFeaturesMap.keySet().iterator(); j
56: .hasNext();) {
57: Layer layer = (Layer) j.next();
58: if (cancelled) {
59: return;
60: }
61: Collection features = (Collection) layerToFeaturesMap
62: .get(layer);
63: paint(g, features, layer, style);
64: }
65: }
66: }
67:
68: private Collection styles = new ArrayList();
69:
70: private Map layerToFeaturesMap = new HashMap();
71:
72: protected void setLayerToFeaturesMap(Map layerToFeaturesMap) {
73: this .layerToFeaturesMap = layerToFeaturesMap;
74: }
75:
76: protected void setStyles(Collection styles) {
77: this.styles = styles;
78: }
79:
80: }
|