001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * JUMP is Copyright (C) 2003 Vivid Solutions
006: *
007: * This program implements extensions to JUMP and is
008: * Copyright (C) 2004 Integrated Systems Analysts, Inc.
009: *
010: * This program is free software; you can redistribute it and/or
011: * modify it under the terms of the GNU General Public License
012: * as published by the Free Software Foundation; either version 2
013: * of the License, or (at your option) any later version.
014: *
015: * This program is distributed in the hope that it will be useful,
016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018: * GNU General Public License for more details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with this program; if not, write to the Free Software
022: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
023: *
024: * For more information, contact:
025: *
026: * Integrated Systems Analysts, Inc.
027: * 630C Anchors St., Suite 101
028: * Fort Walton Beach, Florida
029: * USA
030: *
031: * (850)862-7321
032: * www.ashs.isa.com
033: */
034:
035: package org.openjump.core.ui.plugin.layer;
036:
037: import java.util.Collection;
038: import java.util.Iterator;
039:
040: import javax.swing.JPopupMenu;
041:
042: import com.vividsolutions.jump.I18N;
043: import com.vividsolutions.jump.task.TaskMonitor;
044: import com.vividsolutions.jump.workbench.WorkbenchContext;
045: import com.vividsolutions.jump.workbench.model.Layer;
046: import com.vividsolutions.jump.workbench.model.Layerable;
047: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
048: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
049: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
050: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
051: import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller;
052:
053: public class ToggleVisiblityPlugIn extends AbstractPlugIn {
054: private final static String toggleVisibility = I18N
055: .get("org.openjump.core.ui.plugin.layer.ToggleVisiblityPlugIn.Toggle-Visibility");
056: private final static String errorSeeOutputWindow = I18N
057: .get("org.openjump.core.ui.plugin.layer.ToggleVisiblityPlugIn.Error-See-Output-Window");
058: private final static String layerName = I18N
059: .get("org.openjump.core.ui.plugin.mousemenu.SaveDatasetsPlugIn.Layer-Name");
060:
061: public void initialize(PlugInContext context) throws Exception {
062: WorkbenchContext workbenchContext = context
063: .getWorkbenchContext();
064: FeatureInstaller featureInstaller = new FeatureInstaller(
065: workbenchContext);
066: JPopupMenu layerNamePopupMenu = workbenchContext.getWorkbench()
067: .getFrame().getLayerNamePopupMenu();
068: featureInstaller.addPopupMenuItem(layerNamePopupMenu, this ,
069: toggleVisibility, false, null, ToggleVisiblityPlugIn
070: .createEnableCheck(workbenchContext));
071:
072: JPopupMenu wmsLayerNamePopupMenu = workbenchContext
073: .getWorkbench().getFrame().getWMSLayerNamePopupMenu();
074: featureInstaller.addPopupMenuItem(wmsLayerNamePopupMenu, this ,
075: toggleVisibility, false, null, ToggleVisiblityPlugIn
076: .createEnableCheck2(workbenchContext));
077:
078: }
079:
080: public boolean execute(PlugInContext context) throws Exception {
081: try {
082: Collection layerCollection = (Collection) context
083: .getWorkbenchContext().getLayerNamePanel()
084: .selectedNodes(Layerable.class);
085: boolean firingEvents = context.getLayerManager()
086: .isFiringEvents();
087: context.getLayerManager().setFiringEvents(false);
088: try {
089: for (Iterator j = layerCollection.iterator(); j
090: .hasNext();) {
091: Layerable layer = (Layerable) j.next();
092: // monitor.report(layerName+": " + layer.getName());
093: layer.setVisible(!layer.isVisible());
094: }
095: } finally {
096: context.getLayerManager().setFiringEvents(firingEvents);
097: context.getLayerViewPanel().repaint();
098: context.getWorkbenchFrame().repaint();
099: }
100: } catch (Exception e) {
101: context.getWorkbenchFrame().warnUser(errorSeeOutputWindow);
102: context.getWorkbenchFrame().getOutputFrame()
103: .createNewDocument();
104: context.getWorkbenchFrame().getOutputFrame().addText(
105: "ToggleVisiblityPlugIn Exception:" + e.toString());
106: return false;
107: }
108: return true;
109: }
110:
111: public static MultiEnableCheck createEnableCheck(
112: WorkbenchContext workbenchContext) {
113: EnableCheckFactory checkFactory = new EnableCheckFactory(
114: workbenchContext);
115: return new MultiEnableCheck()
116: .add(
117: checkFactory
118: .createWindowWithSelectionManagerMustBeActiveCheck())
119: .add(
120: checkFactory
121: .createAtLeastNLayersMustBeSelectedCheck(1));
122: }
123:
124: public static MultiEnableCheck createEnableCheck2(
125: WorkbenchContext workbenchContext) {
126: EnableCheckFactory checkFactory = new EnableCheckFactory(
127: workbenchContext);
128: return new MultiEnableCheck()
129: .add(
130: checkFactory
131: .createWindowWithSelectionManagerMustBeActiveCheck())
132: .add(
133: checkFactory
134: .createAtLeastNLayerablesMustBeSelectedCheck(
135: 1, Layerable.class));
136: }
137: }
|