This makes InternalFrames adjust their size to their parent's size when in maximized mode.

2006-08-03  Roman Kennke  <[EMAIL PROTECTED]>

        PR 27637
        * javax/swing/plaf/basic/BasicInternalFrameUI.java
        (ComponentHandler.componentResized): Reimplemented to handle
        arbitrary parents.
        (InternalFramePropertyChangeHandler.propertyChange): (Un)install
        component listener on changed ancestor.
        (installListeners): Install componentListener.
        (uninstallListeners): Uninstall componentListener.


/Roman
Index: javax/swing/plaf/basic/BasicInternalFrameUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicInternalFrameUI.java,v
retrieving revision 1.40
diff -u -1 -2 -r1.40 BasicInternalFrameUI.java
--- javax/swing/plaf/basic/BasicInternalFrameUI.java	25 Jul 2006 10:03:34 -0000	1.40
+++ javax/swing/plaf/basic/BasicInternalFrameUI.java	3 Aug 2006 20:24:43 -0000
@@ -450,36 +450,30 @@
     }
 
     /**
      * This method is called when the JDesktopPane is resized.
      * 
      * @param e
      *          The ComponentEvent fired.
      */
     public void componentResized(ComponentEvent e)
     {
       if (frame.isMaximum())
         {
-          JDesktopPane pane = (JDesktopPane) e.getSource();
-          Insets insets = pane.getInsets();
-          Rectangle bounds = pane.getBounds();
-
-          frame.setBounds(bounds.x + insets.left, bounds.y + insets.top,
-                          bounds.width - insets.left - insets.right,
-                          bounds.height - insets.top - insets.bottom);
-          frame.revalidate();
-          frame.repaint();
+          Container parent = frame.getParent();
+          Insets i = parent.getInsets();
+          int width = parent.getWidth() - i.left - i.right;
+          int height = parent.getHeight() - i.top - i.bottom;
+          frame.setBounds(0, 0, width, height);
         }
-
-      // Sun also resizes the icons. but it doesn't seem to do anything.
     }
 
     /**
      * This method is called when the JDesktopPane is shown.
      * 
      * @param e
      *          The ComponentEvent fired.
      */
     public void componentShown(ComponentEvent e)
     {
       // Do nothing.
     }
@@ -940,35 +934,43 @@
           if (newPane != null)
             {
               newPane.addMouseListener(glassPaneDispatcher);
               newPane.addMouseMotionListener(glassPaneDispatcher);
             }
 
           frame.revalidate();
         }
       else if (property.equals(JInternalFrame.IS_CLOSED_PROPERTY))
         {
           if (evt.getNewValue() == Boolean.TRUE)
             {
+              Container parent = frame.getParent();
+              if (parent != null)
+                parent.removeComponentListener(componentListener);
               closeFrame(frame);
             }
         }
-      /*
-       * FIXME: need to add ancestor properties to JComponents. else if
-       * (evt.getPropertyName().equals(JComponent.ANCESTOR_PROPERTY)) { if
-       * (desktopPane != null)
-       * desktopPane.removeComponentListener(componentListener); desktopPane =
-       * frame.getDesktopPane(); if (desktopPane != null)
-       * desktopPane.addComponentListener(componentListener); }
-       */
+      else if (property.equals("ancestor"))
+        {
+          Container newParent = (Container) evt.getNewValue();
+          Container oldParent = (Container) evt.getOldValue();
+          if (newParent != null)
+            {
+              newParent.addComponentListener(componentListener);
+            }
+          else if (oldParent != null)
+            {
+              oldParent.removeComponentListener(componentListener);
+            }
+        }
     }
   }
 
   /**
    * This helper class is the border for the JInternalFrame.
    */
   class InternalFrameBorder extends AbstractBorder implements
       UIResource
   {
     /** 
      * The width of the border. 
      */
@@ -1249,24 +1251,30 @@
     glassPaneDispatcher = createGlassPaneDispatcher();
     createInternalFrameListener();
     borderListener = createBorderListener(frame);
     componentListener = createComponentListener();
     propertyChangeListener = createPropertyChangeListener();
 
     frame.addMouseListener(borderListener);
     frame.addMouseMotionListener(borderListener);
     frame.addInternalFrameListener(internalFrameListener);
     frame.addPropertyChangeListener(propertyChangeListener);
     frame.getRootPane().getGlassPane().addMouseListener(glassPaneDispatcher);
     frame.getRootPane().getGlassPane().addMouseMotionListener(glassPaneDispatcher);
+
+    Container parent = frame.getParent();
+    if (parent != null)
+      {
+        parent.addComponentListener(componentListener);
+      }
   }
 
   /**
    * This method uninstalls the defaults for the JInternalFrame.
    */
   protected void uninstallDefaults()
   {
     frame.setBorder(null);
     frame.setLayout(null);
     internalFrameLayout = null;
   }
 
@@ -1277,37 +1285,42 @@
   {
     setNorthPane(null);
     setSouthPane(null);
     setEastPane(null);
     setWestPane(null);
   }
 
   /**
    * This method uninstalls the listeners for the JInternalFrame.
    */
   protected void uninstallListeners()
   {
-    if (desktopPane != null)
-      desktopPane.removeComponentListener(componentListener);
+
+    Container parent = frame.getParent();
+    if (parent != null)
+      {
+        parent.removeComponentListener(componentListener);
+      }
+    componentListener = null;
 
     frame.getRootPane().getGlassPane().removeMouseMotionListener(glassPaneDispatcher);
     frame.getRootPane().getGlassPane().removeMouseListener(glassPaneDispatcher);
 
     frame.removePropertyChangeListener(propertyChangeListener);
     frame.removeInternalFrameListener(internalFrameListener);
     frame.removeMouseMotionListener(borderListener);
     frame.removeMouseListener(borderListener);
 
     propertyChangeListener = null;
-    componentListener = null;
+
     borderListener = null;
     internalFrameListener = null;
     glassPaneDispatcher = null;
   }
 
   /**
    * This method uninstalls the keyboard actions for the JInternalFrame.
    */
   protected void uninstallKeyboardActions()
   {
     SwingUtilities.replaceUIActionMap(frame, null);
     SwingUtilities.replaceUIInputMap(frame, JComponent.WHEN_IN_FOCUSED_WINDOW,

Reply via email to