📄 portlist.java
字号:
}else if (len1>len2){
firstPoint.setValue(midPoint);
port.setPortPoint(portPoint);
}else{
secondPoint.setValue(midPoint);
port.setPortPoint(portPoint);
}
}
}
}
/**
* Pick a port within this port list, according to the current x,y position
* @param x,y Current picking position.
*
*/
public Port pickPort(double x,double y){
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Port port =(Port)it.next();
JFPoint portPoint =port.getPortPoint();
if (portPoint.distance(x,y)<=GeomConst.PICK_OFFSET)
return port;
}
return null;
}
/**
* Remove a port from this shape.
* @param port A port to be removed.
*
*/
public boolean removePort(Port port){
if (port==null)
return false;
try{
int index =getIndexByObjectId(port.getObjectId());
Port portRemoved =(Port)getByIndex(index);
if (portRemoved!=null && portRemoved.equals(port)){
port.detachAll();
removeByIndex(index);
return true;
}else{
return false;
}
}catch(Exception e){
return false;
}
}
/**
* Scale current port list by specified points and scale percent.
* We only support a concurrent width-height scale here, suppose width as the length from
* basePoint to refPoint1, height as the length from basePoint to refPoint2, and
* one scale percent acts on both width and height.
*
* @param center A center point of these all ports.
* @param basePoint A base point that is unmovable.
* @param refPoint1 A 'width' reference point.
* @param refPoint2 A 'height' reference point.
* @param scale A reference scale percent.
*
*/
public void scaleBy(JFPoint center,JFPoint basePoint, JFPoint refPoint1, JFPoint refPoint2, double scale){
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Port port=(Port)it.next();
port.scaleBy(center.getX(),center.getY(),scale);
}
JFPoint newCenter =Rect.newScaleCenter(center,basePoint,refPoint1,refPoint2,scale);
//move center
moveBy(newCenter.getX()-center.getX(),newCenter.getY()-center.getY());
}
/**
* Scale current portlist by a specified x and y scale.<br>
* This is a special scale method used to scale a shape in arbitrary x and y scale.<br>
* Please see AbstractShape.scaleBy for detailed description.
*
* @param basePoint A base scale point for scaling reference.
* @param xScale A scale percentage in x coordinate, default to 1.0
* @param yScale A scale percentage in y coordinate, default to 1.0
*
*/
public void scaleBy(JFPoint basePoint,double xScale, double yScale){
if (basePoint==null)
return;
double x =basePoint.getX();
double y =basePoint.getY();
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Port port=(Port)it.next();
port.scaleBy(x,y,xScale,yScale);
}
}
/**
* Move current object by an x and y offset.
*
* @param x, y Moving offsets.
*
*/
public void moveBy(double x, double y){
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Port port =(Port)it.next();
port.moveBy(x,y);
}
}
/**
* Rotate current object by a specified point and an angle theta.
*
* @param baseX, baseY A rotate center coordinates.
*
* @param theta A rotate angle.
*
*/
public void rotateBy(double baseX,double baseY, double theta){
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Port port =(Port)it.next();
port.rotateBy(baseX,baseY,theta);
}
}
/**
* Mirror this object by a x coordinate. We make a left-right mirror here.
*
* @param baseX A mirror base x coordinate.
*
*/
public void mirrorBy(double baseX){
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Port port =(Port)it.next();
port.mirrorBy(baseX);
}
}
/**
* Reverse this object by a y coordinate. We make a up-down flip here.
*
* @param baseY A flip base y coordinate.
*
*/
public void flipBy(double baseY){
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Port port =(Port)it.next();
port.flipBy(baseY);
}
}
/**
* Attach one of current port list to a specified port of other shape.
* @param port A new port of other shape.
*
*/
public boolean attachPort(Port port){
if (port==null)
return false;
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Port myPort =(Port)it.next();
myPort.attachPort(port);
// return true;
}
return true;
}
/**
* Detach current port list to a specified port of other shape.
* @param port A port of other shape.
*
*/
public boolean detachPort(Port port){
if (port==null)
return false;
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Port myPort =(Port)it.next();
myPort.detachPort(port);
}
return true;
}
/**
* Detach all ports attached to this port list.
*
*/
public boolean detachAll(){
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Port myPort =(Port)it.next();
myPort.detachAll();
}
return true;
}
/**
* move relational ports.
* @param movedList An object list that has already processed, so don't change them further.
*/
public void moveRelationalPorts(ObjectList movedList){
//move relational ports
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Port port =(Port)it.next();
port.moveRelationalPorts(movedList,true);
}
//move relational ports' parent objects.
it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Port port =(Port)it.next();
port.moveRelationalPorts(movedList,false);
}
}
/**
* unbound broken ports.
*
*/
public void unboundBrokenPorts(){
Iterator it =m_objectList.iterator();
int i=0;
while (it!=null && it.hasNext()){
Port port =(Port)it.next();
port.unboundBrokenPorts();
}
}
/**
* Set parent object id of each port in the list.
* @param parentId A new id of a parent object.
*/
public void setParentId(int parentId){
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Port port =(Port)it.next();
port.setParentId(parentId);
}
}
/**
* Set parent object of each port in the list.
* @param obj A new parent object.
*/
public void setParent(AbstractObject obj){
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Port port =(Port)it.next();
port.setParent(obj);
}
}
/**
* Get which port that intersects with point pnt.
*
* @param pnt A JFPoint used to test intersection.
* @return A port intersects the point.
*
*/
public Port portIntersects(JFPoint pnt){
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Port port =(Port)it.next();
if (port.intersects(pnt))
return port;
}
return null;
}
/** set zoom scale of all ports.
*/
public void setZoomScale(double zoomScale){
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Port port =(Port)it.next();
port.setZoomScale(zoomScale);
}
}
/**
* A loadFromStream method should only load an parentId-objectId list of ports attached,
* So here we use an attachRealPort to ACTUALLY attach some ports to the ports in this list.
*
* @param shapeList A shapeList used to pick out their ports for ports' attached list
*
*/
public void attachRealPort(ObjectList shapeList){
try{
Iterator it =m_objectList.iterator();
while (it!=null && it.hasNext()){
Port port =(Port)it.next();
port.attachRealPort(shapeList);
}
}catch(Exception e){
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -