当前位置: 首页>>代码示例>>Java>>正文


Java StreamPrintServiceFactory.lookupStreamPrintServiceFactories方法代码示例

本文整理汇总了Java中javax.print.StreamPrintServiceFactory.lookupStreamPrintServiceFactories方法的典型用法代码示例。如果您正苦于以下问题:Java StreamPrintServiceFactory.lookupStreamPrintServiceFactories方法的具体用法?Java StreamPrintServiceFactory.lookupStreamPrintServiceFactories怎么用?Java StreamPrintServiceFactory.lookupStreamPrintServiceFactories使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.print.StreamPrintServiceFactory的用法示例。


在下文中一共展示了StreamPrintServiceFactory.lookupStreamPrintServiceFactories方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import javax.print.StreamPrintServiceFactory; //导入方法依赖的package包/类
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());
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:PrintSEUmlauts.java

示例2: dump

import javax.print.StreamPrintServiceFactory; //导入方法依赖的package包/类
/**
 * 	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]);
		}
	}
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:22,代码来源:PrintUtil.java

示例3: saveComponentAsEPS

import javax.print.StreamPrintServiceFactory; //导入方法依赖的package包/类
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();
}
 
开发者ID:OpenSourcePhysics,项目名称:osp,代码行数:21,代码来源:PrintUtils.java

示例4: print

import javax.print.StreamPrintServiceFactory; //导入方法依赖的package包/类
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);
}
 
开发者ID:shashanksingh28,项目名称:code-similarity,代码行数:30,代码来源:PrintPostScript.java

示例5: createPS

import javax.print.StreamPrintServiceFactory; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:40,代码来源:ReportEngine.java

示例6: getSupportedDocFlavors

import javax.print.StreamPrintServiceFactory; //导入方法依赖的package包/类
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]);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:40,代码来源:DefaultPrintService.java

示例7: createChartPrintPostScriptJob

import javax.print.StreamPrintServiceFactory; //导入方法依赖的package包/类
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);
	}

  }
 
开发者ID:opensim-org,项目名称:opensim-gui,代码行数:56,代码来源:ChartPanel.java

示例8: getSupportedAttributeValues

import javax.print.StreamPrintServiceFactory; //导入方法依赖的package包/类
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");
}
 
开发者ID:shannah,项目名称:cn1,代码行数:52,代码来源:DefaultPrintService.java

示例9: isAttributeValueSupported

import javax.print.StreamPrintServiceFactory; //导入方法依赖的package包/类
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");

}
 
开发者ID:shannah,项目名称:cn1,代码行数:50,代码来源:DefaultPrintService.java

示例10: lookupStreamPrintServices

import javax.print.StreamPrintServiceFactory; //导入方法依赖的package包/类
public static StreamPrintServiceFactory[] lookupStreamPrintServices(
        String mimeType) {
    return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
            javax.print.DocFlavor.SERVICE_FORMATTED.PAGEABLE, mimeType);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:6,代码来源:PrinterJob.java

示例11: lookupStreamPrintServices

import javax.print.StreamPrintServiceFactory; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:PrinterJob.java

示例12: lookupStreamPrintServices

import javax.print.StreamPrintServiceFactory; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:PrinterJob.java

示例13: lookupStreamPrintServices

import javax.print.StreamPrintServiceFactory; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:vilie,项目名称:javify,代码行数:17,代码来源:PrinterJob.java

示例14: lookupStreamPrintServices

import javax.print.StreamPrintServiceFactory; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:17,代码来源:PrinterJob.java

示例15: lookupStreamPrintServices

import javax.print.StreamPrintServiceFactory; //导入方法依赖的package包/类
/**
    * 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);
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:38,代码来源:PrinterJob.java


注:本文中的javax.print.StreamPrintServiceFactory.lookupStreamPrintServiceFactories方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。