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