001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package net.refractions.udig.project.ui.internal.actions;
016:
017: import net.refractions.udig.project.EditManagerEvent;
018: import net.refractions.udig.project.IEditManagerListener;
019: import net.refractions.udig.project.IMap;
020: import net.refractions.udig.project.internal.Map;
021: import net.refractions.udig.project.internal.render.RenderManager;
022: import net.refractions.udig.project.internal.render.impl.CompositeRendererImpl;
023: import net.refractions.udig.project.internal.render.impl.RenderExecutorComposite;
024: import net.refractions.udig.project.internal.render.impl.RenderExecutorImpl;
025: import net.refractions.udig.project.render.IRenderer;
026: import net.refractions.udig.project.render.RenderException;
027: import net.refractions.udig.project.ui.ApplicationGIS;
028: import net.refractions.udig.project.ui.internal.ProjectUIPlugin;
029: import net.refractions.udig.ui.PlatformGIS;
030:
031: import org.eclipse.jface.action.IAction;
032: import org.eclipse.jface.viewers.ISelection;
033: import org.eclipse.swt.widgets.Event;
034: import org.eclipse.ui.IViewActionDelegate;
035: import org.eclipse.ui.IViewPart;
036: import org.eclipse.ui.IWorkbenchWindow;
037: import org.eclipse.ui.IWorkbenchWindowActionDelegate;
038: import org.eclipse.ui.actions.ActionDelegate;
039:
040: /**
041: * Turns on/off the Mylar effect
042: *
043: * @author Jesse
044: * @since 1.0.0
045: */
046: public class MylarAction extends ActionDelegate implements
047: IViewActionDelegate, IWorkbenchWindowActionDelegate {
048:
049: public static final String KEY = "MYLAR"; //$NON-NLS-1$
050:
051: IEditManagerListener selectedLayerListener = new IEditManagerListener() {
052:
053: public void changed(EditManagerEvent event) {
054: IMap map = event.getSource().getMap();
055: if (map != currentMap) {
056: map.getEditManager().removeListener(this );
057: }
058: if (event.getOldValue() != event.getNewValue()) {
059: RenderManager renderManager = (RenderManager) map
060: .getRenderManager();
061: RenderExecutorComposite compositeRendererImpl = ((RenderExecutorComposite) renderManager
062: .getRenderExecutor());
063: compositeRendererImpl.refresh();
064: // compositeRendererImpl.setState(IRenderer.DONE);
065: }
066: }
067:
068: };
069: private Map currentMap;
070:
071: @Override
072: public void runWithEvent(IAction action, Event event) {
073: currentMap = (Map) ApplicationGIS.getActiveMap();
074: if (currentMap == null)
075: return;
076: Boolean temp = (Boolean) currentMap.getBlackboard().get(KEY);
077: boolean currentStatus = temp == null ? false : temp;
078: if (!currentStatus) {
079: currentMap.getEditManager().addListener(
080: selectedLayerListener);
081: } else {
082: currentMap.getEditManager().removeListener(
083: selectedLayerListener);
084: }
085: currentMap.getBlackboard().put(KEY, !currentStatus);
086: action.setChecked(!currentStatus);
087: try {
088: CompositeRendererImpl compositeRendererImpl = ((CompositeRendererImpl) currentMap
089: .getRenderManagerInternal().getRenderExecutor()
090: .getRenderer());
091: compositeRendererImpl.refreshImage();
092: compositeRendererImpl.setState(IRenderer.DONE);
093:
094: } catch (RenderException e) {
095: ProjectUIPlugin.log("", e); //$NON-NLS-1$
096: }
097: }
098:
099: public void init(IWorkbenchWindow window) {
100: }
101:
102: @Override
103: public void selectionChanged(IAction action, ISelection selection) {
104: currentMap = (Map) ApplicationGIS.getActiveMap();
105: if (currentMap == null)
106: return;
107: Boolean temp = (Boolean) currentMap.getBlackboard().get(KEY);
108:
109: action.setChecked(temp == null ? false : temp);
110:
111: }
112:
113: public void init(IViewPart view) {
114: }
115:
116: }
|