abstractedgepainter.java
来自「JPowerGraph is a Java library for creati」· Java 代码 · 共 52 行
JAVA
52 行
package net.sourceforge.jpowergraph.painters;
import java.awt.Point;
import java.awt.Rectangle;
import net.sourceforge.jpowergraph.Edge;
import net.sourceforge.jpowergraph.pane.JGraphPane;
/**
* 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.setBounds(Math.min(from.x,to.x),Math.min(from.y,to.y),Math.abs(to.x-from.x)+1,Math.abs(to.y-from.y)+1);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?