/** * SunSphereButton displays and manages the user controls.<p> * * Copyright &copy; 1996 Martin Minow. All Rights Reserved.<p> * World map copyright &copy; 1992-97 Apple Computer Inc. All Rights Reserved. * Used by permission.<p> * * Permission to use, copy, modify, and redistribute this software and its * documentation for personal, non-commercial use is hereby granted provided that * this copyright notice and appropriate documentation appears in all copies. This * software may not be distributed for fee or as part of commercial, "shareware," * and/or not-for-profit endevors including, but not limited to, CD-ROM collections, * online databases, and subscription services without specific license.<p> * * @author <a href="mailto:minow@pobox.com">Martin Minow</a> * @version 1.2 * Set tabs every 8 characters. */package org.minow.applets.sunsphere;import java.awt.*;import java.awt.event.*;import java.util.*;public abstract class SunSphereButton extends GraphicsButton{    public static final Color	defaultButtonColor	=    			new Color(0x33, 0x99, 0x33);    public static final Color	defaultButtonFillColor	= Color.white;    public static final Color	defaultButtonClickColor	=    			defaultButtonColor.darker().darker();    protected Color		buttonColor;    protected Color		buttonFillColor;    protected Color		buttonClickColor;    protected static final int	buttonRound	    =  8;   /* For drawRoundRect    */        protected Image		offscreenImage;    protected Graphics		offscreenGraphics;    /*     * Concrete subclasses set these values.     */    protected int[]		buttonIcon;        /*     * Accessors     */    protected SunSphereButton(    	    String		buttonLabel,    	    int[]		buttonIcon,    	    int			buttonWidth,    	    int			buttonHeight,    	    Color		buttonColor        )    {    	super(    		buttonWidth,    		buttonHeight    	    );    	setButtonColor(buttonColor);    	buttonFillColor		= defaultButtonFillColor;    	setButtonIcon(buttonIcon);    	setLabel(buttonLabel);    }    protected void setButtonIcon(    	    int[]		buttonIcon        )    {    	this.buttonIcon		= buttonIcon;	repaint();    }    protected void setButtonColor(    	    Color		buttonColor    	)    {    	this.buttonColor	= buttonColor;    	this.buttonClickColor	= buttonColor.darker().darker();    	repaint();    }    protected void setButtonFillColor(    	    Color		buttonFillColor    	)    {	this.buttonFillColor	= buttonFillColor;	repaint();    }    public void update(	    Graphics	    g	)    {	paint(g);    }    public void paint(	    Graphics	    g	)    {    	logMouseEvent("paint");	Dimension d		= size();	if (offscreenImage == null	 || offscreenImage.getWidth(this) != d.width	 || offscreenImage.getHeight(this) != d.height) {	    offscreenImage	= createImage(d.width, d.height);	    offscreenGraphics	= offscreenImage.getGraphics();	}	Graphics osg		= offscreenImage.getGraphics();	osg.setColor(getBackground());	osg.fillRect(0, 0, d.width, d.height);	int x			= (d.width - buttonWidth) / 2;	if (mouseDown && mouseInButton) {	/* Variables in GraphicsButton */	    osg.setColor(buttonClickColor);	    osg.fillRoundRect(x, 0, buttonWidth - 1, buttonHeight - 1, buttonRound, buttonRound);	}	else {	    osg.setColor(Color.black);	    osg.drawRoundRect(x, 0, buttonWidth - 1, buttonHeight - 1, buttonRound, buttonRound);	}	if (buttonIcon != null) {	    int rows	= buttonIcon.length;	    for (int row = 0; row < rows; row++) {		int v		= buttonIcon[row];		int mask	= 0x8000;		int col		= 5;		int start	= col;    exit:	while (mask != 0) {    		    start	= col;		    while (mask != 0 && (v & mask) == 0) {			++col;			mask >>>= 1;		    }		    if (mask == 0) {			break exit;		    }		    start	= col;		    while (mask != 0 && (v & mask) != 0) {			++col;			mask >>>= 1;		    }		    osg.setColor(buttonColor);		    osg.drawLine(x + start, row + 2, x + col - 1, row + 2);		}	    }	}	g.drawImage(offscreenImage, 0, 0, this);    }}