?? editableomrect.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/EditableOMRect.java,v $// $RCSfile: EditableOMRect.java,v $// $Revision: 1.3.2.2 $// $Date: 2005/08/09 21:17:45 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.omGraphics;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.layer.util.stateMachine.State;import com.bbn.openmap.omGraphics.editable.GraphicEditState;import com.bbn.openmap.omGraphics.editable.GraphicSelectedState;import com.bbn.openmap.omGraphics.editable.GraphicSetOffsetState;import com.bbn.openmap.omGraphics.editable.RectStateMachine;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;/** * The EditableOMRect encompasses an OMRect, providing methods for * modifying or creating it. This class only modifies rects in lat/lon * space (RENDERTYPE_LATLON) - and ellipses in screen space * (RENDERTYPE_XY or RENDERTYPE_OFFSET). When you grab at the rect, * you change the radius of the entire rect. Grabbing the center point * moves the rect. If there is an offset point, moving the center * point changes the rect's position in relation to the offset point. * Moving the offset point moves the rect, keeping the distance to the * center point constant. */public class EditableOMRect extends EditableOMGraphic { protected GrabPoint gpnw; protected GrabPoint gpne; protected GrabPoint gpsw; protected GrabPoint gpse; protected OffsetGrabPoint gpc; protected OffsetGrabPoint gpo; // offset protected OMRect rect; public final static String OffsetResetCmd = "OffsetResetCmd"; public final static int CENTER_POINT_INDEX = 0; public final static int NW_POINT_INDEX = 1; public final static int NE_POINT_INDEX = 2; public final static int SW_POINT_INDEX = 3; public final static int SE_POINT_INDEX = 4; public final static int OFFSET_POINT_INDEX = 5; /** * Create the EditableOMRect, setting the state machine to create * the rect off of the gestures. */ public EditableOMRect() { createGraphic(null); } /** * Create an EditableOMRect with the rectType and renderType * parameters in the GraphicAttributes object. */ public EditableOMRect(GraphicAttributes ga) { createGraphic(ga); } /** * Create the EditableOMRect with an OMRect already defined, ready * for editing. * * @param omc OMRect that should be edited. */ public EditableOMRect(OMRect omc) { setGraphic(omc); } /** * Create and initialize the state machine that interprets the * modifying gestures/commands, as well as ititialize the grab * points. Also allocates the grab point array needed by the * EditableOMRect. */ public void init() { Debug.message("eomg", "EditableOMRect.init()"); setCanGrabGraphic(false); setStateMachine(new RectStateMachine(this)); gPoints = new GrabPoint[6]; } /** * Set the graphic within the state machine. If the graphic is * null, then one shall be created, and located off screen until * the gestures driving the state machine place it on the map. */ public void setGraphic(OMGraphic graphic) { init(); if (graphic instanceof OMRect) { rect = (OMRect) graphic; stateMachine.setSelected(); setGrabPoints(rect); } else { createGraphic(null); } } /** * Create and set the graphic within the state machine. The * GraphicAttributes describe the type of rect to create. */ public void createGraphic(GraphicAttributes ga) { init(); stateMachine.setUndefined(); int renderType = OMGraphic.RENDERTYPE_UNKNOWN; int lineType = OMGraphic.LINETYPE_GREATCIRCLE; if (ga != null) { renderType = ga.getRenderType(); lineType = ga.getLineType(); } if (Debug.debugging("eomg")) { Debug.output("EditableOMRect.createGraphic(): rendertype = " + renderType); Debug.output("EditableOMRect.createGraphic(): linetype = " + lineType); } switch (renderType) { case (OMGraphic.RENDERTYPE_LATLON): if (lineType == OMGraphic.LINETYPE_UNKNOWN) { lineType = OMGraphic.LINETYPE_GREATCIRCLE; ga.setLineType(OMGraphic.LINETYPE_GREATCIRCLE); } rect = new OMRect(90f, -180f, 90f, -180f, lineType); break; case (OMGraphic.RENDERTYPE_OFFSET): rect = new OMRect(90f, -180f, -1, -1, 1, 1); break; default: rect = new OMRect(-1, -1, -1, -1); } if (ga != null) { ga.setTo(rect); } assertGrabPoints(); } /** * Get the OMGraphic being created/modified by the EditableOMRect. */ public OMGraphic getGraphic() { return rect; } /** * Set the GrabPoint that is in the middle of being modified, as a * result of a mouseDragged event, or other selection process. */ public void setMovingPoint(GrabPoint gp) { super.setMovingPoint(gp); } float diffx; float diffy; // Called from the state machine... public void initRectSize() { diffx = Math.abs(rect.getEastLon() - rect.getWestLon()) / 2f; diffy = Math.abs(rect.getNorthLat() - rect.getSouthLat()) / 2f; // Debug.output("initRectSize(): diffx:" + diffx + ", diffy:" // + diffy); } protected int lastRenderType = -1; /** * Check to make sure the grab points are not null. If they are, * allocate them, and them assign them to the array. */ public void assertGrabPoints() { int rt = getGraphic().getRenderType(); if (rt != lastRenderType) { clearGrabPoints(); lastRenderType = rt; } if (gpnw == null) { gpnw = new GrabPoint(-1, -1); gPoints[NW_POINT_INDEX] = gpnw; // gpnw.setFillPaint(Color.yellow); } if (gpne == null) { gpne = new GrabPoint(-1, -1); gPoints[NE_POINT_INDEX] = gpne; // gpne.setFillPaint(Color.blue); } if (gpsw == null) { gpsw = new GrabPoint(-1, -1); gPoints[SW_POINT_INDEX] = gpsw; // gpsw.setFillPaint(Color.green); } if (gpse == null) { gpse = new GrabPoint(-1, -1); gPoints[SE_POINT_INDEX] = gpse; // gpse.setFillPaint(Color.orange); } if (gpc == null) { gpc = new OffsetGrabPoint(-1, -1); // gpc.setFillPaint(Color.red); gPoints[CENTER_POINT_INDEX] = gpc; if (getGraphic().getRenderType() != OMGraphic.RENDERTYPE_LATLON) { gpc.addGrabPoint(gpnw); gpc.addGrabPoint(gpne); gpc.addGrabPoint(gpsw); gpc.addGrabPoint(gpse); } } if (gpo == null) { gpo = new OffsetGrabPoint(-1, -1); gPoints[OFFSET_POINT_INDEX] = gpo; gpo.addGrabPoint(gpc); } } protected void clearGrabPoints() { gpc = null; gpnw = null; gpne = null; gpsw = null; gpse = null; gpo = null; gPoints[CENTER_POINT_INDEX] = gpc; gPoints[NW_POINT_INDEX] = gpnw; gPoints[NE_POINT_INDEX] = gpne; gPoints[SW_POINT_INDEX] = gpsw; gPoints[SE_POINT_INDEX] = gpse; gPoints[OFFSET_POINT_INDEX] = gpo; } /** * Set the grab points for the graphic provided, setting them on * the extents of the graphic. Called when you want to set the * grab points off the location of the graphic. */ public void setGrabPoints(OMGraphic graphic) { Debug.message("eomg", "EditableOMRect.setGrabPoints(graphic)"); if (!(graphic instanceof OMRect)) { return; } assertGrabPoints(); OMRect rect = (OMRect) graphic; boolean ntr = rect.getNeedToRegenerate(); int renderType = rect.getRenderType(); int top = 0; int bottom = 0; int left = 0; int right = 0; LatLonPoint llp; int latoffset = 0; int lonoffset = 0; boolean doStraight = true; if (ntr == false) { if (renderType == OMGraphic.RENDERTYPE_LATLON || renderType == OMGraphic.RENDERTYPE_OFFSET) { if (projection != null) { float wlon = rect.getWestLon(); float nlat = rect.getNorthLat(); float elon = rect.getEastLon(); float slat = rect.getSouthLat(); llp = new LatLonPoint(nlat, wlon); java.awt.Point p = projection.forward(llp);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -