1 7 8 package javax.swing.plaf.metal; 9 10 import javax.swing.*; 11 import javax.swing.event.*; 12 import javax.swing.border.*; 13 import javax.swing.plaf.*; 14 import javax.swing.plaf.basic.*; 15 16 import java.awt.*; 17 import java.beans.*; 18 import java.awt.event.*; 19 20 21 36 public class MetalScrollPaneUI extends BasicScrollPaneUI 37 { 38 39 private PropertyChangeListener scrollBarSwapListener; 40 41 public static ComponentUI createUI(JComponent x) { 42 return new MetalScrollPaneUI (); 43 } 44 45 public void installUI(JComponent c) { 46 47 super.installUI(c); 48 49 JScrollPane sp = (JScrollPane)c; 50 updateScrollbarsFreeStanding(); 51 } 52 53 public void uninstallUI(JComponent c) { 54 super.uninstallUI(c); 55 56 JScrollPane sp = (JScrollPane)c; 57 JScrollBar hsb = sp.getHorizontalScrollBar(); 58 JScrollBar vsb = sp.getVerticalScrollBar(); 59 if (hsb != null) { 60 hsb.putClientProperty( MetalScrollBarUI.FREE_STANDING_PROP, null); 61 } 62 if (vsb != null) { 63 vsb.putClientProperty( MetalScrollBarUI.FREE_STANDING_PROP, null); 64 } 65 } 66 67 68 public void installListeners(JScrollPane scrollPane) { 69 super.installListeners(scrollPane); 70 scrollBarSwapListener = createScrollBarSwapListener(); 71 scrollPane.addPropertyChangeListener(scrollBarSwapListener); 72 } 73 74 75 public void uninstallListeners(JScrollPane scrollPane) { 76 super.uninstallListeners(scrollPane); 77 78 scrollPane.removePropertyChangeListener(scrollBarSwapListener); 79 } 80 81 87 private void updateScrollbarsFreeStanding() { 88 if (scrollpane == null) { 89 return; 90 } 91 Border border = scrollpane.getBorder(); 92 Object value; 93 94 if (border instanceof MetalBorders.ScrollPaneBorder ) { 95 value = Boolean.FALSE; 96 } 97 else { 98 value = Boolean.TRUE; 99 } 100 JScrollBar sb = scrollpane.getHorizontalScrollBar(); 101 if (sb != null) { 102 sb.putClientProperty 103 (MetalScrollBarUI.FREE_STANDING_PROP, value); 104 } 105 sb = scrollpane.getVerticalScrollBar(); 106 if (sb != null) { 107 sb.putClientProperty 108 (MetalScrollBarUI.FREE_STANDING_PROP, value); 109 } 110 } 111 112 protected PropertyChangeListener createScrollBarSwapListener() { 113 return new PropertyChangeListener() { 114 public void propertyChange(PropertyChangeEvent e) { 115 String propertyName = e.getPropertyName(); 116 if (propertyName.equals("verticalScrollBar") || 117 propertyName.equals("horizontalScrollBar")) { 118 JScrollBar oldSB = (JScrollBar)e.getOldValue(); 119 if (oldSB != null) { 120 oldSB.putClientProperty( 121 MetalScrollBarUI.FREE_STANDING_PROP, null); 122 } 123 JScrollBar newSB = (JScrollBar)e.getNewValue(); 124 if (newSB != null) { 125 newSB.putClientProperty( 126 MetalScrollBarUI.FREE_STANDING_PROP, 127 Boolean.FALSE); 128 } 129 } 130 else if ("border".equals(propertyName)) { 131 updateScrollbarsFreeStanding(); 132 } 133 }}; 134 } 135 136 } 137 | Popular Tags |