1 7 8 package javax.swing.plaf.synth; 9 10 import java.awt.*; 11 import java.beans.*; 12 import javax.swing.*; 13 import javax.swing.border.*; 14 import javax.swing.plaf.*; 15 import java.awt.*; 16 import java.awt.event.*; 17 import sun.swing.plaf.synth.SynthUI; 18 19 20 25 class SynthViewportUI extends ViewportUI implements 26 PropertyChangeListener, SynthUI { 27 private SynthStyle style; 28 29 public static ComponentUI createUI(JComponent c) { 30 return new SynthViewportUI (); 31 } 32 33 public void installUI(JComponent c) { 34 super.installUI(c); 35 installDefaults(c); 36 installListeners(c); 37 } 38 39 public void uninstallUI(JComponent c) { 40 super.uninstallUI(c); 41 uninstallListeners(c); 42 uninstallDefaults(c); 43 } 44 45 protected void installDefaults(JComponent c) { 46 updateStyle(c); 47 } 48 49 private void updateStyle(JComponent c) { 50 SynthContext context = getContext(c, ENABLED); 51 52 SynthStyle newStyle = SynthLookAndFeel.getStyle(context.getComponent(), 57 context.getRegion()); 58 SynthStyle oldStyle = context.getStyle(); 59 60 if (newStyle != oldStyle) { 61 if (oldStyle != null) { 62 oldStyle.uninstallDefaults(context); 63 } 64 context.setStyle(newStyle); 65 newStyle.installDefaults(context); 66 } 67 this.style = newStyle; 68 context.dispose(); 69 } 70 71 protected void installListeners(JComponent c) { 72 c.addPropertyChangeListener(this); 73 } 74 75 protected void uninstallListeners(JComponent c) { 76 c.removePropertyChangeListener(this); 77 } 78 79 protected void uninstallDefaults(JComponent c) { 80 SynthContext context = getContext(c, ENABLED); 81 style.uninstallDefaults(context); 82 context.dispose(); 83 style = null; 84 } 85 86 public SynthContext getContext(JComponent c) { 87 return getContext(c, getComponentState(c)); 88 } 89 90 private SynthContext getContext(JComponent c, int state) { 91 return SynthContext.getContext(SynthContext .class, c, 92 getRegion(c), style, state); 93 } 94 95 private Region getRegion(JComponent c) { 96 return SynthLookAndFeel.getRegion(c); 97 } 98 99 private int getComponentState(JComponent c) { 100 return SynthLookAndFeel.getComponentState(c); 101 } 102 103 public void update(Graphics g, JComponent c) { 104 SynthContext context = getContext(c); 105 106 SynthLookAndFeel.update(context, g); 107 context.getPainter().paintViewportBackground(context, 108 g, 0, 0, c.getWidth(), c.getHeight()); 109 paint(context, g); 110 context.dispose(); 111 } 112 113 public void paintBorder(SynthContext context, Graphics g, int x, 114 int y, int w, int h) { 115 } 118 119 public void paint(Graphics g, JComponent c) { 120 SynthContext context = getContext(c); 121 122 paint(context, g); 123 context.dispose(); 124 } 125 126 protected void paint(SynthContext context, Graphics g) { 127 } 128 129 public void propertyChange(PropertyChangeEvent e) { 130 if (SynthLookAndFeel.shouldUpdateStyle(e)) { 131 updateStyle((JComponent)e.getSource()); 132 } 133 } 134 } 135 | Popular Tags |