package prog2_aufgabe12; import java.awt.*; import java.util.ArrayList; import javax.swing.border.LineBorder; import javax.swing.border.TitledBorder; public class Knoten implements Comparable { public static Color col_unknown = Color.WHITE; public static Color col_start = new Color(0, 221, 0); public static Color col_ziel = Color.RED; public static Color col_openlist = new Color(152, 251, 152); public static Color col_closedlist = new Color(175, 238, 238); public static Color col_path = Color.BLUE;; public enum Status { unknown, closedList, openList, path, start, ziel } private Status status = Status.unknown; public String bez; public double x = Double.MAX_VALUE; public double y = Double.MAX_VALUE; private Color background = Color.BLACK; public double distance2Ziel = Double.MAX_VALUE; public double g = Double.MAX_VALUE; public double f = Double.MAX_VALUE; public double fFest = Double.MAX_VALUE; public Knoten prev = null; public ArrayList next = new ArrayList(); public boolean start = false; public boolean ziel = false; public Knoten(String bez, double x, double y) { this.bez = bez; this.x = x; this.y = y; setStatus(Status.unknown); } public void init() { distance2Ziel=Double.MAX_VALUE; g=Double.MAX_VALUE; f=Double.MAX_VALUE; prev = null; } public void paint(Graphics g, boolean drawline, double xmin, double diffx, double ymin, double diffy, int width, int height, FontMetrics fontMetrics) { int ix, iy; Knoten v; int ix2, iy2; ix = (int) ((x - xmin) * width / diffx); iy = (int) ((y - ymin) * height / diffy); g.setColor(background); if (drawline) { Graphics2D g2 = (Graphics2D) g; g2.setStroke(new BasicStroke(7.0f)); g.setColor(Color.YELLOW); for (Kante kn : next) { v=kn.next; ix2 = (int) ((v.x - xmin) * width / diffx); iy2 = (int) ((v.y - ymin) * height / diffy); g.drawLine(ix, height - iy, ix2, height - iy2); } } else { int h = fontMetrics.getHeight(); int w = fontMetrics.stringWidth(bez); int w2 = w; if (h > w2) { w2 = h; } g.fillRect(ix - w2 + (w >> 1), height - (iy + w2 + ((int) (h * 0.35))), w2 << 1, w2 << 1); g.setColor(Color.BLACK); Graphics2D g2 = (Graphics2D) g; g2.setStroke(new BasicStroke(4.0f)); g.drawRect(ix - w2 + (w >> 1), height - (iy + w2 + ((int) (h * 0.35))), w2 << 1, w2 << 1); if (start) { g.setColor(col_start); g.drawRect(ix - w2 + (w >> 1)-5, height - (+5+iy + w2 + ((int) (h * 0.35))), (w2 << 1)+10, (w2 << 1)+10); } if (ziel) { g.setColor(col_ziel); g.drawRect(ix - w2 + (w >> 1)-5, height - (+5+iy + w2 + ((int) (h * 0.35))), (w2 << 1)+10, (w2 << 1)+10); } g.setColor(Color.BLACK); g.drawString(bez, ix, height - iy); } } @Override public int compareTo(Knoten bn) { if (distance2Ziel < bn.distance2Ziel) { return -1; } else if (distance2Ziel > bn.distance2Ziel) { return +1; } else { return 0; } } public Status getStatus() { return status; } public String toString() { return bez; } public void setStatus(Status status) { switch (status) { case unknown: if (!start && !ziel) { background = col_unknown; } this.status = status; break; case closedList: //if (!start && !ziel) { background = col_closedlist; //} this.status = status; break; case openList: // if (!start && !ziel) { background = col_openlist; //} this.status = status; break; case path: //if (!start && !ziel) { background = col_path; //} this.status = status; break; case start: background = col_start; this.status = status; break; case ziel: background = col_ziel; this.status = status; break; } } }