1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.lookandfeel;
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.metal.*;
import net.java.sip.communicator.util.skin.*;
/**
* The SIPCommScrollBarUI implementation.
*
* @author Yana Stamcheva
* @author Adam Netocny
*/
public class SIPCommScrollBarUI
extends MetalScrollBarUI
implements Skinnable
{
/**
* The horizontal thumb image.
*/
private BufferedImage horizontalThumb;
/**
* The vertical thumb image.
*/
private BufferedImage verticalThumb;
/**
* The horizontal thumb handle image.
*/
private BufferedImage horizontalThumbHandle;
/**
* The vertical thumb handle image.
*/
private BufferedImage verticalThumbHandle;
/**
* Creates an instance of <tt>SIPCommScrollBarUI</tt>.
*/
public SIPCommScrollBarUI()
{
loadSkin();
}
/**
* Creates the UI for the given <tt>JComponent</tt>.
*
* @param c the <tt>JComponent</tt>, for which to create an UI
* @return the component UI
*/
public static ComponentUI createUI(JComponent c)
{
return new SIPCommScrollBarUI();
}
/**
* Paints the track of the scroll bar.
*
* @param g the <tt>Graphics</tt> object used for painting
* @param c the component to paint a track for
* @param trackBounds the bounds of the track to paint
*/
@Override
protected void paintTrack( Graphics g, JComponent c, Rectangle trackBounds)
{
g.translate( trackBounds.x, trackBounds.y );
boolean leftToRight = c.getComponentOrientation().isLeftToRight();
if ( scrollbar.getOrientation() == JScrollBar.VERTICAL )
{
if ( !isFreeStanding )
{
trackBounds.width += 2;
if ( !leftToRight )
g.translate( -1, 0 );
}
g.setColor(this.trackColor);
g.fillRect(0, 0, trackBounds.width-2, trackBounds.height);
g.setColor(this.trackHighlightColor);
g.drawRect(0, 0, trackBounds.width-2, trackBounds.height);
if ( !isFreeStanding )
{
trackBounds.width -= 2;
if ( !leftToRight )
g.translate( 1, 0 );
}
}
else // HORIZONTAL
{
if ( !isFreeStanding )
{
trackBounds.height += 2;
}
g.setColor(this.trackColor);
g.fillRect(0, 0, trackBounds.width, trackBounds.height-2);
g.setColor(this.trackHighlightColor);
g.drawRect(0, 0, trackBounds.width, trackBounds.height-2);
if ( !isFreeStanding )
{
trackBounds.height -= 2;
}
}
g.translate( -trackBounds.x, -trackBounds.y );
}
/**
* Paints the thumb of the scroll bar.
*
* @param g the <tt>Graphics</tt> object used for painting
* @param c the component to paint a thumb for
* @param thumbBounds the bounds of the thumb to paint
*/
@Override
protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
{
if (!c.isEnabled()) {
return;
}
boolean leftToRight = c.getComponentOrientation().isLeftToRight();
g.translate( thumbBounds.x, thumbBounds.y );
int imgWidth;
int imgHeight;
int indentWidth = 10;
if(scrollbar.getOrientation() == JScrollBar.VERTICAL)
{
if(!isFreeStanding)
{
thumbBounds.width += 2;
if ( !leftToRight )
{
g.translate( -1, 0 );
}
}
imgWidth = verticalThumb.getWidth();
imgHeight = verticalThumb.getHeight();
Image topImage
= verticalThumb.getSubimage(0, 0,
imgWidth,
indentWidth);
Image middleImage
= verticalThumb.getSubimage(0, indentWidth,
imgWidth,
imgHeight-2*indentWidth);
Image bottomImage
= verticalThumb.getSubimage(0, imgHeight-indentWidth,
imgWidth, indentWidth);
g.drawImage(topImage, 0, 0,
thumbBounds.width-2, indentWidth , null);
g.drawImage(middleImage, thumbBounds.x, indentWidth,
thumbBounds.width-2,
thumbBounds.height-indentWidth , null);
g.drawImage(bottomImage, thumbBounds.x,
thumbBounds.height-indentWidth,
thumbBounds.width-2, indentWidth, null);
g.drawImage(verticalThumbHandle,
thumbBounds.width/2-verticalThumbHandle.getWidth()/2,
thumbBounds.height/2-verticalThumbHandle.getHeight()/2,
verticalThumbHandle.getWidth(),
verticalThumbHandle.getHeight(), null);
if (!isFreeStanding)
{
thumbBounds.width -= 2;
if(!leftToRight)
{
g.translate( 1, 0 );
}
}
}
else // HORIZONTAL
{
if (!isFreeStanding)
thumbBounds.height += 2;
imgWidth = horizontalThumb.getWidth();
imgHeight = horizontalThumb.getHeight();
Image leftImage
= horizontalThumb.getSubimage(0, 0,
indentWidth, imgHeight);
Image middleImage
= horizontalThumb.getSubimage(indentWidth, 0,
imgWidth-2*indentWidth,
imgHeight);
Image rightImage
= horizontalThumb.getSubimage(imgWidth-indentWidth, 0,
indentWidth,
imgHeight);
g.drawImage(leftImage, 0, 0,
indentWidth, thumbBounds.height-2, null);
g.drawImage(middleImage, indentWidth, thumbBounds.y,
thumbBounds.width-indentWidth,
thumbBounds.height-2 , null);
g.drawImage(rightImage, thumbBounds.width-indentWidth, thumbBounds.y,
indentWidth, thumbBounds.height-2, null);
g.drawImage(horizontalThumbHandle,
thumbBounds.width/2-horizontalThumbHandle.getWidth()/2,
thumbBounds.height/2-horizontalThumbHandle.getHeight()/2,
horizontalThumbHandle.getWidth(),
horizontalThumbHandle.getHeight(), null);
if (!isFreeStanding)
thumbBounds.height -= 2;
}
g.translate(-thumbBounds.x, -thumbBounds.y);
}
/**
* Returns the minimum scroll thumb size.
*
* @return the minimum scroll thumb size
*/
@Override
protected Dimension getMinimumThumbSize()
{
if(scrollbar.getOrientation() == JScrollBar.VERTICAL)
return new Dimension( scrollBarWidth,
verticalThumbHandle.getHeight()+4);
else
return new Dimension( horizontalThumbHandle.getWidth()+4,
scrollBarWidth);
}
/**
* Loads UI resources.
*/
public void loadSkin()
{
horizontalThumb = (BufferedImage)UIManager
.get("ScrollBar.horizontalThumbIcon");
verticalThumb = (BufferedImage)UIManager
.get("ScrollBar.verticalThumbIcon");
horizontalThumbHandle = (BufferedImage)UIManager
.get("ScrollBar.horizontalThumbHandleIcon");
verticalThumbHandle = (BufferedImage)UIManager
.get("ScrollBar.verticalThumbHandleIcon");
}
}
|