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) 2004 Integrated Systems Analysts, Inc.
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: *
026: * Integrated Systems Analysts, Inc.
027: * 630C Anchors St., Suite 101
028: * Fort Walton Beach, Florida
029: * USA
030: *
031: * (850)862-7321
032: */
033:
034: package org.openjump.core.ui.plugin.edittoolbox;
035:
036: import java.awt.event.ComponentAdapter;
037: import java.awt.event.ComponentEvent;
038:
039: import org.openjump.core.ui.plugin.edittoolbox.cursortools.DrawConstrainedCircleTool;
040:
041: import com.vividsolutions.jump.I18N;
042: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
043: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
044: import com.vividsolutions.jump.workbench.ui.LayerNamePanelProxy;
045: import com.vividsolutions.jump.workbench.ui.cursortool.CursorTool;
046: import com.vividsolutions.jump.workbench.ui.cursortool.QuasimodeTool;
047: import com.vividsolutions.jump.workbench.ui.cursortool.editing.EditingPlugIn;
048: import com.vividsolutions.jump.workbench.ui.toolbox.ToolboxDialog;
049:
050: public class DrawConstrainedCirclePlugIn extends AbstractPlugIn {
051: private boolean circleButtonAdded = false;
052: final static String errorSeeOutputWindow = I18N
053: .get("org.openjump.core.ui.plugin.edittoolbox.DrawConstrainedCirclePlugIn.Error-See-Output-Window");
054:
055: public void initialize(final PlugInContext context)
056: throws Exception {
057: //add a listener so that when the toolbox dialog opens the constrained tools will be added
058: //we can't just add the tools directly at this point since the toolbox isn't ready yet
059:
060: context.getWorkbenchContext().getWorkbench().getFrame()
061: .addComponentListener(new ComponentAdapter() {
062: public void componentShown(ComponentEvent e) {
063: final ToolboxDialog toolBox = ((EditingPlugIn) context
064: .getWorkbenchContext().getBlackboard()
065: .get(EditingPlugIn.KEY))
066: .getToolbox(context
067: .getWorkbenchContext());
068: toolBox
069: .addComponentListener(new ComponentAdapter() {
070:
071: public void componentShown(
072: ComponentEvent e) {
073: addButton(context);
074: }
075:
076: public void componentHidden(
077: ComponentEvent e) {
078: }
079: });
080: }
081: });
082: }
083:
084: public boolean execute(PlugInContext context) throws Exception {
085: try {
086: CursorTool circleTool = DrawConstrainedCircleTool
087: .create((LayerNamePanelProxy) context
088: .getActiveInternalFrame());
089: context.getLayerViewPanel()
090: .setCurrentCursorTool(circleTool);
091: return true;
092: } catch (Exception e) {
093: context.getWorkbenchFrame().warnUser(errorSeeOutputWindow);
094: context.getWorkbenchFrame().getOutputFrame()
095: .createNewDocument();
096: context.getWorkbenchFrame().getOutputFrame().addText(
097: "DrawConstrainedCircleTool Exception:"
098: + e.toString());
099: return false;
100: }
101: }
102:
103: public void addButton(final PlugInContext context) {
104: if (!circleButtonAdded) {
105: final ToolboxDialog toolbox = ((EditingPlugIn) context
106: .getWorkbenchContext().getBlackboard().get(
107: EditingPlugIn.KEY)).getToolbox(context
108: .getWorkbenchContext());
109: QuasimodeTool quasimodeTool = new QuasimodeTool(
110: DrawConstrainedCircleTool.create(toolbox
111: .getContext()));
112: quasimodeTool.add(new QuasimodeTool.ModifierKeySpec(true,
113: false, false), null);
114: quasimodeTool.add(new QuasimodeTool.ModifierKeySpec(true,
115: true, false), null);
116: toolbox.add(quasimodeTool, null);
117: toolbox.finishAddingComponents();
118: toolbox.validate();
119: circleButtonAdded = true;
120: }
121: }
122: }
|