1. /*
  2. * @(#)MotifInternalFrameUI.java 1.26 04/05/18
  3. *
  4. * Copyright 2004 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.26 05/18/04
  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. @Deprecated
  43. protected KeyStroke closeMenuKey;
  44. /////////////////////////////////////////////////////////////////////////////
  45. // ComponentUI Interface Implementation methods
  46. /////////////////////////////////////////////////////////////////////////////
  47. public static ComponentUI createUI(JComponent w) {
  48. return new MotifInternalFrameUI((JInternalFrame)w);
  49. }
  50. public MotifInternalFrameUI(JInternalFrame w) {
  51. super(w);
  52. }
  53. public void installUI(JComponent c) {
  54. super.installUI(c);
  55. setColors((JInternalFrame)c);
  56. }
  57. protected void installDefaults() {
  58. Border frameBorder = frame.getBorder();
  59. frame.setLayout(internalFrameLayout = createLayoutManager());
  60. if (frameBorder == null || frameBorder instanceof UIResource) {
  61. frame.setBorder(new MotifBorders.InternalFrameBorder(frame));
  62. }
  63. }
  64. protected void installKeyboardActions(){
  65. super.installKeyboardActions();
  66. // We replace the
  67. // we use JPopup in our TitlePane so need escape support
  68. closeMenuKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
  69. }
  70. protected void uninstallDefaults() {
  71. LookAndFeel.uninstallBorder(frame);
  72. frame.setLayout(null);
  73. internalFrameLayout = null;
  74. }
  75. private JInternalFrame getFrame(){
  76. return frame;
  77. }
  78. public JComponent createNorthPane(JInternalFrame w) {
  79. titlePane = new MotifInternalFrameTitlePane(w);
  80. return titlePane;
  81. }
  82. public Dimension getMaximumSize(JComponent x) {
  83. return Toolkit.getDefaultToolkit().getScreenSize();
  84. }
  85. protected void uninstallKeyboardActions(){
  86. super.uninstallKeyboardActions();
  87. if (isKeyBindingRegistered()){
  88. JInternalFrame.JDesktopIcon di = frame.getDesktopIcon();
  89. SwingUtilities.replaceUIActionMap(di, null);
  90. SwingUtilities.replaceUIInputMap(di, JComponent.WHEN_IN_FOCUSED_WINDOW,
  91. null);
  92. }
  93. }
  94. protected void setupMenuOpenKey(){
  95. super.setupMenuOpenKey();
  96. ActionMap map = SwingUtilities.getUIActionMap(frame);
  97. if (map != null) {
  98. // BasicInternalFrameUI creates an action with the same name, we override
  99. // it as MotifInternalFrameTitlePane has a titlePane ivar that shadows the
  100. // titlePane ivar in BasicInternalFrameUI, making supers action throw
  101. // an NPE for us.
  102. map.put("showSystemMenu", new AbstractAction(){
  103. public void actionPerformed(ActionEvent e){
  104. titlePane.showSystemMenu();
  105. }
  106. public boolean isEnabled(){
  107. return isKeyBindingActive();
  108. }
  109. });
  110. }
  111. }
  112. protected void setupMenuCloseKey(){
  113. ActionMap map = SwingUtilities.getUIActionMap(frame);
  114. if (map != null) {
  115. map.put("hideSystemMenu", new AbstractAction(){
  116. public void actionPerformed(ActionEvent e){
  117. titlePane.hideSystemMenu();
  118. }
  119. public boolean isEnabled(){
  120. return isKeyBindingActive();
  121. }
  122. });
  123. }
  124. // Set up the bindings for the DesktopIcon, it is odd that
  125. // we install them, and not the desktop icon.
  126. JInternalFrame.JDesktopIcon di = frame.getDesktopIcon();
  127. InputMap diInputMap = SwingUtilities.getUIInputMap
  128. (di, JComponent.WHEN_IN_FOCUSED_WINDOW);
  129. if (diInputMap == null) {
  130. Object[] bindings = (Object[])UIManager.get
  131. ("DesktopIcon.windowBindings");
  132. if (bindings != null) {
  133. diInputMap = LookAndFeel.makeComponentInputMap(di, bindings);
  134. SwingUtilities.replaceUIInputMap(di, JComponent.
  135. WHEN_IN_FOCUSED_WINDOW,
  136. diInputMap);
  137. }
  138. }
  139. ActionMap diActionMap = SwingUtilities.getUIActionMap(di);
  140. if (diActionMap == null) {
  141. diActionMap = new ActionMapUIResource();
  142. diActionMap.put("hideSystemMenu", new AbstractAction(){
  143. public void actionPerformed(ActionEvent e){
  144. JInternalFrame.JDesktopIcon icon = getFrame().
  145. getDesktopIcon();
  146. MotifDesktopIconUI micon = (MotifDesktopIconUI)icon.
  147. getUI();
  148. micon.hideSystemMenu();
  149. }
  150. public boolean isEnabled(){
  151. return isKeyBindingActive();
  152. }
  153. });
  154. SwingUtilities.replaceUIActionMap(di, diActionMap);
  155. }
  156. }
  157. /** This method is called when the frame becomes selected.
  158. */
  159. protected void activateFrame(JInternalFrame f) {
  160. super.activateFrame(f);
  161. setColors(f);
  162. }
  163. /** This method is called when the frame is no longer selected.
  164. */
  165. protected void deactivateFrame(JInternalFrame f) {
  166. setColors(f);
  167. super.deactivateFrame(f);
  168. }
  169. void setColors(JInternalFrame frame) {
  170. if (frame.isSelected()) {
  171. color = UIManager.getColor("InternalFrame.activeTitleBackground");
  172. } else {
  173. color = UIManager.getColor("InternalFrame.inactiveTitleBackground");
  174. }
  175. highlight = color.brighter();
  176. shadow = color.darker().darker();
  177. titlePane.setColors(color, highlight, shadow);
  178. }
  179. }