jfisoscelestrapezoid.java
来自「用Java开发的、实现类似Visio功能的应用程序源码」· Java 代码 · 共 149 行
JAVA
149 行
/**
* $Id:JFIsoscelesTrapezoid.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;
/**
* JFIsoscelesTrapezoid class.
* A rectangle class used to represents isosceles trapezoid shape.
*
* @author CookieMaker
*
* @version $Revision: 1.00 $
*/
public class JFIsoscelesTrapezoid extends AbstractRectangle{
/**
* A XML string tag represents a isosceles trapezoid.
*/
public static final String XML_ISOSCELESTRAPEZOID ="IsoscelesRectangle";
/**
* Constructor for isosceles trapezoid.
*/
public JFIsoscelesTrapezoid(){
setObjectType(ShapeConst.SHAPETYPE_RECT_ISOSCELESTRAPEZOID);
setXMLTag(XML_ISOSCELESTRAPEZOID);
}
/**
* Constructor for isosceles trapezoid.
*
* @param x X coordiate.
*
* @param y Y coordiate.
*
* @param w Width of this rectangle.
*
* @param h Height of this rectangle.
*
*/
public JFIsoscelesTrapezoid(double x, double y, double w, double h){
setObjectType(ShapeConst.SHAPETYPE_RECT_ISOSCELESTRAPEZOID);
setXMLTag(XML_ISOSCELESTRAPEZOID);
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 JFIsoscelesTrapezoid();
}
/**
* 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);
//an offset for parallelogram,trapezoid and isosceles trapezoid:
double offset=pnt1.distance(pnt2.getX(),pnt1.getY())/4;
m_rect.setVertex(Rect.VERTEXTYPE_LEFTTOP,pnt1.getX()+offset,pnt1.getY());
m_rect.setVertex(Rect.VERTEXTYPE_RIGHTTOP,x-offset,pnt1.getY());
m_rect.setVertex(Rect.VERTEXTYPE_LEFTBOTTOM,pnt1.getX(),y);
m_rect.setVertex(Rect.VERTEXTYPE_RIGHTBOTTOM,x,y);
initNodes();
}
}
/**
* When moving a node, in some cases, e.g. ctrl key or shift key pressed to force preserving
* the form of a shape, or force equilateral shapes, we need to recalculate the actual moving
* node's position.
*
* @param movePos Desire moving position of a node.
* @param moveCase Move case of a node, normal, shift key pressed or ctrl key pressed
* @return The actual moving position of a node.
*
*/
public JFPoint getMoveNodePos(Node node,JFPoint movePos,int moveCase){
return movePos;
}
/**
* 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_ISOSCELESTRAPEZOID);
//init shape nodes.
initNodes();
//draw current moving node and its relational lines
draw(g,true);
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?