// Public Methods public void appendNextTreeGeneration(Vector generation) { DefaultMutableTreeNode nextGeneration = generationNodeBuilder(generation); generations.add(nextGeneration); // If Generations contains leaf nodes (generated objects) // Enabled Save All Menu Item if (generations.getLeafCount() > 0) miSaveAll.setEnabled(true); else miSaveAll.setEnabled(false); // Update JTree View // affected nodes needing updating int[] nodeRangeToUpdate = {generations.getIndex(nextGeneration)}; ((DefaultTreeModel) tree.getModel()).nodesWereInserted(generations, nodeRangeToUpdate); // Expand Parent after first child node is displayed if (generationNumber == 1) tree.expandRow(0); ++generationNumber; }
private void doSaveAll() { ObjectOutputStream objectStream = getObjectOutputStream(); if (objectStream != null) { try { System.out.println("Saving All " + generations.getLeafCount() + " Generations..."); for (Enumeration e = generations.depthFirstEnumeration(); e.hasMoreElements(); ) { DefaultMutableTreeNode tmpNode = (DefaultMutableTreeNode) e.nextElement(); if (tmpNode.isLeaf()) objectStream.writeObject(tmpNode.getUserObject()); } objectStream.close(); System.out.println("Save completed successfully."); } catch (IOException e) { System.err.println(e); } } else { System.out.println("Save All Files has been aborted!"); } }