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

📄 arcport.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
字号:
/**
 *    $Id:ArcPort.java $
 *
 *    Copyright 2004 ~ 2005  JingFei International Cooperation LTD. All rights reserved. *
 */
package com.jfimagine.jfgraph.shape.arc;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;

import com.jfimagine.jfdom.Document;
import com.jfimagine.jfdom.Element;

import com.jfimagine.jfgraph.shape.base.AbstractObject; 
import com.jfimagine.jfgraph.shape.base.ShapeConst;
import com.jfimagine.jfgraph.shape.base.Port;
import com.jfimagine.jfgraph.shape.base.JFVersion;

import com.jfimagine.utils.commonutil.CommonUtil;

import com.jfimagine.jfgraph.geom.JFPoint;
import com.jfimagine.jfgraph.geom.JFCurvePoint;
import com.jfimagine.jfgraph.geom.GeomConst;

/**
 * ArcPort Class. A port is used for connecting other ports of shapes.
 *
 * @author     CookieMaker    
 *
 * @version $Revision: 1.00 $
 */  
public class ArcPort extends Port{

   /**
    *   A XML string tag represents an port
    */
   public  static final String	 XML_ARCPORT		="ArcPort";
  
   /**
    *   A XML string tag represents port scale of this port.
    */
   public  static final String   XML_SCALE		="scale";

   /**
    *   A XML string tag represents type of this port.
    */
   public  static final String   XML_POINTTYPE		="pointType";

   /**
    *   port scale of the position.
    */
   private	double	m_scale	=0;
   
   /**
    *   point type of port.
    */
   private	int	m_pointType	=0;


   /**
    *   Get the port scale.
    * 
    *   @return  The port scale.
    *
    */ 	
   public double getScale(){
   	return 	m_scale;
   }

   /**
    *   Set the port scale.<br>
    *
    *   @param scale  A new port scale of this port.
    *
    */ 	
   public void setScale(double scale){
   	m_scale	=scale;
   }

   /**
    *   Get the point type.
    * 
    *   @return  The point type.
    *
    */ 	
   public int getPointType(){
   	return 	m_pointType;
   }

   /**
    *   Set the point type
    *
    *   @param pointType  A new point type of this port.
    *
    */ 	
   public void setPointType(int pointType){
   	m_pointType	=pointType;
   }


   /**
    *   Constructor for ArcPort
    */
   public ArcPort(){
   	setObjectType(ShapeConst.SHAPETYPE_ARCPORT);
   	setXMLTag(XML_ARCPORT);
   }	

   /**
    *   Constructor for ArcPort.
    * 
    *   @param parent parent object of this port.
    *   @param portType The type of a port.
    *   @param portPoint The port point of a port.
    *   @param scale  The port scale of current port.
    *   @param pointType The point type of port.
    *
    */ 	
   public ArcPort(AbstractObject parent,int portType, JFPoint portPoint,double scale,int pointType){

   	setObjectType(ShapeConst.SHAPETYPE_ARCPORT);
   	setXMLTag(XML_ARCPORT);
   	
   	setPortType(portType);
   	setParentId(parent.getObjectId());
   	setParent(parent);
   	setFirstPoint(portPoint);
   	setSecondPoint(portPoint);
   	setPortPoint(portPoint);
   	setScale(scale);
   	setPointType(pointType);
   }


   /**
    *   Convert this port to String <br>
    * 
    *   @return  An string represents the content of the port
    *
    */ 	
   public String toString(){
   	
   	StringBuffer buf=new StringBuffer();
   	buf.append(super.toString());
   	buf.append(";scale=");	buf.append(m_scale);
   	buf.append(";type=");	buf.append(m_pointType);
	
	return buf.toString();
   }

   

   /**
    *   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 ArcPort();
  }

   /**
    *   Creates a new object of the same class and with the same contents as this object.
    * 
    *   @return  A clone of this instance.
    *
    */ 	
  public Object clone() throws CloneNotSupportedException{
  	try{

  		ArcPort	port =(ArcPort) super.clone();
		port.setScale(getScale());
		port.setPointType(getPointType());
  		
  		return port;
  		
	}catch(Exception e){
		throw new CloneNotSupportedException(e.getMessage());
	}
  }

   /**
    *   Returns the hashcode for this Object.
    * 
    *   @return hash code for this Point2D.
    *
    */ 	
  public int hashCode(){
       	
  	long  scale   =Double.doubleToLongBits(m_scale);
  	
  	return  super.hashCode() ^
  		(int)(scale ^ (scale >>> 32))^
  		m_pointType;
  }


   /**
    *   Determines whether or not two objects are equal. 
    * 
    * 	@param obj  an object to be compared with this object 
    * 
    *   @return true if the object to be compared is an instance of Port and has the same values; false otherwise.
    *
    */ 	
  public boolean equals(Object obj){
      if (!super.equals(obj))
      		return false;
      	
      if (obj == this)
        	return true;
      if (!(obj instanceof ArcPort))
            	return false;

      ArcPort  port= (ArcPort)obj;
      
      return  	m_scale==port.getScale() && m_pointType==port.getPointType();
  }



   /**
    *   Append necessary xml child for current element,
    *   this method will be called internally by toDOM.
    * 
    *   @param  element A XML element to append child xml nodes
    *   @param version A file version notification so this object can obey the rules to save data.
    *
    */ 	
  protected void appendChildToDOM(Element element,JFVersion version){
	if (element==null)
  		return;

  	super.appendChildToDOM(element,version);
    	element.addChild(new Element(XML_SCALE, m_scale));
    	element.addChild(new Element(XML_POINTTYPE, m_pointType));
  }


   /**
    *   Extract needed xml child from current element,
    *   this method will be called internally by fromDOM.
    * 
    *   @param  element An element used to extract needed xml child
    *   @param version A file version notification so this object can obey the rules to fetch data.
    *
    */ 	
  protected void extractChildFromDOM(Element element,JFVersion version){
      if (element==null)
      	return;
      
      super.extractChildFromDOM(element,version);
      
      m_scale		=Element.getDoubleValue(element.getChild(XML_SCALE));
      m_pointType	=Element.getIntValue(element.getChild(XML_POINTTYPE));
  }


 
   /**
    *   Save this ArcPort to a binary stream <br>
    * 
    *   @param stream An binary output stream
    *
    *   @param version A file version notification so this object can obey the rules to save data.
    *   @exception  java.io.IOException
    *
    */ 	
  public void saveToStream(com.jfimagine.utils.io.JFWriter stream,JFVersion version) throws IOException{

	super.saveToStream(stream,version);

	stream.writeDouble(m_scale);
	stream.writeInt(m_pointType);
  }


   /**
    *   Load port data from a binary stream <br>
    * 
    *   @param stream An binary input stream
    *
    *   @param skipHead Skip head 'TYPE' check, an shape object should always 
    *   has its own shape-type stored, if this shape-type has already been readed,
    *   this loadFromStream should/could not read the type anymore.
    *
    *   @param version A file version notification so this object can obey the rules to fetch data.
    *   @exception  java.io.IOException
    *
    */ 	
  public void loadFromStream(com.jfimagine.utils.io.JFReader stream,boolean skipHead,JFVersion version) throws IOException{
	
	super.loadFromStream(stream,skipHead,version);
	
	m_scale	=stream.readDouble();
	m_pointType	=stream.readInt();
  }



 
 	
 }

⌨️ 快捷键说明

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