package gui.elements; //import java.awt.*; import java.awt.geom.*; /** *

Title: Java Media for Experiencing Sensation and Perception

*

Description: draws an arrow - use negative values for upward arrows

*

Copyright: Copyright (c) 2002

*

Company: Hanover College

* @author John H. Krantz, Ph.D. * @version 0.1 */ public class Arrow { private int height = 200; private double headAngle = 30; private int headLength = 35; private int startX = 0; private int startY = 0; public final boolean DRAWUP = true; public final boolean DRAWDOWN = false; private boolean up = DRAWDOWN; public Arrow() { } // set methods public void setHeight(int h) { height = (h >= 0 ? h : 200); } public void setHeadAngle(double a){ headAngle = (a > 0 & a <= 90 ? a : 30); } public void setHeadLength(int len){ headLength = (len >= 0 ? len : 35); } public void setStart(int x, int y){ startX = x; startY = y; } public void setDirection(boolean dir){ up = dir; } // get methods public int getHeight() { return height;} public double getHeadAngle() { return headAngle; } public int getHeadLength() { return headLength; } public int getStartX() { return startX; } public int getStartY() { return startY; } public boolean getDirection() { return up; } public GeneralPath formArrow(){ GeneralPath temp = new GeneralPath(); // set the direction float hl = headLength; float len = height; if (up){ hl = hl*-1; len = len*-1; } temp.moveTo(startX,startY); temp.lineTo(startX,startY+len); temp.lineTo(startX+(float)(hl* Math.sin(headAngle*Math.PI/180.0)), startY+len - (float)(hl* Math.cos(headAngle*Math.PI/180.0))); temp.moveTo(startX,startY+len); temp.lineTo(startX-(float)(hl* Math.sin(headAngle*Math.PI/180.0)), startY+len - (float)(hl* Math.cos(headAngle*Math.PI/180.0))); return temp; } }