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