1. /*
  2. * @(#)MotifInternalFrameUI.java 1.15 01/11/29
  3. *
  4. * Copyright 2002 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.plaf.basic.BasicInternalFrameUI;
  15. import javax.swing.border.*;
  16. import javax.swing.plaf.*;
  17. /**
  18. * A Motif L&F implementation of InternalFrame.
  19. * <p>
  20. * <strong>Warning:</strong>
  21. * Serialized objects of this class will not be compatible with
  22. * future Swing releases. The current serialization support is appropriate
  23. * for short term storage or RMI between applications running the same
  24. * version of Swing. A future release of Swing will provide support for
  25. * long term persistence.
  26. *
  27. * @version 1.15 11/29/01
  28. * @author Tom Ball
  29. */
  30. public class MotifInternalFrameUI extends BasicInternalFrameUI {
  31. Color color;
  32. Color highlight;
  33. Color shadow;
  34. MotifInternalFrameTitlePane titlePane;
  35. protected KeyStroke closeMenuKey;
  36. /////////////////////////////////////////////////////////////////////////////
  37. // ComponentUI Interface Implementation methods
  38. /////////////////////////////////////////////////////////////////////////////
  39. public static ComponentUI createUI(JComponent w) {
  40. return new MotifInternalFrameUI((JInternalFrame)w);
  41. }
  42. public MotifInternalFrameUI(JInternalFrame w) {
  43. super(w);
  44. }
  45. public void installUI(JComponent c) {
  46. super.installUI(c);
  47. setColors((JInternalFrame)c);
  48. }
  49. protected void installDefaults() {
  50. Border frameBorder = frame.getBorder();
  51. if (frameBorder == null || frameBorder instanceof UIResource) {
  52. frame.setBorder(new MotifBorders.InternalFrameBorder(frame));
  53. }
  54. }
  55. protected void installKeyboardActions(){
  56. super.installKeyboardActions();
  57. // we use JPopup in our TitlePane so need escape support
  58. closeMenuKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
  59. }
  60. protected void uninstallDefaults() {
  61. LookAndFeel.uninstallBorder(frame);
  62. }
  63. private JInternalFrame getFrame(){
  64. return frame;
  65. }
  66. public JComponent createNorthPane(JInternalFrame w) {
  67. titlePane = new MotifInternalFrameTitlePane(w);
  68. return titlePane;
  69. }
  70. public Dimension getMaximumSize(JComponent x) {
  71. return Toolkit.getDefaultToolkit().getScreenSize();
  72. }
  73. protected void uninstallKeyboardActions(){
  74. super.uninstallKeyboardActions();
  75. if (isKeyBindingRegistered()){
  76. frame.unregisterKeyboardAction(closeMenuKey);
  77. frame.getDesktopIcon().unregisterKeyboardAction(closeMenuKey);
  78. }
  79. }
  80. protected void setupMenuOpenKey(){
  81. frame.registerKeyboardAction(new ActionListener(){
  82. public void actionPerformed(ActionEvent e){
  83. titlePane.showSystemMenu();
  84. }
  85. public boolean isEnabled(){
  86. return isKeyBindingActive();
  87. }
  88. },
  89. openMenuKey,
  90. JComponent.WHEN_IN_FOCUSED_WINDOW);
  91. frame.getDesktopIcon().registerKeyboardAction(new ActionListener(){
  92. public void actionPerformed(ActionEvent e){
  93. JInternalFrame.JDesktopIcon icon = getFrame().getDesktopIcon();
  94. MotifDesktopIconUI micon = (MotifDesktopIconUI)icon.getUI();
  95. micon.showSystemMenu();
  96. }
  97. public boolean isEnabled(){
  98. return isKeyBindingActive();
  99. }
  100. },
  101. openMenuKey,
  102. JComponent.WHEN_IN_FOCUSED_WINDOW);
  103. }
  104. protected void setupMenuCloseKey(){
  105. frame.registerKeyboardAction(new ActionListener(){
  106. public void actionPerformed(ActionEvent e){
  107. titlePane.hideSystemMenu();
  108. }
  109. public boolean isEnabled(){
  110. return isKeyBindingActive();
  111. }
  112. },
  113. closeMenuKey,
  114. JComponent.WHEN_IN_FOCUSED_WINDOW);
  115. frame.getDesktopIcon().registerKeyboardAction(new ActionListener(){
  116. public void actionPerformed(ActionEvent e){
  117. JInternalFrame.JDesktopIcon icon = getFrame().getDesktopIcon();
  118. MotifDesktopIconUI micon = (MotifDesktopIconUI)icon.getUI();
  119. micon.hideSystemMenu();
  120. }
  121. public boolean isEnabled(){
  122. return isKeyBindingActive();
  123. }
  124. },
  125. closeMenuKey,
  126. JComponent.WHEN_IN_FOCUSED_WINDOW);
  127. }
  128. /** This method is called when the frame becomes selected.
  129. */
  130. protected void activateFrame(JInternalFrame f) {
  131. super.activateFrame(f);
  132. setColors(f);
  133. }
  134. /** This method is called when the frame is no longer selected.
  135. */
  136. protected void deactivateFrame(JInternalFrame f) {
  137. setColors(f);
  138. super.deactivateFrame(f);
  139. }
  140. void setColors(JInternalFrame frame) {
  141. if (frame.isSelected()) {
  142. color = UIManager.getColor("activeCaptionBorder");
  143. } else {
  144. color = UIManager.getColor("inactiveCaptionBorder");
  145. }
  146. highlight = color.brighter();
  147. shadow = color.darker().darker();
  148. titlePane.setColors(color, highlight, shadow);
  149. }
  150. }