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

📄 fillformat.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 *    $Id:FillFormat.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.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.TexturePaint;
import java.awt.GradientPaint;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.awt.geom.GeneralPath;
import java.awt.Stroke;
import java.awt.BasicStroke;


import com.jfimagine.jfdom.Document;
import com.jfimagine.jfdom.Element;

import com.jfimagine.jfgraph.geom.Rect;
import com.jfimagine.jfgraph.geom.JFPoint;

import com.jfimagine.jfgraph.shape.base.AbstractObject;
import com.jfimagine.jfgraph.shape.base.ShapeConst;
import com.jfimagine.jfgraph.shape.base.JFVersion;
 
 /**
 * Fill format class. All shapes should use this class for their fill format.
 *
 * @author     CookieMaker    
 *
 * @version $Revision: 1.00 $
 */  
 public class FillFormat extends AbstractObject{
  
   //*****************************************************************
   //         XML Tags
   //*****************************************************************

   /**
    *   A XML string tag represents a fill format.
    */
   public  static final String	 XML_FILLFORMAT		="FillFormat";

   /**
    *   A XML string tag represents the fill style
    */
   public  static final String   XML_FILLSTYLE		="fillStyle";

   /**
    *   A XML string tag represents a fill's color
    */
   public  static final String   XML_FILLCOLOR		="fillColor";

   /**
    *   A XML string tag represents a fill's color2
    */
   public  static final String   XML_FILLCOLOR2		="fillColor2";

   /**
    *   A XML string tag represents the fill line style
    */
   public  static final String   XML_FILLLINESTYLE		="fillLineStyle";

   /**
    *   A XML string tag represents a fill line's color
    */
   public  static final String   XML_FILLLINECOLOR		="fillLineColor";


   //*****************************************************************
   //         Const definitions
   //*****************************************************************

   /**
    *   A const value represent EMPTY fill style.
    */
   public  static final int   FILLSTYLE_EMPTY		=0;

   /**
    *   A const value represent SOLID fill style.
    */
   public  static final int   FILLSTYLE_SOLID		=1;

   /**
    *   A const value represent SLASH fill style, sometimes for some section/cutaway views.
    */
   public  static final int   FILLSTYLE_SLASH		=2;

   /**
    *   A const value represent REVERSE SLASH fill style, sometimes for some section/cutaway views.
    */
   public  static final int   FILLSTYLE_REVERSESLASH	=3;

   /**
    *   A const value represent VERTICAL LINE fill style
    */
   public  static final int   FILLSTYLE_VERTICALLINE		=4;

   /**
    *   A const value represent HORIZONTAL LINE fill style
    */
   public  static final int   FILLSTYLE_HORIZONTALLINE		=5;


   /**
    *   A const value represent GRID fill style
    */
   public  static final int   FILLSTYLE_GRID			=6;

   /**
    *   A const value represent INCLINED GRID fill style
    */
   public  static final int   FILLSTYLE_INCLINEDGRID		=7;


   /**
    *   A const value represent left to right gradient fill style.
    */
   public  static final int   FILLSTYLE_GRADIENT_LEFTRIGHT	=8;

   /**
    *   A const value represent right to left gradient fill style.
    */
   public  static final int   FILLSTYLE_GRADIENT_RIGHTLEFT	=9;


   /**
    *   A const value represent up to down gradient fill style.
    */
   public  static final int   FILLSTYLE_GRADIENT_UPDOWN	        =10;


   /**
    *   A const value represent down to up gradient fill style.
    */
   public  static final int   FILLSTYLE_GRADIENT_DOWNUP	        =11;


   /**
    *   A const value represent up-left to right-down gradient fill style.
    */
   public  static final int   FILLSTYLE_GRADIENT_UPLEFT_RIGHTDOWN   =12;


   /**
    *   A const value represent up-right to left-down gradient fill style.
    */
   public  static final int   FILLSTYLE_GRADIENT_UPRIGHT_LEFTDOWN   =13;

   /**
    *   A const value represent down-left to right-up gradient fill style.
    */
   public  static final int   FILLSTYLE_GRADIENT_DOWNLEFT_RIGHTUP   =14;


   /**
    *   A const value represent down-right to left-up gradient fill style.
    */
   public  static final int   FILLSTYLE_GRADIENT_DOWNRIGHT_LEFTUP   =15;


   private static FillFormat m_defaultFillFormat	=new FillFormat();
   /**
    *   set global default fill format
    *   @param fillFormat A new fill format
    */
   public static void setDefaultFillFormat(FillFormat fillFormat){
   	m_defaultFillFormat.setValue(fillFormat);
   }
   /**
    *   get global default fill format
    *   @return The global default fill format
    */
   public static FillFormat getDefaultFillFormat(){
   	return m_defaultFillFormat;
   }
   

   /**
    *   Fill style variable.
    */
   private	int	m_fillStyle=FILLSTYLE_EMPTY;

   /**
    *   Fill color variable,default to white.
    */
   private	Color	m_fillColor=new Color(Color.white.getRGB());

   /**
    *   Fill color2 variable for gradient only,default to gray.
    */
   private	Color	m_fillColor2=new Color(Color.gray.getRGB());

   /**
    *   Fill line color variable,default to black.
    */
   private	Color	m_fillLineColor=new Color(Color.black.getRGB());

   /**
    *   Fill line style.default to solid.
    */
   private	int	m_fillLineStyle=LineFormat.LINESTYLE_SOLID;

	
   /**
    *   Constructor for FillFormat
    */
   public FillFormat(){
   	setObjectType(ShapeConst.DECORATETYPE_FILLFORMAT);
   	setXMLTag(XML_FILLFORMAT);

   	if (m_defaultFillFormat!=null){ 
   		setValue(m_defaultFillFormat);
   	}
   	   	
   }	

   /**
    *  clear format, then set to default values
    */
   public void clearFormat(){
   	m_fillStyle	=FILLSTYLE_EMPTY;
   	m_fillColor	=new Color(Color.white.getRGB());
   	m_fillColor2	=new Color(Color.gray.getRGB());
   	m_fillLineColor	=new Color(Color.black.getRGB());
   	m_fillLineStyle	=LineFormat.LINESTYLE_SOLID;
   }


   /**
    *   Get current fill style.
    *
    *   @return  The fill style.
    *
    */ 	
   public int getFillStyle(){
   	return m_fillStyle;
   }

   /**
    *   Set current fill style.
    *
    *   @param fillStyle  A new fill style.
    *
    */ 	
   public void setFillStyle(int fillStyle){
   	m_fillStyle	=fillStyle;
   }

   /**
    *   Get current fill color.
    *
    *   @return  The fill color.
    *
    */ 	
   public Color getFillColor(){
   	return m_fillColor;
   }

   /**
    *   Set current fill color.
    *
    *   @param fillColor  A new fill color.
    *
    */ 	
   public void setFillColor(Color fillColor){
   	if (fillColor==null)
   		m_fillColor 	=new Color(Color.white.getRGB());
   	else
   		m_fillColor	=new Color(fillColor.getRGB());
   }

   /**
    *   Get current fill color2.
    *
    *   @return  The fill color2.
    *
    */ 	
   public Color getFillColor2(){
   	return m_fillColor2;
   }

   /**
    *   Set current fill color2.
    *
    *   @param fillColor2  A new fill color2.
    *
    */ 	
   public void setFillColor2(Color fillColor2){
   	if (fillColor2==null)
   		m_fillColor2 	=new Color(Color.gray.getRGB());
   	else
   		m_fillColor2	=new Color(fillColor2.getRGB());
   }


   /**
    *   Get current fill line style.
    *
    *   @return  The fill line style.
    *
    */ 	
   public int getFillLineStyle(){
   	return m_fillLineStyle;
   }

   /**
    *   Set current fill line style.
    *
    *   @param fillLineStyle  A new fill line style.
    *
    */ 	
   public void setFillLineStyle(int fillLineStyle){
   	m_fillLineStyle	=fillLineStyle;
   }


   /**
    *   Get current fill line color.
    *
    *   @return  The fill line color.
    *
    */ 	
   public Color getFillLineColor(){
   	return m_fillLineColor;
   }

   /**
    *   Set new value for this fillFormat.
    *
    *   @param fillFormat A new fill format.
    *
    */ 	
   public void setValue(FillFormat fillFormat){
   	if (fillFormat!=null){
   		setFillStyle(fillFormat.getFillStyle());
   		setFillColor(fillFormat.getFillColor());
   		setFillColor2(fillFormat.getFillColor2());
   		setFillLineStyle(fillFormat.getFillLineStyle());
   		setFillLineColor(fillFormat.getFillLineColor());
   	}
   }



   /**
    *   Set current fill line color.
    *
    *   @param fillLineColor  A new fill line color.
    *
    */ 	
  public void setFillLineColor(Color fillLineColor){
   	if (fillLineColor==null)
   		m_fillLineColor 	=new Color(Color.black.getRGB());
   	else
   		m_fillLineColor	=new Color(fillLineColor.getRGB());
   }


   /**
    *   Draw a path on specified graphics context.
    *  @param g A specified graphics
    *  @param path A general path.
    *  @param rect A drawing rectangle of the objects' bounds.
    *
    */ 	
   public void draw(Graphics g, GeneralPath path,Rect rect){
   	if (g==null)
   		return;

	if (m_fillStyle==FILLSTYLE_EMPTY)
		return;
		   	
   	Graphics2D g2=(Graphics2D)g;
   	setGraphics(g2,rect);
   	g2.fill(path);
   	initGraphics(g);
   }

   /**
    *   Set graphics to a default configuration.
    *
    */ 	

⌨️ 快捷键说明

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