Path: blob/master/src/java.desktop/share/classes/sun/java2d/pipe/ValidatePipe.java
41159 views
/*1* Copyright (c) 1997, 2018, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.pipe;2627import java.awt.Color;28import java.awt.Image;29import java.awt.Shape;30import java.awt.geom.AffineTransform;31import java.awt.image.BufferedImage;32import java.awt.image.BufferedImageOp;33import java.awt.image.ImageObserver;34import sun.java2d.SunGraphics2D;35import java.awt.font.GlyphVector;3637/**38* This class is used to force a revalidation of the pipelines of39* the indicated SunGraphics2D object before a draw command.40* After calling SunGraphics2D.validatePipe() to force the pipeline41* to be revalidated, this object redispatches the draw command to42* the new valid pipe object.43*/44public class ValidatePipe45implements PixelDrawPipe, PixelFillPipe, ShapeDrawPipe, TextPipe,46DrawImagePipe47{48/*49* Different subclasses may override this to do various50* other forms of validation and return a return code51* indicating whether or not the validation was successful.52*/53public boolean validate(SunGraphics2D sg) {54sg.validatePipe();55return true;56}5758public void drawLine(SunGraphics2D sg,59int x1, int y1, int x2, int y2) {60if (validate(sg)) {61sg.drawpipe.drawLine(sg, x1, y1, x2, y2);62}63}6465public void drawRect(SunGraphics2D sg,66int x, int y, int width, int height) {67if (validate(sg)) {68sg.drawpipe.drawRect(sg, x, y, width, height);69}70}7172public void fillRect(SunGraphics2D sg,73int x, int y, int width, int height) {74if (validate(sg)) {75sg.fillpipe.fillRect(sg, x, y, width, height);76}77}7879public void drawRoundRect(SunGraphics2D sg,80int x, int y, int width, int height,81int arcWidth, int arcHeight) {82if (validate(sg)) {83sg.drawpipe.drawRoundRect(sg, x, y, width, height,84arcWidth, arcHeight);85}86}8788public void fillRoundRect(SunGraphics2D sg,89int x, int y, int width, int height,90int arcWidth, int arcHeight) {91if (validate(sg)) {92sg.fillpipe.fillRoundRect(sg, x, y, width, height,93arcWidth, arcHeight);94}95}9697public void drawOval(SunGraphics2D sg,98int x, int y, int width, int height) {99if (validate(sg)) {100sg.drawpipe.drawOval(sg, x, y, width, height);101}102}103104public void fillOval(SunGraphics2D sg,105int x, int y, int width, int height) {106if (validate(sg)) {107sg.fillpipe.fillOval(sg, x, y, width, height);108}109}110111public void drawArc(SunGraphics2D sg,112int x, int y, int width, int height,113int startAngle, int arcAngle) {114if (validate(sg)) {115sg.drawpipe.drawArc(sg, x, y, width, height, startAngle, arcAngle);116}117}118119public void fillArc(SunGraphics2D sg,120int x, int y, int width, int height,121int startAngle, int arcAngle) {122if (validate(sg)) {123sg.fillpipe.fillArc(sg, x, y, width, height, startAngle, arcAngle);124}125}126127public void drawPolyline(SunGraphics2D sg,128int[] xPoints, int[] yPoints,129int nPoints) {130if (validate(sg)) {131sg.drawpipe.drawPolyline(sg, xPoints, yPoints, nPoints);132}133}134135public void drawPolygon(SunGraphics2D sg,136int[] xPoints, int[] yPoints,137int nPoints) {138if (validate(sg)) {139sg.drawpipe.drawPolygon(sg, xPoints, yPoints, nPoints);140}141}142143public void fillPolygon(SunGraphics2D sg,144int[] xPoints, int[] yPoints,145int nPoints) {146if (validate(sg)) {147sg.fillpipe.fillPolygon(sg, xPoints, yPoints, nPoints);148}149}150151public void draw(SunGraphics2D sg, Shape s) {152if (validate(sg)) {153sg.shapepipe.draw(sg, s);154}155}156157public void fill(SunGraphics2D sg, Shape s) {158if (validate(sg)) {159sg.shapepipe.fill(sg, s);160}161}162public void drawString(SunGraphics2D sg, String s, double x, double y) {163if (validate(sg)) {164sg.textpipe.drawString(sg, s, x, y);165}166}167public void drawGlyphVector(SunGraphics2D sg, GlyphVector g,168float x, float y) {169if (validate(sg)) {170sg.textpipe.drawGlyphVector(sg, g, x, y);171}172}173public void drawChars(SunGraphics2D sg,174char[] data, int offset, int length,175int x, int y) {176if (validate(sg)) {177sg.textpipe.drawChars(sg, data, offset, length, x, y);178}179}180public boolean copyImage(SunGraphics2D sg, Image img,181int x, int y,182Color bgColor,183ImageObserver observer) {184if (validate(sg)) {185return sg.imagepipe.copyImage(sg, img, x, y, bgColor, observer);186} else {187return false;188}189}190public boolean copyImage(SunGraphics2D sg, Image img,191int dx, int dy, int sx, int sy, int w, int h,192Color bgColor,193ImageObserver observer) {194if (validate(sg)) {195return sg.imagepipe.copyImage(sg, img, dx, dy, sx, sy, w, h,196bgColor, observer);197} else {198return false;199}200}201public boolean scaleImage(SunGraphics2D sg, Image img, int x, int y,202int w, int h,203Color bgColor,204ImageObserver observer) {205if (validate(sg)) {206return sg.imagepipe.scaleImage(sg, img, x, y, w, h, bgColor,207observer);208} else {209return false;210}211}212public boolean scaleImage(SunGraphics2D sg, Image img,213int dx1, int dy1, int dx2, int dy2,214int sx1, int sy1, int sx2, int sy2,215Color bgColor,216ImageObserver observer) {217if (validate(sg)) {218return sg.imagepipe.scaleImage(sg, img, dx1, dy1, dx2, dy2,219sx1, sy1, sx2, sy2, bgColor,220observer);221} else {222return false;223}224}225public boolean transformImage(SunGraphics2D sg, Image img,226AffineTransform atfm,227ImageObserver observer) {228if (validate(sg)) {229return sg.imagepipe.transformImage(sg, img, atfm, observer);230} else {231return false;232}233}234public void transformImage(SunGraphics2D sg, BufferedImage img,235BufferedImageOp op, int x, int y) {236if (validate(sg)) {237sg.imagepipe.transformImage(sg, img, op, x, y);238}239}240}241242243