1 30 31 package com.jgoodies.looks.plastic; 32 33 import java.beans.PropertyChangeEvent ; 34 import java.beans.PropertyChangeListener ; 35 36 import javax.swing.JComponent ; 37 import javax.swing.JScrollPane ; 38 import javax.swing.LookAndFeel ; 39 import javax.swing.plaf.ComponentUI ; 40 import javax.swing.plaf.metal.MetalScrollPaneUI ; 41 42 import com.jgoodies.looks.Options; 43 44 54 public final class PlasticScrollPaneUI extends MetalScrollPaneUI { 55 56 59 private PropertyChangeListener borderStyleChangeHandler; 60 61 public static ComponentUI createUI(JComponent b) { 62 return new PlasticScrollPaneUI(); 63 } 64 65 protected void installDefaults(JScrollPane scrollPane) { 66 super.installDefaults(scrollPane); 67 installEtchedBorder(scrollPane); 68 } 69 70 71 73 public void installListeners(JScrollPane scrollPane) { 74 super.installListeners(scrollPane); 75 borderStyleChangeHandler = new BorderStyleChangeHandler(); 76 scrollPane.addPropertyChangeListener(Options.IS_ETCHED_KEY, borderStyleChangeHandler); 77 } 78 79 protected void uninstallListeners(JComponent c) { 80 ((JScrollPane ) c).removePropertyChangeListener(Options.IS_ETCHED_KEY, 81 borderStyleChangeHandler); 82 super.uninstallListeners(c); 83 } 84 85 protected void installEtchedBorder(JScrollPane scrollPane) { 86 Object value = scrollPane.getClientProperty(Options.IS_ETCHED_KEY); 87 boolean hasEtchedBorder = Boolean.TRUE.equals(value); 88 LookAndFeel.installBorder(scrollPane, 89 hasEtchedBorder 90 ? "ScrollPane.etchedBorder" 91 : "ScrollPane.border"); 92 } 93 94 private class BorderStyleChangeHandler implements PropertyChangeListener { 95 96 public void propertyChange(PropertyChangeEvent evt) { 97 JScrollPane scrollPane = (JScrollPane ) evt.getSource(); 98 installEtchedBorder(scrollPane); 99 } 100 101 } 102 103 } | Popular Tags |