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