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