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