1 7 8 package javax.swing.plaf.synth; 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.beans.PropertyChangeListener ; 17 import java.beans.PropertyChangeEvent ; 18 19 import java.awt.*; 20 import java.awt.event.*; 21 import sun.swing.plaf.synth.SynthUI; 22 23 24 30 class SynthScrollPaneUI extends BasicScrollPaneUI implements 31 PropertyChangeListener , SynthUI { 32 private SynthStyle style; 33 34 public static ComponentUI createUI(JComponent x) { 35 return new SynthScrollPaneUI (); 36 } 37 38 public void update(Graphics g, JComponent c) { 39 SynthContext context = getContext(c); 40 41 SynthLookAndFeel.update(context, g); 42 context.getPainter().paintScrollPaneBackground(context, 43 g, 0, 0, c.getWidth(), c.getHeight()); 44 paint(context, g); 45 context.dispose(); 46 } 47 48 public void paint(Graphics g, JComponent c) { 49 SynthContext context = getContext(c); 50 51 paint(context, g); 52 context.dispose(); 53 } 54 55 protected void paint(SynthContext context, Graphics g) { 56 Border vpBorder = scrollpane.getViewportBorder(); 57 if (vpBorder != null) { 58 Rectangle r = scrollpane.getViewportBorderBounds(); 59 vpBorder.paintBorder(scrollpane, g, r.x, r.y, r.width, r.height); 60 } 61 } 62 63 64 public void paintBorder(SynthContext context, Graphics g, int x, 65 int y, int w, int h) { 66 context.getPainter().paintScrollPaneBorder(context, g, x, y, w, h); 67 } 68 69 protected void installDefaults(JScrollPane scrollpane) { 70 updateStyle(scrollpane); 71 } 72 73 private void updateStyle(JScrollPane c) { 74 SynthContext context = getContext(c, ENABLED); 75 SynthStyle oldStyle = style; 76 77 style = SynthLookAndFeel.updateStyle(context, this); 78 if (style != oldStyle) { 79 Border vpBorder = scrollpane.getViewportBorder(); 80 if ((vpBorder == null) ||( vpBorder instanceof UIResource)) { 81 scrollpane.setViewportBorder(new ViewportBorder(context)); 82 } 83 if (oldStyle != null) { 84 uninstallKeyboardActions(c); 85 installKeyboardActions(c); 86 } 87 } 88 context.dispose(); 89 } 90 91 92 protected void installListeners(JScrollPane c) { 93 super.installListeners(c); 94 c.addPropertyChangeListener(this); 95 } 96 97 protected void uninstallDefaults(JScrollPane c) { 98 SynthContext context = getContext(c, ENABLED); 99 100 style.uninstallDefaults(context); 101 context.dispose(); 102 103 if (scrollpane.getViewportBorder() instanceof UIResource) { 104 scrollpane.setViewportBorder(null); 105 } 106 } 107 108 109 protected void uninstallListeners(JComponent c) { 110 super.uninstallListeners(c); 111 c.removePropertyChangeListener(this); 112 } 113 114 115 public SynthContext getContext(JComponent c) { 116 return getContext(c, getComponentState(c)); 117 } 118 119 private SynthContext getContext(JComponent c, int state) { 120 return SynthContext.getContext(SynthContext .class, c, 121 SynthLookAndFeel.getRegion(c), style, state); 122 } 123 124 125 private Region getRegion(JComponent c) { 126 return SynthLookAndFeel.getRegion(c); 127 } 128 129 130 private int getComponentState(JComponent c) { 131 return SynthLookAndFeel.getComponentState(c); 132 } 133 134 public void propertyChange(PropertyChangeEvent e) { 135 if (SynthLookAndFeel.shouldUpdateStyle(e)) { 136 updateStyle(scrollpane); 137 } 138 } 139 140 141 142 private class ViewportBorder extends AbstractBorder implements UIResource { 143 private Insets insets; 144 145 ViewportBorder(SynthContext context) { 146 this.insets = (Insets)context.getStyle().get(context, 147 "ScrollPane.viewportBorderInsets"); 148 if (this.insets == null) { 149 this.insets = SynthLookAndFeel.EMPTY_UIRESOURCE_INSETS; 150 } 151 } 152 153 public void paintBorder(Component c, Graphics g, int x, int y, 154 int width, int height) { 155 JComponent jc = (JComponent)c; 156 SynthContext context = getContext(jc); 157 SynthStyle style = context.getStyle(); 158 if (style == null) { 159 assert false: "SynthBorder is being used outside after the " + 160 " UI has been uninstalled"; 161 return; 162 } 163 context.getPainter().paintViewportBorder(context, g, x, y, width, 164 height); 165 context.dispose(); 166 } 167 168 public Insets getBorderInsets(Component c) { 169 return getBorderInsets(c, null); 170 } 171 172 public Insets getBorderInsets(Component c, Insets insets) { 173 if (insets == null) { 174 return new Insets(this.insets.top, this.insets.left, 175 this.insets.bottom, this.insets.right); 176 } 177 insets.top = this.insets.top; 178 insets.bottom = this.insets.bottom; 179 insets.left = this.insets.left; 180 insets.right = this.insets.left; 181 return insets; 182 } 183 184 public boolean isBorderOpaque() { 185 return false; 186 } 187 } 188 } 189 | Popular Tags |