📄 drawingtoollayer.java
字号:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/layer/DrawingToolLayer.java,v $// $RCSfile: DrawingToolLayer.java,v $// $Revision: 1.24.2.6 $// $Date: 2005/08/11 21:03:33 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer;import java.awt.Component;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.StreamCorruptedException;import java.net.URL;import java.util.Properties;import java.util.Vector;import javax.swing.AbstractAction;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JPanel;import com.bbn.openmap.I18n;import com.bbn.openmap.dataAccess.shape.EsriShapeExport;import com.bbn.openmap.event.MapMouseEvent;import com.bbn.openmap.event.MapMouseMode;import com.bbn.openmap.event.MapMouseSupport;import com.bbn.openmap.event.SelectMouseMode;import com.bbn.openmap.omGraphics.OMAction;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.omGraphics.event.MapMouseInterpreter;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.tools.drawing.DrawingTool;import com.bbn.openmap.tools.drawing.DrawingToolRequestor;import com.bbn.openmap.tools.drawing.OMDrawingTool;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.FileUtils;import com.bbn.openmap.util.PaletteHelper;import com.bbn.openmap.util.PropUtils;import com.bbn.openmap.util.propertyEditor.Inspector;/** * This layer can receive graphics from the OMDrawingToolLauncher, and * also sent it's graphics to the OMDrawingTool for editing. * <P> * * The projectionChanged() method is taken care of in the * OMGraphicHandlerLayer superclass. * <P> * * This class responds to all the properties that the * OMGraphicHandlerLayer repsonds to, including the mouseModes * property. If the mouseModes property isn't set, the * SelectMouseMode.modeID mode ID is set. When the MapMouseInterpreter * calls select(OMGraphic), the OMGraphic is passed to the * DrawingTool. This class also responds to the showHints property * (true by default), which dictates if tooltips and information * delegator text is displayed when the layer's contents are moused * over. * * <pre> * * # Properties for DrawingToolLayer: * drawingToolLayer.class=com.bbn.openmap.layer.DrawingToolLayer * * drawingToolLayer.prettyName=General Layer * * # optional flag to tell layer to display tooltip queues over it's OMGraphics * drawingToolLayer.showHints=true * * # optional flag to specify file to store and read OMGraphics. A Save button * # is available on the palette. If it's not specified and the Save button is * # chosen, the user will queried for this location. * drawingToolLayer.file=file to read OMGraphics from * * </pre> */public class DrawingToolLayer extends OMGraphicHandlerLayer implements DrawingToolRequestor { /** Get a handle on the DrawingTool. */ protected OMDrawingTool drawingTool; /** * A flag to provide a tooltip over OMGraphics to click to edit. */ protected boolean showHints = true; /** * A property that can control whether mouse events generate hints * over map objects (showHints). */ public final static String ShowHintsProperty = "showHints"; /** * A property to specify the file to use to read and save map * objects in (file). */ public final static String SerializedURLNameProperty = "file"; /** * The name of the file to read/save OMGraphics in. */ protected String fileName = null; protected boolean DTL_DEBUG = false; public DrawingToolLayer() { //setList(new OMGraphicList()); setAddToBeanContext(true); DTL_DEBUG = Debug.debugging("dtl"); } public void setProperties(String prefix, Properties props) { super.setProperties(prefix, props); String realPrefix = PropUtils.getScopedPropertyPrefix(prefix); showHints = PropUtils.booleanFromProperties(props, realPrefix + ShowHintsProperty, showHints); if (getMouseModeIDsForEvents() == null) { setMouseModeIDsForEvents(new String[] { SelectMouseMode.modeID }); } fileName = props.getProperty(realPrefix + SerializedURLNameProperty); } public Properties getProperties(Properties props) { props = super.getProperties(props); String prefix = PropUtils.getScopedPropertyPrefix(this); props.put(prefix + ShowHintsProperty, new Boolean(showHints).toString()); props.put(prefix + SerializedURLNameProperty, PropUtils.unnull(fileName)); return props; } public Properties getPropertyInfo(Properties props) { props = super.getPropertyInfo(props); String interString; interString = i18n.get(DrawingToolLayer.class, ShowHintsProperty, I18n.TOOLTIP, "Display tooltips over layer's map objects."); props.put(ShowHintsProperty, interString); props.put(ShowHintsProperty + ScopedEditorProperty, "com.bbn.openmap.util.propertyEditor.YesNoPropertyEditor"); interString = i18n.get(DrawingToolLayer.class, ShowHintsProperty, "Show Hints"); props.put(ShowHintsProperty + LabelEditorProperty, interString); interString = i18n.get(DrawingToolLayer.class, SerializedURLNameProperty, I18n.TOOLTIP, "File to use for reading and saving map objects."); props.put(SerializedURLNameProperty, interString); props.put(SerializedURLNameProperty + ScopedEditorProperty, "com.bbn.openmap.util.propertyEditor.FUPropertyEditor"); interString = i18n.get(DrawingToolLayer.class, ShowHintsProperty, "File Name for Saving"); props.put(SerializedURLNameProperty + LabelEditorProperty, interString); props.put(initPropertiesProperty, SerializedURLNameProperty + " " + ShowHintsProperty); return props; } public OMGraphicList prepare() { OMGraphicList list = getList(); Projection proj = getProjection(); if (list == null) { list = load(); } if (list != null && proj != null) { list.generate(proj); } return list; } public OMDrawingTool getDrawingTool() { return drawingTool; } public void setDrawingTool(OMDrawingTool dt) { drawingTool = dt; } /** * DrawingToolRequestor method. */ public void drawingComplete(OMGraphic omg, OMAction action) { if (DTL_DEBUG) { String cname = omg.getClass().getName(); int lastPeriod = cname.lastIndexOf('.'); if (lastPeriod != -1) { cname = cname.substring(lastPeriod + 1); } Debug.output("DrawingToolLayer: DrawingTool complete for " + cname + " > " + action); } // First thing, release the proxy MapMouseMode, if there is // one. releaseProxyMouseMode(); // GRP, assuming that selection is off. OMGraphicList omgl = new OMGraphicList(); omgl.add(omg); deselect(omgl); OMGraphicList list = getList(); if (list == null) { list = load(); setList(list); } if (list != null) { doAction(omg, action); repaint(); } else { Debug.error("Layer " + getName() + " received " + omg + " and " + action + " with no list ready"); } } /** * If the DrawingToolLayer is using a hidden OMDrawingTool, * release the proxy lock on the active MapMouseMode. */ public void releaseProxyMouseMode() { MapMouseMode pmmm = getProxyMouseMode(); OMDrawingTool dt = getDrawingTool(); if (pmmm != null && dt != null) { if (pmmm.isProxyFor(dt.getMouseMode())) { if (DTL_DEBUG) { Debug.output("DTL: releasing proxy on " + pmmm.getID()); } pmmm.releaseProxy(); setProxyMouseMode(null); fireRequestInfoLine(""); // hidden drawing tool put up // coordinates, clean up. } if (dt.isActivated()) { dt.deactivate(); } } } /** * Called by findAndInit(Iterator) so subclasses can find objects, * too. */ public void findAndInit(Object someObj) { if (someObj instanceof OMDrawingTool) { Debug.message("dtl", "DrawingToolLayer: found a drawing tool"); setDrawingTool((OMDrawingTool) someObj); } } /** * BeanContextMembershipListener method. Called when a new object * is removed from the BeanContext of this object. */ public void findAndUndo(Object someObj) { if (someObj instanceof DrawingTool && getDrawingTool() == someObj) { setDrawingTool(null); } } protected MapMouseMode proxyMMM = null; /** * Set the ProxyMouseMode for the internal drawing tool, if there * is one. Can be null. Used to reset the mouse mode when * drawing's complete. */ protected synchronized void setProxyMouseMode(MapMouseMode mmm) { proxyMMM = mmm; } /** * Get the ProxyMouseMode for the internal drawing tool, if there * is one. May be null. Used to reset the mouse mode when * drawing's complete. */ protected synchronized MapMouseMode getProxyMouseMode() { return proxyMMM; } /** * A method called from within different MapMouseListener methods * to check whether an OMGraphic *should* be edited if the * OMDrawingTool is able to edit it. Can be used by subclasses to * delineate between OMGraphics that are non-relocatable versus * those that can be moved. This method should work together with * the getToolTipForOMGraphic() method so that OMGraphics that * shouldn't be edited don't provide tooltips that suggest that * they can be. * <P> * * By default, this method always returns true because the * DrawingToolLayer always thinks the OMGraphic should be edited. */ public boolean shouldEdit(OMGraphic omgr) { return true; } JPanel box; JComboBox jcb; public Component getGUI() { if (box == null) { String interString = i18n.get(DrawingToolLayer.class, "QUERY_HEADER", "What would you like to do?"); box = PaletteHelper.createVerticalPanel(interString); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); box.setLayout(gridbag); jcb = new JComboBox(getActions());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -