jfrectangle.java
来自「用Java开发的、实现类似Visio功能的应用程序源码」· Java 代码 · 共 129 行
JAVA
129 行
/**
* $Id:JFRectangle.java $
*
* Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All rights reserved. *
*/
package com.jfimagine.jfgraph.shape.rectangle;
import java.awt.Graphics;
import com.jfimagine.jfgraph.shape.rectangle.AbstractRectangle;
import com.jfimagine.jfgraph.shape.base.Node;
import com.jfimagine.jfgraph.shape.base.AbstractObject;
import com.jfimagine.jfgraph.shape.base.ShapeConst;
import com.jfimagine.jfgraph.geom.JFPoint;
import com.jfimagine.jfgraph.geom.Rect;
/**
* JFRectangle class.
* A rectangle class used to represents regular rectangle, parallelogram, trapezoid and isoceles trapezoid.
*
* @author CookieMaker
*
* @version $Revision: 1.00 $
*/
public class JFRectangle extends AbstractRectangle{
/**
* A XML string tag represents a rectangle.
*/
public static final String XML_RECTANGLE ="JFRectangle";
/**
* Constructor for rectangle
*/
public JFRectangle(){
setObjectType(ShapeConst.SHAPETYPE_RECT);
setXMLTag(XML_RECTANGLE);
}
/**
* Constructor for rectangle.
*
* @param x X coordiate.
*
* @param y Y coordiate.
*
* @param w Width of this rectangle.
*
* @param h Height of this rectangle.
*
*/
public JFRectangle(double x, double y, double w, double h){
setObjectType(ShapeConst.SHAPETYPE_RECT);
setXMLTag(XML_RECTANGLE);
addNode(x,y);
addNode(x+w,y+h);
finishDrawing();
}
/**
* 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 JFRectangle();
}
/**
* 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){
super.addNode(x,y);
if (m_nodeAdded>1){
//left-top point and right-bottom point:
JFPoint pnt1 =m_firstNode;
JFPoint pnt2 =new JFPoint(x,y);
m_rect.setVertex(Rect.VERTEXTYPE_LEFTTOP,pnt1.getX(),pnt1.getY());
m_rect.setVertex(Rect.VERTEXTYPE_RIGHTTOP,x,pnt1.getY());
m_rect.setVertex(Rect.VERTEXTYPE_LEFTBOTTOM,pnt1.getX(),y);
m_rect.setVertex(Rect.VERTEXTYPE_RIGHTBOTTOM,x,y);
initNodes();
}
}
/**
* Move/adjust a node of current object.
*
* @param node Currently moving node.
*
* @param x, y Moving offsets.
*
* @param g current drawing canvas.
*
*/
public void moveNode(Node node, double x, double y,Graphics g){
super.moveNode(node,x,y,g);
if (node!=null){
if (node.getXOffset()!=x || node.getYOffset()!=y){
//move node and draw a new dragging shape.
int vertexType =getVertexTypeByNode(node);
m_rect.moveVertex(vertexType,x,y,Rect.VERTEXMOVETYPE_RECTANGLE);
//init shape nodes.
initNodes();
//draw current moving node and its relational lines
draw(g,true);
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?