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

📄 property.java

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


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

 
 
 /**
 * Property class.  An instance for BaseProperty.
 *
 * @author     CookieMaker    
 *
 * @version $Revision: 1.00 $
 */  
 public class Property extends AbstractObject{

   /**
    *   A XML string tag represents a jfproperty
    */
   public  static final String	 XML_PROPERTY		="Property";
   /**
    *   A XML string tag represents the name of this property
    */
   public  static final String   XML_NAME		="name";
   /**
    *   A XML string tag represents the type of this property
    */
   public  static final String   XML_TYPE		="type";
   /**
    *   A XML string tag represents the display format of this property
    */
   public  static final String   XML_FORMAT		="format";
   /**
    *   A XML string tag represents the string value of this property
    */
   public  static final String   XML_VALUE		="value";
   /**
    *   A XML string tag represents the comment of this property
    */
   public  static final String   XML_COMMENT		="comment";


   /**
    *   PropertyType: String type
    */ 
   public static final int  PROPERTYTYPE_STRING		=1;

   /**
    *   PropertyType description: String type
    */ 
   public static final String  PROPERTYTYPE_DESC_STRING	=com.jfimagine.jfdraw.gui.resource.CADResource.getString("label.property.type.string");
   
   /**
    *   PropertyType: Numeric type
    */ 
   public static final int  PROPERTYTYPE_NUMERIC	=2;

   /**
    *   PropertyType description: Numeric type
    */ 
   public static final String  PROPERTYTYPE_DESC_NUMERIC=com.jfimagine.jfdraw.gui.resource.CADResource.getString("label.property.type.numeric");

   /**
    *   PropertyType: Boolean type
    */ 
   public static final int  PROPERTYTYPE_BOOLEAN	=3;

   /**
    *   PropertyType description: Boolean type
    */ 
   public static final String  PROPERTYTYPE_DESC_BOOLEAN=com.jfimagine.jfdraw.gui.resource.CADResource.getString("label.property.type.boolean");

   /**
    *   PropertyType: Currency type
    */ 
   public static final int  PROPERTYTYPE_CURRENCY	=4;

   /**
    *   PropertyType description: Currency type
    */ 
   public static final String  PROPERTYTYPE_DESC_CURRENCY=com.jfimagine.jfdraw.gui.resource.CADResource.getString("label.property.type.currency");

   /**
    *   PropertyType: DateTime type
    */ 
   public static final int  PROPERTYTYPE_DATETIME	=5;

   /**
    *   PropertyType description: DateTime type
    */ 
   public static final String  PROPERTYTYPE_DESC_DATETIME=com.jfimagine.jfdraw.gui.resource.CADResource.getString("label.property.type.datetime");


   /**
    *   A name of this property, this name should be unique one with properties of a object.
    */
   private	String	m_name="";

   /**
    *   A type of this property, we can use several type for properties, 
    *   e.g. PROPERTYTYPE_STRING,PROPERTYTYPE_NUMERIC,
    *   PROPERTYTYPE_BOOLEAN,PROPERTYTYPE_CURRENCY,PROPERTYTYPE_DATETIME
    */
   private	int	m_type=PROPERTYTYPE_STRING;
   
   /**
    *   A display format for current property, this field should always be used in datetime 
    *   properties or float properties.
    */
   private	String	m_format="";

   /**
    *   The value of current property,we use a string to represent all the types of value here.
    */
   private	String	m_value="";

   /**
    *   The comment of current property.
    */
   private	String	m_comment="";


	
   /**
    *   Constructor for Property
    */
   public Property(){
   	setObjectType(ShapeConst.SHAPETYPE_PROPERTY);
   	setXMLTag(XML_PROPERTY);
   }	

   /**
    *   Get the name of property
    * 
    *   @return  The name of this property
    *
    */ 	
   public String getName(){
   	return m_name;
   }
   
   /**
    *   Set the name of current property.
    * 
    * 	@param  name The name of this property
    *
    */ 	
   public void setName(String name){
   	if (name==null) name ="";
   	m_name	=name;
   }
   

   /** get a string list of all types */
   public static List getTypeDescList(){
   	List ret	=new ArrayList();
   	ret.add(PROPERTYTYPE_DESC_STRING);
   	ret.add(PROPERTYTYPE_DESC_NUMERIC);
   	ret.add(PROPERTYTYPE_DESC_BOOLEAN);
   	ret.add(PROPERTYTYPE_DESC_CURRENCY);
   	ret.add(PROPERTYTYPE_DESC_DATETIME);
   	
   	return ret;
   }	


   /** get type desc by a type id*/
   public static String getDescByType(int id){
   	switch (id){
   		case  PROPERTYTYPE_STRING:
   			return PROPERTYTYPE_DESC_STRING;

   		case  PROPERTYTYPE_NUMERIC:
   			return PROPERTYTYPE_DESC_NUMERIC;
   			
   		case  PROPERTYTYPE_BOOLEAN:
   			return PROPERTYTYPE_DESC_BOOLEAN;

   		case  PROPERTYTYPE_CURRENCY:
   			return PROPERTYTYPE_DESC_CURRENCY;

   		case  PROPERTYTYPE_DATETIME:
   			return PROPERTYTYPE_DESC_DATETIME; 
   		
   		default:
   			return PROPERTYTYPE_DESC_STRING;
   	}
   	
   }


   /** get type id by a type description*/
   public static int getTypeByDesc(String desc){
   	if (PROPERTYTYPE_DESC_STRING.equals(desc))
   		return PROPERTYTYPE_STRING;
   	
   	else if (PROPERTYTYPE_DESC_NUMERIC.equals(desc))
   		return PROPERTYTYPE_NUMERIC;

   	else if (PROPERTYTYPE_DESC_BOOLEAN.equals(desc))
   		return PROPERTYTYPE_BOOLEAN;

   	else if (PROPERTYTYPE_DESC_CURRENCY.equals(desc))
   		return PROPERTYTYPE_CURRENCY;

   	else if (PROPERTYTYPE_DESC_DATETIME.equals(desc))
   		return PROPERTYTYPE_DATETIME;
   	else
   		return PROPERTYTYPE_STRING;
   	
   }

	
   /**
    *   Get the type of property
    * 
    *   @return  The type of this property
    *
    */ 	
   public int getType(){
   	return m_type;
   }

   /**
    *   Set the type of current property.
    * 
    * 	@param  type The type of this property
    *
    */ 	
   public void setType(int type){
   	m_type	=type;
   }

   /**
    *   Get the display format of property
    * 
    *   @return  The display format of this property
    *
    */ 	
   public String getFormat(){
   	return m_format;
   }
   
   /**
    *   Set the display format of current property.
    * 
    * 	@param  displayFormat The display format of this property
    *
    */ 	
   public void setFormat(String displayFormat){
   	if (displayFormat==null) displayFormat ="";
   	m_format	=displayFormat;
   }


   /**
    *   Get the value of property
    * 
    *   @return  The value of this property, always be a string
    *
    */ 	
   public String getValue(){
   	return m_value;
   }
   
   /**
    *   Set the value of current property.
    * 
    * 	@param  value The value of this property
    *
    */ 	
   public void setValue(String value){
   	if (value==null) value ="";
   	m_value	=value;
   }

   /**
    *   Get the comment of property
    * 
    *   @return  The comment of this property, always be a string
    *
    */ 	
   public String getComment(){
   	return m_comment;
   }
   
   /**
    *   Set the comment of current property.
    * 
    * 	@param  comment The comment of this property
    *
    */ 	
   public void setComment(String comment){
   	if (comment==null) comment ="";
   	m_comment	=comment;
   }


   /**
    *   Convert this property to String <br>
    * 
    *   @return  An string represents the content of the property
    *
    */ 	
   public String toString(){
   	StringBuffer	buf	=new StringBuffer();
   	buf.append(super.toString());
   	buf.append(";name=");		buf.append(m_name);
   	buf.append(";type=");		buf.append(m_type);
   	buf.append(";format=");		buf.append(m_format);
   	buf.append(";value=");		buf.append(m_value);
   	buf.append(";comment=");	buf.append(m_comment);
   	
   	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 Property();
  }

   /**
    *   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{
  		Property	property =(Property)super.clone();
  		
  		property.m_name			=this.m_name;
  		property.m_type			=this.m_type;
  		property.m_format		=this.m_format;
  		property.m_value		=this.m_value;
  		property.m_comment		=this.m_comment;
  		
  		return property;
  		
	}catch(Exception e){
		throw new CloneNotSupportedException(e.getMessage());
	}
  }

   /**
    *   Returns the hashcode for this Object.
    * 
    *   @return hash code for this Property.
    *
    */ 	
  public int hashCode(){
  	
  	return 	super.hashCode() ^
  		m_name.hashCode()	^
  		m_type	^
  		m_format.hashCode()	^
  		m_value.hashCode()	^
  		m_comment.hashCode();
  }


   /**
    *   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 Property 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 Property))
            	return false;
            	
      Property  property= (Property)obj;
      return  	(m_name.equals(property.m_name))&&
      		(m_type==property.m_type)&&
      		(m_format.equals(m_format))&&
      		(m_value.equals(m_value))&&
		(m_comment.equals(m_comment))      		
                ;
  }
   
   /**
    *   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_NAME, m_name));
    	element.addChild(new Element(XML_TYPE, m_type));
    	element.addChild(new Element(XML_FORMAT, m_format));
    	element.addChild(new Element(XML_VALUE, m_value));
    	element.addChild(new Element(XML_COMMENT, m_comment));
  }


   /**
    *   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_name		=Element.getStringValue(element.getChild(XML_NAME));
      	m_type		=Element.getIntValue(element.getChild(XML_TYPE));
      	m_format	=Element.getStringValue(element.getChild(XML_FORMAT));
      	m_value		=Element.getStringValue(element.getChild(XML_VALUE));
      	m_comment	=Element.getStringValue(element.getChild(XML_COMMENT));
  }

   /**
    *   Save this property 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.writeUTF(m_name);
	stream.writeInt(m_type);
	stream.writeUTF(m_format);
	stream.writeUTF(m_value);
	stream.writeUTF(m_comment);
  }


   /**
    *   Load property 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_name		=stream.readUTF();
	m_type		=stream.readInt();
	m_format	=stream.readUTF();
	m_value		=stream.readUTF();
	m_comment	=stream.readUTF();
  }




 	
 }
 

⌨️ 快捷键说明

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