mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-11 14:11:36 +00:00
6682046: Mixing code does not always recalculate shapes correctly when resizing components
The valid property is now encapsulated in Component. Reviewed-by: art
This commit is contained in:
parent
9620b88f07
commit
5a843be073
@ -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 @@ public class Button extends Component implements Accessible {
|
||||
}
|
||||
|
||||
// This could change the preferred size of the Component.
|
||||
if (testvalid && valid) {
|
||||
invalidate();
|
||||
if (testvalid) {
|
||||
invalidateIfValid();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 @@ public class Checkbox extends Component implements ItemSelectable, Accessible {
|
||||
}
|
||||
|
||||
// This could change the preferred size of the Component.
|
||||
if (testvalid && valid) {
|
||||
invalidate();
|
||||
if (testvalid) {
|
||||
invalidateIfValid();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 @@ public class Choice extends Component implements ItemSelectable, Accessible {
|
||||
}
|
||||
|
||||
// This could change the preferred size of the Component.
|
||||
if (valid) {
|
||||
invalidate();
|
||||
}
|
||||
invalidateIfValid();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -269,9 +267,7 @@ public class Choice extends Component implements ItemSelectable, Accessible {
|
||||
}
|
||||
|
||||
// This could change the preferred size of the Component.
|
||||
if (valid) {
|
||||
invalidate();
|
||||
}
|
||||
invalidateIfValid();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -299,9 +295,7 @@ public class Choice extends Component implements ItemSelectable, Accessible {
|
||||
}
|
||||
|
||||
// This could change the preferred size of the Component.
|
||||
if (valid) {
|
||||
invalidate();
|
||||
}
|
||||
invalidateIfValid();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -323,9 +317,7 @@ public class Choice extends Component implements ItemSelectable, Accessible {
|
||||
}
|
||||
|
||||
// This could change the preferred size of the Component.
|
||||
if (valid) {
|
||||
invalidate();
|
||||
}
|
||||
invalidateIfValid();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -367,9 +359,7 @@ public class Choice extends Component implements ItemSelectable, Accessible {
|
||||
}
|
||||
|
||||
// This could change the preferred size of the Component.
|
||||
if (valid) {
|
||||
invalidate();
|
||||
}
|
||||
invalidateIfValid();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -346,7 +346,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||
* @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 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||
// 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 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||
firePropertyChange("locale", oldValue, l);
|
||||
|
||||
// This could change the preferred size of the Component.
|
||||
if (valid) {
|
||||
invalidate();
|
||||
}
|
||||
invalidateIfValid();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2084,8 +2082,8 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||
if (resized) {
|
||||
invalidate();
|
||||
}
|
||||
if (parent != null && parent.valid) {
|
||||
parent.invalidate();
|
||||
if (parent != null) {
|
||||
parent.invalidateIfValid();
|
||||
}
|
||||
}
|
||||
if (needNotify) {
|
||||
@ -2654,7 +2652,8 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||
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 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||
peer.layout();
|
||||
}
|
||||
valid = true;
|
||||
if (!wasValid) {
|
||||
mixOnValidating();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2693,12 +2695,20 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a graphics context for this component. This method will
|
||||
* return <code>null</code> if this component is currently not
|
||||
@ -7716,7 +7726,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||
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 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||
firePropertyChange("componentOrientation", oldValue, o);
|
||||
|
||||
// This could change the preferred size of the Component.
|
||||
if (valid) {
|
||||
invalidate();
|
||||
}
|
||||
invalidateIfValid();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -9328,7 +9336,8 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||
*/
|
||||
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 @@ 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 ********************************
|
||||
}
|
||||
|
||||
@ -505,9 +505,7 @@ public class Container extends Component {
|
||||
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 @@ public class Container extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ public class Container extends Component {
|
||||
comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
|
||||
adjustDescendants(comp.countHierarchyMembers());
|
||||
|
||||
if (valid) {
|
||||
invalidate();
|
||||
}
|
||||
invalidateIfValid();
|
||||
if (peer != null) {
|
||||
comp.addNotify();
|
||||
}
|
||||
@ -1155,9 +1149,7 @@ public class Container extends Component {
|
||||
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 @@ public class Container extends Component {
|
||||
if (peer != null && layoutMgr == null && isVisible()) {
|
||||
updateCursorImmediately();
|
||||
}
|
||||
if (valid) {
|
||||
invalidate();
|
||||
}
|
||||
invalidateIfValid();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1411,9 +1401,7 @@ public class Container extends Component {
|
||||
*/
|
||||
public void setLayout(LayoutManager mgr) {
|
||||
layoutMgr = mgr;
|
||||
if (valid) {
|
||||
invalidate();
|
||||
}
|
||||
invalidateIfValid();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1485,10 +1473,10 @@ public class Container extends Component {
|
||||
*/
|
||||
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 @@ public class Container extends Component {
|
||||
p.beginValidate();
|
||||
}
|
||||
validateTree();
|
||||
valid = true;
|
||||
if (p != null) {
|
||||
p.endValidate();
|
||||
updateCur = isVisible();
|
||||
@ -1520,7 +1507,7 @@ public class Container extends Component {
|
||||
* @see #validate
|
||||
*/
|
||||
protected void validateTree() {
|
||||
if (!valid) {
|
||||
if (!isValid()) {
|
||||
if (peer instanceof ContainerPeer) {
|
||||
((ContainerPeer)peer).beginLayout();
|
||||
}
|
||||
@ -1529,7 +1516,7 @@ public class Container extends Component {
|
||||
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 @@ public class Container extends Component {
|
||||
((ContainerPeer)peer).endLayout();
|
||||
}
|
||||
}
|
||||
valid = true;
|
||||
super.validate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1554,14 +1541,10 @@ public class Container extends Component {
|
||||
((Container)comp).invalidateTree();
|
||||
}
|
||||
else {
|
||||
if (comp.valid) {
|
||||
comp.invalidate();
|
||||
}
|
||||
comp.invalidateIfValid();
|
||||
}
|
||||
}
|
||||
if (valid) {
|
||||
invalidate();
|
||||
}
|
||||
invalidateIfValid();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 ********************************
|
||||
}
|
||||
|
||||
|
||||
@ -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 @@ public class Dialog extends Window {
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 @@ public class Frame extends Window implements MenuContainer {
|
||||
if (peer != null) {
|
||||
mbManagement = true;
|
||||
menuBar.addNotify();
|
||||
if (valid) {
|
||||
invalidate();
|
||||
}
|
||||
invalidateIfValid();
|
||||
peer.setMenuBar(menuBar);
|
||||
}
|
||||
}
|
||||
@ -633,8 +631,8 @@ public class Frame extends Window implements MenuContainer {
|
||||
// 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 @@ public class Frame extends Window implements MenuContainer {
|
||||
FramePeer peer = (FramePeer)this.peer;
|
||||
if (peer != null) {
|
||||
mbManagement = true;
|
||||
if (valid) {
|
||||
invalidate();
|
||||
}
|
||||
invalidateIfValid();
|
||||
peer.setMenuBar(null);
|
||||
m.removeNotify();
|
||||
}
|
||||
|
||||
@ -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 @@ public class Label extends Component implements Accessible {
|
||||
}
|
||||
|
||||
// This could change the preferred size of the Component.
|
||||
if (testvalid && valid) {
|
||||
invalidate();
|
||||
if (testvalid) {
|
||||
invalidateIfValid();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 @@ public class TextField extends TextComponent {
|
||||
super.setText(t);
|
||||
|
||||
// This could change the preferred size of the Component.
|
||||
if (valid) {
|
||||
invalidate();
|
||||
}
|
||||
invalidateIfValid();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user