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