/** * Called to set the OffsetGrabPoint to the current mouse location, and update the OffsetGrabPoint * with all the other GrabPoint locations, so everything can shift smoothly. Should also set the * OffsetGrabPoint to the movingPoint. Should be called only once at the beginning of the general * movement, in order to set the movingPoint. After that, redraw(e) should just be called, and the * movingPoint will make the adjustments to the graphic that are needed. */ public void move(MouseEvent e) { // Need to check to see if the OffsetGrabPoint is currently // being used. If not, just use it, otherwise, will need to // create a special one for the move. Point2D pnt = getProjectionPoint(e); int x = (int) pnt.getX(); int y = (int) pnt.getY(); if (poly.getRenderType() == OMGraphic.RENDERTYPE_OFFSET) { gpm = new OffsetGrabPoint(x, y); gpm.clear(); } else { gpm = gpo; gpm.clear(); gpm.set(x, y); } // Move all the other points along with the offset point... addPolyGrabPointsToOGP(gpm); movingPoint = gpm; }
/** * 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 points of the graphic. */ public void setGrabPoints(OMGraphic graphic) { if (!(graphic instanceof OMPoly)) { return; } assertGrabPoints(); polyGrabPoints.clear(); arrayCleared = true; gpo.clear(); OMPoly poly = (OMPoly) graphic; boolean ntr = poly.getNeedToRegenerate(); int renderType = poly.getRenderType(); Point p = new Point(); GrabPoint gb; int i; int npts; boolean geoProj = projection instanceof GeoProj; if (ntr == false) { if (renderType == OMGraphic.RENDERTYPE_LATLON) { Debug.message("eomg", "EditableOMPoly: modifying lat/lon line"); if (projection != null) { double[] ll = poly.getLatLonArray(); boolean rads = poly.getUnits() == OMGraphic.RADIANS; gb = null; // reset for this loop for (i = 0; i < ll.length; i += 2) { if (geoProj) { ((GeoProj) projection).forward(ll[i], ll[i + 1], p, rads); } else { projection.forward(ll[i], ll[i + 1], p); } // Need to add a grab point for this // coordinate gb = new OffsetGrabPoint((int) p.getX(), (int) p.getY()); polyGrabPoints.add(gb); } } } else if (renderType == OMGraphic.RENDERTYPE_OFFSET) { // Grab the projected endpoints Debug.message("eomg", "EditableOMPoly: modifying offset poly"); int x; int y; npts = poly.xs.length; // Check to see if the poly is a offset poly, and set // the // offset grab point accordingly. if (projection != null) { if (geoProj) { ((GeoProj) projection).forward(poly.lat, poly.lon, p, true); } else { projection.forward(poly.lat, poly.lon, p); } gpo.set((int) p.getX(), (int) p.getY()); if (poly.coordMode == OMPoly.COORDMODE_ORIGIN) { for (i = 0; i < npts; i++) { x = (int) (poly.xs[i] + p.getX()); y = (int) (poly.ys[i] + p.getY()); gb = new OffsetGrabPoint(x, y); polyGrabPoints.add(gb); } } else { // CMode Previous offset deltas int lastX = (int) p.getX(); int lastY = (int) p.getY(); for (i = 0; i < npts; i++) { x = poly.xs[i] + lastX; y = poly.ys[i] + lastY; gb = new OffsetGrabPoint(x, y); polyGrabPoints.add(gb); lastX += x; lastY += y; } } } } else { npts = poly.xs.length; Debug.message("eomg", "EditableOMPoly: modifying x/y poly"); for (i = 0; i < npts; i++) { gb = new OffsetGrabPoint(poly.xs[i], poly.ys[i]); polyGrabPoints.add(gb); } } // Add the || to maintain manualEnclosed if it was // externally set before the OMPoly is actually defined, // indicating that the user wants to draw a polygon. setEnclosed(syncEnclosed() || isEnclosed()); addPolyGrabPointsToOGP(gpo); } else { Debug.message("eomg", "EditableOMPoly.setGrabPoints: graphic needs to be regenerated "); } }