1. /*
  2. * @(#)MotifSliderUI.java 1.21 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.motif;
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import javax.swing.*;
  11. import javax.swing.event.*;
  12. import javax.swing.plaf.*;
  13. import javax.swing.plaf.basic.BasicSliderUI;
  14. /**
  15. * Motif Slider
  16. * <p>
  17. * <strong>Warning:</strong>
  18. * Serialized objects of this class will not be compatible with
  19. * future Swing releases. The current serialization support is appropriate
  20. * for short term storage or RMI between applications running the same
  21. * version of Swing. A future release of Swing will provide support for
  22. * long term persistence.
  23. *
  24. * @version 1.21 01/23/03
  25. * @author Jeff Dinkins
  26. */
  27. public class MotifSliderUI extends BasicSliderUI {
  28. static final Dimension PREFERRED_HORIZONTAL_SIZE = new Dimension(164, 15);
  29. static final Dimension PREFERRED_VERTICAL_SIZE = new Dimension(15, 164);
  30. static final Dimension MINIMUM_HORIZONTAL_SIZE = new Dimension(43, 15);
  31. static final Dimension MINIMUM_VERTICAL_SIZE = new Dimension(15, 43);
  32. /**
  33. * MotifSliderUI Constructor
  34. */
  35. public MotifSliderUI(JSlider b) {
  36. super(b);
  37. }
  38. /**
  39. * create a MotifSliderUI object
  40. */
  41. public static ComponentUI createUI(JComponent b) {
  42. return new MotifSliderUI((JSlider)b);
  43. }
  44. public Dimension getPreferredHorizontalSize() {
  45. return PREFERRED_HORIZONTAL_SIZE;
  46. }
  47. public Dimension getPreferredVerticalSize() {
  48. return PREFERRED_VERTICAL_SIZE;
  49. }
  50. public Dimension getMinimumHorizontalSize() {
  51. return MINIMUM_HORIZONTAL_SIZE;
  52. }
  53. public Dimension getMinimumVerticalSize() {
  54. return MINIMUM_VERTICAL_SIZE;
  55. }
  56. protected Dimension getThumbSize() {
  57. if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
  58. return new Dimension( 30, 15 );
  59. }
  60. else {
  61. return new Dimension( 15, 30 );
  62. }
  63. }
  64. public void paintFocus(Graphics g) {
  65. }
  66. public void paintTrack(Graphics g) {
  67. }
  68. public void paintThumb(Graphics g) {
  69. Rectangle knobBounds = thumbRect;
  70. int x = knobBounds.x;
  71. int y = knobBounds.y;
  72. int w = knobBounds.width;
  73. int h = knobBounds.height;
  74. if ( slider.isEnabled() ) {
  75. g.setColor(slider.getForeground());
  76. }
  77. else {
  78. // PENDING(jeff) - the thumb should be dithered when disabled
  79. g.setColor(slider.getForeground().darker());
  80. }
  81. if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
  82. g.translate(x, knobBounds.y-1);
  83. // fill
  84. g.fillRect(0, 1, w, h - 1);
  85. // highlight
  86. g.setColor(getHighlightColor());
  87. g.drawLine(0, 1, w - 1, 1); // top
  88. g.drawLine(0, 1, 0, h); // left
  89. g.drawLine(w2, 2, w2, h-1); // center
  90. // shadow
  91. g.setColor(getShadowColor());
  92. g.drawLine(0, h, w - 1, h); // bottom
  93. g.drawLine(w - 1, 1, w - 1, h); // right
  94. g.drawLine(w2 - 1, 2, w2 - 1, h); // center
  95. g.translate(-x, -(knobBounds.y-1));
  96. }
  97. else {
  98. g.translate(knobBounds.x-1, 0);
  99. // fill
  100. g.fillRect(1, y, w - 1, h);
  101. // highlight
  102. g.setColor(getHighlightColor());
  103. g.drawLine(1, y, w, y); // top
  104. g.drawLine(1, y+1, 1, y+h-1); // left
  105. g.drawLine(2, y+h2, w-1, y+h2); // center
  106. // shadow
  107. g.setColor(getShadowColor());
  108. g.drawLine(2, y+h-1, w, y+h-1); // bottom
  109. g.drawLine(w, y+h-1, w, y); // right
  110. g.drawLine(2, y+h2-1, w-1, y+h2-1); // center
  111. g.translate(-(knobBounds.x-1), 0);
  112. }
  113. }
  114. }