home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-06-19 | 7.3 KB | 292 lines |
- package symantec.itools.awt;
-
-
- import java.awt.Rectangle;
- import java.awt.Dimension;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Polygon;
-
- // 01/29/97 TWB Integrated changes from Windows
-
- /* *
- * DirectionButton is a button component that has an arrow drawn in it that
- * points one of four ways (left,up,right,down).
- */
-
- /**
- * This component creates an arrow and is an extension of ButtonBase. At
- * runtime, the button has an up look and pressed look.
- * <p>
- * This component is usually used in conjunction with a combo or list box to
- * indicate a list that the user can view by clicking the arrow.
- * <p>
- * To create an interaction with another component, use the Interaction Wizard.
- * <p>
- * @version 1.0, Nov 26, 1996
- * @author Symantec
- */
- public class DirectionButton
- extends ButtonBase
- {
- /**
- * The point LEFT style constant.
- */
- public static final int LEFT = 0;
-
- /**
- * The point RIGHT style constant.
- */
- public static final int RIGHT = 1;
-
- /**
- * The point UP style constant.
- */
- public static final int UP = 2;
-
- /**
- * The point DOWN style constant.
- */
- public static final int DOWN = 3;
-
-
- private int direction;
- private int left;
- private int right;
- private int top;
- private int bottom;
- private int indent;
- private Polygon poly;
-
-
- /**
- * Constructs a default Direction Button which will point left.
- */
- public DirectionButton()
- {
- this(LEFT);
- }
-
- /**
- * Constructs a Direction Button pointing the specified direction.
- * @param d style constant indicating direction to point button
- * @see #LEFT
- * @see #UP
- * @see #RIGHT
- * @see #DOWN
- */
- public DirectionButton(int d)
- {
- direction = d;
- left = 0;
- right = 0;
- bottom = 0;
- indent = 0;
- poly = null;
- }
-
- /**
- * Sets the direction of the arrow after construction.
- * @param d constant indicating direction to point button
- * @see #getDirection
- * @see #LEFT
- * @see #UP
- * @see #RIGHT
- * @see #DOWN
- */
- public void setDirection(int d)
- {
- direction = d;
- }
-
- /**
- * Returs the direction the button is currently pointing.
- * @see #setDirection
- * @see #LEFT
- * @see #UP
- * @see #RIGHT
- * @see #DOWN
- */
- public int getDirection()
- {
- return direction;
- }
-
- /**
- * Sets the size of blank space between the arrow and the button
- * border in pixels.
- * @param ai margin around arrow in pixels. 0=arrow takes up entire button
- * @see #getArrowIndent
- */
- public void setArrowIndent(int ai)
- {
- indent = ai;
- invalidate();
- }
-
- /**
- * Reurns the size of blank space between the arrow and the button
- * border in pixels.
- * @see #setArrowIndent
- */
- public int getArrowIndent()
- {
- return indent;
- }
-
- /**
- * Sets the extra amount in pixels to shrink triangle
- * @param left pixels to shrink from left side
- * @param right pixels to shrink from right side
- * @param top pixels to shrink from top
- * @param bottom pixels to shrink from bottom
- */
- public void shrinkTriangle(int l, int r, int t, int b)
- {
- left = l;
- right = r;
- top = t;
- bottom = b;
- }
-
- /**
- * Paints this component using the given graphics context.
- * This is a standard Java AWT method which typically gets called
- * by the AWT to handle painting this component. It paints this component
- * using the given graphics context. The graphics context clipping region
- * is set to the bounding rectangle of this component and its <0,0>
- * coordinate is this component's top-left corner.
- *
- * @param g the graphics context used for painting
- * @see java.awt.Component#repaint
- * @see symantec.itools.awt.ButtonBase#update
- */
- public void paint(Graphics g)
- {
- super.paint(g);
-
- updatePolygon();
-
- if(isEnabled())
- {
- g.setColor(Color.black);
- }
- else
- {
- g.setColor(Color.gray);
- }
-
- g.fillPolygon(poly);
- }
-
- /**
- * Returns the recommended dimensions to properly display this component.
- * This is a standard Java AWT method which gets called to determine
- * the recommended size of this component.
- *
- * @see java.awt.Component#minimumSize
- */
- public Dimension preferredSize()
- {
- Dimension s;
-
- s = size();
-
- return new Dimension(Math.max(s.width, minimumSize().width), Math.max(s.height, minimumSize().height));
- }
-
- void updatePolygon()
- {
- Dimension s;
- int centerHorizontal;
- int centerVertical;
- int topSide;
- int bottomSide;
- int leftSide;
- int rightSide;
-
- s = size();
- poly = new Polygon();
-
- centerHorizontal = (s.width / 2) + pressedAdjustment;
- centerVertical = (s.height / 2) + pressedAdjustment;
- topSide = (top + bevel * 2) + pressedAdjustment + indent;
- bottomSide = (s.height - bottom - bevel * 2) + pressedAdjustment - indent;
- leftSide = (left + bevel * 2) + pressedAdjustment + indent;
- rightSide = (s.width - right - bevel * 2) + pressedAdjustment - indent;
-
- switch (direction)
- {
- // -1, -2 etc... added 12/11/96 - Andy
- case UP:
- {
- if (symantec.itools.lang.OS.isMacintosh())
- {
- poly.addPoint(centerHorizontal-1, topSide-1);
- poly.addPoint(leftSide-1, bottomSide-2);
- poly.addPoint(rightSide-2, bottomSide-2);
- }
- else
- {
- poly.addPoint(centerHorizontal, topSide);
- poly.addPoint(leftSide, bottomSide);
- poly.addPoint(rightSide, bottomSide);
- }
- break;
- }
-
- case DOWN:
- {
- if (symantec.itools.lang.OS.isMacintosh())
- {
- poly.addPoint(centerHorizontal-1, bottomSide);
- poly.addPoint(leftSide-1, topSide);
- poly.addPoint(rightSide-1, topSide);
- }
- else
- {
- poly.addPoint(centerHorizontal, bottomSide);
- poly.addPoint(leftSide, topSide);
- poly.addPoint(rightSide, topSide);
- }
- break;
- }
-
- case LEFT:
- {
- if (symantec.itools.lang.OS.isMacintosh())
- {
- poly.addPoint(leftSide-2, centerVertical-1);
- poly.addPoint(rightSide-2, topSide-1);
- poly.addPoint(rightSide-2, bottomSide-1);
- }
- else
- {
- poly.addPoint(leftSide, centerVertical);
- poly.addPoint(rightSide, topSide);
- poly.addPoint(rightSide, bottomSide);
- }
- break;
- }
-
- case RIGHT:
- {
- if (symantec.itools.lang.OS.isMacintosh())
- {
- poly.addPoint(rightSide-1, centerVertical-1);
- poly.addPoint(leftSide, topSide-1);
- poly.addPoint(leftSide, bottomSide-2);
- }
- else
- {
- poly.addPoint(rightSide, centerVertical);
- poly.addPoint(leftSide, topSide);
- poly.addPoint(leftSide, bottomSide);
- }
- break;
- }
- }
- }
- }
-
-