curveport.java

来自「用Java开发的、实现类似Visio功能的应用程序源码」· Java 代码 · 共 379 行

JAVA
379
字号
/**
 *    $Id:CurvePort.java $
 *
 *    Copyright 2004 ~ 2005  JingFei International Cooperation LTD. All rights reserved. *
 */
package com.jfimagine.jfgraph.shape.line;


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;

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

   /**
    *   A XML string tag represents a jfport
    */
   public  static final String	 XML_CURVEPORT		="CurvePort";
  
   /**
    *   A XML string tag represents curve interval of this port.
    */
   public  static final String   XML_TIMEINTERVAL	="timeInterval";

   /**
    *   A XML string tag represents segment id of this port on the curve.
    */
   public  static final String   XML_SEGMENTID		="segmentId";

   /**
    *   A XML string tag represents total segments of the curve.
    */
   public  static final String   XML_TOTALSEGMENTS	="totalSegments";

   /**
    *   the serial number of the curve segments.
    */
   private	int	m_segmentId	=0;

   /**
    *   total number of curve segments.
    */
   private	int	m_totalSegments	=0;

   /**
    *   time interval of the position.
    */
   private	double	m_timeInterval	=0;
   

   /**
    *   Get the curve interval.
    * 
    *   @return  The Curve interval.
    *
    */ 	
   public double getTimeInterval(){
   	return 	m_timeInterval;
   }

   /**
    *   Set the curve interval.<br>
    *
    *   @param interval	A new curve interval of this port.
    *
    */ 	
   public void setTimeInterval(double interval){
   	m_timeInterval	=interval;
   }


   /**
    *   Get the serial number of the curve segments.
    *
    *   @return  The serial number.
    *
    */ 	
   public int getSegmentId(){
   	return m_segmentId;
   }

   /**
    *   Set the serial number of the curve segments.
    *
    *   @param segmentId   A new segment serial number.
    *
    */ 	
   public void setSegmentId(int segmentId){
   	m_segmentId	=segmentId;
   }

   /**
    *   Get total segments of the curve.
    *
    *   @return  The total segments.
    *
    */ 	
   public int getTotalSegments(){
   	return m_totalSegments;
   }

   /**
    *   Set total segments of the curve.
    *
    *   @param  New total segments.
    *
    */ 	
   public void setTotalSegments(int totalSegments){
   	m_totalSegments	=totalSegments;
   }


   /**
    *   Constructor for CurvePort
    */
   public CurvePort(){
   	setObjectType(ShapeConst.SHAPETYPE_CURVEPORT);
   	setXMLTag(XML_CURVEPORT);
   }	


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

   	setObjectType(ShapeConst.SHAPETYPE_CURVEPORT);
   	setXMLTag(XML_CURVEPORT);
   	
   	setPortType(portType);
   	setParentId(parent.getObjectId());
   	setParent(parent);
   	setFirstPoint(portPoint);
   	setSecondPoint(portPoint);
   	setPortPoint(portPoint);

   	setTimeInterval(timeInterval);
   	setSegmentId(1);
   	setTotalSegments(1);
   }

   /**
    *   Constructor for CurvePort.
    * 
    *   @param portType The type of a port.
    *   @param parentId The parent object id of a port.
    *   @param portPoint The port point of a port.
    *   @param timeInterval The time interval of current port.
    *   @param segmentId The serial number of this port point on which segment of the curve segments.
    *   @param totalSegments Total curve segments.
    *
    */ 	
   public CurvePort(int portType, int parentId,JFPoint portPoint,double timeInterval, int segmentId, int totalSegments){

   	setObjectType(ShapeConst.SHAPETYPE_CURVEPORT);
   	setXMLTag(XML_PORT);
   	
   	setPortType(portType);
   	setParentId(parentId);
   	setFirstPoint(portPoint);
   	setSecondPoint(portPoint);
   	setPortPoint(portPoint);

   	setTimeInterval(timeInterval);
   	setSegmentId(segmentId);
   	setTotalSegments(totalSegments);
   }

   /**
    *   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(";segmentId=");	buf.append(m_segmentId);
   	buf.append(";totalSegments=");	buf.append(m_totalSegments);
   	buf.append(";timeInterval=");	buf.append(m_timeInterval);
	
	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 CurvePort();
  }

   /**
    *   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{

  		CurvePort	port =(CurvePort) super.clone();
  		
		port.setTimeInterval(getTimeInterval());
		port.setSegmentId(getSegmentId());
		port.setTotalSegments(getTotalSegments());

  		
  		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  interval   =Double.doubleToLongBits(m_timeInterval);
  	
  	return  super.hashCode() ^
  		m_segmentId ^
  		m_totalSegments^
  		(int)(interval ^ (interval >>> 32));
  }


   /**
    *   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 CurvePort))
            	return false;

      CurvePort  port= (CurvePort)obj;
      
      return  	(m_segmentId==port.m_segmentId) &&
      		(m_totalSegments==port.m_totalSegments) &&
      		(m_timeInterval==port.m_timeInterval);
  }



   /**
    *   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_TIMEINTERVAL,m_timeInterval));
    	element.addChild(new Element(XML_SEGMENTID, m_segmentId));
    	element.addChild(new Element(XML_TOTALSEGMENTS, m_totalSegments));
  }


   /**
    *   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_timeInterval	=Element.getDoubleValue(element.getChild(XML_TIMEINTERVAL));
      m_segmentId	=Element.getIntValue(element.getChild(XML_SEGMENTID));
      m_totalSegments	=Element.getIntValue(element.getChild(XML_TOTALSEGMENTS));
  }


 
   /**
    *   Save this CurvePort 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_timeInterval);
	stream.writeInt(m_segmentId);
	stream.writeInt(m_totalSegments);
  }


   /**
    *   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_timeInterval	=stream.readDouble();
	m_segmentId	=stream.readInt();
	m_totalSegments	=stream.readInt();
  }


 
 	
 }

⌨️ 快捷键说明

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