⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 print.java

📁 Java写的ERP系统
💻 JAVA
字号:
/******************************************************************************
 * The contents of this file are subject to the   Compiere License  Version 1.1
 * ("License"); You may not use this file except in compliance with the License
 * You may obtain a copy of the License at http://www.compiere.org/license.html
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * The Original Code is                  Compiere  ERP & CRM  Business Solution
 * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
 * Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
 * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
 * Contributor(s): ______________________________________.
 *****************************************************************************/
package org.compiere.print;

import java.io.*;
import java.awt.*;
import java.awt.print.*;
import javax.print.*;
import javax.print.attribute.*;

import org.compiere.print.layout.*;
import org.compiere.util.*;

/**
 *	Printer interface
 *
 * 	@author 	Jorg Janke
 * 	@version 	$Id: Print.java,v 1.8 2002/09/01 00:55:05 jjanke Exp $
 */
public class Print implements Pageable, Printable, Doc
{
	/**
	 *	Printer interface constructor
	 *  @param layout layout
	 *  @param isCopy is not the original
	 */
	public Print (LayoutEngine layout, boolean isCopy)
	{
		m_layout = layout;
		m_isCopy = isCopy;
	//	m_id = s_id++;
	//	Log.trace(Log.l4_Data, "Print #" + m_id, "Copy=" + m_isCopy);
	}	//	layout

	/**	Layout					*/
	private LayoutEngine 	m_layout;
	/** Is a Copy				*/
	private boolean			m_isCopy;

//	private int m_id;
//	private static int s_id=0;

	/*************************************************************************/

	/**
	 * 	Get number of pages
	 * 	@return number of pages
	 */
	public int getNumberOfPages()
	{
		return m_layout.getPageCount();
	}	//	getNumberOfPages

	/**
	 * 	Do we have the page
	 * 	@param pageIndex page index
	 * 	@return true if page exists
	 */
	private boolean havePage (int pageIndex)
	{
		if (pageIndex < 0 || pageIndex >= m_layout.getPageCount())
			return false;
		return true;
	}	//	havePage

	/**
	 * 	Get Page Format
	 * 	@param pageIndex page index
	 * 	@return Page Format
	 * 	@throws IndexOutOfBoundsException
	 */
	public PageFormat getPageFormat (int pageIndex) throws IndexOutOfBoundsException
	{
		if (!havePage(pageIndex))
			throw new IndexOutOfBoundsException("Print.getPageFormat - no page index" + pageIndex);
		return m_layout.getPageFormat();
	}	//	getPageFormat

	/**
	 * 	Get Printable
	 * 	@param pageIndex page index
	 * 	@return this
	 * 	@throws IndexOutOfBoundsException
	 */
	public Printable getPrintable (int pageIndex) throws IndexOutOfBoundsException
	{
		if (!havePage(pageIndex))
			throw new IndexOutOfBoundsException("Print.getPrintable - no page index " + pageIndex);
		return this;
	}	//	getPrintable

	/**
	 * 	Print Page
	 * 	@param graphics graphics
	 * 	@param pageFormat page format (ignored)
	 * 	@param pageIndex page index
	 * 	@return PageExists/NoSuchPage
	 * 	@throws PrinterException
	 */
	public int print (Graphics graphics, PageFormat pageFormat, int pageIndex)
		throws PrinterException
	{
		if (!havePage(pageIndex))
			return Printable.NO_SUCH_PAGE;
		//
		Rectangle r = new Rectangle (0, 0, (int)m_layout.getPaper().getWidth(true), (int)m_layout.getPaper().getHeight(true));
		Page page = m_layout.getPage(pageIndex+1);
		//
	//	Log.trace(Log.l5_DData, "Print #" + m_id, "PageIndex=" + pageIndex + ", Copy=" + m_isCopy);
		page.paint((Graphics2D)graphics, r, false, m_isCopy);	//	sets context
		m_layout.getHeaderFooter().paint((Graphics2D)graphics, r, false);
		//
		return Printable.PAGE_EXISTS;
	}	//	print

	/*************************************************************************/

	/**
	 * 	Get the doc flavor
	 * 	@return  SERVICE_FORMATTED.PAGEABLE
	 */
	public DocFlavor getDocFlavor()
	{
		return DocFlavor.SERVICE_FORMATTED.PAGEABLE;
	}	//	getDocFlavor

	/**
	 * 	Get Print Data
	 * 	@return this
	 * 	@throws IOException
	 */
	public Object getPrintData() throws IOException
	{
		return this;
	}	//	getPrintData

	/**
	 * Obtains the set of printing attributes for this doc object. If the
	 * returned attribute set includes an instance of a particular attribute
	 * <I>X,</I> the printer must use that attribute value for this doc,
	 * overriding any value of attribute <I>X</I> in the job's attribute set.
	 * If the returned attribute set does not include an instance
	 * of a particular attribute <I>X</I> or if null is returned, the printer
	 * must consult the job's attribute set to obtain the value for
	 * attribute <I>X,</I> and if not found there, the printer must use an
	 * implementation-dependent default value. The returned attribute set is
	 * unmodifiable.
	 *
	 * @return  Unmodifiable set of printing attributes for this doc, or null
	 *          to obtain all attribute values from the job's attribute
	 *          set.
	 */
	public DocAttributeSet getAttributes()
	{
		return null;
	}	//	getAttributes

	/**
	 * 	Obtains a reader for extracting character print data from this doc.
	 * 	@return  null
	 * 	@exception  IOException
	 */
	public Reader getReaderForText() throws IOException
	{
		return null;
	}	//	getReaderForText

	/**
	 * 	Obtains an input stream for extracting byte print data from this doc.
	 * 	@return	null
	 * 	@exception  IOException
	 */
	public InputStream getStreamForBytes() throws IOException
	{
		return null;
	}	//	getStreamForBytes

}	//	Print

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -