Java Code Examples for java.awt.geom.Rectangle2D#getCenterY()

The following examples show how to use java.awt.geom.Rectangle2D#getCenterY() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MeterPlot.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the value label just below the center of the dial.
 *
 * @param g2  the graphics device.
 * @param area  the plot area.
 */
protected void drawValueLabel(Graphics2D g2, Rectangle2D area) {
    g2.setFont(this.valueFont);
    g2.setPaint(this.valuePaint);
    String valueStr = "No value";
    if (this.dataset != null) {
        Number n = this.dataset.getValue();
        if (n != null) {
            valueStr = this.tickLabelFormat.format(n.doubleValue()) + " "
                     + this.units;
        }
    }
    float x = (float) area.getCenterX();
    float y = (float) area.getCenterY() + DEFAULT_CIRCLE_SIZE;
    TextUtilities.drawAlignedString(valueStr, g2, x, y,
            TextAnchor.TOP_CENTER);
}
 
Example 2
Source File: Cardumen_007_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Returns a rectangle that encloses the axis label.  This is typically 
 * used for layout purposes (it gives the maximum dimensions of the label).
 *
 * @param g2  the graphics device.
 * @param edge  the edge of the plot area along which the axis is measuring.
 *
 * @return The enclosing rectangle.
 */
protected Rectangle2D getLabelEnclosure(Graphics2D g2, RectangleEdge edge) {

    Rectangle2D result = new Rectangle2D.Double();
    String axisLabel = getLabel();
    if (axisLabel != null && !axisLabel.equals("")) {
        FontMetrics fm = g2.getFontMetrics(getLabelFont());
        Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm);
        RectangleInsets insets = getLabelInsets();
        bounds = insets.createOutsetRectangle(bounds);
        double angle = getLabelAngle();
        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
            angle = angle - Math.PI / 2.0;
        }
        double x = bounds.getCenterX();
        double y = bounds.getCenterY();
        AffineTransform transformer 
            = AffineTransform.getRotateInstance(angle, x, y);
        Shape labelBounds = transformer.createTransformedShape(bounds);
        result = labelBounds.getBounds2D();
    }

    return result;

}
 
Example 3
Source File: Blob2D.java    From energy2d with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void rotateBy(float degree) {
	Rectangle2D r = path.getBounds2D();
	double cx = r.getCenterX();
	double cy = r.getCenterY();
	double a = Math.toRadians(degree);
	double sin = Math.sin(a);
	double cos = Math.cos(a);
	double dx = 0;
	double dy = 0;
	for (Point2D.Float v : points) {
		dx = v.x - cx;
		dy = v.y - cy;
		v.x = (float) (dx * cos - dy * sin + cx);
		v.y = (float) (dx * sin + dy * cos + cy);
	}
}
 
Example 4
Source File: BoundsTree.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
     * Adds a rectangular bounds to the tree and updates the root bounds.
     *
     * @param label
     * @param bounds the bounding box of the
     */
    public void add(String label, Rectangle2D bounds) {
        // don't add empty bounding boxes to the root
        boolean isEmpty = (bounds.getCenterX() == 0 && bounds.getCenterY() == 0
                && bounds.getWidth() == 0 && bounds.getHeight() == 0);

        childMap.put(label, bounds);
        if (root == null && !isEmpty) {
            root = new Rectangle2D.Double(
                    bounds.getMinX(), bounds.getMinY(),
                    bounds.getWidth(), bounds.getHeight());
            childMap.put(rootLabel, root);
        } else if (!isEmpty) {
            root.add(bounds);
        }
        if (root != null) {
//            System.out.println("root " + BoundsPrinter.toString(root) + " added " + BoundsPrinter.toString(bounds) + " " + label);
        }
    }
 
Example 5
Source File: Cardumen_007_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Returns a rectangle that encloses the axis label.  This is typically 
 * used for layout purposes (it gives the maximum dimensions of the label).
 *
 * @param g2  the graphics device.
 * @param edge  the edge of the plot area along which the axis is measuring.
 *
 * @return The enclosing rectangle.
 */
protected Rectangle2D getLabelEnclosure(Graphics2D g2, RectangleEdge edge) {

    Rectangle2D result = new Rectangle2D.Double();
    String axisLabel = getLabel();
    if (axisLabel != null && !axisLabel.equals("")) {
        FontMetrics fm = g2.getFontMetrics(getLabelFont());
        Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm);
        RectangleInsets insets = getLabelInsets();
        bounds = insets.createOutsetRectangle(bounds);
        double angle = getLabelAngle();
        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
            angle = angle - Math.PI / 2.0;
        }
        double x = bounds.getCenterX();
        double y = bounds.getCenterY();
        AffineTransform transformer 
            = AffineTransform.getRotateInstance(angle, x, y);
        Shape labelBounds = transformer.createTransformedShape(bounds);
        result = labelBounds.getBounds2D();
    }

    return result;

}
 
Example 6
Source File: Axis.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a rectangle that encloses the axis label.  This is typically
 * used for layout purposes (it gives the maximum dimensions of the label).
 *
 * @param g2  the graphics device.
 * @param edge  the edge of the plot area along which the axis is measuring.
 *
 * @return The enclosing rectangle.
 */
protected Rectangle2D getLabelEnclosure(Graphics2D g2, RectangleEdge edge) {

    Rectangle2D result = new Rectangle2D.Double();
    String axisLabel = getLabel();
    if (axisLabel != null && !axisLabel.equals("")) {
        FontMetrics fm = g2.getFontMetrics(getLabelFont());
        Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm);
        RectangleInsets insets = getLabelInsets();
        bounds = insets.createOutsetRectangle(bounds);
        double angle = getLabelAngle();
        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
            angle = angle - Math.PI / 2.0;
        }
        double x = bounds.getCenterX();
        double y = bounds.getCenterY();
        AffineTransform transformer
            = AffineTransform.getRotateInstance(angle, x, y);
        Shape labelBounds = transformer.createTransformedShape(bounds);
        result = labelBounds.getBounds2D();
    }

    return result;

}
 
Example 7
Source File: Cardumen_00144_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Returns a rectangle that encloses the axis label.  This is typically 
 * used for layout purposes (it gives the maximum dimensions of the label).
 *
 * @param g2  the graphics device.
 * @param edge  the edge of the plot area along which the axis is measuring.
 *
 * @return The enclosing rectangle.
 */
protected Rectangle2D getLabelEnclosure(Graphics2D g2, RectangleEdge edge) {

    Rectangle2D result = new Rectangle2D.Double();
    String axisLabel = getLabel();
    if (axisLabel != null && !axisLabel.equals("")) {
        FontMetrics fm = g2.getFontMetrics(getLabelFont());
        Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm);
        RectangleInsets insets = getLabelInsets();
        bounds = insets.createOutsetRectangle(bounds);
        double angle = getLabelAngle();
        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
            angle = angle - Math.PI / 2.0;
        }
        double x = bounds.getCenterX();
        double y = bounds.getCenterY();
        AffineTransform transformer 
            = AffineTransform.getRotateInstance(angle, x, y);
        Shape labelBounds = transformer.createTransformedShape(bounds);
        result = labelBounds.getBounds2D();
    }

    return result;

}
 
Example 8
Source File: DialPointer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the pointer.
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
    Rectangle2D view) {

    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,
            this.radius, this.radius);

    double value = plot.getValue(this.datasetIndex);
    DialScale scale = plot.getScaleForDataset(this.datasetIndex);
    double angle = scale.valueToAngle(value);

    Arc2D arc = new Arc2D.Double(arcRect, angle, 0, Arc2D.OPEN);
    Point2D pt = arc.getEndPoint();

    Line2D line = new Line2D.Double(frame.getCenterX(),
            frame.getCenterY(), pt.getX(), pt.getY());
    g2.draw(line);
}
 
Example 9
Source File: RadialGradientPaint.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static AffineTransform createGradientTransform(Rectangle2D r) {
    double cx = r.getCenterX();
    double cy = r.getCenterY();
    AffineTransform xform = AffineTransform.getTranslateInstance(cx, cy);
    xform.scale(r.getWidth()/2, r.getHeight()/2);
    xform.translate(-cx, -cy);
    return xform;
}
 
