01: package net.refractions.udig.project.internal.render.impl;
02:
03: import java.util.ArrayList;
04: import java.util.List;
05:
06: import net.refractions.udig.catalog.IGeoResource;
07: import net.refractions.udig.core.internal.ExtensionPointProcessor;
08: import net.refractions.udig.project.internal.Layer;
09: import net.refractions.udig.project.internal.render.RenderContext;
10: import net.refractions.udig.project.internal.render.RenderManager;
11: import net.refractions.udig.project.internal.render.SelectionLayer;
12: import net.refractions.udig.project.internal.render.impl.InternalRenderMetricsFactory.InternalRenderMetrics;
13: import net.refractions.udig.project.render.IMultiLayerRenderer;
14: import net.refractions.udig.project.render.IRenderMetricsFactory;
15:
16: import org.eclipse.core.runtime.CoreException;
17: import org.eclipse.core.runtime.IConfigurationElement;
18: import org.eclipse.core.runtime.IExtension;
19:
20: /**
21: * Processes the net.refractions.udig.project.renderer extension point adding the RendererMetricsFactories that apply to the layer to
22: * a cache of legal RendererMetricsFactories.
23: *
24: * @author Jesse
25: * @since 1.0.0
26: */
27: class RendererExtensionProcessor implements ExtensionPointProcessor {
28: Layer layer;
29:
30: List<InternalRenderMetrics> rFactories = new ArrayList<InternalRenderMetrics>();
31:
32: private net.refractions.udig.project.internal.Map map;
33:
34: private RenderManager rm;
35:
36: /**
37: * Creates an new instance of Processor
38: *
39: * @param layer The layer which needs to be rendered
40: */
41: public RendererExtensionProcessor(Layer layer,
42: net.refractions.udig.project.internal.Map map,
43: RenderManager rm) {
44: this .layer = layer;
45: this .rm = rm;
46: this .map = map;
47: }
48:
49: /**
50: * @see net.refractions.udig.core.internal.ExtensionPointProcessor#process(org.eclipse.core.runtime.IExtension,
51: * org.eclipse.core.runtime.IConfigurationElement)
52: */
53: public void process(IExtension extension,
54: IConfigurationElement element) {
55:
56: try {
57: IRenderMetricsFactory createExecutableExtension = (IRenderMetricsFactory) element
58: .createExecutableExtension("class"); //$NON-NLS-1$
59: InternalRenderMetricsFactory metricsFactory = new InternalRenderMetricsFactory(
60: createExecutableExtension, element);
61:
62: List<IGeoResource> data = layer.getGeoResources();
63: for (IGeoResource resource : data) {
64:
65: RenderContext context;
66:
67: try {
68: if (IMultiLayerRenderer.class
69: .isAssignableFrom(metricsFactory
70: .getRendererType())) {
71: context = new CompositeRenderContextImpl();
72: } else {
73: context = new RenderContextImpl(
74: layer instanceof SelectionLayer);
75: }
76: } catch (Throwable e) {
77: context = new RenderContextImpl(
78: layer instanceof SelectionLayer);
79: }
80:
81: context.setMapInternal(map);
82: context.setRenderManagerInternal(rm);
83: context.setLayerInternal(layer);
84: context.setGeoResourceInternal(resource);
85:
86: rFactories.add(metricsFactory.createMetrics(context));
87: }
88: } catch (CoreException e) {
89: throw (RuntimeException) new RuntimeException()
90: .initCause(e);
91: }
92: }
93: }
|