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

📄 jfoperationunbindports.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
字号:
/**
 *    $Id:JFOperationUnbindPorts.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 JFOperationUnbindPorts is used to record an unbind ports operation.
 */
public class JFOperationUnbindPorts extends JFOperation{

	/** A list of ports at current mouse position */
	private   List m_portList	=new ArrayList();  
	
	/** current mouse position */
	private   JFPoint m_mousePos	=new JFPoint();

	/**  
	 *    Constructor.
	 *    @param page A page that used to do opeation.
	 *    @param mousePos Current mouse position.
	 */        
        public JFOperationUnbindPorts(JFPage page,JFPoint mousePos){
        	m_page	=page;
		setActionId(JFOperation.OPER_BINDPORTS);
		m_mousePos.setValue(mousePos);
		try{
			List l	=m_page.getCurrentLayer().portIntersectsList(mousePos);
			if (l==null || l.size()==0)
				return;
			
			Iterator it	=l.iterator();
			while (it!=null && it.hasNext()){
				Port port	=(Port)it.next();
				m_portList.add(port.clone());
			}
		}catch(Exception e){
		}
	}


	/** undo this operation 
	 *  @return new objects selected
	 */
	public List undo(){
		//we cannot simply call an BIND method here.
		//actually we need to restore all ports' situation before unbind.
		try{
			Iterator it	=m_portList.iterator();
			while (it!=null && it.hasNext()){
				Port port=(Port)it.next();
				AbstractObject obj=getObject(port.getParentId(),false);
				if (obj==null) continue;
				
				AbstractShape aShape=(AbstractShape)obj;
				Port actualPort	=aShape.getPortByObjectId(port.getObjectId());
				if (actualPort==null) continue;

			
				//recover attached list.				
				actualPort.setAttachedListStr(port.getAttachedListStr());
				actualPort.attachRealPort(m_page.getCurrentLayer().getShapeList());

				//recover port position.				
				JFPoint oldPos	=port.getPortPoint();
				JFPoint newPos	=actualPort.getPortPoint();								
				if (!newPos.equals(oldPos,true)){
					if (aShape.isOpenShape() && actualPort.getPortType()==Port.PORTTYPE_DEFAULT){
						aShape.movePort(actualPort,oldPos.getX(),oldPos.getY());
					}
				}
				
			}	
		}catch(Exception e){
		}
	
		return null;
	}

	/** redo this operation
	 *  @return new objects selected
	 */
	public List redo(){
		try{
			m_page.unbindPorts(m_mousePos);
		}catch(Exception e){
		}
	
		return null;
	}

	
}

⌨️ 快捷键说明

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