Example 10
Source File: SurveyScaleLegendItem.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Draws the legend item.
 *
 * @param g2
 *          the graphic device.
 * @param area
 *          the area.
 */
public void draw( final Graphics2D g2, final Rectangle2D area ) {
  if ( shape == null || font == null || label == null ) {
    return;
  }
  if ( draw == false && fill == false ) {
    return;
  }

  final Rectangle2D b = this.shape.getBounds2D();
  double x = area.getMinX() + b.getWidth() / 2.0 + 1.0;
  final double y = area.getCenterY();
  final Shape s = getShape();
  g2.translate( x, y );
  g2.setPaint( Color.black );
  if ( this.draw ) {
    g2.setStroke( new BasicStroke( 0.5f ) );
    g2.draw( s );
  }
  if ( this.fill ) {
    g2.fill( s );
  }
  g2.translate( -x, -y );
  x += b.getWidth() / 2.0 + 3.0;
  g2.setFont( this.font );

  final FontRenderContext frc = g2.getFontRenderContext();
  final Font f = g2.getFont();
  // final FontMetrics fm = g2.getFontMetrics(f);
  final LineMetrics metrics = f.getLineMetrics( label, frc );
  final float ascent = metrics.getAscent();
  final float halfAscent = ascent / 2.0f;
  g2.drawString( label, (float) x, (float) ( y + halfAscent ) );
}
 
Example 11
Source File: Cardumen_00193_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Creates a rectangle that is aligned to the frame.
 * 
 * @param dimensions  the dimensions for the rectangle.
 * @param frame  the frame to align to.
 * @param hAlign  the horizontal alignment.
 * @param vAlign  the vertical alignment.
 * 
 * @return A rectangle.
 */
private Rectangle2D createAlignedRectangle2D(Size2D dimensions, 
        Rectangle2D frame, HorizontalAlignment hAlign, 
        VerticalAlignment vAlign) {
    double x = Double.NaN;
    double y = Double.NaN;
    if (hAlign == HorizontalAlignment.LEFT) {
        x = frame.getX();   
    }
    else if (hAlign == HorizontalAlignment.CENTER) {
        x = frame.getCenterX() - (dimensions.width / 2.0);   
    }
    else if (hAlign == HorizontalAlignment.RIGHT) {
        x = frame.getMaxX() - dimensions.width;   
    }
    if (vAlign == VerticalAlignment.TOP) {
        y = frame.getY();   
    }
    else if (vAlign == VerticalAlignment.CENTER) {
        y = frame.getCenterY() - (dimensions.height / 2.0);   
    }
    else if (vAlign == VerticalAlignment.BOTTOM) {
        y = frame.getMaxY() - dimensions.height;   
    }
    
    return new Rectangle2D.Double(x, y, dimensions.width, 
            dimensions.height);
}
 
Example 12
Source File: RadialGradientPaint.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
private static AffineTransform createGradientTransform(Rectangle2D r) {
    double cx = r.getCenterX();
    double cy = r.getCenterY();
    AffineTransform xform = AffineTransform.getTranslateInstance(cx, cy);
    xform.scale(r.getWidth()/2, r.getHeight()/2);
    xform.translate(-cx, -cy);
    return xform;
}
 
