📄 abstractedgepainter.java
字号:
package net.sourceforge.jpowergraph.painters;
import net.sourceforge.jpowergraph.Edge;
import net.sourceforge.jpowergraph.pane.JGraphPane;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
/**
* The abstract painter for edges.
*/
public abstract class AbstractEdgePainter implements EdgePainter {
/**
* Returns the distance of the point to the edge.
*
* @param graphPane the graph pane
* @param edge the edge
* @param point the point
* @return the distance of the point from the edge
*/
public double screenDistanceFromEdge(JGraphPane graphPane,Edge edge,Point point) {
double px=point.x;
double py=point.y;
Point from=graphPane.getScreenPointForNode(edge.getFrom());
Point to=graphPane.getScreenPointForNode(edge.getTo());
double x1=from.x;
double y1=from.y;
double x2=to.x;
double y2=to.y;
if (px<Math.min(x1,x2)-8 || px>Math.max(x1,x2)+8 || py<Math.min(y1,y2)-8 || py>Math.max(y1,y2)+8)
return 1000;
double dist=1000;
if (x1-x2!=0)
dist=Math.abs((y2-y1)/(x2-x1)*(px-x1)+(y1-py));
if (y1-y2!=0)
dist=Math.min(dist,Math.abs((x2-x1)/(y2-y1)*(py-y1)+(x1-px)));
return dist;
}
/**
* Returns the outer rectangle of the edge on screen.
*
* @param graphPane the graph pane
* @param edge the edge
* @param edgeScreenRectangle the rectangle receiving the edge's coordinates
*/
public void getEdgeScreenBounds(JGraphPane graphPane,Edge edge,Rectangle edgeScreenRectangle) {
Point from=graphPane.getScreenPointForNode(edge.getFrom());
Point to=graphPane.getScreenPointForNode(edge.getTo());
edgeScreenRectangle.x = Math.min(from.x,to.x);
edgeScreenRectangle.y = Math.min(from.y,to.y);
edgeScreenRectangle.width = Math.abs(to.x-from.x)+1;
edgeScreenRectangle.height = Math.abs(to.y-from.y)+1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -