Пример #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);
                        }
                }
        }
Пример #2
0
 public void pageableJob(Pageable pageable) throws PrintException {
   try {
     synchronized (this) {
       if (job != null) { // shouldn't happen
         throw new PrintException("already printing");
       } else {
         job = new sun.awt.windows.WPrinterJob();
       }
     }
     PrintService svc = getPrintService();
     job.setPrintService(svc);
     if (copies == 0) {
       Copies c = (Copies) svc.getDefaultAttributeValue(Copies.class);
       copies = c.getValue();
     }
     job.setCopies(copies);
     job.setJobName(jobName);
     job.setPageable(pageable);
     job.print(reqAttrSet);
     notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
     return;
   } catch (PrinterException pe) {
     notifyEvent(PrintJobEvent.JOB_FAILED);
     throw new PrintException(pe);
   } finally {
     printReturned = true;
     notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
   }
 }
  /*

  public void printData() {

  getJMenuBar().repaint();

  try {

  PrinterJob prnJob = PrinterJob.getPrinterJob();

  prnJob.setPrintable(m_panel);

  if (!prnJob.printDialog())

  return;

  setCursor( Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

  prnJob.print();

  setCursor( Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

  JOptionPane.showMessageDialog(this, "Printing completed successfully", "JPEGEditor2",

  JOptionPane.INFORMATION_MESSAGE);

  }

  catch (PrinterException e) {

  e.printStackTrace();

  System.err.println("Printing error: "+e.toString());

  }

  }

  */
  public void printData(Image im) {

    Printer p = new Printer(im);

    try {

      java.awt.print.PrinterJob prnJob = java.awt.print.PrinterJob.getPrinterJob();

      prnJob.setPrintable(p);

      if (!prnJob.printDialog()) {
        return;
      }

      setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));

      prnJob.print();

      setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));

      javax.swing.JOptionPane.showMessageDialog(
          this,
          "Printing completed successfully",
          "JPEGEditor2",
          javax.swing.JOptionPane.INFORMATION_MESSAGE);

    } catch (java.awt.print.PrinterException e) {

      e.printStackTrace();

      System.err.println("Printing_error:_" + e.toString());
    }
  }
  private void jButton1ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    try {
      /*
      jTable1.print();
       */
      org.jdesktop.application.ResourceMap resourceMap =
          org.jdesktop.application.Application.getInstance(bankingapp.BankingApp.class)
              .getContext()
              .getResourceMap(ReportCashBook.class);
      // jTable1.print(PrintMode.FIT_WIDTH,new
      // MessageFormat(resourceMap.getString("print.first")+"-{0}-"+resourceMap.getString("print.second")+resourceMap.getString("print.third")),null);

      PrinterJob job = PrinterJob.getPrinterJob();
      MessageFormat[] header = new MessageFormat[6];
      header[0] = new MessageFormat("");
      header[1] =
          new MessageFormat("                      " + resourceMap.getString("print.first"));
      header[2] =
          new MessageFormat("                      " + resourceMap.getString("print.second"));
      header[3] =
          new MessageFormat("                      " + resourceMap.getString("print.third"));
      header[4] = new MessageFormat("");
      header[5] = new MessageFormat("                                                  Report");
      MessageFormat[] footer = new MessageFormat[1];
      footer[0] = new MessageFormat("--{0}--");
      job.setPrintable(new MyTablePrintable(jTable1, PrintMode.FIT_WIDTH, header, footer));
      job.print();
    } catch (PrinterException ex) {
      Logger.getLogger(ReportCashBook.class.getName()).log(Level.SEVERE, null, ex);
    }
  } // GEN-LAST:event_jButton1ActionPerformed
