提交 7216d912 编写于 作者: S serb

6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails

Reviewed-by: art, dcherepanov, anthony
上级 99bc636c
...@@ -33,12 +33,9 @@ import java.awt.event.ActionEvent; ...@@ -33,12 +33,9 @@ import java.awt.event.ActionEvent;
import javax.swing.plaf.basic.*; import javax.swing.plaf.basic.*;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
public class XButtonPeer extends XComponentPeer implements ButtonPeer { public class XButtonPeer extends XComponentPeer implements ButtonPeer {
private boolean pressed;
boolean pressed; private boolean armed;
boolean armed;
private Insets focusInsets; private Insets focusInsets;
private Insets borderInsets; private Insets borderInsets;
private Insets contentAreaInsets; private Insets contentAreaInsets;
...@@ -86,11 +83,6 @@ public class XButtonPeer extends XComponentPeer implements ButtonPeer { ...@@ -86,11 +83,6 @@ public class XButtonPeer extends XComponentPeer implements ButtonPeer {
this.label = label; this.label = label;
repaint(); repaint();
} }
public void paint(Graphics g) {
paint(g,target);
}
public void setBackground(Color c) { public void setBackground(Color c) {
updateMotifColors(c); updateMotifColors(c);
super.setBackground(c); super.setBackground(c);
...@@ -133,16 +125,10 @@ public class XButtonPeer extends XComponentPeer implements ButtonPeer { ...@@ -133,16 +125,10 @@ public class XButtonPeer extends XComponentPeer implements ButtonPeer {
case MouseEvent.MOUSE_ENTERED: case MouseEvent.MOUSE_ENTERED:
if (pressed) if (pressed)
armed = true; armed = true;
// repaint();
break; break;
case MouseEvent.MOUSE_EXITED: case MouseEvent.MOUSE_EXITED:
armed = false; armed = false;
// repaint();
break; break;
} }
} }
...@@ -209,18 +195,14 @@ public class XButtonPeer extends XComponentPeer implements ButtonPeer { ...@@ -209,18 +195,14 @@ public class XButtonPeer extends XComponentPeer implements ButtonPeer {
public Dimension minimumSize() { public Dimension minimumSize() {
return getMinimumSize(); return getMinimumSize();
} }
/**
* This method is called from Toolkit Thread and so it should not call any
/* * client code.
This method is called from Toolkit Thread and so it should not call any client code
*/ */
public void paint(Graphics g, Component c) @Override
{ void paintPeer(final Graphics g) {
if (!disposed && (g != null)) if (!disposed) {
{
Dimension size = getPeerSize(); Dimension size = getPeerSize();
g.setColor( getPeerBackground() ); /* erase the existing button remains */ g.setColor( getPeerBackground() ); /* erase the existing button remains */
g.fillRect(0,0, size.width , size.height); g.fillRect(0,0, size.width , size.height);
paintBorder(g,borderInsets.left, paintBorder(g,borderInsets.left,
...@@ -239,11 +221,9 @@ public class XButtonPeer extends XComponentPeer implements ButtonPeer { ...@@ -239,11 +221,9 @@ public class XButtonPeer extends XComponentPeer implements ButtonPeer {
viewRect.width = size.width - (contentAreaInsets.left+contentAreaInsets.right); viewRect.width = size.width - (contentAreaInsets.left+contentAreaInsets.right);
viewRect.height = size.height - (contentAreaInsets.top+contentAreaInsets.bottom); viewRect.height = size.height - (contentAreaInsets.top+contentAreaInsets.bottom);
viewRect.x = contentAreaInsets.left; viewRect.x = contentAreaInsets.left;
viewRect.y = contentAreaInsets.right; viewRect.y = contentAreaInsets.top;
String llabel = (label != null) ? label : ""; String llabel = (label != null) ? label : "";
// layout the text and icon // layout the text and icon
String text = SwingUtilities.layoutCompoundLabel( String text = SwingUtilities.layoutCompoundLabel(
fm, llabel, null, fm, llabel, null,
...@@ -309,10 +289,9 @@ public class XButtonPeer extends XComponentPeer implements ButtonPeer { ...@@ -309,10 +289,9 @@ public class XButtonPeer extends XComponentPeer implements ButtonPeer {
else { else {
/*** paint the text disabled ***/ /*** paint the text disabled ***/
g.setColor(getPeerBackground().brighter()); g.setColor(getPeerBackground().brighter());
BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex, BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
textRect.x, textRect.y + fm.getAscent()); textRect.x, textRect.y + fm.getAscent());
g.setColor(c.getBackground().darker()); g.setColor(getPeerBackground().darker());
BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex, BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
textRect.x - 1, textRect.y + fm.getAscent() - 1); textRect.x - 1, textRect.y + fm.getAscent() - 1);
} }
......
...@@ -297,19 +297,15 @@ class XCheckboxPeer extends XComponentPeer implements CheckboxPeer { ...@@ -297,19 +297,15 @@ class XCheckboxPeer extends XComponentPeer implements CheckboxPeer {
double fsize = (double) checkBoxSize; double fsize = (double) checkBoxSize;
myCheckMark = AffineTransform.getScaleInstance(fsize / MASTER_SIZE, fsize / MASTER_SIZE).createTransformedShape(MASTER_CHECKMARK); myCheckMark = AffineTransform.getScaleInstance(fsize / MASTER_SIZE, fsize / MASTER_SIZE).createTransformedShape(MASTER_CHECKMARK);
} }
@Override
public void paint(Graphics g) { void paintPeer(final Graphics g) {
if (g != null) {
//layout(); //layout();
Dimension size = getPeerSize(); Dimension size = getPeerSize();
Font f = getPeerFont(); Font f = getPeerFont();
flush(); flush();
g.setColor(getPeerBackground()); // erase the existing button g.setColor(getPeerBackground()); // erase the existing button
g.fillRect(0,0, size.width, size.height); g.fillRect(0,0, size.width, size.height);
if (label != null) { if (label != null) {
g.setFont(f); g.setFont(f);
paintText(g, textRect, label); paintText(g, textRect, label);
...@@ -322,7 +318,6 @@ class XCheckboxPeer extends XComponentPeer implements CheckboxPeer { ...@@ -322,7 +318,6 @@ class XCheckboxPeer extends XComponentPeer implements CheckboxPeer {
focusRect.width, focusRect.width,
focusRect.height); focusRect.height);
} }
// Paint the checkbox or radio button // Paint the checkbox or radio button
if (checkBoxGroup == null) { if (checkBoxGroup == null) {
paintCheckbox(g, cbX, cbY, checkBoxSize, checkBoxSize); paintCheckbox(g, cbX, cbY, checkBoxSize, checkBoxSize);
...@@ -330,8 +325,6 @@ class XCheckboxPeer extends XComponentPeer implements CheckboxPeer { ...@@ -330,8 +325,6 @@ class XCheckboxPeer extends XComponentPeer implements CheckboxPeer {
else { else {
paintRadioButton(g, cbX, cbY, checkBoxSize, checkBoxSize); paintRadioButton(g, cbX, cbY, checkBoxSize, checkBoxSize);
} }
}
flush(); flush();
} }
......
...@@ -550,10 +550,10 @@ public class XChoicePeer extends XComponentPeer implements ChoicePeer, ToplevelS ...@@ -550,10 +550,10 @@ public class XChoicePeer extends XComponentPeer implements ChoicePeer, ToplevelS
/** /**
* Paint the choice * Paint the choice
*/ */
public void paint(Graphics g) { @Override
void paintPeer(final Graphics g) {
flush(); flush();
Dimension size = getPeerSize(); Dimension size = getPeerSize();
// TODO: when mouse is down over button, widget should be drawn depressed // TODO: when mouse is down over button, widget should be drawn depressed
g.setColor(getPeerBackground()); g.setColor(getPeerBackground());
g.fillRect(0, 0, width, height); g.fillRect(0, 0, width, height);
...@@ -912,16 +912,22 @@ public class XChoicePeer extends XComponentPeer implements ChoicePeer, ToplevelS ...@@ -912,16 +912,22 @@ public class XChoicePeer extends XComponentPeer implements ChoicePeer, ToplevelS
/* /*
* fillRect with current Background color on the whole dropdown list. * fillRect with current Background color on the whole dropdown list.
*/ */
public void paintBackground(){ public void paintBackground() {
Graphics g = getGraphics(); final Graphics g = getGraphics();
if (g != null) {
try {
g.setColor(getPeerBackground()); g.setColor(getPeerBackground());
g.fillRect(0, 0, width, height); g.fillRect(0, 0, width, height);
} finally {
g.dispose();
}
}
} }
/* /*
* 6405689. In some cases we should erase background to eliminate painting * 6405689. In some cases we should erase background to eliminate painting
* artefacts. * artefacts.
*/ */
@Override
public void repaint() { public void repaint() {
if (!isVisible()) { if (!isVisible()) {
return; return;
...@@ -931,8 +937,8 @@ public class XChoicePeer extends XComponentPeer implements ChoicePeer, ToplevelS ...@@ -931,8 +937,8 @@ public class XChoicePeer extends XComponentPeer implements ChoicePeer, ToplevelS
} }
super.repaint(); super.repaint();
} }
@Override
public void paint(Graphics g) { public void paintPeer(Graphics g) {
//System.out.println("UC.paint()"); //System.out.println("UC.paint()");
Choice choice = (Choice)target; Choice choice = (Choice)target;
Color colors[] = XChoicePeer.this.getGUIcolors(); Color colors[] = XChoicePeer.this.getGUIcolors();
......
...@@ -38,7 +38,6 @@ import java.awt.Graphics; ...@@ -38,7 +38,6 @@ import java.awt.Graphics;
import java.awt.GraphicsConfiguration; import java.awt.GraphicsConfiguration;
import java.awt.Image; import java.awt.Image;
import java.awt.Insets; import java.awt.Insets;
import java.awt.KeyboardFocusManager;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.SystemColor; import java.awt.SystemColor;
import java.awt.Toolkit; import java.awt.Toolkit;
...@@ -59,15 +58,11 @@ import java.awt.image.ImageProducer; ...@@ -59,15 +58,11 @@ import java.awt.image.ImageProducer;
import java.awt.image.VolatileImage; import java.awt.image.VolatileImage;
import java.awt.peer.ComponentPeer; import java.awt.peer.ComponentPeer;
import java.awt.peer.ContainerPeer; import java.awt.peer.ContainerPeer;
import java.awt.peer.LightweightPeer;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.security.*; import java.security.*;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.Vector;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
import sun.awt.*; import sun.awt.*;
import sun.awt.event.IgnorePaintEvent; import sun.awt.event.IgnorePaintEvent;
import sun.awt.image.SunVolatileImage; import sun.awt.image.SunVolatileImage;
...@@ -428,27 +423,23 @@ public class XComponentPeer extends XWindow implements ComponentPeer, DropTarget ...@@ -428,27 +423,23 @@ public class XComponentPeer extends XWindow implements ComponentPeer, DropTarget
public void disable() { public void disable() {
setEnabled(false); setEnabled(false);
} }
@Override
public void paint(Graphics g) { public void paint(final Graphics g) {
} super.paint(g);
public void repaint(long tm, int x, int y, int width, int height) { // allow target to change the picture
repaint(); target.paint(g);
} }
public Graphics getGraphics() { public Graphics getGraphics() {
return getGraphics(surfaceData, getPeerForeground(), getPeerBackground(), getPeerFont()); return getGraphics(surfaceData, getPeerForeground(), getPeerBackground(), getPeerFont());
} }
public void print(Graphics g) { public void print(Graphics g) {
// clear rect here to emulate X clears rect before Expose // clear rect here to emulate X clears rect before Expose
g.setColor(target.getBackground()); g.setColor(target.getBackground());
g.fillRect(0, 0, target.getWidth(), target.getHeight()); g.fillRect(0, 0, target.getWidth(), target.getHeight());
g.setColor(target.getForeground()); g.setColor(target.getForeground());
// paint peer // paint peer
paint(g); paintPeer(g);
// allow target to change the picture // allow target to change the picture
target.print(g); target.print(g);
} }
......
...@@ -85,7 +85,8 @@ class XLabelPeer extends XComponentPeer implements LabelPeer { ...@@ -85,7 +85,8 @@ class XLabelPeer extends XComponentPeer implements LabelPeer {
*/ */
// NOTE: This method is called by privileged threads. // NOTE: This method is called by privileged threads.
// DO NOT INVOKE CLIENT CODE ON THIS THREAD! // DO NOT INVOKE CLIENT CODE ON THIS THREAD!
public void paint(Graphics g) { @Override
void paintPeer(final Graphics g) {
int textX = 0; int textX = 0;
int textY = 0; int textY = 0;
g.setColor(getPeerBackground()); g.setColor(getPeerBackground());
......
...@@ -363,9 +363,7 @@ class XListPeer extends XComponentPeer implements ListPeer, XScrollbarClient { ...@@ -363,9 +363,7 @@ class XListPeer extends XComponentPeer implements ListPeer, XScrollbarClient {
return Math.min(items.size()-1, itemsInWindow()-1); return Math.min(items.size()-1, itemsInWindow()-1);
} }
} }
public void repaintScrollbarRequest(XScrollbar scrollbar) { public void repaintScrollbarRequest(XScrollbar scrollbar) {
Graphics g = getGraphics();
if (scrollbar == hsb) { if (scrollbar == hsb) {
repaint(PAINT_HSCROLL); repaint(PAINT_HSCROLL);
} }
...@@ -373,9 +371,6 @@ class XListPeer extends XComponentPeer implements ListPeer, XScrollbarClient { ...@@ -373,9 +371,6 @@ class XListPeer extends XComponentPeer implements ListPeer, XScrollbarClient {
repaint(PAINT_VSCROLL); repaint(PAINT_VSCROLL);
} }
} }
/** /**
* Overridden for performance * Overridden for performance
*/ */
...@@ -410,18 +405,20 @@ class XListPeer extends XComponentPeer implements ListPeer, XScrollbarClient { ...@@ -410,18 +405,20 @@ class XListPeer extends XComponentPeer implements ListPeer, XScrollbarClient {
* @param distance the distance to copy the source area * @param distance the distance to copy the source area
*/ */
private void repaint(int firstItem, int lastItem, int options, Rectangle source, Point distance) { private void repaint(int firstItem, int lastItem, int options, Rectangle source, Point distance) {
Graphics g = getGraphics(); final Graphics g = getGraphics();
if (g != null) {
try { try {
painter.paint(g, firstItem, lastItem, options, source, distance); painter.paint(g, firstItem, lastItem, options, source, distance);
target.paint(g);
} finally { } finally {
g.dispose(); g.dispose();
} }
} }
}
public void paint(Graphics g) { @Override
void paintPeer(final Graphics g) {
painter.paint(g, getFirstVisibleItem(), getLastVisibleItem(), PAINT_ALL); painter.paint(g, getFirstVisibleItem(), getLastVisibleItem(), PAINT_ALL);
} }
public boolean isFocusable() { return true; } public boolean isFocusable() { return true; }
// TODO: share/promote the Focus methods? // TODO: share/promote the Focus methods?
......
...@@ -415,7 +415,7 @@ public class XMenuBarPeer extends XBaseMenuWindow implements MenuBarPeer { ...@@ -415,7 +415,7 @@ public class XMenuBarPeer extends XBaseMenuWindow implements MenuBarPeer {
* Overriden XWindow painting & printing * Overriden XWindow painting & printing
* *
************************************************/ ************************************************/
public void paint(Graphics g) { public void paintPeer(Graphics g) {
resetColors(); resetColors();
/* Calculate menubar dimension. */ /* Calculate menubar dimension. */
int width = getWidth(); int width = getWidth();
......
...@@ -432,9 +432,9 @@ public class XMenuWindow extends XBaseMenuWindow { ...@@ -432,9 +432,9 @@ public class XMenuWindow extends XBaseMenuWindow {
/** /**
* Paints menu window * Paints menu window
*/ */
public void paint(Graphics g) { @Override
public void paintPeer(Graphics g) {
resetColors(); resetColors();
int width = getWidth(); int width = getWidth();
int height = getHeight(); int height = getHeight();
......
...@@ -60,14 +60,13 @@ public class XPanelPeer extends XCanvasPeer implements PanelPeer { ...@@ -60,14 +60,13 @@ public class XPanelPeer extends XCanvasPeer implements PanelPeer {
public Insets getInsets() { public Insets getInsets() {
return new Insets(0, 0, 0, 0); return new Insets(0, 0, 0, 0);
} }
public void paint(Graphics g) { public void paint(Graphics g) {
super.paint(g); super.paint(g);
/* SunGraphicsCallback.PaintHeavyweightComponentsCallback.getInstance(). SunGraphicsCallback.PaintHeavyweightComponentsCallback.getInstance().
runComponents(((Container)target).getComponents(), g, runComponents(((Container)target).getComponents(), g,
SunGraphicsCallback.LIGHTWEIGHTS | SunGraphicsCallback.LIGHTWEIGHTS |
SunGraphicsCallback.HEAVYWEIGHTS); SunGraphicsCallback.HEAVYWEIGHTS);
*/ } }
public void print(Graphics g) { public void print(Graphics g) {
super.print(g); super.print(g);
SunGraphicsCallback.PrintHeavyweightComponentsCallback.getInstance(). SunGraphicsCallback.PrintHeavyweightComponentsCallback.getInstance().
......
...@@ -53,9 +53,9 @@ class XRepaintArea extends RepaintArea { ...@@ -53,9 +53,9 @@ class XRepaintArea extends RepaintArea {
*/ */
protected void updateComponent(Component comp, Graphics g) { protected void updateComponent(Component comp, Graphics g) {
if (comp != null) { if (comp != null) {
ComponentPeer peer = comp.getPeer(); final XComponentPeer peer = (XComponentPeer) comp.getPeer();
if (peer != null) { if (peer != null) {
peer.paint(g); peer.paintPeer(g);
} }
super.updateComponent(comp, g); super.updateComponent(comp, g);
} }
...@@ -66,9 +66,9 @@ class XRepaintArea extends RepaintArea { ...@@ -66,9 +66,9 @@ class XRepaintArea extends RepaintArea {
*/ */
protected void paintComponent(Component comp, Graphics g) { protected void paintComponent(Component comp, Graphics g) {
if (comp != null) { if (comp != null) {
ComponentPeer peer = comp.getPeer(); final XComponentPeer peer = (XComponentPeer) comp.getPeer();
if (peer != null) { if (peer != null) {
peer.paint(g); peer.paintPeer(g);
} }
super.paintComponent(comp, g); super.paintComponent(comp, g);
} }
......
...@@ -293,18 +293,21 @@ class XScrollPanePeer extends XComponentPeer implements ScrollPanePeer, XScrollb ...@@ -293,18 +293,21 @@ class XScrollPanePeer extends XComponentPeer implements ScrollPanePeer, XScrollb
setAdjustableValue(hadj, hsb.getValue(), type); setAdjustableValue(hadj, hsb.getValue(), type);
sx = -(hsb.getValue()); sx = -(hsb.getValue());
Graphics g = getGraphics(); Graphics g = getGraphics();
if (g != null) {
try { try {
paintHorScrollbar(g, colors, true); paintHorScrollbar(g, colors, true);
} finally { } finally {
g.dispose(); g.dispose();
} }
} }
}
if ((flag & VERTICAL) != 0) { if ((flag & VERTICAL) != 0) {
vsb.setValue(Math.min(y, vsb.getMaximum() - vsb.getVisibleAmount())); vsb.setValue(Math.min(y, vsb.getMaximum() - vsb.getVisibleAmount()));
ScrollPaneAdjustable vadj = (ScrollPaneAdjustable)sp.getVAdjustable(); ScrollPaneAdjustable vadj = (ScrollPaneAdjustable)sp.getVAdjustable();
setAdjustableValue(vadj, vsb.getValue(), type); setAdjustableValue(vadj, vsb.getValue(), type);
sy = -(vsb.getValue()); sy = -(vsb.getValue());
Graphics g = getGraphics(); Graphics g = getGraphics();
if (g != null) {
try { try {
paintVerScrollbar(g, colors, true); paintVerScrollbar(g, colors, true);
} finally { } finally {
...@@ -312,6 +315,7 @@ class XScrollPanePeer extends XComponentPeer implements ScrollPanePeer, XScrollb ...@@ -312,6 +315,7 @@ class XScrollPanePeer extends XComponentPeer implements ScrollPanePeer, XScrollb
} }
} }
} }
}
c.move(sx, sy); c.move(sx, sy);
} }
...@@ -327,14 +331,21 @@ class XScrollPanePeer extends XComponentPeer implements ScrollPanePeer, XScrollb ...@@ -327,14 +331,21 @@ class XScrollPanePeer extends XComponentPeer implements ScrollPanePeer, XScrollb
ite.getCause().printStackTrace(); ite.getCause().printStackTrace();
} }
} }
@Override
void paintPeer(final Graphics g) {
public void paint(Graphics g) { final Color[] colors = getGUIcolors();
paintComponent(g); g.setColor(colors[BACKGROUND_COLOR]);
final int h = height - hsbSpace;
final int w = width - vsbSpace;
g.fillRect(0, 0, w, h);
// paint rectangular region between scrollbars
g.fillRect(w, h, vsbSpace, hsbSpace);
if (MARGIN > 0) {
draw3DRect(g, colors, 0, 0, w - 1, h - 1, false);
} }
paintScrollBars(g, colors);
}
void paintScrollBars(Graphics g, Color[] colors) { private void paintScrollBars(Graphics g, Color[] colors) {
if (vsbSpace > 0) { if (vsbSpace > 0) {
paintVerScrollbar(g, colors, true); paintVerScrollbar(g, colors, true);
// paint the whole scrollbar // paint the whole scrollbar
...@@ -345,51 +356,32 @@ class XScrollPanePeer extends XComponentPeer implements ScrollPanePeer, XScrollb ...@@ -345,51 +356,32 @@ class XScrollPanePeer extends XComponentPeer implements ScrollPanePeer, XScrollb
// paint the whole scrollbar // paint the whole scrollbar
} }
} }
void repaintScrollBars() { void repaintScrollBars() {
Graphics g = getGraphics(); Graphics g = getGraphics();
Color colors[] = getGUIcolors(); Color colors[] = getGUIcolors();
if (g != null) { if (g != null) {
paintScrollBars(g,colors); try {
} paintScrollBars(g, colors);
} finally {
g.dispose(); g.dispose();
} }
}
}
public void repaintScrollbarRequest(XScrollbar sb) { public void repaintScrollbarRequest(XScrollbar sb) {
Graphics g = getGraphics(); Graphics g = getGraphics();
Color colors[] = getGUIcolors(); Color colors[] = getGUIcolors();
if (g != null) { if (g != null) {
try {
if (sb == vsb) { if (sb == vsb) {
paintVerScrollbar(g,colors,true); paintVerScrollbar(g, colors, true);
} else if (sb == hsb) {
paintHorScrollbar(g, colors, true);
} }
else if (sb == hsb) { } finally {
paintHorScrollbar(g,colors,true); g.dispose();
} }
} }
} }
/**
* Paint the scrollpane.
*/
public void paintComponent(Graphics g) {
Color colors[] = getGUIcolors();
g.setColor(colors[BACKGROUND_COLOR]);
int h = height - hsbSpace;
int w = width - vsbSpace;
g.fillRect(0, 0, w, h);
// paint rectangular region between scrollbars
g.fillRect(w, h, vsbSpace, hsbSpace);
if (MARGIN > 0) {
draw3DRect(g, colors, 0, 0, w - 1, h - 1, false);
}
paintScrollBars(g,colors);
}
public void handleEvent(java.awt.AWTEvent e) { public void handleEvent(java.awt.AWTEvent e) {
super.handleEvent(e); super.handleEvent(e);
......
...@@ -90,18 +90,12 @@ class XScrollbarPeer extends XComponentPeer implements ScrollbarPeer, XScrollbar ...@@ -90,18 +90,12 @@ class XScrollbarPeer extends XComponentPeer implements ScrollbarPeer, XScrollbar
? new Dimension(getDefaultDimension(), DEFAULT_LENGTH) ? new Dimension(getDefaultDimension(), DEFAULT_LENGTH)
: new Dimension(DEFAULT_LENGTH, getDefaultDimension()); : new Dimension(DEFAULT_LENGTH, getDefaultDimension());
} }
public void repaint() {
Graphics g = getGraphics();
if (g != null) paint(g);
}
/** /**
* Paint the scrollbar. * Paint the scrollbar.
*/ */
public void paint(Graphics g) { @Override
Scrollbar sb = (Scrollbar)target; void paintPeer(final Graphics g) {
Color colors[] = getGUIcolors(); final Color[] colors = getGUIcolors();
g.setColor(colors[BACKGROUND_COLOR]); g.setColor(colors[BACKGROUND_COLOR]);
tsb.paint(g, colors, true); tsb.paint(g, colors, true);
// paint the whole scrollbar // paint the whole scrollbar
......
...@@ -298,15 +298,14 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { ...@@ -298,15 +298,14 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer {
* Paint the component * Paint the component
* this method is called when the repaint instruction has been used * this method is called when the repaint instruction has been used
*/ */
public void repaint() { public void repaint() {
if (textPane != null) { if (textPane != null) {
//textPane.validate(); //textPane.validate();
textPane.repaint(); textPane.repaint();
} }
} }
@Override
public void paint(Graphics g) { void paintPeer(final Graphics g) {
if (textPane != null) { if (textPane != null) {
textPane.paint(g); textPane.paint(g);
} }
......
...@@ -370,12 +370,11 @@ public class XTextFieldPeer extends XComponentPeer implements TextFieldPeer { ...@@ -370,12 +370,11 @@ public class XTextFieldPeer extends XComponentPeer implements TextFieldPeer {
public void repaint() { public void repaint() {
if (xtext != null) xtext.repaint(); if (xtext != null) xtext.repaint();
} }
@Override
public void paint(Graphics g) { void paintPeer(final Graphics g) {
if (xtext != null) xtext.paint(g); if (xtext != null) xtext.paint(g);
} }
public void print(Graphics g) { public void print(Graphics g) {
if (xtext != null) { if (xtext != null) {
xtext.print(g); xtext.print(g);
......
...@@ -241,16 +241,19 @@ class XWarningWindow extends XWindow { ...@@ -241,16 +241,19 @@ class XWarningWindow extends XWindow {
Font getFont () { Font getFont () {
return ownerWindow.getFont(); return ownerWindow.getFont();
} }
@Override
public void repaint() { public void repaint() {
Rectangle bounds = getBounds(); final Rectangle bounds = getBounds();
Graphics g = getGraphics(); final Graphics g = getGraphics();
if (g != null) {
try { try {
paint(g, 0, 0, bounds.width, bounds.height); paint(g, 0, 0, bounds.width, bounds.height);
} finally { } finally {
g.dispose(); g.dispose();
} }
} }
}
@Override @Override
public void handleExposeEvent(XEvent xev) { public void handleExposeEvent(XEvent xev) {
super.handleExposeEvent(xev); super.handleExposeEvent(xev);
...@@ -263,13 +266,15 @@ class XWarningWindow extends XWindow { ...@@ -263,13 +266,15 @@ class XWarningWindow extends XWindow {
SunToolkit.executeOnEventHandlerThread(target, SunToolkit.executeOnEventHandlerThread(target,
new Runnable() { new Runnable() {
public void run() { public void run() {
Graphics g = getGraphics(); final Graphics g = getGraphics();
if (g != null) {
try { try {
paint(g, x, y, width, height); paint(g, x, y, width, height);
} finally { } finally {
g.dispose(); g.dispose();
} }
} }
}
}); });
} }
......
...@@ -502,9 +502,8 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { ...@@ -502,9 +502,8 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
public boolean isEmbedded() { public boolean isEmbedded() {
return embedded; return embedded;
} }
public void repaint(int x,int y, int width, int height) { public void repaint(int x,int y, int width, int height) {
if (!isVisible()) { if (!isVisible() || getWidth() == 0 || getHeight() == 0) {
return; return;
} }
Graphics g = getGraphics(); Graphics g = getGraphics();
...@@ -517,12 +516,11 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { ...@@ -517,12 +516,11 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
} }
} }
} }
void repaint() {
public void repaint() { if (!isVisible() || getWidth() == 0 || getHeight() == 0) {
if (!isVisible()) {
return; return;
} }
Graphics g = getGraphics(); final Graphics g = getGraphics();
if (g != null) { if (g != null) {
try { try {
paint(g); paint(g);
...@@ -531,10 +529,13 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { ...@@ -531,10 +529,13 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
} }
} }
} }
public void paint(final Graphics g) {
void paint(Graphics g) { // paint peer
paintPeer(g);
} }
void paintPeer(final Graphics g) {
}
//used by Peers to avoid flickering withing paint() //used by Peers to avoid flickering withing paint()
protected void flush(){ protected void flush(){
XToolkit.awtLock(); XToolkit.awtLock();
......
/*
* 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import sun.awt.SunToolkit;
import java.awt.Button;
import java.awt.Canvas;
import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.List;
import java.awt.Panel;
import java.awt.ScrollPane;
import java.awt.Scrollbar;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
/*
@test
@bug 6596915
@summary Test Component.paintAll() method
@author sergey.bylokhov@oracle.com: area=awt.component
@run main PaintAll
*/
public class PaintAll {
private static volatile boolean lwPainted;
private static volatile boolean buttonPainted;
private static volatile boolean canvasPainted;
private static volatile boolean checkboxPainted;
private static volatile boolean choicePainted;
private static volatile boolean containerPainted;
private static volatile boolean framePainted;
private static volatile boolean labelPainted;
private static volatile boolean listPainted;
private static volatile boolean panelPainted;
private static volatile boolean scrollbarPainted;
private static volatile boolean scrollPanePainted;
private static volatile boolean textAreaPainted;
private static volatile boolean textFieldPainted;
private static final Button buttonStub = new Button() {
@Override
public void paint(final Graphics g) {
buttonPainted = true;
}
};
private static final Canvas canvasStub = new Canvas() {
@Override
public void paint(final Graphics g) {
canvasPainted = true;
}
};
private static final Checkbox checkboxStub = new Checkbox() {
@Override
public void paint(final Graphics g) {
checkboxPainted = true;
}
};
private static final Choice choiceStub = new Choice() {
@Override
public void paint(final Graphics g) {
choicePainted = true;
}
};
private static final Component lwComponentStub = new Component() {
@Override
public void paint(final Graphics g) {
lwPainted = true;
}
};
private static final Container containerStub = new Container() {
@Override
public void paint(final Graphics g) {
containerPainted = true;
}
};
private static final Frame frame = new Frame() {
@Override
public void paint(final Graphics g) {
super.paint(g);
framePainted = true;
}
};
private static final Label labelStub = new Label() {
@Override
public void paint(final Graphics g) {
labelPainted = true;
}
};
private static final List listStub = new List() {
@Override
public void paint(final Graphics g) {
listPainted = true;
}
};
private static final Panel panelStub = new Panel() {
@Override
public void paint(final Graphics g) {
panelPainted = true;
}
};
private static final Scrollbar scrollbarStub = new Scrollbar() {
@Override
public void paint(final Graphics g) {
scrollbarPainted = true;
}
};
private static final ScrollPane scrollPaneStub = new ScrollPane() {
@Override
public void paint(final Graphics g) {
scrollPanePainted = true;
}
};
private static final TextArea textAreaStub = new TextArea() {
@Override
public void paint(final Graphics g) {
textAreaPainted = true;
}
};
private static final TextField textFieldStub = new TextField() {
@Override
public void paint(final Graphics g) {
textFieldPainted = true;
}
};
public static void main(final String[] args) throws Exception {
//Frame initialisation
final BufferedImage graphicsProducer =
new BufferedImage(BufferedImage.TYPE_INT_ARGB, 1, 1);
final Graphics g = graphicsProducer.getGraphics();
frame.setLayout(new GridLayout());
frame.add(buttonStub);
frame.add(canvasStub);
frame.add(checkboxStub);
frame.add(choiceStub);
frame.add(lwComponentStub);
frame.add(containerStub);
frame.add(labelStub);
frame.add(listStub);
frame.add(panelStub);
frame.add(scrollbarStub);
frame.add(scrollPaneStub);
frame.add(textAreaStub);
frame.add(textFieldStub);
frame.setSize(new Dimension(500, 500));
frame.setLocationRelativeTo(null);
frame.setVisible(true);
sleep();
//Check results.
validation();
//Reset all flags to 'false'.
initPaintedFlags();
//Tested method.
frame.paintAll(g);
sleep();
//Check results.
validation();
cleanup();
}
private static void initPaintedFlags() {
lwPainted = false;
buttonPainted = false;
canvasPainted = false;
checkboxPainted = false;
choicePainted = false;
containerPainted = false;
framePainted = false;
labelPainted = false;
listPainted = false;
panelPainted = false;
scrollbarPainted = false;
scrollPanePainted = false;
textAreaPainted = false;
textFieldPainted = false;
}
private static void validation() {
if (!buttonPainted) {
fail("Paint is not called a Button "
+ "when paintAll() invoked on a parent");
}
if (!canvasPainted) {
fail("Paint is not called a Canvas "
+ "when paintAll() invoked on a parent");
}
if (!checkboxPainted) {
fail("Paint is not called a Checkbox "
+ "when paintAll() invoked on a parent");
}
if (!choicePainted) {
fail("Paint is not called a Choice "
+ "when paintAll() invoked on a parent");
}
if (!lwPainted) {
fail("Paint is not called on a lightweight"
+ " subcomponent when paintAll() invoked on a parent");
}
if (!containerPainted) {
fail("Paint is not called on a Container"
+ " subcomponent when paintAll() invoked on a parent");
}
if (!labelPainted) {
fail("Paint is not called on a Label"
+ " subcomponent when paintAll() invoked on a parent");
}
if (!listPainted) {
fail("Paint is not called on a List"
+ " subcomponent when paintAll() invoked on a parent");
}
if (!panelPainted) {
fail("Paint is not called on a Panel"
+ " subcomponent when paintAll() invoked on a parent");
}
if (!scrollbarPainted) {
fail("Paint is not called on a Scrollbar"
+ " subcomponent when paintAll() invoked on a parent");
}
if (!scrollPanePainted) {
fail("Paint is not called on a ScrollPane"
+ " subcomponent when paintAll() invoked on a parent");
}
if (!textAreaPainted) {
fail("Paint is not called on a TextArea"
+ " subcomponent when paintAll() invoked on a parent");
}
if (!textFieldPainted) {
fail("Paint is not called on a TextField"
+ " subcomponent when paintAll() invoked on a parent");
}
if (!framePainted) {
fail("Paint is not called on a Frame when paintAll()");
}
}
private static void sleep() {
((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
try {
Thread.sleep(500L);
} catch (InterruptedException ignored) {
}
}
private static void fail(final String message) {
cleanup();
throw new RuntimeException(message);
}
private static void cleanup() {
frame.dispose();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册