home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 November
/
Chip_1998-11_cd.bin
/
tema
/
Cafe
/
jfc.bin
/
MetalScrollButton.java
< prev
next >
Wrap
Text File
|
1998-02-26
|
8KB
|
288 lines
/*
* @(#)MetalScrollButton.java 1.9 98/02/06
*
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the confidential and proprietary information of Sun
* Microsystems, Inc. ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Sun.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
* THIS SOFTWARE OR ITS DERIVATIVES.
*
*/
package com.sun.java.swing.plaf.metal;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Polygon;
import com.sun.java.swing.*;
import com.sun.java.swing.plaf.basic.BasicArrowButton;
/**
* JButton object for Metal scrollbar arrows.
* <p>
* Warning: serialized objects of this class will not be compatible with
* future swing releases. The current serialization support is appropriate
* for short term storage or RMI between Swing1.0 applications. It will
* not be possible to load serialized Swing1.0 objects with future releases
* of Swing. The JDK1.2 release of Swing will be the compatibility
* baseline for the serialized form of Swing objects.
*
* @version 1.9 02/06/98
* @author Jeff Shapiro
*/
public class MetalScrollButton extends BasicArrowButton
{
private static Color shadowColor;
private static Color highlightColor;
private boolean isFreeStanding = false;
private int buttonWidth;
public MetalScrollButton( int direction, int width, boolean freeStanding )
{
super( direction );
shadowColor = UIManager.getColor("ScrollBar.shadow");
highlightColor = UIManager.getColor("ScrollBar.highlight");
buttonWidth = width;
isFreeStanding = freeStanding;
}
public void setFreeStanding( boolean freeStanding )
{
isFreeStanding = freeStanding;
}
public void paint( Graphics g )
{
boolean isEnabled = getParent().isEnabled();
Color arrowColor = isEnabled ? MetalLookAndFeel.getControlInfo() : MetalLookAndFeel.getControlDisabled();
boolean isPressed = getModel().isPressed();
int width = getSize().width;
int height = getSize().height;
int w = width;
int h = height;
int arrowHeight = height / 4;
int arrowWidth = height / 2;
if ( isPressed )
{
g.setColor( MetalLookAndFeel.getControlShadow() );
}
else
{
g.setColor( getBackground() );
}
g.fillRect( 0, 0, width, height );
if ( getDirection() == NORTH )
{
if ( !isFreeStanding ) {
width += 2;
}
// Draw the arrow
g.setColor( arrowColor );
g.drawLine( 7, 6, 8, 6 );
g.drawLine( 6, 7, 9, 7 );
g.drawLine( 5, 8, 10, 8 );
g.drawLine( 4, 9, 11, 9 );
if (isEnabled) {
g.setColor( highlightColor );
if ( !isPressed )
{
g.drawLine( 1, 1, width - 3, 1 );
g.drawLine( 1, 1, 1, height - 1 );
}
g.drawLine( width - 1, 1, width - 1, height - 1 );
g.setColor( shadowColor );
g.drawLine( 0, 0, width - 2, 0 );
g.drawLine( 0, 0, 0, height - 1 );
g.drawLine( width - 2, 2, width - 2, height - 1 );
} else {
MetalUtils.drawDisabledBorder(g, 0, 0, width, height+1);
}
if ( !isFreeStanding ) {
width -= 2;
}
}
else if ( getDirection() == SOUTH )
{
if ( !isFreeStanding ) {
width += 2;
height += 1;
}
// Draw the arrow
g.setColor( arrowColor );
g.drawLine( 4, 5, 11, 5 );
g.drawLine( 5, 6, 10, 6 );
g.drawLine( 6, 7, 9, 7 );
g.drawLine( 7, 8, 8, 8 );
if (isEnabled) {
g.setColor( highlightColor );
if ( !isPressed )
{
g.drawLine( 1, 0, width - 3, 0 );
g.drawLine( 1, 0, 1, height - 3 );
}
g.drawLine( 1, height - 1, width - 1, height - 1 );
g.drawLine( width - 1, 0, width - 1, height - 1 );
g.setColor( shadowColor );
g.drawLine( 0, 0, 0, height - 2 );
g.drawLine( width - 2, 0, width - 2, height - 2 );
g.drawLine( 2, height - 2, width - 2, height - 2 );
} else {
MetalUtils.drawDisabledBorder(g, 0,-1, width, height+1);
}
if ( !isFreeStanding ) {
width -= 2;
height -= 1;
}
}
else if ( getDirection() == EAST )
{
if ( !isFreeStanding ) {
height += 2;
width += 1;
}
// Draw the arrow
g.setColor( arrowColor );
g.drawLine( 5, 4, 5, 11 );
g.drawLine( 6, 5, 6, 10 );
g.drawLine( 7, 6, 7, 9 );
g.drawLine( 8, 7, 8, 8 );
if (isEnabled) {
g.setColor( highlightColor );
if ( !isPressed )
{
g.drawLine( 0, 1, width - 3, 1 );
g.drawLine( 0, 1, 0, height - 3 );
}
g.drawLine( width - 1, 1, width - 1, height - 1 );
g.drawLine( 0, height - 1, width - 1, height - 1 );
g.setColor( shadowColor );
g.drawLine( 0, 0,width - 2, 0 );
g.drawLine( width - 2, 2, width - 2, height - 2 );
g.drawLine( 0, height - 2, width - 2, height - 2 );
} else {
MetalUtils.drawDisabledBorder(g,-1,0, width+1, height);
}
if ( !isFreeStanding ) {
height -= 2;
width -= 1;
}
}
else if ( getDirection() == WEST )
{
if ( !isFreeStanding ) {
height += 2;
width += 1;
g.translate( -1, 0 );
}
// Draw the arrow
g.setColor( arrowColor );
g.drawLine( 6, 7, 6, 8 );
g.drawLine( 7, 6, 7, 9 );
g.drawLine( 8, 5, 8, 10 );
g.drawLine( 9, 4, 9, 11 );
if (isEnabled) {
g.setColor( highlightColor );
if ( !isPressed )
{
g.drawLine( 1, 1, width - 1, 1 );
g.drawLine( 1, 1, 1, height - 3 );
}
g.drawLine( 1, height - 1, width - 1, height - 1 );
g.setColor( shadowColor );
g.drawLine( 0, 0, width - 1, 0 );
g.drawLine( 0, 0, 0, height - 2 );
g.drawLine( 2, height - 2, width - 1, height - 2 );
} else {
MetalUtils.drawDisabledBorder(g,0,0, width+1, height);
}
if ( !isFreeStanding ) {
height -= 2;
width -= 1;
g.translate( 1, 0 );
}
}
}
public Dimension getPreferredSize()
{
if ( getDirection() == NORTH )
{
return new Dimension( buttonWidth, buttonWidth - 2 );
}
else if ( getDirection() == SOUTH )
{
return new Dimension( buttonWidth, buttonWidth - (isFreeStanding ? 1 : 2) );
}
else if ( getDirection() == EAST )
{
return new Dimension( buttonWidth - (isFreeStanding ? 1 : 2), buttonWidth );
}
else if ( getDirection() == WEST )
{
return new Dimension( buttonWidth - 2, buttonWidth );
}
else
{
return new Dimension( 0, 0 );
}
}
public Dimension getMinimumSize()
{
return getPreferredSize();
}
public Dimension getMaximumSize()
{
return new Dimension( Integer.MAX_VALUE, Integer.MAX_VALUE );
}
public int getButtonWidth() {
return buttonWidth;
}
}