List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
From source file:tufts.vue.LWComponent.java
public void setFrame(Rectangle2D r) { setFrame((float) r.getX(), (float) r.getY(), (float) r.getWidth(), (float) r.getHeight()); }
From source file:tufts.vue.LWComponent.java
protected boolean doZoomingDoubleClick(MapMouseEvent e) { // System.out.println("zooming double click"); final MapViewer viewer = e.getViewer(); if (viewer.getFocal() == this) { viewer.popFocal(MapViewer.POP_TO_TOP, MapViewer.ANIMATE); return true; //return false; }/* w ww . j ava 2s. c o m*/ VUE.getActiveMap().setTempBounds(VUE.getActiveViewer().getVisibleMapBounds()); final Rectangle2D viewerBounds = viewer.getVisibleMapBounds(); final Rectangle2D mapBounds = getMapBounds(); final Rectangle2D overlap = viewerBounds.createIntersection(mapBounds); final double overlapArea = overlap.getWidth() * overlap.getHeight(); //final double viewerArea = viewerBounds.getWidth() * viewerBounds.getHeight(); final double nodeArea = mapBounds.getWidth() * mapBounds.getHeight(); final boolean clipped = overlapArea < nodeArea; final double overlapWidth = mapBounds.getWidth() / viewerBounds.getWidth(); final double overlapHeight = mapBounds.getHeight() / viewerBounds.getHeight(); final boolean focusNode; // otherwise, re-focus map // Note: this code is way more complicated than we're making use of right now -- // we always fully load objects (slides) as the focal when we zoom to them. // This code permitted double-clicking through a slide-icon stack, where we'd // zoom to the slide icon, but retain the map focal. The overlap herustics here // determined how much of the current view was occupied by the current clicked // on zoom-to object. If mostly in view, assume we want to "de-focus" (zoom // back out to the map from our "virtual focal" zoomed-to node), but if mostly // not in view, re-center on this object. When last tested, this was smart // enough to allow you to simply cycle through a stack of slide-icons with // double clicking on the exposed edge of the nearby slide icons (of course, // this code was on LWSlide back then...) if (DEBUG.Enabled) { outf(" overlapWidth %4.1f%%", overlapWidth * 100); outf("overlapHeight %4.1f%%", overlapHeight * 100); outf("clipped=" + clipped); } if (clipped) { focusNode = true; } else if (overlapWidth > 0.8 || overlapHeight > 0.8) { focusNode = false; } else focusNode = true; if (focusNode) { viewer.clearRollover(); if (SwapFocalOnSlideZoom) { // loadfocal animate only currently works when popping (to a parent focal) //viewer.loadFocal(this, true, AnimateOnZoom); ZoomTool.setZoomFitRegion(viewer, mapBounds, 0, AnimateOnZoom); viewer.loadFocal(this); } else { ZoomTool.setZoomFitRegion(viewer, mapBounds, -LWPathway.PathBorderStrokeWidth / 2, AnimateOnZoom); } } else { // just re-fit to the map viewer.fitToFocal(AnimateOnZoom); } return true; }
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. */// ww w . j a v a 2 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(); // } }
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//from w w w . ja v a 2 s.com * * 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; }