1. /*
  2. * @(#)MotifInternalFrameUI.java 1.18 00/02/02
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package com.sun.java.swing.plaf.motif;
  11. import java.awt.*;
  12. import java.awt.event.*;
  13. import javax.swing.*;
  14. import javax.swing.event.*;
  15. import java.util.EventListener;
  16. import javax.swing.plaf.basic.*;
  17. import javax.swing.border.*;
  18. import javax.swing.plaf.*;
  19. /**
  20. * A Motif L&F implementation of InternalFrame.
  21. * <p>
  22. * <strong>Warning:</strong>
  23. * Serialized objects of this class will not be compatible with
  24. * future Swing releases. The current serialization support is appropriate
  25. * for short term storage or RMI between applications running the same
  26. * version of Swing. A future release of Swing will provide support for
  27. * long term persistence.
  28. *
  29. * @version 1.18 02/02/00
  30. * @author Tom Ball
  31. */
  32. public class MotifInternalFrameUI extends BasicInternalFrameUI {
  33. Color color;
  34. Color highlight;
  35. Color shadow;
  36. MotifInternalFrameTitlePane titlePane;
  37. /**
  38. * As of Java 2 platform v1.3 this previously undocumented field is no
  39. * longer used.
  40. * Key bindings are now defined by the LookAndFeel, please refer to
  41. * the key bindings specification for further details.
  42. *
  43. * @deprecated As of Java 2 platform v1.3.
  44. */
  45. protected KeyStroke closeMenuKey;
  46. /////////////////////////////////////////////////////////////////////////////
  47. // ComponentUI Interface Implementation methods
  48. /////////////////////////////////////////////////////////////////////////////
  49. public static ComponentUI createUI(JComponent w) {
  50. return new MotifInternalFrameUI((JInternalFrame)w);
  51. }
  52. public MotifInternalFrameUI(JInternalFrame w) {
  53. super(w);
  54. }
  55. public void installUI(JComponent c) {
  56. super.installUI(c);
  57. setColors((JInternalFrame)c);
  58. }
  59. protected void installDefaults() {
  60. Border frameBorder = frame.getBorder();
  61. if (frameBorder == null || frameBorder instanceof UIResource) {
  62. frame.setBorder(new MotifBorders.InternalFrameBorder(frame));
  63. }
  64. }
  65. protected void installKeyboardActions(){
  66. super.installKeyboardActions();
  67. // We replace the
  68. // we use JPopup in our TitlePane so need escape support
  69. closeMenuKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
  70. }
  71. protected void uninstallDefaults() {
  72. LookAndFeel.uninstallBorder(frame);
  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("activeCaptionBorder");
  171. } else {
  172. color = UIManager.getColor("inactiveCaptionBorder");
  173. }
  174. highlight = color.brighter();
  175. shadow = color.darker().darker();
  176. titlePane.setColors(color, highlight, shadow);
  177. }
  178. }