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

📄 jfoperation.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
字号:
/**
 *    $Id:JFOperation.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.shape.base.AbstractObject;
import com.jfimagine.jfgraph.shape.base.AbstractShape;
import com.jfimagine.jfgraph.shape.base.ObjectList;

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


/**
 *  Class JFOperation is used to record an individual operation, for furthur undo/redo usages.
 */
public abstract class JFOperation{
        
	public static final int OPER_MOVE		=1;
	public static final int OPER_ROTATE		=2;
	public static final int OPER_MIRROR		=3;
	public static final int OPER_FLIP		=4;
	public static final int OPER_ALIGNMENT		=5;

	public static final int OPER_NEW		=10;
	public static final int OPER_REMOVE		=11;
	public static final int OPER_COPY		=12;
	public static final int OPER_PASTE		=13;
	public static final int OPER_CUT		=14;
	       
	public static final int OPER_MOVENODE		=20;
	public static final int OPER_MOVELABEL		=21;

	public static final int OPER_ADDPORT		=30;
	public static final int OPER_REMOVEPORT		=31;
	public static final int OPER_BINDPORTS		=32;
	public static final int OPER_UNBINDPORTS	=33;

	public static final int OPER_GROUP		=40;
	public static final int OPER_UNGROUP		=41;

	public static final int OPER_SENDTOBACK		=50;
	public static final int OPER_BRINGTOFRONT	=51;

	public static final int OPER_MODIFY_TEXT	=60;
	public static final int OPER_MODIFY_PROPERTIES	=61;
	public static final int OPER_MODIFY_ARROW	=62;
	public static final int OPER_MODIFY_LINEFORMAT	=63;
	public static final int OPER_MODIFY_FONTFORMAT	=64;
	public static final int OPER_MODIFY_FILLFORMAT	=65;

	public static final int OPER_MODIFY_LAYERS	=70;
	public static final int OPER_ZOOM		=71;


	protected JFPage m_page;
       
	private int m_actionId	=0;
	/** get action id of this operation*/
	public int getActionId(){
		return m_actionId;
	}                   
	/** set a new action id of this operation*/
	public void setActionId(int id){
		m_actionId	=id;
	}

 	/**
 	 * object id list.
 	 */
	private List m_objectIdList =new ArrayList();
	
	/** get the object id list from a object list */
	protected List getObjectIdList(List objectList){
		List idList	=new ArrayList();
		if (objectList!=null && objectList.size()>0){
			Iterator it	=objectList.iterator();
			while (it!=null && it.hasNext()){			
				Object obj	=it.next();
				if (obj instanceof AbstractObject){
					AbstractObject aObj	=(AbstractObject)obj;
					idList.add(new Integer(aObj.getObjectId()));
				}
			}
		}

		
		return idList;		
	}

	/** set object list in operation, actually it's setting a new object id list.
	 *  @param objectList All items in list must be AbstractObject.
	 */
	public void setObjectList(List objectList){
		m_objectIdList	=getObjectIdList(objectList);
	}

	/** set object id in operation
	 *  actually it's setting the first object id in the object id list.
	 */
	public void setObjectId(int objectId){
		m_objectIdList	=new ArrayList();
		m_objectIdList.add(new Integer(objectId));		
	}


	/** get an object according a specified object id in list
	 *  @param objectId The id of a object.
	 *  @param returnParent True return the parent group if this object is within a group, false the object itself.
	 */
	protected AbstractObject getObject(int objectId, boolean returnParent){
		try{
			JFLayer	layer		=m_page.getCurrentLayer();
			ObjectList objList	=layer.getShapeList();
			AbstractObject obj=(AbstractObject)objList.getByObjectId(objectId);
			if (obj!=null){
				return obj;
			}else{  
				return objList.getFromGroupsByObjectId(objectId,returnParent);
			}
		}catch(Exception e){
			return null;
		}		
	}

	
	/** get the first object according to the first object id in list*/
	public AbstractObject getObject(){
		if (m_objectIdList.size()==0)
			return null;
		
		try{
			Integer iObj	=(Integer)m_objectIdList.get(0);
			int objectId	=iObj.intValue();
			
			return getObject(objectId,false);
			
		}catch(Exception e){
			return null;
		}
	}

	/** get id of the first object according to the first object id in list*/
	public int getObjectId(){
		AbstractObject obj	=getObject();
		if (obj==null)
			return 0;
		else
			return obj.getObjectId();
	}

	/** get all the objects according to the object ids in list
	 *  @param objectIdList An Integer object list contains object ids.
	 */
	protected List getObjectList(List objectIdList){
		List ret	=new ArrayList();

		if (objectIdList.size()==0)
			return ret;

	
		try{    
			Iterator it	=objectIdList.iterator();
			while (it!=null && it.hasNext()){
				Object obj	=it.next();
				if (obj instanceof Integer){
					Integer iObj	=(Integer)obj;
					int objectId	=iObj.intValue();

					AbstractObject aObj	=getObject(objectId,true);
					if (aObj!=null)
						ret.add(aObj);
				}
			}
		}catch(Exception e){
		}

		return ret;
	}

	/** get all the objects according to the object ids in list*/
	public List getObjectList(){
		return getObjectList(m_objectIdList);
	}
     

	/** undo this operation
	 *  @return new objects selected
	 */
	public abstract List undo();

	/** redo this operation
	 *  @return new objects selected
	 */
	public abstract List redo();
	

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

  	/**
    	*   Move all the relational ports of the objects in list.
    	*
    	*/ 	
  	protected void moveRelationalPorts(){
  		m_page.clearAccessTimes();
  		
  		List selection          =getObjectList();
        	ObjectList movedList    =new ObjectList();
        
        	//firstly add rotatable object into movedList from selection.
        	Iterator it     =selection.iterator();
        	while (it!=null && it.hasNext()){
                	AbstractShape drawObj        =(AbstractShape)it.next();
                       	try{
                        	 movedList.add(drawObj);
                       	}catch(Exception e){
                        }
        	}

        
        	//move all relational ports of this selection.
		it	=selection.iterator();
		while (it!=null && it.hasNext()){		
			AbstractShape thisShape	=(AbstractShape)it.next();	
			thisShape.moveRelationalPorts(movedList);
		}
        
        	//unbound BrokenPorts;
		it	=selection.iterator();
		while (it!=null && it.hasNext()){		
			AbstractShape thisShape	=(AbstractShape)it.next();	
			thisShape.unboundBrokenPorts();
		}
  	}

	
	

}

⌨️ 快捷键说明

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