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.mousemenu;
035:
036: import java.util.Collection;
037:
038: import javax.swing.JComponent;
039: import javax.swing.JPopupMenu;
040:
041: import com.vividsolutions.jts.geom.Geometry;
042: import com.vividsolutions.jts.geom.GeometryCollection;
043: import com.vividsolutions.jts.geom.MultiLineString;
044: import com.vividsolutions.jts.geom.MultiPoint;
045: import com.vividsolutions.jts.geom.MultiPolygon;
046: import com.vividsolutions.jts.geom.Point;
047: import com.vividsolutions.jump.I18N;
048: import com.vividsolutions.jump.workbench.WorkbenchContext;
049: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
050: import com.vividsolutions.jump.workbench.plugin.EnableCheck;
051: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
052: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
053: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
054: import com.vividsolutions.jump.workbench.ui.LayerViewPanel;
055: import com.vividsolutions.jump.workbench.ui.SelectionManagerProxy;
056: import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller;
057:
058: public class EditSelectedSidePlugIn extends AbstractPlugIn {
059:
060: private final static String sEditSelectedSide = I18N
061: .get("org.openjump.core.ui.plugin.mousemenu.EditSelectedSidePlugIn.Edit-Selected-Side");
062: private final static String sPointsDoNotHaveSides = I18N
063: .get("org.openjump.core.ui.plugin.mousemenu.EditSelectedSidePlugIn.Points-do-not-have-sides");
064: private final static String sSelectOnlyOnePart = I18N
065: .get("org.openjump.core.ui.plugin.mousemenu.EditSelectedSidePlugIn.Select-only-one-part");
066:
067: public void initialize(PlugInContext context) throws Exception {
068: WorkbenchContext workbenchContext = context
069: .getWorkbenchContext();
070: FeatureInstaller featureInstaller = new FeatureInstaller(
071: workbenchContext);
072: JPopupMenu popupMenu = LayerViewPanel.popupMenu();
073: featureInstaller.addPopupMenuItem(popupMenu, this ,
074: sEditSelectedSide, false, null, //to do: add icon
075: this .createEnableCheck(workbenchContext));
076: }
077:
078: public boolean execute(final PlugInContext context)
079: throws Exception {
080: reportNothingToUndoYet(context);
081: EditSelectedSideDialog dialog = new EditSelectedSideDialog(
082: context, getName(), false);
083: dialog.setVisible(true);
084: return true;
085: }
086:
087: public EnableCheck noPointsMayBeSelectedCheck(
088: final WorkbenchContext workbenchContext) {
089: return new EnableCheck() {
090: public String check(JComponent component) {
091: Collection selectedItems = ((SelectionManagerProxy) workbenchContext
092: .getWorkbench().getFrame()
093: .getActiveInternalFrame())
094: .getSelectionManager().getSelectedItems();
095: Geometry selectedGeo = (Geometry) selectedItems
096: .iterator().next();
097: return (selectedGeo instanceof Point) ? sPointsDoNotHaveSides
098: : null;
099: }
100: };
101: }
102:
103: public EnableCheck noMultiShapesMayBeSelectedCheck(
104: final WorkbenchContext workbenchContext) {
105: return new EnableCheck() {
106: public String check(JComponent component) {
107: Collection selectedItems = ((SelectionManagerProxy) workbenchContext
108: .getWorkbench().getFrame()
109: .getActiveInternalFrame())
110: .getSelectionManager().getSelectedItems();
111: Geometry selectedGeo = (Geometry) selectedItems
112: .iterator().next();
113:
114: return (((selectedGeo instanceof MultiPoint)
115: || (selectedGeo instanceof MultiLineString)
116: || (selectedGeo instanceof MultiPolygon) || (selectedGeo instanceof GeometryCollection))) ? (sSelectOnlyOnePart)
117: : null;
118: }
119: };
120: }
121:
122: public MultiEnableCheck createEnableCheck(
123: final WorkbenchContext workbenchContext) {
124: EnableCheckFactory checkFactory = new EnableCheckFactory(
125: workbenchContext);
126: return new MultiEnableCheck()
127: .add(
128: checkFactory
129: .createWindowWithLayerViewPanelMustBeActiveCheck())
130: .add(
131: checkFactory
132: .createExactlyNItemsMustBeSelectedCheck(1))
133: .add(noPointsMayBeSelectedCheck(workbenchContext))
134: .add(noMultiShapesMayBeSelectedCheck(workbenchContext))
135: .add(
136: checkFactory
137: .createSelectedItemsLayersMustBeEditableCheck());
138: }
139: }
|