Java Code Examples for javax.print.StreamPrintServiceFactory

The following are top voted examples for showing how to use javax.print.StreamPrintServiceFactory. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: jdk8u-jdk   File: PrintSEUmlauts.java   View source code 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        GraphicsEnvironment.getLocalGraphicsEnvironment();

        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        String mime = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();

        StreamPrintServiceFactory[] factories =
                StreamPrintServiceFactory.
                        lookupStreamPrintServiceFactories(flavor, mime);
        if (factories.length == 0) {
            System.out.println("No print service found.");
            return;
        }

        FileOutputStream output = new FileOutputStream("out.ps");
        StreamPrintService service = factories[0].getPrintService(output);

        SimpleDoc doc =
             new SimpleDoc(new PrintSEUmlauts(),
                           DocFlavor.SERVICE_FORMATTED.PRINTABLE,
                           new HashDocAttributeSet());
        DocPrintJob job = service.createPrintJob();
        job.addPrintJobListener(new PrintJobAdapter() {
            @Override
            public void printJobCompleted(PrintJobEvent pje) {
                testPrintAndExit();
            }
        });

        job.print(doc, new HashPrintRequestAttributeSet());
    }
 
Example 2
Project: metasfresh   File: PrintUtil.java   View source code 6 votes vote down vote up
/**
 * 	Dump Stream Print Services
 * 	@param docFlavor flavor
 * 	@param outputMimeType mime
 */
public static void dump (DocFlavor docFlavor, String outputMimeType)
{
	System.out.println();
	System.out.println("DocFlavor=" + docFlavor + ", Output=" + outputMimeType);
	StreamPrintServiceFactory[] spsfactories =
		StreamPrintServiceFactory.lookupStreamPrintServiceFactories(docFlavor, outputMimeType);
	for (int i = 0; i < spsfactories.length; i++)
	{
		System.out.println("- " + spsfactories[i]);
		DocFlavor dfs[] = spsfactories[i].getSupportedDocFlavors();
		for (int j = 0; j < dfs.length; j++)
		{
			System.out.println("   -> " + dfs[j]);
		}
	}
}
 
Example 3
Project: osp   File: PrintUtils.java   View source code 6 votes vote down vote up
public static void saveComponentAsEPS(Component c) throws IOException {
  // Find a factory object for printing Printable objects to PostScript.
  DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
  String format = "application/postscript"; //$NON-NLS-1$
  StreamPrintServiceFactory factory = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, format)[0];
  // Ask the user to select a file and open the selected file
  //JFileChooser chooser = new JFileChooser();
  JFileChooser chooser = OSPRuntime.getChooser();
  if(chooser.showSaveDialog(c)!=JFileChooser.APPROVE_OPTION) {
    return;
  }
  File f = chooser.getSelectedFile();
  FileOutputStream out = new FileOutputStream(f);
  // Obtain a PrintService that prints to that file
  StreamPrintService service = factory.getPrintService(out);
  // Do the printing with the method below
  printToService(c, service, null);
  // And close the output file.
  out.close();
}
 
Example 4
Project: openjdk-jdk10   File: PrintSEUmlauts.java   View source code 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        GraphicsEnvironment.getLocalGraphicsEnvironment();

        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        String mime = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();

        StreamPrintServiceFactory[] factories =
                StreamPrintServiceFactory.
                        lookupStreamPrintServiceFactories(flavor, mime);
        if (factories.length == 0) {
            System.out.println("No print service found.");
            return;
        }

        FileOutputStream output = new FileOutputStream("out.ps");
        StreamPrintService service = factories[0].getPrintService(output);

        SimpleDoc doc =
             new SimpleDoc(new PrintSEUmlauts(),
                           DocFlavor.SERVICE_FORMATTED.PRINTABLE,
                           new HashDocAttributeSet());
        DocPrintJob job = service.createPrintJob();
        job.addPrintJobListener(new PrintJobAdapter() {
            @Override
            public void printJobCompleted(PrintJobEvent pje) {
                testPrintAndExit();
            }
        });

        job.print(doc, new HashPrintRequestAttributeSet());
    }
 
Example 5
Project: openjdk9   File: PrintSEUmlauts.java   View source code 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        GraphicsEnvironment.getLocalGraphicsEnvironment();

        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        String mime = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();

        StreamPrintServiceFactory[] factories =
                StreamPrintServiceFactory.
                        lookupStreamPrintServiceFactories(flavor, mime);
        if (factories.length == 0) {
            System.out.println("No print service found.");
            return;
        }

        FileOutputStream output = new FileOutputStream("out.ps");
        StreamPrintService service = factories[0].getPrintService(output);

        SimpleDoc doc =
             new SimpleDoc(new PrintSEUmlauts(),
                           DocFlavor.SERVICE_FORMATTED.PRINTABLE,
                           new HashDocAttributeSet());
        DocPrintJob job = service.createPrintJob();
        job.addPrintJobListener(new PrintJobAdapter() {
            @Override
            public void printJobCompleted(PrintJobEvent pje) {
                testPrintAndExit();
            }
        });

        job.print(doc, new HashPrintRequestAttributeSet());
    }
 
Example 6
Project: jdk8u_jdk   File: PrintSEUmlauts.java   View source code 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        GraphicsEnvironment.getLocalGraphicsEnvironment();

        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        String mime = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();

        StreamPrintServiceFactory[] factories =
                StreamPrintServiceFactory.
                        lookupStreamPrintServiceFactories(flavor, mime);
        if (factories.length == 0) {
            System.out.println("No print service found.");
            return;
        }

        FileOutputStream output = new FileOutputStream("out.ps");
        StreamPrintService service = factories[0].getPrintService(output);

        SimpleDoc doc =
             new SimpleDoc(new PrintSEUmlauts(),
                           DocFlavor.SERVICE_FORMATTED.PRINTABLE,
                           new HashDocAttributeSet());
        DocPrintJob job = service.createPrintJob();
        job.addPrintJobListener(new PrintJobAdapter() {
            @Override
            public void printJobCompleted(PrintJobEvent pje) {
                testPrintAndExit();
            }
        });

        job.print(doc, new HashPrintRequestAttributeSet());
    }
 
