List of usage examples for java.awt.geom Rectangle2D.Float Rectangle2D.Float
Rectangle2D.Float
From source file:tufts.vue.LWComponent.java
/** @return the raw, zero based, non-scaled shape; default impl returns same as getZeroBounds */ public Shape getZeroShape() { if (mZeroBounds == null) mZeroBounds = new Rectangle2D.Float(); mZeroBounds.width = getWidth();/*from ww w.java 2s. c o m*/ mZeroBounds.height = getHeight(); return mZeroBounds; }
From source file:tufts.vue.LWComponent.java
/** * @param mapRect -- incoming rectangle to transform to be relative to 0,0 of this component * @param zeroRect -- result is placed here -- will be created if is null * @return zeroRect// ww w . j a v a 2 s.c o m * * E.g., if the incoming mapRect was from map coords 100,100->120,120, and this component was at 100,100, * the resulting zeroRect in this case would be 0,0->20,20 (assuming no scale or rotation). * */ //protected Rectangle2D transformMapToZeroRect(Rectangle2D mapRect, Rectangle2D zeroRect) protected Rectangle2D transformMapToZeroRect(Rectangle2D mapRect) { // if (zeroRect == null) // zeroRect = (Rectangle2D) mapRect.clone(); // simpler than newInstace, tho we won't need the data-copy in the end Rectangle2D zeroRect = new Rectangle2D.Float(); // If want to handle rotation, we'll need to transform each corner of the // rectangle separately, generating Polygon2D (which sun never implemented!) or // a GeneralPath, in either case changing this method to return a Shape. Better // would be to keep a cached rotated map Shape in each object, tho that means // solving the general problem of making sure we're updated any time our // ultimate map location/size/scale/rotation, etc, changes, which of course // changes if any of those values change on any ancestor. If we did that, we'd // also be able to fully cache the _zeroTransform w/out having to recompute it // for each call just in case. (Which would mean getting rid of this method // entirely and using the map shape in intersects, etc) Of course, crap, we // couldn't do all this for links, could we? Tho maybe via special handing in an // override... tho that would only work for the transform, not the shape, as the // parent shape is useless to the link. FYI, currently, we only use this // for doing intersections of links and non-rectangular nodes // final double[] points = new double[8]; // final double width = zeroRect.getWidth(); // final double height = zeroRect.getHeight(); // // UL // points[0] = zeroRect.getX(); // points[1] = zeroRect.getY(); // // UR // points[2] = points[0] + width; // points[3] = points[1]; // // LL // points[4] = points[0]; // points[5] = points[1] + height; // // LR // points[6] = points[0] + width; // points[7] = points[1] + height; // Now that we know the below code can never handle rotation, we also might as // well toss out using the transform entirely and just use getMapScale / // getMapX/Y to mod a Rectangle2D.Float directly... Tho then our zoomed rollover // mod, which is in the transformDown code would stop working for rectangle // picking & clipping, tho we shouldn't need rect picking for zoomed rollovers, // (only point picking) and the zoomed rollover always draws no matter what (in // the MapViewer), so that may be moot, tho would need to fully test to be sure. // All of the this also applies to transformZeroToMapRect below. final AffineTransform tx = getZeroTransform(); final double[] points = new double[4]; points[0] = mapRect.getX(); points[1] = mapRect.getY(); points[2] = points[0] + mapRect.getWidth(); points[3] = points[1] + mapRect.getHeight(); try { tx.inverseTransform(points, 0, points, 0, 2); } catch (java.awt.geom.NoninvertibleTransformException e) { Util.printStackTrace(e); } zeroRect.setRect(points[0], points[1], points[2] - points[0], points[3] - points[1]); return zeroRect; }
From source file:tufts.vue.LWComponent.java
/** * This will take the given zeroRect rectangle in local coordinates, and transform it * into map coordinates, setting mapRect and returning it. If mapRect is null, * a new rectangle will be created and returned. *//* w ww . j a v a2 s . c o m*/ public Rectangle2D transformZeroToMapRect(Rectangle2D zeroRect, Rectangle2D mapRect) { final AffineTransform tx = getZeroTransform(); final double[] points = new double[4]; points[0] = zeroRect.getX(); points[1] = zeroRect.getY(); points[2] = points[0] + zeroRect.getWidth(); points[3] = points[1] + zeroRect.getHeight(); tx.transform(points, 0, points, 0, 2); if (mapRect == null) mapRect = new Rectangle2D.Float(); mapRect.setRect(points[0], points[1], points[2] - points[0], points[3] - points[1]); return mapRect; // Non-rotating & non-transform using version: // final double scale = getMapScale(); // // would this be right? scale the x/y first? // if (scale != 1) { // rect.x *= scale; // rect.y *= scale; // rect.width *= scale; // rect.height *= scale; // } // if (this instanceof LWLink) { // // todo: eventually rewrite this routine entirely to use the transformations // // (will need that if ever want to handle rotation, as well as to skip this // // special case for links). // rect.x += getParent().getMapX(); // rect.y += getParent().getMapY(); // } else { // rect.x += getMapX(); // rect.y += getMapY(); // } }