public void reposition() { if (D.getLayout() == Layout.SIMPLE) { // simple layout reboxTree(); repos(); } else { // Reingold-Tilford layout RTThreads(); RTPreposition(); RTPetrification(0, 0); reboxTree(); } }
private void drawTree2(View v) { if (markSubtree) { Polygon p = new Polygon(); p.addPoint(x - 1, y - 1); if (D.getLayout() == Layout.SIMPLE) { if (height == 1) { p.addPoint(x - 7, y + 10); p.addPoint(x + 7, y + 10); } else { int x1 = x - leftw + DataStructure.minsepx / 2, x2 = x + rightw - DataStructure.minsepx / 2, y1 = y + DataStructure.minsepy, y2 = y + (height - 1) * DataStructure.minsepy; p.addPoint(x1, y1); p.addPoint(x1, y2); p.addPoint(x2, y2); p.addPoint(x2, y1); } } else { BSTNode u = this, w = this; Stack<BSTNode> tmp = new Stack<BSTNode>(); while (u != null && w != null) { p.addPoint(u.x - 1, u.y); tmp.add(w); if (u.thread && w.thread) break; u = (u.left != null) ? u.left : u.right; w = (w.right != null) ? w.right : w.left; } while (!tmp.isEmpty()) { w = tmp.pop(); p.addPoint(w.x + 1, w.y); } } p.addPoint(x + 1, y - 1); v.fillPolygon(p); } if (state != INVISIBLE && parent != null) { v.setColor(Color.black); v.drawLine(x, y, parent.x, parent.y); } if (getLeft() != null) { // System.out.println("kreslim lavy " + getLeft().key + " " + this.key); getLeft().drawTree2(v); } if (D instanceof BST && ((BST) D).order) { // && D.M.S.layout == // Layout.SIMPLE v.setColor(Color.LIGHT_GRAY); ++i; if (i % 10 == 0) { v.drawLine(x, y, x, -22); } else { v.drawLine(x, y, x, -20); } if (i % 10 == 0) { v.drawString("" + i, x, -29, Fonts.NORMAL); } else if (i % 10 == 5) { v.drawString("5", x, -27, Fonts.NORMAL); } else { v.drawString("" + i % 10, x, -27, Fonts.SMALL); } } if (getRight() != null) { getRight().drawTree2(v); } draw(v); }