Example 7
Project: lookaside_java-1.8.0-openjdk   File: PrintSEUmlauts.java   View source code 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        GraphicsEnvironment.getLocalGraphicsEnvironment();

        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        String mime = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();

        StreamPrintServiceFactory[] factories =
                StreamPrintServiceFactory.
                        lookupStreamPrintServiceFactories(flavor, mime);
        if (factories.length == 0) {
            System.out.println("No print service found.");
            return;
        }

        FileOutputStream output = new FileOutputStream("out.ps");
        StreamPrintService service = factories[0].getPrintService(output);

        SimpleDoc doc =
             new SimpleDoc(new PrintSEUmlauts(),
                           DocFlavor.SERVICE_FORMATTED.PRINTABLE,
                           new HashDocAttributeSet());
        DocPrintJob job = service.createPrintJob();
        job.addPrintJobListener(new PrintJobAdapter() {
            @Override
            public void printJobCompleted(PrintJobEvent pje) {
                testPrintAndExit();
            }
        });

        job.print(doc, new HashPrintRequestAttributeSet());
    }
 
Example 8
Project: code-similarity   File: PrintPostScript.java   View source code 5 votes vote down vote up
public void print() throws IOException, PrintException {
    
    DocFlavor inputFlavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8;
    
    // Lookup a print factory to convert from desired input to output.
    StreamPrintServiceFactory[] psfactories =
        StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
            inputFlavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());
    if (psfactories.length == 0) {
        System.err.println("Ack! No StreamPrintFactory found for this job!");
    }
    StreamPrintService printService = 
        psfactories[0].getPrintService(new FileOutputStream("demo.ps"));
    PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
    attrs.add(OrientationRequested.LANDSCAPE);
    attrs.add(MediaSizeName.NA_LETTER);
    attrs.add(new Copies(1));
    attrs.add(new JobName(INPUT_FILE_NAME, null));

    InputStream is = getClass().getResourceAsStream(INPUT_FILE_NAME);
    if (is == null) {
        throw new NullPointerException(
            "Input Stream is null: file not found?");
    }
    Doc doc = new SimpleDoc(is, inputFlavor, null);
    
    DocPrintJob printJob = printService.createPrintJob();
    printJob.print(doc, attrs);
}
 
Example 9
Project: metasfresh   File: ReportEngine.java   View source code 5 votes vote down vote up
/**
 * Write PostScript to writer
 * 
 * @param os output stream
 * @return true if success
 */
public boolean createPS(OutputStream os)
{
	try
	{
		String outputMimeType = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();
		DocFlavor docFlavor = DocFlavor.SERVICE_FORMATTED.PAGEABLE;
		StreamPrintServiceFactory[] spsfactories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(docFlavor, outputMimeType);
		if (spsfactories.length == 0)
		{
			log.error("(fos) - No StreamPrintService");
			return false;
		}
		// just use first one - sun.print.PSStreamPrinterFactory
		// System.out.println("- " + spsfactories[0]);
		StreamPrintService sps = spsfactories[0].getPrintService(os);
		// get format
		if (m_layout == null)
			layout();
		// print it
		sps.createPrintJob().print(m_layout.getPageable(false),
				new HashPrintRequestAttributeSet());
		//
		os.flush();
		// following 2 line for backward compatibility
		if (os instanceof FileOutputStream)
			((FileOutputStream)os).close();
	}
	catch (Exception e)
	{
		log.error("(fos)", e);
	}
	return false;
}
 
Example 10
Project: jdk8u-dev-jdk   File: PrintSEUmlauts.java   View source code 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        GraphicsEnvironment.getLocalGraphicsEnvironment();

        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        String mime = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();

        StreamPrintServiceFactory[] factories =
                StreamPrintServiceFactory.
                        lookupStreamPrintServiceFactories(flavor, mime);
        if (factories.length == 0) {
            System.out.println("No print service found.");
            return;
        }

        FileOutputStream output = new FileOutputStream("out.ps");
        StreamPrintService service = factories[0].getPrintService(output);

        SimpleDoc doc =
             new SimpleDoc(new PrintSEUmlauts(),
                           DocFlavor.SERVICE_FORMATTED.PRINTABLE,
                           new HashDocAttributeSet());
        DocPrintJob job = service.createPrintJob();
        job.addPrintJobListener(new PrintJobAdapter() {
            @Override
            public void printJobCompleted(PrintJobEvent pje) {
                testPrintAndExit();
            }
        });

        job.print(doc, new HashPrintRequestAttributeSet());
    }
 
Example 11
Project: cn1   File: DefaultPrintService.java   View source code 5 votes vote down vote up
public DocFlavor[] getSupportedDocFlavors() {
    DocFlavor clientFlavors[] = client.getSupportedDocFlavors();
    ArrayList flavors = new ArrayList();

    /*
     * Putting all PrintClient's supported flavors (except
     * internal flavors) into list of flavors supported by
     * this print service.
     */
    for (int i = 0; i < clientFlavors.length; i++) {
        if (!isInternalDocFlavor(clientFlavors[i])) {
            flavors.add(clientFlavors[i]);
        }
    }

    /*
     * Searching stream print service factories, which
     * able to convert print data to flavor supported by
     * PrintClient (both user and internal). And then,
     * gathering all flavors supported by those factories
     * and putting them into list of flavors supported
     * by this print service.
     */
    for (int i = 0; i < clientFlavors.length; i++) {
        StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
                .lookupStreamPrintServiceFactories(null, clientFlavors[i]
                        .getMimeType());
        for (int j = 0; j < factories.length; j++) {
            DocFlavor[] factoryFlavors = factories[j]
                    .getSupportedDocFlavors();
            for (int k = 0; k < factoryFlavors.length; k++) {
                if (!flavors.contains(factoryFlavors[k])) {
                    flavors.add(factoryFlavors[k]);
                }
            }
        }
    }
    return (DocFlavor[]) flavors.toArray(new DocFlavor[0]);
}
 
Example 12
Project: cn1   File: All2PSStreamPrintService.java   View source code 5 votes vote down vote up
public All2PSStreamPrintService(OutputStream outputstream,
        StreamPrintServiceFactory factory) {
    super(outputstream);
    if (factory == null) {
        throw new NullPointerException("factory is null");
    }   
}
 
