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

📄 jfoperationmanager.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 *    $Id:JFOperationManager.java $
 *
 *    Copyright 2004 ~ 2005  JingFei International Cooperation LTD. All rights reserved. *
 */
package com.jfimagine.jfgraph.shape.action;


import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;    


import com.jfimagine.jfgraph.geom.JFPoint;
import com.jfimagine.jfgraph.shape.base.AbstractObject;
import com.jfimagine.jfgraph.shape.base.AbstractShape;
import com.jfimagine.jfgraph.shape.base.ObjectList;
import com.jfimagine.jfgraph.shape.base.Port;
import com.jfimagine.jfgraph.shape.base.Node;

import com.jfimagine.jfgraph.shape.union.JFPage;  
import com.jfimagine.jfgraph.shape.union.JFGroup;  

import com.jfimagine.jfgraph.shape.line.JFLine;
import com.jfimagine.jfgraph.shape.line.JFRegularLine;
import com.jfimagine.jfgraph.shape.polygon.JFPolygon;

import com.jfimagine.jfgraph.shape.decorate.Arrow;
import com.jfimagine.jfgraph.shape.decorate.FontFormat;
import com.jfimagine.jfgraph.shape.decorate.FillFormat;
import com.jfimagine.jfgraph.shape.decorate.LineFormat;


/**
 *  Class JFOperationManager is used to to undo or redo operations.
 */
public class JFOperationManager{
        
        /** A JFPage to be undone or redone. */
        private JFPage m_page;
        /** an undo list contains JFOperations */
	private List m_undoList	=new ArrayList();
        /** a redo list contains JFOperations */
	private List m_redoList	=new ArrayList();     

	/** undo depth */	
	private int m_depth	=20;

	/** get undo depth*/	
	public int getDepth(){
		return m_depth;
	}
	/** set undo depth*/	
	public void setDepth(int depth){
		m_depth	=depth;
	}
        
	/**
	 *  Constructor
	 *  @param page A JFPage to be undone or redone.
	 */
	public JFOperationManager(JFPage page){
		m_page	=page;
	} 
	         
	/** clear undo operation list*/
	public void clearUndoList(){
		try{
			m_undoList.clear();
		}catch(Exception e){
		}
	}
	/** get undo operation list*/
	public List getUndoList(){
		return m_undoList;
	}                   

	/** clear redo operation list*/
	public void clearRedoList(){
		try{
			m_redoList.clear();
		}catch(Exception e){
		}
	}
	/** get redo operation list*/
	public List getRedoList(){
		return m_redoList;
	}                   

	/** get current layer id*/
	private int getCurrentLayerId(){
		return m_page.getCurrentLayer().getObjectId();
	}
	
	//***********************************************************************

	/** has any undo operation*/
	public boolean hasUndo(){
		return m_undoList.size()>0;
	}

	/** has any redo operation*/
	public boolean hasRedo(){
		return m_redoList.size()>0;
	}
	
	/** get last operation object */
	private JFOperation getLastOperation(){
		int size	=m_undoList.size();
		if (size>0){
			try{		
				return (JFOperation)m_undoList.get(size-1);
			}catch(Exception e){
				return null;
			}
		}
		return null;
	}


	/** undo this operation
	 *  @return new objects selected
	 */
	public List undo(){
		List ret=null;
		try{
			int size	=m_undoList.size();
			if (size>0){
				JFOperation op	=(JFOperation)m_undoList.get(size-1);
				ret =op.undo();
				m_undoList.remove(size-1);
				m_redoList.add(op);
			}
		}catch(Exception e){
		}
		return ret;
	}
	

	/** redo this operation
	 *  @return new objects selected
	 */
	public List redo(){
		List ret=null;
		try{
			int size	=m_redoList.size();
			if (size>0){
				JFOperation op	=(JFOperation)m_redoList.get(size-1);
				ret=op.redo();
				m_redoList.remove(size-1);
				m_undoList.add(op);
			}
		}catch(Exception e){
		}
		return ret;
	}
	
        
        /** add a new operation into undo list */
	private void addOperation(JFOperation op){
		m_undoList.add(op);
		clearRedoList();
		
		try{
			while (m_undoList.size()>m_depth){
				m_undoList.remove(0);
			}
		}catch(Exception e){
		}
	}
	
	//*******************  move operation  ****************************************************

