jfquadrant.java
来自「用Java开发的、实现类似Visio功能的应用程序源码」· Java 代码 · 共 855 行 · 第 1/2 页
JAVA
855 行
/**
* $Id:JFQuadrant.java $
*
* Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All rights reserved. *
*/
package com.jfimagine.jfgraph.shape.line;
import java.util.List;
import java.util.Iterator;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.GeneralPath;
import java.awt.Color;
import java.awt.BasicStroke;
import com.jfimagine.jfdom.Document;
import com.jfimagine.jfdom.Element;
import com.jfimagine.jfgraph.shape.base.AbstractObject;
import com.jfimagine.jfgraph.shape.base.AbstractShape;
import com.jfimagine.jfgraph.shape.base.ShapeConst;
import com.jfimagine.jfgraph.shape.base.ObjectList;
import com.jfimagine.jfgraph.shape.base.JFVersion;
import com.jfimagine.jfgraph.shape.base.Node;
import com.jfimagine.jfgraph.shape.base.NodeList;
import com.jfimagine.jfgraph.shape.base.Port;
import com.jfimagine.jfgraph.shape.base.PortList;
import com.jfimagine.jfgraph.shape.decorate.LineFormat;
import com.jfimagine.jfgraph.shape.decorate.Arrow;
import com.jfimagine.jfgraph.geom.JFPoint;
import com.jfimagine.jfgraph.geom.JFPointNode;
import com.jfimagine.jfgraph.geom.LineSeg;
import com.jfimagine.jfgraph.geom.PolyLine;
import com.jfimagine.jfgraph.geom.Rect;
import com.jfimagine.jfgraph.geom.GeomConst;
/**
* A JFQuadrant class is used to draw two perpendicular lines which divide a drawing canvas into four sections.
*
* @author CookieMaker
*
* @version $Revision: 1.3.3 $
*/
public class JFQuadrant extends AbstractShape{
/**
* A XML string tag represents a Quadrant
*/
public static final String XML_QUADRANT ="Quadrant";
/** A XML string tag represents the center x coordinate */
public static final String XML_CENTERX ="centerX";
/** A XML string tag represents the center y coordinate */
public static final String XML_CENTERY ="centerY";
/** A XML string tag represents the quadrant width */
public static final String XML_WIDTH ="width";
/** A XML string tag represents the quadrant height */
public static final String XML_HEIGHT ="height";
/**move method: none*/
public static final int MOVEMETHOD_NONE =0;
/**move method: move horizontal line*/
public static final int MOVEMETHOD_HORIZONTALLINE =1;
/**move method: move vertical line*/
public static final int MOVEMETHOD_VERTICALLINE =2;
/**move method: move center(both lines)*/
public static final int MOVEMETHOD_CENTER =3;
/**
* quadrant format of current quadrant.
*/
protected LineFormat m_lineFormat = new LineFormat();
/**
* Quadrant center
*/
protected JFPoint m_center =new JFPoint();
/**
* Default size(pixels) for perpendicular lines
*/
public static final int DEFAULT_SIZE =1000;
/**
* Width for the horizontal line
*/
protected double m_width =DEFAULT_SIZE;
/**
* Height for the vertical line
*/
protected double m_height =DEFAULT_SIZE;
/**
* move method: move horizontal line, vertical line, or the center?
*/
private int m_moveMethod =MOVEMETHOD_NONE;
/**
* Constructor for Line
*/
public JFQuadrant(){
setObjectType(ShapeConst.SHAPETYPE_QUADRANT);
setXMLTag(XML_QUADRANT);
initNodes();
initLabel();
}
/**
* Constructor for Line
*
* @param x,y The center of this quadrant.
*
*/
public JFQuadrant(double x, double y){
setObjectType(ShapeConst.SHAPETYPE_QUADRANT);
setXMLTag(XML_QUADRANT);
m_center.setValue(x,y);
initNodes();
initLabel();
}
/**
* Constructor for Line
*
* @param x,y The center of this quadrant.
* @param width,height The width of the horizontal line and the height of the vertical line.
*
*/
public JFQuadrant(double x, double y,double width, double height){
setObjectType(ShapeConst.SHAPETYPE_QUADRANT);
setXMLTag(XML_QUADRANT);
m_center.setValue(x,y);
m_width =width;
m_height =height;
initNodes();
initLabel();
}
/**
* Get the center of this quadrant.
*
* @return The center
*
*/
public JFPoint getCenter(){
return m_center;
}
/**
* Set the center of this quadrant.
*
* @param center A new center of this quadrant.
*
*/
public void setCenter(JFPoint center){
startMoveLabel();
m_center.setValue(center);
initNodes();
finishMoveLabel();
}
/**
* Set the center of this quadrant.
*
* @param x,y A new center of this quadrant.
*
*/
public void setCenter(double x, double y){
startMoveLabel();
m_center.setValue(x,y);
initNodes();
finishMoveLabel();
}
/**
* Set the width of this quadrant.
* A width is used to represent the length of horizontal line.
*
* @param width A new width.
*
*/
public void setWidth(double width){
m_width =width;
}
/**
* Get the width of this quadrant.
* A width is used to represent the length of horizontal line.
*
* @return the width of current quadrant.
*
*/
public double getWidth(){
return m_width;
}
/**
* Set the height of this quadrant.
* A height is used to represent the length of vertical line.
*
* @param height A new height.
*
*/
public void setHeight(double height){
m_height =height;
}
/**
* Get the height of this quadrant.
* A height is used to represent the length of vertical line.
*
* @return the height of current quadrant.
*
*/
public double getHeight(){
return m_height;
}
/**
* Set the Size of this quadrant.
*
* @param width A width is used to represent the length of horizontal line.
* @param height A height is used to represent the length of vertical line.
*
*/
public void setSize(double width ,double height){
m_width =width;
m_height =height;
}
/**
* Get the line format of current quadrant.
*
* @return The line format.
*
*/
public LineFormat getLineFormat(){
return m_lineFormat;
}
/**
* Set the line format of current quadrant.
*
* @param lineFormat A new line format.
*
*/
public void setLineFormat(LineFormat lineFormat){
m_lineFormat.setValue(lineFormat);
}
/**
* get move method. A move method indicates if one line(horizontal or line) or center has been picked.
* @return the move method
*/
public int getMoveMethod(){
return m_moveMethod;
}
/**
* set move method. A move method indicates if one line(horizontal or line) or center has been picked.
* @param moveMethod A new move method.
*/
public void setMoveMethod(int moveMethod){
m_moveMethod =moveMethod;
}
/**
* Get the bounds of this rectangle.
*
* @return The bounds rectangle of current rectangle.
*
*/
public Rect getBounds(){
return new Rect(m_center.getX(),m_center.getY(),0,0);
}
/**
* Ask if this object is an open shape,e.g. line,curve,arc,etc.
*
* @return true if open,false closed.
*
*/
public boolean isOpenShape(){
return true;
}
/**
* Set the intial position of this internal label.
*
*/
protected void initLabel(){
super.initLabel();
//move the label to the right-bottom corner according to the Quadrant center.
m_label.moveBy(20,20);
}
/**
* Init all nodes of this quadrant.
*/
private void initNodes(){
//only one node(the center) is available in this quadrant.
if (m_nodeList.size()==0){
try{ m_nodeList.add(new Node()); }catch(Exception e){}
}
try{
Node node =(Node)m_nodeList.getByIndex(0);
node.setXOffset(m_center.getX());
node.setYOffset(m_center.getY());
node.setParent(this);
}catch(Exception e){
}
m_nodeList.setZoomScale(getZoomScale());
}
/**
* Add a new node for current node list.
* here this method will always be called by DrawState class or any drawing class.
*
* @param x, y Coordinates of a new node.
*
*/
public void addNode(double x, double y){
//do nothing with this method
}
/**
* Draw current object on graphic canvas.
*
* @param g A graphic canvas.
* @param isXorMode If is in xor mode now.
*
*/
public void draw(Graphics g,boolean isXorMode){
if (g==null)
return;
if (!isXorMode)
setTransparencyComposite(g);
double zoom =getZoomScale();
//horizontal line
GeneralPath hLine= new GeneralPath(GeneralPath.WIND_EVEN_ODD);
float x=0;
float y=0;
//horizontal line
x =0;
y =(float)(m_center.getY() * zoom);
hLine.moveTo(x,y);
x =(float)(m_width * zoom);
hLine.lineTo(x,y);
//vertical line
GeneralPath vLine= new GeneralPath(GeneralPath.WIND_EVEN_ODD);
//vertical line
x =(float)(m_center.getX() * zoom);
y =0;
vLine.moveTo(x,y);
y =(float)(m_height * zoom);
vLine.lineTo(x,y);
//draw quadrant
Graphics2D g2=(Graphics2D)g;
if (!isXorMode){
if (isInvisible()){
LineFormat lineFormat =LineFormat.getInvisibleLineFormat();
lineFormat.draw(g,hLine);
lineFormat.draw(g,vLine);
}else{
m_lineFormat.draw(g,hLine);
m_lineFormat.draw(g,vLine);
}
}else{
g2.setStroke(new BasicStroke(1));
g2.setColor(Color.black);
switch (m_moveMethod){
case MOVEMETHOD_CENTER:
g2.draw(hLine);
g2.draw(vLine);
break;
case MOVEMETHOD_HORIZONTALLINE:
g2.draw(hLine);
break;
case MOVEMETHOD_VERTICALLINE:
g2.draw(vLine);
break;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?