Example 13
Project: freeVM   File: DefaultPrintService.java   View source code 5 votes vote down vote up
public DocFlavor[] getSupportedDocFlavors() {
    DocFlavor clientFlavors[] = client.getSupportedDocFlavors();
    ArrayList flavors = new ArrayList();

    /*
     * Putting all PrintClient's supported flavors (except
     * internal flavors) into list of flavors supported by
     * this print service.
     */
    for (int i = 0; i < clientFlavors.length; i++) {
        if (!isInternalDocFlavor(clientFlavors[i])) {
            flavors.add(clientFlavors[i]);
        }
    }

    /*
     * Searching stream print service factories, which
     * able to convert print data to flavor supported by
     * PrintClient (both user and internal). And then,
     * gathering all flavors supported by those factories
     * and putting them into list of flavors supported
     * by this print service.
     */
    for (int i = 0; i < clientFlavors.length; i++) {
        StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
                .lookupStreamPrintServiceFactories(null, clientFlavors[i]
                        .getMimeType());
        for (int j = 0; j < factories.length; j++) {
            DocFlavor[] factoryFlavors = factories[j]
                    .getSupportedDocFlavors();
            for (int k = 0; k < factoryFlavors.length; k++) {
                if (!flavors.contains(factoryFlavors[k])) {
                    flavors.add(factoryFlavors[k]);
                }
            }
        }
    }
    return (DocFlavor[]) flavors.toArray(new DocFlavor[0]);
}
 
Example 14
Project: freeVM   File: All2PSStreamPrintService.java   View source code 5 votes vote down vote up
public All2PSStreamPrintService(OutputStream outputstream,
        StreamPrintServiceFactory factory) {
    super(outputstream);
    if (factory == null) {
        throw new NullPointerException("factory is null");
    }   
}
 
Example 15
Project: freeVM   File: DefaultPrintService.java   View source code 5 votes vote down vote up
public DocFlavor[] getSupportedDocFlavors() {
    DocFlavor clientFlavors[] = client.getSupportedDocFlavors();
    ArrayList flavors = new ArrayList();

    /*
     * Putting all PrintClient's supported flavors (except
     * internal flavors) into list of flavors supported by
     * this print service.
     */
    for (int i = 0; i < clientFlavors.length; i++) {
        if (!isInternalDocFlavor(clientFlavors[i])) {
            flavors.add(clientFlavors[i]);
        }
    }

    /*
     * Searching stream print service factories, which
     * able to convert print data to flavor supported by
     * PrintClient (both user and internal). And then,
     * gathering all flavors supported by those factories
     * and putting them into list of flavors supported
     * by this print service.
     */
    for (int i = 0; i < clientFlavors.length; i++) {
        StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
                .lookupStreamPrintServiceFactories(null, clientFlavors[i]
                        .getMimeType());
        for (int j = 0; j < factories.length; j++) {
            DocFlavor[] factoryFlavors = factories[j]
                    .getSupportedDocFlavors();
            for (int k = 0; k < factoryFlavors.length; k++) {
                if (!flavors.contains(factoryFlavors[k])) {
                    flavors.add(factoryFlavors[k]);
                }
            }
        }
    }
    return (DocFlavor[]) flavors.toArray(new DocFlavor[0]);
}
 
Example 16
Project: freeVM   File: All2PSStreamPrintService.java   View source code 5 votes vote down vote up
public All2PSStreamPrintService(OutputStream outputstream,
        StreamPrintServiceFactory factory) {
    super(outputstream);
    if (factory == null) {
        throw new NullPointerException("factory is null");
    }   
}
 
Example 17
Project: opensim-gui   File: ChartPanel.java   View source code 4 votes vote down vote up
private void createChartPrintPostScriptJob() {
// Use the pre-defined flavor for a Printable from an InputStream 
	DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;

		// Specify the type of the output stream 
	String psMimeType = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();

	// Locate factory which can export a GIF image stream as Postscript 
	StreamPrintServiceFactory[] factories =
	StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
				flavor, psMimeType);
	if (factories.length == 0) {
		System.err.println("No suitable factories");
		System.exit(0); // FIXME too
	}
               // Obtain file name from user
               JFileChooser fileChooser = new JFileChooser();
               ExtensionFileFilter filter = new ExtensionFileFilter(
                       localizationResources.getString("PostScript_Files"), ".eps");
               fileChooser.addChoosableFileFilter(filter);
               String filename="";
               int option = fileChooser.showSaveDialog(this);
               if (option == JFileChooser.APPROVE_OPTION) {
                  filename = fileChooser.getSelectedFile().getPath();
                  if (isEnforceFileExtensions()) {
                     if (!filename.endsWith(".eps")) {
                        filename = filename + ".eps";
                     }
                  } else
                     return;
               }

	try {
		// Create a file for the exported postscript
		FileOutputStream fos = new FileOutputStream(filename);

		// Create a Stream printer for Postscript 
		StreamPrintService sps = factories[0].getPrintService(fos);

		// Create and call a Print Job 
		DocPrintJob pj = sps.createPrintJob();
		PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

		Doc doc = new SimpleDoc(this, flavor, null);

		pj.print(doc, aset);
		fos.close();

	} catch (PrintException pe) { 
		System.err.println(pe);
	} catch (IOException ie) { 
		System.err.println(ie);
	}

  }
 
Example 18
Project: cn1   File: DefaultPrintService.java   View source code 4 votes vote down vote up
public Object getSupportedAttributeValues(Class category, DocFlavor flavor,
        AttributeSet attributes) {
    if (category == null) {
        throw new NullPointerException("Argument is null");
    }
    if (!(Attribute.class.isAssignableFrom(category))) {
        throw new IllegalArgumentException(
                "Argument must implement interface Attribute");
    }
    if (flavor == null) {
        return client.getSupportedAttributeValues(category, flavor,
                attributes);
    }

    DocFlavor clientFlavors[] = client.getSupportedDocFlavors();
    if (isDocFlavorSupportedByClient(flavor, clientFlavors)) {
        return client.getSupportedAttributeValues(category, flavor,
                attributes);
    }
    /*
     * Searching stream print service factories, which
     * able to convert print data to flavor supported by
     * PrintClient (both user and internal). And then,
     * return supported attributes by created stream print
     * service
     */
    for (int i = 0; i < clientFlavors.length; i++) {
        StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
                .lookupStreamPrintServiceFactories(flavor, clientFlavors[i]
                        .getMimeType());
        for (int j = 0; j < factories.length; j++) {
            StreamPrintService sps = factories[j]
                    .getPrintService(new ByteArrayOutputStream());
            if (sps != null) {
                try {
                    sps.getOutputStream().close();
                } catch (IOException e) {
                    // just ignore
                }
                sps.dispose();
                //return sps.getSupportedAttributeValues(category,
                //        flavor, attributes);
                return client.getSupportedAttributeValues(category,
                        clientFlavors[i], attributes);
            }
        }
    }

    throw new IllegalArgumentException("DocFlavor '" + flavor
            + "' is not supported by the print service");
}
 
Example 19
Project: cn1   File: DefaultPrintService.java   View source code 4 votes vote down vote up
public boolean isAttributeValueSupported(Attribute attrval,
        DocFlavor flavor, AttributeSet attributes) {
    if (attrval == null) {
        throw new NullPointerException("Argument is null");
    }

    if (flavor == null) {
        return client
                .isAttributeValueSupported(attrval, flavor, attributes);
    }

    DocFlavor clientFlavors[] = client.getSupportedDocFlavors();
    if (isDocFlavorSupportedByClient(flavor, clientFlavors)) {
        return client
                .isAttributeValueSupported(attrval, flavor, attributes);
    }

    /*
     * Searching stream print service factories, which
     * able to convert print data to flavor supported by
     * PrintClient (both user and internal). And then,
     * return supported attributes by created stream print
     * service
     */
    for (int i = 0; i < clientFlavors.length; i++) {
        StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
                .lookupStreamPrintServiceFactories(flavor, clientFlavors[i]
                        .getMimeType());
        for (int j = 0; j < factories.length; j++) {
            StreamPrintService sps = factories[j]
                    .getPrintService(new ByteArrayOutputStream());
            if (sps != null) {
                try {
                    sps.getOutputStream().close();
                } catch (IOException e) {
                    // just ignore
                }
                sps.dispose();
                //return sps.isAttributeValueSupported(attrval, flavor, attributes);
                return client.isAttributeValueSupported(attrval,
                        clientFlavors[i], attributes);
            }
        }
    }

    throw new IllegalArgumentException("DocFlavor '" + flavor
            + "' is not supported by the print service");

}
 
Example 20
Project: cn1   File: PrinterJob.java   View source code 4 votes vote down vote up
public static StreamPrintServiceFactory[] lookupStreamPrintServices(
        String mimeType) {
    return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
            javax.print.DocFlavor.SERVICE_FORMATTED.PAGEABLE, mimeType);
}
 
Example 21
Project: freeVM   File: DefaultPrintService.java   View source code 4 votes vote down vote up
public Object getSupportedAttributeValues(Class category, DocFlavor flavor,
        AttributeSet attributes) {
    if (category == null) {
        throw new NullPointerException("Argument is null");
    }
    if (!(Attribute.class.isAssignableFrom(category))) {
        throw new IllegalArgumentException(
                "Argument must implement interface Attribute");
    }
    if (flavor == null) {
        return client.getSupportedAttributeValues(category, flavor,
                attributes);
    }

    DocFlavor clientFlavors[] = client.getSupportedDocFlavors();
    if (isDocFlavorSupportedByClient(flavor, clientFlavors)) {
        return client.getSupportedAttributeValues(category, flavor,
                attributes);
    }
    /*
     * Searching stream print service factories, which
     * able to convert print data to flavor supported by
     * PrintClient (both user and internal). And then,
     * return supported attributes by created stream print
     * service
     */
    for (int i = 0; i < clientFlavors.length; i++) {
        StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
                .lookupStreamPrintServiceFactories(flavor, clientFlavors[i]
                        .getMimeType());
        for (int j = 0; j < factories.length; j++) {
            StreamPrintService sps = factories[j]
                    .getPrintService(new ByteArrayOutputStream());
            if (sps != null) {
                try {
                    sps.getOutputStream().close();
                } catch (IOException e) {
                    // just ignore
                }
                sps.dispose();
                //return sps.getSupportedAttributeValues(category,
                //        flavor, attributes);
                return client.getSupportedAttributeValues(category,
                        clientFlavors[i], attributes);
            }
        }
    }

    throw new IllegalArgumentException("DocFlavor '" + flavor
            + "' is not supported by the print service");
}
 
Example 22
Project: freeVM   File: DefaultPrintService.java   View source code 4 votes vote down vote up
public boolean isAttributeValueSupported(Attribute attrval,
        DocFlavor flavor, AttributeSet attributes) {
    if (attrval == null) {
        throw new NullPointerException("Argument is null");
    }

    if (flavor == null) {
        return client
                .isAttributeValueSupported(attrval, flavor, attributes);
    }

    DocFlavor clientFlavors[] = client.getSupportedDocFlavors();
    if (isDocFlavorSupportedByClient(flavor, clientFlavors)) {
        return client
                .isAttributeValueSupported(attrval, flavor, attributes);
    }

    /*
     * Searching stream print service factories, which
     * able to convert print data to flavor supported by
     * PrintClient (both user and internal). And then,
     * return supported attributes by created stream print
     * service
     */
    for (int i = 0; i < clientFlavors.length; i++) {
        StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
                .lookupStreamPrintServiceFactories(flavor, clientFlavors[i]
                        .getMimeType());
        for (int j = 0; j < factories.length; j++) {
            StreamPrintService sps = factories[j]
                    .getPrintService(new ByteArrayOutputStream());
            if (sps != null) {
                try {
                    sps.getOutputStream().close();
                } catch (IOException e) {
                    // just ignore
                }
                sps.dispose();
                //return sps.isAttributeValueSupported(attrval, flavor, attributes);
                return client.isAttributeValueSupported(attrval,
                        clientFlavors[i], attributes);
            }
        }
    }

    throw new IllegalArgumentException("DocFlavor '" + flavor
            + "' is not supported by the print service");

}
 
Example 23
Project: freeVM   File: PrinterJob.java   View source code 4 votes vote down vote up
public static StreamPrintServiceFactory[] lookupStreamPrintServices(
        String mimeType) {
    return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
            javax.print.DocFlavor.SERVICE_FORMATTED.PAGEABLE, mimeType);
}
 
Example 24
Project: freeVM   File: DefaultPrintService.java   View source code 4 votes vote down vote up
public Object getSupportedAttributeValues(Class category, DocFlavor flavor,
        AttributeSet attributes) {
    if (category == null) {
        throw new NullPointerException("Argument is null");
    }
    if (!(Attribute.class.isAssignableFrom(category))) {
        throw new IllegalArgumentException(
                "Argument must implement interface Attribute");
    }
    if (flavor == null) {
        return client.getSupportedAttributeValues(category, flavor,
                attributes);
    }

    DocFlavor clientFlavors[] = client.getSupportedDocFlavors();
    if (isDocFlavorSupportedByClient(flavor, clientFlavors)) {
        return client.getSupportedAttributeValues(category, flavor,
                attributes);
    }
    /*
     * Searching stream print service factories, which
     * able to convert print data to flavor supported by
     * PrintClient (both user and internal). And then,
     * return supported attributes by created stream print
     * service
     */
    for (int i = 0; i < clientFlavors.length; i++) {
        StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
                .lookupStreamPrintServiceFactories(flavor, clientFlavors[i]
                        .getMimeType());
        for (int j = 0; j < factories.length; j++) {
            StreamPrintService sps = factories[j]
                    .getPrintService(new ByteArrayOutputStream());
            if (sps != null) {
                try {
                    sps.getOutputStream().close();
                } catch (IOException e) {
                    // just ignore
                }
                sps.dispose();
                //return sps.getSupportedAttributeValues(category,
                //        flavor, attributes);
                return client.getSupportedAttributeValues(category,
                        clientFlavors[i], attributes);
            }
        }
    }

    throw new IllegalArgumentException("DocFlavor '" + flavor
            + "' is not supported by the print service");
}
 
Example 25
Project: freeVM   File: DefaultPrintService.java   View source code 4 votes vote down vote up
public boolean isAttributeValueSupported(Attribute attrval,
        DocFlavor flavor, AttributeSet attributes) {
    if (attrval == null) {
        throw new NullPointerException("Argument is null");
    }

    if (flavor == null) {
        return client
                .isAttributeValueSupported(attrval, flavor, attributes);
    }

    DocFlavor clientFlavors[] = client.getSupportedDocFlavors();
    if (isDocFlavorSupportedByClient(flavor, clientFlavors)) {
        return client
                .isAttributeValueSupported(attrval, flavor, attributes);
    }

    /*
     * Searching stream print service factories, which
     * able to convert print data to flavor supported by
     * PrintClient (both user and internal). And then,
     * return supported attributes by created stream print
     * service
     */
    for (int i = 0; i < clientFlavors.length; i++) {
        StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
                .lookupStreamPrintServiceFactories(flavor, clientFlavors[i]
                        .getMimeType());
        for (int j = 0; j < factories.length; j++) {
            StreamPrintService sps = factories[j]
                    .getPrintService(new ByteArrayOutputStream());
            if (sps != null) {
                try {
                    sps.getOutputStream().close();
                } catch (IOException e) {
                    // just ignore
                }
                sps.dispose();
                //return sps.isAttributeValueSupported(attrval, flavor, attributes);
                return client.isAttributeValueSupported(attrval,
                        clientFlavors[i], attributes);
            }
        }
    }

    throw new IllegalArgumentException("DocFlavor '" + flavor
            + "' is not supported by the print service");

}
 
Example 26
Project: freeVM   File: PrinterJob.java   View source code 4 votes vote down vote up
public static StreamPrintServiceFactory[] lookupStreamPrintServices(
        String mimeType) {
    return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
            javax.print.DocFlavor.SERVICE_FORMATTED.PAGEABLE, mimeType);
}
 
Example 27
Project: OpenJSharp   File: PrinterJob.java   View source code 3 votes vote down vote up
/**
 * A convenience method which locates factories for stream print
 * services which can image 2D graphics.
 * Sample usage :
 * <pre>{@code
 * FileOutputStream outstream;
 * StreamPrintService psPrinter;
 * String psMimeType = "application/postscript";
 * PrinterJob pj = PrinterJob.getPrinterJob();
 *
 * StreamPrintServiceFactory[] factories =
 *     PrinterJob.lookupStreamPrintServices(psMimeType);
 * if (factories.length > 0) {
 *     try {
 *         outstream = new File("out.ps");
 *         psPrinter =  factories[0].getPrintService(outstream);
 *         // psPrinter can now be set as the service on a PrinterJob
 *         pj.setPrintService(psPrinter)
 *     } catch (Exception e) {
 *         e.printStackTrace();
 *     }
 * }
 * }</pre>
 * Services returned from this method may be installed on
 * <code>PrinterJob</code> instances which support print services.
 * Calling this method is equivalent to calling
 * {@link javax.print.StreamPrintServiceFactory#lookupStreamPrintServiceFactories(DocFlavor, String)
 * StreamPrintServiceFactory.lookupStreamPrintServiceFactories()
 * } and specifying a Pageable DocFlavor.
 *
 * @param mimeType the required output format, or null to mean any format.
 * @return a possibly empty array of 2D stream print service factories.
 * @since     1.4
 */
public static StreamPrintServiceFactory[]
    lookupStreamPrintServices(String mimeType) {
    return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
                                   DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                   mimeType);
}
 
Example 28
Project: jdk8u-jdk   File: PrinterJob.java   View source code 3 votes vote down vote up
/**
 * A convenience method which locates factories for stream print
 * services which can image 2D graphics.
 * Sample usage :
 * <pre>{@code
 * FileOutputStream outstream;
 * StreamPrintService psPrinter;
 * String psMimeType = "application/postscript";
 * PrinterJob pj = PrinterJob.getPrinterJob();
 *
 * StreamPrintServiceFactory[] factories =
 *     PrinterJob.lookupStreamPrintServices(psMimeType);
 * if (factories.length > 0) {
 *     try {
 *         outstream = new File("out.ps");
 *         psPrinter =  factories[0].getPrintService(outstream);
 *         // psPrinter can now be set as the service on a PrinterJob
 *         pj.setPrintService(psPrinter)
 *     } catch (Exception e) {
 *         e.printStackTrace();
 *     }
 * }
 * }</pre>
 * Services returned from this method may be installed on
 * <code>PrinterJob</code> instances which support print services.
 * Calling this method is equivalent to calling
 * {@link javax.print.StreamPrintServiceFactory#lookupStreamPrintServiceFactories(DocFlavor, String)
 * StreamPrintServiceFactory.lookupStreamPrintServiceFactories()
 * } and specifying a Pageable DocFlavor.
 *
 * @param mimeType the required output format, or null to mean any format.
 * @return a possibly empty array of 2D stream print service factories.
 * @since     1.4
 */
public static StreamPrintServiceFactory[]
    lookupStreamPrintServices(String mimeType) {
    return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
                                   DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                   mimeType);
}
 
Example 29
Project: openjdk-jdk10   File: PrinterJob.java   View source code 3 votes vote down vote up
/**
 * A convenience method which locates factories for stream print
 * services which can image 2D graphics.
 * Sample usage :
 * <pre>{@code
 * FileOutputStream outstream;
 * StreamPrintService psPrinter;
 * String psMimeType = "application/postscript";
 * PrinterJob pj = PrinterJob.getPrinterJob();
 *
 * StreamPrintServiceFactory[] factories =
 *     PrinterJob.lookupStreamPrintServices(psMimeType);
 * if (factories.length > 0) {
 *     try {
 *         outstream = new File("out.ps");
 *         psPrinter =  factories[0].getPrintService(outstream);
 *         // psPrinter can now be set as the service on a PrinterJob
 *         pj.setPrintService(psPrinter)
 *     } catch (Exception e) {
 *         e.printStackTrace();
 *     }
 * }
 * }</pre>
 * Services returned from this method may be installed on
 * {@code PrinterJob} instances which support print services.
 * Calling this method is equivalent to calling
 * {@link javax.print.StreamPrintServiceFactory#lookupStreamPrintServiceFactories(DocFlavor, String)
 * StreamPrintServiceFactory.lookupStreamPrintServiceFactories()
 * } and specifying a Pageable DocFlavor.
 *
 * @param mimeType the required output format, or null to mean any format.
 * @return a possibly empty array of 2D stream print service factories.
 * @since     1.4
 */
public static StreamPrintServiceFactory[]
    lookupStreamPrintServices(String mimeType) {
    return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
                                   DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                   mimeType);
}
 
Example 30
Project: openjdk9   File: PrinterJob.java   View source code 3 votes vote down vote up
/**
 * A convenience method which locates factories for stream print
 * services which can image 2D graphics.
 * Sample usage :
 * <pre>{@code
 * FileOutputStream outstream;
 * StreamPrintService psPrinter;
 * String psMimeType = "application/postscript";
 * PrinterJob pj = PrinterJob.getPrinterJob();
 *
 * StreamPrintServiceFactory[] factories =
 *     PrinterJob.lookupStreamPrintServices(psMimeType);
 * if (factories.length > 0) {
 *     try {
 *         outstream = new File("out.ps");
 *         psPrinter =  factories[0].getPrintService(outstream);
 *         // psPrinter can now be set as the service on a PrinterJob
 *         pj.setPrintService(psPrinter)
 *     } catch (Exception e) {
 *         e.printStackTrace();
 *     }
 * }
 * }</pre>
 * Services returned from this method may be installed on
 * {@code PrinterJob} instances which support print services.
 * Calling this method is equivalent to calling
 * {@link javax.print.StreamPrintServiceFactory#lookupStreamPrintServiceFactories(DocFlavor, String)
 * StreamPrintServiceFactory.lookupStreamPrintServiceFactories()
 * } and specifying a Pageable DocFlavor.
 *
 * @param mimeType the required output format, or null to mean any format.
 * @return a possibly empty array of 2D stream print service factories.
 * @since     1.4
 */
public static StreamPrintServiceFactory[]
    lookupStreamPrintServices(String mimeType) {
    return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
                                   DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                   mimeType);
}
 
Example 31
Project: Java8CN   File: PrinterJob.java   View source code 3 votes vote down vote up
/**
 * A convenience method which locates factories for stream print
 * services which can image 2D graphics.
 * Sample usage :
 * <pre>{@code
 * FileOutputStream outstream;
 * StreamPrintService psPrinter;
 * String psMimeType = "application/postscript";
 * PrinterJob pj = PrinterJob.getPrinterJob();
 *
 * StreamPrintServiceFactory[] factories =
 *     PrinterJob.lookupStreamPrintServices(psMimeType);
 * if (factories.length > 0) {
 *     try {
 *         outstream = new File("out.ps");
 *         psPrinter =  factories[0].getPrintService(outstream);
 *         // psPrinter can now be set as the service on a PrinterJob
 *         pj.setPrintService(psPrinter)
 *     } catch (Exception e) {
 *         e.printStackTrace();
 *     }
 * }
 * }</pre>
 * Services returned from this method may be installed on
 * <code>PrinterJob</code> instances which support print services.
 * Calling this method is equivalent to calling
 * {@link javax.print.StreamPrintServiceFactory#lookupStreamPrintServiceFactories(DocFlavor, String)
 * StreamPrintServiceFactory.lookupStreamPrintServiceFactories()
 * } and specifying a Pageable DocFlavor.
 *
 * @param mimeType the required output format, or null to mean any format.
 * @return a possibly empty array of 2D stream print service factories.
 * @since     1.4
 */
public static StreamPrintServiceFactory[]
    lookupStreamPrintServices(String mimeType) {
    return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
                                   DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                   mimeType);
}
 
Example 32
Project: jdk8u_jdk   File: PrinterJob.java   View source code 3 votes vote down vote up
/**
 * A convenience method which locates factories for stream print
 * services which can image 2D graphics.
 * Sample usage :
 * <pre>{@code
 * FileOutputStream outstream;
 * StreamPrintService psPrinter;
 * String psMimeType = "application/postscript";
 * PrinterJob pj = PrinterJob.getPrinterJob();
 *
 * StreamPrintServiceFactory[] factories =
 *     PrinterJob.lookupStreamPrintServices(psMimeType);
 * if (factories.length > 0) {
 *     try {
 *         outstream = new File("out.ps");
 *         psPrinter =  factories[0].getPrintService(outstream);
 *         // psPrinter can now be set as the service on a PrinterJob
 *         pj.setPrintService(psPrinter)
 *     } catch (Exception e) {
 *         e.printStackTrace();
 *     }
 * }
 * }</pre>
 * Services returned from this method may be installed on
 * <code>PrinterJob</code> instances which support print services.
 * Calling this method is equivalent to calling
 * {@link javax.print.StreamPrintServiceFactory#lookupStreamPrintServiceFactories(DocFlavor, String)
 * StreamPrintServiceFactory.lookupStreamPrintServiceFactories()
 * } and specifying a Pageable DocFlavor.
 *
 * @param mimeType the required output format, or null to mean any format.
 * @return a possibly empty array of 2D stream print service factories.
 * @since     1.4
 */
public static StreamPrintServiceFactory[]
    lookupStreamPrintServices(String mimeType) {
    return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
                                   DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                   mimeType);
}
 
Example 33
Project: lookaside_java-1.8.0-openjdk   File: PrinterJob.java   View source code 3 votes vote down vote up
/**
 * A convenience method which locates factories for stream print
 * services which can image 2D graphics.
 * Sample usage :
 * <pre>{@code
 * FileOutputStream outstream;
 * StreamPrintService psPrinter;
 * String psMimeType = "application/postscript";
 * PrinterJob pj = PrinterJob.getPrinterJob();
 *
 * StreamPrintServiceFactory[] factories =
 *     PrinterJob.lookupStreamPrintServices(psMimeType);
 * if (factories.length > 0) {
 *     try {
 *         outstream = new File("out.ps");
 *         psPrinter =  factories[0].getPrintService(outstream);
 *         // psPrinter can now be set as the service on a PrinterJob
 *         pj.setPrintService(psPrinter)
 *     } catch (Exception e) {
 *         e.printStackTrace();
 *     }
 * }
 * }</pre>
 * Services returned from this method may be installed on
 * <code>PrinterJob</code> instances which support print services.
 * Calling this method is equivalent to calling
 * {@link javax.print.StreamPrintServiceFactory#lookupStreamPrintServiceFactories(DocFlavor, String)
 * StreamPrintServiceFactory.lookupStreamPrintServiceFactories()
 * } and specifying a Pageable DocFlavor.
 *
 * @param mimeType the required output format, or null to mean any format.
 * @return a possibly empty array of 2D stream print service factories.
 * @since     1.4
 */
public static StreamPrintServiceFactory[]
    lookupStreamPrintServices(String mimeType) {
    return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
                                   DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                   mimeType);
}
 
Example 34
Project: javify   File: PrinterJob.java   View source code 3 votes vote down vote up
/**
 * Find and return 2D image stream print services.
 *
 * This is the same as calling
 * StreamPrintServiceFactory.lookupStreamPrintServices()
 * with Pageable service-specified DocFlavor.
 * @param mimeType The output format mime type, or null for any type.
 * @return Array of stream print services, could be empty.
 * @since 1.4
 */
public static StreamPrintServiceFactory[]
  lookupStreamPrintServices(String mimeType)
{
  return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
    DocFlavor.SERVICE_FORMATTED.PAGEABLE, mimeType);
}
 
Example 35
Project: jvm-stm   File: PrinterJob.java   View source code 3 votes vote down vote up
/**
 * Find and return 2D image stream print services.
 * 
 * This is the same as calling
 * StreamPrintServiceFactory.lookupStreamPrintServices()
 * with Pageable service-specified DocFlavor.
 * @param mimeType The output format mime type, or null for any type.
 * @return Array of stream print services, could be empty.
 * @since 1.4
 */
public static StreamPrintServiceFactory[]
  lookupStreamPrintServices(String mimeType)
{
  return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
    DocFlavor.SERVICE_FORMATTED.PAGEABLE, mimeType);
}
 
Example 36
Project: VarJ   File: PrinterJob.java   View source code 3 votes vote down vote up
/**
    * A convenience method which locates factories for stream print
    * services which can image 2D graphics.
    * Sample usage :
    * <pre>
    * FileOutputStream outstream;
    * StreamPrintService psPrinter;
    * String psMimeType = "application/postscript";
    *
    * StreamPrintServiceFactory[] factories =
    *     PrinterJob.lookupStreamPrintServices(psMimeType);
    * if (factories.length > 0) {
    *     try {
    *         outstream = new File("out.ps");
    *         psPrinter =  factories[0].getPrintService(fos);
    *         // psPrinter can now be set as the service on a PrinterJob 
    *     } catch (FileNotFoundException e) {
    *     }
    * }            
    * </pre>
    * Services returned from this method may be installed on
    * <code>PrinterJob</code> instances which support print services.
    * Calling this method is equivalent to calling
    * {@link javax.print.StreamPrintServiceFactory#lookupStreamPrintServiceFactories(DocFlavor, String)
    * <code>StreamPrintServiceFactory.lookupStreamPrintServiceFactories()
    * </code>} and specifying a Pageable DocFlavor.
    * 
    * @param mimeType the required output format, or null to mean any format.
    * @return a possibly empty array of 2D stream print service factories.
    * @since     1.4
    */
   public static StreamPrintServiceFactory[]
lookupStreamPrintServices(String mimeType) {
return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
			       DocFlavor.SERVICE_FORMATTED.PAGEABLE,
			       mimeType);
   }
 
Example 37
Project: jdk-1.7-annotated   File: PrinterJob.java   View source code 3 votes vote down vote up
/**
 * A convenience method which locates factories for stream print
 * services which can image 2D graphics.
 * Sample usage :
 * <pre>
 * FileOutputStream outstream;
 * StreamPrintService psPrinter;
 * String psMimeType = "application/postscript";
 * PrinterJob pj = PrinterJob.getPrinterJob();
 *
 * StreamPrintServiceFactory[] factories =
 *     PrinterJob.lookupStreamPrintServices(psMimeType);
 * if (factories.length > 0) {
 *     try {
 *         outstream = new File("out.ps");
 *         psPrinter =  factories[0].getPrintService(outstream);
 *         // psPrinter can now be set as the service on a PrinterJob
 *         pj.setPrintService(psPrinter)
 *     } catch (Exception e) {
 *         e.printStackTrace();
 *     }
 * }
 * </pre>
 * Services returned from this method may be installed on
 * <code>PrinterJob</code> instances which support print services.
 * Calling this method is equivalent to calling
 * {@link javax.print.StreamPrintServiceFactory#lookupStreamPrintServiceFactories(DocFlavor, String)
 * <code>StreamPrintServiceFactory.lookupStreamPrintServiceFactories()
 * </code>} and specifying a Pageable DocFlavor.
 *
 * @param mimeType the required output format, or null to mean any format.
 * @return a possibly empty array of 2D stream print service factories.
 * @since     1.4
 */
public static StreamPrintServiceFactory[]
    lookupStreamPrintServices(String mimeType) {
    return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
                                   DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                   mimeType);
}
 
Example 38
Project: infobip-open-jdk-8   File: PrinterJob.java   View source code 3 votes vote down vote up
/**
 * A convenience method which locates factories for stream print
 * services which can image 2D graphics.
 * Sample usage :
 * <pre>{@code
 * FileOutputStream outstream;
 * StreamPrintService psPrinter;
 * String psMimeType = "application/postscript";
 * PrinterJob pj = PrinterJob.getPrinterJob();
 *
 * StreamPrintServiceFactory[] factories =
 *     PrinterJob.lookupStreamPrintServices(psMimeType);
 * if (factories.length > 0) {
 *     try {
 *         outstream = new File("out.ps");
 *         psPrinter =  factories[0].getPrintService(outstream);
 *         // psPrinter can now be set as the service on a PrinterJob
 *         pj.setPrintService(psPrinter)
 *     } catch (Exception e) {
 *         e.printStackTrace();
 *     }
 * }
 * }</pre>
 * Services returned from this method may be installed on
 * <code>PrinterJob</code> instances which support print services.
 * Calling this method is equivalent to calling
 * {@link javax.print.StreamPrintServiceFactory#lookupStreamPrintServiceFactories(DocFlavor, String)
 * StreamPrintServiceFactory.lookupStreamPrintServiceFactories()
 * } and specifying a Pageable DocFlavor.
 *
 * @param mimeType the required output format, or null to mean any format.
 * @return a possibly empty array of 2D stream print service factories.
 * @since     1.4
 */
public static StreamPrintServiceFactory[]
    lookupStreamPrintServices(String mimeType) {
    return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
                                   DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                   mimeType);
}
 
Example 39
Project: jdk8u-dev-jdk   File: PrinterJob.java   View source code 3 votes vote down vote up
/**
 * A convenience method which locates factories for stream print
 * services which can image 2D graphics.
 * Sample usage :
 * <pre>{@code
 * FileOutputStream outstream;
 * StreamPrintService psPrinter;
 * String psMimeType = "application/postscript";
 * PrinterJob pj = PrinterJob.getPrinterJob();
 *
 * StreamPrintServiceFactory[] factories =
 *     PrinterJob.lookupStreamPrintServices(psMimeType);
 * if (factories.length > 0) {
 *     try {
 *         outstream = new File("out.ps");
 *         psPrinter =  factories[0].getPrintService(outstream);
 *         // psPrinter can now be set as the service on a PrinterJob
 *         pj.setPrintService(psPrinter)
 *     } catch (Exception e) {
 *         e.printStackTrace();
 *     }
 * }
 * }</pre>
 * Services returned from this method may be installed on
 * <code>PrinterJob</code> instances which support print services.
 * Calling this method is equivalent to calling
 * {@link javax.print.StreamPrintServiceFactory#lookupStreamPrintServiceFactories(DocFlavor, String)
 * StreamPrintServiceFactory.lookupStreamPrintServiceFactories()
 * } and specifying a Pageable DocFlavor.
 *
 * @param mimeType the required output format, or null to mean any format.
 * @return a possibly empty array of 2D stream print service factories.
 * @since     1.4
 */
public static StreamPrintServiceFactory[]
    lookupStreamPrintServices(String mimeType) {
    return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
                                   DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                   mimeType);
}
 
Example 40
Project: jdk7-jdk   File: PrinterJob.java   View source code 3 votes vote down vote up
/**
 * A convenience method which locates factories for stream print
 * services which can image 2D graphics.
 * Sample usage :
 * <pre>
 * FileOutputStream outstream;
 * StreamPrintService psPrinter;
 * String psMimeType = "application/postscript";
 * PrinterJob pj = PrinterJob.getPrinterJob();
 *
 * StreamPrintServiceFactory[] factories =
 *     PrinterJob.lookupStreamPrintServices(psMimeType);
 * if (factories.length > 0) {
 *     try {
 *         outstream = new File("out.ps");
 *         psPrinter =  factories[0].getPrintService(outstream);
 *         // psPrinter can now be set as the service on a PrinterJob
 *         pj.setPrintService(psPrinter)
 *     } catch (Exception e) {
 *         e.printStackTrace();
 *     }
 * }
 * </pre>
 * Services returned from this method may be installed on
 * <code>PrinterJob</code> instances which support print services.
 * Calling this method is equivalent to calling
 * {@link javax.print.StreamPrintServiceFactory#lookupStreamPrintServiceFactories(DocFlavor, String)
 * <code>StreamPrintServiceFactory.lookupStreamPrintServiceFactories()
 * </code>} and specifying a Pageable DocFlavor.
 *
 * @param mimeType the required output format, or null to mean any format.
 * @return a possibly empty array of 2D stream print service factories.
 * @since     1.4
 */
public static StreamPrintServiceFactory[]
    lookupStreamPrintServices(String mimeType) {
    return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
                                   DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                   mimeType);
}