KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > windows > WindowsSliderUI


1 /*
2  * @(#)WindowsSliderUI.java 1.18 06/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.windows;
9
10 import java.awt.*;
11
12 import javax.swing.plaf.*;
13 import javax.swing.plaf.basic.*;
14 import javax.swing.*;
15
16 import com.sun.java.swing.plaf.windows.TMSchema.*;
17 import com.sun.java.swing.plaf.windows.XPStyle.Skin;
18
19
20 /**
21  * Windows rendition of the component.
22  * <p>
23  * <strong>Warning:</strong>
24  * Serialized objects of this class will not be compatible with
25  * future Swing releases. The current serialization support is appropriate
26  * for short term storage or RMI between applications running the same
27  * version of Swing. A future release of Swing will provide support for
28  * long term persistence.
29  */

30 public class WindowsSliderUI extends BasicSliderUI
31 {
32     public WindowsSliderUI(JSlider b){
33     super(b);
34     }
35
36     public static ComponentUI createUI(JComponent b) {
37         return new WindowsSliderUI((JSlider)b);
38     }
39
40
41     public void paintTrack(Graphics g) {
42     XPStyle xp = XPStyle.getXP();
43     if (xp != null) {
44         boolean vertical = (slider.getOrientation() == JSlider.VERTICAL);
45             Part part = vertical ? Part.TKP_TRACKVERT : Part.TKP_TRACK;
46             Skin skin = xp.getSkin(slider, part);
47
48         if (vertical) {
49         int x = (trackRect.width - skin.getWidth()) / 2;
50                 skin.paintSkin(g, trackRect.x + x, trackRect.y,
51                                skin.getWidth(), trackRect.height, null);
52         } else {
53         int y = (trackRect.height - skin.getHeight()) / 2;
54                 skin.paintSkin(g, trackRect.x, trackRect.y + y,
55                                trackRect.width, skin.getHeight(), null);
56         }
57     } else {
58         super.paintTrack(g);
59     }
60     }
61
62
63     protected void paintMinorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) {
64     XPStyle xp = XPStyle.getXP();
65     if (xp != null) {
66             g.setColor(xp.getColor(slider, Part.TKP_TICS, null, Prop.COLOR, Color.black));
67     }
68     super.paintMinorTickForHorizSlider(g, tickBounds, x);
69     }
70
71     protected void paintMajorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) {
72     XPStyle xp = XPStyle.getXP();
73     if (xp != null) {
74             g.setColor(xp.getColor(slider, Part.TKP_TICS, null, Prop.COLOR, Color.black));
75     }
76     super.paintMajorTickForHorizSlider(g, tickBounds, x);
77     }
78
79     protected void paintMinorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) {
80     XPStyle xp = XPStyle.getXP();
81     if (xp != null) {
82             g.setColor(xp.getColor(slider, Part.TKP_TICSVERT, null, Prop.COLOR, Color.black));
83     }
84     super.paintMinorTickForVertSlider(g, tickBounds, y);
85     }
86
87     protected void paintMajorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) {
88     XPStyle xp = XPStyle.getXP();
89     if (xp != null) {
90             g.setColor(xp.getColor(slider, Part.TKP_TICSVERT, null, Prop.COLOR, Color.black));
91     }
92     super.paintMajorTickForVertSlider(g, tickBounds, y);
93     }
94
95
96     public void paintThumb(Graphics g) {
97     XPStyle xp = XPStyle.getXP();
98     if (xp != null) {
99         // Pending: Implement all five states
100
Part part = getXPThumbPart();
101             State state = slider.isEnabled() ? State.NORMAL : State.DISABLED;
102             xp.getSkin(slider, part).paintSkin(g, thumbRect.x, thumbRect.y, state);
103     } else {
104         super.paintThumb(g);
105     }
106     }
107
108     protected Dimension getThumbSize() {
109         XPStyle xp = XPStyle.getXP();
110     if (xp != null) {
111             Dimension size = new Dimension();
112             Skin s = xp.getSkin(slider, getXPThumbPart());
113             size.width = s.getWidth();
114             size.height = s.getHeight();
115             return size;
116     } else {
117         return super.getThumbSize();
118     }
119     }
120
121     private Part getXPThumbPart() {
122     XPStyle xp = XPStyle.getXP();
123         Part part;
124         boolean vertical = (slider.getOrientation() == JSlider.VERTICAL);
125     boolean leftToRight = slider.getComponentOrientation().isLeftToRight();
126     Boolean JavaDoc paintThumbArrowShape =
127         (Boolean JavaDoc)slider.getClientProperty("Slider.paintThumbArrowShape");
128     if ((!slider.getPaintTicks() && paintThumbArrowShape == null) ||
129             paintThumbArrowShape == Boolean.FALSE) {
130             part = vertical ? Part.TKP_THUMBVERT
131                 : Part.TKP_THUMB;
132     } else {
133             part = vertical
134                 ? (leftToRight ? Part.TKP_THUMBRIGHT : Part.TKP_THUMBLEFT)
135                 : Part.TKP_THUMBBOTTOM;
136     }
137         return part;
138     }
139 }
140
141
Popular Tags