Path: blob/master/test/jdk/java/awt/Component/PaintAll/PaintAll.java
41153 views
/*1* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.Button;24import java.awt.Canvas;25import java.awt.Checkbox;26import java.awt.Choice;27import java.awt.Component;28import java.awt.Container;29import java.awt.Dimension;30import java.awt.Frame;31import java.awt.Graphics;32import java.awt.GridLayout;33import java.awt.Label;34import java.awt.List;35import java.awt.Panel;36import java.awt.ScrollPane;37import java.awt.Scrollbar;38import java.awt.TextArea;39import java.awt.TextField;40import java.awt.Toolkit;41import java.awt.image.BufferedImage;4243/*44@test45@key headful46@bug 659691547@summary Test Component.paintAll() method48@author [email protected]: area=awt.component49@library /lib/client/50@build ExtendedRobot51@run main PaintAll52*/53public class PaintAll {5455private static volatile boolean lwPainted;56private static volatile boolean buttonPainted;57private static volatile boolean canvasPainted;58private static volatile boolean checkboxPainted;59private static volatile boolean choicePainted;60private static volatile boolean containerPainted;61private static volatile boolean framePainted;62private static volatile boolean labelPainted;63private static volatile boolean listPainted;64private static volatile boolean panelPainted;65private static volatile boolean scrollbarPainted;66private static volatile boolean scrollPanePainted;67private static volatile boolean textAreaPainted;68private static volatile boolean textFieldPainted;69private static ExtendedRobot robot = null;7071private static final Button buttonStub = new Button() {72@Override73public void paint(final Graphics g) {74buttonPainted = true;75}76};7778private static final Canvas canvasStub = new Canvas() {79@Override80public void paint(final Graphics g) {81canvasPainted = true;82}83};8485private static final Checkbox checkboxStub = new Checkbox() {86@Override87public void paint(final Graphics g) {88checkboxPainted = true;89}90};9192private static final Choice choiceStub = new Choice() {93@Override94public void paint(final Graphics g) {95choicePainted = true;96}97};9899private static final Component lwComponentStub = new Component() {100@Override101public void paint(final Graphics g) {102lwPainted = true;103}104};105106private static final Container containerStub = new Container() {107@Override108public void paint(final Graphics g) {109containerPainted = true;110}111};112113private static final Frame frame = new Frame() {114@Override115public void paint(final Graphics g) {116super.paint(g);117framePainted = true;118}119};120121private static final Label labelStub = new Label() {122@Override123public void paint(final Graphics g) {124labelPainted = true;125}126};127128private static final List listStub = new List() {129@Override130public void paint(final Graphics g) {131listPainted = true;132}133};134135private static final Panel panelStub = new Panel() {136@Override137public void paint(final Graphics g) {138panelPainted = true;139}140};141142private static final Scrollbar scrollbarStub = new Scrollbar() {143@Override144public void paint(final Graphics g) {145scrollbarPainted = true;146}147};148149private static final ScrollPane scrollPaneStub = new ScrollPane() {150@Override151public void paint(final Graphics g) {152scrollPanePainted = true;153}154};155156private static final TextArea textAreaStub = new TextArea() {157@Override158public void paint(final Graphics g) {159textAreaPainted = true;160}161};162163private static final TextField textFieldStub = new TextField() {164@Override165public void paint(final Graphics g) {166textFieldPainted = true;167}168};169170public static void main(final String[] args) throws Exception {171//Frame initialisation172final BufferedImage graphicsProducer =173new BufferedImage(BufferedImage.TYPE_INT_ARGB, 1, 1);174175final Graphics g = graphicsProducer.getGraphics();176177frame.setLayout(new GridLayout());178frame.add(buttonStub);179frame.add(canvasStub);180frame.add(checkboxStub);181frame.add(choiceStub);182frame.add(lwComponentStub);183frame.add(containerStub);184frame.add(labelStub);185frame.add(listStub);186frame.add(panelStub);187frame.add(scrollbarStub);188frame.add(scrollPaneStub);189frame.add(textAreaStub);190frame.add(textFieldStub);191frame.setSize(new Dimension(500, 500));192frame.setLocationRelativeTo(null);193frame.setVisible(true);194sleep();195196//Check results.197validation();198199//Reset all flags to 'false'.200initPaintedFlags();201202//Tested method.203frame.paintAll(g);204sleep();205206//Check results.207validation();208cleanup();209}210211private static void initPaintedFlags() {212lwPainted = false;213buttonPainted = false;214canvasPainted = false;215checkboxPainted = false;216choicePainted = false;217containerPainted = false;218framePainted = false;219labelPainted = false;220listPainted = false;221panelPainted = false;222scrollbarPainted = false;223scrollPanePainted = false;224textAreaPainted = false;225textFieldPainted = false;226}227228private static void validation() {229if (!buttonPainted) {230fail("Paint is not called a Button "231+ "when paintAll() invoked on a parent");232}233if (!canvasPainted) {234fail("Paint is not called a Canvas "235+ "when paintAll() invoked on a parent");236}237if (!checkboxPainted) {238fail("Paint is not called a Checkbox "239+ "when paintAll() invoked on a parent");240}241if (!choicePainted) {242fail("Paint is not called a Choice "243+ "when paintAll() invoked on a parent");244}245if (!lwPainted) {246fail("Paint is not called on a lightweight"247+ " subcomponent when paintAll() invoked on a parent");248}249if (!containerPainted) {250fail("Paint is not called on a Container"251+ " subcomponent when paintAll() invoked on a parent");252}253if (!labelPainted) {254fail("Paint is not called on a Label"255+ " subcomponent when paintAll() invoked on a parent");256}257if (!listPainted) {258fail("Paint is not called on a List"259+ " subcomponent when paintAll() invoked on a parent");260}261if (!panelPainted) {262fail("Paint is not called on a Panel"263+ " subcomponent when paintAll() invoked on a parent");264}265if (!scrollbarPainted) {266fail("Paint is not called on a Scrollbar"267+ " subcomponent when paintAll() invoked on a parent");268}269if (!scrollPanePainted) {270fail("Paint is not called on a ScrollPane"271+ " subcomponent when paintAll() invoked on a parent");272}273if (!textAreaPainted) {274fail("Paint is not called on a TextArea"275+ " subcomponent when paintAll() invoked on a parent");276}277if (!textFieldPainted) {278fail("Paint is not called on a TextField"279+ " subcomponent when paintAll() invoked on a parent");280}281if (!framePainted) {282fail("Paint is not called on a Frame when paintAll()");283}284}285286private static void sleep() {287if(robot == null) {288try {289robot = new ExtendedRobot();290}catch(Exception ex) {291ex.printStackTrace();292throw new RuntimeException("Unexpected failure");293}294}295robot.waitForIdle(500);296}297298private static void fail(final String message) {299cleanup();300throw new RuntimeException(message);301}302303private static void cleanup() {304frame.dispose();305}306}307308309