<commit_before>//
// $Id: VizController.java,v 1.1 2001/08/14 00:45:56 mdb Exp $

package com.samskivert.viztool;

import java.awt.event.ActionEvent;
import java.awt.print.*;

import com.samskivert.swing.*;

/**
 * The viz controller manages the user interface and effects actions that
 * are requested by the user (like moving forward or backward a page).
 */
public class VizController extends Controller
{
    /** The action command for moving forward one page. */
    public static final String FORWARD_PAGE = "forward_page";

    /** The action command for moving backward one page. */
    public static final String BACKWARD_PAGE = "backward_page";

    /** The action command for printing. */
    public static final String PRINT = "print";

    /** The action command for quitting. */
    public static final String QUIT = "quit";

    public VizController (VizPanel vpanel)
    {
        _vpanel = vpanel;

        // create a print job in case we need to print
        _job = PrinterJob.getPrinterJob();
        _format = _job.defaultPage();

        // use sensible margins
        Paper paper = new Paper();
        paper.setImageableArea(
            LEFT_MARGIN, TOP_MARGIN, PAGE_WIDTH, PAGE_HEIGHT);
        _format.setPaper(paper);
    }

    public boolean handleAction (ActionEvent action)
    {
        String cmd = action.getActionCommand();

        if (cmd.equals(FORWARD_PAGE)) {
            int pno = _vpanel.getPage();
            if (pno < _vpanel.getPageCount()-1) {
                _vpanel.setPage(pno+1);
            }
            return true;

        } else if (cmd.equals(BACKWARD_PAGE)) {
            int pno = _vpanel.getPage();
            if (pno > 0) {
                _vpanel.setPage(pno-1);
            }
            return true;

        } else if (cmd.equals(PRINT)) {
            // tell the job to print our visualizer with the format we set
            // up earlier
            _job.setPrintable(_vpanel.getVisualizer(), _format);

            // pop up a dialog to control printing
            if (_job.printDialog()) {
                try {
                    // invoke the printing process
                    _job.print();
                } catch (PrinterException pe) {
                    pe.printStackTrace(System.err);
                }<commit_msg>Switched to using a Pageable in hopes that this would cause Java to allow the user to print only particular pages, but it doesn't seem to make use of the pageable information to do that. Alas.<commit_after>//
// $Id: VizController.java,v 1.2 2001/08/14 00:58:15 mdb Exp $

package com.samskivert.viztool;

import java.awt.event.ActionEvent;
import java.awt.print.*;

import com.samskivert.swing.*;

/**
 * The viz controller manages the user interface and effects actions that
 * are requested by the user (like moving forward or backward a page).
 */
public class VizController extends Controller
{
    /** The action command for moving forward one page. */
    public static final String FORWARD_PAGE = "forward_page";

    /** The action command for moving backward one page. */
    public static final String BACKWARD_PAGE = "backward_page";

    /** The action command for printing. */
    public static final String PRINT = "print";

    /** The action command for quitting. */
    public static final String QUIT = "quit";

    public VizController (VizPanel vpanel)
    {
        _vpanel = vpanel;

        // create a print job in case we need to print
        _job = PrinterJob.getPrinterJob();
        _format = _job.defaultPage();

        // use sensible margins
        Paper paper = new Paper();
        paper.setImageableArea(
            LEFT_MARGIN, TOP_MARGIN, PAGE_WIDTH, PAGE_HEIGHT);
        _format.setPaper(paper);
    }

    public boolean handleAction (ActionEvent action)
    {
        String cmd = action.getActionCommand();

        if (cmd.equals(FORWARD_PAGE)) {
            int pno = _vpanel.getPage();
            if (pno < _vpanel.getPageCount()-1) {
                _vpanel.setPage(pno+1);
            }
            return true;

        } else if (cmd.equals(BACKWARD_PAGE)) {
            int pno = _vpanel.getPage();
            if (pno > 0) {
                _vpanel.setPage(pno-1);
            }
            return true;

        } else if (cmd.equals(PRINT)) {
            // create a pageable to be used by our print job that does the
            // right thing
            Pageable pable = new Pageable()
            {
                public int getNumberOfPages ()
                {
                    return _vpanel.getVisualizer().getPageCount();
                }

                public PageFormat getPageFormat (int pageIndex)
                {
                    return _format;
                }

                public Printable getPrintable (int pageIndex)
                {
                    return _vpanel.getVisualizer();
                }
            };
            _job.setPageable(pable);

            // pop up a dialog to control printing
            if (_job.printDialog()) {
                try {
                    // invoke the printing process
                    _job.print();
                } catch (PrinterException pe) {
                    pe.printStackTrace(System.err);
                }
{'fraction_non_alphanumeric': 0.0896145813556104, 'fraction_numerical': 0.007594456047085627, 'mean_word_length': 1.7887771307570144, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2561574', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1379, 'n_words': 450}