ellipseport.java

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

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


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.JFEllipsePoint;
import com.jfimagine.jfgraph.geom.GeomConst;

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

   /**
    *   A XML string tag represents an port
    */
   public  static final String	 XML_ELLIPSEPORT		="EllipsePort";
  
   /**
    *   A XML string tag represents target side(on the outer rectangle) type of this port.
    */
   public  static final String   XML_TARGETSIDETYPE		="targetSideType";

   

   /**
    *   a target side type is the type of the rectangle's side that the radiant line from center to this point intersects.
    *   note: the RECTANGLE means the outer rectangle of this ellipse.
    */
   private	int	m_targetSideType=0;


   /**
    *   Get the target side type.
    * 
    *   @return  The target side type.
    *
    */ 	
   public int getTargetSideType(){
   	return 	m_targetSideType;
   }

   /**
    *   Set the target side type
    *
    *   @param targetSideType  A new target side type of this port.
    *
    */ 	
   public void setTargetSideType(int targetSideType){
   	m_targetSideType	=targetSideType;
   }


   /**
    *   Constructor for EllipsePort
    */
   public EllipsePort(){
   	setObjectType(ShapeConst.SHAPETYPE_ELLIPSEPORT);
   	setXMLTag(XML_ELLIPSEPORT);
   }	

   /**
    *   Constructor for EllipsePort.
    * 
    *   @param parent parent object of this port.
    *   @param portType The type of a port.
    *   @param firstPoint The first reference end point of a port.
    *   @param secondPoint The second reference end point of a port.
    *   @param portPoint The port point of a port.
    *   @param targetSideType The target side type
    *
    */ 	
   public EllipsePort(AbstractObject parent,int portType, JFPoint firstPoint, JFPoint secondPoint, JFPoint portPoint,int targetSideType){
	
	/**
	 *  1. target point is just the secondPoint here.
	 *  2. first point is the center of ellipse.
	 */
   	setObjectType(ShapeConst.SHAPETYPE_ELLIPSEPORT);
   	setXMLTag(XML_ELLIPSEPORT);
   	
   	setPortType(portType);
   	setParentId(parent.getObjectId());
   	setParent(parent);
   	setFirstPoint(firstPoint);
   	setSecondPoint(secondPoint);
   	setPortPoint(portPoint);
   	setTargetSideType(targetSideType);
   }


   /**
    *   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(";targetSideType=");	buf.append(m_targetSideType);
	
	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 EllipsePort();
  }

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

  		EllipsePort	port =(EllipsePort) super.clone();
		port.setTargetSideType(getTargetSideType());
  		
  		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(){
 	
  	return  super.hashCode() ^
  		m_targetSideType;
  }


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

      EllipsePort  port= (EllipsePort)obj;
      
      return  	m_targetSideType==port.getTargetSideType();
  }



   /**
    *   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_TARGETSIDETYPE, m_targetSideType));
  }


   /**
    *   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_targetSideType	=Element.getIntValue(element.getChild(XML_TARGETSIDETYPE));
  }


 
   /**
    *   Save this EllipsePort 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.writeInt(m_targetSideType);
  }


   /**
    *   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_targetSideType	=stream.readInt();
  }


 
 	
 }

⌨️ 快捷键说明

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