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.plugin.qa;
033:
034: import java.awt.Color;
035: import javax.swing.*;
036:
037: import com.vividsolutions.jump.I18N;
038: import com.vividsolutions.jump.qa.diff.*;
039: import com.vividsolutions.jump.feature.*;
040: import com.vividsolutions.jump.workbench.*;
041: import com.vividsolutions.jump.workbench.model.*;
042: import com.vividsolutions.jump.workbench.plugin.*;
043: import com.vividsolutions.jump.workbench.ui.*;
044: import com.vividsolutions.jump.workbench.ui.plugin.*;
045: import com.vividsolutions.jump.task.*;
046:
047: public class DiffSegmentsPlugIn extends ThreadedBasePlugIn {
048:
049: private String sLayer = I18N
050: .get("jump.plugin.qa.DiffGeometryPlugIn.Layer");
051: private String LAYER1 = sLayer + " 1";
052: private String LAYER2 = sLayer + " 2";
053: private String USE_TOLERANCE = I18N
054: .get("jump.plugin.qa.DiffSegmentsPlugIn.Use-Distance-Tolerance");
055: private String DISTANCE_TOL = I18N
056: .get("jump.plugin.qa.DiffGeometryPlugIn.Distance-Tolerance");
057:
058: private String sSegmentDiffs = I18N
059: .get("jump.plugin.qa.DiffGeometryPlugIn.Segment-Diffs");
060: private String sUnmSegm = I18N
061: .get("jump.plugin.qa.DiffSegmentsPlugIn.Unmatched-Segments-in-Layer");
062: // further strings are below
063:
064: private Layer layer1, layer2;
065: private boolean useTolerance = false;
066: private double distanceTolerance = 0.0;
067:
068: public DiffSegmentsPlugIn() {
069: }
070:
071: /*
072: public void initialize(PlugInContext context) throws Exception {
073: context.getFeatureInstaller().addMainMenuItem(this, new String[] {"QA"},
074: getName() + "...", false, null, new MultiEnableCheck()
075: .add(context.getCheckFactory().createWindowWithLayerViewPanelMustBeActiveCheck())
076: .add(context.getCheckFactory().createAtLeastNLayersMustExistCheck(2)));
077: }
078: */
079:
080: public String getName() {
081: return I18N
082: .get("jump.plugin.qa.DiffSegmentsPlugIn.Calculate-Segment-Differences");
083: }
084:
085: public boolean execute(PlugInContext context) throws Exception {
086:
087: //[sstein, 16.07.2006] set again to obtain correct language
088: sLayer = I18N.get("jump.plugin.qa.DiffGeometryPlugIn.Layer");
089: LAYER1 = sLayer + " 1";
090: LAYER2 = sLayer + " 2";
091: USE_TOLERANCE = I18N
092: .get("jump.plugin.qa.DiffSegmentsPlugIn.Use-Distance-Tolerance");
093: DISTANCE_TOL = I18N
094: .get("jump.plugin.qa.DiffGeometryPlugIn.Distance-Tolerance");
095:
096: sSegmentDiffs = I18N
097: .get("jump.plugin.qa.DiffGeometryPlugIn.Segment-Diffs");
098: sUnmSegm = I18N
099: .get("jump.plugin.qa.DiffSegmentsPlugIn.Unmatched-Segments-in-Layer");
100:
101: MultiInputDialog dialog = new MultiInputDialog(
102: context.getWorkbenchFrame(),
103: I18N
104: .get("jump.plugin.qa.DiffSegmentsPlugIn.Diff-Segments"),
105: true);
106: setDialogValues(dialog, context);
107: GUIUtil.centreOnWindow(dialog);
108: dialog.setVisible(true);
109: if (!dialog.wasOKPressed()) {
110: return false;
111: }
112: getDialogValues(dialog);
113: return true;
114: }
115:
116: public void run(TaskMonitor monitor, PlugInContext context)
117: throws Exception {
118: FeatureCollection[] diffFC;
119: if (!useTolerance) {
120: DiffSegments diff = new DiffSegments(monitor);
121: diff.setSegments(0, layer1.getFeatureCollectionWrapper());
122: diff.setSegments(1, layer2.getFeatureCollectionWrapper());
123:
124: diffFC = new FeatureCollection[2];
125: diffFC[0] = diff.computeDiffEdges(0);
126: diffFC[1] = diff.computeDiffEdges(1);
127: } else {
128: DiffSegmentsWithTolerance diff = new DiffSegmentsWithTolerance(
129: layer1.getFeatureCollectionWrapper(), layer2
130: .getFeatureCollectionWrapper(),
131: distanceTolerance);
132:
133: diffFC = diff.diff();
134: }
135: createLayers(context, diffFC);
136: createOutput(context, diffFC);
137: }
138:
139: private void createLayers(PlugInContext context,
140: FeatureCollection[] diffFC) {
141: Layer lyr = context.addLayer(StandardCategoryNames.QA,
142: sSegmentDiffs + " - " + layer1.getName(), diffFC[0]);
143: LayerStyleUtil.setLinearStyle(lyr, Color.red, 2, 4);
144: lyr.fireAppearanceChanged();
145:
146: Layer lyr2 = context.addLayer(StandardCategoryNames.QA,
147: sSegmentDiffs + " - " + layer2.getName(), diffFC[1]);
148: LayerStyleUtil.setLinearStyle(lyr2, Color.blue, 2, 4);
149: lyr2.fireAppearanceChanged();
150: }
151:
152: private void createOutput(PlugInContext context,
153: FeatureCollection[] diffFC) {
154: context.getOutputFrame().createNewDocument();
155: context
156: .getOutputFrame()
157: .addHeader(
158: 1,
159: I18N
160: .get("jump.plugin.qa.DiffSegmentsPlugIn.Diff-Segments"));
161: context.getOutputFrame().addField(sLayer + " 1: ",
162: layer1.getName());
163: context.getOutputFrame().addField(sLayer + " 2: ",
164: layer2.getName());
165: context.getOutputFrame().addText(" ");
166: if (useTolerance) {
167: context.getOutputFrame().addField(DISTANCE_TOL + ": ",
168: "" + distanceTolerance);
169: }
170: context.getOutputFrame().addField("# " + sUnmSegm + " 1: ",
171: "" + diffFC[0].size());
172: context.getOutputFrame().addField("# " + sUnmSegm + " 2: ",
173: "" + diffFC[1].size());
174: }
175:
176: private void setDialogValues(MultiInputDialog dialog,
177: PlugInContext context) {
178: dialog.setSideBarImage(new ImageIcon(getClass().getResource(
179: "DiffSegments.png")));
180: dialog
181: .setSideBarDescription(I18N
182: .get("jump.plugin.qa.DiffSegmentsPlugIn.Finds-line-segments-which-occur-in-Layer-1-or-Layer-2-but-not-both"));
183: //Set initial layer values to the first and second layers in the layer list.
184: //In #initialize we've already checked that the number of layers >= 2. [Jon Aquino]
185: dialog.addLayerComboBox(LAYER1, context.getLayerManager()
186: .getLayer(0), context.getLayerManager());
187: dialog.addLayerComboBox(LAYER2, context.getLayerManager()
188: .getLayer(1), context.getLayerManager());
189: dialog
190: .addCheckBox(
191: USE_TOLERANCE,
192: useTolerance,
193: I18N
194: .get("jump.plugin.qa.DiffSegmentsPlugIn.Match-segments-if-all-points-are-within-a-Distance-Tolerance"));
195: dialog
196: .addDoubleField(
197: DISTANCE_TOL,
198: distanceTolerance,
199: 8,
200: I18N
201: .get("jump.plugin.qa.DiffSegmentsPlugIn.The-Distance-Tolerance-specifies-how-close-segments-must-be-to-match"));
202: }
203:
204: private void getDialogValues(MultiInputDialog dialog) {
205: layer1 = dialog.getLayer(LAYER1);
206: layer2 = dialog.getLayer(LAYER2);
207: useTolerance = dialog.getBoolean(USE_TOLERANCE);
208: distanceTolerance = dialog.getDouble(DISTANCE_TOL);
209: }
210:
211: }
|