Example 13
Source File: RefractiveTransition2D.java    From pumpernickel with MIT License 4 votes vote down vote up
@Override
public Transition2DInstruction[] getInstructions(float progress,
		Dimension size) {
	List<Rectangle2D> v1 = new ArrayList<Rectangle2D>();
	List<Transition2DInstruction> v2 = new ArrayList<Transition2DInstruction>();

	float factor = .05f;

	float ySize = (size.height) * factor;
	float xSize = (size.width) * factor;
	for (float y = 0; y < size.height; y += ySize) {
		for (float x = 0; x < size.width; x += xSize) {
			v1.add(new Rectangle2D.Float(x, y, xSize, ySize));
		}
	}

	Point2D p1, p2;
	// 1 -> 0, 0 -> PI,
	float angleProgress = (float) ((1 - Math.pow(progress, .2)));
	v2.add(new ImageInstruction(true));
	for (int a = 0; a < v1.size(); a++) {
		try {
			Rectangle2D r = v1.get(a);
			p1 = new Point2D.Double(r.getCenterX(), r.getCenterY());
			AffineTransform transform = new AffineTransform();

			transform.setToRotation(-2 * Math.PI * angleProgress,
					size.width / 2, size.height / 2);
			transform.translate(size.width / 2, size.height / 2);
			transform.scale(progress, progress);
			transform.translate(-size.width / 2, -size.height / 2);

			p2 = new Point2D.Double();
			transform.transform(p1, p2);
			transform.setToTranslation(p2.getX() - p1.getX(), p2.getY()
					- p1.getY());
			v2.add(new ImageInstruction(false, (float) (Math.pow(progress,
					.4)), transform.createInverse(), r));

			transform.setToRotation(2 * Math.PI * angleProgress,
					size.width / 2, size.height / 2);

			p2 = new Point2D.Double();
			transform.transform(p1, p2);
			transform.setToTranslation(p2.getX() - p1.getX(), p2.getY()
					- p1.getY());
			v2.add(new ImageInstruction(false, progress * progress,
					transform.createInverse(), r));
		} catch (Exception e) {

		}
	}
	return v2.toArray(new Transition2DInstruction[v2.size()]);
}
 
Example 14
Source File: RadialGradientPaint.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Constructs a {@code RadialGradientPaint} with a default
 * {@code SRGB} color space.
 * The gradient circle of the {@code RadialGradientPaint} is defined
 * by the given bounding box.
 * <p>
 * This constructor is a more convenient way to express the
 * following (equivalent) code:<br>
 *
 * <pre>
 *     double gw = gradientBounds.getWidth();
 *     double gh = gradientBounds.getHeight();
 *     double cx = gradientBounds.getCenterX();
 *     double cy = gradientBounds.getCenterY();
 *     Point2D center = new Point2D.Double(cx, cy);
 *
 *     AffineTransform gradientTransform = new AffineTransform();
 *     gradientTransform.translate(cx, cy);
 *     gradientTransform.scale(gw / 2, gh / 2);
 *     gradientTransform.translate(-cx, -cy);
 *
 *     RadialGradientPaint gp =
 *         new RadialGradientPaint(center, 1.0f, center,
 *                                 fractions, colors,
 *                                 cycleMethod,
 *                                 ColorSpaceType.SRGB,
 *                                 gradientTransform);
 * </pre>
 *
 * @param gradientBounds the bounding box, in user space, of the circle
 *                       defining the outermost extent of the gradient
 * @param fractions numbers ranging from 0.0 to 1.0 specifying the
 *                  distribution of colors along the gradient
 * @param colors array of colors to use in the gradient.  The first color
 *               is used at the focus point, the last color around the
 *               perimeter of the circle.
 * @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT},
 *                    or {@code REPEAT}
 *
 * @throws NullPointerException
 * if {@code gradientBounds} is null,
 * or {@code fractions} array is null,
 * or {@code colors} array is null,
 * or {@code cycleMethod} is null
 * @throws IllegalArgumentException
 * if {@code gradientBounds} is empty,
 * or {@code fractions.length != colors.length},
 * or {@code colors} is less than 2 in size,
 * or a {@code fractions} value is less than 0.0 or greater than 1.0,
 * or the {@code fractions} are not provided in strictly increasing order
 */
public RadialGradientPaint(Rectangle2D gradientBounds,
                           float[] fractions, Color[] colors,
                           CycleMethod cycleMethod)
{
    // gradient center/focal point is the center of the bounding box,
    // radius is set to 1.0, and then we set a scale transform
    // to achieve an elliptical gradient defined by the bounding box
    this(new Point2D.Double(gradientBounds.getCenterX(),
                            gradientBounds.getCenterY()),
         1.0f,
         new Point2D.Double(gradientBounds.getCenterX(),
                            gradientBounds.getCenterY()),
         fractions,
         colors,
         cycleMethod,
         ColorSpaceType.SRGB,
         createGradientTransform(gradientBounds));

    if (gradientBounds.isEmpty()) {
        throw new IllegalArgumentException("Gradient bounds must be " +
                                           "non-empty");
    }
}
 
