home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / dek17tau / classes / spt / gui / rectangle3d.java < prev   
Encoding:
Java Source  |  1996-08-14  |  1.8 KB  |  104 lines

  1.  
  2. /*
  3.  * Rectangle3D.java
  4.  *
  5.  * Copyright (C) 1996 Shaun Terry. All Rights Reserved.
  6.  */
  7.  
  8. package spt.gui;
  9.  
  10. import java.awt.Component;
  11. import java.awt.Graphics;
  12. import java.awt.Color;
  13.  
  14. /**
  15.  * Draw a 3D rectangle on a Graphics area. The 3D effect
  16.  * can be either in, out, border only in or border only out.
  17.  *
  18.  * @author Shaun Terry
  19.  */
  20.  
  21. public class Rectangle3D {
  22.  
  23.     public final static int IN = 0;
  24.     public final static int OUT = 1;
  25.     public final static int BORDER_IN = 2;
  26.     public final static int BORDER_OUT = 3;
  27.  
  28.     int mode = IN;
  29.  
  30.     Component parent;
  31.  
  32.     int w, h, x, y;
  33.  
  34.     public Rectangle3D(Component c, int X, int Y, int width, int height) {
  35.         x = X;
  36.         y = Y;
  37.         w = width;
  38.         h = height;
  39.         parent = c;
  40.     }
  41.  
  42.     public void setDrawingMode(int m) {
  43.         mode = m;
  44.     }
  45.  
  46.     static public int borderWidthOfMode(int m) {
  47.         return 2;    // They're all 2 right now
  48.     }
  49.  
  50.     public synchronized void paint(Graphics g) {
  51.         Color c = parent.getBackground();
  52.         Color darker = c.darker();
  53.         Color brighter = c.brighter();
  54.  
  55.         Color c1, c2, c3, c4;
  56.  
  57.         if (mode == IN) {
  58.             c1 = darker;
  59.             c2 = brighter;
  60.             c3 = c;
  61.             c4 = Color.black;
  62.         }
  63.         else if (mode == OUT) {
  64.             c3 = darker;
  65.             c2 = darker;
  66.             c4 = c;
  67.             c1 = brighter;
  68.         }
  69.         else if (mode == BORDER_OUT) {
  70.             c4 = darker;
  71.             c2 = darker;
  72.             c1 = brighter;
  73.             c3 = brighter;
  74.         }
  75.         else /* if (mode == BORDER_IN) */ {
  76.             c1 = darker;
  77.             c2 = brighter;
  78.             c3 = c1;
  79.             c4 = brighter;
  80.         }
  81.  
  82.         // Upper left, outer
  83.         g.setColor(c1);
  84.         g.drawLine(x, y, x+w, y);
  85.         g.drawLine(x, y, x, y+h);
  86.  
  87.         // Upper left, inner
  88.         g.setColor(c4);
  89.         g.drawLine(x+1, y+1, x+w-2, y+1);
  90.         g.drawLine(x+1, y+1, x+1, y+h-2);
  91.  
  92.         // Lower right, outer
  93.         g.setColor(c2);
  94.         g.drawLine(x, y+h-1, x+w-1, y+h-1);
  95.         g.drawLine(x+w-1, y, x+w-1, y+h-1);
  96.  
  97.         // Lower right, inner
  98.         g.setColor(c3);
  99.         g.drawLine(x+1, y+h-2, x+w-2, y+h-2);
  100.         g.drawLine(x+w-2, y+1, x+w-2, y+h-2);
  101.     }
  102. }
  103.  
  104.