6682046: Mixing code does not always recalculate shapes correctly when resizing components
Summary: The valid property is now encapsulated in Component.
Reviewed-by: art
--- a/jdk/src/share/classes/java/awt/Button.java Mon Jul 07 16:32:38 2008 +0400
+++ b/jdk/src/share/classes/java/awt/Button.java Mon Jul 07 17:24:21 2008 +0400
@@ -1,5 +1,5 @@
/*
- * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1995-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
@@ -213,8 +213,8 @@
}
// This could change the preferred size of the Component.
- if (testvalid && valid) {
- invalidate();
+ if (testvalid) {
+ invalidateIfValid();
}
}
--- a/jdk/src/share/classes/java/awt/Checkbox.java Mon Jul 07 16:32:38 2008 +0400
+++ b/jdk/src/share/classes/java/awt/Checkbox.java Mon Jul 07 17:24:21 2008 +0400
@@ -1,5 +1,5 @@
/*
- * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1995-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
@@ -284,8 +284,8 @@
}
// This could change the preferred size of the Component.
- if (testvalid && valid) {
- invalidate();
+ if (testvalid) {
+ invalidateIfValid();
}
}
--- a/jdk/src/share/classes/java/awt/Choice.java Mon Jul 07 16:32:38 2008 +0400
+++ b/jdk/src/share/classes/java/awt/Choice.java Mon Jul 07 17:24:21 2008 +0400
@@ -1,5 +1,5 @@
/*
- * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1995-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
@@ -207,9 +207,7 @@
}
// This could change the preferred size of the Component.
- if (valid) {
- invalidate();
- }
+ invalidateIfValid();
}
/**
@@ -269,9 +267,7 @@
}
// This could change the preferred size of the Component.
- if (valid) {
- invalidate();
- }
+ invalidateIfValid();
}
/**
@@ -299,9 +295,7 @@
}
// This could change the preferred size of the Component.
- if (valid) {
- invalidate();
- }
+ invalidateIfValid();
}
/**
@@ -323,9 +317,7 @@
}
// This could change the preferred size of the Component.
- if (valid) {
- invalidate();
- }
+ invalidateIfValid();
}
/**
@@ -367,9 +359,7 @@
}
// This could change the preferred size of the Component.
- if (valid) {
- invalidate();
- }
+ invalidateIfValid();
}
/**
--- a/jdk/src/share/classes/java/awt/Component.java Mon Jul 07 16:32:38 2008 +0400
+++ b/jdk/src/share/classes/java/awt/Component.java Mon Jul 07 17:24:21 2008 +0400
@@ -346,7 +346,7 @@
* @see #validate
* @see #invalidate
*/
- volatile boolean valid = false;
+ private volatile boolean valid = false;
/**
* The <code>DropTarget</code> associated with this component.
@@ -1714,9 +1714,9 @@
// This could change the preferred size of the Component.
// Fix for 6213660. Should compare old and new fonts and do not
// call invalidate() if they are equal.
- if (valid && f != oldFont && (oldFont == null ||
+ if (f != oldFont && (oldFont == null ||
!oldFont.equals(f))) {
- invalidate();
+ invalidateIfValid();
}
}
@@ -1773,9 +1773,7 @@
firePropertyChange("locale", oldValue, l);
// This could change the preferred size of the Component.
- if (valid) {
- invalidate();
- }
+ invalidateIfValid();
}
/**
@@ -2084,8 +2082,8 @@
if (resized) {
invalidate();
}
- if (parent != null && parent.valid) {
- parent.invalidate();
+ if (parent != null) {
+ parent.invalidateIfValid();
}
}
if (needNotify) {
@@ -2654,7 +2652,8 @@
public void validate() {
synchronized (getTreeLock()) {
ComponentPeer peer = this.peer;
- if (!valid && peer != null) {
+ boolean wasValid = isValid();
+ if (!wasValid && peer != null) {
Font newfont = getFont();
Font oldfont = peerFont;
if (newfont != oldfont && (oldfont == null
@@ -2665,6 +2664,9 @@
peer.layout();
}
valid = true;
+ if (!wasValid) {
+ mixOnValidating();
+ }
}
}
@@ -2693,9 +2695,17 @@
if (!isMaximumSizeSet()) {
maxSize = null;
}
- if (parent != null && parent.valid) {
- parent.invalidate();
- }
+ if (parent != null) {
+ parent.invalidateIfValid();
+ }
+ }
+ }
+
+ /** Invalidates the component unless it is already invalid.
+ */
+ final void invalidateIfValid() {
+ if (isValid()) {
+ invalidate();
}
}
@@ -7716,7 +7726,7 @@
protected String paramString() {
String thisName = getName();
String str = (thisName != null? thisName : "") + "," + x + "," + y + "," + width + "x" + height;
- if (!valid) {
+ if (!isValid()) {
str += ",invalid";
}
if (!visible) {
@@ -8476,9 +8486,7 @@
firePropertyChange("componentOrientation", oldValue, o);
// This could change the preferred size of the Component.
- if (valid) {
- invalidate();
- }
+ invalidateIfValid();
}
/**
@@ -9328,7 +9336,8 @@
*/
private boolean areBoundsValid() {
Container cont = getContainer();
- return cont == null || cont.isValid() || cont.getLayout() == null;
+ return cont == null || cont.isValid()
+ || cont.getLayout() == null;
}
/**
@@ -9599,5 +9608,10 @@
}
}
+ void mixOnValidating() {
+ // This method gets overriden in the Container. Obviously, a plain
+ // non-container components don't need to handle validation.
+ }
+
// ****************** END OF MIXING CODE ********************************
}
--- a/jdk/src/share/classes/java/awt/Container.java Mon Jul 07 16:32:38 2008 +0400
+++ b/jdk/src/share/classes/java/awt/Container.java Mon Jul 07 17:24:21 2008 +0400
@@ -505,9 +505,7 @@
comp.parent = null;
component.remove(index);
- if (valid) {
- invalidate();
- }
+ invalidateIfValid();
} else {
// We should remove component and then
// add it by the newIndex without newIndex decrement if even we shift components to the left
@@ -800,9 +798,7 @@
}
}
- if (valid) {
- invalidate();
- }
+ invalidateIfValid();
if (peer != null) {
if (comp.peer == null) { // Remove notify was called or it didn't have peer - create new one
comp.addNotify();
@@ -1064,9 +1060,7 @@
comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
adjustDescendants(comp.countHierarchyMembers());
- if (valid) {
- invalidate();
- }
+ invalidateIfValid();
if (peer != null) {
comp.addNotify();
}
@@ -1155,9 +1149,7 @@
comp.parent = null;
component.remove(index);
- if (valid) {
- invalidate();
- }
+ invalidateIfValid();
if (containerListener != null ||
(eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ||
Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) {
@@ -1249,9 +1241,7 @@
if (peer != null && layoutMgr == null && isVisible()) {
updateCursorImmediately();
}
- if (valid) {
- invalidate();
- }
+ invalidateIfValid();
}
}
@@ -1411,9 +1401,7 @@
*/
public void setLayout(LayoutManager mgr) {
layoutMgr = mgr;
- if (valid) {
- invalidate();
- }
+ invalidateIfValid();
}
/**
@@ -1485,10 +1473,10 @@
*/
public void validate() {
/* Avoid grabbing lock unless really necessary. */
- if (!valid) {
+ if (!isValid()) {
boolean updateCur = false;
synchronized (getTreeLock()) {
- if (!valid && peer != null) {
+ if (!isValid() && peer != null) {
ContainerPeer p = null;
if (peer instanceof ContainerPeer) {
p = (ContainerPeer) peer;
@@ -1497,7 +1485,6 @@
p.beginValidate();
}
validateTree();
- valid = true;
if (p != null) {
p.endValidate();
updateCur = isVisible();
@@ -1520,7 +1507,7 @@
* @see #validate
*/
protected void validateTree() {
- if (!valid) {
+ if (!isValid()) {
if (peer instanceof ContainerPeer) {
((ContainerPeer)peer).beginLayout();
}
@@ -1529,7 +1516,7 @@
Component comp = component.get(i);
if ( (comp instanceof Container)
&& !(comp instanceof Window)
- && !comp.valid) {
+ && !comp.isValid()) {
((Container)comp).validateTree();
} else {
comp.validate();
@@ -1539,7 +1526,7 @@
((ContainerPeer)peer).endLayout();
}
}
- valid = true;
+ super.validate();
}
/**
@@ -1554,14 +1541,10 @@
((Container)comp).invalidateTree();
}
else {
- if (comp.valid) {
- comp.invalidate();
- }
+ comp.invalidateIfValid();
}
}
- if (valid) {
- invalidate();
- }
+ invalidateIfValid();
}
}
@@ -4083,6 +4066,21 @@
}
}
+ @Override
+ void mixOnValidating() {
+ synchronized (getTreeLock()) {
+ if (mixingLog.isLoggable(Level.FINE)) {
+ mixingLog.fine("this = " + this);
+ }
+
+ if (hasHeavyweightDescendants()) {
+ recursiveApplyCurrentShape();
+ }
+
+ super.mixOnValidating();
+ }
+ }
+
// ****************** END OF MIXING CODE ********************************
}
--- a/jdk/src/share/classes/java/awt/Dialog.java Mon Jul 07 16:32:38 2008 +0400
+++ b/jdk/src/share/classes/java/awt/Dialog.java Mon Jul 07 17:24:21 2008 +0400
@@ -1,5 +1,5 @@
/*
- * Copyright 1995-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1995-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
@@ -1327,8 +1327,8 @@
// the insets of the Dialog. If we could, we'd call invalidate()
// from the peer, but we need to guarantee that we're not holding
// the Dialog lock when we call invalidate().
- if (testvalid && valid) {
- invalidate();
+ if (testvalid) {
+ invalidateIfValid();
}
}
--- a/jdk/src/share/classes/java/awt/Frame.java Mon Jul 07 16:32:38 2008 +0400
+++ b/jdk/src/share/classes/java/awt/Frame.java Mon Jul 07 17:24:21 2008 +0400
@@ -1,5 +1,5 @@
/*
- * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1995-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
@@ -590,9 +590,7 @@
if (peer != null) {
mbManagement = true;
menuBar.addNotify();
- if (valid) {
- invalidate();
- }
+ invalidateIfValid();
peer.setMenuBar(menuBar);
}
}
@@ -633,8 +631,8 @@
// the insets of the Frame. If we could, we'd call invalidate()
// from the peer, but we need to guarantee that we're not holding
// the Frame lock when we call invalidate().
- if (testvalid && valid) {
- invalidate();
+ if (testvalid) {
+ invalidateIfValid();
}
firePropertyChange("resizable", oldResizable, resizable);
}
@@ -907,9 +905,7 @@
FramePeer peer = (FramePeer)this.peer;
if (peer != null) {
mbManagement = true;
- if (valid) {
- invalidate();
- }
+ invalidateIfValid();
peer.setMenuBar(null);
m.removeNotify();
}
--- a/jdk/src/share/classes/java/awt/Label.java Mon Jul 07 16:32:38 2008 +0400
+++ b/jdk/src/share/classes/java/awt/Label.java Mon Jul 07 17:24:21 2008 +0400
@@ -1,5 +1,5 @@
/*
- * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1995-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
@@ -257,8 +257,8 @@
}
// This could change the preferred size of the Component.
- if (testvalid && valid) {
- invalidate();
+ if (testvalid) {
+ invalidateIfValid();
}
}
--- a/jdk/src/share/classes/java/awt/TextField.java Mon Jul 07 16:32:38 2008 +0400
+++ b/jdk/src/share/classes/java/awt/TextField.java Mon Jul 07 17:24:21 2008 +0400
@@ -1,5 +1,5 @@
/*
- * Copyright 1995-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1995-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
@@ -296,9 +296,7 @@
super.setText(t);
// This could change the preferred size of the Component.
- if (valid) {
- invalidate();
- }
+ invalidateIfValid();
}
/**