📄 basicgeometry.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/omGraphics/geom/BasicGeometry.java,v $// $RCSfile: BasicGeometry.java,v $// $Revision: 1.8.2.8 $// $Date: 2005/08/11 21:03:34 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.omGraphics.geom;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Shape;import java.awt.geom.FlatteningPathIterator;import java.awt.geom.GeneralPath;import java.awt.geom.Line2D;import java.awt.geom.PathIterator;import java.io.Serializable;import java.util.Hashtable;import java.util.Map;import com.bbn.openmap.omGraphics.OMGeometry;import com.bbn.openmap.omGraphics.OMGraphicConstants;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;/** * Base class implementation of OpenMap OMGeometry, the super class * for all OMGraphics. * <p> * * The geometry classes are intended to pull the object location data * out of the OMGraphics. If you have a bunch of OMGraphics that are * all rendered with common attributes, you can create a bunch of * OMGeometry objects to plavce in a OMGeometryList that will render * them all alike. * <p> * * The BasicGeometry can hold attributes. Traditionally, there has * been an appObject (Application Object) that could be set in the * OMGeometry/OMGraphic to maintain a pointer for additional * infomration about the shape. This has been modified so that an * attribute Map can be maintained for the BasicGeometry to let it * hold on to a bunch of organized attributes. To maintain backward * compatibility, the setAppObject() and getAppObject() methods have * been modified to manage a java.util.Map along with any Objects * stored in the appObject. Using the setAppObject() and * getAppObject() methods in conjunction with other attributes will * cause that object to be stored in the attribute Map under the * APP_OBJECT_KEY Map key. * * @see PolygonGeometry * @see PolylineGeometry * @see com.bbn.openmap.omGraphics.OMGeometryList * @see Projection */public abstract class BasicGeometry implements OMGeometry, Serializable, OMGraphicConstants { /** * The lineType describes the way a line will be drawn between * points. LINETYPE_STRAIGHT will mean the line is drawn straight * between the pixels of the endpoints of the line, across the * window. LINETYPE_GREATCIRCLE means the line will be drawn on * the window representing the shortest line along the land. * LINETYPE_RHUMB means a line will be drawn along a constant * bearing between the two points. */ protected int lineType = LINETYPE_UNKNOWN; /** Flag to indicate that the object needs to be reprojected. */ protected boolean needToRegenerate = true; /** * Space for an application to associate geometry with an * application object. This object can contain attribute * information about the geometry. * * @see #setAppObject * @see #getAppObject */ protected Object appObject; /** * A flag to render this geometry visible. */ protected boolean visible = true; /** * The Java 2D containing the Shape of the Graphic. There may be * several paths appended to each other, in case the graphic wraps * around the earth, and we need to show the other edge of the * graphic on the other side of the earth. */ protected transient GeneralPath shape = null; protected static final String APP_OBJECT_KEY = "app_object_key"; protected static final String ATT_MAP_KEY = "att_map_key"; ////////////////////////////////////////////////////////// /** * Set the line type for the graphic, which will affect how the * lines will be drawn. See the definition of the lineType * parameter. Accepts LINETYPE_RHUMB, LINETYPE_STRAIGHT and * LINETYPE_GREATCIRCLE. Any weird values get set to * LINETYPE_STRAIGHT. * * @param value the line type of the graphic. */ public void setLineType(int value) { if (lineType == value) return; setNeedToRegenerate(true); // flag dirty lineType = value; } /** * Return the line type. * * @return the linetype - LINETYPE_RHUMB, LINETYPE_STRAIGHT, * LINETYPE_GREATCIRCLE or LINETYPE_UNKNOWN. */ public int getLineType() { return lineType; } /** * Return the render type. * * @return the rendertype of the object - RENDERTYPE_LATLON, * RENDERTYPE_XY, RENDERTYPE_OFFSET and * RENDERTYPE_UNKNOWN. */ public abstract int getRenderType(); /** * Sets the regenerate flag for the graphic. This flag is used to * determine if extra work needs to be done to prepare the object * for rendering. * * @param value boolean */ public void setNeedToRegenerate(boolean value) { needToRegenerate = value; if (value == true) { shape = null; } } /** * Return the regeneration status. * * @return boolean */ public boolean getNeedToRegenerate() { return needToRegenerate; } /** * Set the visibility variable. NOTE: <br> * This is checked by the OMGeometryList when it iterates through * its list for render and gesturing. It is not checked by the * internal OMGeometry methods, although maybe it should be... * * @param visible boolean */ public void setVisible(boolean visible) { this.visible = visible; } /** * Get the visibility variable. * * @return boolean */ public boolean isVisible() { return visible; } /** * Let the geometry object know it's selected. No action mandated. */ public void select() {} /** * Let the geometry object know it's deselected. No action * mandated. */ public void deselect() {} /** * Holds an application specific object for later access. This can * be used to associate an application object with an OMGeometry * for later retrieval. For instance, when the graphic is clicked * on, the application gets the OMGeometry object back from the * OMGeometryList, and can then get back to the application level * object through this pointer. * <P> * * The BasicGeometry has been updated to use an attribute Object * Map to hold multiple attributes. If no attributes have been * added, then the appObject will just hold any object passed in * here. If attributes have already been added, then calling this * method will add the object to the Map under the APP_OBJECT_KEY * key. getAppObject() will return the object set in this method. * * @param obj Object */ public synchronized void setAppObject(Object obj) { setAppObject(obj, true); } /** * Same as setAppObject with the option for disabling the * attribute Map management. * * @param checkToReplaceObjWithMap if false, just sets obj to * appObject. */ protected synchronized void setAppObject(Object obj, boolean checkToReplaceObjWithMap) { if (checkToReplaceObjWithMap && checkAttributeMap()) { putAttribute(APP_OBJECT_KEY, obj); } else { appObject = obj; } } /** * Gets the application's object pointer. If an attribute Map * object is being used, returns the object stored in that map * under the APP_OBJECT_KEY key. * * @return Object */ public synchronized Object getAppObject() { return getAppObject(true); } /** * Same as getAppObject, with the option of disabling the * attribute Map management. * * @param checkForObjOnMap if false, just returns the appObject. */ protected synchronized Object getAppObject(boolean checkForObjOnMap) { if (checkForObjOnMap && checkAttributeMap()) { return getAttribute(APP_OBJECT_KEY); } else { return appObject; } } /** * A call used by the BasicGeometry to replace a current * appication object with an Object Map while also adding that * application object to the Map under the APP_OBJECT_KEY key * value. */ protected void replaceAppObjectWithAttributeMap() { if (!checkAttributeMap()) { // OK, we know we need to create a Map for the attributes, // and place it in the appObject of this BasicGeometry. // So, get whatever is already there, Object appObj = getAppObject(false); // Create the new Map, set a pointer to itself so we know // it's the attribute Map (and not just replacing a Map // that someone else was using before Map attributes = createAttributeMap(); attributes.put(ATT_MAP_KEY, attributes); setAppObject(attributes, false); // Now, set the old appObject if appropriate. if (appObj != null) { attributes.put(APP_OBJECT_KEY, appObj); } } } /** * Returns true if the appObject is a Map and if it's the * attribute Map, false if the appObject is something different or * null. */ protected boolean checkAttributeMap() { return checkAttributeMap(getAppObject(false)); } /** * Returns true of the Object is a Map and is pointing to itself * in the Map under the ATT_MAP_KEY. */ protected boolean checkAttributeMap(Object obj) { return (obj instanceof Map && ((Map) obj).get(ATT_MAP_KEY) == obj); } /** * Returns a Map that is being used as an attribute holder. If a * Map doesn't exist, one will be created. If the current * appObject isn't the map, a Map will be created and the * appObject will be added to it under the APP_OBJECT_KEY. * Regardless, the attribute map will be returned from this method * call. */ protected Map getAttributeMap() { // replaceAppObjectWithAttributeMap will do nothing if // attribute map is already set.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -