/** * Returns the FontBBox value as integer array. * @return the font's bounding box */ public int[] getFontBBoxAsIntArray() { RectangularShape rect = getFontBBox(); return new int[] { (int)Math.floor(rect.getMinX()), (int)Math.floor(rect.getMinY()), (int)Math.ceil(rect.getMaxX()), (int)Math.ceil(rect.getMaxY())}; }
/** * Returns the minimum <var>y</var> coordinate of the rectangle * (the logical coordinate, not the pixel coordinate). */ public double getMinY() { return logicalShape.getMinY(); }
/** * Returns the FontBBox value as integer array. * @return the font's bounding box */ public int[] getFontBBoxAsIntArray() { RectangularShape rect = getFontBBox(); return new int[] { (int)Math.floor(rect.getMinX()), (int)Math.floor(rect.getMinY()), (int)Math.ceil(rect.getMaxX()), (int)Math.ceil(rect.getMaxY())}; }
/** * Returns the FontBBox value as integer array. * @return the font's bounding box */ public int[] getFontBBoxAsIntArray() { RectangularShape rect = getFontBBox(); return new int[] { (int)Math.floor(rect.getMinX()), (int)Math.floor(rect.getMinY()), (int)Math.ceil(rect.getMaxX()), (int)Math.ceil(rect.getMaxY())}; }
String s = "S"; // always a single character! Rectangle rect = getRect(); // defines the desired size and position FontMetrics fm = g2d.getFontMetrics(); FontRenderContext frc = g2d.getFontRenderContext(); TextLayout tl = new TextLayout(s, g2d.getFont(), frc); AffineTransform transform = new AffineTransform(); transform.setToTranslation(rect.getX(), rect.getY()); double scaleY = rect.getHeight() / (double) (tl.getOutline(null).getBounds().getMaxY() - tl.getOutline(null).getBounds().getMinY()); transform.scale(rect.getWidth() / (double) fm.stringWidth(s), scaleY); Shape shape = tl.getOutline(transform); g2d.setClip(shape); g2d.fill(shape.getBounds());
/** * Splits a bar into subregions (elsewhere, these subregions will have * different gradients applied to them). * * @param bar the bar shape. * @param a the first division. * @param b the second division. * @param c the third division. * * @return An array containing four subregions. */ private Rectangle2D[] splitVerticalBar(RectangularShape bar, double a, double b, double c) { Rectangle2D[] result = new Rectangle2D[4]; double x0 = bar.getMinX(); double x1 = Math.rint(x0 + (bar.getWidth() * a)); double x2 = Math.rint(x0 + (bar.getWidth() * b)); double x3 = Math.rint(x0 + (bar.getWidth() * c)); result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), x1 - x0, bar.getHeight()); result[1] = new Rectangle2D.Double(x1, bar.getMinY(), x2 - x1, bar.getHeight()); result[2] = new Rectangle2D.Double(x2, bar.getMinY(), x3 - x2, bar.getHeight()); result[3] = new Rectangle2D.Double(x3, bar.getMinY(), bar.getMaxX() - x3, bar.getHeight()); return result; }
/** * Splits a bar into subregions (elsewhere, these subregions will have * different gradients applied to them). * * @param bar the bar shape. * @param a the first division. * @param b the second division. * @param c the third division. * * @return An array containing four subregions. */ private Rectangle2D[] splitVerticalBar(RectangularShape bar, double a, double b, double c) { Rectangle2D[] result = new Rectangle2D[4]; double x0 = bar.getMinX(); double x1 = Math.rint(x0 + (bar.getWidth() * a)); double x2 = Math.rint(x0 + (bar.getWidth() * b)); double x3 = Math.rint(x0 + (bar.getWidth() * c)); result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), x1 - x0, bar.getHeight()); result[1] = new Rectangle2D.Double(x1, bar.getMinY(), x2 - x1, bar.getHeight()); result[2] = new Rectangle2D.Double(x2, bar.getMinY(), x3 - x2, bar.getHeight()); result[3] = new Rectangle2D.Double(x3, bar.getMinY(), bar.getMaxX() - x3, bar.getHeight()); return result; }
/** * Splits a bar into subregions (elsewhere, these subregions will have * different gradients applied to them). * * @param bar the bar shape. * @param a the first division. * @param b the second division. * @param c the third division. * * @return An array containing four subregions. */ private Rectangle2D[] splitVerticalBar(RectangularShape bar, double a, double b, double c) { Rectangle2D[] result = new Rectangle2D[4]; double x0 = bar.getMinX(); double x1 = Math.rint(x0 + (bar.getWidth() * a)); double x2 = Math.rint(x0 + (bar.getWidth() * b)); double x3 = Math.rint(x0 + (bar.getWidth() * c)); result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), x1 - x0, bar.getHeight()); result[1] = new Rectangle2D.Double(x1, bar.getMinY(), x2 - x1, bar.getHeight()); result[2] = new Rectangle2D.Double(x2, bar.getMinY(), x3 - x2, bar.getHeight()); result[3] = new Rectangle2D.Double(x3, bar.getMinY(), bar.getMaxX() - x3, bar.getHeight()); return result; }
protected boolean isSelected(RectangularShape rectangle, float mouseX, float mouseY) { return mouseX >= rectangle.getMinX() && mouseY >= rectangle.getMinY() && mouseX < rectangle.getMaxX() && mouseY < rectangle.getMaxY(); }
@Override public void mouseWheelMoved(MouseWheelEvent e) { if (e.isConsumed()) { return; } Point2D.Double mouseLoc = new Point2D.Double(e.getPoint().x, e.getPoint().y); // ensure the point is within the window RectangularShape bounds = component.getBounds(); mouseLoc.x = Math.max(mouseLoc.x, bounds.getMinX()); mouseLoc.x = Math.min(mouseLoc.x, bounds.getMaxX()); mouseLoc.y = Math.max(mouseLoc.y, bounds.getMinY()); mouseLoc.y = Math.min(mouseLoc.y, bounds.getMaxY()); zoomPoint(component, component.toGraphicCoordinate(mouseLoc), (e.getWheelRotation() > 0) ? 1.05 : 0.95); }
/** * Called each time the position of the rectangle is adjusted. This * method will adjust the value displayed in the text field * based on the position of the rectangle. */ private void updateText(final JFormattedTextField editor) { String text; if (!logicalShape.isEmpty() || ((text = editor.getText()) != null && text.trim().length() != 0)) { double value; switch (inverseTransform(side)) { case NORTH: value = logicalShape.getMinY(); break; case SOUTH: value = logicalShape.getMaxY(); break; case WEST: value = logicalShape.getMinX(); break; case EAST: value = logicalShape.getMaxX(); break; default : return; } editor.setValue(isDate ? (Object) new Date(Math.round(value)) : (Object) new Double(value)); } }
/** * Splits a bar into subregions (elsewhere, these subregions will have * different gradients applied to them). * * @param bar the bar shape. * @param a the first division. * @param b the second division. * @param c the third division. * * @return An array containing four subregions. */ private Rectangle2D[] splitHorizontalBar(RectangularShape bar, double a, double b, double c) { Rectangle2D[] result = new Rectangle2D[4]; double y0 = bar.getMinY(); double y1 = Math.rint(y0 + (bar.getHeight() * a)); double y2 = Math.rint(y0 + (bar.getHeight() * b)); double y3 = Math.rint(y0 + (bar.getHeight() * c)); result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), y1 - y0); result[1] = new Rectangle2D.Double(bar.getMinX(), y1, bar.getWidth(), y2 - y1); result[2] = new Rectangle2D.Double(bar.getMinX(), y2, bar.getWidth(), y3 - y2); result[3] = new Rectangle2D.Double(bar.getMinX(), y3, bar.getWidth(), bar.getMaxY() - y3); return result; }
/** * Splits a bar into subregions (elsewhere, these subregions will have * different gradients applied to them). * * @param bar the bar shape. * @param a the first division. * @param b the second division. * @param c the third division. * * @return An array containing four subregions. */ private Rectangle2D[] splitHorizontalBar(RectangularShape bar, double a, double b, double c) { Rectangle2D[] result = new Rectangle2D[4]; double y0 = bar.getMinY(); double y1 = Math.rint(y0 + (bar.getHeight() * a)); double y2 = Math.rint(y0 + (bar.getHeight() * b)); double y3 = Math.rint(y0 + (bar.getHeight() * c)); result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), y1 - y0); result[1] = new Rectangle2D.Double(bar.getMinX(), y1, bar.getWidth(), y2 - y1); result[2] = new Rectangle2D.Double(bar.getMinX(), y2, bar.getWidth(), y3 - y2); result[3] = new Rectangle2D.Double(bar.getMinX(), y3, bar.getWidth(), bar.getMaxY() - y3); return result; }
/** * Splits a bar into subregions (elsewhere, these subregions will have * different gradients applied to them). * * @param bar the bar shape. * @param a the first division. * @param b the second division. * @param c the third division. * * @return An array containing four subregions. */ private Rectangle2D[] splitHorizontalBar(RectangularShape bar, double a, double b, double c) { Rectangle2D[] result = new Rectangle2D[4]; double y0 = bar.getMinY(); double y1 = Math.rint(y0 + (bar.getHeight() * a)); double y2 = Math.rint(y0 + (bar.getHeight() * b)); double y3 = Math.rint(y0 + (bar.getHeight() * c)); result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), y1 - y0); result[1] = new Rectangle2D.Double(bar.getMinX(), y1, bar.getWidth(), y2 - y1); result[2] = new Rectangle2D.Double(bar.getMinX(), y2, bar.getWidth(), y3 - y2); result[3] = new Rectangle2D.Double(bar.getMinX(), y3, bar.getWidth(), bar.getMaxY() - y3); return result; }
/** * Splits a bar into subregions (elsewhere, these subregions will have * different gradients applied to them). * * @param bar the bar shape. * @param a the first division. * @param b the second division. * @param c the third division. * * @return An array containing four subregions. */ private Rectangle2D[] splitHorizontalBar(RectangularShape bar, double a, double b, double c) { Rectangle2D[] result = new Rectangle2D[4]; double y0 = bar.getMinY(); double y1 = Math.rint(y0 + (bar.getHeight() * a)); double y2 = Math.rint(y0 + (bar.getHeight() * b)); double y3 = Math.rint(y0 + (bar.getHeight() * c)); result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), y1 - y0); result[1] = new Rectangle2D.Double(bar.getMinX(), y1, bar.getWidth(), y2 - y1); result[2] = new Rectangle2D.Double(bar.getMinX(), y2, bar.getWidth(), y3 - y2); result[3] = new Rectangle2D.Double(bar.getMinX(), y3, bar.getWidth(), bar.getMaxY() - y3); return result; }
protected void drawOutline(RectangularShape rectangle, int color, double outlineSize) { this.drawOutline(rectangle.getMinX(), rectangle.getMinY(), rectangle.getWidth(), rectangle.getHeight(), color, outlineSize); }
protected void drawTexturedRectangle(RectangularShape rectangle, int color) { this.drawTexturedRectangle(rectangle.getMinX(), rectangle.getMinY(), rectangle.getWidth(), rectangle.getHeight(), color); }
protected void drawRectangle(RectangularShape rectangle, int color) { this.drawRectangle(rectangle.getMinX(), rectangle.getMinY(), rectangle.getWidth(), rectangle.getHeight(), color); }
/** * Update the (x,y) and width height boundary of this view * * Implemented because the canvas has no layout manager */ @Override public void updateBounds() { super.updateBounds(); // TOP-LEFT dragPoints.get(0).setLocation(noteRect.getMinX(), noteRect.getMinY()); // TOP-MIDDLE dragPoints.get(1).setLocation(noteRect.getCenterX(), noteRect.getMinY()); // TOP-RIGHT dragPoints.get(2).setLocation(noteRect.getMaxX(), noteRect.getMinY()); // MIDDLE-RIGHT dragPoints.get(3).setLocation(noteRect.getMaxX(), noteRect.getCenterY()); // BOTTOM-RIGHT dragPoints.get(4).setLocation(noteRect.getMaxX(), noteRect.getMaxY()); // BOTTOM-MIDDLE dragPoints.get(5).setLocation(noteRect.getCenterX(), noteRect.getMaxY()); // BOTTOM-LEFT dragPoints.get(6).setLocation(noteRect.getMinX(), noteRect.getMaxY()); // MIDDLE-LEFT dragPoints.get(7).setLocation(noteRect.getMinX(), noteRect.getCenterY()); }
/** * Asserts that two rectangles have the same location and the same size. * * @param expected the expected rectangle. * @param actual the rectangle to compare with the expected one. * @param tolx the tolerance threshold on location along the <var>x</var> axis. * @param toly the tolerance threshold on location along the <var>y</var> axis. */ public static void assertRectangleEquals(final RectangularShape expected, final RectangularShape actual, final double tolx, final double toly) { assertEquals("Min X", expected.getMinX(), actual.getMinX(), tolx); assertEquals("Min Y", expected.getMinY(), actual.getMinY(), toly); assertEquals("Max X", expected.getMaxX(), actual.getMaxX(), tolx); assertEquals("Max Y", expected.getMaxY(), actual.getMaxY(), toly); assertEquals("Center X", expected.getCenterX(), actual.getCenterX(), tolx); assertEquals("Center Y", expected.getCenterY(), actual.getCenterY(), toly); assertEquals("Width", expected.getWidth(), actual.getWidth(), tolx*2); assertEquals("Height", expected.getHeight(), actual.getHeight(), toly*2); }