1. /*
  2. * @(#)SynthInternalFrameUI.java 1.20 04/04/16
  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.*;
  10. import java.awt.peer.LightweightPeer;
  11. import javax.swing.*;
  12. import javax.swing.plaf.*;
  13. import javax.swing.plaf.basic.BasicInternalFrameUI;
  14. import javax.swing.event.*;
  15. import java.beans.*;
  16. import java.io.Serializable;
  17. import sun.swing.plaf.synth.SynthUI;
  18. /**
  19. * Synth's InternalFrameUI.
  20. *
  21. * @version 1.20 04/16/04
  22. * @author David Kloba
  23. * @author Joshua Outwater
  24. * @author Rich Schiavi
  25. */
  26. class SynthInternalFrameUI extends BasicInternalFrameUI implements SynthUI,
  27. PropertyChangeListener {
  28. private SynthStyle style;
  29. private static DesktopManager sharedDesktopManager;
  30. private boolean componentListenerAdded = false;
  31. private Rectangle parentBounds;
  32. public static ComponentUI createUI(JComponent b) {
  33. return new SynthInternalFrameUI((JInternalFrame)b);
  34. }
  35. public SynthInternalFrameUI(JInternalFrame b) {
  36. super(b);
  37. }
  38. public void installDefaults() {
  39. frame.setLayout(internalFrameLayout = createLayoutManager());
  40. updateStyle(frame);
  41. }
  42. protected void installListeners() {
  43. super.installListeners();
  44. frame.addPropertyChangeListener(this);
  45. }
  46. protected void uninstallComponents() {
  47. if (frame.getComponentPopupMenu() instanceof UIResource) {
  48. frame.setComponentPopupMenu(null);
  49. }
  50. super.uninstallComponents();
  51. }
  52. protected void uninstallListeners() {
  53. frame.removePropertyChangeListener(this);
  54. super.uninstallListeners();
  55. }
  56. private void updateStyle(JComponent c) {
  57. SynthContext context = getContext(c, ENABLED);
  58. SynthStyle oldStyle = style;
  59. style = SynthLookAndFeel.updateStyle(context, this);
  60. if (style != oldStyle) {
  61. Icon frameIcon = frame.getFrameIcon();
  62. if (frameIcon == null || frameIcon instanceof UIResource) {
  63. frame.setFrameIcon(context.getStyle().getIcon(
  64. context, "InternalFrame.icon"));
  65. }
  66. if (oldStyle != null) {
  67. uninstallKeyboardActions();
  68. installKeyboardActions();
  69. }
  70. }
  71. context.dispose();
  72. }
  73. protected void uninstallDefaults() {
  74. SynthContext context = getContext(frame, ENABLED);
  75. style.uninstallDefaults(context);
  76. context.dispose();
  77. style = null;
  78. if(frame.getLayout() == internalFrameLayout) {
  79. frame.setLayout(null);
  80. }
  81. }
  82. public SynthContext getContext(JComponent c) {
  83. return getContext(c, getComponentState(c));
  84. }
  85. private SynthContext getContext(JComponent c, int state) {
  86. return SynthContext.getContext(SynthContext.class, c,
  87. SynthLookAndFeel.getRegion(c), style, state);
  88. }
  89. private Region getRegion(JComponent c) {
  90. return SynthLookAndFeel.getRegion(c);
  91. }
  92. public int getComponentState(JComponent c) {
  93. return SynthLookAndFeel.getComponentState(c);
  94. }
  95. protected JComponent createNorthPane(JInternalFrame w) {
  96. titlePane = new SynthInternalFrameTitlePane(w);
  97. titlePane.setName("InternalFrame.northPane");
  98. return titlePane;
  99. }
  100. protected ComponentListener createComponentListener() {
  101. if (UIManager.getBoolean("InternalFrame.useTaskBar")) {
  102. return new ComponentHandler() {
  103. public void componentResized(ComponentEvent e) {
  104. if (frame != null && frame.isMaximum()) {
  105. JDesktopPane desktop = (JDesktopPane)e.getSource();
  106. for (Component comp : desktop.getComponents()) {
  107. if (comp instanceof SynthDesktopPaneUI.TaskBar) {
  108. frame.setBounds(0, 0,
  109. desktop.getWidth(),
  110. desktop.getHeight() - comp.getHeight());
  111. frame.revalidate();
  112. break;
  113. }
  114. }
  115. }
  116. // Update the new parent bounds for next resize, but don't
  117. // let the super method touch this frame
  118. JInternalFrame f = frame;
  119. frame = null;
  120. super.componentResized(e);
  121. frame = f;
  122. }
  123. };
  124. } else {
  125. return super.createComponentListener();
  126. }
  127. }
  128. public void update(Graphics g, JComponent c) {
  129. SynthContext context = getContext(c);
  130. SynthLookAndFeel.update(context, g);
  131. context.getPainter().paintInternalFrameBackground(context,
  132. g, 0, 0, c.getWidth(), c.getHeight());
  133. paint(context, g);
  134. context.dispose();
  135. }
  136. public void paint(Graphics g, JComponent c) {
  137. SynthContext context = getContext(c);
  138. paint(context, g);
  139. context.dispose();
  140. }
  141. protected void paint(SynthContext context, Graphics g) {
  142. }
  143. public void paintBorder(SynthContext context, Graphics g, int x,
  144. int y, int w, int h) {
  145. context.getPainter().paintInternalFrameBorder(context,
  146. g, x, y, w, h);
  147. }
  148. public void propertyChange(PropertyChangeEvent evt) {
  149. if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
  150. updateStyle((JInternalFrame)evt.getSource());
  151. }
  152. }
  153. }