result.append("\n"); Canvas canvas = new Canvas(); int width = 0; for (Node n : nodes) {
public void draw(Canvas canvas, int line, int column, int width) { canvas.set(line, getNamePos(column, width), name); if (alias) canvas.set(line + 1, column + ((width - 1) / 2), "*"); else if (!children.isEmpty()) { int[] childWidth = new int[children.size()]; int childrenWidth = 0; for (int i = 0; i < children.size(); i++) childrenWidth += childWidth[i] = children.get(i).getMinWidth(); while (childrenWidth < width) for (int i = children.size() - 1; i >= 0; i--) { childWidth[i]++; childrenWidth++; } int childCol = column; for (int i = 0; i < children.size(); i++) { Node child = children.get(i); drawEdge(canvas, line, getNamePos(column, width), name.length(), getNamePos(childCol, childWidth[i]), child.name.length()); child.draw(canvas, line + 2, childCol, childWidth[i]); childCol += childWidth[i]; } } }
result.append("\n"); Canvas canvas = new Canvas(); int width = 0; for (Node n : nodes) {
public void draw(Canvas canvas, int line, int column, int width) { canvas.set(line, getNamePos(column, width), name); if (alias) canvas.set(line + 1, column + ((width - 1) / 2), "*"); else if (!children.isEmpty()) { int[] childWidth = new int[children.size()]; int childrenWidth = 0; for (int i = 0; i < children.size(); i++) childrenWidth += childWidth[i] = children.get(i).getMinWidth(); while (childrenWidth < width) for (int i = children.size() - 1; i >= 0; i--) { childWidth[i]++; childrenWidth++; } int childCol = column; for (int i = 0; i < children.size(); i++) { Node child = children.get(i); drawEdge(canvas, line, getNamePos(column, width), name.length(), getNamePos(childCol, childWidth[i]), child.name.length()); child.draw(canvas, line + 2, childCol, childWidth[i]); childCol += childWidth[i]; } } }
protected void drawEdge(Canvas canvas, int fromLine, int fromCol, int fromWidth, int toCol, int toWidth) { int toPos = toCol + ((toWidth - 1) / 2); if ((fromCol <= toCol && fromCol + fromWidth >= toCol) || (fromCol <= toCol + toWidth && fromCol + fromWidth >= toCol + toWidth)) { int left = Math.max(fromCol, toCol); int right = Math.min(fromCol + fromWidth, toCol + toWidth); canvas.set(fromLine + 1, left - ((left - right) / 2), "|"); } else if (fromCol + 1 > toPos) { for (int i = toPos + 2; i < fromCol - 1; i++) canvas.set(fromLine, i, "_"); canvas.set(fromLine + 1, toPos + 1, "/"); } else if (fromCol + fromWidth - 1 < toPos) { for (int i = toPos - 2; i > fromCol + fromWidth; i--) canvas.set(fromLine, i, "_"); canvas.set(fromLine + 1, toPos - 1, "\\"); } }
protected void drawEdge(Canvas canvas, int fromLine, int fromCol, int fromWidth, int toCol, int toWidth) { int toPos = toCol + ((toWidth - 1) / 2); if ((fromCol <= toCol && fromCol + fromWidth >= toCol) || (fromCol <= toCol + toWidth && fromCol + fromWidth >= toCol + toWidth)) { int left = Math.max(fromCol, toCol); int right = Math.min(fromCol + fromWidth, toCol + toWidth); canvas.set(fromLine + 1, left - ((left - right) / 2), "|"); } else if (fromCol + 1 > toPos) { for (int i = toPos + 2; i < fromCol - 1; i++) canvas.set(fromLine, i, "_"); canvas.set(fromLine + 1, toPos + 1, "/"); } else if (fromCol + fromWidth - 1 < toPos) { for (int i = toPos - 2; i > fromCol + fromWidth; i--) canvas.set(fromLine, i, "_"); canvas.set(fromLine + 1, toPos - 1, "\\"); } }