Пример #5
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (SHEET_COMMAND.equals(e.getActionCommand())) {
     new PreviewLoader((URI) sheetBox.getSelectedItem()).execute();
   } else if (PAGE_COMMAND.equals(e.getActionCommand())) {
     previewPanel.setPage(pageBox.getSelectedIndex());
   } else if (ZOOM_COMMAND.equals(e.getActionCommand())) {
     Double zoom = (Double) zoomBox.getSelectedItem();
     previewPanel.setScaleFactor(zoom);
   } else if (ZOOM_IN_COMMAND.equals(e.getActionCommand())) {
     Double zoom = (Double) zoomBox.getSelectedItem();
     zoomBox.setSelectedItem(zoom * ZOOM_MULTIPLIER);
   } else if (ZOOM_OUT_COMMAND.equals(e.getActionCommand())) {
     Double zoom = (Double) zoomBox.getSelectedItem();
     zoomBox.setSelectedItem(zoom / ZOOM_MULTIPLIER);
   } else if (PRINT_COMMAND.equals(e.getActionCommand())) {
     PrinterJob printerJob = PrinterJob.getPrinterJob();
     printerJob.setPageable(pageable);
     if (printerJob.printDialog()) {
       try {
         printerJob.print();
         dispose();
       } catch (PrinterException ex) {
         String message = "Could not print " + character.getNameRef().get();
         Logging.errorPrint(message, ex);
         frame.showErrorMessage(Constants.APPLICATION_NAME, message);
       }
     }
   } else if (CANCEL_COMMAND.equals(e.getActionCommand())) {
     dispose();
   }
 }
  public synchronized void printThisInvoice(JTable tbl) {
    this.tblprint = tbl;
    // this.totrecords = totrec;

    PrinterJob pj = PrinterJob.getPrinterJob();

    PageFormat pf = new PageFormat();

    Paper paper = new Paper();

    paper.setSize(WIDTH, HEIGHT);
    paper.setImageableArea(0, 0, WIDTH, HEIGHT);
    pf.setPaper(paper);
    pj.setPrintable(this, pf);

    // if (pj.printDialog()) {
    try {
      System.out.println("Starting........");
      pj.print();
      System.out.println("Done!......");
    } catch (Exception e) {
      System.out.println("Error: Print Error: " + e);
      e.printStackTrace();
    }
    //  }

  }
  public void PrintSingles() {
    if (Mechs.size() == 0) {
      return;
    }

    page.setPaper(paper);

    if (useDialog) {
      if (Mechs.size() == 1) {
        if (!PrintDialog((PrintMech) Mechs.get(0))) return;
      } else {
        if (!BatchDialog()) return;
      }
    }

    for (int index = 0; index <= Mechs.size() - 1; index++) {
      PrintMech pm = (PrintMech) Mechs.get(index);
      job.setJobName(pm.CurMech.GetFullName().trim());
      job.setPrintable(pm);
      try {
        job.print();
      } catch (PrinterException ex) {
        Logger.getLogger(Printer.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
Пример #8
0
    private void runDialogsAndPrint() throws java.awt.print.PrinterException {
      out("job starting for " + this.map);
      PrinterJob job = getPrinterJob();
      out("got OS job: " + tufts.Util.tags(job));
      if (job.printDialog()) {
        out("printDialog ran, waiting for format...");
        // PageFormat format = getPageFormat(job, bounds);
        PageFormat format = getPageFormatInteractive(job, bounds);
        out("format: " + outpf(format));
        if (format != null) {
          job.setJobName(jobName);
          job.setPrintable(this, format);
          // try setting pageable to see if it then
          // skips system dialog (we'd like a no-dialog option)
          // job.setPrintService(job.getPrintService());

          // this only *sometimes* works as a workaround
          // for the vue ap mysteriously being raised above
          // the system print dialog...
          // VUE.frame.toBack();

          out("printing...");
          job.print();
        }
      }
      out("job complete.");
    }
  public void Print() {
    // If they didn't provide a mech exit
    if (Mechs.size() == 0) {
      return;
    }

    job.setJobName(jobName.trim());

    // Here is where we will show the print dialog, determine if it's a single mech or multiples
    if (useDialog) {
      if (Mechs.size() == 1) {
        if (!PrintDialog((PrintMech) Mechs.get(0))) return;
      } else {
        if (!BatchDialog()) return;
      }
    }

    // start building the print objects necessary
    GeneratePrints();

    job.setPageable(pages);
    boolean DoPrint = job.printDialog();
    if (DoPrint) {
      try {
        job.print();
      } catch (PrinterException e) {
        System.err.println(e.getMessage());
        System.out.println(e.getStackTrace());
      }

      Mechs.clear();
    }
  }
Пример #10
0
  /**
   * Starts the print operation. This is quite expensive, and is kicked off in a separate thread.
   */
  public void print() {
    final PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(this);

    // make a local copy of the object to be printed, for use by the print thread
    // below...

    final Component printMe = getPrintComponent();

    Thread worker =
        new Thread() {
          public void run() {
            if (job.printDialog()) {
              try {
                // need to make sure that no other thread tries to
                // run a print job and set printCompnent at the same
                // time...
                synchronized (this) {
                  printComponent = printMe;
                  job.print();
                  printComponent = null;
                }
              } catch (Exception ex) {
                log.warning("error printing: " + ex);
              }
            }
          }
        };
    worker.start();
  }
Пример #11
0
 public void print() {
   PrinterJob job = PrinterJob.getPrinterJob();
   int printFontSize = Config.getPropInteger("bluej.fontsize.printText", 10);
   Font font = new Font("Monospaced", Font.PLAIN, printFontSize);
   if (job.printDialog()) {
     TerminalPrinter.printTerminal(job, text, job.defaultPage(), font);
   }
 }
Пример #12
0
 public void print() {
   PrinterJob printJob = PrinterJob.getPrinterJob();
   printJob.setPrintable(this);
   if (printJob.printDialog())
     try {
       printJob.print();
     } catch (PrinterException pe) {
       System.err.println("Printing error: " + pe);
     }
 }
Пример #13
0
 /** @param args */
 public static void main(String[] args) throws Throwable {
   PrinterJob job = PrinterJob.getPrinterJob();
   PageFormat format = new PageFormat();
   format.setOrientation(format.PORTRAIT);
   Paper paper = new Paper();
   paper.setSize(3 * 72, 5 * 72);
   paper.setImageableArea(0, 0, 1200 * 3, 1200 * 5);
   job.setPrintable(new TestPrintable(), format);
   job.print();
 }
Пример #14
0
 public void print() {
   PrinterJob printJob = PrinterJob.getPrinterJob();
   printJob.setPrintable(this);
   if (printJob.printDialog())
     try {
       printJob.print();
     } catch (PrinterException pe) {
       ExceptionManager.doError("Error printing: ", pe);
     }
 }
Пример #15
0
  public void printableJob(Printable printable) throws PrintException {
    try {
      synchronized (this) {
        if (job != null) { // shouldn't happen
          throw new PrintException("already printing");
        } else {
          job = new sun.awt.windows.WPrinterJob();
        }
      }
      PrintService svc = getPrintService();
      job.setPrintService(svc);
      if (copies == 0) {
        Copies c = (Copies) svc.getDefaultAttributeValue(Copies.class);
        copies = c.getValue();
      }

      if (mediaName == null) {
        Object media = svc.getDefaultAttributeValue(Media.class);
        if (media instanceof MediaSizeName) {
          mediaName = (MediaSizeName) media;
          mediaSize = MediaSize.getMediaSizeForName(mediaName);
        }
      }

      if (orient == null) {
        orient = (OrientationRequested) svc.getDefaultAttributeValue(OrientationRequested.class);
      }

      job.setCopies(copies);
      job.setJobName(jobName);
      PageFormat pf = new PageFormat();
      if (mediaSize != null) {
        Paper p = new Paper();
        p.setSize(mediaSize.getX(MediaSize.INCH) * 72.0, mediaSize.getY(MediaSize.INCH) * 72.0);
        p.setImageableArea(72.0, 72.0, p.getWidth() - 144.0, p.getHeight() - 144.0);
        pf.setPaper(p);
      }
      if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
        pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
      } else if (orient == OrientationRequested.LANDSCAPE) {
        pf.setOrientation(PageFormat.LANDSCAPE);
      }
      job.setPrintable(printable, pf);
      job.print(reqAttrSet);
      notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
      return;
    } catch (PrinterException pe) {
      notifyEvent(PrintJobEvent.JOB_FAILED);
      throw new PrintException(pe);
    } finally {
      printReturned = true;
      notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
  }
Пример #16
0
 // Graphically print the component to the printer
 protected synchronized void printComponent(Component c) {
   printTarget = c;
   PrinterJob pj = PrinterJob.getPrinterJob();
   pj.setPrintable(this);
   pj.printDialog();
   try {
     pj.print();
   } catch (Exception printException) {
     printException.printStackTrace();
   }
 }
Пример #17
0
  /**
   * Show a dialog for printing the current drawing.
   *
   * @param fff the parent frame which will be used for dialogs and message boxes.
   * @param CCr the CircuitPanel containing the drawing to be exported.
   */
  public void printDrawing(JFrame fff, CircuitPanel CCr) {
    cc = CCr;
    DialogPrint dp = new DialogPrint(fff);
    dp.setMirror(printMirror);
    dp.setFit(printFitToPage);
    dp.setBW(printBlackWhite);
    dp.setLandscape(printLandscape);
    dp.setVisible(true);

    // Get some information about the printing options.
    printMirror = dp.getMirror();
    printFitToPage = dp.getFit();
    printLandscape = dp.getLandscape();
    printBlackWhite = dp.getBW();

    Vector<LayerDesc> ol = cc.dmp.getLayers();
    if (dp.shouldPrint()) {
      if (printBlackWhite) {
        Vector<LayerDesc> v = new Vector<LayerDesc>();

        // Here we create an alternative array of layers in
        // which all colors are pitch black. This may be
        // useful for PCB's.

        for (int i = 0; i < LayerDesc.MAX_LAYERS; ++i)
          v.add(
              new LayerDesc(
                  new ColorSwing(Color.black),
                  ((LayerDesc) ol.get(i)).getVisible(),
                  "B/W",
                  ((LayerDesc) ol.get(i)).getAlpha()));
        cc.dmp.setLayers(v);
      }
      PrinterJob job = PrinterJob.getPrinterJob();
      job.setPrintable(this);
      boolean ok = job.printDialog();
      if (ok) {
        try {
          PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
          // Set the correct printing orientation.
          if (printLandscape) {
            aset.add(OrientationRequested.LANDSCAPE);
          } else {
            aset.add(OrientationRequested.PORTRAIT);
          }
          job.print(aset);
        } catch (PrinterException ex) {
          // The job did not successfully complete
          JOptionPane.showMessageDialog(fff, Globals.messages.getString("Print_uncomplete"));
        }
      }
      cc.dmp.setLayers(ol);
    }
  }
Пример #18
0
 /** print the canvas scaled with factor <code>scale</code> */
 public void print(double scale) {
   printScale = scale;
   PrinterJob printJob = PrinterJob.getPrinterJob();
   printJob.setPrintable(this);
   if (printJob.printDialog()) {
     try {
       printJob.print();
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   }
 }
Пример #19
0
 private PrintableBase doPrintAutoImpl(
     Container cont,
     PrinterJob job,
     StreamPrintService ps,
     int pOrientation,
     Paper paper,
     int offscrnImageType,
     int dpi,
     int numSamples,
     int tileWidth,
     int tileHeight,
     boolean resizeWithinPrintTest) {
   try {
     PageFormat pageFormat = job.defaultPage();
     if (null != paper) {
       /**
        * Paper paper = new Paper(); paper.setSize(500,500); // Large Address Dimension
        * paper.setImageableArea(20, 20, 450, 420);
        */
       pageFormat.setPaper(paper);
     }
     pageFormat.setOrientation(pOrientation); // PageFormat.LANDSCAPE or PageFormat.PORTRAIT
     job.setPrintService(ps);
     final PrintableBase printable;
     if (0 < offscrnImageType) {
       printable =
           new OffscreenPrintable(
               job,
               cont,
               dpi,
               numSamples,
               tileWidth,
               tileHeight,
               offscrnImageType,
               getPrintFilename(
                   offscrnImageType,
                   dpi,
                   numSamples,
                   tileWidth,
                   tileHeight,
                   "png",
                   resizeWithinPrintTest));
     } else {
       printable = new OnscreenPrintable(job, cont, dpi, numSamples, tileWidth, tileHeight);
     }
     printable.job.setPrintable(printable, pageFormat);
     doPrintImpl(printable, resizeWithinPrintTest);
     return printable;
   } catch (PrinterException pe) {
     pe.printStackTrace();
     return null;
   }
 }
Пример #20
0
 public void actionPerformed(ActionEvent e) {
   PrinterJob job = PrinterJob.getPrinterJob();
   job.setPrintable(canvas);
   boolean ok = job.printDialog();
   if (ok) {
     try {
       job.print();
     } catch (PrinterException ex) {
       /* The job did not successfully complete */
     }
   }
 }
Пример #21
0
 @Action
 public void printTable() {
   PrinterJob pj = PrinterJob.getPrinterJob();
   pj.setPrintable(this);
   if (pj.printDialog()) {
     try {
       pj.print();
       SecurityLog.addEntry("User printed a user report");
     } catch (Exception PrintException) {
       System.out.println(PrintException.getMessage());
     }
   }
 }
  private static void print(final Image img, String size) {
    PrinterJob printjob = PrinterJob.getPrinterJob();
    printjob.setJobName("Print");

    ImgPrinter printable = new ImgPrinter(img);

    try {
      System.out.println("Printing.");
      printable.printPage(size);
    } catch (Exception ex) {
      System.out.println("NO PAGE FOUND." + ex);
    }
  }
  public void print(HashPrintRequestAttributeSet aset) {

    try {
      for (int pos = 0; pos < smallCraftList.size(); pos++) {
        PrinterJob pj = PrinterJob.getPrinterJob();
        pj.setPrintService(masterPrintJob.getPrintService());

        aset.add(PrintQuality.HIGH);

        PageFormat pageFormat = new PageFormat();
        pageFormat = pj.getPageFormat(null);

        Paper p = pageFormat.getPaper();
        p.setImageableArea(0, 0, p.getWidth(), p.getHeight());
        pageFormat.setPaper(p);

        pj.setPrintable(this, pageFormat);
        smallCraft = smallCraftList.get(pos);
        pj.setJobName(smallCraft.getChassis() + " " + smallCraft.getModel());

        try {
          pj.print(aset);
        } catch (Exception ex) {
          ex.printStackTrace();
        }
        System.gc();
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Пример #24
0
  public void actionPerformed(ActionEvent e) {

    PrinterJob pj = PrinterJob.getPrinterJob();

    if (pj != null && pj.printDialog()) {
      pj.setPrintable(c);
      try {
        pj.print();
      } catch (PrinterException pe) {
      } finally {
        System.err.println("PRINT RETURNED");
      }
    }
  }
  public void PrintBattleforce() {
    if (battleforces.size() == 0) {
      return;
    }
    pages = new Book();
    page.setPaper(paper);

    if (jobName.isEmpty()) {
      jobName = "BattleForce";
    }
    if (battleforces.size() == 1) {
      BattleForce bf = ((BattleforcePrinter) battleforces.get(0)).getBattleforce();
      if (!bf.ForceName.isEmpty()) {
        jobName = bf.ForceName.trim();
      }
    }

    job.setJobName(jobName);

    if (useDialog) {
      for (int i = 0; i < battleforces.size(); i++) {
        BattleforcePrinter bf = (BattleforcePrinter) battleforces.get(i);
        dlgPrintBattleforce pForce =
            new dlgPrintBattleforce((javax.swing.JFrame) Parent, true, bf.getBattleforce());
        pForce.setLocationRelativeTo((javax.swing.JFrame) Parent);
        pForce.setVisible(true);
        if (!pForce.Result) {
          return;
        }

        bf.setType(pForce.Sheet);
      }
    }

    for (int i = 0; i < battleforces.size(); i++) {
      pages.append((BattleforcePrinter) battleforces.get(i), page);
    }

    job.setPageable(pages);
    boolean DoPrint = job.printDialog();
    if (DoPrint) {
      try {
        job.print();
      } catch (PrinterException e) {
        System.err.println(e.getMessage());
        System.out.println(e.getStackTrace());
      }
    }
  }
  public static void print(JTextPane textPane) {

    PrinterJob job = PrinterJob.getPrinterJob();
    PrintableHandler printable = new PrintableHandler(textPane);
    job.setPrintable(printable);
    boolean print = job.printDialog();

    if (print) {
      try {
        job.print();
      } catch (PrinterException ex) {
        ex.printStackTrace();
      }
    }
  }
 private void printPlot() {
   PrinterJob job = PrinterJob.getPrinterJob();
   PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
   // PageFormat pf = job.pageDialog(aset);
   job.setPrintable(this);
   boolean ok = job.printDialog(aset);
   if (ok) {
     try {
       job.print(aset);
     } catch (PrinterException ex) {
       // showFeedback("An error was encountered while printing." + ex);
       /* The job did not successfully complete */
     }
   }
 }
  // 从预览中点击打印按钮时执行此函数打印
  public void printBinaryPicture() {

    int formatIndex = jComboBox_deviceName.getSelectedIndex();
    int number = Integer.parseInt(getBinaryPrintNum());

    int index = jComboBox_deviceName.getSelectedIndex();
    String deviceName = getDeviceName();
    String deviceType = getDeviceModel();
    String deviceID = getDeviceID(); // MAC
    String manageIP = getManageIP();
    String deviceSN = getDeviceSN();
    // String deviceVresion = getDeviceVersion();
    String power = getPower();
    String officialWebsite = getOfficialWebsite();

    Book book = new Book();
    PageFormat pf = new MyPaperFormat(mainUi);

    // 生成二维码
    productPowerLineQRCode(head, deviceID, deviceSN, manageIP);

    printInfo printinfo = mainUi.new printInfo();

    printinfo.setdeviceID(deviceID);
    printinfo.setManageIP(manageIP);
    printinfo.setDeviceSN(deviceSN);

    printinfo.setdeviceName(deviceName);
    printinfo.setdeviceType(deviceType);
    // printinfo.setDeviceVresion(deviceVresion);
    printinfo.setPower(power);
    printinfo.setOfficialWebsite(officialWebsite);
    printinfo.setCompany(companyInit);
    printinfo.setPowerLineIndex(index);

    myPrint = new MyPrint(printinfo);
    book.append(myPrint, pf);
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPageable(book);
    try {
      if (true) {
        job.print();
        mainUi.appendTextareaText(mainUi.jTextArea_status, "\n执行打印");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #29
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;
  }
Пример #30
0
  /**
   * Takes a printer name and find the associated PrintService. If no match can be made it randomly
   * picks the first printer listed from the call to lookupPrintServices.
   *
   * @param printerName
   * @return PrintService referenced by the printerName
   */
  public PrintService getPrinterInternal(final String printerName, final String lastPrinterName) {
    // The parameter value was not provided, and we are allowed to create
    // user interface forms

    PrintService[] services = PrinterJob.lookupPrintServices();
    for (PrintService element : services) {
      if (element.getName().equals(printerName)) {
        return element;
      }
    }
    if (feedbackAllowed()) {
      // If it's not valid then lets find one and end this current run.
      ArrayList values = new ArrayList();
      for (PrintService element : services) {
        String value = element.getName();
        values.add(value);
      }
      createFeedbackParameter(
          StandardSettings.PRINTER_NAME,
          Messages.getInstance().getString("PrintComponent.USER_PRINTER_NAME"),
          "",
          lastPrinterName,
          values,
          null,
          "select"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      promptNeeded();
      return null;
    }
    return services[0];
  }