Example 15
Source File: MeterPlot.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws a tick on the dial.
 *
 * @param g2  the graphics device.
 * @param meterArea  the meter area.
 * @param value  the tick value.
 * @param label  a flag that controls whether or not a value label is drawn.
 */
protected void drawTick(Graphics2D g2, Rectangle2D meterArea,
                        double value, boolean label) {

    double valueAngle = valueToAngle(value);

    double meterMiddleX = meterArea.getCenterX();
    double meterMiddleY = meterArea.getCenterY();

    g2.setPaint(this.tickPaint);
    g2.setStroke(new BasicStroke(2.0f));

    double valueP2X;
    double valueP2Y;

    double radius = (meterArea.getWidth() / 2) + DEFAULT_BORDER_SIZE;
    double radius1 = radius - 15;

    double valueP1X = meterMiddleX
            + (radius * Math.cos(Math.PI * (valueAngle / 180)));
    double valueP1Y = meterMiddleY
            - (radius * Math.sin(Math.PI * (valueAngle / 180)));

    valueP2X = meterMiddleX
            + (radius1 * Math.cos(Math.PI * (valueAngle / 180)));
    valueP2Y = meterMiddleY
            - (radius1 * Math.sin(Math.PI * (valueAngle / 180)));

    Line2D.Double line = new Line2D.Double(valueP1X, valueP1Y, valueP2X,
            valueP2Y);
    g2.draw(line);

    if (this.tickLabelsVisible && label) {

        String tickLabel =  this.tickLabelFormat.format(value);
        g2.setFont(this.tickLabelFont);
        g2.setPaint(this.tickLabelPaint);

        FontMetrics fm = g2.getFontMetrics();
        Rectangle2D tickLabelBounds
            = TextUtilities.getTextBounds(tickLabel, g2, fm);

        double x = valueP2X;
        double y = valueP2Y;
        if (valueAngle == 90 || valueAngle == 270) {
            x = x - tickLabelBounds.getWidth() / 2;
        }
        else if (valueAngle < 90 || valueAngle > 270) {
            x = x - tickLabelBounds.getWidth();
        }
        if ((valueAngle > 135 && valueAngle < 225)
                || valueAngle > 315 || valueAngle < 45) {
            y = y - tickLabelBounds.getHeight() / 2;
        }
        else {
            y = y + tickLabelBounds.getHeight() / 2;
        }
        g2.drawString(tickLabel, (float) x, (float) y);
    }
}
 
Example 16
Source File: PolarPlot.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a
 * printer).
 * <P>
 * This plot relies on a {@link PolarItemRenderer} to draw each
 * item in the plot.  This allows the visual representation of the data to
 * be changed easily.
 * <P>
 * The optional info argument collects information about the rendering of
 * the plot (dimensions, tooltip information etc).  Just pass in
 * <code>null</code> if you do not need this information.
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot (including axes and
 *              labels) should be drawn.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param parentState  ignored.
 * @param info  collects chart drawing information (<code>null</code>
 *              permitted).
 */
public void draw(Graphics2D g2,
                 Rectangle2D area,
                 Point2D anchor,
                 PlotState parentState,
                 PlotRenderingInfo info) {

    // if the plot area is too small, just return...
    boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
    boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
    if (b1 || b2) {
        return;
    }

    // record the plot area...
    if (info != null) {
        info.setPlotArea(area);
    }

    // adjust the drawing area for the plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);

    Rectangle2D dataArea = area;
    if (info != null) {
        info.setDataArea(dataArea);
    }

    // draw the plot background and axes...
    drawBackground(g2, dataArea);
    double h = Math.min(dataArea.getWidth() / 2.0,
            dataArea.getHeight() / 2.0) - MARGIN;
    Rectangle2D quadrant = new Rectangle2D.Double(dataArea.getCenterX(),
            dataArea.getCenterY(), h, h);
    AxisState state = drawAxis(g2, area, quadrant);
    if (this.renderer != null) {
        Shape originalClip = g2.getClip();
        Composite originalComposite = g2.getComposite();

        g2.clip(dataArea);
        g2.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, getForegroundAlpha()));

        this.angleTicks = refreshAngleTicks();
        drawGridlines(g2, dataArea, this.angleTicks, state.getTicks());

        // draw...
        render(g2, dataArea, info);

        g2.setClip(originalClip);
        g2.setComposite(originalComposite);
    }
    drawOutline(g2, dataArea);
    drawCornerTextItems(g2, dataArea);
}
 
Example 17
Source File: RadialGradientPaint.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a {@code RadialGradientPaint} with a default
 * {@code SRGB} color space.
 * The gradient circle of the {@code RadialGradientPaint} is defined
 * by the given bounding box.
 * <p>
 * This constructor is a more convenient way to express the
 * following (equivalent) code:<br>
 *
 * <pre>
 *     double gw = gradientBounds.getWidth();
 *     double gh = gradientBounds.getHeight();
 *     double cx = gradientBounds.getCenterX();
 *     double cy = gradientBounds.getCenterY();
 *     Point2D center = new Point2D.Double(cx, cy);
 *
 *     AffineTransform gradientTransform = new AffineTransform();
 *     gradientTransform.translate(cx, cy);
 *     gradientTransform.scale(gw / 2, gh / 2);
 *     gradientTransform.translate(-cx, -cy);
 *
 *     RadialGradientPaint gp =
 *         new RadialGradientPaint(center, 1.0f, center,
 *                                 fractions, colors,
 *                                 cycleMethod,
 *                                 ColorSpaceType.SRGB,
 *                                 gradientTransform);
 * </pre>
 *
 * @param gradientBounds the bounding box, in user space, of the circle
 *                       defining the outermost extent of the gradient
 * @param fractions numbers ranging from 0.0 to 1.0 specifying the
 *                  distribution of colors along the gradient
 * @param colors array of colors to use in the gradient.  The first color
 *               is used at the focus point, the last color around the
 *               perimeter of the circle.
 * @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT},
 *                    or {@code REPEAT}
 *
 * @throws NullPointerException
 * if {@code gradientBounds} is null,
 * or {@code fractions} array is null,
 * or {@code colors} array is null,
 * or {@code cycleMethod} is null
 * @throws IllegalArgumentException
 * if {@code gradientBounds} is empty,
 * or {@code fractions.length != colors.length},
 * or {@code colors} is less than 2 in size,
 * or a {@code fractions} value is less than 0.0 or greater than 1.0,
 * or the {@code fractions} are not provided in strictly increasing order
 */
public RadialGradientPaint(Rectangle2D gradientBounds,
                           float[] fractions, Color[] colors,
                           CycleMethod cycleMethod)
{
    // gradient center/focal point is the center of the bounding box,
    // radius is set to 1.0, and then we set a scale transform
    // to achieve an elliptical gradient defined by the bounding box
    this(new Point2D.Double(gradientBounds.getCenterX(),
                            gradientBounds.getCenterY()),
         1.0f,
         new Point2D.Double(gradientBounds.getCenterX(),
                            gradientBounds.getCenterY()),
         fractions,
         colors,
         cycleMethod,
         ColorSpaceType.SRGB,
         createGradientTransform(gradientBounds));

    if (gradientBounds.isEmpty()) {
        throw new IllegalArgumentException("Gradient bounds must be " +
                                           "non-empty");
    }
}
 
Example 18
Source File: VisualComponent.java    From workcraft with MIT License 4 votes vote down vote up
public Point2D getOffset(Positioning positioning) {
    Rectangle2D bb = getInternalBoundingBoxInLocalSpace();
    double xOffset = (positioning.xSign < 0) ? bb.getMinX() : (positioning.xSign > 0) ? bb.getMaxX() : bb.getCenterX();
    double yOffset = (positioning.ySign < 0) ? bb.getMinY() : (positioning.ySign > 0) ? bb.getMaxY() : bb.getCenterY();
    return new Point2D.Double(xOffset, yOffset);
}
 
