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: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.workbench.ui.zoom;
034:
035: import java.util.Arrays;
036: import java.util.Iterator;
037:
038: import javax.swing.JComponent;
039: import javax.swing.JMenuItem;
040:
041: import com.vividsolutions.jts.geom.Envelope;
042: import com.vividsolutions.jump.geom.EnvelopeUtil;
043: import com.vividsolutions.jump.util.StringUtil;
044: import com.vividsolutions.jump.workbench.WorkbenchContext;
045: import com.vividsolutions.jump.workbench.model.Layer;
046: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
047: import com.vividsolutions.jump.workbench.plugin.EnableCheck;
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:
052: public class ZoomToLayerPlugIn extends AbstractPlugIn {
053: public ZoomToLayerPlugIn() {
054: }
055:
056: public boolean execute(PlugInContext context) throws Exception {
057: reportNothingToUndoYet(context);
058: context.getLayerViewPanel().getViewport().zoom(
059: EnvelopeUtil.bufferByFraction(
060: envelopeOfSelectedLayers(context), 0.03));
061:
062: return true;
063: }
064:
065: private Envelope envelopeOfSelectedLayers(PlugInContext context) {
066: Envelope envelope = new Envelope();
067:
068: for (Iterator i = Arrays.asList(
069: context.getLayerNamePanel().getSelectedLayers())
070: .iterator(); i.hasNext();) {
071: Layer layer = (Layer) i.next();
072: envelope.expandToInclude(layer
073: .getFeatureCollectionWrapper().getEnvelope());
074: }
075:
076: return envelope;
077: }
078:
079: public MultiEnableCheck createEnableCheck(
080: final WorkbenchContext workbenchContext) {
081: EnableCheckFactory checkFactory = new EnableCheckFactory(
082: workbenchContext);
083:
084: return new MultiEnableCheck()
085: .add(
086: checkFactory
087: .createWindowWithLayerNamePanelMustBeActiveCheck())
088: .add(
089: checkFactory
090: .createAtLeastNLayersMustBeSelectedCheck(1))
091: .add(new EnableCheck() {
092: public String check(JComponent component) {
093: ((JMenuItem) component).setText(getName()
094: + StringUtil.s(workbenchContext
095: .getLayerNamePanel()
096: .getSelectedLayers().length));
097:
098: return null;
099: }
100: });
101: }
102: }
|