KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > motif > MotifScrollBarUI


1 /*
2  * @(#)MotifScrollBarUI.java 1.14 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package com.sun.java.swing.plaf.motif;
8
9 import javax.swing.*;
10 import javax.swing.event.*;
11 import javax.swing.plaf.*;
12 import javax.swing.border.*;
13 import javax.swing.plaf.basic.BasicScrollBarUI JavaDoc;
14
15 import java.awt.Dimension JavaDoc;
16 import java.awt.Insets JavaDoc;
17 import java.awt.Rectangle JavaDoc;
18 import java.awt.Graphics JavaDoc;
19 import java.awt.Color JavaDoc;
20
21
22 /**
23  * Implementation of ScrollBarUI for the Motif Look and Feel
24  * <p>
25  * <strong>Warning:</strong>
26  * Serialized objects of this class will not be compatible with
27  * future Swing releases. The current serialization support is appropriate
28  * for short term storage or RMI between applications running the same
29  * version of Swing. A future release of Swing will provide support for
30  * long term persistence.
31  *
32  * @version 1.14 12/19/03
33  * @author Rich Schiavi
34  * @author Hans Muller
35  */

36 public class MotifScrollBarUI extends BasicScrollBarUI JavaDoc
37 {
38
39     public static ComponentUI createUI(JComponent c) {
40     return new MotifScrollBarUI();
41     }
42
43     public Dimension JavaDoc getPreferredSize(JComponent c) {
44     Insets JavaDoc insets = c.getInsets();
45     int dx = insets.left + insets.right;
46     int dy = insets.top + insets.bottom;
47     return (scrollbar.getOrientation() == JScrollBar.VERTICAL)
48         ? new Dimension JavaDoc(dx + 11, dy + 33)
49         : new Dimension JavaDoc(dx + 33, dy + 11);
50     }
51
52     protected JButton createDecreaseButton(int orientation) {
53     return new MotifScrollBarButton(orientation);
54     }
55
56     protected JButton createIncreaseButton(int orientation) {
57     return new MotifScrollBarButton(orientation);
58     }
59   
60
61     public void paintTrack(Graphics JavaDoc g, JComponent c, Rectangle JavaDoc trackBounds) {
62         g.setColor(trackColor);
63         g.fillRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height);
64     }
65
66
67     public void paintThumb(Graphics JavaDoc g, JComponent c, Rectangle JavaDoc thumbBounds)
68     {
69
70     if(thumbBounds.isEmpty() || !scrollbar.isEnabled()) {
71         return;
72     }
73
74     int w = thumbBounds.width;
75     int h = thumbBounds.height;
76
77     g.translate(thumbBounds.x, thumbBounds.y);
78     g.setColor(thumbColor);
79     g.fillRect(0, 0, w-1, h-1);
80       
81     g.setColor(thumbHighlightColor);
82     g.drawLine(0, 0, 0, h-1);
83     g.drawLine(1, 0, w-1, 0);
84       
85     g.setColor(thumbLightShadowColor);
86     g.drawLine(1, h-1, w-1, h-1);
87     g.drawLine(w-1, 1, w-1, h-2);
88
89     g.translate(-thumbBounds.x, -thumbBounds.y);
90     }
91 }
92
Popular Tags