[Jreepad-CVS] jreepad/src/jreepad TreeView.java,1.3,1.4
Brought to you by:
danstowell
From: PeWu <pe...@us...> - 2007-03-15 12:47:11
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv22251/src/jreepad Modified Files: TreeView.java Log Message: Code cleanup Index: TreeView.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/TreeView.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TreeView.java 26 Jan 2007 22:38:37 -0000 1.3 --- TreeView.java 15 Mar 2007 12:46:05 -0000 1.4 *************** *** 43,47 **** public class TreeView extends JTree { ! private JreepadTreeModel treeModel; public TreeView(JreepadTreeModel treeModel) --- 43,48 ---- public class TreeView extends JTree { ! private static final String UNTITLED_NODE_TEXT = "<Untitled node>"; ! private JreepadTreeModel treeModel; public TreeView(JreepadTreeModel treeModel) *************** *** 68,77 **** public void editingCanceled(ChangeEvent e) { ! ensureNodeTitleIsNotEmpty(e); } public void editingStopped(ChangeEvent e) { ! ensureNodeTitleIsNotEmpty(e); } }); --- 69,78 ---- public void editingCanceled(ChangeEvent e) { ! ensureNodeTitleIsNotEmpty(); } public void editingStopped(ChangeEvent e) { ! ensureNodeTitleIsNotEmpty(); } }); *************** *** 79,83 **** // Add mouse listener - this will be used to implement drag-and-drop, context menu (?), etc addMouseListener(new TreeViewMouseListener()); - } --- 80,83 ---- *************** *** 87,109 **** JreepadNode lastEditedNode = (JreepadNode)(getSelectionPath().getLastPathComponent()); if (lastEditedNode.getTitle().equals("")) ! lastEditedNode.setTitle("<Untitled node>"); } ! private void ensureNodeTitleIsNotEmpty(ChangeEvent e) ! { ! TreeCellEditor theEditor = (TreeCellEditor)getCellEditor(); ! String newTitle = (String)(theEditor.getCellEditorValue()); ! ! // JreepadNode thatNode = (JreepadNode)(tree.getEditingPath().getLastPathComponent()); ! // System.out.println("ensureNodeTitleIsNotEmpty(): Event source = " + e.getSource()); ! // System.out.println("ensureNodeTitleIsNotEmpty(): thatNode = " + thatNode); ! // System.out.println("getCellEditorValue() = " + newTitle); ! if(newTitle.equals("")) ! { ! theEditor.getTreeCellEditorComponent(this, "<Untitled node>", true, true, false, 1); ! // thatNode.setTitle("<Untitled node>"); ! } ! } public void moveNode(JreepadNode node, JreepadNode newParent) --- 87,102 ---- JreepadNode lastEditedNode = (JreepadNode)(getSelectionPath().getLastPathComponent()); if (lastEditedNode.getTitle().equals("")) ! lastEditedNode.setTitle(UNTITLED_NODE_TEXT); } ! private void ensureNodeTitleIsNotEmpty() ! { ! TreeCellEditor theEditor = getCellEditor(); ! String newTitle = (String) (theEditor.getCellEditorValue()); ! if (newTitle.equals("")) ! theEditor.getTreeCellEditorComponent(this, UNTITLED_NODE_TEXT, ! true, true, false, 1); ! } public void moveNode(JreepadNode node, JreepadNode newParent) *************** *** 112,120 **** // - otherwise things would go really wonky! if (node.isNodeDescendant(newParent)) - { return; - } - - // DEL storeForUndo(); JreepadNode oldParent = node.getParentNode(); --- 105,109 ---- *************** *** 129,144 **** expanded = new Vector(); while (enumer.hasMoreElements()) ! { ! expanded.add((TreePath)enumer.nextElement()); ! // System.out.println(expanded.lastElement()); ! } } ! node.removeFromParent(); ! newParent.add(node); treeModel.reload(oldParent); treeModel.reload(newParent); - // treeModel.reload((TreeNode)tree.getPathForRow(0).getLastPathComponent()); // If the destination node didn't previously have any children, then we'll expand it --- 118,128 ---- expanded = new Vector(); while (enumer.hasMoreElements()) ! expanded.add(enumer.nextElement()); } ! newParent.add(node); // Also removes from old parent treeModel.reload(oldParent); treeModel.reload(newParent); // If the destination node didn't previously have any children, then we'll expand it |