⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edge.java

📁 ALGAE是一个快速创建算法演示的框架。目前支持的算法实现语言包括java和c
💻 JAVA
字号:
package edu.odu.cs.zeil.AlgAE.Client.DataViewer.DataGraph;import edu.odu.cs.zeil.AlgAE.Debug;import edu.odu.cs.zeil.AlgAE.Direction;import edu.odu.cs.zeil.AlgAE.Client.GraphicsInfo;import edu.odu.cs.zeil.AlgAE.Client.DataViewer.DataGraph.Edgeable;import java.awt.Color;import java.awt.Graphics;import java.awt.Point;import java.awt.Polygon;  public abstract class Edge{  public /* final */ Edgeable source;      // final causes intermittant  public /* final */ Edgeable destination; //  compiler problems: JDK 1.1.2  public /* final */ int dir;  public /* final */ Color color;  public /* final */ String label;  Edge(Edgeable src, Edgeable dest, int direction, Color colour, String edgeLabel)  {    source = src;    destination = dest;    dir = direction;    color = colour;    label = edgeLabel;  }    Point exitPoint()  {    int d = dir;    if (dir == Direction.ANYDIR)      {	if (destination != null)	  d = source.directionTo(destination.center());	else	  d = Direction.SW;      }    return source.exitPoint(d);  }    protected void drawExitPoint (GraphicsInfo gi, Point p)  {    if (dir != Direction.ANYDIR) {      gi.g.setColor (color);      int diameter = 3*gi.getTextOffset().width / 3;      gi.g.fillOval (p.x - diameter/2, p.y - diameter/2,		     diameter, diameter);    }  }  abstract Point entryPoint();  abstract void draw(GraphicsInfo gi);  abstract double length();  abstract double positionScore(double targetLength);  protected void drawArrowHead(Point tip, Point base, GraphicsInfo gi)  {    int dx = tip.x - base.x;    int dy = tip.y - base.y;    if (dx != 0 || dy != 0)      {	double len = Math.sqrt (((double)dx)*dx + ((double)dy)*dy);	Point p1 = new Point();	p1.x = tip.x - (int)(3 * gi.getTextOffset().width / 2 / len * dx);	p1.y = tip.y - (int)(3 * gi.getTextOffset().width / 2 / len * dy);	      	Polygon triangle = new Polygon();	triangle.addPoint (tip.x, tip.y);	triangle.addPoint 	  (p1.x + 2 * (tip.y - p1.y) / 3,	   p1.y - 2 * (tip.x - p1.x) / 3	    );	triangle.addPoint 	  (p1.x - 2 * (tip.y - p1.y) / 3,	   p1.y + 2 * (tip.x - p1.x) / 3	    );	gi.g.setColor (color);	gi.g.fillPolygon (triangle);      }  }  static public final double one2 = 1.0/Math.sqrt(2.0);  static public final double one5 = 1.0/Math.sqrt(5.0);  static public final double two5 = 2.0/Math.sqrt(5.0);    static public final double xNorm[] =    {0.0, one5, one2, two5, 1.0, two5, one2, one5,     0.0, -one5, -one2, -two5, -1.0, -two5, -one2, -one5};  static public final double yNorm[] =    {-1.0, -two5, -one2, -one5, 0.0, one5, one2, two5,      1.0, two5, one2, one5, 0.0, -one5, -one2, -two5};     }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -