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) Stefan Steiniger.
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: * Stefan Steiniger
026: * perriger@gmx.de
027: */
028: /*****************************************************
029: * created: 20.05.2005
030: * last modified: 22.05.2005
031: *
032: * description:
033: * selects items within a cirlce of the actual selected layers
034: * and informs about the number of selected items<p>
035: * uses selectItemsByCircle class for user interaction and
036: * determination of selection
037: *
038: *****************************************************/package org.openjump.core.ui.plugin.edit;
039:
040: import org.openjump.core.ui.plugin.edit.helpclassesselection.SelectItemsByCircleTool;
041:
042: import com.vividsolutions.jts.geom.Coordinate;
043: import com.vividsolutions.jts.geom.Envelope;
044: import com.vividsolutions.jump.I18N;
045: import com.vividsolutions.jump.workbench.WorkbenchContext;
046: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
047: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
048: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
049: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
050: import com.vividsolutions.jump.workbench.ui.GUIUtil;
051: import com.vividsolutions.jump.workbench.ui.MenuNames;
052: import com.vividsolutions.jump.workbench.ui.MultiInputDialog;
053:
054: /**
055: * @description:
056: * selects items of the actual layer
057: * and informs about the number of selected items
058: *
059: * @author sstein
060: *
061: */
062: public class SelectItemsByCircleFromSelectedLayersPlugIn extends
063: AbstractPlugIn {
064:
065: private String T1 = "diameter";
066: private String sidebarstring = "";
067: private double diameter = 50;
068:
069: public void initialize(PlugInContext context) throws Exception {
070:
071: this .T1 = I18N
072: .get("org.openjump.core.ui.plugin.edit.SelectItemsByCirlceFromSelectedLayersPlugIn.cirlce-diameter")
073: + ":";
074: this .sidebarstring = I18N
075: .get("org.openjump.core.ui.plugin.edit.SelectItemsByCirlceFromSelectedLayersPlugIn.select-items-within-a-circle-from-currently-selected-layers");
076:
077: context
078: .getFeatureInstaller()
079: .addMainMenuItemWithJava14Fix(
080: this ,
081: new String[] { MenuNames.EDIT },
082: I18N
083: .get("org.openjump.core.ui.plugin.edit.SelectItemsByCirlceFromSelectedLayersPlugIn.select-items-by-cirlce-from-selected-layers")
084: + "{pos:7}",
085: false, //icon
086: null, //icon
087: createEnableCheck(context.getWorkbenchContext())); //enable check
088: }
089:
090: public static MultiEnableCheck createEnableCheck(
091: WorkbenchContext workbenchContext) {
092: EnableCheckFactory checkFactory = new EnableCheckFactory(
093: workbenchContext);
094: return new MultiEnableCheck().add(checkFactory
095: .createAtLeastNLayersMustExistCheck(1));
096: }
097:
098: public boolean makeDialogThings(PlugInContext context)
099: throws Exception {
100: this .reportNothingToUndoYet(context);
101: MultiInputDialog dialog = new MultiInputDialog(context
102: .getWorkbenchFrame(), getName(), true);
103: setDialogValues(dialog, context);
104: GUIUtil.centreOnWindow(dialog);
105: dialog.setVisible(true);
106: if (!dialog.wasOKPressed()) {
107: return false;
108: }
109: getDialogValues(dialog);
110: return true;
111: }
112:
113: private void setDialogValues(MultiInputDialog dialog,
114: PlugInContext context) {
115: dialog.setSideBarDescription(this .sidebarstring);
116: dialog.addDoubleField(T1, this .diameter, 7, T1);
117: }
118:
119: private void getDialogValues(MultiInputDialog dialog) {
120: this .diameter = dialog.getDouble(T1);
121:
122: }
123:
124: public boolean execute(PlugInContext context) throws Exception {
125: try {
126: this .makeDialogThings(context);
127: Envelope viewportEnvelope = context.getLayerViewPanel()
128: .getViewport().getEnvelopeInModelCoordinates();
129: double x = viewportEnvelope.getMinX()
130: + viewportEnvelope.getWidth() / 2;
131: double y = viewportEnvelope.getMinY()
132: + viewportEnvelope.getHeight() / 2;
133: Coordinate initCoords = new Coordinate(x, y);
134: SelectItemsByCircleTool sit = new SelectItemsByCircleTool(
135: context, this .diameter, initCoords);
136: context.getLayerViewPanel().setCurrentCursorTool(sit);
137:
138: //-- if an toolbar item should be added use the following?
139: /**
140: QuasimodeTool tool = new QuasimodeTool(sit).add(
141: new QuasimodeTool.ModifierKeySpec(true, false, false), null);
142: WorkbenchContext wbcontext = context.getWorkbenchContext();
143: wbcontext.getWorkbench().getFrame().getToolBar().addCursorTool(tool).getQuasimodeTool();
144: **/
145: } catch (Exception e) {
146: context.getWorkbenchFrame().warnUser(
147: "SelecItemsByCircleTool Exception:" + e.toString());
148: return false;
149: }
150:
151: System.gc();
152: return true;
153: }
154:
155: }
|