1. /*
  2. * @(#)MetalInternalFrameUI.java 1.17 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 javax.swing.plaf.metal;
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import javax.swing.*;
  11. import javax.swing.border.*;
  12. import javax.swing.plaf.basic.*;
  13. import java.util.EventListener;
  14. import java.beans.PropertyChangeListener;
  15. import java.beans.PropertyChangeEvent;
  16. import java.beans.PropertyVetoException;
  17. import javax.swing.plaf.*;
  18. /**
  19. * Metal implementation of JInternalFrame.
  20. * <p>
  21. *
  22. * @version 1.17 11/29/01
  23. * @author Steve Wilson
  24. */
  25. public class MetalInternalFrameUI extends BasicInternalFrameUI {
  26. private MetalInternalFrameTitlePane titlePane;
  27. private PropertyChangeListener paletteListener;
  28. private PropertyChangeListener contentPaneListener;
  29. private static final Border handyEmptyBorder = new EmptyBorder(0,0,0,0);
  30. protected static String IS_PALETTE = "JInternalFrame.isPalette";
  31. public MetalInternalFrameUI(JInternalFrame b) {
  32. super(b);
  33. }
  34. public static ComponentUI createUI(JComponent c) {
  35. return new MetalInternalFrameUI( (JInternalFrame) c);
  36. }
  37. public void installUI(JComponent c) {
  38. frame = (JInternalFrame)c;
  39. paletteListener = new PaletteListener();
  40. contentPaneListener = new ContentPaneListener();
  41. c.addPropertyChangeListener(paletteListener);
  42. c.addPropertyChangeListener(contentPaneListener);
  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. c.removePropertyChangeListener(paletteListener);
  54. c.removePropertyChangeListener(contentPaneListener);
  55. Container cont = ((JInternalFrame)(c)).getContentPane();
  56. if (cont instanceof JComponent) {
  57. JComponent content = (JComponent)cont;
  58. if ( content.getBorder() == handyEmptyBorder) {
  59. content.setBorder(null);
  60. }
  61. }
  62. super.uninstallUI(c);
  63. }
  64. protected void installKeyboardActions(){
  65. }
  66. protected void uninstallKeyboardActions(){
  67. }
  68. private void stripContentBorder(Object c) {
  69. if ( c instanceof JComponent ) {
  70. JComponent contentComp = (JComponent)c;
  71. Border contentBorder = contentComp.getBorder();
  72. if (contentBorder == null || contentBorder instanceof UIResource) {
  73. contentComp.setBorder( handyEmptyBorder );
  74. }
  75. }
  76. }
  77. protected JComponent createNorthPane(JInternalFrame w) {
  78. titlePane = new MetalInternalFrameTitlePane(w);
  79. return titlePane;
  80. }
  81. protected void replacePane(JComponent currentPane, JComponent newPane) {
  82. super.replacePane(currentPane, newPane);
  83. //fix for 4146355
  84. if(currentPane != null) {
  85. if (currentPane instanceof MetalInternalFrameTitlePane) {
  86. frame.removePropertyChangeListener((PropertyChangeListener)currentPane);
  87. }
  88. }
  89. }
  90. public void setPalette(boolean isPalette) {
  91. if (isPalette) {
  92. LookAndFeel.installBorder(frame, "InternalFrame.paletteBorder");
  93. } else {
  94. LookAndFeel.installBorder(frame, "InternalFrame.border");
  95. }
  96. titlePane.setPalette(isPalette);
  97. }
  98. class PaletteListener implements PropertyChangeListener {
  99. public void propertyChange(PropertyChangeEvent e) {
  100. String name = e.getPropertyName();
  101. if ( name.equals( IS_PALETTE ) ) {
  102. if ( e.getNewValue() != null ) {
  103. setPalette( ((Boolean)e.getNewValue()).booleanValue() );
  104. }
  105. else {
  106. setPalette( false );
  107. }
  108. }
  109. }
  110. } // end class PaletteListener
  111. class ContentPaneListener implements PropertyChangeListener {
  112. public void propertyChange(PropertyChangeEvent e) {
  113. String name = e.getPropertyName();
  114. if ( name.equals( JInternalFrame.CONTENT_PANE_PROPERTY ) ) {
  115. stripContentBorder(e.getNewValue());
  116. }
  117. }
  118. } // end class ContentPaneListener
  119. }