Thread: [Jreepad-CVS] jreepad/src/jreepad SoftLinkNode.java, NONE, 1.1 JreepadNode.java, 1.25, 1.26 TreeVie
Brought to you by:
danstowell
From: PeWu <pe...@us...> - 2007-01-26 22:38:42
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv18279/src/jreepad Modified Files: JreepadNode.java TreeView.java Added Files: SoftLinkNode.java Log Message: refactoring: made SoftLinkNode a separate class not to interfere with JreepadNode's default implementation Index: TreeView.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/TreeView.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TreeView.java 16 Jan 2007 23:56:03 -0000 1.2 --- TreeView.java 26 Jan 2007 22:38:37 -0000 1.3 *************** *** 35,38 **** --- 35,39 ---- + /** * The GUI component that displays the tree. *************** *** 110,114 **** // First we need to make sure that the node is not a parent of the new parent // - otherwise things would go really wonky! ! if (node.isNodeInSubtree(newParent)) { return; --- 111,115 ---- // First we need to make sure that the node is not a parent of the new parent // - otherwise things would go really wonky! ! if (node.isNodeDescendant(newParent)) { return; --- NEW FILE: SoftLinkNode.java --- /* Jreepad - personal information manager. Copyright (C) 2004-2006 Dan Stowell This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. The full license can be read online here: http://www.gnu.org/copyleft/gpl.html */ package jreepad; import java.util.Enumeration; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.MutableTreeNode; import javax.swing.tree.TreeNode; /** * Soft link tree node. Points to another node in the tree. * * @version $Id$ */ public class SoftLinkNode extends JreepadNode { private JreepadNode target; public SoftLinkNode(SoftLinkNode target) { super((JreepadArticle)null); this.target = target; } public void add(MutableTreeNode child) { target.add(child); } public JreepadNode removeChild(int child) // Can be used to delete, OR to 'get' one for moving { return target.removeChild(child); } public TreeNode getChildAt(int child) { return target.getChildAt(child); } public int getChildCount() { return target.getChildCount(); } public void moveChildUp(int child) { target.moveChildUp(child); } public void moveChildDown(int child) { target.moveChildDown(child); } public JreepadNode addChild() { return target.addChild(); } public JreepadNode addChild(int index) { return target.addChild(index); } public int getIndex(TreeNode child) { return target.getIndex(child); } public boolean isNodeDescendant(DefaultMutableTreeNode n) { return target.isNodeDescendant(n); } public void sortChildren() { target.sortChildren(); } public void sortChildrenRecursive() { target.sortChildrenRecursive(); } public Enumeration children() { return target.children(); } // MutableTreeNode functions public void remove(int child) { target.remove(child); } public void remove(MutableTreeNode node) { target.remove(node); } public void insert(MutableTreeNode child, int index) { target.insert(child, index); } public JreepadNode getSoftLinkTarget() { return target; } } Index: JreepadNode.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadNode.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** JreepadNode.java 26 Jan 2007 21:47:55 -0000 1.25 --- JreepadNode.java 26 Jan 2007 22:38:37 -0000 1.26 *************** *** 23,34 **** import java.io.IOException; import java.io.InputStreamReader; - import java.util.Enumeration; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.MutableTreeNode; ! import javax.swing.tree.TreeNode; /** ! * The tree node. Contains an article or is a soft link to another node. * * @version $Id$ --- 23,33 ---- import java.io.IOException; import java.io.InputStreamReader; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.MutableTreeNode; ! /** ! * The tree node. Contains an article. * * @version $Id$ *************** *** 38,43 **** implements Comparable { - private JreepadNode softLinkTarget = null; - public JreepadNode() { --- 37,40 ---- *************** *** 62,85 **** public JreepadArticle getArticle() { - if (isSoftLink()) - return softLinkTarget.getArticle(); return (JreepadArticle)getUserObject(); } - public JreepadNode(JreepadNode softLinkTarget) - { - this.softLinkTarget = softLinkTarget; - } - - public String toString() - { - return getTitle(); - } - - public boolean isSoftLink() - { - return softLinkTarget != null; - } - public String toFullString() { --- 59,65 ---- *************** *** 155,171 **** } - public void add(JreepadNode child) - { - if (isSoftLink()) - softLinkTarget.add(child); - else - super.add(child); - } - public JreepadNode removeChild(int child) // Can be used to delete, OR to 'get' one for moving { - if (isSoftLink()) - return softLinkTarget.removeChild(child); - JreepadNode ret = (JreepadNode)getChildAt(child); remove(child); --- 135,140 ---- *************** *** 173,190 **** } - public TreeNode getChildAt(int child) - { - if (isSoftLink()) - return softLinkTarget.getChildAt(child); - return super.getChildAt(child); - } - - public int getChildCount() - { - if (isSoftLink()) - return softLinkTarget.getChildCount(); - return super.getChildCount(); - } - public boolean indent() { --- 142,145 ---- *************** *** 226,234 **** public void moveChildUp(int child) { - if (isSoftLink()) - { - softLinkTarget.moveChildUp(child); - return; - } if (child < 1 || child >= getChildCount()) return; --- 181,184 ---- *************** *** 239,247 **** public void moveChildDown(int child) { - if (isSoftLink()) - { - softLinkTarget.moveChildDown(child); - return; - } if (child < 0 || child >= getChildCount() - 1) return; --- 189,192 ---- *************** *** 278,284 **** public JreepadNode addChild() { - if (isSoftLink()) - return softLinkTarget.addChild(); - JreepadNode theChild = new JreepadNode(); add(theChild); --- 223,226 ---- *************** *** 288,294 **** public JreepadNode addChild(int index) { - if (isSoftLink()) - return softLinkTarget.addChild(index); - JreepadNode theChild = new JreepadNode(); insert(theChild, index); --- 230,233 ---- *************** *** 296,306 **** } - public int getIndex(TreeNode child) - { - if (isSoftLink()) - return softLinkTarget.getIndex(child); - return super.getIndex(child); - } - public int getIndex() { --- 235,238 ---- *************** *** 310,336 **** } - public boolean isNodeInSubtree(JreepadNode n) - { - if (isSoftLink()) - return softLinkTarget.isNodeInSubtree(n); - return isNodeDescendant(n); - } - - public void sortChildren() - { - if (isSoftLink()) - softLinkTarget.sortChildren(); - else - sort(); - } - public void sortChildrenRecursive() { ! if (isSoftLink()) ! { ! softLinkTarget.sortChildrenRecursive(); ! return; ! } ! sort(); for (int i = 0; i < getChildCount(); i++) ((JreepadNode)getChildAt(i)).sortChildrenRecursive(); --- 242,248 ---- } public void sortChildrenRecursive() { ! sortChildren(); for (int i = 0; i < getChildCount(); i++) ((JreepadNode)getChildAt(i)).sortChildrenRecursive(); *************** *** 338,342 **** // Function for using Java's built-in mergesort ! private void sort() { Object[] childrenArray = children.toArray(); --- 250,254 ---- // Function for using Java's built-in mergesort ! public void sortChildren() { Object[] childrenArray = children.toArray(); *************** *** 379,389 **** } - public Enumeration children() - { - if (isSoftLink()) - return softLinkTarget.children(); - return super.children(); - } - public JreepadNode getParentNode() { --- 291,294 ---- *************** *** 391,427 **** } - // MutableTreeNode functions - public void remove(int child) - { - if (isSoftLink()) - softLinkTarget.remove(child); - else - super.remove(child); - } - - public void remove(MutableTreeNode node) - { - if (isSoftLink()) - softLinkTarget.remove(node); - else - super.remove(node); - } - - public void insert(MutableTreeNode child, int index) - { - if (isSoftLink()) - softLinkTarget.insert(child, index); - else - super.insert(child, index); - } - public void addChildFromTextFile(InputStreamReader textFile, String nodeName) throws IOException { - if (isSoftLink()) - { - softLinkTarget.addChildFromTextFile(textFile, nodeName); - return; - } // Load the content as a string StringBuffer contentString = new StringBuffer(); --- 296,302 ---- *************** *** 447,453 **** public JreepadNode getChildByTitle(String title) { - if (isSoftLink()) - return softLinkTarget.getChildByTitle(title); - for (int i = 0; i < getChildCount(); i++) if (((JreepadNode)getChildAt(i)).getTitle().equals(title)) --- 322,325 ---- *************** *** 456,464 **** } - public JreepadNode getSoftLinkTarget() - { - return softLinkTarget; - } - public String getTitle() { --- 328,331 ---- |