Example 19
Source File: MeterPlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws a tick on the dial.
 *
 * @param g2  the graphics device.
 * @param meterArea  the meter area.
 * @param value  the tick value.
 * @param label  a flag that controls whether or not a value label is drawn.
 */
protected void drawTick(Graphics2D g2, Rectangle2D meterArea,
                        double value, boolean label) {

    double valueAngle = valueToAngle(value);

    double meterMiddleX = meterArea.getCenterX();
    double meterMiddleY = meterArea.getCenterY();

    g2.setPaint(this.tickPaint);
    g2.setStroke(new BasicStroke(2.0f));

    double valueP2X;
    double valueP2Y;

    double radius = (meterArea.getWidth() / 2) + DEFAULT_BORDER_SIZE;
    double radius1 = radius - 15;

    double valueP1X = meterMiddleX
            + (radius * Math.cos(Math.PI * (valueAngle / 180)));
    double valueP1Y = meterMiddleY
            - (radius * Math.sin(Math.PI * (valueAngle / 180)));

    valueP2X = meterMiddleX
            + (radius1 * Math.cos(Math.PI * (valueAngle / 180)));
    valueP2Y = meterMiddleY
            - (radius1 * Math.sin(Math.PI * (valueAngle / 180)));

    Line2D.Double line = new Line2D.Double(valueP1X, valueP1Y, valueP2X,
            valueP2Y);
    g2.draw(line);

    if (this.tickLabelsVisible && label) {

        String tickLabel =  this.tickLabelFormat.format(value);
        g2.setFont(this.tickLabelFont);
        g2.setPaint(this.tickLabelPaint);

        FontMetrics fm = g2.getFontMetrics();
        Rectangle2D tickLabelBounds
            = TextUtilities.getTextBounds(tickLabel, g2, fm);

        double x = valueP2X;
        double y = valueP2Y;
        if (valueAngle == 90 || valueAngle == 270) {
            x = x - tickLabelBounds.getWidth() / 2;
        }
        else if (valueAngle < 90 || valueAngle > 270) {
            x = x - tickLabelBounds.getWidth();
        }
        if ((valueAngle > 135 && valueAngle < 225)
                || valueAngle > 315 || valueAngle < 45) {
            y = y - tickLabelBounds.getHeight() / 2;
        }
        else {
            y = y + tickLabelBounds.getHeight() / 2;
        }
        g2.drawString(tickLabel, (float) x, (float) y);
    }
}
 
Example 20
Source File: BlockToNbhd.java    From data-polygamy with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void readBlockData(FSDataInputStream fis) throws IOException {
    
    int id = 0;
    
    try {
        BufferedReader buff = new BufferedReader(new InputStreamReader(fis));
        String line = buff.readLine();
        
        ArrayList<Double> xPoints = new ArrayList<Double>();
        ArrayList<Double> yPoints = new ArrayList<Double>();
        
        while (line != null) {
            buff.readLine();
            Integer nbPoints = Integer.parseInt(buff.readLine());
            
            xPoints = new ArrayList<Double>(nbPoints);
            yPoints = new ArrayList<Double>(nbPoints);
            for (int i = 0; i < nbPoints; i++) {
                String[] points = buff.readLine().split(" ");
                xPoints.add(Double.parseDouble(points[0]));
                yPoints.add(Double.parseDouble(points[1]));
            }
            
            // creating polygon
            Path2D polygon = new Path2D.Double();
            polygon.moveTo(xPoints.get(0), yPoints.get(0));
            for (int i = 1; i < xPoints.size(); ++i) {
                polygon.lineTo(xPoints.get(i), yPoints.get(i));
            }
            polygon.closePath();
            
            Rectangle2D rect = polygon.getBounds2D();
            double x = rect.getCenterX();
            double y = rect.getCenterY();
            
            int r = grid.getRegion(x, y);
            if(r != -1) {
                blockRegions.put(id, nbhdRegionNames.get(r));
            }
            
            id++;
            line = buff.readLine();
        }
        
        buff.close();
        
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        fis.close();
    }
}