📄 relation.java
字号:
arrowhead.y = p2.y + (int) (h2 / 2);
}
} else if (p2.y == p1.y && p2.x < p1.x) {
arrowhead.x = p2.x + (int) d2 / 2;
arrowhead.y = p2.y;
} else if (p2.y > p1.y && p2.x < p1.x) {
if (k2 >= k) {
arrowhead.x = p2.x + (int) d2 / 2;
arrowhead.y = p2.y - (int) (d2 * k / 2);
} else {
arrowhead.x = p2.x + (int) (h2 / 2 / k);
arrowhead.y = p2.y - (int) (h2 / 2);
}
} else {
arrowhead.x = p2.x;
arrowhead.y = p2.y - (int) h2 / 2;
}
return arrowhead;
}
public Vector getVector() {
return this.vector;
}
public void addVector(Object obj) {
if (this.vector.size() < 2) {
this.vector.addElement(obj);
} else { // 把新折点插入vector
int i = this.getWhichLine(this.getBreakpoint());
this.vector.insertElementAt(obj, i + 1);
}
}
public boolean checkDistance(Point point) { // 检查点到点的距离是否小于一个给定常数
int x = point.x;
int y = point.y;
int lx = 0;
int ly = 0;
int hx = 0;
int hy = 0;
int i = this.getWhichLine(this.getBreakpoint());
if (i >= 0) {
Point obj1 = (Point) this.vector.elementAt(i);
Point obj2 = (Point) this.vector.elementAt(i + 1);
if (i == 0) {
obj1 = this.getStartPoint();
}
if (i == this.vector.size() - 2) {
obj2 = this.getEndPoint();
}
if (obj1.x < obj2.x) {
lx = obj1.x;
hx = obj2.x;
} else {
hx = obj1.x;
lx = obj2.x;
}
if (obj1.y < obj2.y) {
ly = obj1.y;
hy = obj2.y;
} else {
hy = obj1.y;
ly = obj2.y;
}
double k = (double) (obj2.y - obj1.y) / (obj2.x - obj1.x);
double z = obj1.y - k * obj1.x;
int py = (int) (k * x + z);
int px = (int) ((y - z) / k);
if (k > 1 || k < -1) {
if ((ly <= y && y <= hy) && ((x - px) >= -15 && (x - px) <= 15)) {
return true;
} else {
}
} else {
if ((lx <= x && x <= hx) && ((y - py) >= -15 && (y - py) <= 15)) {
return true;
} else {
}
}
}
return false;
}
public void changeVector(Point point) {
int pos = this.getChangevector();
if (pos != -1) {
this.vector.setElementAt((Object) point, pos);
}
}
public int getWhichLine(Point point) { // 检查新折点应该插入哪条折线之间
if (point == null) {
return -1;
} else {
}
int x = point.x;
int y = point.y;
int lx = 0;
int ly = 0;
int hx = 0;
int hy = 0;
int i = 0;
if (endnodeid != null && !getStartnode().isSelected(x, y)
&& !getEndnode().isSelected(x, y)) {
for (i = 0; i < this.vector.size() - 1; i++) {
Point obj1 = (Point) this.vector.elementAt(i);
Point obj2 = (Point) this.vector.elementAt(i + 1);
if (i == 0) {
obj1 = this.getStartPoint();
}
if (i == this.vector.size() - 2) {
obj2 = this.getEndPoint();
}
if (obj1.x < obj2.x) {
lx = obj1.x;
hx = obj2.x;
} else {
hx = obj1.x;
lx = obj2.x;
}
if (obj1.y < obj2.y) {
ly = obj1.y;
hy = obj2.y;
} else {
hy = obj1.y;
ly = obj2.y;
}
double k = (double) (obj2.y - obj1.y) / (obj2.x - obj1.x);
double z = obj1.y - k * obj1.x;
int py = (int) (k * x + z);
int px = (int) ((y - z) / k);
if (k > 1 || k < -1) {
if ((ly <= y && y <= hy)
&& ((x - px) >= -5 && (x - px) <= 5)) {
break;
} else {
}
} else {
if ((lx <= x && x <= hx)
&& ((y - py) >= -5 && (y - py) <= 5)) {
break;
} else {
}
}
}
}
return i;
}
public Node getStartnode() {
System.out.print("startnodeid-->" + startnodeid);
if (startnodeid != null && startnodeid.trim().length() > 0) {
if (_startnode == null) {
Element sn = _owner.getElementByID(startnodeid);
_startnode = (Node) sn;
}
return _startnode;
}
return null;
}
/**
* Sets the value of the Startnode property.
*
* @param aStartnode
* the new value of the Startnode property@param nd
* @roseuid 3E0A6E1B0322
*/
public void setStartnode(Node nd) {
startnodeid = nd.id;
}
/**
* Access method for the Endnode property.
*
* @return the current value of the Endnode property
* @roseuid 3E0A6E1B0336
*/
public Node getEndnode() {
if (endnodeid != null && endnodeid.trim().length() > 0) {
if (_endnode == null) {
Element en = _owner.getElementByID(endnodeid);
_endnode = (Node) en;
}
return _endnode;
}
return null;
}
/**
* Sets the value of the Endnode property.
*
* @param aEndnode
* the new value of the Endnode property@param nd
* @roseuid 3E0A6E1B034A
*/
public void setEndnode(Node nd) {
endnodeid = nd.id;
}
/**
* @param x
* @param y
* @roseuid 3E0A6E1B035E
*/
public void moveTo(int x, int y) {
if (_mousepoint == null) {
_mousepoint = new Point(x, y);
} else {
_mousepoint.move(x, y);
}
if (_startpoint == null) {
_startpoint = _mousepoint;
}
if (_endpoint == null) {
_endpoint = _mousepoint;
}
}
/**
* @param x
* @param y
* @return boolean
* @roseuid 3E0A6E1B037C
*/
public boolean isSelected(int x, int y) {
boolean selected = false;
int lx = 0;
int ly = 0;
int hx = 0;
int hy = 0;
Node startNode = getStartnode();
Node endNode = getEndnode();
if (endnodeid != null && startNode != null && endNode != null
&& !startNode.isSelected(x, y) && !endNode.isSelected(x, y)) {
for (int i = 0; i < this.vector.size() - 1; i++) {
Point obj1 = (Point) this.vector.elementAt(i);
Point obj2 = (Point) this.vector.elementAt(i + 1);
if (i == 0) {
obj1 = this.getStartPoint();
}
if (i == this.vector.size() - 2) {
obj2 = this.getEndPoint();
}
if (obj1.x < obj2.x) {
lx = obj1.x;
hx = obj2.x;
} else {
hx = obj1.x;
lx = obj2.x;
}
if (obj1.y < obj2.y) {
ly = obj1.y;
hy = obj2.y;
} else {
hy = obj1.y;
ly = obj2.y;
}
double k = (double) (obj2.y - obj1.y) / (obj2.x - obj1.x);
double z = obj1.y - k * obj1.x;
// 斜率大于1时比较x方向的差距,否则比较y方向的差距
int py = (int) (k * x + z);
int px = (int) ((y - z) / k);
if (k > 1 || k < -1) {
if ((ly <= y && y <= hy)
&& ((x - px) >= -5 && (x - px) <= 5)) {
selected = true;
break;
} else {
selected = false;
}
} else {
if ((lx <= x && x <= hx)
&& ((y - py) >= -5 && (y - py) <= 5)) {
selected = true;
break;
} else {
selected = false;
}
}
}
}
if (selected) {
if (this._owner.get_statues() == 0x00000001) {
} else {
this._owner.setCursor(new Cursor(Cursor.SW_RESIZE_CURSOR));
}
} else {
if (this._owner.get_statues() == 0x00000001) {
} else {
this._owner.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
return selected;
}
/**
* @return java.awt.Rectangle
* @roseuid 3E0A6E1B039A
*/
public Rectangle getRepaintRect() {
Rectangle rct = new Rectangle();
return rct;
}
public int checkWhichpoint(Point point) { // 检查新折点与哪个原有折点距离最近
int d = 0;
int i = 0;
int position = -1;
for (i = 0; i < this.vector.size(); i++) {
Point obj = (Point) this.vector.elementAt(i);
d = Math.abs((int) (Math.sqrt((point.y - obj.y) * (point.y - obj.y)
+ (point.x - obj.x) * (point.x - obj.x))));
if (d <= 10) {
position = i;
this.changevector = i;
break;
}
}
return position;
}
public int getDistance(Point point1, Point point2) { // 得到点到点之间的距离
int d = -1;
d = Math.abs((int) Math.sqrt((point2.y - point1.y)
* (point2.y - point1.y) + (point2.x - point1.x)
* (point2.x - point1.x)));
return d;
}
public boolean lineTolineAngle(Point point1, Point point2, Point point3) { // 检查线与线的夹角是否小于一个给定值
double k1 = 0;
double k2 = 0;
double a = 0;
if (point2.x == point1.x && point3.x == point2.x) {
return true;
} else if (point2.x == point1.x) {
k1 = 0;
k2 = (double) (point3.y - point2.y) / (point3.x - point2.x);
a = Math.abs((double) (k2 - k1) / (1 + k1 * k2));
if (a >= Math.tan((double) 85 / 180 * Math.PI)) {
return true;
} else {
}
} else {
if (point3.x == point2.x) {
k2 = 0;
k1 = (double) (point2.y - point1.y) / (point2.x - point1.x);
a = Math.abs((double) (k2 - k1) / (1 + k1 * k2));
if (a >= Math.tan((double) 85 / 180 * Math.PI)) {
return true;
} else {
}
} else {
k1 = (double) (point2.y - point1.y) / (point2.x - point1.x);
k2 = (double) (point3.y - point2.y) / (point3.x - point2.x);
a = Math.abs((double) (k2 - k1) / (1 + k1 * k2));
if (a <= Math.tan((double) 5 / 180 * Math.PI)) {
return true;
} else {
}
}
}
return false;
}
/**
* @return java.awt.Point
* @roseuid 3E0A6E1B03B8
*/
public Point getMovepoint() {
return this._movepoint;
}
public void setMovepoint(Point p) {
this._movepoint = p;
}
public Point getStartPoint() {
Node nd = this.getStartnode();
if (nd != null) {
Point p = new Point((int) (nd.x + nd._imgrect.width / 2),
(int) (nd.y + nd._imgrect.height / 2));
_startpoint = p;
return p;
}
return this._startpoint;
}
/**
* @return java.awt.Point
* @roseuid 3E0A6E1B03CC
*/
public Point getEndPoint() {
Node nd = this.getEndnode();
if (nd != null) {
Point p = new Point((int) (nd.x + nd._imgrect.width / 2),
(int) (nd.y + nd._imgrect.height / 2));
_endpoint = p;
return p;
} else {
return this._endpoint;
}
}
public boolean removeSubElement(String id) {
return false;
}
public void removeAllSubElement() {
}
/**
* @param e
* @roseuid 3E0A6F9A0047
*/
public void onMouseClicked(MouseEvent e) {
}
/**
* @param e
* @roseuid 3E0A6F9A0098
*/
public void onMouseDragged(MouseEvent e) {
}
/**
* @param e
* @roseuid 3E0A6F9A00F2
*/
public void onMouseMoved(MouseEvent e) {
}
/**
* @param e
* @roseuid 3E0A6F9A014C
*/
public void onMousePressed(MouseEvent e) {
}
/**
* @param e
* @roseuid 3E0A6F9A019C
*/
public void onMouseReleased(MouseEvent e) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -