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.DrawConstrainedPolygonTool;
040: import org.openjump.core.ui.plugin.edittoolbox.tab.ConstraintsOptionsPanel;
041:
042: import com.vividsolutions.jump.I18N;
043: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
044: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
045: import com.vividsolutions.jump.workbench.ui.LayerNamePanelProxy;
046: import com.vividsolutions.jump.workbench.ui.OptionsDialog;
047: import com.vividsolutions.jump.workbench.ui.cursortool.CursorTool;
048: import com.vividsolutions.jump.workbench.ui.cursortool.QuasimodeTool;
049: import com.vividsolutions.jump.workbench.ui.cursortool.editing.EditingPlugIn;
050: import com.vividsolutions.jump.workbench.ui.toolbox.ToolboxDialog;
051: import com.vividsolutions.jump.workbench.ui.zoom.PanTool;
052: import com.vividsolutions.jump.workbench.ui.zoom.ZoomTool;
053:
054: public class DrawConstrainedPolygonPlugIn extends AbstractPlugIn {
055: private boolean polygonButtonAdded = false;
056:
057: final static String constraints = I18N
058: .get("org.openjump.core.ui.plugin.edittoolbox.DrawConstrainedPolygonPlugIn.Constraints");
059: final static String errorSeeOutputWindow = I18N
060: .get("org.openjump.core.ui.plugin.edittoolbox.DrawConstrainedPolygonPlugIn.Error-See-Output-Window");
061:
062: public void initialize(final PlugInContext context)
063: throws Exception {
064: OptionsDialog.instance(
065: context.getWorkbenchContext().getWorkbench()).addTab(
066: constraints,
067: new ConstraintsOptionsPanel(context
068: .getWorkbenchContext()));
069: //add a listener so that when the toolbox dialog opens the constrained tools will be added
070: //we can't just add the tools directly at this point since the toolbox isn't ready yet
071:
072: context.getWorkbenchContext().getWorkbench().getFrame()
073: .addComponentListener(new ComponentAdapter() {
074: public void componentShown(ComponentEvent e) {
075: final ToolboxDialog toolBox = ((EditingPlugIn) context
076: .getWorkbenchContext().getBlackboard()
077: .get(EditingPlugIn.KEY))
078: .getToolbox(context
079: .getWorkbenchContext());
080: toolBox
081: .addComponentListener(new ComponentAdapter() {
082:
083: public void componentShown(
084: ComponentEvent e) {
085: addButton(context);
086: }
087:
088: public void componentHidden(
089: ComponentEvent e) {
090: }
091: });
092: }
093: });
094: }
095:
096: public boolean execute(PlugInContext context) throws Exception {
097: try {
098: CursorTool polyTool = DrawConstrainedPolygonTool
099: .create((LayerNamePanelProxy) context
100: .getActiveInternalFrame());
101: context.getLayerViewPanel().setCurrentCursorTool(polyTool);
102: return true;
103: } catch (Exception e) {
104: context.getWorkbenchFrame().warnUser(errorSeeOutputWindow);
105: context.getWorkbenchFrame().getOutputFrame()
106: .createNewDocument();
107: context.getWorkbenchFrame().getOutputFrame().addText(
108: "DrawConstrainedPolygonPlugIn Exception:"
109: + e.toString());
110: return false;
111: }
112: }
113:
114: public void addButton(final PlugInContext context) {
115: if (!polygonButtonAdded) {
116: final ToolboxDialog toolbox = ((EditingPlugIn) context
117: .getWorkbenchContext().getBlackboard().get(
118: EditingPlugIn.KEY)).getToolbox(context
119: .getWorkbenchContext());
120: toolbox.addToolBar();
121: QuasimodeTool quasimodeTool = new QuasimodeTool(
122: DrawConstrainedPolygonTool.create(toolbox
123: .getContext()));
124: quasimodeTool.add(new QuasimodeTool.ModifierKeySpec(true,
125: false, false), null);
126: quasimodeTool.add(new QuasimodeTool.ModifierKeySpec(true,
127: true, false), null);
128: quasimodeTool.add(new QuasimodeTool.ModifierKeySpec(false,
129: false, true), new ZoomTool());
130: quasimodeTool.add(new QuasimodeTool.ModifierKeySpec(false,
131: true, true), new PanTool());
132: toolbox.add(quasimodeTool, null);
133: toolbox.finishAddingComponents();
134: toolbox.validate();
135: polygonButtonAdded = true;
136: }
137: }
138: }
|