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: package com.vividsolutions.jump.workbench.ui.plugin.test;
033:
034: import java.awt.Color;
035: import java.util.ArrayList;
036: import java.util.Iterator;
037: import java.util.List;
038: import com.vividsolutions.jts.geom.Envelope;
039: import com.vividsolutions.jump.feature.Feature;
040: import com.vividsolutions.jump.feature.FeatureCollection;
041: import com.vividsolutions.jump.feature.FeatureDatasetFactory;
042: import com.vividsolutions.jump.geom.GeometryMicroscope;
043: import com.vividsolutions.jump.workbench.model.Layer;
044: import com.vividsolutions.jump.workbench.model.StandardCategoryNames;
045: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
046: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
047: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
048: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
049:
050: public class MicroscopePlugIn extends AbstractPlugIn {
051: public MicroscopePlugIn() {
052: }
053:
054: public void initialize(PlugInContext context) throws Exception {
055: EnableCheckFactory checkFactory = new EnableCheckFactory(
056: context.getWorkbenchContext());
057: context
058: .getFeatureInstaller()
059: .addMainMenuItemWithJava14Fix(
060: this ,
061: new String[] { "Tools", "Test" },
062: getName(),
063: false,
064: null,
065: new MultiEnableCheck()
066: .add(
067: checkFactory
068: .createWindowWithLayerNamePanelMustBeActiveCheck())
069: .add(
070: checkFactory
071: .createExactlyNLayersMustBeSelectedCheck(1))
072: .add(
073: checkFactory
074: .createWindowWithLayerViewPanelMustBeActiveCheck())
075: .add(
076: checkFactory
077: .createFenceMustBeDrawnCheck()));
078: }
079:
080: public boolean execute(PlugInContext context) throws Exception {
081: FeatureCollection fc = context.getSelectedLayer(0)
082: .getFeatureCollectionWrapper();
083: Envelope fence = context.getLayerViewPanel().getFence()
084: .getEnvelopeInternal();
085: FeatureCollection magFC = magnify(fc, fence);
086: Layer lyr = context.addLayer(StandardCategoryNames.QA,
087: "Microscope", magFC);
088: lyr.getBasicStyle().setFillColor(Color.red);
089: lyr.getBasicStyle().setLineColor(Color.red);
090: lyr.getBasicStyle().setAlpha(100);
091: lyr.getVertexStyle().setEnabled(true);
092: lyr.fireAppearanceChanged();
093: return true;
094: }
095:
096: private FeatureCollection magnify(FeatureCollection fc, Envelope env) {
097: List geomList = new ArrayList();
098: for (Iterator i = fc.query(env).iterator(); i.hasNext();) {
099: Feature feature = (Feature) i.next();
100: geomList.add(feature.getGeometry().clone());
101: }
102: //double minSep = 5.0;
103: double minSep = env.getWidth() / 20; // kluge
104: GeometryMicroscope micro = new GeometryMicroscope(geomList,
105: env, minSep);
106: List result = micro.getAdjusted();
107: return FeatureDatasetFactory.createFromGeometry(result);
108: }
109: }
|