1. /*
  2. * @(#)SynthPanelUI.java 1.12 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 java.awt.*;
  9. import javax.swing.*;
  10. import javax.swing.border.*;
  11. import javax.swing.plaf.*;
  12. import javax.swing.plaf.basic.BasicPanelUI;
  13. import java.awt.*;
  14. import java.awt.event.*;
  15. import java.beans.*;
  16. import sun.swing.plaf.synth.SynthUI;
  17. /**
  18. * Synth's PanelUI.
  19. *
  20. * @version 1.12, 12/19/03
  21. * @author Steve Wilson
  22. */
  23. class SynthPanelUI extends BasicPanelUI implements PropertyChangeListener,
  24. SynthUI {
  25. private SynthStyle style;
  26. public static ComponentUI createUI(JComponent c) {
  27. return new SynthPanelUI();
  28. }
  29. public void installUI(JComponent c) {
  30. JPanel p = (JPanel)c;
  31. super.installUI(c);
  32. installListeners(p);
  33. }
  34. public void uninstallUI(JComponent c) {
  35. JPanel p = (JPanel)c;
  36. uninstallListeners(p);
  37. super.uninstallUI(c);
  38. }
  39. protected void installListeners(JPanel p) {
  40. p.addPropertyChangeListener(this);
  41. }
  42. protected void uninstallListeners(JPanel p) {
  43. p.removePropertyChangeListener(this);
  44. }
  45. protected void installDefaults(JPanel p) {
  46. updateStyle(p);
  47. }
  48. protected void uninstallDefaults(JPanel p) {
  49. SynthContext context = getContext(p, ENABLED);
  50. style.uninstallDefaults(context);
  51. context.dispose();
  52. style = null;
  53. }
  54. private void updateStyle(JPanel c) {
  55. SynthContext context = getContext(c, ENABLED);
  56. style = SynthLookAndFeel.updateStyle(context, this);
  57. context.dispose();
  58. }
  59. public SynthContext getContext(JComponent c) {
  60. return getContext(c, getComponentState(c));
  61. }
  62. private SynthContext getContext(JComponent c, int state) {
  63. return SynthContext.getContext(SynthContext.class, c,
  64. SynthLookAndFeel.getRegion(c), style, state);
  65. }
  66. private Region getRegion(JComponent c) {
  67. return SynthLookAndFeel.getRegion(c);
  68. }
  69. private int getComponentState(JComponent c) {
  70. return SynthLookAndFeel.getComponentState(c);
  71. }
  72. public void update(Graphics g, JComponent c) {
  73. SynthContext context = getContext(c);
  74. SynthLookAndFeel.update(context, g);
  75. context.getPainter().paintPanelBackground(context,
  76. g, 0, 0, c.getWidth(), c.getHeight());
  77. paint(context, g);
  78. context.dispose();
  79. }
  80. public void paint(Graphics g, JComponent c) {
  81. SynthContext context = getContext(c);
  82. paint(context, g);
  83. context.dispose();
  84. }
  85. protected void paint(SynthContext context, Graphics g) {
  86. // do actual painting
  87. }
  88. public void paintBorder(SynthContext context, Graphics g, int x,
  89. int y, int w, int h) {
  90. context.getPainter().paintPanelBorder(context, g, x, y, w, h);
  91. }
  92. public void propertyChange(PropertyChangeEvent pce) {
  93. if (SynthLookAndFeel.shouldUpdateStyle(pce)) {
  94. updateStyle((JPanel)pce.getSource());
  95. }
  96. }
  97. }