public void createStruct(int type) { switch (type) { case IGEDConst.LISTA: LinkedList l = new LinkedList(quadro); l.setyBase(Quadro.YBASE); int y = Quadro.YBASE; for (WrapperStruct w : structs.values()) { if (w.isDataStruct()) { if (w.getStruct() != null) { y += w.getStruct().getBond() + 35; } } } l.setyBase(y); pilha.push(new WrapperStruct(l, IGEDConst.LISTA, quadro)); break; case IGEDConst.NODE: LinkedListNode n = new LinkedListNode(new Point2D.Double(getXNodeSoltos(), Quadro.YBASE_TRABALHO), quadro); pilha.push(new WrapperStruct(n, IGEDConst.NODE, quadro)); quadro.add(n); this.nodesSoltos++; break; case IGEDConst.VETOR: int y2 = Quadro.YBASE; for (WrapperStruct w : structs.values()) { if (w.isDataStruct()) { if (w.getStruct() != null) { y2 += w.getStruct().getBond() + 35; } } } Vetor v = new Vetor(y2, quadro); v.setSize(this.regVet); pilha.push(new WrapperStruct(v, IGEDConst.VETOR, quadro)); break; case IGEDConst.NODE_TREE: NodeTree nt = new NodeTree( new Point2D.Double(getXNodeSoltos(), this.boundsBinaryTree + ESPACO_ESTRUTURAS), quadro); pilha.push(new WrapperStruct(nt, IGEDConst.NODE_TREE, quadro)); quadro.add(nt); this.nodesSoltos++; break; case IGEDConst.BINARY_TREE: BinaryTree bt = new BinaryTree(quadro); pilha.push(new WrapperStruct(bt, IGEDConst.BINARY_TREE, quadro)); break; default: break; } }
public void lixeiro() { quadro.limpar(); for (WrapperStruct w : this.structs.values()) { System.out.println(w.getReferencia()); w.startRepaint(); } // Pintas as Estruturas diferentes de Nodes. List<WrapperStruct> nodes = new ArrayList<WrapperStruct>(); for (WrapperStruct w : this.structs.values()) { if (w.isDataStruct()) { System.out.println("Repintar: " + w.getReferencia()); /** * Devido a particularidade da binarytree em crescer para baixo o código deste if calcula o * limite inferior da árvore */ if (w.getType() == IGEDConst.BINARY_TREE && w.getStruct() != null) { BinaryTree bt = ((BinaryTree) w.getStruct()); bt.adjust(); this.calculaBound(bt.readField(IGEDConst.NODE_TREE_ROOT), IGEDConst.BINARY_TREE); System.out.println("o/"); } w.repintar(); } else { System.out.println("Nodes add: " + w.getReferencia()); nodes.add(w); } } this.nodesSoltos = 0; Collections.sort(nodes); for (WrapperStruct no : nodes) { if (no.getStruct() != null && !no.getStruct().isRepintado()) { no.repintar(); System.out.println("HHHHHHH"); if (no.getType() == IGEDConst.NODE) { LinkedListNode n = ((LinkedListNode) no.getStruct()); // Cria um semaphoro que bloquea a Thread equanto os nodes n forem desenhados. LinkedListNode aux = n.getProx(); // Conta com o no atual n. int count = 1; while ((aux != null) && (!aux.isAjustado()) && (aux != n)) { ++count; aux = aux.getProx(); } System.out.println("Noooode: " + count); if (count > 0) { Semaphore sem = new Semaphore(0, true); n.adjust(new Point2D.Double(getXNodeSoltos(), Quadro.YBASE_TRABALHO), sem); try { sem.acquire(count); } catch (InterruptedException ie) { } } nodesSoltos++; } else { NodeTree nt = ((NodeTree) no.getStruct()); nt.mover( new Point2D.Double(getXNodeSoltos(), this.boundsBinaryTree + this.ESPACO_ESTRUTURAS)); nt.repintar(); nodesSoltos++; } // // LinkedListNode n = ((LinkedListNode) no.getStruct()); // // ((LinkedListNode) no.getStruct()).adjust(new // Point2D.Double(getXNodeSoltos(), yBaseTrabalho)); // nodesSoltos++; } else { no.repintar(); } } quadro.atualizar(); clearStack(); this.vi.repintar(); }