Java 类javax.print.ServiceUI 实例源码

项目:openjdk-jdk10    文件:ServiceDlgPageRangeTest.java   
/**
 * Starts the application.
 */
public static void printTest() {

    System.out.println("\nDefault print service: " +
                          PrintServiceLookup.lookupDefaultPrintService());
    System.out.println("is flavor: "+flavor+" supported? "+
                                 services[0].isDocFlavorSupported(flavor));
    System.out.println("is Page Ranges category supported? "+
               services[0].isAttributeCategorySupported(PageRanges.class));
    System.out.println("is PageRanges[2] value supported ? "+
               services[0].isAttributeValueSupported(
                                         new PageRanges(2), flavor, null));

    HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();
    //prSet.add(new PageRanges(2));
    PrintService selService = ServiceUI.printDialog(null, 200, 200,
                                      services, services[0], flavor, prSet);

    System.out.println("\nSelected Values\n");
    Attribute attr[] = prSet.toArray();
    for (int x = 0; x < attr.length; x ++) {
        System.out.println("Attribute: " + attr[x].getName() +
                                                    " Value: " + attr[x]);
    }
}
项目:javify    文件:JavaPrinterJob.java   
/**
 * Displays a dialog box to the user which allows the print job
 * attributes to be modified.
 *
 * @return <code>false</code> if the user cancels the dialog box,
 * <code>true</code> otherwise.
 */
public boolean printDialog(PrintRequestAttributeSet attributes)
  throws HeadlessException
{
  PrintService chosenPrinter = ServiceUI.printDialog
    (null, 50, 50, services, null,
     DocFlavor.INPUT_STREAM.POSTSCRIPT, attributes);

  getPageAttributes();

  if( chosenPrinter != null )
    {
      try
        {
          setPrintService( chosenPrinter );
        }
      catch(PrinterException pe)
        {
          // Should not happen.
        }
      return true;
    }
  return false;
}
项目:jvm-stm    文件:JavaPrinterJob.java   
/**
  * Displays a dialog box to the user which allows the print job
  * attributes to be modified.
  *
  * @return <code>false</code> if the user cancels the dialog box,
  * <code>true</code> otherwise.
  */
 public boolean printDialog(PrintRequestAttributeSet attributes)
   throws HeadlessException
 {
   PrintService chosenPrinter = ServiceUI.printDialog
     (null, 50, 50, services, null, 
      DocFlavor.INPUT_STREAM.POSTSCRIPT, attributes);

   getPageAttributes();

   if( chosenPrinter != null )
     {
try
  {
    setPrintService( chosenPrinter );
  }
catch(PrinterException pe)
  {
    // Should not happen.
  }
return true;
     }
   return false;
 }
项目:RipplePower    文件:PrintImageOutput.java   
public static boolean out(BufferedImage image) {
    try {
        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        PrintRequestAttributeSet requestAttributeSet = new HashPrintRequestAttributeSet();
        requestAttributeSet.add(MediaSizeName.ISO_A4);
        requestAttributeSet.add(new JobName(LSystem.applicationName + LSystem.getTime(), Locale.ENGLISH));
        PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, requestAttributeSet);
        PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
        PrintService service = ServiceUI.printDialog(null, 100, 100, services, defaultService, flavor,
                requestAttributeSet);
        if (service != null) {
            DocPrintJob job = service.createPrintJob();
            SimpleDoc doc = new SimpleDoc(new BufferedImagePrintable(image), flavor, null);
            job.print(doc, requestAttributeSet);
        }
    } catch (Exception e) {
        return false;
    }
    return true;
}
项目:cn1    文件:PrinterJobImpl.java   
@Override
public boolean printDialog(final PrintRequestAttributeSet attributes)
                throws HeadlessException {
    checkHeadless();

    if (attributes == null) {
        throw new NullPointerException();
    }

    final PrintRequestAttributeSet attrs = mergeAttrs(attributes);
    final Rectangle screen = GraphicsEnvironment
                    .getLocalGraphicsEnvironment().getDefaultScreenDevice()
                    .getDefaultConfiguration().getBounds();
    final PrintService newService = ServiceUI.printDialog(null,
                    screen.width / 3, screen.height / 3,
                    lookupPrintServices(), getPrintService(),
                    DocFlavor.SERVICE_FORMATTED.PRINTABLE, attrs);

    if (newService != null) {
        printService = newService;
    }

    return newService != null;
}
项目:JamVM-PH    文件:JavaPrinterJob.java   
/**
  * Displays a dialog box to the user which allows the print job
  * attributes to be modified.
  *
  * @return <code>false</code> if the user cancels the dialog box,
  * <code>true</code> otherwise.
  */
 public boolean printDialog(PrintRequestAttributeSet attributes)
   throws HeadlessException
 {
   PrintService chosenPrinter = ServiceUI.printDialog
     (null, 50, 50, services, null, 
      DocFlavor.INPUT_STREAM.POSTSCRIPT, attributes);

   getPageAttributes();

   if( chosenPrinter != null )
     {
try
  {
    setPrintService( chosenPrinter );
  }
catch(PrinterException pe)
  {
    // Should not happen.
  }
return true;
     }
   return false;
 }
项目:classpath    文件:JavaPrinterJob.java   
/**
 * Displays a dialog box to the user which allows the print job
 * attributes to be modified.
 *
 * @return <code>false</code> if the user cancels the dialog box,
 * <code>true</code> otherwise.
 */
public boolean printDialog(PrintRequestAttributeSet attributes)
  throws HeadlessException
{
  PrintService chosenPrinter = ServiceUI.printDialog
    (null, 50, 50, services, null,
     DocFlavor.INPUT_STREAM.POSTSCRIPT, attributes);

  getPageAttributes();

  if( chosenPrinter != null )
    {
      try
        {
          setPrintService( chosenPrinter );
        }
      catch(PrinterException pe)
        {
          // Should not happen.
        }
      return true;
    }
  return false;
}
项目:freeVM    文件:PrinterJobImpl.java   
@Override
public boolean printDialog(final PrintRequestAttributeSet attributes)
                throws HeadlessException {
    checkHeadless();

    if (attributes == null) {
        throw new NullPointerException();
    }

    final PrintRequestAttributeSet attrs = mergeAttrs(attributes);
    final Rectangle screen = GraphicsEnvironment
                    .getLocalGraphicsEnvironment().getDefaultScreenDevice()
                    .getDefaultConfiguration().getBounds();
    final PrintService newService = ServiceUI.printDialog(null,
                    screen.width / 3, screen.height / 3,
                    lookupPrintServices(), getPrintService(),
                    DocFlavor.SERVICE_FORMATTED.PRINTABLE, attrs);

    if (newService != null) {
        printService = newService;
    }

    return newService != null;
}
项目:osp    文件:PrintUtils.java   
public static void printComponent(Component c) {
  // Get a list of all printers that can handle Printable objects.
  DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
  PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null);
  // Set some define printing attributes
  PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
  //printAttributes.add(OrientationRequested.LANDSCAPE); // landscape mode
  printAttributes.add(OrientationRequested.PORTRAIT);                    // PORTRAIT mode
  printAttributes.add(Chromaticity.MONOCHROME);                          // print in mono
  printAttributes.add(javax.print.attribute.standard.PrintQuality.HIGH); // highest resolution
  // Display a dialog that allows the user to select one of the
  // available printers and to edit the default attributes
  PrintService service = ServiceUI.printDialog(null, 100, 100, services, null, null, printAttributes);
  // If the user canceled, don't do anything
  if(service==null) {
    return;
  }
  // Now call a method defined below to finish the printing
  printToService(c, service, printAttributes);
}
项目:openjdk-jdk10    文件:ServiceDlgSheetCollateTest.java   
private static void printTest() {
    ServiceDlgSheetCollateTest pd = new ServiceDlgSheetCollateTest();
    DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;
    //DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
    PrintService defService = null, service[] = null;
    defService = PrintServiceLookup.lookupDefaultPrintService();
    service = PrintServiceLookup.lookupPrintServices(flavor, null);

    if ((service == null) || (service.length == 0)) {
        throw new RuntimeException("No Printer services found");
    }
    if (defService != null) {
        System.out.println("\nDefault print service: " + service );
        System.out.println("is flavor: "+flavor+" supported? "+
                        defService.isDocFlavorSupported(flavor));
        System.out.println("is SheetCollate category supported? "+
              defService.isAttributeCategorySupported(SheetCollate.class));
        System.out.println("is SheetCollate.COLLATED value supported ? "+
              defService.isAttributeValueSupported(SheetCollate.COLLATED,
                                                        flavor, null));
    }
    HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();
    try {
        PrintService selService = ServiceUI.printDialog(null, 200, 200, service, defService, flavor, prSet);
    } catch (IllegalArgumentException ia) {
        System.out.println("Exception thrown : " + ia);
    }

    System.out.println("\nSelected Values\n");
    Attribute attr[] = prSet.toArray();
    for (int x = 0; x < attr.length; x ++) {
        System.out.println("Attribute: " + attr[x].getName() + " Value: " + attr[x]);
    }

}
项目:openjdk-jdk10    文件:ServiceDialogValidateTest.java   
private static void printTest() {
    PrintService defService = null, service[] = null;
    HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();
    DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;

    service = PrintServiceLookup.lookupPrintServices(flavor, null);
    defService = PrintServiceLookup.lookupDefaultPrintService();

    if ((service == null) || (service.length == 0)) {
        throw new RuntimeException("No Printer services found");
    }
    File f = new File("output.ps");
    Destination d = new Destination(f.toURI());
    prSet.add(d);
    if (defService != null) {
        System.out.println("isAttrCategory Supported? " +
                defService.isAttributeCategorySupported(Destination.class));
        System.out.println("isAttrValue Supported? " +
                defService.isAttributeValueSupported(d, flavor, null));
    }

    defService = ServiceUI.printDialog(null, 100, 100, service, defService,
            flavor, prSet);

    ServiceUI.printDialog(null, 100, 100, service, defService,
            DocFlavor.SERVICE_FORMATTED.PAGEABLE,
            new HashPrintRequestAttributeSet());
}
项目:fop    文件:ExampleFO2JPSPrint.java   
private DocPrintJob createDocPrintJob() {
    PrintService[] services = PrintServiceLookup.lookupPrintServices(
            DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
    PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
    PrintService printService = ServiceUI.printDialog(null, 50, 50,
            services, services[0], null, attributes);
    if (printService != null) {
        return printService.createPrintJob();
    } else {
        return null;
    }
}
项目:JuggleMasterPro    文件:ImagesPrinter.java   
final public Boolean showPrintJDialog() {

        final PrintService objLdefaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
        final PrintRequestAttributeSet objLprintRequestAttributeSet = new HashPrintRequestAttributeSet();

        if (this.objGprintServiceA.length > 0) {
            int intLdefaultServiceIndex = 0;
            if (objLdefaultPrintService != null) {
                for (intLdefaultServiceIndex = 0; intLdefaultServiceIndex < this.objGprintServiceA.length; intLdefaultServiceIndex++) {
                    if (this.objGprintServiceA[intLdefaultServiceIndex].equals(objLdefaultPrintService)) {
                        break;
                    }
                }
            }
            if (intLdefaultServiceIndex == this.objGprintServiceA.length) {
                intLdefaultServiceIndex = 0;
            }

            ServiceUI.printDialog(  null,
                                    50,
                                    50,
                                    this.objGprintServiceA,
                                    this.objGprintServiceA[intLdefaultServiceIndex],
                                    null,
                                    objLprintRequestAttributeSet);

            final PrintJDialog objLprintJDialog = new PrintJDialog(this.objGcontrolJFrame, this.objGprintServiceA, intLdefaultServiceIndex);
            objLprintJDialog.setVisible();
            final PrintService objLprintService = objLprintJDialog.getPrintService();
            objLprintJDialog.dispose();

            if (objLprintService != null) {
                final DocPrintJob objLdocPrintJob = objLprintService.createPrintJob();
                final SimpleDoc objLsimpleDoc = new SimpleDoc(this, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);
                try {
                    objLdocPrintJob.print(objLsimpleDoc, objLprintRequestAttributeSet);
                    return new Boolean(true);
                } catch (final Throwable objPthrowable) {}
            } else {
                return null;
            }
        } else {
            new PopUpJDialog(   this.objGcontrolJFrame,
                                Constants.bytS_UNCLASS_NO_VALUE,
                                Constants.intS_FILE_ICON_ALERT,
                                this.objGcontrolJFrame.getLanguageString(Language.intS_TITLE_PRINT_PATTERN),
                                Tools.getLocaleString("dialog.noprintermsg"),
                                null,
                                true);
        }
        return new Boolean(false);
    }
项目:cn1    文件:PSPrinterJob.java   
public boolean printDialog(PrintRequestAttributeSet dialogAttrs)
        throws HeadlessException {

    if (dialogAttrs == null) {
        throw new NullPointerException();
    } else if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    /* Combine this PrinterJob attrs attribute set and printerAttrs set
       and resolve MediaPrintableArea/MediaMargins conflict if it is 
       needed */
    PrintRequestAttributeSet sum = 
            updateMediaAndMarginsIfNeeded(dialogAttrs);

    Rectangle screen = GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration().getBounds();

    /* call cross-platform print dialog */
    PrintService newSrv = ServiceUI.printDialog(
            null, 
            screen.width / 3, 
            screen.height / 3, 
            lookupServicesForDialog(), 
            service,
            DocFlavor.SERVICE_FORMATTED.PRINTABLE, 
            sum);

    if (newSrv!=null) {
        /* Set selected print service and update attrs attribute set 
           if user clicked "Print" button */
        try {
            setPrintService(newSrv);
            this.attrs.clear();
            this.attrs.addAll(sum);
            return true;
        } catch (PrinterException e) {
            System.out.println(e);
            return false;
        }
    }
    return false;   /* "Cancel button was pressed */
}
项目:freeVM    文件:PSPrinterJob.java   
public boolean printDialog(PrintRequestAttributeSet dialogAttrs)
        throws HeadlessException {

    if (dialogAttrs == null) {
        throw new NullPointerException();
    } else if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    /* Combine this PrinterJob attrs attribute set and printerAttrs set
       and resolve MediaPrintableArea/MediaMargins conflict if it is 
       needed */
    PrintRequestAttributeSet sum = 
            updateMediaAndMarginsIfNeeded(dialogAttrs);

    Rectangle screen = GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration().getBounds();

    /* call cross-platform print dialog */
    PrintService newSrv = ServiceUI.printDialog(
            null, 
            screen.width / 3, 
            screen.height / 3, 
            lookupServicesForDialog(), 
            service,
            DocFlavor.SERVICE_FORMATTED.PRINTABLE, 
            sum);

    if (newSrv!=null) {
        /* Set selected print service and update attrs attribute set 
           if user clicked "Print" button */
        try {
            setPrintService(newSrv);
            this.attrs.clear();
            this.attrs.addAll(sum);
            return true;
        } catch (PrinterException e) {
            System.out.println(e);
            return false;
        }
    }
    return false;   /* "Cancel button was pressed */
}
项目:freeVM    文件:PSPrinterJob.java   
public boolean printDialog(PrintRequestAttributeSet dialogAttrs)
        throws HeadlessException {

    if (dialogAttrs == null) {
        throw new NullPointerException();
    } else if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    /* Combine this PrinterJob attrs attribute set and printerAttrs set
       and resolve MediaPrintableArea/MediaMargins conflict if it is 
       needed */
    PrintRequestAttributeSet sum = 
            updateMediaAndMarginsIfNeeded(dialogAttrs);

    Rectangle screen = GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration().getBounds();

    /* call cross-platform print dialog */
    PrintService newSrv = ServiceUI.printDialog(
            null, 
            screen.width / 3, 
            screen.height / 3, 
            lookupServicesForDialog(), 
            service,
            DocFlavor.SERVICE_FORMATTED.PRINTABLE, 
            sum);

    if (newSrv!=null) {
        /* Set selected print service and update attrs attribute set 
           if user clicked "Print" button */
        try {
            setPrintService(newSrv);
            this.attrs.clear();
            this.attrs.addAll(sum);
            return true;
        } catch (PrinterException e) {
            System.out.println(e);
            return false;
        }
    }
    return false;   /* "Cancel button was pressed */
}