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: 03.11.2005
030: * last modified:
031: *
032: * description:
033: * draw a circle for a given radius and a specified
034: * number of vertices per circle quarter<p>
035: *
036: *****************************************************/package org.openjump.core.ui.plugin.edittoolbox;
037:
038: import java.awt.event.ComponentAdapter;
039: import java.awt.event.ComponentEvent;
040:
041: import org.openjump.core.ui.plugin.edittoolbox.cursortools.DrawCircleWithGivenRadiusTool;
042:
043: import com.vividsolutions.jump.workbench.WorkbenchContext;
044: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
045: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
046: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
047: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
048: import com.vividsolutions.jump.workbench.ui.GUIUtil;
049: import com.vividsolutions.jump.workbench.ui.LayerNamePanelProxy;
050: import com.vividsolutions.jump.workbench.ui.MultiInputDialog;
051: import com.vividsolutions.jump.workbench.ui.cursortool.CursorTool;
052: import com.vividsolutions.jump.workbench.ui.cursortool.QuasimodeTool;
053: import com.vividsolutions.jump.workbench.ui.cursortool.editing.EditingPlugIn;
054: import com.vividsolutions.jump.workbench.ui.toolbox.ToolboxDialog;
055:
056: /**
057: * @description:
058: * selects items of the actual layer
059: * and informs about the number of selected items
060: *
061: * @author sstein
062: *
063: */
064: public class DrawCircleWithGivenRadiusPlugIn extends AbstractPlugIn {
065:
066: private boolean circleButtonAdded = false;
067: private String T1 = "diameter";
068: private String T2 = "Points";
069: private String sidebarstring = "";
070: private double diameter = 50;
071: private int points = 8; //points per cirlce quarter
072:
073: public void initialize(final PlugInContext context)
074: throws Exception {
075:
076: //this.T1 = I18N.get("org.openjump.core.ui.plugin.edit.SelectItemsByCirlceFromSelectedLayersPlugIn.cirlce-diameter") + ":";
077: this .T1 = "Circle Diameter";
078: this .T2 = "Number of segments per circle quarter";
079: this .sidebarstring = "Draw a circle by specifiying the radius, the number of points per circle quarter and the center position by mouse click";
080: /**
081: context.getFeatureInstaller().addMainMenuItemWithJava14Fix(this,
082: new String[] {MenuNames.TOOLS, MenuNames.TOOLS_GENERATE},
083: "Draw Cirlce for Given Radius",
084: false, //icon
085: null, //icon
086: createEnableCheck(context.getWorkbenchContext())); //enable check
087: **/
088: //add a listener so that when the toolbox dialog opens the constrained tools will be added
089: //we can't just add the tools directly at this point since the toolbox isn't ready yet
090: context.getWorkbenchContext().getWorkbench().getFrame()
091: .addComponentListener(new ComponentAdapter() {
092: public void componentShown(ComponentEvent e) {
093: final ToolboxDialog toolBox = ((EditingPlugIn) context
094: .getWorkbenchContext().getBlackboard()
095: .get(EditingPlugIn.KEY))
096: .getToolbox(context
097: .getWorkbenchContext());
098: toolBox
099: .addComponentListener(new ComponentAdapter() {
100:
101: public void componentShown(
102: ComponentEvent e) {
103: addButton(context);
104: }
105:
106: public void componentHidden(
107: ComponentEvent e) {
108: }
109: });
110: }
111: });
112: }
113:
114: public static MultiEnableCheck createEnableCheck(
115: WorkbenchContext workbenchContext) {
116: EnableCheckFactory checkFactory = new EnableCheckFactory(
117: workbenchContext);
118: return new MultiEnableCheck().add(checkFactory
119: .createSelectedLayersMustBeEditableCheck());
120: }
121:
122: public boolean makeDialogThings(PlugInContext context)
123: throws Exception {
124: this .reportNothingToUndoYet(context);
125: MultiInputDialog dialog = new MultiInputDialog(context
126: .getWorkbenchFrame(), getName(), true);
127: setDialogValues(dialog, context);
128: GUIUtil.centreOnWindow(dialog);
129: dialog.setVisible(true);
130: if (!dialog.wasOKPressed()) {
131: return false;
132: }
133: getDialogValues(dialog);
134: return true;
135: }
136:
137: private void setDialogValues(MultiInputDialog dialog,
138: PlugInContext context) {
139: dialog.setSideBarDescription(this .sidebarstring);
140: dialog.addDoubleField(T1, this .diameter, 7, T1);
141: dialog.addIntegerField(T2, this .points, 8, T2);
142: }
143:
144: private void getDialogValues(MultiInputDialog dialog) {
145: this .diameter = dialog.getDouble(T1);
146: this .points = dialog.getInteger(T2);
147: }
148:
149: public boolean execute(PlugInContext context) throws Exception {
150: try {
151: /**
152: this.makeDialogThings(context);
153: Envelope viewportEnvelope = context.getLayerViewPanel().getViewport().getEnvelopeInModelCoordinates();
154: double x = viewportEnvelope.getMinX() + viewportEnvelope.getWidth()/2;
155: double y = viewportEnvelope.getMinY() + viewportEnvelope.getHeight()/2;
156: Coordinate initCoords = new Coordinate(x,y);
157: TestDrawCircleByRadiusTool circleTool = new TestDrawCircleByRadiusTool(context, Math.abs(this.diameter),
158: Math.abs(this.points), initCoords);
159:
160: context.getLayerViewPanel().setCurrentCursorTool(circleTool);
161: **/
162: CursorTool circleTool = DrawCircleWithGivenRadiusTool
163: .create((LayerNamePanelProxy) context
164: .getActiveInternalFrame());
165: context.getLayerViewPanel()
166: .setCurrentCursorTool(circleTool);
167:
168: //-- if an toolbar item should be added use the following?
169: /**
170: QuasimodeTool tool = new QuasimodeTool(sit).add(
171: new QuasimodeTool.ModifierKeySpec(true, false, false), null);
172: WorkbenchContext wbcontext = context.getWorkbenchContext();
173: wbcontext.getWorkbench().getFrame().getToolBar().addCursorTool(tool).getQuasimodeTool();
174: **/
175: } catch (Exception e) {
176: context.getWorkbenchFrame().warnUser(
177: "SelecItemsByCircleTool Exception:" + e.toString());
178: return false;
179: }
180:
181: System.gc();
182: return true;
183: }
184:
185: public void addButton(final PlugInContext pcontext) {
186: if (!circleButtonAdded) {
187: final ToolboxDialog toolbox = ((EditingPlugIn) pcontext
188: .getWorkbenchContext().getBlackboard().get(
189: EditingPlugIn.KEY)).getToolbox(pcontext
190: .getWorkbenchContext());
191: QuasimodeTool quasimodeTool = new QuasimodeTool(
192: DrawCircleWithGivenRadiusTool.create(toolbox
193: .getContext()));
194: quasimodeTool.add(new QuasimodeTool.ModifierKeySpec(true,
195: false, false), null);
196: quasimodeTool.add(new QuasimodeTool.ModifierKeySpec(true,
197: true, false), null);
198: toolbox.add(quasimodeTool, null);
199: toolbox.finishAddingComponents();
200: toolbox.validate();
201: circleButtonAdded = true;
202: }
203: }
204:
205: }
|