提交 6ea83095 编写于 作者: D dav

6616323: consider benefits of replacing a componen array with other collection...

6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
Reviewed-by: uta, art
上级 1896053f
......@@ -2141,7 +2141,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
Toolkit.getEventQueue().postEvent(e);
}
} else {
if (this instanceof Container && ((Container)this).ncomponents > 0) {
if (this instanceof Container && ((Container)this).countComponents() > 0) {
boolean enabledOnToolkit =
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK);
if (resized) {
......
......@@ -357,7 +357,7 @@ public class ScrollPane extends Container implements Accessible {
*/
public void setScrollPosition(int x, int y) {
synchronized (getTreeLock()) {
if (ncomponents <= 0) {
if (getComponentCount()==0) {
throw new NullPointerException("child is null");
}
hAdjustable.setValue(x);
......@@ -393,10 +393,12 @@ public class ScrollPane extends Container implements Accessible {
*/
@Transient
public Point getScrollPosition() {
if (ncomponents <= 0) {
throw new NullPointerException("child is null");
synchronized (getTreeLock()) {
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 {
*/
@Deprecated
public void layout() {
if (ncomponents > 0) {
Component c = getComponent(0);
Point p = getScrollPosition();
Dimension cs = calculateChildSize();
Dimension vs = getViewportSize();
Insets i = getInsets();
c.reshape(i.left - p.x, i.top - p.y, cs.width, cs.height);
ScrollPanePeer peer = (ScrollPanePeer)this.peer;
if (peer != null) {
peer.childResized(cs.width, cs.height);
}
if (getComponentCount()==0) {
return;
}
Component c = getComponent(0);
Point p = getScrollPosition();
Dimension cs = calculateChildSize();
Dimension vs = getViewportSize();
Insets i = getInsets();
// 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);
c.reshape(i.left - p.x, i.top - p.y, cs.width, cs.height);
ScrollPanePeer peer = (ScrollPanePeer)this.peer;
if (peer != null) {
peer.childResized(cs.width, cs.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 {
* @see Component#printAll
*/
public void printComponents(Graphics g) {
if (ncomponents > 0) {
Component c = component[0];
Point p = c.getLocation();
Dimension vs = getViewportSize();
Insets i = getInsets();
Graphics cg = g.create();
try {
cg.clipRect(i.left, i.top, vs.width, vs.height);
cg.translate(p.x, p.y);
c.printAll(cg);
} finally {
cg.dispose();
}
if (getComponentCount()==0) {
return;
}
Component c = getComponent(0);
Point p = c.getLocation();
Dimension vs = getViewportSize();
Insets i = getInsets();
Graphics cg = g.create();
try {
cg.clipRect(i.left, i.top, vs.width, vs.height);
cg.translate(p.x, p.y);
c.printAll(cg);
} finally {
cg.dispose();
}
}
......@@ -589,7 +593,7 @@ public class ScrollPane extends Container implements Accessible {
default:
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();
return super.paramString()+",ScrollPosition=("+p.x+","+p.y+")"+
",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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -30,8 +30,6 @@
* AwtContainer fields
*/
jfieldID AwtContainer::ncomponentsID;
jfieldID AwtContainer::componentID;
jfieldID AwtContainer::layoutMgrID;
jmethodID AwtContainer::findComponentAtMID;
......@@ -45,18 +43,12 @@ JNIEXPORT void JNICALL
Java_java_awt_Container_initIDs(JNIEnv *env, jclass cls) {
TRY;
AwtContainer::ncomponentsID = env->GetFieldID(cls, "ncomponents", "I");
AwtContainer::componentID =
env->GetFieldID(cls, "component", "[Ljava/awt/Component;");
AwtContainer::layoutMgrID =
env->GetFieldID(cls, "layoutMgr", "Ljava/awt/LayoutManager;");
AwtContainer::findComponentAtMID =
env->GetMethodID(cls, "findComponentAt", "(IIZ)Ljava/awt/Component;");
DASSERT(AwtContainer::ncomponentsID != NULL);
DASSERT(AwtContainer::componentID != NULL);
DASSERT(AwtContainer::layoutMgrID != NULL);
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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -37,8 +37,6 @@ class AwtContainer {
public:
/* java.awt.Container field ids */
static jfieldID ncomponentsID;
static jfieldID componentID;
static jfieldID layoutMgrID;
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.
先完成此消息的编辑!
想要评论请 注册