exportbase.java

来自「用Java开发的、实现类似Visio功能的应用程序源码」· Java 代码 · 共 254 行

JAVA
254
字号

/**
 *    $Id: ExportBase.java $
 *
 *    Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All rights reserved.
 *
 */
package com.jfimagine.jfgraph.transfer;


import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.RenderingHints;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.geom.AffineTransform;


import com.jfimagine.jfgraph.shape.decorate.JFRuler;
import com.jfimagine.jfgraph.shape.decorate.GridFormat;
import com.jfimagine.jfgraph.shape.decorate.JFPageFormat;
import com.jfimagine.jfgraph.shape.base.ObjectList;
import com.jfimagine.jfgraph.shape.union.JFPage; 


 /**
 * Export base class is used to export a page or a list to some vector or image files.
 *
 * @author     CookieMaker    
 *
 * @version $Revision: 1.3.0 $
 */ 
 
public class ExportBase {
        
	/**Output page type*/	        
        public static final int OUTPUTTYPE_PAGE	=1;
	/**Output list type*/	        
        public static final int OUTPUTTYPE_LIST	=2;
        
        /**An OutputList object, used to output image*/
	protected OutputList m_outputList;
	
	/**An OutputPage object, used to output image*/
	protected OutputPage m_outputPage;
	
	/**current output type*/
	protected int m_outputType	=OUTPUTTYPE_PAGE;
	
	/** if use page bounds or page format to decide the size of an exportation
	 *  this is used when exporting a page.
	 *  True to use page bounds, false use page format.
	 */
	protected boolean m_usePageBounds	=true; 

	/** if use page bounds or page format to decide the size of an exportation
	 *  this is used when exporting a page.
	 *  @return True to use page bounds, false use page format.
	 */
	public boolean isUsePageBounds(){
		return m_usePageBounds;
	}
	public void setUsePageBounds(boolean usePageBounds){
		m_usePageBounds	=usePageBounds;
	}


	/**get current outputList object*/	
	public OutputList getOutputList(){
		return m_outputList;
	}
	
	/**get current outputPage  object*/	
	public OutputPage getOutputPage(){
		return m_outputPage;
	}

        /**get current output type*/
	public int getOutputType(){
		return 	m_outputType;
	}
	
        /**set current output type*/
	public void setOutputType(int outputType){
		m_outputType	=outputType;
		switch (outputType){
			case OUTPUTTYPE_PAGE:
				if (m_outputPage==null)
					m_outputPage	=new OutputPage();
				break;

			case OUTPUTTYPE_LIST:
				if (m_outputList==null)
					m_outputList	=new OutputList();	
				break;
		}
	}

        /**set page output parameters
         * @param page A page data to be output.
         * @param zoomScale A new zoom scale of current page.
         * @param isExportWithGrid Want to export with background grids
         * @param isExportWithRuler Want to export with vertical and horizontal rulers.
         * @param gridFormat Grid format used when isExportWithGrid is true.
         */
	public void setPage(JFPage page,
				  boolean cloneNew,
				  double zoomScale, 
				  boolean isExportWithGrid, 
				  boolean isExportWithRuler, 
				  boolean isMetric,
				  GridFormat gridFormat ){  
		
		setOutputType(OUTPUTTYPE_PAGE); 
		
		m_outputPage.setExportWithGrid(isExportWithGrid);
		m_outputPage.setExportWithRuler(isExportWithRuler);
		m_outputPage.setIsMetric(isMetric);
		m_outputPage.setGridFormat(gridFormat);
		m_outputPage.setPage(page,zoomScale,cloneNew);
	}



        /**set list output parameters
         * @param objList An object list data to be output.
         * @param zoomScale A new zoom scale of current page.
         */
	public void setList(ObjectList objList,
			    boolean cloneNew,
			    double zoomScale){
		
		setOutputType(OUTPUTTYPE_LIST); 
		
		m_outputList.setList(objList,zoomScale,cloneNew);
	}	

   	/** 
     	 *  Draw current page or list to a specified graphics context.
     	 *  @param g A specified graphics context.
    	 */
	public void  draw(Graphics g){
		prepareExport();
		switch (m_outputType){
			case OUTPUTTYPE_PAGE:
				if (m_outputPage!=null)
					m_outputPage.draw(g);
				break;
			case OUTPUTTYPE_LIST:
				if (m_outputList!=null)
					m_outputList.draw(g);
				break;
		}
	}


   	/** 
    	*  Draw current page or list to an internal buffered image.
    	*  @return An image that generated.
    	*/
   	public BufferedImage getImage() {
   		prepareExport();
		switch (m_outputType){
			case OUTPUTTYPE_PAGE:
				if (m_outputPage!=null)
					return m_outputPage.getImage();
			case OUTPUTTYPE_LIST:
				if (m_outputList!=null)
					return m_outputList.getImage();
		}   		
		
		return null;
	}

   	/** 
    	*  Prepare to draw.
    	*/
   	protected void prepareExport(){
		switch (m_outputType){
			case OUTPUTTYPE_PAGE:
				if (m_outputPage!=null)
					m_outputPage.prepareExport(m_usePageBounds);
			case OUTPUTTYPE_LIST:
				if (m_outputList!=null)
					m_outputList.prepareExport();
		}   		
	}

	/** get export width */	
	public int getExportWidth(){
		prepareExport();
		switch (m_outputType){
			case OUTPUTTYPE_PAGE:
				if (m_outputPage!=null)
					return m_outputPage.getExportWidth();
			case OUTPUTTYPE_LIST:
				if (m_outputList!=null)
					return m_outputList.getExportWidth();
		}   		
		return 0;
	}    	

	/** get export height */
	public int getExportHeight(){
		prepareExport();
		switch (m_outputType){
			case OUTPUTTYPE_PAGE:
				if (m_outputPage!=null)
					return m_outputPage.getExportHeight();
			case OUTPUTTYPE_LIST:
				if (m_outputList!=null)
					return m_outputList.getExportHeight();
		}   		
		return 0;
	} 
   								
   	/** 
    	*  Export current page or list to a specified output.
    	*/
   	public boolean export(){
   		//this method would be implemented by subclasses.
   		return true;
	}

   	/** 
    	*  Export current page or list to a specified file.
    	*  @param fileName A specified file name to be exported.
    	*/
   	public boolean export(String fileName){
   		//this method would be implemented by subclasses.
   		return true;
	}

   	/** 
    	*  get export file extension.
    	*  @return the export file extension.
    	*/
   	public String getExportFileExt(){
   		return "";
	}

   	/** 
    	*  get export file description
    	*  @return the export file description
    	*/
   	public String getExportFileDesc(){
   		return "";
	}


	
}

⌨️ 快捷键说明

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