home *** CD-ROM | disk | FTP | other *** search
/ Datatid 2000 #1 / Datatid-2000-01.iso / Internet / JAVA_NAVIGATOR / JAVANAVIGATOR.EXE / %MAINDIR% / files / JClass / DirectionButton.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-08-31  |  3.0 KB  |  116 lines

  1. import java.awt.Color;
  2. import java.awt.Component;
  3. import java.awt.Dimension;
  4. import java.awt.Graphics;
  5. import java.awt.Polygon;
  6.  
  7. public class DirectionButton extends ButtonBase {
  8.    public static final int LEFT = 0;
  9.    public static final int RIGHT = 1;
  10.    // $FF: renamed from: UP int
  11.    public static final int field_0 = 2;
  12.    public static final int DOWN = 3;
  13.    private int direction;
  14.    private int left;
  15.    private int right;
  16.    private int top;
  17.    private int bottom;
  18.    private int indent;
  19.    private Polygon poly;
  20.    Color cForeColor;
  21.  
  22.    public DirectionButton() {
  23.       this(0);
  24.    }
  25.  
  26.    public DirectionButton(int d) {
  27.       this.cForeColor = Color.black;
  28.       this.direction = d;
  29.       this.left = 0;
  30.       this.right = 0;
  31.       this.bottom = 0;
  32.       this.indent = 0;
  33.       this.poly = null;
  34.    }
  35.  
  36.    public void setDirection(int d) {
  37.       this.direction = d;
  38.    }
  39.  
  40.    public int getDirection() {
  41.       return this.direction;
  42.    }
  43.  
  44.    public void setForeColor(Color c) {
  45.       this.cForeColor = c;
  46.       ((Component)this).invalidate();
  47.    }
  48.  
  49.    public void setArrowIndent(int ai) {
  50.       this.indent = ai;
  51.       ((Component)this).invalidate();
  52.    }
  53.  
  54.    public int getArrowIndent() {
  55.       return this.indent;
  56.    }
  57.  
  58.    public void shrinkTriangle(int l, int r, int t, int b) {
  59.       this.left = l;
  60.       this.right = r;
  61.       this.top = t;
  62.       this.bottom = b;
  63.    }
  64.  
  65.    public void paint(Graphics g) {
  66.       super.paint(g);
  67.       this.updatePolygon();
  68.       if (((Component)this).isEnabled()) {
  69.          g.setColor(this.cForeColor);
  70.       } else {
  71.          g.setColor(Color.gray);
  72.       }
  73.  
  74.       g.fillPolygon(this.poly);
  75.    }
  76.  
  77.    public Dimension preferredSize() {
  78.       Dimension s = ((Component)this).size();
  79.       return new Dimension(Math.max(s.width, ((Component)this).minimumSize().width), Math.max(s.height, ((Component)this).minimumSize().height));
  80.    }
  81.  
  82.    void updatePolygon() {
  83.       Dimension s = ((Component)this).size();
  84.       this.poly = new Polygon();
  85.       int centerHorizontal = s.width / 2 + super.pressedAdjustment;
  86.       int centerVertical = s.height / 2 + super.pressedAdjustment;
  87.       int topSide = this.top + super.bevel * 2 + super.pressedAdjustment + this.indent;
  88.       int bottomSide = s.height - this.bottom - super.bevel * 2 + super.pressedAdjustment - this.indent;
  89.       int leftSide = this.left + super.bevel * 2 + super.pressedAdjustment + this.indent;
  90.       int rightSide = s.width - this.right - super.bevel * 2 + super.pressedAdjustment - this.indent;
  91.       switch (this.direction) {
  92.          case 0:
  93.             this.poly.addPoint(leftSide, centerVertical);
  94.             this.poly.addPoint(rightSide, topSide);
  95.             this.poly.addPoint(rightSide, bottomSide);
  96.             return;
  97.          case 1:
  98.             this.poly.addPoint(rightSide, centerVertical);
  99.             this.poly.addPoint(leftSide, topSide);
  100.             this.poly.addPoint(leftSide, bottomSide);
  101.             return;
  102.          case 2:
  103.             this.poly.addPoint(centerHorizontal, topSide);
  104.             this.poly.addPoint(leftSide, bottomSide);
  105.             this.poly.addPoint(rightSide, bottomSide);
  106.             return;
  107.          case 3:
  108.             this.poly.addPoint(centerHorizontal, bottomSide);
  109.             this.poly.addPoint(leftSide, topSide);
  110.             this.poly.addPoint(rightSide, topSide);
  111.             return;
  112.          default:
  113.       }
  114.    }
  115. }
  116.