?? editableomscalingraster.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/EditableOMScalingRaster.java,v $// $RCSfile: EditableOMScalingRaster.java,v $// $Revision: 1.1.2.7 $// $Date: 2005/08/11 21:03:22 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.omGraphics;import com.bbn.openmap.Environment;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.layer.util.stateMachine.State;import com.bbn.openmap.omGraphics.editable.*;import com.bbn.openmap.proj.*;import com.bbn.openmap.util.Debug;import java.awt.image.BufferedImage;import javax.swing.JOptionPane;/** * The EditableOMScalingRaster encompasses an OMScalingRaster, * providing methods for modifying or creating it. This class only * modifies OMScaling Rasters in lat/lon space (RENDERTYPE_LATLON). * When you grab at the raster, you change the size of the entire * rect. Grabbing the center point moves the raster. 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 EditableOMScalingRaster extends EditableOMGraphic { protected GrabPoint gpnw; protected GrabPoint gpne; protected GrabPoint gpsw; protected GrabPoint gpse; protected OffsetGrabPoint gpc; protected OffsetGrabPoint gpo; // offset protected OMScalingRaster raster; 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 EditableOMScalingRaster() { createGraphic(null); } /** * Create an EditableOMScalingRaster with the rectType and * renderType parameters in the GraphicAttributes object. */ public EditableOMScalingRaster(GraphicAttributes ga) { createGraphic(ga); } /** * Create the EditableOMScalingRaster with an OMScalingRaster * already defined, ready for editing. * * @param omsr OMScalingRaster that should be edited. */ public EditableOMScalingRaster(OMScalingRaster omsr) { setGraphic(omsr); } /** * 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 * EditableOMScalingRaster. */ public void init() { Debug.message("eomg", "EditableOMScalingRaster.init()"); setCanGrabGraphic(false); setStateMachine(new ScalingRasterStateMachine(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 OMScalingRaster) { raster = (OMScalingRaster) graphic; stateMachine.setSelected(); setGrabPoints(raster); } 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(); String pathToFile = null; /// This would be an ideal place to bring up a chooser! if (!Environment.isApplet()) { pathToFile = com.bbn.openmap.util.FileUtils.getFilePathToOpenFromUser("Choose Image File for Raster"); } else { JOptionPane.showMessageDialog(null, "Can't search for images in an applet!", "Can't Choose Image", JOptionPane.ERROR_MESSAGE); } if (pathToFile == null) return; try { javax.swing.ImageIcon ii = new javax.swing.ImageIcon(pathToFile); raster = new OMScalingRaster(90f, -180f, 89f, -179f, ii); } catch (IllegalArgumentException iae) { // Not an image file, punch Debug.error("EditableOMScalingRaster: " + pathToFile + " doesn't appear to be an image file"); raster = new OMScalingRaster(90f, -180f, 89f, -179f, new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB)); } if (ga != null) { ga.setTo(raster); } assertGrabPoints(); } /** * Get the OMGraphic being created/modified by the * EditableOMScalingRaster. */ public OMGraphic getGraphic() { return raster; } /** * 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(raster.getLRLon() - raster.getULLon()) / 2f; diffy = Math.abs(raster.getULLat() - raster.getLRLat()) / 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() { OMGraphic omg = getGraphic(); if (omg == null) return; int rt = omg.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", "EditableOMScalingRaster.setGrabPoints(graphic)"); if (!(graphic instanceof OMScalingRaster)) { return; } assertGrabPoints(); OMScalingRaster raster = (OMScalingRaster) graphic; if (graphic instanceof OMScalingIcon) { setGrabPointsForOMSI((OMScalingIcon) graphic); return; } boolean ntr = raster.getNeedToRegenerate(); int renderType = raster.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 = raster.getULLon(); float nlat = raster.getULLat(); float elon = raster.getLRLon(); float slat = raster.getLRLat(); llp = new LatLonPoint(nlat, wlon); java.awt.Point p = projection.forward(llp); if (renderType == OMGraphic.RENDERTYPE_LATLON) { doStraight = false; top = (int) p.getY(); left = (int) p.getX(); gpnw.set((int) p.getX(), (int) p.getY()); p = projection.forward(slat, elon); gpse.set((int) p.getX(), (int) p.getY()); p = projection.forward(nlat, elon); gpne.set((int) p.getX(), (int) p.getY()); p = projection.forward(slat, wlon); gpsw.set((int) p.getX(), (int) p.getY()); p = projection.forward(nlat - (nlat - slat) / 2f, wlon + (elon - wlon) / 2f); gpc.set((int) p.getX(), (int) p.getY()); } else { latoffset = (int) p.getY(); lonoffset = (int) p.getX(); gpo.set(lonoffset, latoffset); } } } if (doStraight) { Debug.message("eomg", "EditableOMScalingRaster: drawing straight line rectangle");
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -