6802868: JInternalFrame is not maximized when maximized parent frame.
Reviewed-by: rupashka
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicDesktopIconUI.java Mon Jul 20 13:34:54 2009 +0400
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicDesktopIconUI.java Wed Jul 22 12:21:31 2009 +0400
@@ -1,5 +1,5 @@
/*
- * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -32,9 +32,6 @@
import javax.swing.border.*;
import javax.swing.plaf.*;
import java.beans.*;
-import java.util.EventListener;
-import java.io.Serializable;
-
/**
* Basic L&F for a minimized window on a desktop.
@@ -47,7 +44,6 @@
protected JInternalFrame.JDesktopIcon desktopIcon;
protected JInternalFrame frame;
- private DesktopIconMover desktopIconMover;
/**
* The title pane component used in the desktop icon.
@@ -128,21 +124,12 @@
mouseInputListener = createMouseInputListener();
desktopIcon.addMouseMotionListener(mouseInputListener);
desktopIcon.addMouseListener(mouseInputListener);
- getDesktopIconMover().installListeners();
}
protected void uninstallListeners() {
desktopIcon.removeMouseMotionListener(mouseInputListener);
desktopIcon.removeMouseListener(mouseInputListener);
mouseInputListener = null;
- getDesktopIconMover().uninstallListeners();
- }
-
- private DesktopIconMover getDesktopIconMover() {
- if (desktopIconMover == null) {
- desktopIconMover = new DesktopIconMover(desktopIcon);
- }
- return desktopIconMover;
}
protected void installDefaults() {
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicInternalFrameUI.java Mon Jul 20 13:34:54 2009 +0400
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicInternalFrameUI.java Wed Jul 22 12:21:31 2009 +0400
@@ -27,16 +27,10 @@
import java.awt.*;
import java.awt.event.*;
-import java.awt.peer.LightweightPeer;
-
import javax.swing.*;
-import javax.swing.border.*;
import javax.swing.plaf.*;
import javax.swing.event.*;
-
import java.beans.*;
-import java.io.Serializable;
-
import sun.swing.DefaultLookup;
import sun.swing.UIAction;
@@ -55,6 +49,7 @@
protected MouseInputAdapter borderListener;
protected PropertyChangeListener propertyChangeListener;
protected LayoutManager internalFrameLayout;
+ protected ComponentListener componentListener;
protected MouseInputListener glassPaneDispatcher;
private InternalFrameListener internalFrameListener;
@@ -66,9 +61,9 @@
protected BasicInternalFrameTitlePane titlePane; // access needs this
private static DesktopManager sharedDesktopManager;
+ private boolean componentListenerAdded = false;
private Rectangle parentBounds;
- private DesktopIconMover desktopIconMover;
private boolean dragging = false;
private boolean resizing = false;
@@ -209,17 +204,14 @@
frame.getGlassPane().addMouseListener(glassPaneDispatcher);
frame.getGlassPane().addMouseMotionListener(glassPaneDispatcher);
}
+ componentListener = createComponentListener();
if (frame.getParent() != null) {
parentBounds = frame.getParent().getBounds();
}
- getDesktopIconMover().installListeners();
- }
-
- private DesktopIconMover getDesktopIconMover() {
- if (desktopIconMover == null) {
- desktopIconMover = new DesktopIconMover(frame);
+ if ((frame.getParent() != null) && !componentListenerAdded) {
+ frame.getParent().addComponentListener(componentListener);
+ componentListenerAdded = true;
}
- return desktopIconMover;
}
// Provide a FocusListener to listen for a WINDOW_LOST_FOCUS event,
@@ -290,7 +282,11 @@
* @since 1.3
*/
protected void uninstallListeners() {
- getDesktopIconMover().uninstallListeners();
+ if ((frame.getParent() != null) && componentListenerAdded) {
+ frame.getParent().removeComponentListener(componentListener);
+ componentListenerAdded = false;
+ }
+ componentListener = null;
if (glassPaneDispatcher != null) {
frame.getGlassPane().removeMouseListener(glassPaneDispatcher);
frame.getGlassPane().removeMouseMotionListener(glassPaneDispatcher);
@@ -1228,6 +1224,15 @@
}
}
+ // Relocate the icon base on the new parent bounds.
+ if (icon != null) {
+ Rectangle iconBounds = icon.getBounds();
+ int y = iconBounds.y +
+ (parentNewBounds.height - parentBounds.height);
+ icon.setBounds(iconBounds.x, y,
+ iconBounds.width, iconBounds.height);
+ }
+
// Update the new parent bounds for next resize.
if (!parentBounds.equals(parentNewBounds)) {
parentBounds = parentNewBounds;
@@ -1399,6 +1404,9 @@
// Cancel a resize in progress if the internal frame
// gets a setClosed(true) or dispose().
cancelResize();
+ if ((frame.getParent() != null) && componentListenerAdded) {
+ frame.getParent().removeComponentListener(componentListener);
+ }
closeFrame(f);
}
} else if (JInternalFrame.IS_MAXIMUM_PROPERTY == prop) {
@@ -1431,6 +1439,10 @@
} else {
parentBounds = null;
}
+ if ((frame.getParent() != null) && !componentListenerAdded) {
+ f.getParent().addComponentListener(componentListener);
+ componentListenerAdded = true;
+ }
} else if (JInternalFrame.TITLE_PROPERTY == prop ||
prop == "closable" || prop == "iconable" ||
prop == "maximizable") {
--- a/jdk/src/share/classes/javax/swing/plaf/basic/DesktopIconMover.java Mon Jul 20 13:34:54 2009 +0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,168 +0,0 @@
-/*
- * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package javax.swing.plaf.basic;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.*;
-import java.beans.*;
-
-/**
- * DesktopIconMover is intended to move desktop icon
- * when parent window is resized.
- */
-class DesktopIconMover implements ComponentListener, PropertyChangeListener {
- private Component parent;
- private JInternalFrame frame; // if not null, DesktopIconMover(frame)
- // constructor was used
- private JInternalFrame.JDesktopIcon icon;
- private Rectangle parentBounds;
- private boolean componentListenerAdded = false;
-
- public DesktopIconMover(JInternalFrame frame) {
- if (frame == null) {
- throw new NullPointerException("Frame cannot be null");
- }
- this.frame = frame;
- this.icon = frame.getDesktopIcon();
- if (icon == null) {
- throw new NullPointerException(
- "frame.getDesktopIcon() cannot be null");
- }
- this.parent = frame.getParent();
- if (this.parent != null) {
- parentBounds = this.parent.getBounds();
- }
- }
-
- public DesktopIconMover(JInternalFrame.JDesktopIcon icon) {
- if (icon == null) {
- throw new NullPointerException("Icon cannot be null");
- }
- this.icon = icon;
- this.parent = icon.getParent();
- if (this.parent != null) {
- parentBounds = this.parent.getBounds();
- }
- }
-
- public void installListeners() {
- if (frame != null) {
- frame.addPropertyChangeListener(this);
- } else {
- icon.addPropertyChangeListener(this);
- }
- addComponentListener();
- }
-
- public void uninstallListeners() {
- if (frame != null) {
- frame.removePropertyChangeListener(this);
- } else {
- icon.removePropertyChangeListener(this);
- }
- removeComponentListener();
- }
-
- public void propertyChange(PropertyChangeEvent evt) {
- String propName = evt.getPropertyName();
- if ("ancestor".equals(propName)) {
- Component newAncestor = (Component) evt.getNewValue();
-
- // Remove component listener if parent is changing
- Component probablyNewParent = getCurrentParent();
- if ((probablyNewParent != null) &&
- (!probablyNewParent.equals(parent))) {
- removeComponentListener();
- parent = probablyNewParent;
- }
-
- if (newAncestor == null) {
- removeComponentListener();
- } else {
- addComponentListener();
- }
-
- // Update parentBounds
- if (parent != null) {
- parentBounds = parent.getBounds();
- } else {
- parentBounds = null;
- }
- } else if (JInternalFrame.IS_CLOSED_PROPERTY.equals(propName)) {
- removeComponentListener();
- }
- }
-
- private void addComponentListener() {
- if (!componentListenerAdded && (parent != null)) {
- parent.addComponentListener(this);
- componentListenerAdded = true;
- }
- }
-
- private void removeComponentListener() {
- if ((parent != null) && componentListenerAdded) {
- parent.removeComponentListener(this);
- componentListenerAdded = false;
- }
- }
-
- private Component getCurrentParent() {
- if (frame != null) {
- return frame.getParent();
- } else {
- return icon.getParent();
- }
- }
-
- public void componentResized(ComponentEvent e) {
- if ((parent == null) || (parentBounds == null)) {
- return;
- }
-
- Rectangle parentNewBounds = parent.getBounds();
- if ((parentNewBounds == null) || parentNewBounds.equals(parentBounds)) {
- return;
- }
-
- // Move desktop icon only in up-down direction
- int newIconY = icon.getLocation().y +
- (parentNewBounds.height - parentBounds.height);
- icon.setLocation(icon.getLocation().x, newIconY);
-
- parentBounds = parentNewBounds;
- }
-
- public void componentMoved(ComponentEvent e) {
- }
-
- public void componentShown(ComponentEvent e) {
- }
-
- public void componentHidden(ComponentEvent e) {
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JInternalFrame/Test6802868.java Wed Jul 22 12:21:31 2009 +0400
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6802868
+ * @summary JInternalFrame is not maximized when maximized parent frame
+ * @author Alexander Potochkin
+ */
+
+import sun.awt.SunToolkit;
+
+import java.awt.Dimension;
+import java.awt.Point;
+import java.awt.Robot;
+import java.awt.Toolkit;
+import java.beans.PropertyVetoException;
+import javax.swing.JDesktopPane;
+import javax.swing.JFrame;
+import javax.swing.JInternalFrame;
+import javax.swing.SwingUtilities;
+
+public class Test6802868 {
+ static JInternalFrame jif;
+ static JFrame frame;
+ static Dimension size;
+ static Point location;
+
+ public static void main(String[] args) throws Exception {
+ Robot robot = new Robot();
+ robot.setAutoDelay(20);
+ SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame = new JFrame();
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ JDesktopPane jdp = new JDesktopPane();
+ frame.getContentPane().add(jdp);
+
+ jif = new JInternalFrame("Title", true, true, true, true);
+ jdp.add(jif);
+ jif.setVisible(true);
+
+ frame.setSize(200, 200);
+ frame.setLocationRelativeTo(null);
+ frame.setVisible(true);
+
+ try {
+ jif.setMaximum(true);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ toolkit.realSync();
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ size = jif.getSize();
+ frame.setSize(300, 300);
+ }
+ });
+ toolkit.realSync();
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ if (jif.getSize().equals(size)) {
+ throw new RuntimeException("InternalFrame hasn't changed its size");
+ }
+ try {
+ jif.setIcon(true);
+ } catch (PropertyVetoException e) {
+ e.printStackTrace();
+ }
+ location = jif.getDesktopIcon().getLocation();
+ frame.setSize(400, 400);
+ }
+ });
+ toolkit.realSync();
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ if (jif.getDesktopIcon().getLocation().equals(location)) {
+ throw new RuntimeException("JDesktopIcon hasn't moved");
+ }
+ }
+ });
+ }
+}