home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / main.bin / DirectionButton.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-08-04  |  3.2 KB  |  140 lines

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