	/** add a move operation to undo list
	 *  @param obj The object has been moved(this object must be AbstractObject or a list of AbstractObject).
	 *  @param xOffset the x offset of the object moved
	 *  @param yOffset the y offset of the object moved.
	 */
	public void addMove(Object obj,double xOffset, double yOffset){ 
		if (obj==null) return;
		
		if (obj instanceof AbstractObject || obj instanceof List){			
			JFOperation op  =new JFOperationMove(m_page,obj,xOffset,yOffset);
			addOperation(op);
		}
	}                   


	/** add an alignment operation to undo list
	 *  Note: this alignment operation method will not be a complete one until
	 *  you call JFOperationAlignment.addAlignmentObject and JFOperationAlignment.finalizeAlignment
	 *  to prepare alignment operation manually.
	 *
	 *  @return  A new alignment opearation object to be furthur configured.
	 */
	public JFOperationAlignment addAlignment(){ 
		JFOperationAlignment op  =new JFOperationAlignment(m_page);
		addOperation(op);
		
		return op;
	} 

	
	/** add a move label operation to undo list
	 *  @param obj The object has been moved label(this object must be AbstractObject).
	 *  @param xOffset the x offset of the label moved
	 *  @param yOffset the y offset of the label moved.
	 */
	public void addMoveLabel(Object obj,double xOffset, double yOffset){ 
		if (obj==null) return;
		
		if (obj instanceof AbstractObject){
			JFOperation op  =new JFOperationMoveLabel(m_page,obj,xOffset,yOffset);
			addOperation(op);
		}
	}                   


	//*******************  rotate operation  ****************************************************

	/** add a rotate operation to undo list
	 *  @param obj The object has been moved(this object must be AbstractObject or a list of AbstractObject).
	 *  @param rotateCenter The rotate center point.
	 *  @param originalAngle Original angle of the object.
	 *  @param finalAngle Final angle of the object.
	 */
	public void addRotate(Object obj,JFPoint rotateCenter,double originalAngle,double finalAngle){ 
		if (obj==null) return;
		if (obj instanceof AbstractObject || obj instanceof List){			
			JFOperation op	=new JFOperationRotate(m_page,obj,rotateCenter,originalAngle,finalAngle);
			addOperation(op);
		}
	}                   
	
	/** add a rotate operation to undo list
	 *  @param obj The object has been moved(this object must be AbstractObject or a list of AbstractObject).
	 *  @param rotateCenter The rotate center point.
	 *  @param x1,y1 The first reference point according to rotate center.
	 *  @param x2,y2 The second reference point according to rotate center.
	 */
	public void addRotate(Object obj,JFPoint rotateCenter,double x1, double y1, double x2, double y2){ 
		if (obj==null) return;
		if (obj instanceof AbstractObject || obj instanceof List){			
			JFOperation op	=new JFOperationRotate(m_page,obj,rotateCenter,x1,y1,x2,y2);
			addOperation(op);
		}
	}                   


	//*******************  flip operation  ****************************************************

	/** add a flip operation to undo list
	 *  @param obj The object has been flipped(this object must be AbstractObject or a list of AbstractObject).
	 *  @param baseY a base y coordinate for flip.
	 */
	public void addFlip(Object obj,double baseY){ 
		if (obj==null) return;
		
		if (obj instanceof AbstractObject || obj instanceof List){
			JFOperation op  =new JFOperationFlip(m_page,obj,baseY);
			addOperation(op);
		}
	}                   

	//*******************  mirror operation  ****************************************************

	/** add a mirror operation to undo list
	 *  @param obj The object has been mirrored(this object must be AbstractObject or a list of AbstractObject).
	 *  @param baseX a base x coordinate for mirror.
	 */
	public void addMirror(Object obj,double baseX){ 
		if (obj==null) return;
		
		if (obj instanceof AbstractObject || obj instanceof List){
			JFOperation op  =new JFOperationMirror(m_page,obj,baseX);
			addOperation(op);
		}
	}                   


	//*******************  new/remove operation  ****************************************************

	/** add a new operation to undo list
	 *  @param obj The object has been created(this object must be AbstractObject).
	 */
	public void addNew(Object obj){ 
		if (obj==null) return;
		
		if (obj instanceof AbstractObject){
			JFOperation op  =new JFOperationNew(m_page,obj);
			addOperation(op);
		}
	}                   

	/** add a new operation to undo list
	 *    @param obj The object has been created(this object must be AbstractObject).
	 *    @param attachPort1 A first port of other object that will attach to this object.
	 *    @param attachPort2 A second port of other object that will attach to this object.
	 */

⌨️ 快捷键说明

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