Java Graphics Draw printAll(java.awt.Graphics2D g2, java.awt.Component component)

Here you can find the source of printAll(java.awt.Graphics2D g2, java.awt.Component component)

Description

print All

License

Open Source License

Declaration

private static void printAll(java.awt.Graphics2D g2, java.awt.Component component) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006, 2015, Carnegie Mellon University. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * 3. Products derived from the software may not be called "Alice", nor may
 *    "Alice" appear in their name, without prior written permission of
 *    Carnegie Mellon University.//ww  w .  ja v a  2  s .  c  om
 *
 * 4. All advertising materials mentioning features or use of this software must
 *    display the following acknowledgement: "This product includes software
 *    developed by Carnegie Mellon University"
 *
 * 5. The gallery of art assets and animations provided with this software is
 *    contributed by Electronic Arts Inc. and may be used for personal,
 *    non-commercial, and academic use only. Redistributions of any program
 *    source code that utilizes The Sims 2 Assets must also retain the copyright
 *    notice, list of conditions and the disclaimer contained in
 *    The Alice 3.0 Art Gallery License.
 *
 * DISCLAIMER:
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
 * ANY AND ALL EXPRESS, STATUTORY OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,  FITNESS FOR A
 * PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
 * SHALL THE AUTHORS, COPYRIGHT OWNERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING FROM OR OTHERWISE RELATING TO
 * THE USE OF OR OTHER DEALINGS WITH THE SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/

public class Main {
    private static void printAll(java.awt.Graphics2D g2, java.awt.Component component) {
        if (component != null) {
            int x = component.getX();
            int y = component.getY();
            g2.translate(x, y);
            try {
                java.awt.Shape prevClip = g2.getClip();
                try {
                    java.awt.Component c = getViewportViewIfNecessary(component);
                    java.awt.Dimension size = c.getPreferredSize();
                    g2.setClip(0, 0, size.width, size.height);
                    getViewportViewIfNecessary(component).printAll(g2);
                } finally {
                    g2.setClip(prevClip);
                }
            } finally {
                g2.translate(-x, -y);
            }
        }
    }

    private static java.awt.Component getViewportViewIfNecessary(java.awt.Component component) {
        if (component instanceof javax.swing.JScrollPane) {
            javax.swing.JScrollPane jScrollPane = (javax.swing.JScrollPane) component;
            return jScrollPane.getViewport().getView();
        } else {
            return component;
        }
    }
}

Related

  1. paintRectCompartment(Graphics g, Dimension size, int x, int y, Color fillColor, Color strokeColor)
  2. paintRectShadow(Graphics g, int x, int y, int width, int height)
  3. paintShape(Shape shape, Graphics2D g2d, Color colorStroke, Stroke stroke, Color colorFill, double downsample)
  4. paintSprite(Graphics g, int x, int y, int[][] sprite, Color[] colors)
  5. prepareGraphics(Graphics g)
  6. raiseOval(Graphics2D g2, Rectangle r, Color foreColor)
  7. raiseRect(Graphics2D g2, Rectangle r, Color foreColor)
  8. renderByLineGraphics(JComponent c, Graphics g)
  9. renderGraphics(JComponent c, Graphics g)