/** * Method disconnects the last point from the first point. Make sure they are both * OffsetGrabPoints. */ protected boolean unsyncEnclosed() { try { OffsetGrabPoint gb0 = (OffsetGrabPoint) polyGrabPoints.get(0); OffsetGrabPoint ogb = (OffsetGrabPoint) polyGrabPoints.get(polyGrabPoints.size() - 1); // disconnect them... if (gb0.getX() == ogb.getX() && gb0.getY() == ogb.getY()) { gb0.removeGrabPoint(ogb); ogb.removeGrabPoint(gb0); return true; } } catch (ClassCastException cce) { } catch (ArrayIndexOutOfBoundsException aioobe) { } return false; }
/** * Delete a point at a certain point in the polygon coordinate list. If the position is less than * zero, the deleted point will be the starting point. If the position is greater than the list of * current points, the point will be deleted from the end of the poly. */ public void deletePoint(int position) { int renderType = poly.getRenderType(); boolean needToHookUp = false; if (position <= 0 && isEnclosed()) { // if the position is 0 and the polygon is enclosed, we // need to disengage the two points, then reattach. enclose(false); needToHookUp = true; } if (renderType == OMGraphic.RENDERTYPE_LATLON) { Debug.message("eomg", "EditableOMPoly: removing point from lat/lon poly"); if (projection != null) { double[] ll = poly.getLatLonArray(); double[] newll = new double[ll.length - 2]; int actualPosition = (position == Integer.MAX_VALUE ? ll.length : position * 2); if (actualPosition >= ll.length) { // Pull the new points off the end System.arraycopy(ll, 0, newll, 0, ll.length - 2); position = (ll.length - 2) / 2; } else if (actualPosition <= 0) { // Pull the new points off the beginning System.arraycopy(ll, 2, newll, 0, ll.length - 2); position = 0; } else { // actualPosition because there are 2 floats for // every // position. System.arraycopy(ll, 0, newll, 0, actualPosition); System.arraycopy( ll, actualPosition + 2, newll, actualPosition, ll.length - actualPosition - 2); } poly.setLocation((double[]) newll, poly.getUnits()); } } else { // Grab the projected endpoints Debug.message("eomg", "EditableOMPoly: removing point from x/y or offset poly"); int currentLength = poly.xs.length; int[] newxs = new int[currentLength - 1]; int[] newys = new int[currentLength - 1]; if (position >= currentLength) { // Pull the points from the end... System.arraycopy(poly.xs, 0, newxs, 0, currentLength - 1); System.arraycopy(poly.ys, 0, newys, 0, currentLength - 1); position = currentLength - 1; } else if (position <= 0) { // Pull the points from the beginning... System.arraycopy(poly.xs, 1, newxs, 0, currentLength - 1); System.arraycopy(poly.ys, 1, newys, 0, currentLength - 1); position = 0; } else { System.arraycopy(poly.xs, 0, newxs, 0, position); System.arraycopy(poly.xs, position + 1, newxs, position, currentLength - position - 1); System.arraycopy(poly.ys, 0, newys, 0, position); System.arraycopy(poly.ys, position + 1, newys, position, currentLength - position - 1); } if (poly.getRenderType() == OMGraphic.RENDERTYPE_OFFSET) { poly.setLocation(poly.lat, poly.lon, poly.getUnits(), newxs, newys); } else { poly.setLocation(newxs, newys); } } if (projection != null) { poly.regenerate(projection); } // Remove the GrabPoint for the deleted spot. GrabPoint gp = (GrabPoint) polyGrabPoints.remove(position); if (gpo != null && gp != null) { gpo.removeGrabPoint(gp); } if (needToHookUp) { enclose(true); } }
/** * Detach from a Moving OffsetGrabPoint. The EditableOMGraphic version doesn't do anything, each * subclass should remove whatever GrabPoint it would have attached to an OffsetGrabPoint. */ public void detachFromMovingGrabPoint(OffsetGrabPoint gp) { gp.removeGrabPoint(gpo); }