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