1 7 8 package javax.swing.plaf.synth; 9 10 11 import javax.swing.*; 12 import javax.swing.colorchooser.*; 13 import javax.swing.event.*; 14 import javax.swing.border.*; 15 import javax.swing.plaf.*; 16 import javax.swing.plaf.basic.BasicColorChooserUI ; 17 import java.util.*; 18 import java.awt.*; 19 import java.awt.image.*; 20 import java.awt.event.*; 21 import java.beans.PropertyChangeEvent ; 22 import java.beans.PropertyChangeListener ; 23 import java.io.Serializable ; 24 import sun.swing.plaf.synth.SynthUI; 25 26 27 34 class SynthColorChooserUI extends BasicColorChooserUI implements 35 PropertyChangeListener , SynthUI { 36 private SynthStyle style; 37 38 public static ComponentUI createUI(JComponent c) { 39 return new SynthColorChooserUI (); 40 } 41 42 protected AbstractColorChooserPanel[] createDefaultChoosers() { 43 SynthContext context = getContext(chooser, ENABLED); 44 AbstractColorChooserPanel[] panels = (AbstractColorChooserPanel[]) 45 context.getStyle().get(context, "ColorChooser.panels"); 46 context.dispose(); 47 48 if (panels == null) { 49 panels = ColorChooserComponentFactory.getDefaultChooserPanels(); 50 } 51 return panels; 52 } 53 54 protected void installDefaults() { 55 updateStyle(chooser); 56 } 57 58 private void updateStyle(JComponent c) { 59 SynthContext context = getContext(c, ENABLED); 60 style = SynthLookAndFeel.updateStyle(context, this); 61 context.dispose(); 62 } 63 64 protected void uninstallDefaults() { 65 SynthContext context = getContext(chooser, ENABLED); 66 67 style.uninstallDefaults(context); 68 context.dispose(); 69 style = null; 70 super.uninstallDefaults(); 71 } 72 73 protected void installListeners() { 74 super.installListeners(); 75 chooser.addPropertyChangeListener(this); 76 } 77 78 protected void uninstallListeners() { 79 chooser.removePropertyChangeListener(this); 80 super.uninstallListeners(); 81 } 82 83 public SynthContext getContext(JComponent c) { 84 return getContext(c, getComponentState(c)); 85 } 86 87 private SynthContext getContext(JComponent c, int state) { 88 return SynthContext.getContext(SynthContext .class, c, 89 SynthLookAndFeel.getRegion(c), style, state); 90 } 91 92 private Region getRegion(JComponent c) { 93 return SynthLookAndFeel.getRegion(c); 94 } 95 96 private int getComponentState(JComponent c) { 97 return SynthLookAndFeel.getComponentState(c); 98 } 99 100 public void update(Graphics g, JComponent c) { 101 SynthContext context = getContext(c); 102 103 SynthLookAndFeel.update(context, g); 104 context.getPainter().paintColorChooserBackground(context, g, 0, 0, 105 c.getWidth(), c.getHeight()); 106 paint(context, g); 107 context.dispose(); 108 } 109 110 public void paint(Graphics g, JComponent c) { 111 SynthContext context = getContext(c); 112 113 paint(context, g); 114 context.dispose(); 115 } 116 117 protected void paint(SynthContext context, Graphics g) { 118 } 119 120 public void paintBorder(SynthContext context, Graphics g, int x, 121 int y, int w, int h) { 122 context.getPainter().paintColorChooserBorder(context, g, x, y,w,h); 123 } 124 125 public void propertyChange(PropertyChangeEvent e) { 126 if (SynthLookAndFeel.shouldUpdateStyle(e)) { 127 updateStyle((JColorChooser)e.getSource()); 128 } 129 } 130 } 131 | Popular Tags |