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

📄 jfoperationnew.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
字号:
/**
 *    $Id:JFOperationNew.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.Port;

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

/**
 *  Class JFOperationNew is used to record a new operation.
 */
public class JFOperationNew extends JFOperation{

		
	/**  newObject A new created object. */
	private AbstractShape m_newObject =null;
	/**  attachPort1 A first port of other object that will attach to this object. */
	private int m_attachPortId1		=0;
	private int m_attachPortParentId1	=0;
	
	/**  attachPort2 A second port of other object that will attach to this object. */
	private int m_attachPortId2		=0;
	private int m_attachPortParentId2	=0;


	/**  
	 *    Constructor.
	 *    @param page A page that used to do opeation.
	 *    @param obj The object has been created(this object must be AbstractObject).
	 */        
        public JFOperationNew(JFPage page,Object obj){
        	m_page	=page;
		setActionId(JFOperation.OPER_NEW);
		
		if (obj instanceof AbstractObject){
			AbstractObject aObj	=(AbstractObject)obj;
			setObjectId(aObj.getObjectId());
			m_newObject	=(AbstractShape)aObj;
		}
	}

	/**  
	 *    Constructor.
	 *    @param page A page that used to do opeation.
	 *    @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.
	 */        
        public JFOperationNew(JFPage page,Object obj, Port attachPort1, Port attachPort2){
        	m_page	=page;
		setActionId(JFOperation.OPER_NEW);
		
		if (obj instanceof AbstractObject){
			AbstractObject aObj	=(AbstractObject)obj;
			setObjectId(aObj.getObjectId());
			m_newObject	=(AbstractShape)aObj;
			
			if (attachPort1!=null){
				m_attachPortId1		=attachPort1.getObjectId();
				m_attachPortParentId1	=attachPort1.getParentId();
			}
			
			if (attachPort2!=null){
				m_attachPortId2		=attachPort2.getObjectId();
				m_attachPortParentId2	=attachPort2.getParentId();
			}
		}
	}


        
        private Port getAttachPort1(){
        	if (m_attachPortId1==0 || m_attachPortParentId1==0)
        		return null;
		
		try{        		
			//get the attached port and its parent.
			JFLayer	layer			=m_page.getCurrentLayer();
			AbstractShape attachShape	=(AbstractShape)layer.getShapeList().getByObjectId(m_attachPortParentId1);
                	return (Port)attachShape.getPortList().getByObjectId(m_attachPortId1);
                }catch(Exception e){
                	return null;
                }
	}

        private Port getAttachPort2(){
        	if (m_attachPortId2==0 || m_attachPortParentId2==0)
        		return null;
        	
        	try{	
			//get the attached port and its parent.
			JFLayer	layer			=m_page.getCurrentLayer();
			AbstractShape attachShape	=(AbstractShape)layer.getShapeList().getByObjectId(m_attachPortParentId2);
                	return (Port)attachShape.getPortList().getByObjectId(m_attachPortId2);
                }catch(Exception e){
                	return null;
                }
	}

	/** undo this operation
	 *  @return new objects selected
	 */
	public List undo(){
		Port attachPort1	=getAttachPort1();
		Port attachPort2	=getAttachPort2();

		if (attachPort1!=null)
			m_newObject.detachPort(attachPort1);
		if (attachPort2!=null)
			m_newObject.detachPort(attachPort2);

		try{			
			m_page.getCurrentLayer().getShapeList().removeByObjectId(m_newObject.getObjectId());
		}catch(Exception e){
		}
	
		return null;
	}

	/** redo this operation
	 *  @return new objects selected
	 */
	public List redo(){
		Port attachPort1	=getAttachPort1();
		Port attachPort2	=getAttachPort2();

		if (attachPort1!=null)
			m_newObject.attachPort(attachPort1);
		if (attachPort2!=null)
			m_newObject.attachPort(attachPort2);

		try{
			m_page.getCurrentLayer().getShapeList().add(m_newObject);
		}catch(Exception e){
		}
	
		return getObjectList();
	}

}

⌨️ 快捷键说明

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