KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)MotifSliderUI.java 1.22 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
8 package com.sun.java.swing.plaf.motif;
9
10 import java.awt.*;
11 import java.awt.event.*;
12
13 import javax.swing.*;
14 import javax.swing.event.*;
15 import javax.swing.plaf.*;
16
17 import javax.swing.plaf.basic.BasicSliderUI JavaDoc;
18
19 /**
20  * Motif Slider
21  * <p>
22  * <strong>Warning:</strong>
23  * Serialized objects of this class will not be compatible with
24  * future Swing releases. The current serialization support is appropriate
25  * for short term storage or RMI between applications running the same
26  * version of Swing. A future release of Swing will provide support for
27  * long term persistence.
28  *
29  * @version 1.22 12/19/03
30  * @author Jeff Dinkins
31  */

32 public class MotifSliderUI extends BasicSliderUI JavaDoc {
33
34     static final Dimension PREFERRED_HORIZONTAL_SIZE = new Dimension(164, 15);
35     static final Dimension PREFERRED_VERTICAL_SIZE = new Dimension(15, 164);
36
37     static final Dimension MINIMUM_HORIZONTAL_SIZE = new Dimension(43, 15);
38     static final Dimension MINIMUM_VERTICAL_SIZE = new Dimension(15, 43);
39
40     /**
41      * MotifSliderUI Constructor
42      */

43     public MotifSliderUI(JSlider b) {
44         super(b);
45     }
46
47     /**
48      * create a MotifSliderUI object
49      */

50     public static ComponentUI createUI(JComponent b) {
51         return new MotifSliderUI((JSlider)b);
52     }
53
54     public Dimension getPreferredHorizontalSize() {
55         return PREFERRED_HORIZONTAL_SIZE;
56     }
57
58     public Dimension getPreferredVerticalSize() {
59         return PREFERRED_VERTICAL_SIZE;
60     }
61
62     public Dimension getMinimumHorizontalSize() {
63         return MINIMUM_HORIZONTAL_SIZE;
64     }
65
66     public Dimension getMinimumVerticalSize() {
67         return MINIMUM_VERTICAL_SIZE;
68     }
69
70     protected Dimension getThumbSize() {
71         if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
72         return new Dimension( 30, 15 );
73     }
74     else {
75         return new Dimension( 15, 30 );
76     }
77     }
78
79     public void paintFocus(Graphics g) {
80     }
81
82     public void paintTrack(Graphics g) {
83     }
84   
85     public void paintThumb(Graphics g) {
86         Rectangle knobBounds = thumbRect;
87
88         int x = knobBounds.x;
89         int y = knobBounds.y;
90         int w = knobBounds.width;
91         int h = knobBounds.height;
92
93         if ( slider.isEnabled() ) {
94             g.setColor(slider.getForeground());
95         }
96         else {
97             // PENDING(jeff) - the thumb should be dithered when disabled
98
g.setColor(slider.getForeground().darker());
99         }
100
101         if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
102             g.translate(x, knobBounds.y-1);
103
104             // fill
105
g.fillRect(0, 1, w, h - 1);
106
107             // highlight
108
g.setColor(getHighlightColor());
109             g.drawLine(0, 1, w - 1, 1); // top
110
g.drawLine(0, 1, 0, h); // left
111
g.drawLine(w/2, 2, w/2, h-1); // center
112

113             // shadow
114
g.setColor(getShadowColor());
115             g.drawLine(0, h, w - 1, h); // bottom
116
g.drawLine(w - 1, 1, w - 1, h); // right
117
g.drawLine(w/2 - 1, 2, w/2 - 1, h); // center
118

119             g.translate(-x, -(knobBounds.y-1));
120         }
121         else {
122             g.translate(knobBounds.x-1, 0);
123
124             // fill
125
g.fillRect(1, y, w - 1, h);
126
127             // highlight
128
g.setColor(getHighlightColor());
129             g.drawLine(1, y, w, y); // top
130
g.drawLine(1, y+1, 1, y+h-1); // left
131
g.drawLine(2, y+h/2, w-1, y+h/2); // center
132

133             // shadow
134
g.setColor(getShadowColor());
135             g.drawLine(2, y+h-1, w, y+h-1); // bottom
136
g.drawLine(w, y+h-1, w, y); // right
137
g.drawLine(2, y+h/2-1, w-1, y+h/2-1); // center
138

139             g.translate(-(knobBounds.x-1), 0);
140         }
141     }
142 }
143
144
Popular Tags