1. /*
  2. * @(#)MotifScrollBarUI.java 1.9 01/11/29
  3. *
  4. * Copyright 2002 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 javax.swing.*;
  9. import javax.swing.event.*;
  10. import javax.swing.plaf.*;
  11. import javax.swing.border.*;
  12. import javax.swing.plaf.basic.BasicScrollBarUI;
  13. import javax.swing.plaf.basic.BasicGraphicsUtils;
  14. import java.awt.Dimension;
  15. import java.awt.Insets;
  16. import java.awt.Rectangle;
  17. import java.awt.Graphics;
  18. import java.awt.Color;
  19. /**
  20. * Implementation of ScrollBarUI for the Motif Look and Feel
  21. * <p>
  22. * <strong>Warning:</strong>
  23. * Serialized objects of this class will not be compatible with
  24. * future Swing releases. The current serialization support is appropriate
  25. * for short term storage or RMI between applications running the same
  26. * version of Swing. A future release of Swing will provide support for
  27. * long term persistence.
  28. *
  29. * @version 1.9 11/29/01
  30. * @author Rich Schiavi
  31. * @author Hans Muller
  32. */
  33. public class MotifScrollBarUI extends BasicScrollBarUI
  34. {
  35. public static ComponentUI createUI(JComponent c) {
  36. return new MotifScrollBarUI();
  37. }
  38. public Dimension getPreferredSize(JComponent c) {
  39. Insets insets = c.getInsets();
  40. int dx = insets.left + insets.right;
  41. int dy = insets.top + insets.bottom;
  42. return (scrollbar.getOrientation() == JScrollBar.VERTICAL)
  43. ? new Dimension(dx + 11, dy + 33)
  44. : new Dimension(dx + 33, dy + 11);
  45. }
  46. protected JButton createDecreaseButton(int orientation) {
  47. return new MotifScrollBarButton(orientation);
  48. }
  49. protected JButton createIncreaseButton(int orientation) {
  50. return new MotifScrollBarButton(orientation);
  51. }
  52. public void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
  53. g.setColor(trackColor);
  54. g.fillRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height);
  55. }
  56. public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
  57. {
  58. if(thumbBounds.isEmpty() || !scrollbar.isEnabled()) {
  59. return;
  60. }
  61. int w = thumbBounds.width;
  62. int h = thumbBounds.height;
  63. g.translate(thumbBounds.x, thumbBounds.y);
  64. g.setColor(thumbColor);
  65. g.fillRect(0, 0, w-1, h-1);
  66. g.setColor(thumbHighlightColor);
  67. g.drawLine(0, 0, 0, h-1);
  68. g.drawLine(1, 0, w-1, 0);
  69. g.setColor(thumbLightShadowColor);
  70. g.drawLine(1, h-1, w-1, h-1);
  71. g.drawLine(w-1, 1, w-1, h-2);
  72. g.translate(-thumbBounds.x, -thumbBounds.y);
  73. }
  74. }