jfoperationungroup.java
来自「用Java开发的、实现类似Visio功能的应用程序源码」· Java 代码 · 共 165 行
JAVA
165 行
/**
* $Id:JFOperationUngroup.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;
import com.jfimagine.jfgraph.shape.union.JFGroup;
/**
* Class JFOperationUngroup is used to record an ungroup shape operation.
*/
public class JFOperationUngroup extends JFOperation{
/** define an upgroup id object list,
* here we don't use JFOperation.m_objectIdList,
* in order to store both id integer objects and id integer list object.
*
* for a list objects to be ungrouped, there will be single objects that
* cannot be ungrouped or group objects that can be grouped in it.
*/
private List m_ungroupIdList =new ArrayList();
private static final int IDTYPE_SINGLE =1;
private static final int IDTYPE_GROUP =2;
/** an UngroupId class is used to store single object id or multi-id list*/
private class UngroupId{
private int m_idType =IDTYPE_SINGLE;
public int getIdType(){
return m_idType;
}
private int m_id=0;
public int getId(){
return m_id;
}
private List m_idList;
public List getIdList(){
return m_idList;
}
public UngroupId(int id){
m_idType =IDTYPE_SINGLE;
m_id =id;
}
public UngroupId(int id, List idList){
m_idType =IDTYPE_GROUP;
m_id =id;
m_idList =idList;
}
}
/**
* Constructor.
* @param page A page that used to do opeation.
* @param l An object collection to be ungrouped.
*/
public JFOperationUngroup(JFPage page,List l){
m_page =page;
setActionId(JFOperation.OPER_UNGROUP);
if (l==null || l.size()==0)
return;
Iterator it =l.iterator();
while (it!=null && it.hasNext()){
AbstractObject obj =(AbstractObject)it.next();
if (!(obj instanceof JFGroup)){
//simply add the object id to list
m_ungroupIdList.add(new UngroupId(obj.getObjectId()));
}else{
//add sub object id list of group to list
JFGroup g =(JFGroup)obj;
List idList =getObjectIdList(g.getList().getList());
m_ungroupIdList.add(new UngroupId(g.getObjectId(),idList));
}
}
}
/** undo this operation
* @return new objects selected
*/
public List undo(){
List ret =new ArrayList();
Iterator it =m_ungroupIdList.iterator();
while (it!=null && it.hasNext()){
UngroupId gid =(UngroupId)it.next();
int id =gid.getId();
AbstractObject obj=null;
switch (gid.getIdType()){
case IDTYPE_SINGLE:
//do nothing for a single object.
obj =getObject(id,false);
break;
case IDTYPE_GROUP:
//re-group for multi-objects within a group.
List objList =getObjectList(gid.getIdList());
obj =m_page.groupShapes(objList);
obj.setObjectId(id);
break;
}
if (obj!=null)
ret.add(obj);
}
return ret;
}
/** redo this operation
* @return new objects selected
*/
public List redo(){
List objList =new ArrayList();
Iterator it =m_ungroupIdList.iterator();
while (it!=null && it.hasNext()){
UngroupId gid =(UngroupId)it.next();
int id =gid.getId();
Object obj =getObject(id,false);
if (obj!=null)
objList.add(obj);
}
return m_page.ungroupShapes(objList);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?