2
* Copyright (c) 2002 and later by MH Software-Entwicklung. All Rights Reserved.
4
* JTattoo is multiple licensed. If your are an open source developer you can use
5
* it under the terms and conditions of the GNU General Public License version 2.0
6
* or later as published by the Free Software Foundation.
10
* If you pay for a license you will become a registered user who could use the
11
* software under the terms and conditions of the GNU Lesser General Public License
12
* version 2.0 or later with classpath exception as published by the Free Software
16
* see: classpath-exception.txt
18
* Registered users could also use JTattoo under the terms and conditions of the
19
* Apache License, Version 2.0 as published by the Apache Software Foundation.
21
* see: APACHE-LICENSE-2.0.txt
24
package com.jtattoo.plaf;
27
import javax.swing.Icon;
30
* @author Michael Hagen
32
public abstract class XPScrollButton extends BaseScrollButton {
34
public XPScrollButton(int direction, int width) {
35
super(direction, width);
38
public abstract Icon getUpArrowIcon();
39
public abstract Icon getDownArrowIcon();
40
public abstract Icon getLeftArrowIcon();
41
public abstract Icon getRightArrowIcon();
43
public Color getFrameColor() {
47
public void paint(Graphics g) {
48
Graphics2D g2D = (Graphics2D) g;
49
Composite savedComposite = g2D.getComposite();
50
Paint savedPaint = g2D.getPaint();
52
boolean isPressed = getModel().isPressed();
53
boolean isRollover = getModel().isRollover();
55
int width = getWidth();
56
int height = getHeight();
58
Color[] tc = AbstractLookAndFeel.getTheme().getThumbColors();
60
Color c2 = tc[tc.length - 1];
62
c1 = ColorHelper.darker(c1, 5);
63
c2 = ColorHelper.darker(c2, 5);
64
} else if (isRollover) {
65
c1 = ColorHelper.brighter(c1, 20);
66
c2 = ColorHelper.brighter(c2, 20);
69
g2D.setPaint(new GradientPaint(0, 0, c1, width, height, c2));
70
g.fillRect(0, 0, width, height);
71
g2D.setPaint(savedPaint);
73
g.setColor(getFrameColor());
74
g.drawLine(1, 1, width - 2, 1);
75
g.drawLine(1, 1, 1, height - 3);
76
g.drawLine(width - 2, 1, width - 2, height - 3);
77
g.drawLine(2, height - 2, width - 3, height - 2);
79
AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
80
g2D.setComposite(alpha);
82
g.drawLine(2, 2, width - 3, 2);
83
g.drawLine(2, 3, 2, height - 3);
85
g.setColor(ColorHelper.darker(c2, 40));
86
g.drawLine(width - 1, 2, width - 1, height - 3);
87
g.drawLine(3, height - 1, width - 3, height - 1);
88
alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f);
89
g2D.setComposite(alpha);
90
g.drawLine(1, height - 2, 2, height - 1);
91
g.drawLine(width - 1, height - 2, width - 2, height - 1);
93
g2D.setComposite(savedComposite);
96
if (getDirection() == NORTH) {
97
int x = (width / 2) - (getUpArrowIcon().getIconWidth() / 2);
98
int y = (height / 2) - (getUpArrowIcon().getIconHeight() / 2);
99
getUpArrowIcon().paintIcon(this, g, x, y);
100
} else if (getDirection() == SOUTH) {
101
int x = (width / 2) - (getDownArrowIcon().getIconWidth() / 2);
102
int y = (height / 2) - (getDownArrowIcon().getIconHeight() / 2) + 1;
103
getDownArrowIcon().paintIcon(this, g, x, y);
104
} else if (getDirection() == WEST) {
105
int x = (width / 2) - (getLeftArrowIcon().getIconWidth() / 2);
106
int y = (height / 2) - (getLeftArrowIcon().getIconHeight() / 2);
107
getLeftArrowIcon().paintIcon(this, g, x, y);
109
int x = (width / 2) - (getRightArrowIcon().getIconWidth() / 2) + 1;
110
int y = (height / 2) - (getRightArrowIcon().getIconHeight() / 2);
111
getRightArrowIcon().paintIcon(this, g, x, y);
115
public Dimension getPreferredSize() {
116
if (getDirection() == NORTH) {
117
return new Dimension(buttonWidth, buttonWidth);
118
} else if (getDirection() == SOUTH) {
119
return new Dimension(buttonWidth, buttonWidth);
120
} else if (getDirection() == EAST) {
121
return new Dimension(buttonWidth, buttonWidth);
122
} else if (getDirection() == WEST) {
123
return new Dimension(buttonWidth, buttonWidth);
125
return new Dimension(0, 0);