1. /*
  2. * @(#)MetalScrollPaneUI.java 1.12 00/02/02
  3. *
  4. * Copyright 1998-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 javax.swing.plaf.metal;
  11. import javax.swing.*;
  12. import javax.swing.event.*;
  13. import javax.swing.border.*;
  14. import javax.swing.plaf.*;
  15. import javax.swing.plaf.basic.*;
  16. import java.awt.*;
  17. import java.beans.*;
  18. import java.awt.event.*;
  19. /**
  20. * A Metal L&F implementation of ScrollPaneUI.
  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. * @1.12 02/02/00
  30. * @author Steve Wilson
  31. */
  32. public class MetalScrollPaneUI extends BasicScrollPaneUI
  33. {
  34. private PropertyChangeListener scrollBarSwapListener;
  35. public static ComponentUI createUI(JComponent x) {
  36. return new MetalScrollPaneUI();
  37. }
  38. public void installUI(JComponent c) {
  39. super.installUI(c);
  40. JScrollPane sp = (JScrollPane)c;
  41. JScrollBar hsb = sp.getHorizontalScrollBar();
  42. JScrollBar vsb = sp.getVerticalScrollBar();
  43. hsb.putClientProperty( MetalScrollBarUI.FREE_STANDING_PROP, Boolean.FALSE);
  44. vsb.putClientProperty( MetalScrollBarUI.FREE_STANDING_PROP, Boolean.FALSE);
  45. }
  46. public void uninstallUI(JComponent c) {
  47. super.uninstallUI(c);
  48. JScrollPane sp = (JScrollPane)c;
  49. JScrollBar hsb = sp.getHorizontalScrollBar();
  50. JScrollBar vsb = sp.getVerticalScrollBar();
  51. hsb.putClientProperty( MetalScrollBarUI.FREE_STANDING_PROP, null);
  52. vsb.putClientProperty( MetalScrollBarUI.FREE_STANDING_PROP, null);
  53. }
  54. public void installListeners(JScrollPane scrollPane) {
  55. super.installListeners(scrollPane);
  56. scrollBarSwapListener = createScrollBarSwapListener();
  57. scrollPane.addPropertyChangeListener(scrollBarSwapListener);
  58. }
  59. public void uninstallListeners(JScrollPane scrollPane) {
  60. super.uninstallListeners(scrollPane);
  61. scrollPane.removePropertyChangeListener(scrollBarSwapListener);
  62. }
  63. protected PropertyChangeListener createScrollBarSwapListener() {
  64. return new PropertyChangeListener() {
  65. public void propertyChange(PropertyChangeEvent e) {
  66. String propertyName = e.getPropertyName();
  67. if (propertyName.equals("verticalScrollBar") ||
  68. propertyName.equals("horizontalScrollBar")) {
  69. ((JScrollBar)e.getOldValue()).putClientProperty( MetalScrollBarUI.FREE_STANDING_PROP,
  70. null);
  71. ((JScrollBar)e.getNewValue()).putClientProperty( MetalScrollBarUI.FREE_STANDING_PROP,
  72. Boolean.FALSE);
  73. }
  74. }};
  75. }
  76. }