提交 a0158dbd 编写于 作者: D dav

Merge

...@@ -2141,7 +2141,7 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -2141,7 +2141,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
Toolkit.getEventQueue().postEvent(e); Toolkit.getEventQueue().postEvent(e);
} }
} else { } else {
if (this instanceof Container && ((Container)this).ncomponents > 0) { if (this instanceof Container && ((Container)this).countComponents() > 0) {
boolean enabledOnToolkit = boolean enabledOnToolkit =
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK); Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK);
if (resized) { if (resized) {
......
...@@ -357,7 +357,7 @@ public class ScrollPane extends Container implements Accessible { ...@@ -357,7 +357,7 @@ public class ScrollPane extends Container implements Accessible {
*/ */
public void setScrollPosition(int x, int y) { public void setScrollPosition(int x, int y) {
synchronized (getTreeLock()) { synchronized (getTreeLock()) {
if (ncomponents <= 0) { if (getComponentCount()==0) {
throw new NullPointerException("child is null"); throw new NullPointerException("child is null");
} }
hAdjustable.setValue(x); hAdjustable.setValue(x);
...@@ -393,10 +393,12 @@ public class ScrollPane extends Container implements Accessible { ...@@ -393,10 +393,12 @@ public class ScrollPane extends Container implements Accessible {
*/ */
@Transient @Transient
public Point getScrollPosition() { public Point getScrollPosition() {
if (ncomponents <= 0) { synchronized (getTreeLock()) {
throw new NullPointerException("child is null"); if (getComponentCount()==0) {
throw new NullPointerException("child is null");
}
return new Point(hAdjustable.getValue(), vAdjustable.getValue());
} }
return new Point(hAdjustable.getValue(), vAdjustable.getValue());
} }
/** /**
...@@ -486,26 +488,27 @@ public class ScrollPane extends Container implements Accessible { ...@@ -486,26 +488,27 @@ public class ScrollPane extends Container implements Accessible {
*/ */
@Deprecated @Deprecated
public void layout() { public void layout() {
if (ncomponents > 0) { if (getComponentCount()==0) {
Component c = getComponent(0); return;
Point p = getScrollPosition(); }
Dimension cs = calculateChildSize(); Component c = getComponent(0);
Dimension vs = getViewportSize(); Point p = getScrollPosition();
Insets i = getInsets(); Dimension cs = calculateChildSize();
Dimension vs = getViewportSize();
c.reshape(i.left - p.x, i.top - p.y, cs.width, cs.height); Insets i = getInsets();
ScrollPanePeer peer = (ScrollPanePeer)this.peer;
if (peer != null) {
peer.childResized(cs.width, cs.height);
}
// update adjustables... the viewport size may have changed c.reshape(i.left - p.x, i.top - p.y, cs.width, cs.height);
// with the scrollbars coming or going so the viewport size ScrollPanePeer peer = (ScrollPanePeer)this.peer;
// is updated before the adjustables. if (peer != null) {
vs = getViewportSize(); peer.childResized(cs.width, cs.height);
hAdjustable.setSpan(0, cs.width, vs.width);
vAdjustable.setSpan(0, cs.height, vs.height);
} }
// update adjustables... the viewport size may have changed
// with the scrollbars coming or going so the viewport size
// is updated before the adjustables.
vs = getViewportSize();
hAdjustable.setSpan(0, cs.width, vs.width);
vAdjustable.setSpan(0, cs.height, vs.height);
} }
/** /**
...@@ -515,20 +518,21 @@ public class ScrollPane extends Container implements Accessible { ...@@ -515,20 +518,21 @@ public class ScrollPane extends Container implements Accessible {
* @see Component#printAll * @see Component#printAll
*/ */
public void printComponents(Graphics g) { public void printComponents(Graphics g) {
if (ncomponents > 0) { if (getComponentCount()==0) {
Component c = component[0]; return;
Point p = c.getLocation(); }
Dimension vs = getViewportSize(); Component c = getComponent(0);
Insets i = getInsets(); Point p = c.getLocation();
Dimension vs = getViewportSize();
Graphics cg = g.create(); Insets i = getInsets();
try {
cg.clipRect(i.left, i.top, vs.width, vs.height); Graphics cg = g.create();
cg.translate(p.x, p.y); try {
c.printAll(cg); cg.clipRect(i.left, i.top, vs.width, vs.height);
} finally { cg.translate(p.x, p.y);
cg.dispose(); c.printAll(cg);
} } finally {
cg.dispose();
} }
} }
...@@ -589,7 +593,7 @@ public class ScrollPane extends Container implements Accessible { ...@@ -589,7 +593,7 @@ public class ScrollPane extends Container implements Accessible {
default: default:
sdpStr = "invalid display policy"; sdpStr = "invalid display policy";
} }
Point p = ncomponents > 0? getScrollPosition() : new Point(0,0); Point p = (getComponentCount()>0)? getScrollPosition() : new Point(0,0);
Insets i = getInsets(); Insets i = getInsets();
return super.paramString()+",ScrollPosition=("+p.x+","+p.y+")"+ return super.paramString()+",ScrollPosition=("+p.x+","+p.y+")"+
",Insets=("+i.top+","+i.left+","+i.bottom+","+i.right+")"+ ",Insets=("+i.top+","+i.left+","+i.bottom+","+i.right+")"+
......
/* /*
* Copyright 1998-2000 Sun Microsystems, Inc. All Rights Reserved. * Copyright 1998-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
...@@ -30,8 +30,6 @@ ...@@ -30,8 +30,6 @@
* AwtContainer fields * AwtContainer fields
*/ */
jfieldID AwtContainer::ncomponentsID;
jfieldID AwtContainer::componentID;
jfieldID AwtContainer::layoutMgrID; jfieldID AwtContainer::layoutMgrID;
jmethodID AwtContainer::findComponentAtMID; jmethodID AwtContainer::findComponentAtMID;
...@@ -45,18 +43,12 @@ JNIEXPORT void JNICALL ...@@ -45,18 +43,12 @@ JNIEXPORT void JNICALL
Java_java_awt_Container_initIDs(JNIEnv *env, jclass cls) { Java_java_awt_Container_initIDs(JNIEnv *env, jclass cls) {
TRY; TRY;
AwtContainer::ncomponentsID = env->GetFieldID(cls, "ncomponents", "I");
AwtContainer::componentID =
env->GetFieldID(cls, "component", "[Ljava/awt/Component;");
AwtContainer::layoutMgrID = AwtContainer::layoutMgrID =
env->GetFieldID(cls, "layoutMgr", "Ljava/awt/LayoutManager;"); env->GetFieldID(cls, "layoutMgr", "Ljava/awt/LayoutManager;");
AwtContainer::findComponentAtMID = AwtContainer::findComponentAtMID =
env->GetMethodID(cls, "findComponentAt", "(IIZ)Ljava/awt/Component;"); env->GetMethodID(cls, "findComponentAt", "(IIZ)Ljava/awt/Component;");
DASSERT(AwtContainer::ncomponentsID != NULL);
DASSERT(AwtContainer::componentID != NULL);
DASSERT(AwtContainer::layoutMgrID != NULL); DASSERT(AwtContainer::layoutMgrID != NULL);
DASSERT(AwtContainer::findComponentAtMID); DASSERT(AwtContainer::findComponentAtMID);
......
/* /*
* Copyright 1998-1999 Sun Microsystems, Inc. All Rights Reserved. * Copyright 1998-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
...@@ -37,8 +37,6 @@ class AwtContainer { ...@@ -37,8 +37,6 @@ class AwtContainer {
public: public:
/* java.awt.Container field ids */ /* java.awt.Container field ids */
static jfieldID ncomponentsID;
static jfieldID componentID;
static jfieldID layoutMgrID; static jfieldID layoutMgrID;
static jmethodID findComponentAtMID; static jmethodID findComponentAtMID;
......
/*
@test %I% %E%
@bug 2161766
@summary Component is missing after changing the z-order of the component & focus is not transfered in
@author Andrei Dmitriev : area=awt.container
@run main CheckZOrderChange
*/
import java.awt.*;
import java.awt.event.*;
public class CheckZOrderChange {
private static Button content[] = new Button[]{new Button("Button 1"), new Button("Button 2"), new Button("Button 3"), new Button("Button 4")};
private static Frame frame;
public static void main(String[] args) {
frame = new Frame("Test Frame");
frame.setLayout(new FlowLayout());
for (Button b: content){
frame.add(b);
}
frame.setSize(300, 300);
frame.setVisible(true);
/* INITIAL ZORDERS ARE*/
for (Button b: content){
System.out.println("frame.getComponentZOrder("+ b +") = " + frame.getComponentZOrder(b));
}
//Change the Z Order
frame.setComponentZOrder(content[0], 2);
System.out.println("ZOrder of button1 changed to 2");
if (frame.getComponentZOrder(content[0]) != 2 ||
frame.getComponentZOrder(content[1]) != 0 ||
frame.getComponentZOrder(content[2]) != 1 ||
frame.getComponentZOrder(content[3]) != 3)
{
for (Button b: content){
System.out.println("frame.getComponentZOrder("+ b +") = " + frame.getComponentZOrder(b));
}
throw new RuntimeException("TEST FAILED: getComponentZOrder did not return the correct value");
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册