Exemplo n.º 1
1
        public Print2DPrinterJob() {

                /* Construct the print request specification.
                * The print data is a Printable object.
                * the request additonally specifies a job name, 2 copies, and
                * landscape orientation of the media.
                */
                PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
                aset.add(OrientationRequested.LANDSCAPE);
                aset.add(new Copies(2));
                aset.add(new JobName("My job", null));

                /* Create a print job */
                PrinterJob pj = PrinterJob.getPrinterJob();       
                pj.setPrintable(this);
                /* locate a print service that can handle the request */
                PrintService[] services =
                        PrinterJob.lookupPrintServices();

                if (services.length > 0) {
                        System.out.println("selected printer " + services[0].getName());
                        try {
                                pj.setPrintService(services[0]);
                                pj.pageDialog(aset);
                                if(pj.printDialog(aset)) {
                                        pj.print(aset);
                                }
                        } catch (PrinterException pe) { 
                                System.err.println(pe);
                        }
                }
        }
Exemplo n.º 2
0
  public OperandToken evaluate(Token[] operands, GlobalValues globals) {

    debugLine("print evaluate");

    /*if (operands==null)
    {
    	// figure called with no arguments
    	//getGraphicsManager().createNewFigure();

    }
          else
          {
           if (getNArgIn(operands) != 1)
    		throwMathLibException("print: number of arguments != 1");

       	if (!(operands[0] instanceof NumberToken))
          		throwMathLibException("print: argument must be a number");

    	int figureNumber  = (int)(((NumberToken)operands[0]).getValues()[0][0]);

    	getGraphicsManager().createNewFigure(figureNumber);
          }
    */

    PrinterJob pjob = PrinterJob.getPrinterJob();
    PageFormat defaultPF = pjob.defaultPage();
    PageFormat pageformat = pjob.pageDialog(defaultPF);
    pjob.setPrintable(globals.getGraphicsManager().getCurrentFigure(), pageformat);

    // somebody hit cancel
    if (pageformat != defaultPF) {
      debugLine("print: pageformat changed");
      // return null;
    }

    boolean status = pjob.printDialog();

    if (!status) {
      debugLine("print: cancelled");
      return null;
    }

    try {
      pjob.print();
    } catch (PrinterException e) {
      debugLine("print: Printer Exception");
      globals.getInterpreter().displayText("print: Printer Exception");
    }

    // getGraphicsManager().getCurrentFigure().print();

    return null;
  }
Exemplo n.º 3
0
  public static PageFormat getPageFormat(PageFormat pf, Properties settings, Frame frame) {
    PageFormat npf;
    if (Utils.getAsBoolean(
        settings.getProperty("useSystemPageDialog", "false"))) // $NON-NLS-1$ //$NON-NLS-2$
    {
      PrinterJob pj = PrinterJob.getPrinterJob();
      npf = pj.pageDialog(pf == null ? new PageFormat() : pf);
      pj.cancel(); // TODO:figure out if this is needed...
    } else {
      PageSetupDialog psd = new PageSetupDialog(frame, false);
      psd.showDialog(pf);
      npf = psd.getPageFormat();
    }

    return npf;
  }
 /*
  * Calls up printing prompt for gnomon.
  */
 public void printGnomon() {
   PrinterJob pjob = PrinterJob.getPrinterJob();
   PageFormat preformat = pjob.defaultPage();
   PageFormat postformat = pjob.pageDialog(preformat);
   // If user does not hit cancel then print.
   if (preformat != postformat) {
     // Set print component
     pjob.setPrintable(
         new SundialPrint(frame), postformat); // this is what's needed to integrate it
     if (pjob.printDialog()) {
       try {
         pjob.print();
       } catch (PrinterException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
       }
     }
   }
 }
 /**
  * DOC
  *
  * @param view
  */
 public static void pageSetup(View view) {
   PrinterJob prnJob = getPrintJob("PageSetupOnly"); // $NON-NLS-1$
   if (prnJob.pageDialog(format) != null) {
     savePrintSpec();
   }
 }
Exemplo n.º 6
0
 // {{{ pageSetup() method
 public static void pageSetup(View view) {
   PrinterJob prnJob = getPrintJob("PageSetupOnly");
   if (prnJob.pageDialog(format) != null) savePrintSpec();
 } // }}}
