/* * Rectangle3D.java * * Copyright (C) 1996 Shaun Terry. All Rights Reserved. */ package spt.gui; import java.awt.Component; import java.awt.Graphics; import java.awt.Color; /** * Draw a 3D rectangle on a Graphics area. The 3D effect * can be either in, out, border only in or border only out. * * @author Shaun Terry */ public class Rectangle3D { public final static int IN = 0; public final static int OUT = 1; public final static int BORDER_IN = 2; public final static int BORDER_OUT = 3; int mode = IN; Component parent; int w, h, x, y; public Rectangle3D(Component c, int X, int Y, int width, int height) { x = X; y = Y; w = width; h = height; parent = c; } public void setDrawingMode(int m) { mode = m; } static public int borderWidthOfMode(int m) { return 2; // They're all 2 right now } public synchronized void paint(Graphics g) { Color c = parent.getBackground(); Color darker = c.darker(); Color brighter = c.brighter(); Color c1, c2, c3, c4; if (mode == IN) { c1 = darker; c2 = brighter; c3 = c; c4 = Color.black; } else if (mode == OUT) { c3 = darker; c2 = darker; c4 = c; c1 = brighter; } else if (mode == BORDER_OUT) { c4 = darker; c2 = darker; c1 = brighter; c3 = brighter; } else /* if (mode == BORDER_IN) */ { c1 = darker; c2 = brighter; c3 = c1; c4 = brighter; } // Upper left, outer g.setColor(c1); g.drawLine(x, y, x+w, y); g.drawLine(x, y, x, y+h); // Upper left, inner g.setColor(c4); g.drawLine(x+1, y+1, x+w-2, y+1); g.drawLine(x+1, y+1, x+1, y+h-2); // Lower right, outer g.setColor(c2); g.drawLine(x, y+h-1, x+w-1, y+h-1); g.drawLine(x+w-1, y, x+w-1, y+h-1); // Lower right, inner g.setColor(c3); g.drawLine(x+1, y+h-2, x+w-2, y+h-2); g.drawLine(x+w-2, y+1, x+w-2, y+h-2); } }