38 |
|
|
39 |
package javax.swing.plaf.metal; |
package javax.swing.plaf.metal; |
40 |
|
|
41 |
|
import java.awt.Dimension; |
42 |
|
import java.awt.Graphics; |
43 |
|
import java.awt.Rectangle; |
44 |
import java.util.HashMap; |
import java.util.HashMap; |
45 |
|
|
46 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
47 |
|
import javax.swing.UIDefaults; |
48 |
|
import javax.swing.UIManager; |
49 |
import javax.swing.plaf.ComponentUI; |
import javax.swing.plaf.ComponentUI; |
50 |
import javax.swing.plaf.basic.BasicScrollBarUI; |
import javax.swing.plaf.basic.BasicScrollBarUI; |
51 |
|
|
53 |
extends BasicScrollBarUI |
extends BasicScrollBarUI |
54 |
{ |
{ |
55 |
|
|
56 |
|
/** The minimum thumb size */ |
57 |
|
private static final Dimension MIN_THUMB_SIZE = new Dimension(18, 18); |
58 |
|
|
59 |
// FIXME: maybe replace by a Map of instances when this becomes stateful |
// FIXME: maybe replace by a Map of instances when this becomes stateful |
60 |
/** The shared UI instance for JScrollBars. */ |
/** The shared UI instance for JScrollBars. */ |
61 |
private static HashMap instances = null; |
private static HashMap instances = null; |
92 |
|
|
93 |
return instance; |
return instance; |
94 |
} |
} |
95 |
|
|
96 |
|
/** |
97 |
|
* Paints the slider button of the ScrollBar. |
98 |
|
* |
99 |
|
* @param g the Graphics context to use |
100 |
|
* @param c the JComponent on which we paint |
101 |
|
* @param thumbBounds the rectangle that is the slider button |
102 |
|
*/ |
103 |
|
protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) |
104 |
|
{ |
105 |
|
// first we fill the background |
106 |
|
g.setColor(thumbColor); |
107 |
|
g.fillRect(thumbBounds.x, thumbBounds.y, thumbBounds.width, |
108 |
|
thumbBounds.height); |
109 |
|
|
110 |
|
// draw the outer dark line |
111 |
|
g.setColor(thumbDarkShadowColor); |
112 |
|
g.drawRect(thumbBounds.x, thumbBounds.y, thumbBounds.width - 1, |
113 |
|
thumbBounds.height - 1); |
114 |
|
|
115 |
|
// draw the inner light line |
116 |
|
g.setColor(thumbHighlightColor); |
117 |
|
g.drawLine(thumbBounds.x + 1, thumbBounds.y + 1, |
118 |
|
thumbBounds.x + thumbBounds.width - 2, |
119 |
|
thumbBounds.y + 1); |
120 |
|
g.drawLine(thumbBounds.x + 1, thumbBounds.y + 1, |
121 |
|
thumbBounds.x + 1, |
122 |
|
thumbBounds.y + thumbBounds.height - 2); |
123 |
|
|
124 |
|
// draw the shadow line |
125 |
|
UIDefaults def = UIManager.getLookAndFeelDefaults(); |
126 |
|
g.setColor(def.getColor("ScrollBar.shadow")); |
127 |
|
g.drawLine(thumbBounds.x + 1, thumbBounds.y + thumbBounds.height, |
128 |
|
thumbBounds.x + thumbBounds.width, |
129 |
|
thumbBounds.y + thumbBounds.height); |
130 |
|
|
131 |
|
// draw the pattern |
132 |
|
int xOff = 0; |
133 |
|
for (int y = thumbBounds.y + 4; |
134 |
|
y < (thumbBounds.y + thumbBounds.height - 4); y++) |
135 |
|
{ |
136 |
|
// set color alternating with every line |
137 |
|
if ((y % 2) == 0) |
138 |
|
g.setColor(thumbHighlightColor); |
139 |
|
else |
140 |
|
g.setColor(thumbDarkShadowColor); |
141 |
|
|
142 |
|
for (int x = thumbBounds.x + 3 + (xOff); |
143 |
|
x < (thumbBounds.x + thumbBounds.width - 3); x = x + 4) |
144 |
|
{ |
145 |
|
g.drawLine(x, y, x, y); |
146 |
|
} |
147 |
|
|
148 |
|
// increase x offset |
149 |
|
xOff++; |
150 |
|
if (xOff > 3) |
151 |
|
xOff = 0; |
152 |
|
|
153 |
|
} |
154 |
|
} |
155 |
|
|
156 |
|
/** |
157 |
|
* This method returns the minimum thumb size. |
158 |
|
* |
159 |
|
* @return The minimum thumb size. |
160 |
|
*/ |
161 |
|
protected Dimension getMinimumThumbSize() |
162 |
|
{ |
163 |
|
return MIN_THUMB_SIZE; |
164 |
|
} |
165 |
} |
} |