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

📄 arrow.java

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


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

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.Stroke;
import java.awt.BasicStroke;

import java.awt.geom.GeneralPath;


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


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.JFVersion;


 
 /**
 * Arrow class.
 * An arrow class is used for any line or curve shapes.
 *
 * @author     CookieMaker    
 *
 * @version $Revision: 1.00 $
 */  
 public class Arrow  extends AbstractObject{

   /**
    *   A XML string tag represents an arrow format.
    */
   public  static final String	 XML_ARROW		="Arrow";


   /**
    *   A XML string tag represents the arrow type of begin point of a line/curve.
    */
   public  static final String	 XML_STARTARROW		="startArrowType";
  
   /**
    *   A XML string tag represents the arrow type of end point of a line/curve.
    */
   public  static final String	 XML_ENDARROW		="endArrowType";

   private static Arrow m_defaultArrow	=new Arrow();
   /**
    *   set global default arrow
    *   @param fontFormat A new arrow
    */
   public static void setDefaultArrow(Arrow arrow){
   	m_defaultArrow.setValue(arrow);
   }
   /**
    *   get global default arrow
    *   @return The global default arrow
    */
   public static Arrow getDefaultArrow(){
   	return m_defaultArrow;
   }
   
   

   /**
    *   A start arrow type of a shape.
    */	   
   private  int m_startArrow	=ARROWTYPE_NONE;
   
   /**
    *  Get start arrow type.
    *  @return start arrow type.
    */
   public int getStartArrow(){
   	return m_startArrow;
   }
   /**
    *  Set start arrow type.
    *  @param arrow start arrow type.
    */
   public void setStartArrow(int arrow){
   	m_startArrow	=arrow;
   }

   /**
    *   A end arrow type of a shape.
    */	   
   private  int m_endArrow	=ARROWTYPE_NONE;

   /**
    *  Get end arrow type.
    *  @return end arrow type.
    */
   public int getEndArrow(){
   	return m_endArrow;
   }
   /**
    *  Set end arrow type.
    *  @param arrow end arrow type.
    */
   public void setEndArrow(int arrow){
   	m_endArrow	=arrow;
   }
   
   
   /** 
    *  Set the value of this arrow.
    *  @param arrow A new arrow value.
    */	   
   public void setValue(Arrow arrow){
   	if (arrow!=null){
   		m_startArrow	=arrow.m_startArrow;
   		m_endArrow	=arrow.m_endArrow;
   	}
   }

   /** 
    *  Constructor of Arrow.
    */
   public Arrow(){
   	setObjectType(ShapeConst.DECORATETYPE_ARROW);
   	setXMLTag(XML_ARROW);   	
   	
   	if (m_defaultArrow!=null){
   		setValue(m_defaultArrow);
   	}
   }  
   
   /** 
    *  Constructor of Arrow.
    */
   public Arrow(Arrow arrow){
   	setObjectType(ShapeConst.DECORATETYPE_ARROW);
   	setXMLTag(XML_ARROW);   	
   	setValue(arrow);
   }  

   /**
    *   Convert this object to String 
    * 
    *   @return  An string represents the content of the object
    *
    */ 	
   public String toString(){
  	StringBuffer buf =new StringBuffer();
  	buf.append(super.toString());
  	buf.append(";startArrow=");  	buf.append(m_startArrow);
  	buf.append(";endArrow=");  	buf.append(m_endArrow);
  	
  	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 Arrow();
  }
  
     /**
    *   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{
  		Arrow	arrow =(Arrow) super.clone();
  		arrow.setValue(this);
  		return arrow;
  		
	}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_startArrow ^
  		m_endArrow;
  }


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

      Arrow arrow= (Arrow)obj;
      
      return	(m_startArrow==arrow.m_startArrow)&&
      		(m_endArrow==arrow.m_endArrow);
  }


   /**
    *   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_STARTARROW, m_startArrow));
    	element.addChild(new Element(XML_ENDARROW,m_endArrow));
  }

   /**
    *   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_startArrow	=Element.getIntValue(element.getChild(XML_STARTARROW));
      m_endArrow	=Element.getIntValue(element.getChild(XML_ENDARROW));
  }

   /**
    *   Save this object 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_startArrow);
	stream.writeInt(m_endArrow);
  }


   /**
    *   Load object 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_startArrow		=stream.readInt();
	m_endArrow		=stream.readInt();
  }


   /**  An empty arrow type.   */
   public  static final int	ARROWTYPE_NONE		=0;
   

   /**  A solid triangle arrow type.   */
   public  static final int	ARROWTYPE_TRIANGLE			=1;
   /**  An empty triangle arrow type.   */
   public  static final int	ARROWTYPE_TRIANGLE_EMPTY		=2;
   /**  An arrow type with two inclined lines constructed an arrow.   */
   public  static final int	ARROWTYPE_TRIANGLELINES			=3;
   /**  An arrow type with one inclined line on the end of a line.   */
   public  static final int	ARROWTYPE_LINE_INCLINED			=4;
   /**  An arrow type with one inclined line on the end of a line, but intersects it.  */
   public  static final int	ARROWTYPE_LINE_INCLINED_INTERSECT	=5;

   /**  An empty small circle on the end of line. */
   public  static final int	ARROWTYPE_CIRCLE_EMPTY			=6;
   /**  A solid small circle on the end of line. */
   public  static final int	ARROWTYPE_CIRCLE			=7;
   /**  An empty small rectangle on the end of line. */
   public  static final int	ARROWTYPE_RECTANGLE_EMPTY		=8;
   /**  A solid small rectangle on the end of line. */
   public  static final int	ARROWTYPE_RECTANGLE			=9;
   /**  An empty diamond on the end of line. */
   public  static final int	ARROWTYPE_DIAMOND_EMPTY			=10;

   /**  An empty diamond and an empty small circle on the end of line. */

⌨️ 快捷键说明

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