提交 6b8ffb4b 编写于 作者: A alexp

6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP

Reviewed-by: rupashka
上级 2c8871ff
......@@ -4910,14 +4910,17 @@ public abstract class JComponent extends Container implements Serializable,
* Returns {@code true} if a paint triggered on a child component should cause
* painting to originate from this Component, or one of its ancestors.
* <p/>
* Calling {@link JComponent#repaint} on a Swing component will be delegated to
* the first ancestor which {@code isPaintingOrigin()} returns {@true},
* if there are any.
* Calling {@link #repaint} or {@link #paintImmediately(int, int, int, int)}
* on a Swing component will result in calling
* the {@link JComponent#paintImmediately(int, int, int, int)} method of
* the first ancestor which {@code isPaintingOrigin()} returns {@true}, if there are any.
* <p/>
* {@code JComponent} subclasses that need to be repainted when any of their
* {@code JComponent} subclasses that need to be painted when any of their
* children are repainted should override this method to return {@code true}.
*
* @return always returns {@code false}
*
* @see #paintImmediately(int, int, int, int)
*/
protected boolean isPaintingOrigin() {
return false;
......@@ -4932,12 +4935,16 @@ public abstract class JComponent extends Container implements Serializable,
* and can collapse redundant requests into a single paint call.
* This method is useful if one needs to update the display while
* the current event is being dispatched.
* <p>
* This method is to be overridden when the dirty region needs to be changed
* for components that are painting origins.
*
* @param x the x value of the region to be painted
* @param y the y value of the region to be painted
* @param w the width of the region to be painted
* @param h the height of the region to be painted
* @see #repaint
* @see #isPaintingOrigin()
*/
public void paintImmediately(int x,int y,int w, int h) {
Component c = this;
......@@ -4946,6 +4953,15 @@ public abstract class JComponent extends Container implements Serializable,
if(!isShowing()) {
return;
}
JComponent paintingOigin = SwingUtilities.getPaintingOrigin(this);
if (paintingOigin != null) {
Rectangle rectangle = SwingUtilities.convertRectangle(
c, new Rectangle(x, y, w, h), paintingOigin);
paintingOigin.paintImmediately(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
return;
}
while(!c.isOpaque()) {
parent = c.getParent();
if(parent != null) {
......
......@@ -156,8 +156,9 @@ public final class JLayer<V extends Component>
// when layerUI is serializable
private LayerUI<? super V> layerUI;
private JPanel glassPane;
private boolean isPainting;
private long eventMask;
private transient boolean isPainting;
private transient boolean isPaintingImmediately;
private static final LayerEventController eventController =
new LayerEventController();
......@@ -393,17 +394,25 @@ public final class JLayer<V extends Component>
}
/**
* Delegates repainting to {@link javax.swing.plaf.LayerUI#repaint} method.
* Delegates its functionality to the
* {@link javax.swing.plaf.LayerUI#paintImmediately(int, int, int, int, JLayer)} method,
* if {@code LayerUI} is set.
*
* @param tm this parameter is not used
* @param x the x value of the dirty region
* @param y the y value of the dirty region
* @param width the width of the dirty region
* @param height the height of the dirty region
*/
public void repaint(long tm, int x, int y, int width, int height) {
if (getUI() != null) {
getUI().repaint(tm, x, y, width, height, this);
* @param x the x value of the region to be painted
* @param y the y value of the region to be painted
* @param w the width of the region to be painted
* @param h the height of the region to be painted
*/
public void paintImmediately(int x, int y, int w, int h) {
if (!isPaintingImmediately && getUI() != null) {
isPaintingImmediately = true;
try {
getUI().paintImmediately(x, y, w, h, this);
} finally {
isPaintingImmediately = false;
}
} else {
super.paintImmediately(x, y, w, h);
}
}
......@@ -415,8 +424,11 @@ public final class JLayer<V extends Component>
public void paint(Graphics g) {
if (!isPainting) {
isPainting = true;
super.paintComponent(g);
isPainting = false;
try {
super.paintComponent(g);
} finally {
isPainting = false;
}
} else {
super.paint(g);
}
......
......@@ -438,7 +438,6 @@ public class RepaintManager
* @param y Y coordinate of the region to repaint
* @param w Width of the region to repaint
* @param h Height of the region to repaint
* @see JComponent#isPaintingOrigin()
* @see JComponent#repaint
*/
public void addDirtyRegion(JComponent c, int x, int y, int w, int h)
......@@ -448,16 +447,6 @@ public class RepaintManager
delegate.addDirtyRegion(c, x, y, w, h);
return;
}
Container p = c;
while ((p = p.getParent()) instanceof JComponent) {
JComponent jp = (JComponent) p;
if (jp.isPaintingOrigin()) {
Rectangle rectangle = SwingUtilities.convertRectangle(
c, new Rectangle(x, y, w, h), jp);
jp.repaint(0, rectangle.x, rectangle.y, rectangle.width, rectangle.height);
return;
}
}
addDirtyRegion0(c, x, y, w, h);
}
......
......@@ -1532,6 +1532,17 @@ public class SwingUtilities implements SwingConstants
return applet;
}
static JComponent getPaintingOrigin(JComponent c) {
Container p = c;
while ((p = p.getParent()) instanceof JComponent) {
JComponent jp = (JComponent) p;
if (jp.isPaintingOrigin()) {
return jp;
}
}
return null;
}
/**
* Process the key bindings for the <code>Component</code> associated with
* <code>event</code>. This method is only useful if
......
......@@ -703,21 +703,19 @@ public class LayerUI<V extends Component>
}
/**
* Adds the specified region to the dirty region list if the component
* is showing. The component will be repainted after all of the
* currently pending events have been dispatched.
* Paints the specified region in the {@code JLayer} this {@code LayerUI} is set to, immediately.
* <p/>
* This method is to be overridden when the dirty region needs to be changed.
* The default implementation delegates its functionality to {@link JComponent#paintImmediately(int, int, int, int)}.
*
* @param tm this parameter is not used
* @param x the x value of the dirty region
* @param y the y value of the dirty region
* @param width the width of the dirty region
* @param height the height of the dirty region
* @see java.awt.Component#isShowing
* @see RepaintManager#addDirtyRegion
* @param x the x value of the region to be painted
* @param y the y value of the region to be painted
* @param w the width of the region to be painted
* @param h the height of the region to be painted
*
* @see JComponent#paintImmediately(int, int, int, int)
*/
public void repaint(long tm, int x, int y, int width, int height, JLayer<? extends V> l) {
RepaintManager.currentManager(l).addDirtyRegion(l, x, y, width, height);
public void paintImmediately(int x, int y, int width, int height, JLayer<? extends V> l) {
l.paintImmediately(x, y, width, height);
}
}
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, Oracle and/or its affiliates. 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
......@@ -28,76 +28,107 @@
@run main bug6989617
*/
import sun.awt.SunToolkit;
import javax.swing.*;
import java.awt.*;
public class bug6989617 {
private static MyPanel panel;
private static JButton button;
private boolean isPaintingOrigin;
private boolean innerPanelRepainted, outerPanelRepainted;
public bug6989617() {
public static void main(String... args) throws Exception {
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JFrame frame = new JFrame();
frame. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel = new MyPanel();
final JButton button = new JButton("button");
button = new JButton("Hello");
panel.add(button);
frame.add(panel);
JPanel innerPanel = new JPanel() {
protected boolean isPaintingOrigin() {
return isPaintingOrigin;
frame.setSize(200, 300);
frame.setVisible(true);
}
public void repaint(long tm, int x, int y, int width, int height) {
if (button.getParent() != null) {
innerPanelRepainted = true;
if (!button.getSize().equals(new Dimension(width, height))) {
throw new RuntimeException("Wrong size of the dirty area");
}
if (!button.getLocation().equals(new Point(x, y))) {
throw new RuntimeException("Wrong location of the dirty area");
}
});
// Testing the panel as a painting origin,
// the panel.paintImmediately() must be triggered
// when button.repaint() is called
toolkit.realSync();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
if (panel.getPaintRectangle() != null) {
throw new RuntimeException("paint rectangle is not null");
}
super.repaint(tm, x, y, width, height);
button.repaint();
}
};
JPanel outerPanel = new JPanel() {
protected boolean isPaintingOrigin() {
return isPaintingOrigin;
});
toolkit.realSync();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
Rectangle pr = panel.getPaintRectangle();
if (!pr.getSize().equals(button.getSize())) {
throw new RuntimeException("wrong size of the dirty area");
}
if (!pr.getLocation().equals(button.getLocation())) {
throw new RuntimeException("wrong location of the dirty area");
}
}
public void repaint(long tm, int x, int y, int width, int height) {
if (button.getParent() != null) {
outerPanelRepainted = true;
if (!button.getSize().equals(new Dimension(width, height))) {
throw new RuntimeException("Wrong size of the dirty area");
}
});
// Testing the panel as NOT a painting origin
// the panel.paintImmediately() must NOT be triggered
// when button.repaint() is called
toolkit.realSync();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
panel.resetPaintRectangle();
panel.setPaintingOrigin(false);
if (panel.getPaintRectangle() != null) {
throw new RuntimeException("paint rectangle is not null");
}
button.repaint();
}
});
toolkit.realSync();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
if(panel.getPaintRectangle() != null) {
throw new RuntimeException("paint rectangle is not null");
}
super.repaint(tm, x, y, width, height);
System.out.println("Test passed...");
}
};
});
}
static class MyPanel extends JPanel {
private boolean isPaintingOrigin = true;
private Rectangle paintRectangle;
outerPanel.add(innerPanel);
innerPanel.add(button);
{
setLayout(new GridBagLayout());
}
outerPanel.setSize(100, 100);
innerPanel.setBounds(10, 10, 50, 50);
button.setBounds(10, 10, 20, 20);
public boolean isPaintingOrigin() {
return isPaintingOrigin;
}
if (innerPanelRepainted || outerPanelRepainted) {
throw new RuntimeException("Repainted flag is unexpectedly on");
public void setPaintingOrigin(boolean paintingOrigin) {
isPaintingOrigin = paintingOrigin;
}
button.repaint();
if (innerPanelRepainted || outerPanelRepainted) {
throw new RuntimeException("Repainted flag is unexpectedly on");
public void paintImmediately(int x, int y, int w, int h) {
super.paintImmediately(x, y, w, h);
paintRectangle = new Rectangle(x, y, w, h);
}
isPaintingOrigin = true;
button.repaint();
if (!innerPanelRepainted || !outerPanelRepainted) {
throw new RuntimeException("Repainted flag is unexpectedly off");
public Rectangle getPaintRectangle() {
return paintRectangle == null? null: new Rectangle(paintRectangle);
}
}
public static void main(String... args) throws Exception {
new bug6989617();
public void resetPaintRectangle() {
this.paintRectangle = null;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册