@Override public Rectangle2D getOriginalSelectionBounds(double x, double y) { Shape s = getShape(); AffineTransform af = new AffineTransform(); af.setToRotation(-totalRotation, x, y); Area a = new Area(af.createTransformedShape(s)); return a.getBounds2D(); }
protected static void addToDownload( Area a, Rectangle2D r, Collection<Rectangle2D> results, double max_area) { Area tmp = new Area(r); // intersect with sought-after area tmp.intersect(a); if (tmp.isEmpty()) { return; } Rectangle2D bounds = tmp.getBounds2D(); if (bounds.getWidth() * bounds.getHeight() > max_area) { // the rectangle gets too large; split it and make recursive call. Rectangle2D r1; Rectangle2D r2; if (bounds.getWidth() > bounds.getHeight()) { // rectangles that are wider than high are split into a left and right half, r1 = new Rectangle2D.Double( bounds.getX(), bounds.getY(), bounds.getWidth() / 2, bounds.getHeight()); r2 = new Rectangle2D.Double( bounds.getX() + bounds.getWidth() / 2, bounds.getY(), bounds.getWidth() / 2, bounds.getHeight()); } else { // others into a top and bottom half. r1 = new Rectangle2D.Double( bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight() / 2); r2 = new Rectangle2D.Double( bounds.getX(), bounds.getY() + bounds.getHeight() / 2, bounds.getWidth(), bounds.getHeight() / 2); } addToDownload(a, r1, results, max_area); addToDownload(a, r2, results, max_area); } else { results.add(bounds); } }
protected void calcPreferredSize() { super.calcPreferredSize(); PFont font = getFont(); float fs = getFontSize(); float px = getPadX(); float py = getPadY(); /* * Calculate the text rectangle size. */ tWidth = UIUtils.getTextWidth(menu.canvas.g, font, fs, getName(), true); /* * For the height, let's use the height of some capital letters. */ float tHeight = UIUtils.getTextHeight(menu.canvas.g, font, fs, "XYZ", true); float triangleWidth = 0; if (drawChildrenTriangle && items.size() > 0 && layoutMode != LAYOUT_BELOW) { /* * Calculate the width of the "submenu" triangle shape. */ at = AffineTransform.getScaleInstance(tHeight / 2f, tHeight / 2f); Area tri = (Area) getStyle().get("subTriangle"); Area a = tri.createTransformedArea(at); ToolbarItem.tri = a; ToolbarItem.triWidth = (float) a.getBounds2D().getWidth(); triangleWidth = triWidth + px; } shortcutWidth = 0; if (shortcut != null) { shortcutWidth = px + UIUtils.getTextWidth(menu.buff, font, fs * shortcutTextSize, shortcut.label, true); } setWidth(tWidth + triangleWidth + shortcutWidth + 2 * px); setHeight(tHeight + 2 * py); }
/** * Returns the bargraph track image with the given with and height. * * @param WIDTH * @param START_ANGLE * @param ANGLE_EXTEND * @param APEX_ANGLE * @param BARGRAPH_OFFSET * @param image * @return buffered image containing the bargraph track image */ protected BufferedImage create_BARGRAPH_TRACK_Image( final int WIDTH, final double START_ANGLE, final double ANGLE_EXTEND, final double APEX_ANGLE, final double BARGRAPH_OFFSET, BufferedImage image) { if (WIDTH <= 0) { return null; } if (image == null) { image = UTIL.createImage(WIDTH, WIDTH, Transparency.TRANSLUCENT); } final Graphics2D G2 = image.createGraphics(); G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // G2.setRenderingHint(RenderingHints.KEY_RENDERING, // RenderingHints.VALUE_RENDER_QUALITY); // G2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); // G2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, // RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); // G2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, // RenderingHints.VALUE_COLOR_RENDER_QUALITY); // G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, // RenderingHints.VALUE_STROKE_NORMALIZE); final int IMAGE_WIDTH = image.getWidth(); final int IMAGE_HEIGHT = image.getHeight(); // Create led track final java.awt.geom.Arc2D BACK = new java.awt.geom.Arc2D.Double(java.awt.geom.Arc2D.PIE); BACK.setFrame( IMAGE_WIDTH * 0.1074766355, IMAGE_HEIGHT * 0.1074766355, IMAGE_WIDTH * 0.785046729, IMAGE_HEIGHT * 0.785046729); BACK.setAngleStart(START_ANGLE + 2); BACK.setAngleExtent(ANGLE_EXTEND - 5); final Ellipse2D BACK_SUB = new Ellipse2D.Double( IMAGE_WIDTH * 0.1822429907, IMAGE_HEIGHT * 0.1822429907, IMAGE_WIDTH * 0.6355140187, IMAGE_HEIGHT * 0.6355140187); final java.awt.geom.Area LED_TRACK_FRAME = new java.awt.geom.Area(BACK); LED_TRACK_FRAME.subtract(new java.awt.geom.Area(BACK_SUB)); final Point2D LED_TRACK_FRAME_START = new Point2D.Double(0, LED_TRACK_FRAME.getBounds2D().getMinY()); final Point2D LED_TRACK_FRAME_STOP = new Point2D.Double(0, LED_TRACK_FRAME.getBounds2D().getMaxY()); final float[] LED_TRACK_FRAME_FRACTIONS = {0.0f, 0.22f, 0.76f, 1.0f}; final Color[] LED_TRACK_FRAME_COLORS = { new Color(0, 0, 0, 255), new Color(51, 51, 51, 255), new Color(51, 51, 51, 255), new Color(100, 100, 100, 255) }; final LinearGradientPaint LED_TRACK_FRAME_GRADIENT = new LinearGradientPaint( LED_TRACK_FRAME_START, LED_TRACK_FRAME_STOP, LED_TRACK_FRAME_FRACTIONS, LED_TRACK_FRAME_COLORS); G2.setPaint(LED_TRACK_FRAME_GRADIENT); G2.fill(LED_TRACK_FRAME); final java.awt.geom.Arc2D FRONT = new java.awt.geom.Arc2D.Double(java.awt.geom.Arc2D.PIE); FRONT.setFrame( IMAGE_WIDTH * 0.1121495327, IMAGE_HEIGHT * 0.1121495327, IMAGE_WIDTH * 0.7803738318, IMAGE_HEIGHT * 0.7803738318); FRONT.setAngleStart(START_ANGLE); FRONT.setAngleExtent(ANGLE_EXTEND); final Ellipse2D FRONT_SUB = new Ellipse2D.Double( IMAGE_WIDTH * 0.1822429907, IMAGE_HEIGHT * 0.1822429907, IMAGE_WIDTH * 0.6448598131, IMAGE_HEIGHT * 0.6448598131); final java.awt.geom.Area LED_TRACK_MAIN = new java.awt.geom.Area(BACK); LED_TRACK_MAIN.subtract(new java.awt.geom.Area(FRONT_SUB)); final Point2D LED_TRACK_MAIN_START = new Point2D.Double(0, LED_TRACK_MAIN.getBounds2D().getMinY()); final Point2D LED_TRACK_MAIN_STOP = new Point2D.Double(0, LED_TRACK_MAIN.getBounds2D().getMaxY()); final float[] LED_TRACK_MAIN_FRACTIONS = {0.0f, 1.0f}; final Color[] LED_TRACK_MAIN_COLORS = {new Color(17, 17, 17, 255), new Color(51, 51, 51, 255)}; final LinearGradientPaint LED_TRACK_MAIN_GRADIENT = new LinearGradientPaint( LED_TRACK_MAIN_START, LED_TRACK_MAIN_STOP, LED_TRACK_MAIN_FRACTIONS, LED_TRACK_MAIN_COLORS); G2.setPaint(LED_TRACK_MAIN_GRADIENT); G2.fill(LED_TRACK_MAIN); // Draw the inactive leds final Point2D CENTER = new Point2D.Double(WIDTH / 2.0, WIDTH / 2.0); final Rectangle2D LED = new Rectangle2D.Double( WIDTH * 0.1168224299, WIDTH * 0.4859813084, WIDTH * 0.06074766355140187, WIDTH * 0.023364486); final Point2D LED_CENTER = new Point2D.Double(LED.getCenterX(), LED.getCenterY()); final Color[] LED_COLORS = new Color[] {new Color(60, 60, 60, 255), new Color(50, 50, 50, 255)}; final RadialGradientPaint LED_GRADIENT = new RadialGradientPaint( LED_CENTER, (float) (0.030373831775700934 * IMAGE_WIDTH), LED_FRACTIONS, LED_COLORS); G2.setPaint(LED_GRADIENT); final AffineTransform OLD_TRANSFORM = G2.getTransform(); for (double angle = 0; angle <= APEX_ANGLE; angle += 5.0) { G2.rotate(Math.toRadians(angle + BARGRAPH_OFFSET), CENTER.getX(), CENTER.getY()); G2.fill(LED); G2.setTransform(OLD_TRANSFORM); } G2.dispose(); return image; }