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

📄 fontformat.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   /**
    *   Get a zoomed font of current font. <br>
    *
    *   @return  A new zoomed font of current font.
    *
    */ 	
   public Font getZoomedFont(){
   	double zoom	=getZoomScale();
   	
   	if (zoom==1.0)
   		return getFont();
   	else
   		return new Font(m_fontName, m_fontStyle, (int)(m_fontSize * zoom));
   }


   /**
    *   Indicates whether or not this Font object's style is PLAIN.
    *
    *   @return  true if this Font object's style is PLAIN; false otherwise.
    *
    */ 	
   public boolean isPlain(){
   	return (m_fontStyle & Font.PLAIN) ==Font.PLAIN;
   }

   /**
    *   Indicates whether or not this Font object's style is BOLD.
    *
    *   @return  true if this Font object's style is BOLD; false otherwise.
    *
    */ 	
   public boolean isBold(){
   	return (m_fontStyle & Font.BOLD) ==Font.BOLD;
   }

   /**
    *   Indicates whether or not this Font object's style is ITALIC.
    *
    *   @return  true if this Font object's style is ITALIC; false otherwise.
    *
    */ 	
   public boolean isItalic(){
   	return (m_fontStyle & Font.ITALIC) ==Font.ITALIC;
   }

   /**
    *   Indicates whether or not this Font object's style is both BOLD and ITALIC.
    *
    *   @return  true if this Font object's style is both BOLD and ITALIC; false otherwise.
    *
    */ 	
   public boolean isBoldItalic(){
   	return isBold() && isItalic();
   }


   /**
    *   Set current font object.
    *
    *   @param fontObj  A new font object.
    *
    */ 	
   public void setFont(Font fontObj){
   	if (fontObj!=null){
   		m_fontName	=fontObj.getFontName();
   		m_fontSize	=fontObj.getSize();
   		m_fontStyle	=fontObj.getStyle();
   		initFont();
   	}
   }

   /**
    *   Set current font object.
    *
    *   @param fontFormat a new font format object.
    *
    */ 	
   public void setValue(FontFormat fontFormat){
   	if (fontFormat!=null){
   		m_fontName	=fontFormat.getFontName();
   		m_fontSize	=fontFormat.getFont().getSize();
   		m_fontStyle	=fontFormat.getFontStyle();
   		m_fontColor	=new Color(fontFormat.getFontColor().getRGB());
   		m_transparency	=fontFormat.getTransparency();
   		m_useStrokeAndFill	=fontFormat.isUseStrokeAndFill();
   		m_lineFormat.setValue(fontFormat.getLineFormat());
   		m_fillFormat.setValue(fontFormat.getFillFormat());
   		initFont();
   	}
   }
   
   /**
    *   Initialize the font object.
    *
    */ 	
   public void initFont(){ 
   	m_font	=new Font(m_fontName,m_fontStyle,m_fontSize);
   }

   /**
    *   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(";fontStyle=");  	buf.append(m_fontStyle);
  	buf.append(";fontSize=");  	buf.append(m_fontSize);
  	buf.append(";fontName=");  	buf.append(m_fontName);
  	buf.append(";fontColor=");  	buf.append(m_fontColor.getRGB());
  	buf.append(";fontTransparency=");  	buf.append(m_transparency);
  	buf.append(";useStrokeAndFill=");  	buf.append(m_useStrokeAndFill);
  	buf.append("<lineFormat>\n"); 
  	buf.append(m_lineFormat.toString());
  	buf.append("\n<fillFormat>\n"); 
  	buf.append(m_fillFormat.toString());
  	
  	
  	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 FontFormat();
  }
  
     /**
    *   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{
  		FontFormat	fontFormat =(FontFormat) super.clone();
  		
  		fontFormat.m_fontStyle	=this.m_fontStyle;
  		fontFormat.m_fontSize	=this.m_fontSize;
  		fontFormat.m_fontName	=this.m_fontName;
  		fontFormat.m_fontColor	=new Color(this.m_fontColor.getRGB());
  		fontFormat.m_transparency =this.m_transparency;
  		fontFormat.m_useStrokeAndFill	=this.m_useStrokeAndFill;
  		fontFormat.m_lineFormat.setValue(this.m_lineFormat);
  		fontFormat.m_fillFormat.setValue(this.m_fillFormat);
		fontFormat.initFont();
		 		
  		return fontFormat;
  		
	}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_fontStyle ^
  		m_fontSize ^
  		m_fontName.hashCode() ^
  		m_fontColor.hashCode() ^
  		m_transparency ^
  		(m_useStrokeAndFill?1:0) ^
  		m_lineFormat.hashCode() ^
  		m_fillFormat.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 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 FontFormat))
            	return false;

      FontFormat fontFormat= (FontFormat)obj;
      
      return	(m_fontStyle==fontFormat.m_fontStyle) &&
      		(m_fontSize==fontFormat.m_fontSize) &&
      		(m_fontName.equals(fontFormat.m_fontName)) &&
      		(m_fontColor.equals(fontFormat.m_fontColor)) &&
      		m_transparency==fontFormat.m_transparency &&
      		m_useStrokeAndFill==fontFormat.m_useStrokeAndFill &&
      		m_lineFormat.equals(fontFormat.m_lineFormat) &&
      		m_fillFormat.equals(fontFormat.m_fillFormat)
              	;
  }


   /**
    *   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_FONTSTYLE, m_fontStyle));
    	element.addChild(new Element(XML_FONTSIZE, m_fontSize));
    	element.addChild(new Element(XML_FONTNAME, CommonUtil.strToHex(m_fontName)));
    	element.addChild(new Element(XML_FONTCOLOR, m_fontColor.getRGB()));

    	element.addChild(new Element(XML_FONTTRANSPARENCY, m_transparency));
	element.addChild(new Element(XML_USESTROKEANDFILL,m_useStrokeAndFill));
	m_lineFormat.toDOM(element,version);
	m_fillFormat.toDOM(element,version);


  }

   /**
    *   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_fontStyle	=Element.getIntValue(element.getChild(XML_FONTSTYLE));
      m_fontSize	=Element.getIntValue(element.getChild(XML_FONTSIZE));
      m_fontName	=CommonUtil.hexToStr(Element.getStringValue(element.getChild(XML_FONTNAME)));
      m_fontColor	=new Color(Element.getIntValue(element.getChild(XML_FONTCOLOR)));

      if (!version.lowerVersionOf(JFVersion.VERSIONID_1701)){
      		m_transparency	=Element.getIntValue(element.getChild(XML_FONTTRANSPARENCY));
      }

      if (!version.lowerVersionOf(JFVersion.VERSIONID_170)){
      		m_useStrokeAndFill=Element.getBooleanValue(element.getChild(XML_USESTROKEANDFILL));
      		m_lineFormat.fromDOM(element.getChild(m_lineFormat.getXMLTag()),version);
      		m_fillFormat.fromDOM(element.getChild(m_fillFormat.getXMLTag()),version);
      }

      	     
      initFont();
  }

 
   /**
    *   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_fontStyle);
	stream.writeInt(m_fontSize);
	stream.writeUTF(m_fontName);
	stream.writeInt(m_fontColor.getRGB());
	
	stream.writeInt(m_transparency);
	stream.writeBoolean(m_useStrokeAndFill);
	m_lineFormat.saveToStream(stream,version);
	m_fillFormat.saveToStream(stream,version);
  }

   /**
    *   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_fontStyle		=stream.readInt();
	m_fontSize		=stream.readInt();
	m_fontName		=stream.readUTF();
	m_fontColor		=new Color(stream.readInt());

      	if (!version.lowerVersionOf(JFVersion.VERSIONID_1701)){
      		m_transparency	=stream.readInt();
	}

      	if (!version.lowerVersionOf(JFVersion.VERSIONID_170)){
      		m_useStrokeAndFill	=stream.readBoolean();
      		m_lineFormat.loadFromStream(stream,false,version);
      		m_fillFormat.loadFromStream(stream,false,version);
	}
	initFont();
  }




}

⌨️ 快捷键说明

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