# HG changeset patch # User serb # Date 1310743383 -14400 # Node ID f9ac9a52952d0fb0bc607b9867853f387d0b2d48 # Parent daec42746ec0f4faf8564e966b5cb8e9a123d835 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails Reviewed-by: art, dcherepanov, anthony diff -r daec42746ec0 -r f9ac9a52952d jdk/src/solaris/classes/sun/awt/X11/XButtonPeer.java --- a/jdk/src/solaris/classes/sun/awt/X11/XButtonPeer.java Fri Jul 15 19:19:33 2011 +0400 +++ b/jdk/src/solaris/classes/sun/awt/X11/XButtonPeer.java Fri Jul 15 19:23:03 2011 +0400 @@ -33,12 +33,9 @@ import javax.swing.plaf.basic.*; import javax.swing.SwingUtilities; import javax.swing.SwingConstants; - public class XButtonPeer extends XComponentPeer implements ButtonPeer { - - boolean pressed; - boolean armed; - + private boolean pressed; + private boolean armed; private Insets focusInsets; private Insets borderInsets; private Insets contentAreaInsets; @@ -86,11 +83,6 @@ this.label = label; repaint(); } - - public void paint(Graphics g) { - paint(g,target); - } - public void setBackground(Color c) { updateMotifColors(c); super.setBackground(c); @@ -133,16 +125,10 @@ case MouseEvent.MOUSE_ENTERED: if (pressed) armed = true; -// repaint(); - break; - case MouseEvent.MOUSE_EXITED: armed = false; -// repaint(); - break; - } } @@ -209,18 +195,14 @@ public Dimension minimumSize() { return getMinimumSize(); } - - - /* - This method is called from Toolkit Thread and so it should not call any client code - - */ - public void paint(Graphics g, Component c) - { - if (!disposed && (g != null)) - { + /** + * This method is called from Toolkit Thread and so it should not call any + * client code. + */ + @Override + void paintPeer(final Graphics g) { + if (!disposed) { Dimension size = getPeerSize(); - g.setColor( getPeerBackground() ); /* erase the existing button remains */ g.fillRect(0,0, size.width , size.height); paintBorder(g,borderInsets.left, @@ -239,11 +221,9 @@ viewRect.width = size.width - (contentAreaInsets.left+contentAreaInsets.right); viewRect.height = size.height - (contentAreaInsets.top+contentAreaInsets.bottom); - viewRect.x = contentAreaInsets.left; - viewRect.y = contentAreaInsets.right; + viewRect.y = contentAreaInsets.top; String llabel = (label != null) ? label : ""; - // layout the text and icon String text = SwingUtilities.layoutCompoundLabel( fm, llabel, null, @@ -309,10 +289,9 @@ else { /*** paint the text disabled ***/ g.setColor(getPeerBackground().brighter()); - BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex, textRect.x, textRect.y + fm.getAscent()); - g.setColor(c.getBackground().darker()); + g.setColor(getPeerBackground().darker()); BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex, textRect.x - 1, textRect.y + fm.getAscent() - 1); } diff -r daec42746ec0 -r f9ac9a52952d jdk/src/solaris/classes/sun/awt/X11/XCheckboxPeer.java --- a/jdk/src/solaris/classes/sun/awt/X11/XCheckboxPeer.java Fri Jul 15 19:19:33 2011 +0400 +++ b/jdk/src/solaris/classes/sun/awt/X11/XCheckboxPeer.java Fri Jul 15 19:23:03 2011 +0400 @@ -297,40 +297,33 @@ double fsize = (double) checkBoxSize; myCheckMark = AffineTransform.getScaleInstance(fsize / MASTER_SIZE, fsize / MASTER_SIZE).createTransformedShape(MASTER_CHECKMARK); - } - - public void paint(Graphics g) { - if (g != null) { - //layout(); - Dimension size = getPeerSize(); - Font f = getPeerFont(); - - flush(); - g.setColor(getPeerBackground()); // erase the existing button - g.fillRect(0,0, size.width, size.height); + @Override + void paintPeer(final Graphics g) { + //layout(); + Dimension size = getPeerSize(); + Font f = getPeerFont(); + flush(); + g.setColor(getPeerBackground()); // erase the existing button + g.fillRect(0,0, size.width, size.height); + if (label != null) { + g.setFont(f); + paintText(g, textRect, label); + } - if (label != null) { - g.setFont(f); - paintText(g, textRect, label); - } - - if (hasFocus()) { - paintFocus(g, - focusRect.x, - focusRect.y, - focusRect.width, - focusRect.height); - } - - // Paint the checkbox or radio button - if (checkBoxGroup == null) { - paintCheckbox(g, cbX, cbY, checkBoxSize, checkBoxSize); - } - else { - paintRadioButton(g, cbX, cbY, checkBoxSize, checkBoxSize); - } - + if (hasFocus()) { + paintFocus(g, + focusRect.x, + focusRect.y, + focusRect.width, + focusRect.height); + } + // Paint the checkbox or radio button + if (checkBoxGroup == null) { + paintCheckbox(g, cbX, cbY, checkBoxSize, checkBoxSize); + } + else { + paintRadioButton(g, cbX, cbY, checkBoxSize, checkBoxSize); } flush(); } diff -r daec42746ec0 -r f9ac9a52952d jdk/src/solaris/classes/sun/awt/X11/XChoicePeer.java --- a/jdk/src/solaris/classes/sun/awt/X11/XChoicePeer.java Fri Jul 15 19:19:33 2011 +0400 +++ b/jdk/src/solaris/classes/sun/awt/X11/XChoicePeer.java Fri Jul 15 19:23:03 2011 +0400 @@ -550,10 +550,10 @@ /** * Paint the choice */ - public void paint(Graphics g) { + @Override + void paintPeer(final Graphics g) { flush(); Dimension size = getPeerSize(); - // TODO: when mouse is down over button, widget should be drawn depressed g.setColor(getPeerBackground()); g.fillRect(0, 0, width, height); @@ -912,16 +912,22 @@ /* * fillRect with current Background color on the whole dropdown list. */ - public void paintBackground(){ - Graphics g = getGraphics(); - g.setColor(getPeerBackground()); - g.fillRect(0, 0, width, height); + public void paintBackground() { + final Graphics g = getGraphics(); + if (g != null) { + try { + g.setColor(getPeerBackground()); + g.fillRect(0, 0, width, height); + } finally { + g.dispose(); + } + } } - /* * 6405689. In some cases we should erase background to eliminate painting * artefacts. */ + @Override public void repaint() { if (!isVisible()) { return; @@ -931,8 +937,8 @@ } super.repaint(); } - - public void paint(Graphics g) { + @Override + public void paintPeer(Graphics g) { //System.out.println("UC.paint()"); Choice choice = (Choice)target; Color colors[] = XChoicePeer.this.getGUIcolors(); diff -r daec42746ec0 -r f9ac9a52952d jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java --- a/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java Fri Jul 15 19:19:33 2011 +0400 +++ b/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java Fri Jul 15 19:23:03 2011 +0400 @@ -38,7 +38,6 @@ import java.awt.GraphicsConfiguration; import java.awt.Image; import java.awt.Insets; -import java.awt.KeyboardFocusManager; import java.awt.Rectangle; import java.awt.SystemColor; import java.awt.Toolkit; @@ -59,15 +58,11 @@ import java.awt.image.VolatileImage; import java.awt.peer.ComponentPeer; import java.awt.peer.ContainerPeer; -import java.awt.peer.LightweightPeer; import java.lang.reflect.*; import java.security.*; import java.util.Collection; -import java.util.HashSet; import java.util.Set; -import java.util.Vector; import sun.util.logging.PlatformLogger; - import sun.awt.*; import sun.awt.event.IgnorePaintEvent; import sun.awt.image.SunVolatileImage; @@ -428,27 +423,23 @@ public void disable() { setEnabled(false); } - - public void paint(Graphics g) { + @Override + public void paint(final Graphics g) { + super.paint(g); + // allow target to change the picture + target.paint(g); } - public void repaint(long tm, int x, int y, int width, int height) { - repaint(); - } - public Graphics getGraphics() { return getGraphics(surfaceData, getPeerForeground(), getPeerBackground(), getPeerFont()); } - - - public void print(Graphics g) { // clear rect here to emulate X clears rect before Expose g.setColor(target.getBackground()); g.fillRect(0, 0, target.getWidth(), target.getHeight()); g.setColor(target.getForeground()); // paint peer - paint(g); + paintPeer(g); // allow target to change the picture target.print(g); } diff -r daec42746ec0 -r f9ac9a52952d jdk/src/solaris/classes/sun/awt/X11/XLabelPeer.java --- a/jdk/src/solaris/classes/sun/awt/X11/XLabelPeer.java Fri Jul 15 19:19:33 2011 +0400 +++ b/jdk/src/solaris/classes/sun/awt/X11/XLabelPeer.java Fri Jul 15 19:23:03 2011 +0400 @@ -85,7 +85,8 @@ */ // NOTE: This method is called by privileged threads. // DO NOT INVOKE CLIENT CODE ON THIS THREAD! - public void paint(Graphics g) { + @Override + void paintPeer(final Graphics g) { int textX = 0; int textY = 0; g.setColor(getPeerBackground()); diff -r daec42746ec0 -r f9ac9a52952d jdk/src/solaris/classes/sun/awt/X11/XListPeer.java --- a/jdk/src/solaris/classes/sun/awt/X11/XListPeer.java Fri Jul 15 19:19:33 2011 +0400 +++ b/jdk/src/solaris/classes/sun/awt/X11/XListPeer.java Fri Jul 15 19:23:03 2011 +0400 @@ -363,9 +363,7 @@ return Math.min(items.size()-1, itemsInWindow()-1); } } - public void repaintScrollbarRequest(XScrollbar scrollbar) { - Graphics g = getGraphics(); if (scrollbar == hsb) { repaint(PAINT_HSCROLL); } @@ -373,9 +371,6 @@ repaint(PAINT_VSCROLL); } } - - - /** * Overridden for performance */ @@ -410,18 +405,20 @@ * @param distance the distance to copy the source area */ private void repaint(int firstItem, int lastItem, int options, Rectangle source, Point distance) { - Graphics g = getGraphics(); - try { - painter.paint(g, firstItem, lastItem, options, source, distance); - } finally { - g.dispose(); + final Graphics g = getGraphics(); + if (g != null) { + try { + painter.paint(g, firstItem, lastItem, options, source, distance); + target.paint(g); + } finally { + g.dispose(); + } } } - - public void paint(Graphics g) { + @Override + void paintPeer(final Graphics g) { painter.paint(g, getFirstVisibleItem(), getLastVisibleItem(), PAINT_ALL); } - public boolean isFocusable() { return true; } // TODO: share/promote the Focus methods? diff -r daec42746ec0 -r f9ac9a52952d jdk/src/solaris/classes/sun/awt/X11/XMenuBarPeer.java --- a/jdk/src/solaris/classes/sun/awt/X11/XMenuBarPeer.java Fri Jul 15 19:19:33 2011 +0400 +++ b/jdk/src/solaris/classes/sun/awt/X11/XMenuBarPeer.java Fri Jul 15 19:23:03 2011 +0400 @@ -415,7 +415,7 @@ * Overriden XWindow painting & printing * ************************************************/ - public void paint(Graphics g) { + public void paintPeer(Graphics g) { resetColors(); /* Calculate menubar dimension. */ int width = getWidth(); diff -r daec42746ec0 -r f9ac9a52952d jdk/src/solaris/classes/sun/awt/X11/XMenuWindow.java --- a/jdk/src/solaris/classes/sun/awt/X11/XMenuWindow.java Fri Jul 15 19:19:33 2011 +0400 +++ b/jdk/src/solaris/classes/sun/awt/X11/XMenuWindow.java Fri Jul 15 19:23:03 2011 +0400 @@ -432,9 +432,9 @@ /** * Paints menu window */ - public void paint(Graphics g) { + @Override + public void paintPeer(Graphics g) { resetColors(); - int width = getWidth(); int height = getHeight(); diff -r daec42746ec0 -r f9ac9a52952d jdk/src/solaris/classes/sun/awt/X11/XPanelPeer.java --- a/jdk/src/solaris/classes/sun/awt/X11/XPanelPeer.java Fri Jul 15 19:19:33 2011 +0400 +++ b/jdk/src/solaris/classes/sun/awt/X11/XPanelPeer.java Fri Jul 15 19:23:03 2011 +0400 @@ -60,14 +60,13 @@ public Insets getInsets() { return new Insets(0, 0, 0, 0); } - public void paint(Graphics g) { super.paint(g); - /* SunGraphicsCallback.PaintHeavyweightComponentsCallback.getInstance(). - runComponents(((Container)target).getComponents(), g, - SunGraphicsCallback.LIGHTWEIGHTS | - SunGraphicsCallback.HEAVYWEIGHTS); - */ } + SunGraphicsCallback.PaintHeavyweightComponentsCallback.getInstance(). + runComponents(((Container)target).getComponents(), g, + SunGraphicsCallback.LIGHTWEIGHTS | + SunGraphicsCallback.HEAVYWEIGHTS); + } public void print(Graphics g) { super.print(g); SunGraphicsCallback.PrintHeavyweightComponentsCallback.getInstance(). diff -r daec42746ec0 -r f9ac9a52952d jdk/src/solaris/classes/sun/awt/X11/XRepaintArea.java --- a/jdk/src/solaris/classes/sun/awt/X11/XRepaintArea.java Fri Jul 15 19:19:33 2011 +0400 +++ b/jdk/src/solaris/classes/sun/awt/X11/XRepaintArea.java Fri Jul 15 19:23:03 2011 +0400 @@ -53,9 +53,9 @@ */ protected void updateComponent(Component comp, Graphics g) { if (comp != null) { - ComponentPeer peer = comp.getPeer(); + final XComponentPeer peer = (XComponentPeer) comp.getPeer(); if (peer != null) { - peer.paint(g); + peer.paintPeer(g); } super.updateComponent(comp, g); } @@ -66,9 +66,9 @@ */ protected void paintComponent(Component comp, Graphics g) { if (comp != null) { - ComponentPeer peer = comp.getPeer(); + final XComponentPeer peer = (XComponentPeer) comp.getPeer(); if (peer != null) { - peer.paint(g); + peer.paintPeer(g); } super.paintComponent(comp, g); } diff -r daec42746ec0 -r f9ac9a52952d jdk/src/solaris/classes/sun/awt/X11/XScrollPanePeer.java --- a/jdk/src/solaris/classes/sun/awt/X11/XScrollPanePeer.java Fri Jul 15 19:19:33 2011 +0400 +++ b/jdk/src/solaris/classes/sun/awt/X11/XScrollPanePeer.java Fri Jul 15 19:23:03 2011 +0400 @@ -293,10 +293,12 @@ setAdjustableValue(hadj, hsb.getValue(), type); sx = -(hsb.getValue()); Graphics g = getGraphics(); - try { - paintHorScrollbar(g, colors, true); - } finally { - g.dispose(); + if (g != null) { + try { + paintHorScrollbar(g, colors, true); + } finally { + g.dispose(); + } } } if ((flag & VERTICAL) != 0) { @@ -305,10 +307,12 @@ setAdjustableValue(vadj, vsb.getValue(), type); sy = -(vsb.getValue()); Graphics g = getGraphics(); - try { - paintVerScrollbar(g, colors, true); - } finally { - g.dispose(); + if (g != null) { + try { + paintVerScrollbar(g, colors, true); + } finally { + g.dispose(); + } } } } @@ -327,14 +331,21 @@ ite.getCause().printStackTrace(); } } - - - public void paint(Graphics g) { - paintComponent(g); + @Override + void paintPeer(final Graphics g) { + final Color[] colors = getGUIcolors(); + 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) { paintVerScrollbar(g, colors, true); // paint the whole scrollbar @@ -345,51 +356,32 @@ // paint the whole scrollbar } } - - void repaintScrollBars() { - Graphics g = getGraphics(); - Color colors[] = getGUIcolors(); - if (g != null) { - paintScrollBars(g,colors); - } - g.dispose(); - } - - public void repaintScrollbarRequest(XScrollbar sb) { - Graphics g = getGraphics(); - Color colors[] = getGUIcolors(); - if (g != null) { - if (sb == vsb) { - paintVerScrollbar(g,colors,true); - } - else if (sb == hsb) { - paintHorScrollbar(g,colors,true); - } - } + void repaintScrollBars() { + Graphics g = getGraphics(); + Color colors[] = getGUIcolors(); + if (g != null) { + try { + paintScrollBars(g, colors); + } finally { + g.dispose(); + } + } } - - /** - * Paint the scrollpane. - */ - public void paintComponent(Graphics g) { - + public void repaintScrollbarRequest(XScrollbar sb) { + Graphics g = getGraphics(); 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); + if (g != null) { + try { + if (sb == vsb) { + paintVerScrollbar(g, colors, true); + } else if (sb == hsb) { + paintHorScrollbar(g, colors, true); + } + } finally { + g.dispose(); + } } - - paintScrollBars(g,colors); } - public void handleEvent(java.awt.AWTEvent e) { super.handleEvent(e); diff -r daec42746ec0 -r f9ac9a52952d jdk/src/solaris/classes/sun/awt/X11/XScrollbarPeer.java --- a/jdk/src/solaris/classes/sun/awt/X11/XScrollbarPeer.java Fri Jul 15 19:19:33 2011 +0400 +++ b/jdk/src/solaris/classes/sun/awt/X11/XScrollbarPeer.java Fri Jul 15 19:23:03 2011 +0400 @@ -90,18 +90,12 @@ ? new Dimension(getDefaultDimension(), DEFAULT_LENGTH) : new Dimension(DEFAULT_LENGTH, getDefaultDimension()); } - - public void repaint() { - Graphics g = getGraphics(); - if (g != null) paint(g); - } - /** * Paint the scrollbar. */ - public void paint(Graphics g) { - Scrollbar sb = (Scrollbar)target; - Color colors[] = getGUIcolors(); + @Override + void paintPeer(final Graphics g) { + final Color[] colors = getGUIcolors(); g.setColor(colors[BACKGROUND_COLOR]); tsb.paint(g, colors, true); // paint the whole scrollbar diff -r daec42746ec0 -r f9ac9a52952d jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java --- a/jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java Fri Jul 15 19:19:33 2011 +0400 +++ b/jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java Fri Jul 15 19:23:03 2011 +0400 @@ -298,15 +298,14 @@ * Paint the component * this method is called when the repaint instruction has been used */ - public void repaint() { if (textPane != null) { //textPane.validate(); textPane.repaint(); } } - - public void paint(Graphics g) { + @Override + void paintPeer(final Graphics g) { if (textPane != null) { textPane.paint(g); } diff -r daec42746ec0 -r f9ac9a52952d jdk/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java --- a/jdk/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java Fri Jul 15 19:19:33 2011 +0400 +++ b/jdk/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java Fri Jul 15 19:23:03 2011 +0400 @@ -370,12 +370,11 @@ public void repaint() { if (xtext != null) xtext.repaint(); } - - public void paint(Graphics g) { + @Override + void paintPeer(final Graphics g) { if (xtext != null) xtext.paint(g); } - public void print(Graphics g) { if (xtext != null) { xtext.print(g); diff -r daec42746ec0 -r f9ac9a52952d jdk/src/solaris/classes/sun/awt/X11/XWarningWindow.java --- a/jdk/src/solaris/classes/sun/awt/X11/XWarningWindow.java Fri Jul 15 19:19:33 2011 +0400 +++ b/jdk/src/solaris/classes/sun/awt/X11/XWarningWindow.java Fri Jul 15 19:23:03 2011 +0400 @@ -241,16 +241,19 @@ Font getFont () { return ownerWindow.getFont(); } + + @Override public void repaint() { - Rectangle bounds = getBounds(); - Graphics g = getGraphics(); - try { - paint(g, 0, 0, bounds.width, bounds.height); - } finally { - g.dispose(); + final Rectangle bounds = getBounds(); + final Graphics g = getGraphics(); + if (g != null) { + try { + paint(g, 0, 0, bounds.width, bounds.height); + } finally { + g.dispose(); + } } } - @Override public void handleExposeEvent(XEvent xev) { super.handleExposeEvent(xev); @@ -263,11 +266,13 @@ SunToolkit.executeOnEventHandlerThread(target, new Runnable() { public void run() { - Graphics g = getGraphics(); - try { - paint(g, x, y, width, height); - } finally { - g.dispose(); + final Graphics g = getGraphics(); + if (g != null) { + try { + paint(g, x, y, width, height); + } finally { + g.dispose(); + } } } }); diff -r daec42746ec0 -r f9ac9a52952d jdk/src/solaris/classes/sun/awt/X11/XWindow.java --- a/jdk/src/solaris/classes/sun/awt/X11/XWindow.java Fri Jul 15 19:19:33 2011 +0400 +++ b/jdk/src/solaris/classes/sun/awt/X11/XWindow.java Fri Jul 15 19:23:03 2011 +0400 @@ -502,9 +502,8 @@ public boolean isEmbedded() { return embedded; } - public void repaint(int x,int y, int width, int height) { - if (!isVisible()) { + if (!isVisible() || getWidth() == 0 || getHeight() == 0) { return; } Graphics g = getGraphics(); @@ -517,12 +516,11 @@ } } } - - public void repaint() { - if (!isVisible()) { + void repaint() { + if (!isVisible() || getWidth() == 0 || getHeight() == 0) { return; } - Graphics g = getGraphics(); + final Graphics g = getGraphics(); if (g != null) { try { paint(g); @@ -531,10 +529,13 @@ } } } - - void paint(Graphics g) { + public void paint(final Graphics g) { + // paint peer + paintPeer(g); } + void paintPeer(final Graphics g) { + } //used by Peers to avoid flickering withing paint() protected void flush(){ XToolkit.awtLock(); diff -r daec42746ec0 -r f9ac9a52952d jdk/test/java/awt/Component/PaintAll/PaintAll.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Component/PaintAll/PaintAll.java Fri Jul 15 19:23:03 2011 +0400 @@ -0,0 +1,301 @@ +/* + * 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(); + } +}