📄 omgraphic.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/OMGraphic.java,v $// $RCSfile: OMGraphic.java,v $// $Revision: 1.8.2.6 $// $Date: 2005/09/06 20:01:21 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.omGraphics;import java.awt.BasicStroke;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Paint;import java.awt.Point;import java.awt.Stroke;import java.awt.TexturePaint;import java.awt.geom.GeneralPath;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.Serializable;import com.bbn.openmap.omGraphics.geom.BasicGeometry;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;/** * Used to be the base class of OpenMap graphics, but now inherits * from BasicGeometry, which now contains all the information about * the geometry of the OMGraphic. The OMGraphic also contains * information about how the geometry should be drawn. * <P> * The OMGraphics are raster and vector graphic objects that know how * to position and render themselves on a given x-y window or lat-lon * map projection. All you have to do is supply the location data * (x/y, lat/lon) and drawing information (color, line width) and the * graphic handles the rest. * <p> * * This class contains parameters that are common to most types of * graphics. If a parameter doesn't make sense for a particular * graphic type, it is ignored. * <p> * * The OMGraphics are being updated to be able to provide * java.awt.Shape representations of themselves after they have been * generated(). The getShape() method returns a java.awt.Shape object. * With the Shape object, you can do some spatial analysis (object * operations) on the projected OMGraphics. * * NOTES: * <ul> * <li>Color values cannot be set to null, but can be set to * OMGraphic.clear. Actually, if you set them to null, they will set * themselves to be clear. * <li>XY Rendering: Java specifies that the origin is the top left * of the window, x increases to the right, y increases down. * <li>LatLon Rendering: Defined by the Projection object. The center * of the window usually corresponds to the center of the projection. * OMGraphics should project themselves using the appropriate * forward() method listed in the Projection interface * <li>Offset Rendering: same as XY, but with origin set to a * projected LatLon point. * </ul> * * @see OMBitmap * @see OMCircle * @see OMLine * @see OMPoly * @see OMRect * @see OMRaster * @see OMText * @see OMGraphicList * @see Projection */public abstract class OMGraphic extends BasicGeometry implements OMGeometry, OMGraphicConstants, Cloneable, Serializable { /** * The Java2D Stroke. This is used for lineWidth, and dashing of * the lines and polygon edges. */ protected transient Stroke stroke = BASIC_STROKE; /** * This color is the real foreground color of the object. It is * kept so that the object knows how to de-highlight itself. It * defaults to black. */ protected Paint linePaint = Color.black; /** * This paint is used for the matting area around the edge of an * OMGraphic painted when the matted variable is set to true. */ protected Paint mattingPaint = Color.black; /** * The color that the object is displayed with. This color changes * back and forth between the selectColor and the lineColor, * depending on the if the object is selected or not. */ protected Paint displayPaint = linePaint; /** * This color is the fill color of the object. It defaults to a * black color that is transparent. */ protected Paint fillPaint = clear; /** * This Paint object is the fill texture mask of the object. It * defaults to null. If this texture mask is set, the fill paint * will still be used to fill the OMGraphic shape, but then this * paint will be rendered on top. If the textureMask has * transparency, the fill paint still influences appearance. */ protected TexturePaint textureMask = null; /** * This color is the highlight color that can be used when the * object is selected. The default color is black, just like the * line color. */ protected Paint selectPaint = Color.black; /** * Flag to indicate that the object has/hasnot been put in a * special mode as a result of some event. Set through the * select()/deselect methods(). */ protected boolean selected = false; /** * A flag for whether an EditableOMGraphic should show it's * palette if the OMGraphic is modified. */ protected boolean showEditablePalette = true; /** * Flag to note if the current edge color matches the fill color. * Can be used to save from rendering the edge if rendering the * filled area already takes care of it. */ protected boolean edgeMatchesFill = false; /** * The renderType describes the relation of the object to the * window. RENDERTYPE_LATLON means the object is positioned * relative to lat/lon points. RENDERTYPE_XY means the object is * positioned relative to window pixel coordinates. * RENDERTYPE_OFFSET means the object is drawn at a pixel offset * to a lat/lon point. */ protected int renderType = RENDERTYPE_UNKNOWN; /** * Decluttering is not supported by OpenMap yet. But, when it is, * these parameters will describe the way the object is * manipulated on the window relative to its neighbors. * DECLUTTERTYPE_NONE means the object will be drawn where its * attributes say it should be. DECLUTTERTYPE_SPACE indicates that * the window space of the object should be marked as taken, but * the object should not be moved. DECLUTTERTYPE_MOVE means the * object should be moved to the nearest open location closest to * the position indicated by its attributes. DECLUTTERTYPE_LINE is * the same as MOVE, but in addition, a line is drawn from the * current position to its original position. */ protected int declutterType = DECLUTTERTYPE_NONE; /** * Flag for determining when the matting around the edge of an * OMGraphic. Matting is a line, two pixels wider than the edge, * painted under the edge. It makes the OMGraphic stand out on * busy backgrounds. */ protected boolean matted = false; /** * The flag set in generate that causes the OMGraphic to look for * an OMLabeler attribute in render. This flag prevents an * unnecessary hashtable lookup every render call. */ protected transient boolean hasLabel = false; /** * Checks if the Paint is clear. * * @param paint Paint or null. * @return true if Paint is null or is a Color with a 0 alpha * value. */ public static boolean isClear(Paint paint) { if (paint instanceof Color) { return ((((Color) paint).getRGB() & 0xff000000) == 0); } else { return false; } } // //////////////////////////////////////////////////////// /** * Construct a default OMGraphic. */ protected OMGraphic() {} /** * Construct an OMGraphic. Standard simple constructor that the * child OMGraphics usually call. All of the other parameters get * set to their default values. * * @param rType render type * @param lType line type * @param dcType declutter type */ protected OMGraphic(int rType, int lType, int dcType) { setRenderType(rType); setLineType(lType); setDeclutterType(dcType); } /** * Construct an OMGraphic. More complex constructor that lets you * set the rest of the parameters. * * @param rType render type * @param lType line type * @param dcType declutter type * @param lc line color * @param fc fill color * @param sc select color */ public OMGraphic(int rType, int lType, int dcType, Color lc, Color fc, Color sc) { this(rType, lType, dcType); setLinePaint(lc); setSelectPaint(sc); setFillPaint(fc); } /** * Set the render type of the graphic. Accepts RENDERTYPE_LATLON, * RENDERTYPE_XY and RENDERTYPE_OFFSET. All weird values get set * to RENDERTYPE_XY. See the definition on the renderType * parameter. * * @param value the rendertype for the object. */ public void setRenderType(int value) { if (renderType == value) return; setNeedToRegenerate(true); // flag dirty renderType = value; } /** * Return the render type. * * @return the rendertype of the object - RENDERTYPE_LATLON, * RENDERTYPE_XY, RENDERTYPE_OFFSET and * RENDERTYPE_UNKNOWN. */ public int getRenderType() { return renderType; } /** * OMGraphic method for returning a simple description of the * OMGraphic. * * @param level used by OMGraphicLists to provide an offset, or a * notion of embedding. */ public String getDescription(int level) { if (level == 0) { return getDescription(); } else { return "|--> " + getDescription(); } } /** * OMGraphic method for returning a simple description of the * OMGraphic. */ public String getDescription() { String cname = getClass().getName(); int lastPeriod = cname.lastIndexOf('.'); if (lastPeriod != -1) { cname = cname.substring(lastPeriod + 1); } return cname; } /** * Set the declutter setting for the graphic. Accepts * DECLUTTERTYPE_SPACE, DECLUTTERTYPE_MOVE, DECLUTTERTYPE_LINE, * and DECLUTTERTYPE_NONE. All weird values are set to * DECLUTTERTYPE_NONE. * <p> * Right now, this is unimplemented in OpenMap. But for * information, DECLUTTERTYPE_NONE means the object has no impact * on the placement of objects. DECLUTTERTYPE_SPACE means the * object shouldn't have things placed on it, but to draw it where * the coordinates dictate. DECLUTTERTYPE_MOVE means to put the * object in an open space, and DELCUTTERTYPE_LINE adds the * feature that if the object is not drawn where it's coordinates * say it should be, then a line should be drawn showing where the * original position is. * <P> * Decluttering of geometries is not supported. This flag is not * used. * * @param value the declutter type value. */ public void setDeclutterType(int value) { if (declutterType == value) return; setNeedToRegenerate(true); // flag dirty declutterType = value; } /** * Return the declutter type. * * @return declutter type, see above. */ public int getDeclutterType() { return declutterType; } /** * Given a java.awt.Graphics object, set the Stroke and Paint * parameters of it to match the OMGraphic's edge settings. * * @param g java.awt.Graphics * @see #setGraphicsColor */ public void setGraphicsForEdge(Graphics g) { if (g instanceof Graphics2D) { ((Graphics2D) g).setStroke(getStroke()); } setGraphicsColor(g, getDisplayPaint()); } /** * Given a java.awt.Graphics object, set the Paint to be the * OMGraphic's fillPaint setting. * * @param g java.awt.Graphics * @see #setGraphicsColor */ public void setGraphicsForFill(Graphics g) { if (g instanceof Graphics2D) { ((Graphics2D) g).setStroke(BASIC_STROKE); } setGraphicsColor(g, getFillPaint()); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -