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

📄 jfpie.java

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

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.GeneralPath;


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

import com.jfimagine.jfgraph.shape.base.Port;
import com.jfimagine.jfgraph.shape.base.Node;
import com.jfimagine.jfgraph.shape.base.ShapeConst;
import com.jfimagine.jfgraph.shape.base.AbstractObject;
import com.jfimagine.jfgraph.shape.arc.AbstractArc;
import com.jfimagine.jfgraph.shape.decorate.Arrow;
 
 
 /**
 * JFPie class.  
 * A pie is part or whole of the curve of a circle, but with the two line segment, line from center to start point and line from center to end point,
 * constructed into a pie shape.
 *
 * @author     CookieMaker    
 *
 * @version $Revision: 1.00 $
 */  
 public class JFPie extends AbstractArc{

   /**
    *   A XML string tag represents an Pie
    */
   public  static final String	 XML_PIE		="Pie";

   
   /**
    *   initialization for JFPie
    */
   private void initPie(){
   	setObjectType(ShapeConst.SHAPETYPE_PIE);
   	setXMLTag(XML_PIE);
   	m_arc.setArcType(Arc.PIE);
   }	

   /**
    *   Constructor for JFPie
    */
   public JFPie(){
   	initPie();
   }	

   /**
    *   Constructor for JFPie
    */
   public JFPie(AbstractArc arc){
   	setArc(arc);
   	initPie();
   }	

   /**
    *   Constructor for JFPie
    *   @param x1,y1 start point of this pie
    *   @param x2,y2 end point of this pie
    */
   public JFPie(double x1,double y1, double x2, double y2){
   	initPie();
   	addNode(x1,y1);
   	addNode(x2,y2);
   	finishDrawing();
   }	


   /**
    *   Constructor for JFPie
    *   @param centerx,centery center point of this pie
    *   @param x1,y1 start point of this pie
    *   @param angle Angle of this pie.
    */
   public JFPie(double centerx, double centery,double x1,double y1, double angle){
   	initPie();
   	m_arc.setValue(new JFPoint(centerx,centery),new JFPoint(x1,y1),angle);
   	finishDrawing();
   }	

   /**
    *   Init all nodes of this pie. 
    *   We will always consider that an pie object has four nodes: startpoint,endpoint ,controlpoint and centerPoint
    *   node1 as start point,
    *   node2 as end point,
    *   node3 as control point,
    *   node4 as center point
    */ 	
   protected void initNodes(){

   	super.initNodes();
   	
   	//add four nodes if not assigned yet.
   	while (m_nodeList.size()<4){
   		try{ m_nodeList.add(new Node()); 	}catch(Exception e){ break;}
   	}
   	
       //set fourth node as center point.
       Node node;

       	try{
       		node	=(Node)m_nodeList.getByIndex(3);
       		node.setNodePoint(m_arc.getCenter());
       		node.setParent(this);
       	}catch(Exception e){
       	}

	m_nodeList.setZoomScale(getZoomScale());
      	
   }

   /**
    *   Draw an arc on canvas, by specified line format.
    * 
    *   @param  g  A graphic canvas.	
    *   @param  isXorMode If is in xor mode now.
    *
    */ 	
   public void  drawArc(Graphics g, boolean isXorMode){

  	double zoom		=getZoomScale();
	JFPoint startPoint	=m_arc.getStartPoint();
	JFPoint center		=m_arc.getCenter();
	
	startPoint	=new JFPoint(startPoint.getX() * zoom, startPoint.getY() * zoom);
	center		=new JFPoint(center.getX() * zoom, center.getY() * zoom);
	
	
	GeneralPath	path	=getArcPath();
	path.lineTo((float)center.getX(),(float)center.getY());
	path.lineTo((float)startPoint.getX(),(float)startPoint.getY());
	path.closePath();
		
   	if (!isXorMode){
   		Rect rect	=getBounds();
   		rect.setValue(rect.getX() * zoom, rect.getY() * zoom, rect.getWidth() * zoom, rect.getHeight() * zoom);
   		m_fillFormat.draw(g,path,rect);
   		m_lineFormat.draw(g,path);
   	}else
   		((Graphics2D)g).draw(path);
   }



   /**
    *   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 JFPie();
  }

   /**
    *   Init all ports of this shape.
    *   An object will always has its one or more stable ports and some customized ports,
    */ 	
   protected void initPorts(){

   	if (m_portList.size()==0){
   		try{
			JFPoint  startPoint   	=m_arc.getStartPoint();
			JFPoint  endPoint   	=m_arc.getEndPoint();
			JFPoint  controlPoint  	=m_arc.getControlPoint();
			JFPoint  center  	=m_arc.getCenter();
			
			m_portList.addPort(new ArcPort(this,Port.PORTTYPE_DEFAULT,controlPoint,0.5,JFArcPoint.POINTTYPE_CURVE));
			m_portList.addPort(new ArcPort(this,Port.PORTTYPE_DEFAULT,center.midPoint(startPoint),0.5,JFArcPoint.POINTTYPE_PIE_START));
			m_portList.addPort(new ArcPort(this,Port.PORTTYPE_DEFAULT,center.midPoint(endPoint),0.5,JFArcPoint.POINTTYPE_PIE_END));

   		}catch(Exception e){
   		}
   	}     
        
        m_portList.setZoomScale(getZoomScale());
	
   	
   }


   /**
    *   Get the arrow format of current object.
    * 
    *   @return  The arrow format.
    *
    */ 	
   public Arrow getArrow(){
   	return null;
   }

   /**
    *   Set the arrow format of current object.
    *
    *   @param arrow  A new arrow format object.
    *
    */ 	
   public void setArrow(Arrow arrow){
   }


}

⌨️ 快捷键说明

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