📄 relation.java
字号:
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() {
if (startnodeid != null && startnodeid.trim().length() > 0) {
Element sn = _owner.getElementByID(startnodeid);
if (sn instanceof Node) {
return (Node) sn;
}
}
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;
// nd.appendElement(this);
}
/**
* 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) {
Element en = _owner.getElementByID(endnodeid);
if (en instanceof Node) {
return (Node) en;
}
}
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;
if (endnodeid != null && getStartnode() != null && getEndnode() != null
&& !getStartnode().isSelected(x, y)
&& !getEndnode().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.getRect().width / 2),
(int) (nd.y + nd.getRect().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.getRect().width / 2),
(int) (nd.y + nd.getRect().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) {
}
public void drawLine(Graphics g, int x1, int y1, int x2, int y2,
boolean dashed) {
if (false) {
double sina = Math.abs((double) Math.sqrt((y2 - y1) * (y2 - y1))
/ Math
.sqrt(((x2 - x1) * (x2 - x1) + (y2 - y1)
* (y2 - y1))));
double cosa = Math.abs((double) Math.sqrt((x2 - x1) * (x2 - x1))
/ Math
.sqrt(((x2 - x1) * (x2 - x1) + (y2 - y1)
* (y2 - y1))));
int len = 20, blen = 30;
int lencosa = (int) (len * cosa);
int lensina = (int) (len * sina);
int blencosa = (int) (blen * cosa);
int blensina = (int) (blen * sina);
int tx1 = 0, ty1 = 0, tx2 = 0, ty2 = 0;
tx1 = x1;
ty1 = y1;
while ((tx2 - x1) * (tx2 - x1) + (ty2 - y1) * (ty2 - y1) <= (y2 - y1)
* (y2 - y1) + (x2 - x1) * (x2 - x1)) {
tx2 = (int) (tx1 + ((x2 - x1) >= 0 ? 1 : -1) * lencosa);
ty2 = (int) (ty1 + ((y2 - y1) >= 0 ? 1 : -1) * lensina);
g.drawLine(tx1, ty1, tx2, ty2);
tx1 = (int) (tx1 + ((x2 - x1) >= 0 ? 1 : -1) * blencosa);
ty1 = (int) (ty1 + ((y2 - y1) >= 0 ? 1 : -1) * blensina);
}
} else {
g.drawLine(x1, y1, x2, y2);
}
}
public Node getAnotherEndNode(Node node) {
if (node == null || node.id == null)
return null;
Node startNode = getStartnode();
Node endNode = getEndnode();
if (startNode != null && startNode.id != null) {
if (startNode.id.equals(node.id)) {
return endNode;
}
}
if (endNode != null && endNode.id != null) {
if (endNode.id.equals(node.id)) {
return startNode;
}
}
return null;
}
public boolean isLinkageKeyRelation() {
Node startNode = getStartnode();
Node endNode = getEndnode();
if (startNode != null && startNode instanceof Column && endNode != null
&& endNode instanceof Column) {
return true;
} else {
return false;
}
}
public LinkageKey getLinkageKey() {
Node startNode = getStartnode();
Node endNode = getEndnode();
if (startNode != null && startNode instanceof Column && endNode != null
&& endNode instanceof Column) {
LinkageKey lks = new LinkageKey();
AbstractSheet sheet = ((Column) startNode).getSheet();
if (sheet instanceof MasterSheet) {
lks.masterSheet = (MasterSheet) sheet;
lks.masterSheetKeyColumn = (Column) startNode;
} else if (sheet instanceof DetailSheet) {
lks.detailSheet = (DetailSheet) sheet;
lks.detailSheetKeyColumn = (Column) startNode;
}
sheet = ((Column) endNode).getSheet();
if (sheet instanceof MasterSheet) {
lks.masterSheet = (MasterSheet) sheet;
lks.masterSheetKeyColumn = (Column) endNode;
} else if (sheet instanceof DetailSheet) {
lks.detailSheet = (DetailSheet) sheet;
lks.detailSheetKeyColumn = (Column) endNode;
}
return lks;
} else {
return null;
}
}
public boolean isCurrentToEdit() {
return _owner.isCurrentToEdit(this);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -