1. /*
  2. * @(#)MotifInternalFrameUI.java 1.22 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.java.swing.plaf.motif;
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import javax.swing.*;
  11. import javax.swing.event.*;
  12. import java.util.EventListener;
  13. import javax.swing.plaf.basic.*;
  14. import javax.swing.border.*;
  15. import javax.swing.plaf.*;
  16. /**
  17. * A Motif L&F implementation of InternalFrame.
  18. * <p>
  19. * <strong>Warning:</strong>
  20. * Serialized objects of this class will not be compatible with
  21. * future Swing releases. The current serialization support is appropriate
  22. * for short term storage or RMI between applications running the same
  23. * version of Swing. A future release of Swing will provide support for
  24. * long term persistence.
  25. *
  26. * @version 1.22 01/23/03
  27. * @author Tom Ball
  28. */
  29. public class MotifInternalFrameUI extends BasicInternalFrameUI {
  30. Color color;
  31. Color highlight;
  32. Color shadow;
  33. MotifInternalFrameTitlePane titlePane;
  34. /**
  35. * As of Java 2 platform v1.3 this previously undocumented field is no
  36. * longer used.
  37. * Key bindings are now defined by the LookAndFeel, please refer to
  38. * the key bindings specification for further details.
  39. *
  40. * @deprecated As of Java 2 platform v1.3.
  41. */
  42. protected KeyStroke closeMenuKey;
  43. /////////////////////////////////////////////////////////////////////////////
  44. // ComponentUI Interface Implementation methods
  45. /////////////////////////////////////////////////////////////////////////////
  46. public static ComponentUI createUI(JComponent w) {
  47. return new MotifInternalFrameUI((JInternalFrame)w);
  48. }
  49. public MotifInternalFrameUI(JInternalFrame w) {
  50. super(w);
  51. }
  52. public void installUI(JComponent c) {
  53. super.installUI(c);
  54. setColors((JInternalFrame)c);
  55. }
  56. protected void installDefaults() {
  57. Border frameBorder = frame.getBorder();
  58. frame.setLayout(internalFrameLayout = createLayoutManager());
  59. if (frameBorder == null || frameBorder instanceof UIResource) {
  60. frame.setBorder(new MotifBorders.InternalFrameBorder(frame));
  61. }
  62. }
  63. protected void installKeyboardActions(){
  64. super.installKeyboardActions();
  65. // We replace the
  66. // we use JPopup in our TitlePane so need escape support
  67. closeMenuKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
  68. }
  69. protected void uninstallDefaults() {
  70. LookAndFeel.uninstallBorder(frame);
  71. frame.setLayout(null);
  72. internalFrameLayout = null;
  73. }
  74. private JInternalFrame getFrame(){
  75. return frame;
  76. }
  77. public JComponent createNorthPane(JInternalFrame w) {
  78. titlePane = new MotifInternalFrameTitlePane(w);
  79. return titlePane;
  80. }
  81. public Dimension getMaximumSize(JComponent x) {
  82. return Toolkit.getDefaultToolkit().getScreenSize();
  83. }
  84. protected void uninstallKeyboardActions(){
  85. super.uninstallKeyboardActions();
  86. if (isKeyBindingRegistered()){
  87. JInternalFrame.JDesktopIcon di = frame.getDesktopIcon();
  88. SwingUtilities.replaceUIActionMap(di, null);
  89. SwingUtilities.replaceUIInputMap(di, JComponent.WHEN_IN_FOCUSED_WINDOW,
  90. null);
  91. }
  92. }
  93. protected void setupMenuOpenKey(){
  94. super.setupMenuOpenKey();
  95. ActionMap map = SwingUtilities.getUIActionMap(frame);
  96. if (map != null) {
  97. // BasicInternalFrameUI creates an action with the same name, we override
  98. // it as MotifInternalFrameTitlePane has a titlePane ivar that shadows the
  99. // titlePane ivar in BasicInternalFrameUI, making supers action throw
  100. // an NPE for us.
  101. map.put("showSystemMenu", new AbstractAction(){
  102. public void actionPerformed(ActionEvent e){
  103. titlePane.showSystemMenu();
  104. }
  105. public boolean isEnabled(){
  106. return isKeyBindingActive();
  107. }
  108. });
  109. }
  110. }
  111. protected void setupMenuCloseKey(){
  112. ActionMap map = SwingUtilities.getUIActionMap(frame);
  113. if (map != null) {
  114. map.put("hideSystemMenu", new AbstractAction(){
  115. public void actionPerformed(ActionEvent e){
  116. titlePane.hideSystemMenu();
  117. }
  118. public boolean isEnabled(){
  119. return isKeyBindingActive();
  120. }
  121. });
  122. }
  123. // Set up the bindings for the DesktopIcon, it is odd that
  124. // we install them, and not the desktop icon.
  125. JInternalFrame.JDesktopIcon di = frame.getDesktopIcon();
  126. InputMap diInputMap = SwingUtilities.getUIInputMap
  127. (di, JComponent.WHEN_IN_FOCUSED_WINDOW);
  128. if (diInputMap == null) {
  129. Object[] bindings = (Object[])UIManager.get
  130. ("DesktopIcon.windowBindings");
  131. if (bindings != null) {
  132. diInputMap = LookAndFeel.makeComponentInputMap(di, bindings);
  133. SwingUtilities.replaceUIInputMap(di, JComponent.
  134. WHEN_IN_FOCUSED_WINDOW,
  135. diInputMap);
  136. }
  137. }
  138. ActionMap diActionMap = SwingUtilities.getUIActionMap(di);
  139. if (diActionMap == null) {
  140. diActionMap = new ActionMapUIResource();
  141. diActionMap.put("hideSystemMenu", new AbstractAction(){
  142. public void actionPerformed(ActionEvent e){
  143. JInternalFrame.JDesktopIcon icon = getFrame().
  144. getDesktopIcon();
  145. MotifDesktopIconUI micon = (MotifDesktopIconUI)icon.
  146. getUI();
  147. micon.hideSystemMenu();
  148. }
  149. public boolean isEnabled(){
  150. return isKeyBindingActive();
  151. }
  152. });
  153. SwingUtilities.replaceUIActionMap(di, diActionMap);
  154. }
  155. }
  156. /** This method is called when the frame becomes selected.
  157. */
  158. protected void activateFrame(JInternalFrame f) {
  159. super.activateFrame(f);
  160. setColors(f);
  161. }
  162. /** This method is called when the frame is no longer selected.
  163. */
  164. protected void deactivateFrame(JInternalFrame f) {
  165. setColors(f);
  166. super.deactivateFrame(f);
  167. }
  168. void setColors(JInternalFrame frame) {
  169. if (frame.isSelected()) {
  170. color = UIManager.getColor("InternalFrame.activeTitleBackground");
  171. } else {
  172. color = UIManager.getColor("InternalFrame.inactiveTitleBackground");
  173. }
  174. highlight = color.brighter();
  175. shadow = color.darker().darker();
  176. titlePane.setColors(color, highlight, shadow);
  177. }
  178. }