1. /*
  2. * @(#)SynthRootPaneUI.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 java.awt.event.ActionEvent;
  10. import java.beans.PropertyChangeEvent;
  11. import java.beans.PropertyChangeListener;
  12. import javax.swing.*;
  13. import javax.swing.plaf.*;
  14. import javax.swing.plaf.basic.BasicRootPaneUI;
  15. import sun.swing.plaf.synth.SynthUI;
  16. /**
  17. * Synth's RootPaneUI.
  18. *
  19. * @version 1.12, 12/19/03
  20. * @author Scott Violet
  21. */
  22. class SynthRootPaneUI extends BasicRootPaneUI implements SynthUI {
  23. private SynthStyle style;
  24. public static ComponentUI createUI(JComponent c) {
  25. return new SynthRootPaneUI();
  26. }
  27. protected void installDefaults(JRootPane c){
  28. updateStyle(c);
  29. }
  30. protected void uninstallDefaults(JRootPane root) {
  31. SynthContext context = getContext(root, ENABLED);
  32. style.uninstallDefaults(context);
  33. context.dispose();
  34. style = null;
  35. }
  36. public SynthContext getContext(JComponent c) {
  37. return getContext(c, getComponentState(c));
  38. }
  39. private SynthContext getContext(JComponent c, int state) {
  40. return SynthContext.getContext(SynthContext.class, c,
  41. SynthLookAndFeel.getRegion(c), style, state);
  42. }
  43. private Region getRegion(JComponent c) {
  44. return SynthLookAndFeel.getRegion(c);
  45. }
  46. private int getComponentState(JComponent c) {
  47. return SynthLookAndFeel.getComponentState(c);
  48. }
  49. private void updateStyle(JComponent c) {
  50. SynthContext context = getContext(c, ENABLED);
  51. SynthStyle oldStyle = style;
  52. style = SynthLookAndFeel.updateStyle(context, this);
  53. if (style != oldStyle) {
  54. if (oldStyle != null) {
  55. uninstallKeyboardActions((JRootPane)c);
  56. installKeyboardActions((JRootPane)c);
  57. }
  58. }
  59. context.dispose();
  60. }
  61. public void update(Graphics g, JComponent c) {
  62. SynthContext context = getContext(c);
  63. SynthLookAndFeel.update(context, g);
  64. context.getPainter().paintRootPaneBackground(context,
  65. g, 0, 0, c.getWidth(), c.getHeight());
  66. paint(context, g);
  67. context.dispose();
  68. }
  69. public void paint(Graphics g, JComponent c) {
  70. SynthContext context = getContext(c);
  71. paint(context, g);
  72. context.dispose();
  73. }
  74. protected void paint(SynthContext context, Graphics g) {
  75. }
  76. public void paintBorder(SynthContext context, Graphics g, int x,
  77. int y, int w, int h) {
  78. context.getPainter().paintRootPaneBorder(context, g, x, y, w, h);
  79. }
  80. /**
  81. * Invoked when a property changes on the root pane. If the event
  82. * indicates the <code>defaultButton</code> has changed, this will
  83. * reinstall the keyboard actions.
  84. */
  85. public void propertyChange(PropertyChangeEvent e) {
  86. if (SynthLookAndFeel.shouldUpdateStyle(e)) {
  87. updateStyle((JRootPane)e.getSource());
  88. }
  89. super.propertyChange(e);
  90. }
  91. }