提交 331fe7cf 编写于 作者: A anthony

6682046: Mixing code does not always recalculate shapes correctly when resizing components

Summary: The valid property is now encapsulated in Component.
Reviewed-by: art
上级 7dd8e5de
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -213,8 +213,8 @@ public class Button extends Component implements Accessible { ...@@ -213,8 +213,8 @@ public class Button extends Component implements Accessible {
} }
// This could change the preferred size of the Component. // This could change the preferred size of the Component.
if (testvalid && valid) { if (testvalid) {
invalidate(); invalidateIfValid();
} }
} }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -284,8 +284,8 @@ public class Checkbox extends Component implements ItemSelectable, Accessible { ...@@ -284,8 +284,8 @@ public class Checkbox extends Component implements ItemSelectable, Accessible {
} }
// This could change the preferred size of the Component. // This could change the preferred size of the Component.
if (testvalid && valid) { if (testvalid) {
invalidate(); invalidateIfValid();
} }
} }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -207,9 +207,7 @@ public class Choice extends Component implements ItemSelectable, Accessible { ...@@ -207,9 +207,7 @@ public class Choice extends Component implements ItemSelectable, Accessible {
} }
// This could change the preferred size of the Component. // This could change the preferred size of the Component.
if (valid) { invalidateIfValid();
invalidate();
}
} }
/** /**
...@@ -269,9 +267,7 @@ public class Choice extends Component implements ItemSelectable, Accessible { ...@@ -269,9 +267,7 @@ public class Choice extends Component implements ItemSelectable, Accessible {
} }
// This could change the preferred size of the Component. // This could change the preferred size of the Component.
if (valid) { invalidateIfValid();
invalidate();
}
} }
/** /**
...@@ -299,9 +295,7 @@ public class Choice extends Component implements ItemSelectable, Accessible { ...@@ -299,9 +295,7 @@ public class Choice extends Component implements ItemSelectable, Accessible {
} }
// This could change the preferred size of the Component. // This could change the preferred size of the Component.
if (valid) { invalidateIfValid();
invalidate();
}
} }
/** /**
...@@ -323,9 +317,7 @@ public class Choice extends Component implements ItemSelectable, Accessible { ...@@ -323,9 +317,7 @@ public class Choice extends Component implements ItemSelectable, Accessible {
} }
// This could change the preferred size of the Component. // This could change the preferred size of the Component.
if (valid) { invalidateIfValid();
invalidate();
}
} }
/** /**
...@@ -367,9 +359,7 @@ public class Choice extends Component implements ItemSelectable, Accessible { ...@@ -367,9 +359,7 @@ public class Choice extends Component implements ItemSelectable, Accessible {
} }
// This could change the preferred size of the Component. // This could change the preferred size of the Component.
if (valid) { invalidateIfValid();
invalidate();
}
} }
/** /**
......
...@@ -346,7 +346,7 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -346,7 +346,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
* @see #validate * @see #validate
* @see #invalidate * @see #invalidate
*/ */
volatile boolean valid = false; private volatile boolean valid = false;
/** /**
* The <code>DropTarget</code> associated with this component. * The <code>DropTarget</code> associated with this component.
...@@ -1714,9 +1714,9 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -1714,9 +1714,9 @@ public abstract class Component implements ImageObserver, MenuContainer,
// This could change the preferred size of the Component. // This could change the preferred size of the Component.
// Fix for 6213660. Should compare old and new fonts and do not // Fix for 6213660. Should compare old and new fonts and do not
// call invalidate() if they are equal. // call invalidate() if they are equal.
if (valid && f != oldFont && (oldFont == null || if (f != oldFont && (oldFont == null ||
!oldFont.equals(f))) { !oldFont.equals(f))) {
invalidate(); invalidateIfValid();
} }
} }
...@@ -1773,9 +1773,7 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -1773,9 +1773,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
firePropertyChange("locale", oldValue, l); firePropertyChange("locale", oldValue, l);
// This could change the preferred size of the Component. // This could change the preferred size of the Component.
if (valid) { invalidateIfValid();
invalidate();
}
} }
/** /**
...@@ -2084,8 +2082,8 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -2084,8 +2082,8 @@ public abstract class Component implements ImageObserver, MenuContainer,
if (resized) { if (resized) {
invalidate(); invalidate();
} }
if (parent != null && parent.valid) { if (parent != null) {
parent.invalidate(); parent.invalidateIfValid();
} }
} }
if (needNotify) { if (needNotify) {
...@@ -2654,7 +2652,8 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -2654,7 +2652,8 @@ public abstract class Component implements ImageObserver, MenuContainer,
public void validate() { public void validate() {
synchronized (getTreeLock()) { synchronized (getTreeLock()) {
ComponentPeer peer = this.peer; ComponentPeer peer = this.peer;
if (!valid && peer != null) { boolean wasValid = isValid();
if (!wasValid && peer != null) {
Font newfont = getFont(); Font newfont = getFont();
Font oldfont = peerFont; Font oldfont = peerFont;
if (newfont != oldfont && (oldfont == null if (newfont != oldfont && (oldfont == null
...@@ -2665,6 +2664,9 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -2665,6 +2664,9 @@ public abstract class Component implements ImageObserver, MenuContainer,
peer.layout(); peer.layout();
} }
valid = true; valid = true;
if (!wasValid) {
mixOnValidating();
}
} }
} }
...@@ -2693,12 +2695,20 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -2693,12 +2695,20 @@ public abstract class Component implements ImageObserver, MenuContainer,
if (!isMaximumSizeSet()) { if (!isMaximumSizeSet()) {
maxSize = null; maxSize = null;
} }
if (parent != null && parent.valid) { if (parent != null) {
parent.invalidate(); parent.invalidateIfValid();
} }
} }
} }
/** Invalidates the component unless it is already invalid.
*/
final void invalidateIfValid() {
if (isValid()) {
invalidate();
}
}
/** /**
* Creates a graphics context for this component. This method will * Creates a graphics context for this component. This method will
* return <code>null</code> if this component is currently not * return <code>null</code> if this component is currently not
...@@ -7716,7 +7726,7 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -7716,7 +7726,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
protected String paramString() { protected String paramString() {
String thisName = getName(); String thisName = getName();
String str = (thisName != null? thisName : "") + "," + x + "," + y + "," + width + "x" + height; String str = (thisName != null? thisName : "") + "," + x + "," + y + "," + width + "x" + height;
if (!valid) { if (!isValid()) {
str += ",invalid"; str += ",invalid";
} }
if (!visible) { if (!visible) {
...@@ -8476,9 +8486,7 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -8476,9 +8486,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
firePropertyChange("componentOrientation", oldValue, o); firePropertyChange("componentOrientation", oldValue, o);
// This could change the preferred size of the Component. // This could change the preferred size of the Component.
if (valid) { invalidateIfValid();
invalidate();
}
} }
/** /**
...@@ -9328,7 +9336,8 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -9328,7 +9336,8 @@ public abstract class Component implements ImageObserver, MenuContainer,
*/ */
private boolean areBoundsValid() { private boolean areBoundsValid() {
Container cont = getContainer(); Container cont = getContainer();
return cont == null || cont.isValid() || cont.getLayout() == null; return cont == null || cont.isValid()
|| cont.getLayout() == null;
} }
/** /**
...@@ -9599,5 +9608,10 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -9599,5 +9608,10 @@ public abstract class Component implements ImageObserver, MenuContainer,
} }
} }
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 ******************************** // ****************** END OF MIXING CODE ********************************
} }
...@@ -505,9 +505,7 @@ public class Container extends Component { ...@@ -505,9 +505,7 @@ public class Container extends Component {
comp.parent = null; comp.parent = null;
component.remove(index); component.remove(index);
if (valid) { invalidateIfValid();
invalidate();
}
} else { } else {
// We should remove component and then // We should remove component and then
// add it by the newIndex without newIndex decrement if even we shift components to the left // add it by the newIndex without newIndex decrement if even we shift components to the left
...@@ -800,9 +798,7 @@ public class Container extends Component { ...@@ -800,9 +798,7 @@ public class Container extends Component {
} }
} }
if (valid) { invalidateIfValid();
invalidate();
}
if (peer != null) { if (peer != null) {
if (comp.peer == null) { // Remove notify was called or it didn't have peer - create new one if (comp.peer == null) { // Remove notify was called or it didn't have peer - create new one
comp.addNotify(); comp.addNotify();
...@@ -1064,9 +1060,7 @@ public class Container extends Component { ...@@ -1064,9 +1060,7 @@ public class Container extends Component {
comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK)); comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
adjustDescendants(comp.countHierarchyMembers()); adjustDescendants(comp.countHierarchyMembers());
if (valid) { invalidateIfValid();
invalidate();
}
if (peer != null) { if (peer != null) {
comp.addNotify(); comp.addNotify();
} }
...@@ -1155,9 +1149,7 @@ public class Container extends Component { ...@@ -1155,9 +1149,7 @@ public class Container extends Component {
comp.parent = null; comp.parent = null;
component.remove(index); component.remove(index);
if (valid) { invalidateIfValid();
invalidate();
}
if (containerListener != null || if (containerListener != null ||
(eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ||
Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) { Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) {
...@@ -1249,9 +1241,7 @@ public class Container extends Component { ...@@ -1249,9 +1241,7 @@ public class Container extends Component {
if (peer != null && layoutMgr == null && isVisible()) { if (peer != null && layoutMgr == null && isVisible()) {
updateCursorImmediately(); updateCursorImmediately();
} }
if (valid) { invalidateIfValid();
invalidate();
}
} }
} }
...@@ -1411,9 +1401,7 @@ public class Container extends Component { ...@@ -1411,9 +1401,7 @@ public class Container extends Component {
*/ */
public void setLayout(LayoutManager mgr) { public void setLayout(LayoutManager mgr) {
layoutMgr = mgr; layoutMgr = mgr;
if (valid) { invalidateIfValid();
invalidate();
}
} }
/** /**
...@@ -1485,10 +1473,10 @@ public class Container extends Component { ...@@ -1485,10 +1473,10 @@ public class Container extends Component {
*/ */
public void validate() { public void validate() {
/* Avoid grabbing lock unless really necessary. */ /* Avoid grabbing lock unless really necessary. */
if (!valid) { if (!isValid()) {
boolean updateCur = false; boolean updateCur = false;
synchronized (getTreeLock()) { synchronized (getTreeLock()) {
if (!valid && peer != null) { if (!isValid() && peer != null) {
ContainerPeer p = null; ContainerPeer p = null;
if (peer instanceof ContainerPeer) { if (peer instanceof ContainerPeer) {
p = (ContainerPeer) peer; p = (ContainerPeer) peer;
...@@ -1497,7 +1485,6 @@ public class Container extends Component { ...@@ -1497,7 +1485,6 @@ public class Container extends Component {
p.beginValidate(); p.beginValidate();
} }
validateTree(); validateTree();
valid = true;
if (p != null) { if (p != null) {
p.endValidate(); p.endValidate();
updateCur = isVisible(); updateCur = isVisible();
...@@ -1520,7 +1507,7 @@ public class Container extends Component { ...@@ -1520,7 +1507,7 @@ public class Container extends Component {
* @see #validate * @see #validate
*/ */
protected void validateTree() { protected void validateTree() {
if (!valid) { if (!isValid()) {
if (peer instanceof ContainerPeer) { if (peer instanceof ContainerPeer) {
((ContainerPeer)peer).beginLayout(); ((ContainerPeer)peer).beginLayout();
} }
...@@ -1529,7 +1516,7 @@ public class Container extends Component { ...@@ -1529,7 +1516,7 @@ public class Container extends Component {
Component comp = component.get(i); Component comp = component.get(i);
if ( (comp instanceof Container) if ( (comp instanceof Container)
&& !(comp instanceof Window) && !(comp instanceof Window)
&& !comp.valid) { && !comp.isValid()) {
((Container)comp).validateTree(); ((Container)comp).validateTree();
} else { } else {
comp.validate(); comp.validate();
...@@ -1539,7 +1526,7 @@ public class Container extends Component { ...@@ -1539,7 +1526,7 @@ public class Container extends Component {
((ContainerPeer)peer).endLayout(); ((ContainerPeer)peer).endLayout();
} }
} }
valid = true; super.validate();
} }
/** /**
...@@ -1554,14 +1541,10 @@ public class Container extends Component { ...@@ -1554,14 +1541,10 @@ public class Container extends Component {
((Container)comp).invalidateTree(); ((Container)comp).invalidateTree();
} }
else { else {
if (comp.valid) { comp.invalidateIfValid();
comp.invalidate();
}
} }
} }
if (valid) { invalidateIfValid();
invalidate();
}
} }
} }
...@@ -4083,6 +4066,21 @@ public class Container extends Component { ...@@ -4083,6 +4066,21 @@ public class Container extends Component {
} }
} }
@Override
void mixOnValidating() {
synchronized (getTreeLock()) {
if (mixingLog.isLoggable(Level.FINE)) {
mixingLog.fine("this = " + this);
}
if (hasHeavyweightDescendants()) {
recursiveApplyCurrentShape();
}
super.mixOnValidating();
}
}
// ****************** END OF MIXING CODE ******************************** // ****************** END OF MIXING CODE ********************************
} }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -1327,8 +1327,8 @@ public class Dialog extends Window { ...@@ -1327,8 +1327,8 @@ public class Dialog extends Window {
// the insets of the Dialog. If we could, we'd call invalidate() // 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 // from the peer, but we need to guarantee that we're not holding
// the Dialog lock when we call invalidate(). // the Dialog lock when we call invalidate().
if (testvalid && valid) { if (testvalid) {
invalidate(); invalidateIfValid();
} }
} }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -590,9 +590,7 @@ public class Frame extends Window implements MenuContainer { ...@@ -590,9 +590,7 @@ public class Frame extends Window implements MenuContainer {
if (peer != null) { if (peer != null) {
mbManagement = true; mbManagement = true;
menuBar.addNotify(); menuBar.addNotify();
if (valid) { invalidateIfValid();
invalidate();
}
peer.setMenuBar(menuBar); peer.setMenuBar(menuBar);
} }
} }
...@@ -633,8 +631,8 @@ public class Frame extends Window implements MenuContainer { ...@@ -633,8 +631,8 @@ public class Frame extends Window implements MenuContainer {
// the insets of the Frame. If we could, we'd call invalidate() // 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 // from the peer, but we need to guarantee that we're not holding
// the Frame lock when we call invalidate(). // the Frame lock when we call invalidate().
if (testvalid && valid) { if (testvalid) {
invalidate(); invalidateIfValid();
} }
firePropertyChange("resizable", oldResizable, resizable); firePropertyChange("resizable", oldResizable, resizable);
} }
...@@ -907,9 +905,7 @@ public class Frame extends Window implements MenuContainer { ...@@ -907,9 +905,7 @@ public class Frame extends Window implements MenuContainer {
FramePeer peer = (FramePeer)this.peer; FramePeer peer = (FramePeer)this.peer;
if (peer != null) { if (peer != null) {
mbManagement = true; mbManagement = true;
if (valid) { invalidateIfValid();
invalidate();
}
peer.setMenuBar(null); peer.setMenuBar(null);
m.removeNotify(); m.removeNotify();
} }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -257,8 +257,8 @@ public class Label extends Component implements Accessible { ...@@ -257,8 +257,8 @@ public class Label extends Component implements Accessible {
} }
// This could change the preferred size of the Component. // This could change the preferred size of the Component.
if (testvalid && valid) { if (testvalid) {
invalidate(); invalidateIfValid();
} }
} }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -296,9 +296,7 @@ public class TextField extends TextComponent { ...@@ -296,9 +296,7 @@ public class TextField extends TextComponent {
super.setText(t); super.setText(t);
// This could change the preferred size of the Component. // This could change the preferred size of the Component.
if (valid) { invalidateIfValid();
invalidate();
}
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册