1 7 8 package com.sun.java.swing.plaf.motif; 9 10 import javax.swing.*; 11 import javax.swing.border.*; 12 import javax.swing.plaf.*; 13 import javax.swing.plaf.basic.BasicScrollPaneUI ; 14 15 import java.beans.PropertyChangeEvent ; 16 import java.beans.PropertyChangeListener ; 17 18 31 public class MotifScrollPaneUI extends BasicScrollPaneUI 32 { 33 private final static Border vsbMarginBorderR = new EmptyBorder(0, 4, 0, 0); 34 private final static Border vsbMarginBorderL = new EmptyBorder(0, 0, 0, 4); 35 private final static Border hsbMarginBorder = new EmptyBorder(4, 0, 0, 0); 36 37 private CompoundBorder vsbBorder; 38 private CompoundBorder hsbBorder; 39 40 private PropertyChangeListener propertyChangeHandler; 41 42 protected void installListeners(JScrollPane scrollPane) { 43 super.installListeners(scrollPane); 44 propertyChangeHandler = createPropertyChangeHandler(); 45 scrollPane.addPropertyChangeListener(propertyChangeHandler); 46 } 47 48 protected void uninstallListeners(JScrollPane scrollPane) { 49 super.uninstallListeners(scrollPane); 50 scrollPane.removePropertyChangeListener(propertyChangeHandler); 51 } 52 53 private PropertyChangeListener createPropertyChangeHandler() { 54 return new PropertyChangeListener () { 55 public void propertyChange(PropertyChangeEvent e) { 56 String propertyName = e.getPropertyName(); 57 58 if (propertyName.equals("componentOrientation")) { 59 JScrollPane pane = (JScrollPane)e.getSource(); 60 JScrollBar vsb = pane.getVerticalScrollBar(); 61 if (vsb != null && vsbBorder != null && 62 vsb.getBorder() == vsbBorder) { 63 if (MotifGraphicsUtils.isLeftToRight(pane)) { 66 vsbBorder = new CompoundBorder(vsbMarginBorderR, 67 vsbBorder.getInsideBorder()); 68 } else { 69 vsbBorder = new CompoundBorder(vsbMarginBorderL, 70 vsbBorder.getInsideBorder()); 71 } 72 vsb.setBorder(vsbBorder); 73 } 74 } 75 }}; 76 } 77 78 protected void installDefaults(JScrollPane scrollpane) { 79 super.installDefaults(scrollpane); 80 81 JScrollBar vsb = scrollpane.getVerticalScrollBar(); 82 if (vsb != null) { 83 if (MotifGraphicsUtils.isLeftToRight(scrollpane)) { 84 vsbBorder = new CompoundBorder(vsbMarginBorderR, 85 vsb.getBorder()); 86 } 87 else { 88 vsbBorder = new CompoundBorder(vsbMarginBorderL, 89 vsb.getBorder()); 90 } 91 vsb.setBorder(vsbBorder); 92 } 93 94 JScrollBar hsb = scrollpane.getHorizontalScrollBar(); 95 if (hsb != null) { 96 hsbBorder = new CompoundBorder(hsbMarginBorder, hsb.getBorder()); 97 hsb.setBorder(hsbBorder); 98 } 99 } 100 101 102 protected void uninstallDefaults(JScrollPane c) { 103 super.uninstallDefaults(c); 104 105 JScrollBar vsb = scrollpane.getVerticalScrollBar(); 106 if (vsb != null) { 107 if (vsb.getBorder() == vsbBorder) { 108 vsb.setBorder(null); 109 } 110 vsbBorder = null; 111 } 112 113 JScrollBar hsb = scrollpane.getHorizontalScrollBar(); 114 if (hsb != null) { 115 if (hsb.getBorder() == hsbBorder) { 116 hsb.setBorder(null); 117 } 118 hsbBorder = null; 119 } 120 } 121 122 123 public static ComponentUI createUI(JComponent x) { 124 return new MotifScrollPaneUI(); 125 } 126 } 127 128 | Popular Tags |