1. /*
  2. * @(#)WindowsSliderUI.java 1.16 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.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. // Pending: Implement all five states
  79. int index = 0;
  80. if (!slider.isEnabled()) {
  81. index = 4;
  82. }
  83. getXPThumbSkin().paintSkin(g, thumbRect.x, thumbRect.y, index);
  84. } else {
  85. super.paintThumb(g);
  86. }
  87. }
  88. protected Dimension getThumbSize() {
  89. XPStyle xp = XPStyle.getXP();
  90. if (xp != null) {
  91. Dimension size = new Dimension();
  92. XPStyle.Skin s = getXPThumbSkin();
  93. size.width = s.getWidth();
  94. size.height = s.getHeight();
  95. return size;
  96. } else {
  97. return super.getThumbSize();
  98. }
  99. }
  100. private XPStyle.Skin getXPThumbSkin() {
  101. XPStyle xp = XPStyle.getXP();
  102. String category;
  103. boolean vertical = (slider.getOrientation() == JSlider.VERTICAL);
  104. boolean leftToRight = slider.getComponentOrientation().isLeftToRight();
  105. Boolean paintThumbArrowShape =
  106. (Boolean)slider.getClientProperty("Slider.paintThumbArrowShape");
  107. if ((!slider.getPaintTicks() && paintThumbArrowShape == null) ||
  108. paintThumbArrowShape == Boolean.FALSE) {
  109. category = vertical ? "trackbar.thumbvert"
  110. : "trackbar.thumb";
  111. } else {
  112. category = vertical ? (leftToRight ? "trackbar.thumbright" : "trackbar.thumbleft")
  113. : "trackbar.thumbbottom";
  114. }
  115. return xp.getSkin(category);
  116. }
  117. }