Java Draw Arrow drawHorizontalArrow(Graphics g, Rectangle r, boolean direction)

Here you can find the source of drawHorizontalArrow(Graphics g, Rectangle r, boolean direction)

Description

draw Horizontal Arrow

License

LGPL

Declaration

public static void drawHorizontalArrow(Graphics g, Rectangle r, boolean direction) 

Method Source Code


//package com.java2s;
/*/*  w  ww . j  a  va  2  s.  c o  m*/
 * Copyright (c) 2007-2012 The Broad Institute, Inc.
 * SOFTWARE COPYRIGHT NOTICE
 * This software and its documentation are the copyright of the Broad Institute, Inc. All rights are reserved.
 *
 * This software is supplied without any warranty or guaranteed support whatsoever. The Broad Institute is not responsible for its use, misuse, or functionality.
 *
 * This software is licensed under the terms of the GNU Lesser General Public License (LGPL),
 * Version 2.1 which is available at http://www.opensource.org/licenses/lgpl-2.1.php.
 */

import java.awt.*;

public class Main {
    public static void drawHorizontalArrow(Graphics g, Rectangle r, boolean direction) {
        int[] x;
        int[] y;

        int dy = r.height / 3;
        int y0 = r.y;
        int y1 = y0 + dy;
        int y3 = y0 + r.height;
        int y2 = y3 - dy;
        int yc = (y1 + y2) / 2;
        int dx = yc - y0;
        if (direction) {
            int x1 = r.x;
            int x3 = x1 + r.width;
            int x2 = x3 - dx;
            x = new int[] { x1, x2, x2, x3, x2, x2, x1 };
            y = new int[] { y1, y1, y0, yc, y3, y2, y2 };
        } else {
            int x1 = r.x;
            int x3 = x1 + r.width;
            int x2 = x1 + dx;
            x = new int[] { x1, x2, x2, x3, x3, x2, x2 };
            y = new int[] { yc, y0, y1, y1, y2, y2, y3 };

        }

        g.fillPolygon(x, y, x.length);
    }
}

Related

  1. drawArrowHead(final Graphics2D aG, final int aXpos, final int aYpos, final int aFactor, final int aArrowWidth, final int aArrowHeight)
  2. drawArrowHead(Graphics g, double c1, double c2, double phi, int l, int grad, boolean fill)
  3. drawArrowLine(Graphics g, int x1, int y1, int x2, int y2, int d, int h, boolean capOnly)
  4. drawArrowLine(Graphics g, int x1, int y1, int x2, int y2, int dist, boolean arrowLeft, boolean arrowRight)
  5. drawDoubleHeadedArrow(final Graphics aG, final int aX1, final int aY, final int aX2)