Example usage for javax.swing.text View paint

List of usage examples for javax.swing.text View paint

Introduction

In this page you can find the example usage for javax.swing.text View paint.

Prototype

public abstract void paint(Graphics g, Shape allocation);

Source Link

Document

Renders using the given rendering surface and area on that surface.

Usage

From source file:org.gephi.ui.components.ReportSelection.java

/**
 *
 * @param graphics/*from  w w  w .j ava 2  s .  c  o m*/
 * @param pageFormat
 * @param pageIndex
 * @return
 */
@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {

    boolean last = false;
    try {

        View rootView = displayPane.getUI().getRootView(displayPane);

        double scaleX = pageFormat.getImageableWidth() / displayPane.getMinimumSize().getWidth();

        scaleX = Math.min(scaleX, 1.0);
        double scaleY = scaleX;

        int end = (int) (pageIndex * ((1.0f / scaleY) * (double) pageFormat.getImageableHeight()));
        Rectangle allocation = new Rectangle(0, -end, (int) pageFormat.getImageableWidth(),
                (int) pageFormat.getImageableHeight());
        ((Graphics2D) graphics).scale(scaleX, scaleY);

        graphics.setClip((int) (pageFormat.getImageableX() / scaleX),
                (int) (pageFormat.getImageableY() / scaleY), (int) (pageFormat.getImageableWidth() / scaleX),
                (int) (pageFormat.getImageableHeight() / scaleY));

        ((Graphics2D) graphics).translate(((Graphics2D) graphics).getClipBounds().getX(),
                ((Graphics2D) graphics).getClipBounds().getY());

        rootView.paint(graphics, allocation);

        last = end > displayPane.getUI().getPreferredSize(displayPane).getHeight();

        if ((last)) {
            return Printable.NO_SUCH_PAGE;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return Printable.PAGE_EXISTS;
}