001: /*
002: * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
003: * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
004: * under the terms of the GNU Lesser General Public License as published by the Free Software
005: * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
006: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
007: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
008: */
009: package net.refractions.udig.project.internal.render.impl;
010:
011: import java.awt.Point;
012: import java.util.List;
013:
014: import net.refractions.udig.project.ILayer;
015: import net.refractions.udig.project.internal.Layer;
016: import net.refractions.udig.project.internal.render.CompositeRenderContext;
017: import net.refractions.udig.project.internal.render.ExecutorVisitor;
018: import net.refractions.udig.project.internal.render.MultiLayerRenderer;
019: import net.refractions.udig.project.internal.render.RenderContext;
020: import net.refractions.udig.project.internal.render.RenderExecutor;
021: import net.refractions.udig.project.internal.render.Renderer;
022: import net.refractions.udig.project.render.IRenderContext;
023:
024: import org.eclipse.emf.common.notify.Notification;
025:
026: import com.vividsolutions.jts.geom.Envelope;
027:
028: /**
029: * A RenderExecutor that runs MultiLayerRenderers such as WMSRenderer and MapGraphic Renderers.
030: *
031: * @author Jesse
032: * @since 1.0.0
033: */
034: public class RenderExecutorMultiLayer extends RenderExecutorImpl {
035:
036: protected final static class MultiLayerRendererLayerListener extends
037: LayerListener {
038:
039: /**
040: * Construct <code>CompositeRendererLayerListener</code>.
041: *
042: * @param executor
043: */
044: MultiLayerRendererLayerListener(
045: RenderExecutorMultiLayer executor) {
046: super (executor);
047: }
048:
049: /**
050: * @see net.refractions.udig.project.internal.render.impl.RenderExecutorAdapters.ILayerListener#styleBlackboardChanged(org.eclipse.emf.common.notify.Notification)
051: */
052: protected void styleBlackboardChanged(Notification msg) {
053: if (executor.getRenderer() instanceof MultiLayerRenderer)
054: return;
055:
056: executor.getContext().getRenderManager().refresh(
057: (ILayer) msg.getNotifier(), (Envelope) null);
058:
059: }
060:
061: /**
062: * @see net.refractions.udig.project.internal.render.impl.RenderExecutorAdapters.ILayerListener#layerNotVisible(net.refractions.udig.project.Layer,
063: * org.eclipse.emf.common.notify.Notification)
064: */
065: protected void layerNotVisible(Layer layer, Notification msg) {
066: executor.getContext().getLabelPainter()
067: .disableLayer(
068: executor.getContext().getLayer().getID()
069: .toString());
070: CompositeRenderContext context = ((RenderExecutorMultiLayer) executor)
071: .getContext();
072: if (context.isVisible() && context.getContexts().size() > 1) {
073: executor.getContext().getRenderManager().refresh(layer,
074: (Envelope) null);
075: } else {
076: super .layerNotVisible(layer, msg);
077: }
078: }
079:
080: /**
081: * @see net.refractions.udig.project.internal.render.impl.RenderExecutorAdapters.ILayerListener#layerVisible(net.refractions.udig.project.Layer,
082: * org.eclipse.emf.common.notify.Notification)
083: */
084: protected void layerVisible(Layer layer, Notification msg) {
085: CompositeRenderContext context = ((RenderExecutorMultiLayer) executor)
086: .getContext();
087:
088: executor.getContext().getLabelPainter()
089: .disableLayer(
090: executor.getContext().getLayer().getID()
091: .toString());
092: if (context.getContexts().size() > 1)
093: executor.getContext().getRenderManager().refresh(layer,
094: (Envelope) null);
095: else
096: super .layerVisible(layer, msg);
097: }
098: }
099:
100: protected class ContextListener implements CompositeContextListener {
101:
102: public void notifyChanged(CompositeRenderContext context,
103: List<RenderContext> contexts, boolean added) {
104: if (added) {
105: for (RenderContext context2 : contexts) {
106: addLayerListener(context2);
107: }
108: } else {
109: for (RenderContext context2 : contexts) {
110: removeLayerListener(context2);
111: }
112: }
113: }
114: }
115:
116: protected static class MultiLayerRendererListener extends
117: RendererListener {
118: /**
119: * Construct <code>CompositeRendererListener</code>.
120: *
121: * @param executor
122: */
123: MultiLayerRendererListener(RenderExecutor executor) {
124: super (executor);
125: }
126:
127: /**
128: * @see net.refractions.udig.project.internal.render.impl.RenderExecutorAdapters.RendererListener#stateChanged(org.eclipse.emf.common.notify.Notification)
129: */
130: protected void stateChanged(Notification msg) {
131: super .stateChanged(msg);
132: }
133: }
134:
135: /**
136: * Construct <code>CompositeRendererExecutor</code>.
137: */
138: public RenderExecutorMultiLayer() {
139: renderJob = new RenderJob(this );
140: }
141:
142: String jobName;
143:
144: ContextListener listener = new ContextListener();
145:
146: /**
147: * @see net.refractions.udig.project.internal.render.impl.RenderExecutorImpl#getRenderJobName()
148: */
149: protected String getRenderJobName() {
150: if (jobName == null) {
151: synchronized (this ) {
152: if (jobName == null) {
153: StringBuffer buffer = new StringBuffer("["); //$NON-NLS-1$
154: CompositeRenderContext context = (CompositeRenderContext) getContext();
155: for (IRenderContext rc : context.getContexts()) {
156: buffer.append(rc.getLayer().getName());
157: buffer.append(","); //$NON-NLS-1$
158: }
159: buffer.replace(buffer.length() - 1,
160: buffer.length(), "]"); //$NON-NLS-1$
161: jobName = buffer.toString();
162: }
163: }
164: }
165: return jobName;
166: }
167:
168: /**
169: * @see net.refractions.udig.project.internal.render.impl.RenderExecutorImpl#setRenderer(net.refractions.udig.project.render.Renderer)
170: */
171: @SuppressWarnings("unchecked")
172: public void setRenderer(Renderer newRenderer) {
173: if (getContext() != null)
174: for (IRenderContext context : getContext().getContexts()) {
175: removeLayerListener(context);
176: }
177:
178: if (getContext() != null)
179: getContext().removeListener(listener);
180: setRendererInternal(newRenderer);
181: if (getContext() != null)
182: getContext().addListener(listener);
183: for (IRenderContext context : ((CompositeRenderContext) newRenderer
184: .getContext()).getContexts()) {
185: addLayerListener(context);
186: }
187: }
188:
189: protected void setRendererInternal(Renderer newRenderer) {
190: super .setRenderer(newRenderer);
191: }
192:
193: /**
194: * @see net.refractions.udig.project.internal.render.impl.RenderExecutorImpl#getContext()
195: */
196: public CompositeRenderContext getContext() {
197: return (CompositeRenderContext) super .getContext();
198: }
199:
200: protected void resyncState(Renderer renderer) {
201: // if (getContext() == null)
202: // return;
203: // List<IRenderContext> contexts = getContext().getContexts();
204: // synchronized (contexts) {
205: // for( IRenderContext context : contexts ) {
206: // setLayerState(context, renderer.getState());
207: // }
208: // }
209:
210: }
211:
212: /**
213: * @see net.refractions.udig.project.internal.render.impl.RendererImpl#getInfo(Point, Layer)
214: * public InfoList getInfo(Point screenLocation) throws IOException { return
215: * renderer.getInfo(screenLocation); }
216: */
217:
218: protected LayerListener getLayerListener() {
219: return new MultiLayerRendererLayerListener(this );
220: }
221:
222: protected RendererListener getRendererListener() {
223: return new MultiLayerRendererListener(this );
224: }
225:
226: /**
227: * @see net.refractions.udig.project.internal.render.impl.RenderExecutorImpl#visit(net.refractions.udig.project.render.ExecutorVisitor)
228: */
229: public void visit(ExecutorVisitor visitor) {
230: visitor.visit(this );
231: }
232:
233: @Override
234: public String toString() {
235: return super .toString();
236: }
237:
238: @Override
239: public void dispose() {
240:
241: for (Layer layer : getContext().getMapInternal()
242: .getLayersInternal()) {
243: layer.eAdapters().remove(listener);
244: }
245: super.dispose();
246: }
247: }
|