1. /*
  2. * @(#)WindowsSliderUI.java 1.13 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.java.swing.plaf.windows;
  8. import java.awt.*;
  9. import javax.swing.plaf.*;
  10. import javax.swing.plaf.basic.*;
  11. import javax.swing.*;
  12. /**
  13. * Windows rendition of the component.
  14. * <p>
  15. * <strong>Warning:</strong>
  16. * Serialized objects of this class will not be compatible with
  17. * future Swing releases. The current serialization support is appropriate
  18. * for short term storage or RMI between applications running the same
  19. * version of Swing. A future release of Swing will provide support for
  20. * long term persistence.
  21. */
  22. public class WindowsSliderUI extends BasicSliderUI
  23. {
  24. public WindowsSliderUI(JSlider b){
  25. super(b);
  26. }
  27. public static ComponentUI createUI(JComponent b) {
  28. return new WindowsSliderUI((JSlider)b);
  29. }
  30. public void paintTrack(Graphics g) {
  31. XPStyle xp = XPStyle.getXP();
  32. if (xp != null) {
  33. boolean vertical = (slider.getOrientation() == JSlider.VERTICAL);
  34. String category = vertical ? "trackbar.trackvert" : "trackbar.track";
  35. XPStyle.Skin skin = xp.getSkin(category);
  36. if (vertical) {
  37. int x = (trackRect.width - skin.getWidth()) / 2;
  38. skin.paintSkin(g, trackRect.x + x, trackRect.y, skin.getWidth(), trackRect.height, 0);
  39. } else {
  40. int y = (trackRect.height - skin.getHeight()) / 2;
  41. skin.paintSkin(g, trackRect.x, trackRect.y + y, trackRect.width, skin.getHeight(), 0);
  42. }
  43. } else {
  44. super.paintTrack(g);
  45. }
  46. }
  47. protected void paintMinorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) {
  48. XPStyle xp = XPStyle.getXP();
  49. if (xp != null) {
  50. g.setColor(xp.getColor("trackbar.tics.color", Color.black));
  51. }
  52. super.paintMinorTickForHorizSlider(g, tickBounds, x);
  53. }
  54. protected void paintMajorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) {
  55. XPStyle xp = XPStyle.getXP();
  56. if (xp != null) {
  57. g.setColor(xp.getColor("trackbar.tics.color", Color.black));
  58. }
  59. super.paintMajorTickForHorizSlider(g, tickBounds, x);
  60. }
  61. protected void paintMinorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) {
  62. XPStyle xp = XPStyle.getXP();
  63. if (xp != null) {
  64. g.setColor(xp.getColor("trackbar.ticsvert.color", Color.black));
  65. }
  66. super.paintMinorTickForVertSlider(g, tickBounds, y);
  67. }
  68. protected void paintMajorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) {
  69. XPStyle xp = XPStyle.getXP();
  70. if (xp != null) {
  71. g.setColor(xp.getColor("trackbar.ticsvert.color", Color.black));
  72. }
  73. super.paintMajorTickForVertSlider(g, tickBounds, y);
  74. }
  75. public void paintThumb(Graphics g) {
  76. XPStyle xp = XPStyle.getXP();
  77. if (xp != null) {
  78. String category;
  79. boolean vertical = (slider.getOrientation() == JSlider.VERTICAL);
  80. boolean leftToRight = slider.getComponentOrientation().isLeftToRight();
  81. if (!slider.getPaintTicks()) {
  82. category = vertical ? "trackbar.thumbvert"
  83. : "trackbar.thumb";
  84. } else {
  85. category = vertical ? (leftToRight ? "trackbar.thumbright" : "trackbar.thumbleft")
  86. : "trackbar.thumbbottom";
  87. }
  88. // Pending: Implement all five states
  89. int index = 0;
  90. if (!slider.isEnabled()) {
  91. index = 4;
  92. }
  93. xp.getSkin(category).paintSkin(g, thumbRect.x, thumbRect.y, index);
  94. } else {
  95. super.paintThumb(g);
  96. }
  97. }
  98. }