Java Draw Arrow drawArrowHead(final Graphics2D aG, final int aXpos, final int aYpos, final int aFactor, final int aArrowWidth, final int aArrowHeight)

Here you can find the source of drawArrowHead(final Graphics2D aG, final int aXpos, final int aYpos, final int aFactor, final int aArrowWidth, final int aArrowHeight)

Description

Draws a single arrow head

License

Open Source License

Parameter

Parameter Description
aG the canvas to draw on;
aXpos the X position of the arrow head;
aYpos the (center) Y position of the arrow head;
aFactor +1 to have a left-facing arrow head, -1 to have a right-facing arrow head;
aArrowWidth the total width of the arrow head;
aArrowHeight the total height of the arrow head.

Declaration

public static final void drawArrowHead(final Graphics2D aG, final int aXpos, final int aYpos, final int aFactor,
        final int aArrowWidth, final int aArrowHeight) 

Method Source Code


//package com.java2s;
/*/*from w ww.j  a  v a2  s  . c  o m*/
 * OpenBench LogicSniffer / SUMP project
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 *
 * 
 * Copyright (C) 2010-2011 - J.W. Janssen, http://www.lxtreme.nl
 */

import java.awt.*;

public class Main {
    /**
     * Draws a single arrow head
     * 
     * @param aG
     *          the canvas to draw on;
     * @param aXpos
     *          the X position of the arrow head;
     * @param aYpos
     *          the (center) Y position of the arrow head;
     * @param aFactor
     *          +1 to have a left-facing arrow head, -1 to have a right-facing
     *          arrow head;
     * @param aArrowWidth
     *          the total width of the arrow head;
     * @param aArrowHeight
     *          the total height of the arrow head.
     */
    public static final void drawArrowHead(final Graphics2D aG, final int aXpos, final int aYpos, final int aFactor,
            final int aArrowWidth, final int aArrowHeight) {
        final double halfHeight = aArrowHeight / 2.0;
        final int x1 = aXpos + (aFactor * aArrowWidth);
        final int y1 = (int) Math.ceil(aYpos - halfHeight);
        final int y2 = (int) Math.floor(aYpos + halfHeight);

        final Polygon arrowHead = new Polygon();
        arrowHead.addPoint(aXpos, aYpos);
        arrowHead.addPoint(x1, y1);
        arrowHead.addPoint(x1, y2);

        aG.fill(arrowHead);
    }
}

Related

  1. drawArrow(Graphics g, Point from, Point to)
  2. drawArrow(Graphics g1, int x1, int y1, int x2, int y2, int lineWidth)
  3. drawArrow(Graphics2D g, Point2D point, double angle, int len)
  4. drawArrow(Graphics2D g2d, double x1, double y1, double x2, double y2)
  5. drawArrow(Graphics2D g2d, int xCenter, int yCenter, int x, int y, float stroke)
  6. drawArrowHead(Graphics g, double c1, double c2, double phi, int l, int grad, boolean fill)
  7. drawArrowLine(Graphics g, int x1, int y1, int x2, int y2, int d, int h, boolean capOnly)
  8. drawArrowLine(Graphics g, int x1, int y1, int x2, int y2, int dist, boolean arrowLeft, boolean arrowRight)
  9. drawDoubleHeadedArrow(final Graphics aG, final int aX1, final int aY, final int aX2)