/*
 * Copyright (c) 1997, Subrahmanyam Allamaraju. All Rights Reserved.
 * 
 * Permission to use, copy, modify, and distribute this software for
 * NON-COMMERCIAL purposes and without fee is hereby granted provided that this
 * copyright notice appears in all copies.
 *
 * This software is intended for demonstration purposes only, and comes without
 * any explicit or implicit warranty.
 *
 * Please report any bugs to subrahmanyam@geocities.com
 *
 */


import java.awt.*;
import java.awt.image.*;
import java.net.*;


public class ThreeDBorder 
{
    static final int DEPRESSED = -1;
    static final int DEFAULT = 0;
    static final int FOCUSSED = 1;
    private static final int SHARP = 0;
    private static final int ROUND = 1;
    
    private int x = 0;
    private int y = 0;
    private int width = 0;
    private int height = 0;
    private Color backGround = null;
    private int status = DEFAULT;
    private int borderThickness = 2;

    public ThreeDBorder(int x, int y, int width, int height, int
			borderThickness, Color backGround) 
	{
	    this.x = x;
	    this.y = y;
	    this.width = width;
	    this.height = height;
	    this.backGround = backGround;
	    this.borderThickness = borderThickness;
	}
    
    public boolean setStatus(int status) 
	{
	    this.status = status;
	    return true;
	}
    
    public boolean setHeight(int height) 
	{
	    this.height = height;
	    return true;
	}
    
    public boolean setWidth(int width) 
	{
	    this.width = width;
	    return true;
	}
    

    public void paint(Graphics g) 
	{

	    Color brighter = null;
	    Color darker = null;

	    if(backGround != null) {
		g.setColor(backGround);
		
		switch(status) {
		case DEPRESSED:
		case FOCUSSED:
                    brighter = VColor.brighterShade(backGround);
                    darker = VColor.darkerShade(backGround);
                    break;
                }

		g.fillRect(x, y, width, height);
		
	    }
	    
	    for(int idx = 0; idx < borderThickness; idx++) {

		Color top = brighter;
		Color bottom = darker;
		
		if(status == DEPRESSED) {
		    top = darker;
		    bottom = brighter;
		}

		if(idx == (borderThickness-1) && status == DEPRESSED) { 
		    g.setColor(VColor.darkerShade(top));
		}
		else if(status == FOCUSSED) {
		    g.setColor(top);
		}
		
		if(status == DEPRESSED || status == FOCUSSED) {
		    
		    g.drawLine(x+idx, y+idx, x+idx, y+((height-1)-idx)); 
		    g.drawLine(x+idx, y+idx, x+((width-1)-idx), y+idx);
		    
		    if(((idx == (borderThickness - 1)) && status  ==
			DEPRESSED) || (idx == 0 && status == FOCUSSED)) {
			g.setColor(VColor.darkerShade(bottom));
		    }
		    else {
			g.setColor(bottom);
		    }
		    
		    g.drawLine(x+idx, y+((height-1)-(idx)),
			       x+((width-1)-(idx)), y+((height-1)-(idx)));
		    g.drawLine(x+((width-1)-(idx)), y+idx,
			       x+((width-1)-(idx)), y+((height-1)-(idx)));
		}
	    }
	}
}