Exemplo n.º 7
0
  /** Convenience method */
  public void print() throws PrinterException {
    //
    // Now, request the transcoder to actually perform the
    // printing job.
    //
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    PageFormat pageFormat = printerJob.defaultPage();

    //
    // Set the page parameters from the hints
    //
    Paper paper = pageFormat.getPaper();

    Float pageWidth = (Float) hints.get(KEY_PAGE_WIDTH);
    Float pageHeight = (Float) hints.get(KEY_PAGE_HEIGHT);
    if (pageWidth != null) {
      paper.setSize(pageWidth.floatValue(), paper.getHeight());
    }
    if (pageHeight != null) {
      paper.setSize(paper.getWidth(), pageHeight.floatValue());
    }

    float x = 0, y = 0;
    float width = (float) paper.getWidth();
    float height = (float) paper.getHeight();

    Float leftMargin = (Float) hints.get(KEY_MARGIN_LEFT);
    Float topMargin = (Float) hints.get(KEY_MARGIN_TOP);
    Float rightMargin = (Float) hints.get(KEY_MARGIN_RIGHT);
    Float bottomMargin = (Float) hints.get(KEY_MARGIN_BOTTOM);

    if (leftMargin != null) {
      x = leftMargin.floatValue();
      width -= leftMargin.floatValue();
    }
    if (topMargin != null) {
      y = topMargin.floatValue();
      height -= topMargin.floatValue();
    }
    if (rightMargin != null) {
      width -= rightMargin.floatValue();
    }
    if (bottomMargin != null) {
      height -= bottomMargin.floatValue();
    }

    paper.setImageableArea(x, y, width, height);

    String pageOrientation = (String) hints.get(KEY_PAGE_ORIENTATION);
    if (VALUE_PAGE_ORIENTATION_PORTRAIT.equalsIgnoreCase(pageOrientation)) {
      pageFormat.setOrientation(PageFormat.PORTRAIT);
    } else if (VALUE_PAGE_ORIENTATION_LANDSCAPE.equalsIgnoreCase(pageOrientation)) {
      pageFormat.setOrientation(PageFormat.LANDSCAPE);
    } else if (VALUE_PAGE_ORIENTATION_REVERSE_LANDSCAPE.equalsIgnoreCase(pageOrientation)) {
      pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE);
    }

    pageFormat.setPaper(paper);
    pageFormat = printerJob.validatePage(pageFormat);

    //
    // If required, pop up a dialog to adjust the page format
    //
    Boolean showPageFormat = (Boolean) hints.get(KEY_SHOW_PAGE_DIALOG);
    if ((showPageFormat != null) && (showPageFormat.booleanValue())) {
      PageFormat tmpPageFormat = printerJob.pageDialog(pageFormat);
      if (tmpPageFormat == pageFormat) {
        // Dialog was cancelled, meaning that the print process should
        // be stopped.
        return;
      }

      pageFormat = tmpPageFormat;
    }

    // Set printable before showing printer dialog so
    // it can update the pageFormat if it wishes...
    printerJob.setPrintable(this, pageFormat);

    //
    // If required, pop up a dialog to select the printer
    //
    Boolean showPrinterDialog;
    showPrinterDialog = (Boolean) hints.get(KEY_SHOW_PRINTER_DIALOG);
    if (showPrinterDialog != null && showPrinterDialog.booleanValue()) {
      if (!printerJob.printDialog()) {
        // Dialog was cancelled, meaning that the print process
        // should be stopped.
        return;
      }
    }

    // Print now
    printerJob.print();
  }
Exemplo n.º 8
0
 /**
  * Run the system page format dialog using the last used PageFormat as the default setup. If user
  * hits cancel on the dialog, null is returned.
  */
 private PageFormat getPageFormatInteractive(PrinterJob job, Rectangle2D bounds) {
   PageFormat initial = getPageFormat(job, bounds);
   PageFormat result = job.pageDialog(initial);
   if (result != initial) return pageFormat = result;
   else return null; // dialog was canceled
 }
Exemplo n.º 9
0
 /* performs page setup */
 public synchronized void performAction() {
   PrintSettings ps = (PrintSettings) PrintSettings.findObject(PrintSettings.class, true);
   PrinterJob pj = PrinterJob.getPrinterJob();
   ps.setPageFormat(pj.pageDialog(PrintSettings.getPageFormat(pj)));
 }
 /**
  * Richtet die Seite ein
  *
  * @return true, if successful
  */
 public boolean setupPageFormat() {
   PageFormat defaultPF = pjob.defaultPage();
   this.pageformat = pjob.pageDialog(defaultPF);
   pjob.setPrintable(this, this.pageformat);
   return (this.pageformat != defaultPF);
 }