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.ConstrainedMoveVertexTool;
040:
041: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
042: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
043: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
044: import com.vividsolutions.jump.workbench.ui.cursortool.QuasimodeTool;
045: import com.vividsolutions.jump.workbench.ui.cursortool.editing.EditingPlugIn;
046: import com.vividsolutions.jump.workbench.ui.toolbox.ToolboxDialog;
047:
048: public class ConstrainedMoveVertexPlugIn extends AbstractPlugIn {
049: private boolean moveVertexButtonAdded = false;
050:
051: public void initialize(final PlugInContext context)
052: throws Exception {
053: //add a listener so that when the toolbox dialog opens the constrained tools will be added
054: //we can't just add the tools directly at this point since the toolbox isn't ready yet
055:
056: context.getWorkbenchContext().getWorkbench().getFrame()
057: .addComponentListener(new ComponentAdapter() {
058: public void componentShown(ComponentEvent e) {
059: final ToolboxDialog toolBox = ((EditingPlugIn) context
060: .getWorkbenchContext().getBlackboard()
061: .get(EditingPlugIn.KEY))
062: .getToolbox(context
063: .getWorkbenchContext());
064: toolBox
065: .addComponentListener(new ComponentAdapter() {
066:
067: public void componentShown(
068: ComponentEvent e) {
069: addButton(context);
070: }
071:
072: public void componentHidden(
073: ComponentEvent e) {
074: }
075: });
076: }
077: });
078: }
079:
080: public boolean execute(PlugInContext context) throws Exception {
081: return true;
082: }
083:
084: public void addButton(final PlugInContext context) {
085: if (!moveVertexButtonAdded) {
086: final ToolboxDialog toolbox = ((EditingPlugIn) context
087: .getWorkbenchContext().getBlackboard().get(
088: EditingPlugIn.KEY)).getToolbox(context
089: .getWorkbenchContext());
090: toolbox.addToolBar(); //to create a new row
091: QuasimodeTool quasimodeTool = new QuasimodeTool(
092: new ConstrainedMoveVertexTool(
093: new EnableCheckFactory(toolbox.getContext())));
094: quasimodeTool.add(new QuasimodeTool.ModifierKeySpec(true,
095: false, false), null);
096: quasimodeTool.add(new QuasimodeTool.ModifierKeySpec(true,
097: true, false), null);
098: toolbox.add(quasimodeTool, null);
099: toolbox.finishAddingComponents();
100: toolbox.validate();
101: moveVertexButtonAdded = true;
102: }
103: }
104: }
|