提交 733d83ee 编写于 作者: A alexp

7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value

Reviewed-by: anthony
上级 6c523868
...@@ -27,7 +27,8 @@ package javax.swing; ...@@ -27,7 +27,8 @@ package javax.swing;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Vector; import java.util.Collection;
import java.util.Iterator;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.accessibility.*; import javax.accessibility.*;
...@@ -42,7 +43,6 @@ import java.io.IOException; ...@@ -42,7 +43,6 @@ import java.io.IOException;
import java.beans.PropertyVetoException; import java.beans.PropertyVetoException;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
/** /**
* A container used to create a multiple-document interface or a virtual desktop. * A container used to create a multiple-document interface or a virtual desktop.
* You create <code>JInternalFrame</code> objects and add them to the * You create <code>JInternalFrame</code> objects and add them to the
...@@ -261,25 +261,26 @@ public class JDesktopPane extends JLayeredPane implements Accessible ...@@ -261,25 +261,26 @@ public class JDesktopPane extends JLayeredPane implements Accessible
* @return an array of <code>JInternalFrame</code> objects * @return an array of <code>JInternalFrame</code> objects
*/ */
public JInternalFrame[] getAllFrames() { public JInternalFrame[] getAllFrames() {
return getAllFrames(this).toArray(new JInternalFrame[0]);
}
private static Collection<JInternalFrame> getAllFrames(Container parent) {
int i, count; int i, count;
JInternalFrame[] results; Collection<JInternalFrame> results = new ArrayList<JInternalFrame>();
Vector<JInternalFrame> vResults = new Vector<JInternalFrame>(10); count = parent.getComponentCount();
for (i = 0; i < count; i++) {
count = getComponentCount(); Component next = parent.getComponent(i);
for(i = 0; i < count; i++) { if (next instanceof JInternalFrame) {
Component next = getComponent(i); results.add((JInternalFrame) next);
if(next instanceof JInternalFrame) } else if (next instanceof JInternalFrame.JDesktopIcon) {
vResults.addElement((JInternalFrame) next); JInternalFrame tmp = ((JInternalFrame.JDesktopIcon) next).getInternalFrame();
else if(next instanceof JInternalFrame.JDesktopIcon) { if (tmp != null) {
JInternalFrame tmp = ((JInternalFrame.JDesktopIcon)next).getInternalFrame(); results.add(tmp);
if(tmp != null) }
vResults.addElement(tmp); } else if (next instanceof Container) {
results.addAll(getAllFrames((Container) next));
} }
} }
results = new JInternalFrame[vResults.size()];
vResults.copyInto(results);
return results; return results;
} }
...@@ -322,27 +323,14 @@ public class JDesktopPane extends JLayeredPane implements Accessible ...@@ -322,27 +323,14 @@ public class JDesktopPane extends JLayeredPane implements Accessible
* @see JLayeredPane * @see JLayeredPane
*/ */
public JInternalFrame[] getAllFramesInLayer(int layer) { public JInternalFrame[] getAllFramesInLayer(int layer) {
int i, count; Collection<JInternalFrame> allFrames = getAllFrames(this);
JInternalFrame[] results; Iterator<JInternalFrame> iterator = allFrames.iterator();
Vector<JInternalFrame> vResults = new Vector<JInternalFrame>(10); while (iterator.hasNext()) {
if (iterator.next().getLayer() != layer) {
count = getComponentCount(); iterator.remove();
for(i = 0; i < count; i++) {
Component next = getComponent(i);
if(next instanceof JInternalFrame) {
if(((JInternalFrame)next).getLayer() == layer)
vResults.addElement((JInternalFrame) next);
} else if(next instanceof JInternalFrame.JDesktopIcon) {
JInternalFrame tmp = ((JInternalFrame.JDesktopIcon)next).getInternalFrame();
if(tmp != null && tmp.getLayer() == layer)
vResults.addElement(tmp);
} }
} }
return allFrames.toArray(new JInternalFrame[0]);
results = new JInternalFrame[vResults.size()];
vResults.copyInto(results);
return results;
} }
private List<JInternalFrame> getFrames() { private List<JInternalFrame> getFrames() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册