1. /*
  2. * @(#)MetalInternalFrameUI.java 1.30 03/12/19
  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.metal;
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import javax.swing.*;
  11. import javax.swing.event.*;
  12. import javax.swing.border.*;
  13. import javax.swing.plaf.basic.*;
  14. import java.util.EventListener;
  15. import java.beans.PropertyChangeListener;
  16. import java.beans.PropertyChangeEvent;
  17. import java.beans.PropertyVetoException;
  18. import javax.swing.plaf.*;
  19. /**
  20. * Metal implementation of JInternalFrame.
  21. * <p>
  22. *
  23. * @version 1.30 12/19/03
  24. * @author Steve Wilson
  25. */
  26. public class MetalInternalFrameUI extends BasicInternalFrameUI {
  27. private MetalInternalFrameTitlePane titlePane;
  28. private static final PropertyChangeListener metalPropertyChangeListener =
  29. new MetalPropertyChangeHandler();
  30. private static final Border handyEmptyBorder = new EmptyBorder(0,0,0,0);
  31. protected static String IS_PALETTE = "JInternalFrame.isPalette";
  32. private static String FRAME_TYPE = "JInternalFrame.frameType";
  33. private static String NORMAL_FRAME = "normal";
  34. private static String PALETTE_FRAME = "palette";
  35. private static String OPTION_DIALOG = "optionDialog";
  36. public MetalInternalFrameUI(JInternalFrame b) {
  37. super(b);
  38. }
  39. public static ComponentUI createUI(JComponent c) {
  40. return new MetalInternalFrameUI( (JInternalFrame) c);
  41. }
  42. public void installUI(JComponent c) {
  43. super.installUI(c);
  44. Object paletteProp = c.getClientProperty( IS_PALETTE );
  45. if ( paletteProp != null ) {
  46. setPalette( ((Boolean)paletteProp).booleanValue() );
  47. }
  48. Container content = frame.getContentPane();
  49. stripContentBorder(content);
  50. //c.setOpaque(false);
  51. }
  52. public void uninstallUI(JComponent c) {
  53. frame = (JInternalFrame)c;
  54. Container cont = ((JInternalFrame)(c)).getContentPane();
  55. if (cont instanceof JComponent) {
  56. JComponent content = (JComponent)cont;
  57. if ( content.getBorder() == handyEmptyBorder) {
  58. content.setBorder(null);
  59. }
  60. }
  61. super.uninstallUI(c);
  62. }
  63. protected void installListeners() {
  64. super.installListeners();
  65. frame.addPropertyChangeListener(metalPropertyChangeListener);
  66. }
  67. protected void uninstallListeners() {
  68. frame.removePropertyChangeListener(metalPropertyChangeListener);
  69. super.uninstallListeners();
  70. }
  71. protected void installKeyboardActions(){
  72. super.installKeyboardActions();
  73. ActionMap map = SwingUtilities.getUIActionMap(frame);
  74. if (map != null) {
  75. // BasicInternalFrameUI creates an action with the same name, we override
  76. // it as Metal frames do not have system menus.
  77. map.remove("showSystemMenu");
  78. }
  79. }
  80. protected void uninstallKeyboardActions(){
  81. super.uninstallKeyboardActions();
  82. }
  83. protected void uninstallComponents() {
  84. titlePane = null;
  85. super.uninstallComponents();
  86. }
  87. private void stripContentBorder(Object c) {
  88. if ( c instanceof JComponent ) {
  89. JComponent contentComp = (JComponent)c;
  90. Border contentBorder = contentComp.getBorder();
  91. if (contentBorder == null || contentBorder instanceof UIResource) {
  92. contentComp.setBorder( handyEmptyBorder );
  93. }
  94. }
  95. }
  96. protected JComponent createNorthPane(JInternalFrame w) {
  97. titlePane = new MetalInternalFrameTitlePane(w);
  98. return titlePane;
  99. }
  100. private void setFrameType( String frameType )
  101. {
  102. if ( frameType.equals( OPTION_DIALOG ) )
  103. {
  104. LookAndFeel.installBorder(frame, "InternalFrame.optionDialogBorder");
  105. titlePane.setPalette( false );
  106. }
  107. else if ( frameType.equals( PALETTE_FRAME ) )
  108. {
  109. LookAndFeel.installBorder(frame, "InternalFrame.paletteBorder");
  110. titlePane.setPalette( true );
  111. }
  112. else
  113. {
  114. LookAndFeel.installBorder(frame, "InternalFrame.border");
  115. titlePane.setPalette( false );
  116. }
  117. }
  118. // this should be deprecated - jcs
  119. public void setPalette(boolean isPalette) {
  120. if (isPalette) {
  121. LookAndFeel.installBorder(frame, "InternalFrame.paletteBorder");
  122. } else {
  123. LookAndFeel.installBorder(frame, "InternalFrame.border");
  124. }
  125. titlePane.setPalette(isPalette);
  126. }
  127. private static class MetalPropertyChangeHandler implements
  128. PropertyChangeListener
  129. {
  130. public void propertyChange(PropertyChangeEvent e)
  131. {
  132. String name = e.getPropertyName();
  133. JInternalFrame jif = (JInternalFrame)e.getSource();
  134. if (!(jif.getUI() instanceof MetalInternalFrameUI)) {
  135. return;
  136. }
  137. MetalInternalFrameUI ui = (MetalInternalFrameUI)jif.getUI();
  138. if ( name.equals( FRAME_TYPE ) )
  139. {
  140. if ( e.getNewValue() instanceof String )
  141. {
  142. ui.setFrameType( (String) e.getNewValue() );
  143. }
  144. }
  145. else if ( name.equals( IS_PALETTE ) )
  146. {
  147. if ( e.getNewValue() != null )
  148. {
  149. ui.setPalette( ((Boolean)e.getNewValue()).booleanValue() );
  150. }
  151. else
  152. {
  153. ui.setPalette( false );
  154. }
  155. } else if ( name.equals( JInternalFrame.CONTENT_PANE_PROPERTY ) ) {
  156. ui.stripContentBorder(e.getNewValue());
  157. }
  158. }
  159. } // end class MetalPropertyChangeHandler
  160. }