📄 nodelist.java
字号:
/**
* $Id:NodeList.java $
*
* Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All rights reserved. *
*/
package com.jfimagine.jfgraph.shape.base;
import java.awt.Graphics;
import java.awt.Color;
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.ObjectList;
import com.jfimagine.jfgraph.shape.base.Node;
import com.jfimagine.jfgraph.geom.GeomConst;
import com.jfimagine.jfgraph.geom.JFPoint;
import com.jfimagine.jfgraph.geom.Rect;
/**
* NodeList class. A node list is used to manipulate node issues.
*
* @author CookieMaker
*
* @version $Revision: 1.00 $
*/
public class NodeList extends ObjectList{
/**
* A XML string tag represents a Node List
*/
public static final String XML_NODELIST ="NodeList";
/**
* Constructor for NodeList
*/
public NodeList(){
setObjectType(ShapeConst.OBJECTTYPE_NODELIST);
setXMLTag(XML_NODELIST);
}
/**
* Set parent object of each node in the list.
* @param parentId A new id of a parent object.
*/
public void setParent(AbstractObject obj){
if (obj==null) return;
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Node node =(Node)it.next();
node.setParent(obj);
}
}
/**
* Get the index of a node within the list.
*
* @param node A node to be found.
*
* @return The index.
*
*/
public int getIndex(Node node){
if (node==null) return -1;
try{
return getIndexByObjectId(node.getObjectId());
}catch(Exception e){
return -1;
}
}
/**
* Creates a new AbstractObject of the same class and with the same contents as this object.
* This method implements the method defined in AbstractObject.
*
* @return A clone of this class.
*
*/
protected AbstractObject cloneMe() throws CloneNotSupportedException{
return new NodeList();
}
/**
* Draw current object on graphic canvas.
*
* @param g A graphic canvas.
* @param ifRotate If user's operation or other actions force objects to be rotated.
*
*/
public void draw(Graphics g, boolean ifRotate){
if (g==null)
return;
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Node node =(Node)it.next();
node.draw(g,ifRotate);
}
}
/**
* Get which node that intersects with point pnt.
*
* @param pnt A JFPoint used to test intersection.
* @param usage Purpose to get a node intersected, e.g. move or rotate.
*
* @return A node of current shape.
*
*/
public Node nodeIntersects(JFPoint pnt,int usage){
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Node node =(Node)it.next();
if (node.intersects(pnt))
return node;
}
return null;
}
/**
* Get the maximum bounds of this all nodes.
*
* @return The bounds rectangle of all nodes.
*
*/
public Rect getBounds(){
double minx=GeomConst.LARGE_VALUE,miny=GeomConst.LARGE_VALUE,
maxx=-GeomConst.LARGE_VALUE,maxy=-GeomConst.LARGE_VALUE;
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Node node =(Node)it.next();
minx =Math.min(minx,node.getXOffset());
miny =Math.min(miny,node.getYOffset());
maxx =Math.max(maxx,node.getXOffset());
maxy =Math.max(maxy,node.getYOffset());
}
if (minx>maxx) minx =maxx;
if (miny>maxy) miny =maxy;
return new Rect(minx,miny,maxx-minx,maxy-miny);
}
/**
* Remove last node in this list.
* @return Last node that remained.
*
*/
public Node removeLastNode(){
try{
if (size()==0)
return null;
else{
removeByIndex(size()-1);
if (size()==0)
return null;
else
return (Node)getByIndex(size()-1);
}
}catch(Exception e){
return null;
}
}
/** set zoom scale of all nodes.
*/
public void setZoomScale(double zoomScale){
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Node node =(Node)it.next();
node.setZoomScale(zoomScale);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -