1. /*
  2. * @(#)SynthColorChooserUI.java 1.11 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.plaf.synth;
  8. import javax.swing.*;
  9. import javax.swing.colorchooser.*;
  10. import javax.swing.event.*;
  11. import javax.swing.border.*;
  12. import javax.swing.plaf.*;
  13. import javax.swing.plaf.basic.BasicColorChooserUI;
  14. import java.util.*;
  15. import java.awt.*;
  16. import java.awt.image.*;
  17. import java.awt.event.*;
  18. import java.beans.PropertyChangeEvent;
  19. import java.beans.PropertyChangeListener;
  20. import java.io.Serializable;
  21. import sun.swing.plaf.synth.SynthUI;
  22. /**
  23. * Synth's ColorChooserUI.
  24. *
  25. * @version 1.11, 12/19/03
  26. * @author Tom Santos
  27. * @author Steve Wilson
  28. */
  29. class SynthColorChooserUI extends BasicColorChooserUI implements
  30. PropertyChangeListener, SynthUI {
  31. private SynthStyle style;
  32. public static ComponentUI createUI(JComponent c) {
  33. return new SynthColorChooserUI();
  34. }
  35. protected AbstractColorChooserPanel[] createDefaultChoosers() {
  36. SynthContext context = getContext(chooser, ENABLED);
  37. AbstractColorChooserPanel[] panels = (AbstractColorChooserPanel[])
  38. context.getStyle().get(context, "ColorChooser.panels");
  39. context.dispose();
  40. if (panels == null) {
  41. panels = ColorChooserComponentFactory.getDefaultChooserPanels();
  42. }
  43. return panels;
  44. }
  45. protected void installDefaults() {
  46. updateStyle(chooser);
  47. }
  48. private void updateStyle(JComponent c) {
  49. SynthContext context = getContext(c, ENABLED);
  50. style = SynthLookAndFeel.updateStyle(context, this);
  51. context.dispose();
  52. }
  53. protected void uninstallDefaults() {
  54. SynthContext context = getContext(chooser, ENABLED);
  55. style.uninstallDefaults(context);
  56. context.dispose();
  57. style = null;
  58. super.uninstallDefaults();
  59. }
  60. protected void installListeners() {
  61. super.installListeners();
  62. chooser.addPropertyChangeListener(this);
  63. }
  64. protected void uninstallListeners() {
  65. chooser.removePropertyChangeListener(this);
  66. super.uninstallListeners();
  67. }
  68. public SynthContext getContext(JComponent c) {
  69. return getContext(c, getComponentState(c));
  70. }
  71. private SynthContext getContext(JComponent c, int state) {
  72. return SynthContext.getContext(SynthContext.class, c,
  73. SynthLookAndFeel.getRegion(c), style, state);
  74. }
  75. private Region getRegion(JComponent c) {
  76. return SynthLookAndFeel.getRegion(c);
  77. }
  78. private int getComponentState(JComponent c) {
  79. return SynthLookAndFeel.getComponentState(c);
  80. }
  81. public void update(Graphics g, JComponent c) {
  82. SynthContext context = getContext(c);
  83. SynthLookAndFeel.update(context, g);
  84. context.getPainter().paintColorChooserBackground(context, g, 0, 0,
  85. c.getWidth(), c.getHeight());
  86. paint(context, g);
  87. context.dispose();
  88. }
  89. public void paint(Graphics g, JComponent c) {
  90. SynthContext context = getContext(c);
  91. paint(context, g);
  92. context.dispose();
  93. }
  94. protected void paint(SynthContext context, Graphics g) {
  95. }
  96. public void paintBorder(SynthContext context, Graphics g, int x,
  97. int y, int w, int h) {
  98. context.getPainter().paintColorChooserBorder(context, g, x, y,w,h);
  99. }
  100. public void propertyChange(PropertyChangeEvent e) {
  101. if (SynthLookAndFeel.shouldUpdateStyle(e)) {
  102. updateStyle((JColorChooser)e.getSource());
  103. }
  104. }
  105. }