📄 arrow.java
字号:
package com.sunking.tp.framework;import java.beans.*;import java.awt.*;/** * * <p>Title: </p> * <p>Description: 箭头</p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author <a href="mailto:sunkingxie@hotmail.com">SunKing</a> * @version 1.0 * @see LineRenderer */public class Arrow implements LineRenderer { /** *所属连线 */ protected AssoicatorLine line; /** *箭头的绘画范围 */ transient protected Polygon polygon; /** * @param line 所属连线 */ public Arrow(AssoicatorLine line) { this.line = line; } /** *取得箭头的绘画范围 */ public Rectangle getBounds() { return getPolygon().getBounds(); } /** *绘制箭头 */ public void paint(java.awt.Graphics g) { if(line.getAssociateType() == 1){ return; } Color oldC= g.getColor(); g.setColor(javax.swing.UIManager.getColor("Desktop.background")); g.fillPolygon(getPolygon()); g.setColor(Color.black); if(line.getAssociateType() == 3){ g.fillPolygon(getPolygon()); }else{ g.drawPolygon(getPolygon()); } g.setColor(oldC); } /** *取得默认的绘画范围 * @return */ protected Polygon getPolygon(){ if(polygon == null){ polygon = getDefaultPolygon(); } return polygon; } /** *根据所属连线的位置定位三个点的偏移点. */ private Polygon getDefaultPolygon(){ Locator locs[] = new Locator[] { new PolarCoordinate( 10, 0.5 + Math.PI ), new PolarCoordinate( 0, 0.0 ), new PolarCoordinate( 10, -0.5 + Math.PI ) }; int xArray[] = new int[locs.length]; int yArray[] = new int[locs.length]; for ( int i = 0; i < locs.length; i++ ) { xArray[i] = getArrowLocator( locs[i] ).x(); yArray[i] = getArrowLocator( locs[i] ).y(); } return new Polygon( xArray, yArray, locs.length); } protected Locator getArrowLocator( Locator loc ) { Locator source = new DrawingPoint((int)line.getX1(),(int)line.getY1()); Locator dest = new DrawingPoint((int)line.getX2(),(int)line.getY2()); Locator relative = new DrawingPoint(dest.x()-source.x(), dest.y()-source.y()); PolarCoordinate coord = new PolarCoordinate( loc.r(), loc.theta() + relative.theta() ); return new DrawingPoint( dest.x() + coord.x(), dest.y() + coord.y() ); }}/** * * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author <a href="mailto:sunkingxie@hotmail.com">SunKing</a> * @version 1.0 */interface Locator { public abstract int r(); public abstract double theta(); public abstract int x(); public abstract int y();}/** * * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author <a href="mailto:sunkingxie@hotmail.com">SunKing</a> * @version 1.0 */class PolarCoordinate implements Locator { protected int r; protected double theta; public PolarCoordinate(int r, double theta) { this.r = r; this.theta = theta; } public int r() { return r; } public double theta() { return theta; } public int x() { return (int)( r * Math.cos( theta ) ); } public int y() { return (int)( r * Math.sin( theta ) ); }}/** * * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author <a href="mailto:sunkingxie@hotmail.com">SunKing</a> * @version 1.0 */class DrawingPoint implements Locator{ protected int x; protected int y; public DrawingPoint(int x, int y) { this.x = x; this.y = y; } public int x() { return x; } public int y() { return y; } public int r() { int myX = x(); int myY = y(); return (int)Math.sqrt((myX * myX) + (myY * myY)); } public double theta() { double theta = Math.atan((double)y()/(double)x()); if (x() < 0) theta = theta + Math.PI; return theta; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -