📄 arrowshell.java
字号:
package org.goshawk.workflow.GUI.ShapeShell;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MenuItem;
import java.awt.Polygon;
import java.awt.PopupMenu;
import java.awt.Shape;
import java.awt.geom.Line2D;
import java.util.Map;
import org.goshawk.workflow.GUI.Action.DeleteArrowAction;
public class ArrowShell extends ShapeShell
{
private int fx;
private int fy;
private int endx;
private int endy;
private ShapeShell startNode;
private ShapeShell endNode;
private Polygon triangle = null;
private Line2D line = null;
private PopupMenu popupMenu = null;
public ArrowShell(int fx, int fy, int endx, int endy)
{
this.fx = fx;
this.fy = fy;
this.endx = endx;
this.endy = endy;
triangle = (Polygon) drawArrow(fx,fy,endx,endy,15);
line = new Line2D.Double(fx,fy,endx,endy);
}
public ArrowShell(ShapeShell start,ShapeShell end)
{
this.fx = start.getCenterX();
this.fy = start.getCenterY();
this.endx = end.getCenterX();
this.endy = end.getCenterY();
triangle = (Polygon) drawArrow(fx,fy,endx,endy,15);
line = new Line2D.Double(fx,fy,endx,endy);
this.startNode = start;
this.endNode =end;
}
public boolean contains(int x, int y)
{
return triangle.contains(x,y)||lineCotains(x,y);
}
public Shape getShape()
{
System.out.println("该图形没有Shape,如有疑问请与作者联系");
return null;
}
public void setShape(Shape shape) throws ShapeShellException
{
System.out.println("该图形没有Shape,如有疑问请与作者联系");
}
public int getHeight(){return 0;}
public void setHeight(int height){}
public int getWidth(){return 0;}
public void setWidth(int width){}
public int getX(){return 0;}
public void setX(int x){}
public int getY(){return 0;}
public void setY(int y){}
public int getCenterX(){return 0;}
public int getCenterY(){return 0;}
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
g2.fill(triangle);
g2.draw(line);
if(isSelected)
{
g2.setColor(selectedColor);
g2.fillRect(fx-2,fy-2,4,4);
g2.fillRect(endx-2,endy-2,4,4);
}
}
public PopupMenu getPopupMenu()
{
popupMenu = new PopupMenu("1");
MenuItem deleteItem = new MenuItem("删除");
deleteItem.addActionListener(new DeleteArrowAction(this));
popupMenu.add(deleteItem);
return popupMenu;
}
public void setPopupMenu(PopupMenu menu){}
public Object clone(){return null;}
public void editShape(int mousex, int mousey){}
private Shape drawArrow(int startX,int startY,int endX,int endY,int size)
{
double xx=0,yy=0,xx1=0,yy1=0,xx2=0,yy2=0;
int myWidth=0;
int myHeight=0;
xx=endX-(endX-startX)*myWidth/Math.pow((double)(endX-startX)*(endX-startX)+(double)(endY-startY)*(endY-startY),1/2d);
yy=endY-(endY-startY)*myHeight/(Math.pow((double)(endX-startX)*(endX-startX)+(double)(endY-startY)*(endY-startY),1/2d));
xx1=xx-size*Math.cos(Math.atan(((double)yy-startY)/((double)xx-startX))-radians(30));
yy1=yy-size*Math.sin(Math.atan(((double)yy-startY)/((double)xx-startX))-radians(30));
xx2=xx-size*Math.sin(radians(60)-Math.atan(((double)(yy-startY))/((double)(xx-startX))));
yy2=yy-size*Math.cos(radians(60)-Math.atan(((double)(yy-startY))/((double)(xx-startX))));
if(startX+myWidth>endX+myWidth) {
xx1=xx+size*Math.cos(Math.atan(((double)yy-startY)/((double)xx-startX))-radians(30));
yy1=yy+size*Math.sin(Math.atan(((double)yy-startY)/((double)xx-startX))-radians(30));
xx2=xx+size*Math.sin(radians(60)-Math.atan(((double)(yy-startY))/((double)(xx-startX))));
yy2=yy+size*Math.cos(radians(60)-Math.atan(((double)(yy-startY))/((double)(xx-startX))));
}
return new Polygon(new int[] {(int)xx2,(int)xx1,(int)xx}, new int[] {(int)yy2,(int)yy1,(int)yy}, 3);
}
public double radians(int degrees)// 该函数用于将角度转化为弧度
{
return ((double) degrees) * Math.PI / 180.0;
}
public void addOtherShape(ShapeShell shape)
{
}
public Map getOtherShapes()
{
return null;
}
public Map setOtherShapes(Map shapes)
{
return null;
}
public ShapeShell getOtherShape(String id)
{
return null;
}
public ShapeShell removeOtherShape(String id)
{
return null;
}
public ShapeShell getEndNode()
{
return endNode;
}
public void setEndNode(ShapeShell endNode)
{
this.endNode = endNode;
endx = endNode.getCenterX();
endy = endNode.getCenterY();
triangle = (Polygon) drawArrow(fx,fy,endx,endy,15);
line = line = new Line2D.Double(fx,fy,endx,endy);
}
public ShapeShell getStartNode()
{
return startNode;
}
public void setStartNode(ShapeShell startNode)
{
this.startNode = startNode;
fx = startNode.getCenterX();
fy = startNode.getCenterY();
triangle = (Polygon) drawArrow(fx,fy,endx,endy,15);
line = line = new Line2D.Double(fx,fy,endx,endy);
}
private boolean lineCotains(double x,double y)
{
/*double startx = fx;
double starty = fy;
double endx = this.endx;
double endy = this.endy;
double k1 = (y-starty)/(x-startx);
double k2 = (endy-starty)/(endx-startx);
return k1==k2;*/
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -