jreepad-cvs Mailing List for Jreepad - Java Treepad Editor (Page 3)
Brought to you by:
danstowell
You can subscribe to this list here.
2007 |
Jan
(33) |
Feb
(19) |
Mar
(14) |
Apr
(10) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(5) |
Oct
|
Nov
|
Dec
|
---|
From: PeWu <pe...@us...> - 2007-01-26 22:49:11
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv23249/src/jreepad Modified Files: JreepadNode.java SoftLinkNode.java Log Message: code cleanup: removed unneeded code - insert() and add() call parent.remove() before adding node Index: SoftLinkNode.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/SoftLinkNode.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SoftLinkNode.java 26 Jan 2007 22:38:37 -0000 1.1 --- SoftLinkNode.java 26 Jan 2007 22:49:04 -0000 1.2 *************** *** 62,75 **** } - public void moveChildUp(int child) - { - target.moveChildUp(child); - } - - public void moveChildDown(int child) - { - target.moveChildDown(child); - } - public JreepadNode addChild() { --- 62,65 ---- Index: JreepadNode.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadNode.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** JreepadNode.java 26 Jan 2007 22:38:37 -0000 1.26 --- JreepadNode.java 26 Jan 2007 22:49:04 -0000 1.27 *************** *** 151,155 **** MutableTreeNode oldParent = (MutableTreeNode)getParent(); DefaultMutableTreeNode newParent = (DefaultMutableTreeNode)oldParent.getChildAt(pos - 1); - removeFromParent(); newParent.add(this); return true; --- 151,154 ---- *************** *** 179,198 **** } - public void moveChildUp(int child) - { - if (child < 1 || child >= getChildCount()) - return; - - insert(removeChild(child), child - 1); - } - - public void moveChildDown(int child) - { - if (child < 0 || child >= getChildCount() - 1) - return; - - insert(removeChild(child), child + 1); - } - public void moveUp() { --- 178,181 ---- *************** *** 204,208 **** return; - removeFromParent(); parent.insert(this, index - 1); } --- 187,190 ---- *************** *** 217,221 **** return; - removeFromParent(); parent.insert(this, index + 1); } --- 199,202 ---- |
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 ---- |
From: PeWu <pe...@us...> - 2007-01-26 21:48:04
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv26820/src/jreepad Modified Files: JreepadViewer.java JreepadView.java JreepadNode.java find.java Added Files: JreepadArticle.java Log Message: refactoring: refactored JreepadArticle from JreepadNode. JreepadNode is the tree node and contains an article. JreepadArticle is the article with no connection to the tree. Index: JreepadView.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadView.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** JreepadView.java 16 Jan 2007 23:56:03 -0000 1.34 --- JreepadView.java 26 Jan 2007 21:47:55 -0000 1.35 *************** *** 247,251 **** if(!copyEditorPaneContentToNodeContent) return; // i.e. we are deactivated while changing from node to node ! if(currentNode.getArticleMode() != JreepadNode.ARTICLEMODE_ORDINARY) return; // i.e. we are only relevant when in plain-text mode --- 247,251 ---- if(!copyEditorPaneContentToNodeContent) return; // i.e. we are deactivated while changing from node to node ! if(currentNode.getArticle().getArticleMode() != JreepadArticle.ARTICLEMODE_ORDINARY) return; // i.e. we are only relevant when in plain-text mode *************** *** 253,257 **** { // System.out.println("UPDATE - I'd now overwrite node content with editorpane content"); ! currentNode.setContent(editorPanePlainText.getText()); setWarnAboutUnsaved(true); } --- 253,257 ---- { // System.out.println("UPDATE - I'd now overwrite node content with editorpane content"); ! currentNode.getArticle().setContent(editorPanePlainText.getText()); setWarnAboutUnsaved(true); } *************** *** 383,388 **** { // Only update the node's stored content if it's a plaintext node ! if(currentNode.getArticleMode() == JreepadNode.ARTICLEMODE_ORDINARY) ! currentNode.setContent(getEditorPaneText()); return; } --- 383,388 ---- { // Only update the node's stored content if it's a plaintext node ! if(currentNode.getArticle().getArticleMode() == JreepadArticle.ARTICLEMODE_ORDINARY) ! currentNode.getArticle().setContent(getEditorPaneText()); return; } *************** *** 392,400 **** { // Only update the node's stored content if it's a plaintext node ! if(currentNode.getArticleMode() == JreepadNode.ARTICLEMODE_ORDINARY) ! currentNode.setContent(getEditorPaneText()); } currentNode = n; ! setEditorPaneText(n.getContent()); // editorPanePlainText.setText(n.getContent()); // editorPaneHtml.setText(n.getContent()); --- 392,400 ---- { // Only update the node's stored content if it's a plaintext node ! if(currentNode.getArticle().getArticleMode() == JreepadArticle.ARTICLEMODE_ORDINARY) ! currentNode.getArticle().setContent(getEditorPaneText()); } currentNode = n; ! setEditorPaneText(n.getArticle()); // editorPanePlainText.setText(n.getContent()); // editorPaneHtml.setText(n.getContent()); *************** *** 540,544 **** public void insertDate() { ! if(currentNode.getArticleMode() != JreepadNode.ARTICLEMODE_ORDINARY) return; // May want to fix this later - allow other modes to have the date inserted... --- 540,544 ---- public void insertDate() { ! if(currentNode.getArticle().getArticleMode() != JreepadArticle.ARTICLEMODE_ORDINARY) return; // May want to fix this later - allow other modes to have the date inserted... *************** *** 576,580 **** JreepadNode parent = currentNode.getParentNode(); JreepadNode ret = parent.addChild(index); ! ret.setContent(getContentForNewNode()); treeModel.nodesWereInserted(parent, new int[]{index}); TreePath newPath = (parentPath.pathByAddingChild(ret)); --- 576,580 ---- JreepadNode parent = currentNode.getParentNode(); JreepadNode ret = parent.addChild(index); ! ret.getArticle().setContent(getContentForNewNode()); treeModel.nodesWereInserted(parent, new int[]{index}); TreePath newPath = (parentPath.pathByAddingChild(ret)); *************** *** 598,602 **** JreepadNode parent = currentNode.getParentNode(); JreepadNode ret = parent.addChild(index+1); ! ret.setContent(getContentForNewNode()); treeModel.nodesWereInserted(parent, new int[]{index+1}); tree.startEditingAtPath(parentPath.pathByAddingChild(ret)); --- 598,602 ---- JreepadNode parent = currentNode.getParentNode(); JreepadNode ret = parent.addChild(index+1); ! ret.getArticle().setContent(getContentForNewNode()); treeModel.nodesWereInserted(parent, new int[]{index+1}); tree.startEditingAtPath(parentPath.pathByAddingChild(ret)); *************** *** 607,611 **** //DEL storeForUndo(); JreepadNode ret = currentNode.addChild(); ! ret.setContent(getContentForNewNode()); TreePath nodePath = tree.getSelectionPath(); treeModel.nodesWereInserted(currentNode, new int[]{currentNode.getIndex(ret)}); --- 607,611 ---- //DEL storeForUndo(); JreepadNode ret = currentNode.addChild(); ! ret.getArticle().setContent(getContentForNewNode()); TreePath nodePath = tree.getSelectionPath(); treeModel.nodesWereInserted(currentNode, new int[]{currentNode.getIndex(ret)}); *************** *** 733,739 **** public String getSelectedTextInArticle() { ! switch(currentNode.getArticleMode()) { ! case JreepadNode.ARTICLEMODE_CSV: int x = editorPaneCsv.getSelectedColumn(); int y = editorPaneCsv.getSelectedRow(); --- 733,739 ---- public String getSelectedTextInArticle() { ! switch(currentNode.getArticle().getArticleMode()) { ! case JreepadArticle.ARTICLEMODE_CSV: int x = editorPaneCsv.getSelectedColumn(); int y = editorPaneCsv.getSelectedRow(); *************** *** 741,747 **** return ""; return editorPaneCsv.getValueAt(y,x).toString(); ! case JreepadNode.ARTICLEMODE_HTML: return editorPaneHtml.getSelectedText(); ! case JreepadNode.ARTICLEMODE_ORDINARY: default: return editorPanePlainText.getSelectedText(); --- 741,747 ---- return ""; return editorPaneCsv.getValueAt(y,x).toString(); ! case JreepadArticle.ARTICLEMODE_HTML: return editorPaneHtml.getSelectedText(); ! case JreepadArticle.ARTICLEMODE_ORDINARY: default: return editorPanePlainText.getSelectedText(); *************** *** 817,821 **** url = currentNode.getTitle(); ! if((url == null) && (currentNode.getArticleMode()==JreepadNode.ARTICLEMODE_ORDINARY)) { try --- 817,821 ---- url = currentNode.getTitle(); ! if((url == null) && (currentNode.getArticle().getArticleMode()==JreepadArticle.ARTICLEMODE_ORDINARY)) { try *************** *** 858,862 **** { String url = getSelectedTextInArticle(); ! if((url == null) && (currentNode.getArticleMode()==JreepadNode.ARTICLEMODE_ORDINARY)) { try --- 858,862 ---- { String url = getSelectedTextInArticle(); ! if((url == null) && (currentNode.getArticle().getArticleMode()==JreepadArticle.ARTICLEMODE_ORDINARY)) { try *************** *** 1154,1158 **** { //DEL storeForUndo(); ! currentNode.wrapContentToCharWidth(charWidth); editorPanePlainText.setText(currentNode.getContent()); editorPaneHtml.setText(currentNode.getContent()); --- 1154,1158 ---- { //DEL storeForUndo(); ! currentNode.getArticle().wrapContentToCharWidth(charWidth); editorPanePlainText.setText(currentNode.getContent()); editorPaneHtml.setText(currentNode.getContent()); *************** *** 1162,1166 **** { //DEL storeForUndo(); ! currentNode.stripAllTags(); editorPanePlainText.setText(currentNode.getContent()); editorPaneHtml.setText(currentNode.getContent()); --- 1162,1166 ---- { //DEL storeForUndo(); ! currentNode.getArticle().stripAllTags(); editorPanePlainText.setText(currentNode.getContent()); editorPaneHtml.setText(currentNode.getContent()); *************** *** 1176,1180 **** copyEditorPaneContentToNodeContent = false; // Disables store-for-undo ! currentNode.setContent(editorPanePlainText.getText()); /* switch(currentNode.getArticleMode()) --- 1176,1180 ---- copyEditorPaneContentToNodeContent = false; // Disables store-for-undo ! currentNode.getArticle().setContent(editorPanePlainText.getText()); /* switch(currentNode.getArticleMode()) *************** *** 1195,1206 **** switch(newMode) { ! case JreepadNode.ARTICLEMODE_ORDINARY: // DELETEME - PLAINTEXT SHOULD NOT BE AFFECTED BY OTHERS editorPanePlainText.setText(currentNode.getContent()); break; ! case JreepadNode.ARTICLEMODE_HTML: editorPaneHtml.setText(currentNode.getContent()); break; ! case JreepadNode.ARTICLEMODE_TEXTILEHTML: try{ editorPaneHtml.setText(JTextile.textile(currentNode.getContent())); --- 1195,1206 ---- switch(newMode) { ! case JreepadArticle.ARTICLEMODE_ORDINARY: // DELETEME - PLAINTEXT SHOULD NOT BE AFFECTED BY OTHERS editorPanePlainText.setText(currentNode.getContent()); break; ! case JreepadArticle.ARTICLEMODE_HTML: editorPaneHtml.setText(currentNode.getContent()); break; ! case JreepadArticle.ARTICLEMODE_TEXTILEHTML: try{ editorPaneHtml.setText(JTextile.textile(currentNode.getContent())); *************** *** 1209,1219 **** } break; ! case JreepadNode.ARTICLEMODE_CSV: ! articleToJTable(currentNode.getContent()); break; default: return; } ! currentNode.setArticleMode(newMode); ensureCorrectArticleRenderMode(); getEditorPaneComponent().repaint(); --- 1209,1219 ---- } break; ! case JreepadArticle.ARTICLEMODE_CSV: ! articleToJTable(currentNode.getArticle()); break; default: return; } ! currentNode.getArticle().setArticleMode(newMode); ensureCorrectArticleRenderMode(); getEditorPaneComponent().repaint(); *************** *** 1228,1232 **** public void articleToJTable() { ! String[][] rowData = currentNode.interpretContentAsCsv(); String[] columnNames = null; --- 1228,1232 ---- public void articleToJTable() { ! String[][] rowData = currentNode.getArticle().interpretContentAsCsv(); String[] columnNames = null; *************** *** 1234,1240 **** initJTable(rowData, columnNames); } ! public void articleToJTable(String s) { ! String[][] rowData = JreepadNode.interpretContentAsCsv(s); String[] columnNames = new String[rowData[0].length]; for(int i=0; i<columnNames.length; i++) --- 1234,1240 ---- initJTable(rowData, columnNames); } ! public void articleToJTable(JreepadArticle a) { ! String[][] rowData = a.interpretContentAsCsv(); String[] columnNames = new String[rowData[0].length]; for(int i=0; i<columnNames.length; i++) *************** *** 1266,1277 **** return editorPanePlainText; // This is a bit of a hack - it shouldn't really even be called to act on null ! switch(currentNode.getArticleMode()) { ! case JreepadNode.ARTICLEMODE_ORDINARY: return editorPanePlainText; ! case JreepadNode.ARTICLEMODE_HTML: ! case JreepadNode.ARTICLEMODE_TEXTILEHTML: return editorPaneHtml; ! case JreepadNode.ARTICLEMODE_CSV: return editorPaneCsv; default: --- 1266,1277 ---- return editorPanePlainText; // This is a bit of a hack - it shouldn't really even be called to act on null ! switch(currentNode.getArticle().getArticleMode()) { ! case JreepadArticle.ARTICLEMODE_ORDINARY: return editorPanePlainText; ! case JreepadArticle.ARTICLEMODE_HTML: ! case JreepadArticle.ARTICLEMODE_TEXTILEHTML: return editorPaneHtml; ! case JreepadArticle.ARTICLEMODE_CSV: return editorPaneCsv; default: *************** *** 1282,1294 **** String getEditorPaneText() { ! switch(currentNode.getArticleMode()) { ! case JreepadNode.ARTICLEMODE_ORDINARY: return editorPanePlainText.getText(); ! case JreepadNode.ARTICLEMODE_HTML: return editorPaneHtml.getText(); ! case JreepadNode.ARTICLEMODE_TEXTILEHTML: return editorPaneHtml.getText(); ! case JreepadNode.ARTICLEMODE_CSV: return jTableContentToCsv(); default: --- 1282,1294 ---- String getEditorPaneText() { ! switch(currentNode.getArticle().getArticleMode()) { ! case JreepadArticle.ARTICLEMODE_ORDINARY: return editorPanePlainText.getText(); ! case JreepadArticle.ARTICLEMODE_HTML: return editorPaneHtml.getText(); ! case JreepadArticle.ARTICLEMODE_TEXTILEHTML: return editorPaneHtml.getText(); ! case JreepadArticle.ARTICLEMODE_CSV: return jTableContentToCsv(); default: *************** *** 1297,1302 **** } } ! void setEditorPaneText(String s) { try{ editorPanePlainText.setText(s); --- 1297,1303 ---- } } ! void setEditorPaneText(JreepadArticle a) { + String s = a.getContent(); try{ editorPanePlainText.setText(s); *************** *** 1307,1318 **** ex.printStackTrace(); } ! switch(currentNode.getArticleMode()) { ! case JreepadNode.ARTICLEMODE_ORDINARY: break; ! case JreepadNode.ARTICLEMODE_HTML: editorPaneHtml.setText(s); break; ! case JreepadNode.ARTICLEMODE_TEXTILEHTML: try{ editorPaneHtml.setText(JTextile.textile(s)); --- 1308,1319 ---- ex.printStackTrace(); } ! switch(currentNode.getArticle().getArticleMode()) { ! case JreepadArticle.ARTICLEMODE_ORDINARY: break; ! case JreepadArticle.ARTICLEMODE_HTML: editorPaneHtml.setText(s); break; ! case JreepadArticle.ARTICLEMODE_TEXTILEHTML: try{ editorPaneHtml.setText(JTextile.textile(s)); *************** *** 1321,1326 **** } break; ! case JreepadNode.ARTICLEMODE_CSV: ! articleToJTable(s); break; default: --- 1322,1327 ---- } break; ! case JreepadArticle.ARTICLEMODE_CSV: ! articleToJTable(a); break; default: *************** *** 1374,1379 **** { // System.out.println(" -- tableChanged() -- "); ! if(currentNode.getArticleMode() == JreepadNode.ARTICLEMODE_CSV) ! currentNode.setContent(jTableContentToCsv()); } --- 1375,1380 ---- { // System.out.println(" -- tableChanged() -- "); ! if(currentNode.getArticle().getArticleMode() == JreepadArticle.ARTICLEMODE_CSV) ! currentNode.getArticle().setContent(jTableContentToCsv()); } *************** *** 1466,1470 **** //System.out.println(" Node undoMgr: " + getCurrentNode().undoMgr); //Thread.currentThread().dumpStack(); ! getCurrentNode().undoMgr.addEdit(e.getEdit()); } --- 1467,1471 ---- //System.out.println(" Node undoMgr: " + getCurrentNode().undoMgr); //Thread.currentThread().dumpStack(); ! getCurrentNode().getArticle().getUndoMgr().addEdit(e.getEdit()); } Index: find.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/find.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** find.java 20 Jan 2007 13:01:19 -0000 1.6 --- find.java 26 Jan 2007 21:47:55 -0000 1.7 *************** *** 293,297 **** { JreepadNode n = res.getNode(); ! return "-- " + n.getTitle() + " --\n" + n.getContent(); } private static String formatResultBrieferText(JreepadSearcher.JreepadSearchResult res) --- 293,297 ---- { JreepadNode n = res.getNode(); ! return "-- " + n.getArticle().getTitle() + " --\n" + n.getArticle().getContent(); } private static String formatResultBrieferText(JreepadSearcher.JreepadSearchResult res) Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** JreepadViewer.java 22 Jan 2007 23:00:36 -0000 1.47 --- JreepadViewer.java 26 Jan 2007 21:47:55 -0000 1.48 *************** *** 631,635 **** articleViewModeTextMenuItem = new JMenuItem(lang.getString("MENUITEM_ARTICLEFORMAT_TEXT")); //"Text"); articleViewModeTextMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { ! theJreepad.setArticleMode(JreepadNode.ARTICLEMODE_ORDINARY); updateUndoRedoMenuState(); }}); --- 631,635 ---- articleViewModeTextMenuItem = new JMenuItem(lang.getString("MENUITEM_ARTICLEFORMAT_TEXT")); //"Text"); articleViewModeTextMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { ! theJreepad.setArticleMode(JreepadArticle.ARTICLEMODE_ORDINARY); updateUndoRedoMenuState(); }}); *************** *** 637,641 **** articleViewModeHtmlMenuItem = new JMenuItem(lang.getString("MENUITEM_ARTICLEFORMAT_HTML")); //"HTML"); articleViewModeHtmlMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { ! theJreepad.setArticleMode(JreepadNode.ARTICLEMODE_HTML); updateUndoRedoMenuState(); }}); --- 637,641 ---- articleViewModeHtmlMenuItem = new JMenuItem(lang.getString("MENUITEM_ARTICLEFORMAT_HTML")); //"HTML"); articleViewModeHtmlMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { ! theJreepad.setArticleMode(JreepadArticle.ARTICLEMODE_HTML); updateUndoRedoMenuState(); }}); *************** *** 643,647 **** articleViewModeCsvMenuItem = new JMenuItem(lang.getString("MENUITEM_ARTICLEFORMAT_CSV")); //"Table (comma-separated data)"); articleViewModeCsvMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { ! theJreepad.setArticleMode(JreepadNode.ARTICLEMODE_CSV); updateUndoRedoMenuState(); }}); --- 643,647 ---- articleViewModeCsvMenuItem = new JMenuItem(lang.getString("MENUITEM_ARTICLEFORMAT_CSV")); //"Table (comma-separated data)"); articleViewModeCsvMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { ! theJreepad.setArticleMode(JreepadArticle.ARTICLEMODE_CSV); updateUndoRedoMenuState(); }}); *************** *** 649,653 **** articleViewModeTextileMenuItem = new JMenuItem(lang.getString("MENUITEM_ARTICLEFORMAT_TEXTILE")); articleViewModeTextileMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { ! theJreepad.setArticleMode(JreepadNode.ARTICLEMODE_TEXTILEHTML); updateUndoRedoMenuState(); }}); --- 649,653 ---- articleViewModeTextileMenuItem = new JMenuItem(lang.getString("MENUITEM_ARTICLEFORMAT_TEXTILE")); articleViewModeTextileMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { ! theJreepad.setArticleMode(JreepadArticle.ARTICLEMODE_TEXTILEHTML); updateUndoRedoMenuState(); }}); *************** *** 1380,1384 **** // hBox.add(Box.createGlue()); hBox.add(new JLabel(lang.getString("PREFS_HTML_TREATTEXTAS"), SwingConstants.LEFT)); ! htmlExportModeSelector = new JComboBox(JreepadNode.getHtmlExportArticleTypes()); htmlExportModeSelector.setAlignmentX(Component.LEFT_ALIGNMENT); htmlExportModeSelector.setSelectedIndex(getPrefs().htmlExportArticleType); --- 1380,1384 ---- // hBox.add(Box.createGlue()); hBox.add(new JLabel(lang.getString("PREFS_HTML_TREATTEXTAS"), SwingConstants.LEFT)); ! htmlExportModeSelector = new JComboBox(JreepadArticle.getHtmlExportArticleTypes()); htmlExportModeSelector.setAlignmentX(Component.LEFT_ALIGNMENT); htmlExportModeSelector.setSelectedIndex(getPrefs().htmlExportArticleType); *************** *** 1406,1410 **** // hBox.add(Box.createGlue()); hBox.add(new JLabel(lang.getString("PREFS_HTML_INTERNALLINKS"), SwingConstants.LEFT)); ! htmlExportAnchorTypeSelector = new JComboBox(JreepadNode.getHtmlExportAnchorLinkTypes()); htmlExportAnchorTypeSelector.setSelectedIndex(getPrefs().htmlExportAnchorLinkType); htmlExportAnchorTypeSelector.setAlignmentX(Component.LEFT_ALIGNMENT); --- 1406,1410 ---- // hBox.add(Box.createGlue()); hBox.add(new JLabel(lang.getString("PREFS_HTML_INTERNALLINKS"), SwingConstants.LEFT)); ! htmlExportAnchorTypeSelector = new JComboBox(JreepadArticle.getHtmlExportAnchorLinkTypes()); htmlExportAnchorTypeSelector.setSelectedIndex(getPrefs().htmlExportAnchorLinkType); htmlExportAnchorTypeSelector.setAlignmentX(Component.LEFT_ALIGNMENT); *************** *** 1970,1974 **** setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); ! String output = theJreepad.getCurrentNode().exportSingleArticleAsHtml( getPrefs().htmlExportArticleType, getPrefs().htmlExportUrlsToLinks, getPrefs().htmlExportAnchorLinkType, true); --- 1970,1974 ---- setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); ! String output = theJreepad.getCurrentNode().getArticle().exportAsHtml( getPrefs().htmlExportArticleType, getPrefs().htmlExportUrlsToLinks, getPrefs().htmlExportAnchorLinkType, true); *************** *** 2114,2118 **** JOptionPane.showMessageDialog(this, lang.getString("MSG_NOTHING_TO_UNDO"), "No change" , JOptionPane.INFORMATION_MESSAGE); */ ! UndoManager undoMgr = theJreepad.getCurrentNode().undoMgr; String undoStyle = undoMgr.getUndoPresentationName(); try{ --- 2114,2118 ---- JOptionPane.showMessageDialog(this, lang.getString("MSG_NOTHING_TO_UNDO"), "No change" , JOptionPane.INFORMATION_MESSAGE); */ ! UndoManager undoMgr = theJreepad.getCurrentNode().getArticle().getUndoMgr(); String undoStyle = undoMgr.getUndoPresentationName(); try{ *************** *** 2129,2133 **** } private void redoAction(){ ! UndoManager undoMgr = theJreepad.getCurrentNode().undoMgr; String redoStyle = undoMgr.getRedoPresentationName(); try{ --- 2129,2133 ---- } private void redoAction(){ ! UndoManager undoMgr = theJreepad.getCurrentNode().getArticle().getUndoMgr(); String redoStyle = undoMgr.getRedoPresentationName(); try{ *************** *** 2150,2154 **** return false; ! if(theJreepad.getCurrentNode().getArticleMode() != JreepadNode.ARTICLEMODE_ORDINARY) return false; --- 2150,2154 ---- return false; ! if(theJreepad.getCurrentNode().getArticle().getArticleMode() != JreepadArticle.ARTICLEMODE_ORDINARY) return false; *************** *** 2163,2170 **** return false; ! if(theJreepad.getCurrentNode().getArticleMode() != JreepadNode.ARTICLEMODE_ORDINARY) return false; ! if(!theJreepad.getCurrentNode().undoMgr.canRedo()) return false; --- 2163,2170 ---- return false; ! if(theJreepad.getCurrentNode().getArticle().getArticleMode() != JreepadArticle.ARTICLEMODE_ORDINARY) return false; ! if(!theJreepad.getCurrentNode().getArticle().getUndoMgr().canRedo()) return false; --- NEW FILE: JreepadArticle.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.text.CharacterIterator; import java.text.StringCharacterIterator; import javax.swing.undo.UndoManager; import org.philwilson.JTextile; /** * Class representing a single article without its tree context. * * @version $Id$ */ public class JreepadArticle { public static final int ARTICLEMODE_ORDINARY = 1; public static final int ARTICLEMODE_HTML = 2; public static final int ARTICLEMODE_CSV = 3; public static final int ARTICLEMODE_TEXTILEHTML = 4; public static final int CSVPARSE_MODE_INQUOTES = 1; public static final int CSVPARSE_MODE_EXPECTINGDELIMITER = 2; public static final int CSVPARSE_MODE_EXPECTINGDATA = 3; public static final int EXPORT_HTML_NORMAL = 0; public static final int EXPORT_HTML_PREFORMATTED = 1; public static final int EXPORT_HTML_HTML = 2; public static final int EXPORT_HTML_TEXTILEHTML = 3; public static final int EXPORT_HTML_ANCHORS_PATH = 0; public static final int EXPORT_HTML_ANCHORS_WIKI = 1; private String title; private String content; private int articleMode; private UndoManager undoMgr; public JreepadArticle() { this(""); } public JreepadArticle(String content) { this("", content); } public JreepadArticle(String title, String content) { this(title, content, ARTICLEMODE_ORDINARY); } public JreepadArticle(String title, String content, int articleMode) { this.title = title; this.content = content; this.articleMode = articleMode; undoMgr = new UndoManager(); } public int getArticleMode() { return articleMode; } public void setArticleMode(int articleMode) { this.articleMode = articleMode; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public UndoManager getUndoMgr() { return undoMgr; } public String toString() { return title; } public static final String[] getHtmlExportArticleTypes() { return new String[] { JreepadViewer.lang.getString("PREFS_EXPORTTYPE_TEXT"), JreepadViewer.lang.getString("PREFS_EXPORTTYPE_PREFORMATTED"), JreepadViewer.lang.getString("PREFS_EXPORTTYPE_HTML"), JreepadViewer.lang.getString("PREFS_EXPORTTYPE_TEXTILEHTML") }; } public static final String[] getHtmlExportAnchorLinkTypes() { return new String[] { "node:// links", "WikiLike links" }; } public String exportAsHtml(int exportMode, boolean urlsToLinks, int anchorType, boolean causeToPrint) { StringBuffer ret = new StringBuffer(); ret.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n<head>\n<title>"); ret.append(htmlSpecialChars(getTitle())); ret.append("</title>\n<style type=\"text/css\">\n" + "dl {}\ndl dt { font-weight: bold; margin-top: 10px; font-size: 24pt; }\ndl dd {margin-left: 20px; padding-left: 0px;}\ndl dd dl dt {background: black; color: white; font-size: 12pt; }\ndl dd dl dd dl dt {background: white; color: black; }" + "\n</style>\n</head>\n\n<body" + (causeToPrint ? " onload='print();'" : "") + ">\n<!-- Exported from Jreepad -->\n<dl>"); ret.append(toHtml(exportMode, urlsToLinks, anchorType)); ret.append("\n</dl>\n</body>\n</html>"); return ret.toString(); } public String toHtml(int exportMode, boolean urlsToLinks, int anchorType) { switch (articleMode) { case ARTICLEMODE_HTML: return getContent(); case ARTICLEMODE_TEXTILEHTML: try { return JTextile.textile(getContent()); } catch (Exception e) { return getContent(); } case ARTICLEMODE_CSV: String[][] csv = interpretContentAsCsv(); StringBuffer csvHtml = new StringBuffer( "\n <table border='1' cellspacing='0' cellpadding='2'>"); for (int i = 0; i < csv.length; i++) { csvHtml.append("\n <tr>"); for (int j = 0; j < csv[0].length; j++) csvHtml.append("\n <td>" + htmlSpecialChars(csv[i][j]) + "</td>"); csvHtml.append("\n </tr>"); } csvHtml.append("\n </table>"); return csvHtml.toString(); case ARTICLEMODE_ORDINARY: default: switch (exportMode) { case EXPORT_HTML_PREFORMATTED: return "<pre>" + (urlsToLinks ? urlsToHtmlLinksAndHtmlSpecialChars(getContent(), anchorType) : htmlSpecialChars(getContent())) + "</pre>"; case EXPORT_HTML_HTML: return getContent(); case EXPORT_HTML_TEXTILEHTML: try { return JTextile.textile(getContent()); } catch (Exception e) { return getContent(); } case EXPORT_HTML_NORMAL: default: return (urlsToLinks ? urlsToHtmlLinksAndHtmlSpecialChars(getContent(), anchorType) : htmlSpecialChars(getContent())); } } } private static String htmlSpecialChars(String in) { char[] c = in.toCharArray(); StringBuffer ret = new StringBuffer(); for (int i = 0; i < c.length; i++) if (c[i] == '<') ret.append("<"); else if (c[i] == '>') ret.append(">"); else if (c[i] == '&') ret.append("&"); else if (c[i] == '\n') ret.append(" <br />\n"); else if (c[i] == '"') ret.append("""); else ret.append(c[i]); return ret.toString(); } // Search through the String, replacing URI-like substrings (containing ://) with HTML links private String urlsToHtmlLinksAndHtmlSpecialChars(String in, int anchorType) { StringCharacterIterator iter = new StringCharacterIterator(in); StringBuffer out = new StringBuffer(""); StringBuffer currentWord = new StringBuffer(""); // "space" characters get stuck straight // back out, but words need aggregating char c = iter.current(), c2; while (true) { if (Character.isWhitespace(c) || c == '"' || c == '\'' || c == '<' || c == '>' || c == '\n' || c == CharacterIterator.DONE) { // // First check whether currentWord is empty...? // if(c!=CharacterIterator.DONE && currentWord.length()==0) // continue; // Check if the current word is a URL - do weird stuff to it if so, else just output // it if (currentWord.toString().indexOf("://") > 0) { // We don't like quotes - let's remove 'em! // Ideally, a beginning quote would signify that we need to keep on searching // until we find an end quote // but that aspect is NOT IMPLEMENTED YET c2 = currentWord.charAt(0); if (c2 == '"' || c2 == '\'') currentWord.deleteCharAt(0); c2 = currentWord.charAt(currentWord.length() - 1); if (c2 == '"' || c2 == '\'') currentWord.deleteCharAt(currentWord.length() - 1); // At this stage, beginning with "node://" should indicate that we want an // anchor link not a "real" HTML link String currentWordString = currentWord.toString(); if (currentWordString.startsWith("node://")) { String anchorLink; if (anchorType == EXPORT_HTML_ANCHORS_WIKI) anchorLink = currentWordString.substring(currentWordString .lastIndexOf('/') + 1); else anchorLink = currentWordString.substring(7); out.append("<a href=\"#" + anchorLink + "\">" + currentWordString + "</a>"); } else out.append("<a href=\"" + currentWord + "\">" + currentWordString + "</a>"); } else if (anchorType == EXPORT_HTML_ANCHORS_WIKI && JreepadView.isWikiWord(currentWord.toString())) { String currentWordString = currentWord.toString(); if (currentWordString.length() > 4 && currentWordString.startsWith("[[") && currentWordString.endsWith("]]")) currentWordString = currentWordString.substring(2, currentWordString .length() - 2); out.append("<a href=\"#" + currentWordString + "\">" + currentWordString + "</a>"); } else out.append(currentWord.toString()); if (c == '<') out.append("<"); else if (c == '>') out.append(">"); else if (c == '\n') out.append(" <br />\n"); else if (c == '"') out.append("""); else if (c == '&') out.append("&"); else if (c != CharacterIterator.DONE) out.append(c); currentWord.setLength(0); if (c == CharacterIterator.DONE) break; } else { currentWord.append(c); // Just aggregate character onto current "Word" } c = iter.next(); } // End "while" return out.toString(); } public synchronized void wrapContentToCharWidth(int charWidth) { if (charWidth < 2) return; StringBuffer ret = new StringBuffer(); StringCharacterIterator iter = new StringCharacterIterator(content); int charsOnThisLine = 0; for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) { if (c == '\n') charsOnThisLine = 0; else if (++charsOnThisLine >= charWidth) { ret.append('\n'); charsOnThisLine = 0; } ret.append(c); } content = ret.toString(); } public synchronized void stripAllTags() { StringBuffer ret = new StringBuffer(); StringCharacterIterator iter = new StringCharacterIterator(content); boolean on = true; for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) { if ((!on) && c == '>') on = true; else if (on && c == '<') on = false; else if (on) ret.append(c); } content = ret.toString(); } public String[][] interpretContentAsCsv() { String theContent = getContent(); int rows = 1; int cols = 1; theContent = theContent.trim(); char c; int curCols = 1; int parseMode = CSVPARSE_MODE_EXPECTINGDATA; StringBuffer curData = new StringBuffer(); // Go through once to determine the number of rows and columns StringCharacterIterator iter = new StringCharacterIterator(theContent); c = iter.current(); while (true) { if (c == CharacterIterator.DONE) { // / System.out.println("I've just parsed this data item: " + curData + " and I'm in // mode " + parseMode); cols = (curCols > cols) ? curCols : cols; break; } if (parseMode == CSVPARSE_MODE_INQUOTES) { if (c == '"') { parseMode = CSVPARSE_MODE_EXPECTINGDELIMITER; } else { curData.append(c); } } else if (parseMode == CSVPARSE_MODE_EXPECTINGDELIMITER || parseMode == CSVPARSE_MODE_EXPECTINGDATA) { if (c == '"') { parseMode = CSVPARSE_MODE_INQUOTES; } else if (c == '\n' || c == Character.LINE_SEPARATOR) { parseMode = CSVPARSE_MODE_EXPECTINGDATA; // / System.out.println("I've just parsed this data item: " + curData + " and // I'm in mode " + parseMode); curData = new StringBuffer(); cols = (curCols > cols) ? curCols : cols; curCols = 1; rows++; } else if (c == ',') { parseMode = CSVPARSE_MODE_EXPECTINGDATA; curCols++; // / System.out.println("I've just parsed this data item: " + curData + " and // I'm in mode " + parseMode); curData = new StringBuffer(); } else { curData.append(c); } } c = iter.next(); } // Now go through and actually assign the content String[][] csv = new String[rows][cols]; for (int i = 0; i < csv.length; i++) java.util.Arrays.fill(csv[i], ""); iter = new StringCharacterIterator(theContent); parseMode = CSVPARSE_MODE_EXPECTINGDATA; curData = new StringBuffer(); int col = 0; int row = 0; c = iter.current(); while (true) { if (c == CharacterIterator.DONE) { csv[row][col] = curData.toString(); break; } if (parseMode == CSVPARSE_MODE_INQUOTES) { if (c == '"') { parseMode = CSVPARSE_MODE_EXPECTINGDELIMITER; } else { curData.append(c); } } else if (parseMode == CSVPARSE_MODE_EXPECTINGDELIMITER || parseMode == CSVPARSE_MODE_EXPECTINGDATA) { if (c == '"') { parseMode = CSVPARSE_MODE_INQUOTES; } else if (c == '\n' || c == Character.LINE_SEPARATOR) { csv[row][col] = curData.toString(); parseMode = CSVPARSE_MODE_EXPECTINGDATA; curData = new StringBuffer(); col = 0; row++; } else if (c == ',') { csv[row][col] = curData.toString(); parseMode = CSVPARSE_MODE_EXPECTINGDATA; col++; curData = new StringBuffer(); } else { curData.append(c); } } c = iter.next(); } return csv; } protected void setContentAsCsv(String[][] in) { StringBuffer o = new StringBuffer(); for (int i = 0; i < in.length; i++) { for (int j = 0; j < in[0].length; j++) { o.append("\"" + in[i][j] + "\""); } o.append("\n"); } setContent(o.toString()); } } Index: JreepadNode.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadNode.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** JreepadNode.java 22 Jan 2007 23:31:03 -0000 1.24 --- JreepadNode.java 26 Jan 2007 21:47:55 -0000 1.25 *************** *** 1,20 **** /* ! 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, [...1363 lines suppressed...] ! return getArticle().getContent(); ! } ! /* ! // Listens for edits that can be undone. ! protected class JreepadNodeUndoableEditListener ! implements UndoableEditListener { ! public void undoableEditHappened(UndoableEditEvent e) { ! //System.out.println("Undoable event is " + (e.getEdit().isSignificant()?"":"NOT ") + "significant"); ! //System.out.println("Undoable event source: " + e.getEdit()); ! //Remember the edit and update the menus. ! undoMgr.addEdit(e.getEdit()); ! //undoAction.updateUndoState(); ! //redoAction.updateRedoState(); ! } ! } ! */ } |
From: PeWu <pe...@us...> - 2007-01-26 21:48:00
|
Update of /cvsroot/jreepad/jreepad/src/jreepad/io In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv26820/src/jreepad/io Modified Files: XmlReader.java TreepadReader.java HtmlWriter.java XmlWriter.java Log Message: refactoring: refactored JreepadArticle from JreepadNode. JreepadNode is the tree node and contains an article. JreepadArticle is the article with no connection to the tree. Index: XmlReader.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/XmlReader.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** XmlReader.java 20 Jan 2007 13:01:19 -0000 1.1 --- XmlReader.java 26 Jan 2007 21:47:55 -0000 1.2 *************** *** 25,28 **** --- 25,29 ---- import java.io.InputStreamReader; + import jreepad.JreepadArticle; import jreepad.JreepadNode; *************** *** 108,120 **** if (typeString.equals("text/csv")) ! node.setArticleMode(JreepadNode.ARTICLEMODE_CSV); else if (typeString.equals("text/html")) ! node.setArticleMode(JreepadNode.ARTICLEMODE_HTML); else if (typeString.equals("text/textile")) ! node.setArticleMode(JreepadNode.ARTICLEMODE_TEXTILEHTML); ! else if (typeString.equals("application/x-jreepad-softlink")) ! node.setArticleMode(JreepadNode.ARTICLEMODE_SOFTLINK); else ! node.setArticleMode(JreepadNode.ARTICLEMODE_ORDINARY); node.setTitle(xmlUnescapeChars(title)); --- 109,121 ---- if (typeString.equals("text/csv")) ! node.getArticle().setArticleMode(JreepadArticle.ARTICLEMODE_CSV); else if (typeString.equals("text/html")) ! node.getArticle().setArticleMode(JreepadArticle.ARTICLEMODE_HTML); else if (typeString.equals("text/textile")) ! node.getArticle().setArticleMode(JreepadArticle.ARTICLEMODE_TEXTILEHTML); ! //else if (typeString.equals("application/x-jreepad-softlink")) ! // node.setArticleMode(JreepadArticle.ARTICLEMODE_SOFTLINK); else ! node.getArticle().setArticleMode(JreepadArticle.ARTICLEMODE_ORDINARY); node.setTitle(xmlUnescapeChars(title)); *************** *** 155,159 **** String returnFromBaby = currentXmlContent.substring(endTagOffset + 7); // System.out.println("\n\nBaby intends to return:"+returnFromBaby); ! node.setContent(content); return new ReturnValue(returnFromBaby, node); } --- 156,160 ---- String returnFromBaby = currentXmlContent.substring(endTagOffset + 7); // System.out.println("\n\nBaby intends to return:"+returnFromBaby); ! node.getArticle().setContent(content); return new ReturnValue(returnFromBaby, node); } *************** *** 163,167 **** { content += xmlUnescapeChars(currentXmlContent.substring(0, startTagOffset)); ! node.setContent(content); } --- 164,168 ---- { content += xmlUnescapeChars(currentXmlContent.substring(0, startTagOffset)); ! node.getArticle().setContent(content); } *************** *** 191,195 **** if (readingContent && (endTagOffset != -1)) content += xmlUnescapeChars(currentXmlContent.substring(0, endTagOffset)); ! node.setContent(content); // System.out.println("THE MAIN WHILE LOOP HAS ENDED. SPARE CONTENT:\n" + // currentXmlContent); --- 192,196 ---- if (readingContent && (endTagOffset != -1)) content += xmlUnescapeChars(currentXmlContent.substring(0, endTagOffset)); ! node.getArticle().setContent(content); // System.out.println("THE MAIN WHILE LOOP HAS ENDED. SPARE CONTENT:\n" + // currentXmlContent); Index: HtmlWriter.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/HtmlWriter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** HtmlWriter.java 22 Jan 2007 23:00:37 -0000 1.1 --- HtmlWriter.java 26 Jan 2007 21:47:56 -0000 1.2 *************** *** 27,30 **** --- 27,31 ---- import java.util.Enumeration; + import jreepad.JreepadArticle; import jreepad.JreepadNode; *************** *** 120,124 **** { writer.write("\n<dt><a name=\""); ! if (anchorType == JreepadNode.EXPORT_HTML_ANCHORS_WIKI) writer.write(node.getTitle()); else --- 121,125 ---- { writer.write("\n<dt><a name=\""); ! if (anchorType == JreepadArticle.EXPORT_HTML_ANCHORS_WIKI) writer.write(node.getTitle()); else *************** *** 130,134 **** // Write out the node's article content - using normal, preformatted, or HTML modes as // appropriate ! writer.write(node.articleToHtml(exportMode, urlsToLinks, anchorType)); if (node.getChildCount() > 0) --- 131,135 ---- // Write out the node's article content - using normal, preformatted, or HTML modes as // appropriate ! writer.write(node.getArticle().toHtml(exportMode, urlsToLinks, anchorType)); if (node.getChildCount() > 0) Index: TreepadReader.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/TreepadReader.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TreepadReader.java 20 Jan 2007 13:01:19 -0000 1.1 --- TreepadReader.java 26 Jan 2007 21:47:56 -0000 1.2 *************** *** 26,29 **** --- 26,30 ---- import java.util.Stack; + import jreepad.JreepadArticle; import jreepad.JreepadNode; *************** *** 101,106 **** String compareContent = newNode.getContent().toLowerCase().trim(); int newArticleMode = (autoDetectHtmlArticles && compareContent.startsWith("<html>") && compareContent ! .endsWith("</html>")) ? JreepadNode.ARTICLEMODE_HTML : JreepadNode.ARTICLEMODE_ORDINARY; ! newNode.setArticleMode(newArticleMode); if (depthLine.equals("0")) --- 102,107 ---- String compareContent = newNode.getContent().toLowerCase().trim(); int newArticleMode = (autoDetectHtmlArticles && compareContent.startsWith("<html>") && compareContent ! .endsWith("</html>")) ? JreepadArticle.ARTICLEMODE_HTML : JreepadArticle.ARTICLEMODE_ORDINARY; ! newNode.getArticle().setArticleMode(newArticleMode); if (depthLine.equals("0")) Index: XmlWriter.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/XmlWriter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** XmlWriter.java 22 Jan 2007 23:16:40 -0000 1.3 --- XmlWriter.java 26 Jan 2007 21:47:56 -0000 1.4 *************** *** 26,29 **** --- 26,30 ---- import java.util.Enumeration; + import jreepad.JreepadArticle; import jreepad.JreepadNode; *************** *** 59,71 **** writer.write("title=\"" + xmlEscapeChars(node.getTitle()) + "\" type=\""); ! switch (node.getArticleMode()) { ! case JreepadNode.ARTICLEMODE_HTML: writer.write("text/html"); break; ! case JreepadNode.ARTICLEMODE_TEXTILEHTML: writer.write("text/textile"); break; ! case JreepadNode.ARTICLEMODE_CSV: writer.write("text/csv"); break; --- 60,72 ---- writer.write("title=\"" + xmlEscapeChars(node.getTitle()) + "\" type=\""); ! switch (node.getArticle().getArticleMode()) { ! case JreepadArticle.ARTICLEMODE_HTML: writer.write("text/html"); break; ! case JreepadArticle.ARTICLEMODE_TEXTILEHTML: writer.write("text/textile"); break; ! case JreepadArticle.ARTICLEMODE_CSV: writer.write("text/csv"); break; |
From: PeWu <pe...@us...> - 2007-01-22 23:31:07
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv3689/src/jreepad Modified Files: JreepadNode.java Log Message: Comparator class is not needed. Comparable.compareTo() is sufficient Index: JreepadNode.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadNode.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** JreepadNode.java 22 Jan 2007 23:00:37 -0000 1.23 --- JreepadNode.java 22 Jan 2007 23:31:03 -0000 1.24 *************** *** 23,30 **** import java.io.IOException; import java.io.InputStreamReader; - import java.io.Serializable; import java.text.CharacterIterator; import java.text.StringCharacterIterator; - import java.util.Comparator; import java.util.Enumeration; --- 23,28 ---- *************** *** 41,45 **** private String content; private JreepadNode softLinkTarget; - private static OurSortComparator ourSortComparator = new OurSortComparator(); //protected transient javax.swing.table.TableColumnModel tblColModel; --- 39,42 ---- *************** *** 496,529 **** { Object[] childrenArray = children.toArray(); ! java.util.Arrays.sort(childrenArray, ourSortComparator); removeAllChildren(); for(int i=0; i<childrenArray.length; i++) add((JreepadNode)childrenArray[i]); } ! private static class OurSortComparator implements Comparator, Serializable ! { ! public int compare(Object o1, Object o2) ! { ! // return ((JreepadNode)o1).getTitle().compareToIgnoreCase( ! // ((JreepadNode)o2).getTitle()); ! return ((JreepadNode)o1).compareTo(o2); ! } ! /* ! public boolean equals(Object obj) ! { ! return obj.equals(this); // Lazy! ! } ! public int hashCode() // Apparently this is required by the contract of Object.hashCode() ! { ! return this.hashCode(); ! } ! */ ! } ! /* ! public int OLDSIMPLEcompareTo(Object o) ! { ! return getTitle().compareToIgnoreCase( ! ((JreepadNode)o).getTitle()); ! }*/ // The following function is a halfway-house on the way to "natural numerical ordering" public int compareTo(Object o) --- 493,502 ---- { Object[] childrenArray = children.toArray(); ! java.util.Arrays.sort(childrenArray); removeAllChildren(); for(int i=0; i<childrenArray.length; i++) add((JreepadNode)childrenArray[i]); } ! // The following function is a halfway-house on the way to "natural numerical ordering" public int compareTo(Object o) |
From: PeWu <pe...@us...> - 2007-01-22 23:16:45
|
Update of /cvsroot/jreepad/jreepad/src/jreepad/io In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv30506/src/jreepad/io Modified Files: XmlWriter.java Log Message: bug: should be closing the Writer not the OutputStream Index: XmlWriter.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/XmlWriter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** XmlWriter.java 20 Jan 2007 13:01:35 -0000 1.2 --- XmlWriter.java 22 Jan 2007 23:16:40 -0000 1.3 *************** *** 49,53 **** writer.write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n"); writeNode(writer, node, 0, true); ! out.close(); } --- 49,53 ---- writer.write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n"); writeNode(writer, node, 0, true); ! writer.close(); } |
From: PeWu <pe...@us...> - 2007-01-22 23:00:42
|
Update of /cvsroot/jreepad/jreepad/src/jreepad/io In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv24141/src/jreepad/io Added Files: HtmlWriter.java Log Message: refactoring: extracted HtmlWriter from JreepadNode --- NEW FILE: HtmlWriter.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.io; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.StringWriter; import java.io.Writer; import java.util.Enumeration; import jreepad.JreepadNode; /** * Writes the Jreepad tree as HTML. * * @version $Id$ */ public class HtmlWriter implements JreepadWriter { private String encoding; private int exportMode; private boolean urlsToLinks; private int anchorType; private boolean causeToPrint; /** * Constructs the writer. */ public HtmlWriter(String encoding, int exportMode, boolean urlsToLinks, int anchorType) { this(encoding, exportMode, urlsToLinks, anchorType, false); } /** * Constructs the writer. */ public HtmlWriter(String encoding, int exportMode, boolean urlsToLinks, int anchorType, boolean causeToPrint) { this.encoding = encoding; this.exportMode = exportMode; this.urlsToLinks = urlsToLinks; this.anchorType = anchorType; this.causeToPrint = causeToPrint; } /** * Writes the tree to the output stream starting from selected node. * @param out output stream * @param node root node */ public void write(OutputStream out, JreepadNode node) throws IOException { Writer writer = new OutputStreamWriter(out, encoding); write(writer, node); out.close(); } /** * Writes the tree to a string starting from selected node. * @param node root node */ public String write(JreepadNode node) { Writer writer = new StringWriter(); try { write(writer, node); } catch (IOException e) { e.printStackTrace(); return ""; } return writer.toString(); } /** * Writes the tree to the given writer starting from selected node. * @param writer output writer * @param node root node */ public void write(Writer writer, JreepadNode node) throws IOException { writer.write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n<head>\n<title>"); writer.write(htmlSpecialChars(node.getTitle())); writer.write("</title>\n<style type=\"text/css\">\n" + "dl {}\ndl dt { font-weight: bold; margin-top: 10px; font-size: 24pt; }\ndl dd {margin-left: 20px; padding-left: 0px;}\ndl dd dl dt {background: black; color: white; font-size: 12pt; }\ndl dd dl dd dl dt {background: white; color: black; }" + "\n</style>\n</head>\n\n<body" + (causeToPrint ? " onload='print();'" : "") + ">\n<!-- Exported from Jreepad -->\n<dl>"); writeNode(writer, node); writer.write("\n</dl>\n</body>\n</html>"); } /** * Writes the node and its children to the writer. * @param writer output writer * @param node root node */ public void writeNode(Writer writer, JreepadNode node) throws IOException { writer.write("\n<dt><a name=\""); if (anchorType == JreepadNode.EXPORT_HTML_ANCHORS_WIKI) writer.write(node.getTitle()); else writer.write(node.getWikiAnchor()); writer.write("\"></a>"); writer.write(htmlSpecialChars(node.getTitle())); writer.write("</dt>\n<dd>"); // Write out the node's article content - using normal, preformatted, or HTML modes as // appropriate writer.write(node.articleToHtml(exportMode, urlsToLinks, anchorType)); if (node.getChildCount() > 0) writer.write("\n<dl>"); Enumeration kids = node.children(); while (kids.hasMoreElements()) writeNode(writer, (JreepadNode)kids.nextElement()); if (node.getChildCount() > 0) writer.write("\n</dl>"); writer.write("</dd>"); } /** * Replaces special characters to HTML entities. */ private static String htmlSpecialChars(String in) { char[] c = in.toCharArray(); StringBuffer ret = new StringBuffer(); for (int i = 0; i < c.length; i++) if (c[i] == '<') ret.append("<"); else if (c[i] == '>') ret.append(">"); else if (c[i] == '&') ret.append("&"); else if (c[i] == '\n') ret.append(" <br />\n"); else if (c[i] == '"') ret.append("""); else ret.append(c[i]); return ret.toString(); } public int getAnchorType() { return anchorType; } public void setAnchorType(int anchorType) { this.anchorType = anchorType; } public boolean isCauseToPrint() { return causeToPrint; } public void setCauseToPrint(boolean causeToPrint) { this.causeToPrint = causeToPrint; } public String getEncoding() { return encoding; } public void setEncoding(String encoding) { this.encoding = encoding; } public int getExportMode() { return exportMode; } public void setExportMode(int exportMode) { this.exportMode = exportMode; } public boolean isUrlsToLinks() { return urlsToLinks; } public void setUrlsToLinks(boolean urlsToLinks) { this.urlsToLinks = urlsToLinks; } } |
From: PeWu <pe...@us...> - 2007-01-22 23:00:42
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv24141/src/jreepad Modified Files: JreepadViewer.java JreepadNode.java Log Message: refactoring: extracted HtmlWriter from JreepadNode Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** JreepadViewer.java 20 Jan 2007 13:01:19 -0000 1.46 --- JreepadViewer.java 22 Jan 2007 23:00:36 -0000 1.47 *************** *** 48,51 **** --- 48,52 ---- import jreepad.io.AutoDetectReader; + import jreepad.io.HtmlWriter; import jreepad.io.JreepadReader; import jreepad.io.JreepadWriter; *************** *** 1892,1916 **** getPrefs().exportLocation = fileChooser.getSelectedFile(); ! String output; switch(exportFormat) { case FILE_FORMAT_HTML: ! output = theJreepad.getCurrentNode().exportAsHtml(getPrefs().htmlExportArticleType, ! getPrefs().htmlExportUrlsToLinks, ! getPrefs().htmlExportAnchorLinkType); break; case FILE_FORMAT_XML: case FILE_FORMAT_HJT: ! JreepadWriter writer; ! if (exportFormat == FILE_FORMAT_XML) ! writer= new XmlWriter(getPrefs().getEncoding()); ! else ! writer= new TreepadWriter(getPrefs().getEncoding()); ! OutputStream fos = new FileOutputStream(getPrefs().exportLocation); ! writer.write(fos, theJreepad.getCurrentNode()); ! fos.close(); ! setCursor(Cursor.getDefaultCursor()); ! return; ! case FILE_FORMAT_TEXT: output = theJreepad.getCurrentNode().getContent(); --- 1893,1912 ---- getPrefs().exportLocation = fileChooser.getSelectedFile(); ! String output = null; ! JreepadWriter writer = null; switch(exportFormat) { case FILE_FORMAT_HTML: ! writer = new HtmlWriter(getPrefs().getEncoding(), ! getPrefs().htmlExportArticleType, ! getPrefs().htmlExportUrlsToLinks, ! getPrefs().htmlExportAnchorLinkType); break; case FILE_FORMAT_XML: + writer= new XmlWriter(getPrefs().getEncoding()); + break; case FILE_FORMAT_HJT: ! writer= new TreepadWriter(getPrefs().getEncoding()); ! break; case FILE_FORMAT_TEXT: output = theJreepad.getCurrentNode().getContent(); *************** *** 1931,1942 **** } ! FileOutputStream fO = new FileOutputStream(getPrefs().exportLocation); ! // DataOutputStream dO = new DataOutputStream(fO); ! OutputStreamWriter osw = new OutputStreamWriter(fO, getPrefs().getEncoding()); ! // dO.writeBytes(output); ! osw.write(output); ! osw.close(); ! // dO.close(); ! fO.close(); setCursor(Cursor.getDefaultCursor()); } --- 1927,1942 ---- } ! OutputStream fos = new FileOutputStream(getPrefs().exportLocation); ! if (writer != null) ! { ! writer.write(fos, theJreepad.getCurrentNode()); ! fos.close(); ! } ! else // assume (output != null) ! { ! OutputStreamWriter osw = new OutputStreamWriter(fos, getPrefs().getEncoding()); ! osw.write(output); ! osw.close(); ! } setCursor(Cursor.getDefaultCursor()); } *************** *** 1953,1959 **** setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); ! String output = theJreepad.getCurrentNode().exportAsHtml(getPrefs().htmlExportArticleType, ! getPrefs().htmlExportUrlsToLinks, ! getPrefs().htmlExportAnchorLinkType, true); toBrowserForPrintAction(output); --- 1953,1963 ---- setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); ! HtmlWriter writer = new HtmlWriter( ! getPrefs().getEncoding(), ! getPrefs().htmlExportArticleType, ! getPrefs().htmlExportUrlsToLinks, ! getPrefs().htmlExportAnchorLinkType, ! true); ! String output = writer.write(theJreepad.getCurrentNode()); toBrowserForPrintAction(output); Index: JreepadNode.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadNode.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** JreepadNode.java 20 Jan 2007 13:01:19 -0000 1.22 --- JreepadNode.java 22 Jan 2007 23:00:37 -0000 1.23 *************** *** 102,151 **** public static final int EXPORT_HTML_ANCHORS_PATH=0; public static final int EXPORT_HTML_ANCHORS_WIKI=1; - public String exportAsHtml(int exportMode, boolean urlsToLinks, int anchorType) - { - return exportAsHtml(exportMode, urlsToLinks, anchorType, false); - } - public String exportAsHtml(int exportMode, boolean urlsToLinks, int anchorType, boolean causeToPrint) - { - StringBuffer ret = new StringBuffer(); - ret.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n<head>\n<title>"); - ret.append(htmlSpecialChars(getTitle())); - ret.append("</title>\n<style type=\"text/css\">\n" - + "dl {}\ndl dt { font-weight: bold; margin-top: 10px; font-size: 24pt; }\ndl dd {margin-left: 20px; padding-left: 0px;}\ndl dd dl dt {background: black; color: white; font-size: 12pt; }\ndl dd dl dd dl dt {background: white; color: black; }" - + "\n</style>\n</head>\n\n<body" - + (causeToPrint? " onload='print();'" : "") - + ">\n<!-- Exported from Jreepad -->\n<dl>"); - ret.append(exportAsHtml(exportMode, urlsToLinks, htmlSpecialChars(getTitle()), anchorType)); - ret.append("\n</dl>\n</body>\n</html>"); - return ret.toString(); - } - public StringBuffer exportAsHtml(int exportMode, boolean urlsToLinks, String anchorName, int anchorType) - { - StringBuffer ret = new StringBuffer(); - ret.append("\n<dt><a name=\""); - if(anchorType==EXPORT_HTML_ANCHORS_WIKI) - ret.append(getTitle()); - else - ret.append(anchorName); - ret.append("\"></a>"); - ret.append(htmlSpecialChars(getTitle())); - ret.append("</dt>\n<dd>"); - - // Write out the node's article content - using normal, preformatted, or HTML modes as appropriate - ret.append(articleToHtml(exportMode, urlsToLinks, anchorName, anchorType)); - - if(getChildCount()>0) - ret.append("\n<dl>"); - for(int i=0; i<children.size(); i++) - { - JreepadNode thisKid = (JreepadNode)getChildAt(i); - ret.append(thisKid.exportAsHtml(exportMode, urlsToLinks, anchorName+"/"+htmlSpecialChars(thisKid.getTitle()), anchorType)); - } - if(getChildCount()>0) - ret.append("\n</dl>"); - ret.append("</dd>"); - - return ret; - } public String exportSingleArticleAsHtml(int exportMode, boolean urlsToLinks, int anchorType, boolean causeToPrint) --- 102,105 ---- *************** *** 159,168 **** + (causeToPrint? " onload='print();'" : "") + ">\n<!-- Exported from Jreepad -->\n<dl>"); ! ret.append(articleToHtml(exportMode, urlsToLinks, htmlSpecialChars(getTitle()), anchorType)); ret.append("\n</dl>\n</body>\n</html>"); return ret.toString(); } ! public String articleToHtml(int exportMode, boolean urlsToLinks, String anchorName, int anchorType) { switch(articleMode) --- 113,122 ---- + (causeToPrint? " onload='print();'" : "") + ">\n<!-- Exported from Jreepad -->\n<dl>"); ! ret.append(articleToHtml(exportMode, urlsToLinks, anchorType)); ret.append("\n</dl>\n</body>\n</html>"); return ret.toString(); } ! public String articleToHtml(int exportMode, boolean urlsToLinks, int anchorType) { switch(articleMode) *************** *** 213,216 **** --- 167,177 ---- } + public String getWikiAnchor() + { + if (getParent() == null) + return htmlSpecialChars(getTitle()); + return getParentNode().getWikiAnchor() + "/" + htmlSpecialChars(getTitle()); + } + private static String htmlSpecialChars(String in) { *************** *** 730,733 **** --- 691,699 ---- } + public JreepadNode getSoftLinkTarget() + { + return softLinkTarget; + } + public String getTitle() { return articleMode==ARTICLEMODE_SOFTLINK ? softLinkTarget.getTitle() : title; } *************** *** 784,788 **** static final int CSVPARSE_MODE_EXPECTINGDELIMITER = 2; static final int CSVPARSE_MODE_EXPECTINGDATA = 3; ! protected String[][] interpretContentAsCsv() { return interpretContentAsCsv(getContent()); --- 750,754 ---- static final int CSVPARSE_MODE_EXPECTINGDELIMITER = 2; static final int CSVPARSE_MODE_EXPECTINGDATA = 3; ! public String[][] interpretContentAsCsv() { return interpretContentAsCsv(getContent()); *************** *** 931,978 **** } - private static String xmlUnescapeChars(String in) - { - char[] c = in.toCharArray(); - StringBuffer ret = new StringBuffer(); - StringBuffer entity = new StringBuffer(); - String ent; - - int i,j; - OuterLoop: - for(i=0; i<c.length; i++) - if(c[i]=='&') - { - entity = new StringBuffer(); - for(j=0; j<8; j++) // Add things into the entity buffer until we hit a semicolon - { - i++; - if(i == c.length) - { - ret.append('&' + entity.toString()); - continue OuterLoop; - } - else if(c[i]!=';') - entity.append(c[i]); - else - break; // Reached end of the entity (or end of the whole string!) - } - ent = entity.toString(); - if(ent.equals("lt")) - ret.append("<"); - else if(ent.equals("gt")) - ret.append(">"); - else if(ent.equals("amp")) - ret.append("&"); - else if(ent.equals("quot")) - ret.append("\""); - else - ret.append('&' + ent + ';'); - } - else - ret.append(c[i]); - - return ret.toString(); - } - private void makeMeASoftLinkTo(JreepadNode targetNode) { --- 897,900 ---- |
From: PeWu <pe...@us...> - 2007-01-20 13:01:38
|
Update of /cvsroot/jreepad/jreepad/src/jreepad/io In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv6758/src/jreepad/io Modified Files: TreepadWriter.java JreepadWriter.java XmlWriter.java Log Message: Added header comment Index: JreepadWriter.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/JreepadWriter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JreepadWriter.java 18 Jan 2007 09:37:27 -0000 1.1 --- JreepadWriter.java 20 Jan 2007 13:01:35 -0000 1.2 *************** *** 1,4 **** ! package jreepad.io; import java.io.IOException; --- 1,22 ---- ! /* ! 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.io; import java.io.IOException; Index: TreepadWriter.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/TreepadWriter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TreepadWriter.java 18 Jan 2007 09:37:26 -0000 1.1 --- TreepadWriter.java 20 Jan 2007 13:01:35 -0000 1.2 *************** *** 1,2 **** --- 1,21 ---- + /* + 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.io; Index: XmlWriter.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/XmlWriter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** XmlWriter.java 18 Jan 2007 09:37:27 -0000 1.1 --- XmlWriter.java 20 Jan 2007 13:01:35 -0000 1.2 *************** *** 1,2 **** --- 1,21 ---- + /* + 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.io; |
From: PeWu <pe...@us...> - 2007-01-20 13:01:24
|
Update of /cvsroot/jreepad/jreepad/src/jreepad/io In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv6732/src/jreepad/io Modified Files: JreepadReader.java Added Files: XmlReader.java TreepadReader.java AutoDetectReader.java Log Message: refactoring: moved XML and HJT readers from JreepadNode to separate classes Index: JreepadReader.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/JreepadReader.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JreepadReader.java 18 Jan 2007 09:37:27 -0000 1.1 --- JreepadReader.java 20 Jan 2007 13:01:19 -0000 1.2 *************** *** 1,6 **** package jreepad.io; import java.io.IOException; ! import java.io.Reader; import jreepad.JreepadNode; --- 1,25 ---- + /* + 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.io; import java.io.IOException; ! import java.io.InputStream; import jreepad.JreepadNode; *************** *** 14,17 **** public interface JreepadReader { ! public JreepadNode read(Reader in) throws IOException; } --- 33,36 ---- public interface JreepadReader { ! public JreepadNode read(InputStream in) throws IOException; } --- NEW FILE: AutoDetectReader.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.io; import java.io.IOException; import java.io.InputStream; import jreepad.JreepadNode; /** * Reads a Jreepad file automatically detecting file type (XML or HJT). * * @version $Id$ */ public class AutoDetectReader implements JreepadReader { XmlReader xmlReader; TreepadReader treepadReader; public AutoDetectReader(String encoding, boolean autoDetectHtmlArticles) { xmlReader = new XmlReader(); treepadReader = new TreepadReader(encoding, autoDetectHtmlArticles); } public JreepadNode read(InputStream in) throws IOException { in = new RewindableInputStream(in); // Read first line String currentLine = ((RewindableInputStream)in).readLine(); in.reset(); // reset stream, so the specific readers read from the beginning if (currentLine.startsWith("<?xml version=\"1.0\"")) { // Try and find out what character encoding to use int encPos = currentLine.indexOf("encoding="); String xmlEncoding = null; if (encPos != -1) { xmlEncoding = currentLine.substring(encPos + 10); encPos = xmlEncoding.indexOf("\""); if (encPos == -1) encPos = xmlEncoding.indexOf("'"); if (encPos != -1) xmlEncoding = xmlEncoding.substring(0, encPos); // System.out.println("Start of XML loading: decided on the following character // encoding: " + xmlEncoding); } xmlReader.setEncoding(xmlEncoding); return xmlReader.read(in); } else if ((currentLine.toLowerCase().startsWith("<treepad") && currentLine.endsWith(">"))) { treepadReader.setFileFormat(1); return treepadReader.read(in); } else if ((currentLine.toLowerCase().startsWith("<hj-treepad") && currentLine.endsWith(">"))) { treepadReader.setFileFormat(1); return treepadReader.read(in); } else { System.out.println("First line of file does not indicate a recognised format:\n" + currentLine + "\n"); throw new IOException("First line of file does not indicate a recognised format:\n\n" + currentLine); } } public boolean isAutoDetectHtmlArticles() { return treepadReader.isAutoDetectHtmlArticles(); } public void setAutoDetectHtmlArticles(boolean autoDetectHtmlArticles) { treepadReader.setAutoDetectHtmlArticles(autoDetectHtmlArticles); } public String getEncoding() { return treepadReader.getEncoding(); } public void setEncoding(String encoding) { treepadReader.setEncoding(encoding); } /** * This class wraps the byte inputstreams we're presented with. We need it because * java.io.InputStreams don't provide functionality to reread processed bytes, and they have a * habit of reading more than one character when you call their read() methods. This means that, * once we discover the true (declared) encoding of a document, we can neither backtrack to read * the whole doc again nor start reading where we are with a new reader. This class allows * rewinding an inputStream by allowing a mark to be set, and the stream reset to that position. * <strong>The class assumes that it needs to read one character per invocation when it's read() * method is inovked, but uses the underlying InputStream's read(char[], offset length) * method--it won't buffer data read this way!</strong> * * @xerces.internal * @author Neil Graham, IBM * @author Glenn Marcy, IBM */ protected static class RewindableInputStream extends InputStream { private static int BUFFER_SIZE = 2048; private InputStream fInputStream; private byte[] fData; private int fStartOffset; private int fEndOffset; private int fOffset; private int fLength; private int fMark; public RewindableInputStream(InputStream is) { fData = new byte[BUFFER_SIZE]; fInputStream = is; fStartOffset = 0; fEndOffset = -1; fOffset = 0; fLength = 0; fMark = 0; } public void setStartOffset(int offset) { fStartOffset = offset; } public void rewind() { fOffset = fStartOffset; System.out.println("Rewinding " + fOffset + "/" + fLength + " -> " + fStartOffset + "(end=" + fEndOffset + ")"); } public int read() throws IOException { int b = 0; if (fOffset < fLength) { return fData[fOffset++] & 0xff; } if (fOffset == fEndOffset) { return -1; } if (fOffset == fData.length) { byte[] newData = new byte[fOffset << 1]; System.arraycopy(fData, 0, newData, 0, fOffset); fData = newData; } b = fInputStream.read(); if (b == -1) { fEndOffset = fOffset; return -1; } fData[fLength++] = (byte)b; fOffset++; return b & 0xff; } public int read(byte[] b, int off, int len) throws IOException { int bytesLeft = fLength - fOffset; if (bytesLeft == 0) { if (fOffset == fEndOffset) { return -1; } return fInputStream.read(b, off, len); } if (len < bytesLeft) { if (len <= 0) { return 0; } } else { len = bytesLeft; } if (b != null) { System.arraycopy(fData, fOffset, b, off, len); } fOffset += len; return len; } public long skip(long n) throws IOException { int bytesLeft; if (n <= 0) { return 0; } bytesLeft = fLength - fOffset; if (bytesLeft == 0) { if (fOffset == fEndOffset) { return 0; } return fInputStream.skip(n); } if (n <= bytesLeft) { fOffset += n; return n; } fOffset += bytesLeft; if (fOffset == fEndOffset) { return bytesLeft; } n -= bytesLeft; /* * In a manner of speaking, when this class isn't permitting more than one byte at a * time to be read, it is "blocking". The available() method should indicate how much * can be read without blocking, so while we're in this mode, it should only indicate * that bytes in its buffer are available; otherwise, the result of available() on the * underlying InputStream is appropriate. */ return fInputStream.skip(n) + bytesLeft; } public int available() throws IOException { int bytesLeft = fLength - fOffset; if (bytesLeft == 0) { if (fOffset == fEndOffset) { return -1; } return fInputStream.available(); } return bytesLeft; } public void mark(int howMuch) { fMark = fOffset; } public void reset() { fOffset = fMark; } public boolean markSupported() { return true; } public void close() throws IOException { if (fInputStream != null) { fInputStream.close(); fInputStream = null; } } public String readLine() throws IOException { byte[] bytes = new byte[BUFFER_SIZE]; int len = 0; while (len < BUFFER_SIZE) { int ret = read(); if (ret == -1 || ret == 0x0a || ret == 0x0d) break; bytes[len] = (byte)(ret & 0xff); len++; } return new String(bytes, 0, len); } } // end of RewindableInputStream class } --- NEW FILE: XmlReader.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.io; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import jreepad.JreepadNode; /** * Reads XML input into Jreepad. * * @version $Id$ */ public class XmlReader implements JreepadReader { private String encoding; public XmlReader() { this(null); } public XmlReader(String encoding) { this.encoding = encoding; } public JreepadNode read(InputStream in) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(in, encoding)); String currentLine; String currentXmlContent = ""; int nodeTagOffset = 0; // Spool until we're at the very first node while ((currentLine = reader.readLine()) != null && (nodeTagOffset = currentXmlContent.indexOf("<node")) == -1 && (nodeTagOffset == -1 || currentXmlContent.indexOf('>', nodeTagOffset) == -1)) { currentXmlContent += (currentLine + "\n"); } if (currentLine != null) currentXmlContent += (currentLine + "\n"); // System.out.println("XMLparse: I've spooled to the first node and content is now: " + // currentXmlContent); // So currentXmlContent now contains all of the opening tag, including its attributes etc // Strip off anything BEFORE the node opening currentXmlContent = currentXmlContent.substring(nodeTagOffset); // System.out.println("XMLparse: I've stripped anything before the first node and content is // now: " + currentXmlContent); return readNode(reader, currentXmlContent, 0).node; } // This function should return any XML string content that remains unprocessed // Also returns newly created node ReturnValue readNode(BufferedReader reader, String currentXmlContent, int depth) throws IOException { // System.out.println("XMLparse recursive: depth "+depth); // String currentXmlContent should BEGIN with the <node> tag. This is assumed, and if not // true may cause problems! String currentLine; int titleOffset, typeOffset, startTagOffset, endTagOffset; String title, typeString, content = ""; JreepadNode node = new JreepadNode(); // Extract the attributes titleOffset = currentXmlContent.indexOf("title="); typeOffset = currentXmlContent.indexOf("type="); if (titleOffset != -1) title = currentXmlContent.substring(titleOffset + 7, currentXmlContent.indexOf('"', titleOffset + 7)); else title = "<Untitled node>"; if (typeOffset != -1) typeString = currentXmlContent.substring(typeOffset + 6, currentXmlContent.indexOf('"', typeOffset + 6)); else typeString = "text/plain"; if (typeString.equals("text/csv")) node.setArticleMode(JreepadNode.ARTICLEMODE_CSV); else if (typeString.equals("text/html")) node.setArticleMode(JreepadNode.ARTICLEMODE_HTML); else if (typeString.equals("text/textile")) node.setArticleMode(JreepadNode.ARTICLEMODE_TEXTILEHTML); else if (typeString.equals("application/x-jreepad-softlink")) node.setArticleMode(JreepadNode.ARTICLEMODE_SOFTLINK); else node.setArticleMode(JreepadNode.ARTICLEMODE_ORDINARY); node.setTitle(xmlUnescapeChars(title)); // OK, so we've interpreted the attributes etc. Now we need to trim the opening tag away currentXmlContent = currentXmlContent.substring(currentXmlContent.indexOf('>') + 1); // System.out.println("XMLparse: I've stripped off the <node> tag and content is now: " + // currentXmlContent); boolean readingContent = true; // Once the baby nodes come in, we're not interested in // adding any more to the content while ((currentLine = reader.readLine()) != null) { // System.out.println("XMLparserecursive: Here's a line: " + currentLine); currentLine += "\n"; // We want to keep the newlines, but the BufferedReader doesn't // give us them // We're reading CONTENT into the current node. currentXmlContent += currentLine; // System.out.println("\n\nThe content that I'm currently trying to process // is:\n"+currentXmlContent); // Look out for <node which tells us we're starting a child startTagOffset = currentXmlContent.indexOf("<node"); // Look out for </node> which tells us we're finishing this node and returning to the // parent endTagOffset = currentXmlContent.indexOf("</node>"); while (!(startTagOffset == -1 || endTagOffset == -1)) { if (startTagOffset == -1 || endTagOffset < startTagOffset) { // Process the nearest end tag if (readingContent) content += xmlUnescapeChars(currentXmlContent.substring(0, endTagOffset)); String returnFromBaby = currentXmlContent.substring(endTagOffset + 7); // System.out.println("\n\nBaby intends to return:"+returnFromBaby); node.setContent(content); return new ReturnValue(returnFromBaby, node); } else { if (readingContent) { content += xmlUnescapeChars(currentXmlContent.substring(0, startTagOffset)); node.setContent(content); } // Having found a child node, we want to STOP adding anything to the current // node's content (e.g. newlines...) readingContent = false; // Process the nearest start tag // System.out.println("\n\nJust before passing to baby: content // is:\n"+currentXmlContent); ReturnValue returnValue = readNode(reader, currentXmlContent .substring(startTagOffset), depth + 1); currentXmlContent = returnValue.xmlContent; // System.out.println("\n\nJust after passing to baby: content // is:\n"+currentXmlContent); node.add(returnValue.node); } startTagOffset = currentXmlContent.indexOf("<node"); endTagOffset = currentXmlContent.indexOf("</node>"); } } // End while // Just make sure we haven't wasted any content... endTagOffset = currentXmlContent.indexOf('<'); if (readingContent && (endTagOffset != -1)) content += xmlUnescapeChars(currentXmlContent.substring(0, endTagOffset)); node.setContent(content); // System.out.println("THE MAIN WHILE LOOP HAS ENDED. SPARE CONTENT:\n" + // currentXmlContent); return new ReturnValue("", node); } private static String xmlUnescapeChars(String in) { char[] c = in.toCharArray(); StringBuffer ret = new StringBuffer(); StringBuffer entity = new StringBuffer(); String ent; int i, j; OuterLoop: for (i = 0; i < c.length; i++) if (c[i] == '&') { entity = new StringBuffer(); for (j = 0; j < 8; j++) // Add things into the entity buffer until we hit a // semicolon { i++; if (i == c.length) { ret.append('&' + entity.toString()); continue OuterLoop; } else if (c[i] != ';') entity.append(c[i]); else break; // Reached end of the entity (or end of the whole string!) } ent = entity.toString(); if (ent.equals("lt")) ret.append("<"); else if (ent.equals("gt")) ret.append(">"); else if (ent.equals("amp")) ret.append("&"); else if (ent.equals("quot")) ret.append("\""); else ret.append('&' + ent + ';'); } else ret.append(c[i]); return ret.toString(); } public String getEncoding() { return encoding; } public void setEncoding(String encoding) { this.encoding = encoding; } /** * Container class to make it possible to return two objects from readNode(). */ private static class ReturnValue { public String xmlContent; public JreepadNode node; public ReturnValue(String xmlContent, JreepadNode node) { this.xmlContent = xmlContent; this.node = node; } } } --- NEW FILE: TreepadReader.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.io; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.LineNumberReader; import java.util.Stack; import jreepad.JreepadNode; /** * Reads a treepad file into Jreepad. * * @version $Id$ */ public class TreepadReader implements JreepadReader { private boolean autoDetectHtmlArticles; private String encoding; private int fileFormat; public TreepadReader(String encoding, boolean autoDetectHtmlArticles) { this.encoding = encoding; this.autoDetectHtmlArticles = autoDetectHtmlArticles; } public JreepadNode read(InputStream in) throws IOException { LineNumberReader reader = new LineNumberReader(new InputStreamReader(in, encoding)); reader.readLine(); // skip first line // TODO check for treepadness Stack nodeStack = new Stack(); int depthMarker; JreepadNode newNode; JreepadNode rootNode = null; String dtLine, nodeLine, titleLine, depthLine; StringBuffer currentContent; String currentLine; dtLine = "dt=text"; while ((fileFormat == 2 || (dtLine = reader.readLine()) != null) && (nodeLine = reader.readLine()) != null && (titleLine = reader.readLine()) != null && (depthLine = reader.readLine()) != null) { // Read "dt=text" [or error] - NB THE OLDER FORMAT DOESN'T INCLUDE THIS LINE SO WE SKIP // IT if (dtLine.equals("") && nodeLine.startsWith("<bmarks>")) throw new IOException( "This is not a Treepad-Lite-compatible file!\n\nFiles created in more advanced versions of Treepad\ncontain features that are not available in Jreepad."); if (fileFormat != 2) if (!(dtLine.toLowerCase().startsWith("dt=text"))) throw new IOException("Unrecognised node dt format at line " + reader.getLineNumber() + ": " + dtLine); // Read "<node>" [or error] if (!(nodeLine.toLowerCase().startsWith("<node>"))) throw new IOException("Unrecognised node format at line " + (reader.getLineNumber() + 1) + ": " + nodeLine); // Read THE CONTENT! [loop until we find "<end node> 5P9i0s8y19Z"] currentContent = new StringBuffer(); while ((currentLine = reader.readLine()) != null && !currentLine.equals("<end node> 5P9i0s8y19Z")) { currentContent.append(currentLine + "\n"); } // Now, having established the content and the title and the depth, we'll create the // child String content = currentContent.substring(0, Math.max(currentContent.length() - 1, 0)); newNode = new JreepadNode(titleLine, content); // babyNode = new JreepadNode(titleLine, currentContent.substring(0, // Math.max(currentContent.length()-2,0)), // (JreepadNode)(nodeStack.peek())); // Turn it into a HTML-mode node if it matches "<html> ... </html>" String compareContent = newNode.getContent().toLowerCase().trim(); int newArticleMode = (autoDetectHtmlArticles && compareContent.startsWith("<html>") && compareContent .endsWith("</html>")) ? JreepadNode.ARTICLEMODE_HTML : JreepadNode.ARTICLEMODE_ORDINARY; newNode.setArticleMode(newArticleMode); if (depthLine.equals("0")) { rootNode = newNode; } else { depthMarker = Integer.parseInt(depthLine); while (nodeStack.size() > depthMarker) nodeStack.pop(); ((JreepadNode)(nodeStack.peek())).add(newNode); } nodeStack.push(newNode); } return rootNode; } public boolean isAutoDetectHtmlArticles() { return autoDetectHtmlArticles; } public void setAutoDetectHtmlArticles(boolean autoDetectHtmlArticles) { this.autoDetectHtmlArticles = autoDetectHtmlArticles; } public String getEncoding() { return encoding; } public void setEncoding(String encoding) { this.encoding = encoding; } public int getFileFormat() { return fileFormat; } public void setFileFormat(int fileFormat) { this.fileFormat = fileFormat; } } |
From: PeWu <pe...@us...> - 2007-01-20 13:01:24
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv6732/src/jreepad Modified Files: JreepadViewer.java JreepadNode.java find.java Log Message: refactoring: moved XML and HJT readers from JreepadNode to separate classes Index: find.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/find.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** find.java 18 Jan 2007 09:37:27 -0000 1.5 --- find.java 20 Jan 2007 13:01:19 -0000 1.6 *************** *** 36,39 **** --- 36,41 ---- import java.util.Vector; + import jreepad.io.AutoDetectReader; + import jreepad.io.JreepadReader; import jreepad.io.JreepadWriter; import jreepad.io.TreepadWriter; *************** *** 232,236 **** try { ! root = new JreepadNode(new InputStreamReader(new FileInputStream(userFile), encoding), false); } catch(IOException err) --- 234,240 ---- try { ! InputStream in = new FileInputStream(userFile); ! JreepadReader reader = new AutoDetectReader(encoding, false); ! root = reader.read(in); } catch(IOException err) Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** JreepadViewer.java 18 Jan 2007 09:37:27 -0000 1.45 --- JreepadViewer.java 20 Jan 2007 13:01:19 -0000 1.46 *************** *** 47,50 **** --- 47,52 ---- import java.lang.reflect.*; + import jreepad.io.AutoDetectReader; + import jreepad.io.JreepadReader; import jreepad.io.JreepadWriter; import jreepad.io.TreepadWriter; *************** *** 357,361 **** getPrefs().openLocation = firstTimeFile; content.remove(theJreepad); ! theJreepad = new JreepadView(new JreepadNode(new InputStreamReader(new FileInputStream(getPrefs().openLocation), getPrefs().getEncoding()), getPrefs().autoDetectHtmlArticles)); getPrefs().saveLocation = getPrefs().exportLocation = getPrefs().importLocation = getPrefs().openLocation; content.add(theJreepad); --- 359,367 ---- getPrefs().openLocation = firstTimeFile; content.remove(theJreepad); ! ! InputStream in = new FileInputStream(getPrefs().openLocation); ! JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! theJreepad = new JreepadView(reader.read(in)); ! getPrefs().saveLocation = getPrefs().exportLocation = getPrefs().importLocation = getPrefs().openLocation; content.add(theJreepad); *************** *** 1622,1626 **** getPrefs().openLocation = f; content.remove(theJreepad); ! theJreepad = new JreepadView(new JreepadNode(new InputStreamReader(new FileInputStream(getPrefs().openLocation), getPrefs().getEncoding()), getPrefs().autoDetectHtmlArticles)); getPrefs().saveLocation = getPrefs().openLocation; content.add(theJreepad); --- 1628,1636 ---- getPrefs().openLocation = f; content.remove(theJreepad); ! ! InputStream in = new FileInputStream(getPrefs().openLocation); ! JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! theJreepad = new JreepadView(reader.read(in)); ! getPrefs().saveLocation = getPrefs().openLocation; content.add(theJreepad); *************** *** 1825,1829 **** { case FILE_FORMAT_HJT: ! theJreepad.addChild(new JreepadNode(new InputStreamReader(new FileInputStream(getPrefs().importLocation), getPrefs().getEncoding()), getPrefs().autoDetectHtmlArticles)); break; case FILE_FORMAT_TEXT: --- 1835,1841 ---- { case FILE_FORMAT_HJT: ! InputStream in = new FileInputStream(getPrefs().importLocation); ! JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! theJreepad.addChild(reader.read(in)); break; case FILE_FORMAT_TEXT: Index: JreepadNode.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadNode.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** JreepadNode.java 18 Jan 2007 09:37:27 -0000 1.21 --- JreepadNode.java 20 Jan 2007 13:01:19 -0000 1.22 *************** *** 18,22 **** */ - package jreepad; --- 18,21 ---- *************** *** 29,33 **** import java.util.Comparator; import java.util.Enumeration; - import java.util.Stack; import javax.swing.tree.DefaultMutableTreeNode; --- 28,31 ---- *************** *** 73,409 **** undoMgr = new UndoManager(); } - public JreepadNode(InputStreamReader treeInputStream, boolean autoDetectHtmlArticles) throws IOException - { - undoMgr = new UndoManager(); - constructFromInputStream(treeInputStream, autoDetectHtmlArticles); - } - private void constructFromInputStream(InputStreamReader treeInputStream, boolean autoDetectHtmlArticles) throws IOException - { - int lineNum = 2; - BufferedReader bReader = new BufferedReader(treeInputStream); - - Stack nodeStack = new Stack(); - nodeStack.push(this); - - String currentLine = bReader.readLine(); // Read the first line, check for treepadness - - if(currentLine.startsWith("<?xml version=\"1.0\"")) - { - // Try and find out what character encoding to use - int encPos = currentLine.indexOf("encoding="); - String xmlEncoding; - if(encPos==-1) - xmlEncoding = ""; // getPrefs().getEncoding(); - else - { - xmlEncoding = currentLine.substring(encPos+10); - encPos = xmlEncoding.indexOf("\""); - if(encPos==-1) - encPos = xmlEncoding.indexOf("'"); - if(encPos==-1) - xmlEncoding = ""; // getPrefs().getEncoding(); - else - xmlEncoding = xmlEncoding.substring(0, encPos); - //System.out.println("Start of XML loading: decided on the following character encoding: " + xmlEncoding); - //System.out.println(" ...but unfortunately can't do anything about that. Using encoding " + treeInputStream.getEncoding()); - constructFromXmlInputStream(bReader); - } - } - else if((currentLine.toLowerCase().startsWith("<treepad") && currentLine.endsWith(">")) ) - { - constructFromHjtInputStream(treeInputStream, autoDetectHtmlArticles, - 1, bReader, lineNum, nodeStack); - } - else if((currentLine.toLowerCase().startsWith("<hj-treepad") && currentLine.endsWith(">")) ) - constructFromHjtInputStream(treeInputStream, autoDetectHtmlArticles, - 2, bReader, lineNum, nodeStack); - else - { - System.out.println("First line of file does not indicate a recognised format:\n" + currentLine + "\n"); - throw new IOException("First line of file does not indicate a recognised format:\n\n" + currentLine); - } - - - - } - - private void constructFromXmlInputStream(BufferedReader bReader) throws IOException - { - String currentLine; - String currentXmlContent = ""; - int nodeTagOffset = 0; - - // Spool until we're at the very first node - while((currentLine = bReader.readLine())!=null && (nodeTagOffset = currentXmlContent.indexOf("<node"))==-1 - && currentXmlContent.indexOf('>', nodeTagOffset)==-1) - currentXmlContent += (currentLine + "\n"); - - if(currentLine != null) - currentXmlContent += (currentLine + "\n"); - - //System.out.println("XMLparse: I've spooled to the first node and content is now: " + currentXmlContent); - - // So currentXmlContent now contains all of the opening tag, including its attributes etc - // Strip off anything BEFORE the node opening - currentXmlContent = currentXmlContent.substring(nodeTagOffset); - - //System.out.println("XMLparse: I've stripped anything before the first node and content is now: " + currentXmlContent); - - recursiveCreateFromXmlStream(bReader, currentXmlContent, 0); - } - - // This function should return any XML string content that remains unprocessed - private String recursiveCreateFromXmlStream(BufferedReader bReader, String currentXmlContent, int depth) throws IOException - { - - // System.out.println("XMLparse recursive: depth "+depth); - - // String currentXmlContent should BEGIN with the <node> tag. This is assumed, and if not true may cause problems! - String currentLine; - int titleOffset, typeOffset, startTagOffset, endTagOffset; - String title, typeString, content; - JreepadNode babyNode; - removeAllChildren(); - this.content = ""; - - // Extract the attributes - titleOffset = currentXmlContent.indexOf("title="); - typeOffset = currentXmlContent.indexOf("type="); - if(titleOffset!=-1) - title = currentXmlContent.substring(titleOffset+7, currentXmlContent.indexOf('"', titleOffset+7)); - else - title = "<Untitled node>"; - if(typeOffset!=-1) - typeString = currentXmlContent.substring(typeOffset+6, currentXmlContent.indexOf('"', typeOffset+6)); - else - typeString = "text/plain"; - - if(typeString.equals("text/csv")) - this.articleMode = ARTICLEMODE_CSV; - else if(typeString.equals("text/html")) - this.articleMode = ARTICLEMODE_HTML; - else if(typeString.equals("text/textile")) - this.articleMode = ARTICLEMODE_TEXTILEHTML; - else if(typeString.equals("application/x-jreepad-softlink")) - this.articleMode = ARTICLEMODE_SOFTLINK; - else - this.articleMode = ARTICLEMODE_ORDINARY; - - this.title = xmlUnescapeChars(title); - - // OK, so we've interpreted the attributes etc. Now we need to trim the opening tag away - currentXmlContent = currentXmlContent.substring(currentXmlContent.indexOf('>')+1); - - //System.out.println("XMLparse: I've stripped off the <node> tag and content is now: " + currentXmlContent); - - boolean readingContent = true; // Once the baby nodes come in, we're not interested in adding any more to the content - while((currentLine = bReader.readLine())!=null) - { - //System.out.println("XMLparserecursive: Here's a line: " + currentLine); - currentLine += "\n"; // We want to keep the newlines, but the BufferedReader doesn't give us them - - // We're reading CONTENT into the current node. - currentXmlContent += currentLine; - - // System.out.println("\n\nThe content that I'm currently trying to process is:\n"+currentXmlContent); - - // Look out for <node which tells us we're starting a child - startTagOffset = currentXmlContent.indexOf("<node"); - // Look out for </node> which tells us we're finishing this node and returning to the parent - endTagOffset = currentXmlContent.indexOf("</node>"); - - while(!(startTagOffset==-1 || endTagOffset==-1)) - { - if(startTagOffset==-1 || endTagOffset<startTagOffset) - { - // Process the nearest end tag - if(readingContent) - this.content += xmlUnescapeChars(currentXmlContent.substring(0, endTagOffset)); - String returnFromBaby = currentXmlContent.substring(endTagOffset+7); - //System.out.println("\n\nBaby intends to return:"+returnFromBaby); - return returnFromBaby; - } - else - { - if(readingContent) - this.content += xmlUnescapeChars(currentXmlContent.substring(0, startTagOffset)); - - // Having found a child node, we want to STOP adding anything to the current node's content (e.g. newlines...) - readingContent = false; - - // Process the nearest start tag - babyNode = new JreepadNode(); - //System.out.println("\n\nJust before passing to baby: content is:\n"+currentXmlContent); - currentXmlContent = babyNode.recursiveCreateFromXmlStream(bReader, - currentXmlContent.substring(startTagOffset), depth+1); - //System.out.println("\n\nJust after passing to baby: content is:\n"+currentXmlContent); - add(babyNode); - } - - startTagOffset = currentXmlContent.indexOf("<node"); - endTagOffset = currentXmlContent.indexOf("</node>"); - } - - } // End while - - - // Just make sure we haven't wasted any content... - endTagOffset = currentXmlContent.indexOf('<'); - if(readingContent && (endTagOffset != -1)) - this.content += xmlUnescapeChars(currentXmlContent.substring(0, endTagOffset)); - // System.out.println("THE MAIN WHILE LOOP HAS ENDED. SPARE CONTENT:\n" + currentXmlContent); - return ""; - } - - - private void constructFromHjtInputStream(InputStreamReader treeInputStream, boolean autoDetectHtmlArticles, - int hjtFileFormat, BufferedReader bReader, int lineNum, Stack nodeStack) throws IOException - { - int depthMarker; - JreepadNode babyNode; - String dtLine, nodeLine, titleLine, depthLine; - StringBuffer currentContent; - String currentLine; // = bReader.readLine(); // Read the first line, check for treepadness - dtLine = "dt=text"; - - while( (hjtFileFormat == 2 || (dtLine = bReader.readLine())!=null) - && (nodeLine = bReader.readLine())!=null && - (titleLine = bReader.readLine())!=null && (depthLine = bReader.readLine())!=null) - { - // Read "dt=text" [or error] - NB THE OLDER FORMAT DOESN'T INCLUDE THIS LINE SO WE SKIP IT - if(dtLine.equals("") && nodeLine.startsWith("<bmarks>")) - throw new IOException("This is not a Treepad-Lite-compatible file!\n\nFiles created in more advanced versions of Treepad\ncontain features that are not available in Jreepad."); - - if(hjtFileFormat != 2) - if(! (dtLine.toLowerCase().startsWith("dt=text"))) - throw new IOException("Unrecognised node dt format at line " + lineNum + ": " + dtLine); - // Read "<node>" [or error] - if(! (nodeLine.toLowerCase().startsWith("<node>"))) - throw new IOException("Unrecognised node format at line " + (lineNum+1) + ": " + nodeLine); - - lineNum += 4; - - // Read THE CONTENT! [loop until we find "<end node> 5P9i0s8y19Z"] - currentContent = new StringBuffer(); - while((currentLine = bReader.readLine())!=null && !currentLine.equals("<end node> 5P9i0s8y19Z")) - { - currentContent.append(currentLine + "\n"); - lineNum++; - } - - // Now, having established the content and the title and the depth, we'll create the child - babyNode = new JreepadNode(titleLine, currentContent.substring(0, Math.max(currentContent.length()-1,0))); - // babyNode = new JreepadNode(titleLine, currentContent.substring(0, Math.max(currentContent.length()-2,0)), - // (JreepadNode)(nodeStack.peek())); - - // Turn it into a HTML-mode node if it matches "<html> ... </html>" - String compareContent = babyNode.getContent().toLowerCase().trim(); - int newArticleMode = (autoDetectHtmlArticles && compareContent.startsWith("<html>") && compareContent.endsWith("</html>")) - ? ARTICLEMODE_HTML - : ARTICLEMODE_ORDINARY; - - if(depthLine.equals("0")) - { - this.title = titleLine; - this.content = currentContent.substring(0, Math.max(currentContent.length()-1,0)); - this.articleMode = newArticleMode; - } - else - { - babyNode.setArticleMode(newArticleMode); - depthMarker = Integer.parseInt(depthLine); - while(nodeStack.size()>depthMarker) - nodeStack.pop(); - - ((JreepadNode)(nodeStack.peek())).add(babyNode); - nodeStack.push(babyNode); - } - } - - } // End of constructor from HJT FileInputStream - - /* - private void OLDVERSIONconstructFromInputStream(InputStreamReader treeInputStream, boolean autoDetectHtmlArticles) throws IOException - { - int lineNum = 2; - int depthMarker; - BufferedReader bReader = new BufferedReader(treeInputStream); - JreepadNode babyNode; - children = new Vector(); - - Stack nodeStack = new Stack(); - nodeStack.push(this); - - int hjtFileFormat = -1; - - String dtLine, nodeLine, titleLine, depthLine; - StringBuffer currentContent; - String currentLine = bReader.readLine(); // Read the first line, check for treepadness - if((currentLine.toLowerCase().startsWith("<treepad") && currentLine.endsWith(">")) ) - hjtFileFormat = 1; - else if((currentLine.toLowerCase().startsWith("<hj-treepad") && currentLine.endsWith(">")) ) - hjtFileFormat = 2; - else - throw new IOException("\"<Treepad>\" tag not found at beginning of file!\n(This can be caused by having the wrong character set specified.)"); - - dtLine = "dt=text"; - - while( (hjtFileFormat == 2 || (dtLine = bReader.readLine())!=null) - && (nodeLine = bReader.readLine())!=null && - (titleLine = bReader.readLine())!=null && (depthLine = bReader.readLine())!=null) - { - // Read "dt=text" [or error] - NB THE OLDER FORMAT DOESN'T INCLUDE THIS LINE SO WE SKIP IT - if(dtLine.equals("") && nodeLine.startsWith("<bmarks>")) - throw new IOException("This is not a Treepad-Lite-compatible file!\n\nFiles created in more advanced versions of Treepad\ncontain features that are not available in Jreepad."); - - if(hjtFileFormat != 2) - if(! (dtLine.toLowerCase().startsWith("dt=text"))) - throw new IOException("Unrecognised node dt format at line " + lineNum + ": " + dtLine); - // Read "<node>" [or error] - if(! (nodeLine.toLowerCase().startsWith("<node>"))) - throw new IOException("Unrecognised node format at line " + (lineNum+1) + ": " + nodeLine); - - lineNum += 4; - - // Read THE CONTENT! [loop until we find "<end node> 5P9i0s8y19Z"] - currentContent = new StringBuffer(); - while((currentLine = bReader.readLine())!=null && !currentLine.equals("<end node> 5P9i0s8y19Z")) - { - currentContent.append(currentLine + "\n"); - lineNum++; - } - - // Now, having established the content and the title and the depth, we'll create the child - babyNode = new JreepadNode(titleLine, currentContent.substring(0, Math.max(currentContent.length()-1,0)), - (JreepadNode)(nodeStack.peek())); - // babyNode = new JreepadNode(titleLine, currentContent.substring(0, Math.max(currentContent.length()-2,0)), - // (JreepadNode)(nodeStack.peek())); - - // Turn it into a HTML-mode node if it matches "<html> ... </html>" - String compareContent = babyNode.getContent().toLowerCase().trim(); - int newArticleMode = (autoDetectHtmlArticles && compareContent.startsWith("<html>") && compareContent.endsWith("</html>")) - ? ARTICLEMODE_HTML - : ARTICLEMODE_ORDINARY; - - if(depthLine.equals("0")) - { - this.title = titleLine; - this.content = currentContent.substring(0, Math.max(currentContent.length()-1,0)); - this.articleMode = newArticleMode; - } - else - { - babyNode.setArticleMode(newArticleMode); - depthMarker = Integer.parseInt(depthLine); - while(nodeStack.size()>depthMarker) - nodeStack.pop(); - - ((JreepadNode)(nodeStack.peek())).addChild(babyNode); - nodeStack.push(babyNode); - } - } - - } // End of constructor from FileInputStream - */ public String toString() --- 71,74 ---- |
From: PeWu <pe...@us...> - 2007-01-18 09:37:31
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv22523/src/jreepad Modified Files: JreepadViewer.java JreepadNode.java find.java Log Message: refactoring: started new reader/writer framework and moved two writers out from JreepadNode Index: find.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/find.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** find.java 16 Jan 2007 23:56:03 -0000 1.4 --- find.java 18 Jan 2007 09:37:27 -0000 1.5 *************** *** 32,38 **** --- 32,43 ---- */ import java.io.*; + import javax.swing.tree.TreePath; import java.util.Vector; + import jreepad.io.JreepadWriter; + import jreepad.io.TreepadWriter; + import jreepad.io.XmlWriter; + /* *************** *** 99,103 **** private static final File prefsFile = new File(System.getProperty("user.home"), ".jreepref"); ! public static void main(String[] args) { int maxResults = 200; // A default which can be overridden --- 104,108 ---- private static final File prefsFile = new File(System.getProperty("user.home"), ".jreepref"); ! public static void main(String[] args) throws IOException { int maxResults = 200; // A default which can be overridden *************** *** 261,274 **** break; case OUTPUT_XML: - resultsParent = new JreepadNode("Search results",""); - for(int i=0; i<res.length; i++) - resultsParent.add(res[i].getNode()); - System.out.println(resultsParent.toXml("ISO-8859-1")); // FIXME: What should the encoding be, if anything? - break; case OUTPUT_HJT: resultsParent = new JreepadNode("Search results",""); for(int i=0; i<res.length; i++) resultsParent.add(res[i].getNode()); ! System.out.println(resultsParent.toTreepadString()); break; case OUTPUT_TITLES: --- 266,280 ---- break; case OUTPUT_XML: case OUTPUT_HJT: resultsParent = new JreepadNode("Search results",""); for(int i=0; i<res.length; i++) resultsParent.add(res[i].getNode()); ! String outputEncoding = "ISO-8859-1"; // FIXME: What should the encoding be? ! JreepadWriter writer; ! if (outputFormat == OUTPUT_XML) ! writer= new XmlWriter(outputEncoding); ! else ! writer= new TreepadWriter(outputEncoding); ! writer.write(System.out, resultsParent); break; case OUTPUT_TITLES: *************** *** 290,293 **** --- 296,300 ---- return n.getTitle() + "\n " + res.getArticleQuote().replace('\n', ' '); } + /* private static String formatResultXml(JreepadSearcher.JreepadSearchResult res) { *************** *** 297,300 **** --- 304,308 ---- // return "<node title=\"" + n.getTitle() + "\">" + n.getContent() + "</node>"; } + */ private static void printUsage() Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** JreepadViewer.java 16 Jan 2007 23:56:02 -0000 1.44 --- JreepadViewer.java 18 Jan 2007 09:37:27 -0000 1.45 *************** *** 47,50 **** --- 47,54 ---- import java.lang.reflect.*; + import jreepad.io.JreepadWriter; + import jreepad.io.TreepadWriter; + import jreepad.io.XmlWriter; + public class JreepadViewer extends JFrame // implements ApplicationListener { *************** *** 1648,1665 **** setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); ! // Get the output to be written - as HJT or as XML ! String writeMe; if(getPrefs().mainFileType==JreepadPrefs.FILETYPE_XML) ! writeMe = theJreepad.getRootJreepadNode().toXml(getPrefs().getEncoding()); else ! writeMe = theJreepad.getRootJreepadNode().toTreepadString(); - FileOutputStream fO = new FileOutputStream(getPrefs().saveLocation); - DataOutputStream dO = new DataOutputStream(fO); - BufferedWriter bO = new BufferedWriter(new OutputStreamWriter(dO, getPrefs().getEncoding())); - bO.write(writeMe); - bO.close(); - dO.close(); - fO.close(); if(MAC_OS_X){ com.apple.eio.FileManager.setFileTypeAndCreator(getPrefs().saveLocation.toString(), --- 1652,1665 ---- setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); ! // Write to either HJT or XML ! JreepadWriter writer; if(getPrefs().mainFileType==JreepadPrefs.FILETYPE_XML) ! writer = new XmlWriter(getPrefs().getEncoding()); else ! writer = new TreepadWriter(getPrefs().getEncoding()); ! OutputStream fos = new FileOutputStream(getPrefs().saveLocation); ! writer.write(fos, theJreepad.getRootJreepadNode()); ! fos.close(); if(MAC_OS_X){ com.apple.eio.FileManager.setFileTypeAndCreator(getPrefs().saveLocation.toString(), *************** *** 1697,1714 **** getPrefs().saveLocation = fileChooser.getSelectedFile(); ! // Get the output to be written - as HJT or as XML ! String writeMe; ! if(getPrefs().mainFileType==JreepadPrefs.FILETYPE_XML) ! writeMe = theJreepad.getRootJreepadNode().toXml(getPrefs().getEncoding()); else ! writeMe = theJreepad.getRootJreepadNode().toTreepadString(); - FileOutputStream fO = new FileOutputStream(getPrefs().saveLocation); - DataOutputStream dO = new DataOutputStream(fO); - BufferedWriter bO = new BufferedWriter(new OutputStreamWriter(dO, getPrefs().getEncoding())); - bO.write(writeMe); - bO.close(); - dO.close(); - fO.close(); if(MAC_OS_X){ com.apple.eio.FileManager.setFileTypeAndCreator(getPrefs().saveLocation.toString(), --- 1697,1710 ---- getPrefs().saveLocation = fileChooser.getSelectedFile(); ! // Write to either HJT or XML ! JreepadWriter writer; ! if(getPrefs().mainFileType == JreepadPrefs.FILETYPE_XML) ! writer = new XmlWriter(getPrefs().getEncoding()); else ! writer = new TreepadWriter(getPrefs().getEncoding()); ! OutputStream fos = new FileOutputStream(getPrefs().saveLocation); ! writer.write(fos, theJreepad.getRootJreepadNode()); ! fos.close(); if(MAC_OS_X){ com.apple.eio.FileManager.setFileTypeAndCreator(getPrefs().saveLocation.toString(), *************** *** 1741,1750 **** setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); getPrefs().backupLocation = fileChooser.getSelectedFile(); ! String writeMe = theJreepad.getRootJreepadNode().toTreepadString(); ! FileOutputStream fO = new FileOutputStream(getPrefs().backupLocation); ! DataOutputStream dO = new DataOutputStream(fO); ! dO.writeBytes(writeMe); ! dO.close(); ! fO.close(); setCursor(Cursor.getDefaultCursor()); return true; --- 1737,1747 ---- setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); getPrefs().backupLocation = fileChooser.getSelectedFile(); ! ! // Write to either HJT ! JreepadWriter writer = new TreepadWriter(getPrefs().getEncoding()); ! OutputStream fos = new FileOutputStream(getPrefs().backupLocation); ! writer.write(fos, theJreepad.getRootJreepadNode()); ! fos.close(); ! setCursor(Cursor.getDefaultCursor()); return true; *************** *** 1886,1892 **** switch(exportFormat) { - case FILE_FORMAT_HJT: - output = theJreepad.getCurrentNode().toTreepadString(); - break; case FILE_FORMAT_HTML: output = theJreepad.getCurrentNode().exportAsHtml(getPrefs().htmlExportArticleType, --- 1883,1886 ---- *************** *** 1895,1901 **** break; case FILE_FORMAT_XML: ! // output = theJreepad.getCurrentNode().exportAsSimpleXml(); ! output = theJreepad.getCurrentNode().toXml(getPrefs().getEncoding()); ! break; case FILE_FORMAT_TEXT: output = theJreepad.getCurrentNode().getContent(); --- 1889,1904 ---- break; case FILE_FORMAT_XML: ! case FILE_FORMAT_HJT: ! JreepadWriter writer; ! if (exportFormat == FILE_FORMAT_XML) ! writer= new XmlWriter(getPrefs().getEncoding()); ! else ! writer= new TreepadWriter(getPrefs().getEncoding()); ! OutputStream fos = new FileOutputStream(getPrefs().exportLocation); ! writer.write(fos, theJreepad.getCurrentNode()); ! fos.close(); ! setCursor(Cursor.getDefaultCursor()); ! return; ! case FILE_FORMAT_TEXT: output = theJreepad.getCurrentNode().getContent(); Index: JreepadNode.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadNode.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** JreepadNode.java 16 Jan 2007 23:56:03 -0000 1.20 --- JreepadNode.java 18 Jan 2007 09:37:27 -0000 1.21 *************** *** 24,29 **** import java.io.IOException; import java.io.InputStreamReader; - import java.io.ObjectInputStream; - import java.io.ObjectOutputStream; import java.io.Serializable; import java.text.CharacterIterator; --- 24,27 ---- *************** *** 673,677 **** } ! private void writeObject(ObjectOutputStream out) throws IOException { --- 671,675 ---- } ! /* private void writeObject(ObjectOutputStream out) throws IOException { *************** *** 686,705 **** constructFromInputStream(new InputStreamReader(in), false); } ! public String toTreepadString() ! { ! return "<Treepad version 2.7>\n" + toTreepadString(0); ! } ! public String toTreepadString(int currentDepth) ! { ! StringBuffer ret = new StringBuffer("dt=Text\n<node>\n"); ! ret.append(getTitle() + "\n" + (currentDepth++) + "\n" + getContent() ! + "\n" ! // + (currentDepth==1?"ROOTNODEMANIA":"\n") // Not sure why I need to be slightly unusual with the root node... ! + "<end node> 5P9i0s8y19Z\n"); ! for(int i=0; i<getChildCount(); i++) ! ret.append(((JreepadNode)getChildAt(i)).toTreepadString(currentDepth)); ! // System.out.println("\n\n____________________NODE AT DEPTH " + currentDepth + "_________________________\n" + ret); ! return ret.toString(); ! } public void add(JreepadNode child) --- 684,688 ---- constructFromInputStream(new InputStreamReader(in), false); } ! */ public void add(JreepadNode child) *************** *** 1283,1351 **** } - public String toXml(String encoding) - { - String ret = "<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n"; - ret += toXmlNoHeader(encoding, 0, true); - return stripControlChars(ret); - } - - public String toXmlNoHeader(String encoding, int depth, boolean incChildren) - { - StringBuffer ret = new StringBuffer("<node "); - if(depth==0) - ret.append("xmlns=\"http://jreepad.sourceforge.net/formats\" |
From: PeWu <pe...@us...> - 2007-01-18 09:37:30
|
Update of /cvsroot/jreepad/jreepad/src/jreepad/io In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv22523/src/jreepad/io Added Files: TreepadWriter.java JreepadWriter.java JreepadReader.java XmlWriter.java Log Message: refactoring: started new reader/writer framework and moved two writers out from JreepadNode --- NEW FILE: JreepadWriter.java --- package jreepad.io; import java.io.IOException; import java.io.OutputStream; import jreepad.JreepadNode; /** * Interface for classes that export Jreepad trees. * * @author <a href="mailto:pe...@lo...">Przemek WiÄch</a> * @version $Id$ */ public interface JreepadWriter { public void write(OutputStream out, JreepadNode node) throws IOException; } --- NEW FILE: JreepadReader.java --- package jreepad.io; import java.io.IOException; import java.io.Reader; import jreepad.JreepadNode; /** * Interface for classes that read Jreepad trees. * * @author <a href="mailto:pe...@lo...">Przemek WiÄch</a> * @version $Id$ */ public interface JreepadReader { public JreepadNode read(Reader in) throws IOException; } --- NEW FILE: TreepadWriter.java --- package jreepad.io; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.util.Enumeration; import jreepad.JreepadNode; /** * Writes the Jreepad tree as a Treepad file. * * @version $Id$ */ public class TreepadWriter implements JreepadWriter { private String encoding; public TreepadWriter(String encoding) { this.encoding = encoding; } public void write(OutputStream out, JreepadNode node) throws IOException { Writer writer = new OutputStreamWriter(out, encoding); writer.write("<Treepad version 2.7>\n"); writeNode(writer, node, 0); writer.close(); } private void writeNode(Writer writer, JreepadNode node, int depth) throws IOException { writer.write("dt=Text\n<node>\n"); writer.write(node.getTitle()); writer.write("\n"); writer.write(depth + "\n"); writer.write(node.getContent()); writer.write("\n"); writer.write("<end node> 5P9i0s8y19Z\n"); Enumeration kids = node.children(); while (kids.hasMoreElements()) writeNode(writer, (JreepadNode)kids.nextElement(), depth + 1); } } --- NEW FILE: XmlWriter.java --- package jreepad.io; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.util.Enumeration; import jreepad.JreepadNode; /** * Writes the Jreepad tree as XML. * * @version $Id$ */ public class XmlWriter implements JreepadWriter { private String encoding; public XmlWriter(String encoding) { this.encoding = encoding; } public void write(OutputStream out, JreepadNode node) throws IOException { Writer writer = new OutputStreamWriter(out, encoding); writer.write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n"); writeNode(writer, node, 0, true); out.close(); } private void writeNode(Writer writer, JreepadNode node, int depth, boolean includeChildren) throws IOException { writer.write("<node "); if (depth == 0) writer.write("xmlns=\"http://jreepad.sourceforge.net/formats\" "); writer.write("title=\"" + xmlEscapeChars(node.getTitle()) + "\" type=\""); switch (node.getArticleMode()) { case JreepadNode.ARTICLEMODE_HTML: writer.write("text/html"); break; case JreepadNode.ARTICLEMODE_TEXTILEHTML: writer.write("text/textile"); break; case JreepadNode.ARTICLEMODE_CSV: writer.write("text/csv"); break; default: writer.write("text/plain"); break; } writer.write("\">"); writer.write(xmlEscapeChars(node.getContent())); if (includeChildren) { Enumeration kids = node.children(); while (kids.hasMoreElements()) writeNode(writer, (JreepadNode)kids.nextElement(), depth + 1, includeChildren); } writer.write("</node>\n"); } public String getEncoding() { return encoding; } public void setEncoding(String encoding) { this.encoding = encoding; } private static String xmlEscapeChars(String in) { char[] c = in.toCharArray(); StringBuffer ret = new StringBuffer(); for (int i = 0; i < c.length; i++) if (c[i] == '<') ret.append("<"); else if (c[i] == '>') ret.append(">"); else if (c[i] == '&') ret.append("&"); else if (c[i] == '"') ret.append("""); else ret.append(c[i]); return ret.toString(); } } |
From: PeWu <pe...@us...> - 2007-01-18 09:37:28
|
Update of /cvsroot/jreepad/jreepad/src/jreepad/io In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv22513/src/jreepad/io Log Message: Directory /cvsroot/jreepad/jreepad/src/jreepad/io added to the repository |
From: PeWu <pe...@us...> - 2007-01-18 09:33:10
|
Update of /cvsroot/jreepad/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv20863 Modified Files: .classpath Log Message: Updated for the new name of gnu regexp jar Index: .classpath =================================================================== RCS file: /cvsroot/jreepad/jreepad/.classpath,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** .classpath 14 Jan 2007 16:58:24 -0000 1.1 --- .classpath 18 Jan 2007 09:33:07 -0000 1.2 *************** *** 4,8 **** <classpathentry kind="lib" path="lib/AppleJavaExtensions.jar"/> <classpathentry kind="lib" path="lib/BrowserLauncher2-10rc4.jar"/> ! <classpathentry kind="lib" path="lib/gnu-regexp-1.1.4.jar"/> <classpathentry kind="lib" path="lib/JTextile-1.2.jar"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> --- 4,8 ---- <classpathentry kind="lib" path="lib/AppleJavaExtensions.jar"/> <classpathentry kind="lib" path="lib/BrowserLauncher2-10rc4.jar"/> ! <classpathentry kind="lib" path="lib/gnu-regexp-1.1.4-lib.jar"/> <classpathentry kind="lib" path="lib/JTextile-1.2.jar"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> |
From: PeWu <pe...@us...> - 2007-01-16 23:56:08
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv26093/src/jreepad Modified Files: JreepadViewer.java JreepadView.java JreepadNode.java find.java TreeView.java Log Message: refactoring: JreepadNode now inherits from DefaultMutableTreeNode and uses its implementation Index: JreepadView.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadView.java,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** JreepadView.java 14 Jan 2007 17:10:21 -0000 1.33 --- JreepadView.java 16 Jan 2007 23:56:03 -0000 1.34 *************** *** 161,165 **** public JreepadView() { ! this(new JreepadNode("<Untitled node>", "", null)); } --- 161,165 ---- public JreepadView() { ! this(new JreepadNode("<Untitled node>", "")); } *************** *** 711,715 **** { //DEL storeForUndo(); ! getCurrentNode().addChild(newKid); treeModel.reload(currentNode); tree.expandPath(tree.getSelectionPath()); --- 711,715 ---- { //DEL storeForUndo(); ! getCurrentNode().add(newKid); treeModel.reload(currentNode); tree.expandPath(tree.getSelectionPath()); *************** *** 725,729 **** while((curLine = bReader.readLine())!=null) if(curLine.trim().length() > 0) ! getCurrentNode().addChild(new JreepadNode(curLine.trim(), "", getCurrentNode())); treeModel.reload(currentNode); --- 725,729 ---- while((curLine = bReader.readLine())!=null) if(curLine.trim().length() > 0) ! getCurrentNode().add(new JreepadNode(curLine.trim(), "")); treeModel.reload(currentNode); *************** *** 1076,1080 **** JreepadNode newNode; TreePath newPath; ! newNode = new JreepadNode(text, "", currentNode); addChild(newNode); TreePath leadPath = tree.getLeadSelectionPath(); --- 1076,1080 ---- JreepadNode newNode; TreePath newPath; ! newNode = new JreepadNode(text, ""); addChild(newNode); TreePath leadPath = tree.getLeadSelectionPath(); Index: TreeView.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/TreeView.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TreeView.java 14 Jan 2007 17:10:21 -0000 1.1 --- TreeView.java 16 Jan 2007 23:56:03 -0000 1.2 *************** *** 135,139 **** node.removeFromParent(); ! newParent.addChild(node); treeModel.reload(oldParent); --- 135,139 ---- node.removeFromParent(); ! newParent.add(node); treeModel.reload(oldParent); Index: find.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/find.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** find.java 13 Feb 2005 20:41:39 -0000 1.3 --- find.java 16 Jan 2007 23:56:03 -0000 1.4 *************** *** 37,41 **** /* ! The "Find" class is a command-line utility for searching a single HJT file. Examples of usage: --- 37,41 ---- /* ! The "Find" class is a command-line utility for searching a single HJT file. Examples of usage: *************** *** 47,51 **** The "-f" argument indicates the file to load. ! The remaining arguments are the search terms, which by default are found in EITHER the node title or the article. A "-t" indicates that what follows should only be in the title. --- 47,51 ---- The "-f" argument indicates the file to load. ! The remaining arguments are the search terms, which by default are found in EITHER the node title or the article. A "-t" indicates that what follows should only be in the title. *************** *** 106,113 **** File userFile = null; int outputFormat = OUTPUT_XML; ! Vector titleSearches = new Vector(); Vector articleSearches = new Vector(); ! // Load the arguments and check them out if(args.length==0 || (args.length==1 && (args[0].startsWith("-h") || args[0].startsWith("--h")) )) --- 106,113 ---- File userFile = null; int outputFormat = OUTPUT_XML; ! Vector titleSearches = new Vector(); Vector articleSearches = new Vector(); ! // Load the arguments and check them out if(args.length==0 || (args.length==1 && (args[0].startsWith("-h") || args[0].startsWith("--h")) )) *************** *** 166,170 **** } } ! String inNodes = ""; for(int i=0; i<titleSearches.size(); i++) --- 166,170 ---- } } ! String inNodes = ""; for(int i=0; i<titleSearches.size(); i++) *************** *** 181,185 **** System.out.println("Warning: complicated searches (more than 1 item to find in article, or more than 1 article to find in title) don't currently work properly!"); } ! String encoding = "UTF-8"; File prefsLastFile = null; --- 181,185 ---- System.out.println("Warning: complicated searches (more than 1 item to find in article, or more than 1 article to find in title) don't currently work properly!"); } ! String encoding = "UTF-8"; File prefsLastFile = null; *************** *** 194,198 **** jreepref = (JreepadPrefs)prefsLoader.readObject(); prefsLoader.close(); ! // ...and take some data from it encoding = jreepref.getEncoding(); --- 194,198 ---- jreepref = (JreepadPrefs)prefsLoader.readObject(); prefsLoader.close(); ! // ...and take some data from it encoding = jreepref.getEncoding(); *************** *** 206,214 **** { } ! // If no file specified by user, attempt to take it from the preferences file if(userFile==null) userFile = prefsLastFile; ! // If file unspecified or not found, exit with error if(userFile==null) --- 206,214 ---- { } ! // If no file specified by user, attempt to take it from the preferences file if(userFile==null) userFile = prefsLastFile; ! // If file unspecified or not found, exit with error if(userFile==null) *************** *** 222,226 **** System.exit(1); } ! // Load the file to be searched JreepadNode root = new JreepadNode(); --- 222,226 ---- System.exit(1); } ! // Load the file to be searched JreepadNode root = new JreepadNode(); *************** *** 234,239 **** System.exit(1); } ! ! // Carry out the search JreepadSearcher searcher = new JreepadSearcher(root); --- 234,239 ---- System.exit(1); } ! ! // Carry out the search JreepadSearcher searcher = new JreepadSearcher(root); *************** *** 241,245 **** orNotAnd, caseSensitive, maxResults); JreepadSearcher.JreepadSearchResult[] res = searcher.getSearchResults(); ! if(res.length==0) { --- 241,245 ---- orNotAnd, caseSensitive, maxResults); JreepadSearcher.JreepadSearchResult[] res = searcher.getSearchResults(); ! if(res.length==0) { *************** *** 247,251 **** System.exit(1); } ! // Output the results JreepadNode resultsParent; --- 247,251 ---- System.exit(1); } ! // Output the results JreepadNode resultsParent; *************** *** 261,273 **** break; case OUTPUT_XML: ! resultsParent = new JreepadNode("Search results","",null); for(int i=0; i<res.length; i++) ! resultsParent.addChild(res[i].getNode()); System.out.println(resultsParent.toXml("ISO-8859-1")); // FIXME: What should the encoding be, if anything? break; case OUTPUT_HJT: ! resultsParent = new JreepadNode("Search results","",null); for(int i=0; i<res.length; i++) ! resultsParent.addChild(res[i].getNode()); System.out.println(resultsParent.toTreepadString()); break; --- 261,273 ---- break; case OUTPUT_XML: ! resultsParent = new JreepadNode("Search results",""); for(int i=0; i<res.length; i++) ! resultsParent.add(res[i].getNode()); System.out.println(resultsParent.toXml("ISO-8859-1")); // FIXME: What should the encoding be, if anything? break; case OUTPUT_HJT: ! resultsParent = new JreepadNode("Search results",""); for(int i=0; i<res.length; i++) ! resultsParent.add(res[i].getNode()); System.out.println(resultsParent.toTreepadString()); break; Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** JreepadViewer.java 14 Jan 2007 00:23:19 -0000 1.43 --- JreepadViewer.java 16 Jan 2007 23:56:02 -0000 1.44 *************** *** 1581,1585 **** } content.remove(theJreepad); ! theJreepad = new JreepadView(new JreepadNode("<Untitled node>",theJreepad.getContentForNewNode(), null)); getPrefs().saveLocation = null; content.add(theJreepad); --- 1581,1585 ---- } content.remove(theJreepad); ! theJreepad = new JreepadView(new JreepadNode("<Untitled node>",theJreepad.getContentForNewNode())); getPrefs().saveLocation = null; content.add(theJreepad); *************** *** 2478,2482 **** else titStr = contStr.substring(0, newlinePos-1); ! theJreepad.addChild(new JreepadNode(titStr, contStr, theJreepad.getCurrentNode())); } catch(Exception err) --- 2478,2482 ---- else titStr = contStr.substring(0, newlinePos-1); ! theJreepad.addChild(new JreepadNode(titStr, contStr)); } catch(Exception err) Index: JreepadNode.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadNode.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** JreepadNode.java 14 Jan 2007 00:20:41 -0000 1.19 --- JreepadNode.java 16 Jan 2007 23:56:03 -0000 1.20 *************** *** 21,41 **** package jreepad; ! import java.util.*; ! import java.io.*; ! import javax.swing.tree.*; ! import java.text.*; ! import javax.swing.undo.*; import org.philwilson.JTextile; ! public class JreepadNode implements Serializable, TreeNode, MutableTreeNode, Comparable { - private Vector children; private String title; private String content; ! // private int childrenCount=0; ! private JreepadNode parentNode, softLinkTarget; ! private OurSortComparator ourSortComparator; ! protected transient javax.swing.table.TableColumnModel tblColModel; // private String lineSeparator = System.getProperty("line.separator"); --- 21,50 ---- package jreepad; ! import java.io.BufferedReader; ! import java.io.IOException; ! import java.io.InputStreamReader; ! import java.io.ObjectInputStream; ! import java.io.ObjectOutputStream; ! import java.io.Serializable; ! import java.text.CharacterIterator; ! import java.text.StringCharacterIterator; ! import java.util.Comparator; ! import java.util.Enumeration; ! import java.util.Stack; ! ! import javax.swing.tree.DefaultMutableTreeNode; ! import javax.swing.tree.MutableTreeNode; ! import javax.swing.tree.TreeNode; ! import javax.swing.undo.UndoManager; import org.philwilson.JTextile; ! public class JreepadNode extends DefaultMutableTreeNode implements Comparable { private String title; private String content; ! private JreepadNode softLinkTarget; ! private static OurSortComparator ourSortComparator = new OurSortComparator(); ! //protected transient javax.swing.table.TableColumnModel tblColModel; // private String lineSeparator = System.getProperty("line.separator"); *************** *** 50,74 **** // Undo features protected transient UndoManager undoMgr; ! protected transient String lastEditStyle = ""; public JreepadNode() { ! this((JreepadNode)null); ! } ! public JreepadNode(JreepadNode parentNode) ! { ! this("", parentNode); } ! public JreepadNode(String content, JreepadNode parentNode) { ! this("",content, parentNode); } ! public JreepadNode(String title, String content, JreepadNode parentNode) { this.title = title; this.content = content; - this.parentNode = parentNode; - ourSortComparator = new OurSortComparator(); - children = new Vector(); undoMgr = new UndoManager(); } --- 59,76 ---- // Undo features protected transient UndoManager undoMgr; ! //protected transient String lastEditStyle = ""; public JreepadNode() { ! this(""); } ! public JreepadNode(String content) { ! this("",content); } ! public JreepadNode(String title, String content) { this.title = title; this.content = content; undoMgr = new UndoManager(); } *************** *** 82,86 **** int lineNum = 2; BufferedReader bReader = new BufferedReader(treeInputStream); - children = new Vector(); Stack nodeStack = new Stack(); --- 84,87 ---- *************** *** 114,122 **** { constructFromHjtInputStream(treeInputStream, autoDetectHtmlArticles, ! 1, bReader, lineNum, nodeStack, children); } else if((currentLine.toLowerCase().startsWith("<hj-treepad") && currentLine.endsWith(">")) ) constructFromHjtInputStream(treeInputStream, autoDetectHtmlArticles, ! 2, bReader, lineNum, nodeStack, children); else { --- 115,123 ---- { constructFromHjtInputStream(treeInputStream, autoDetectHtmlArticles, ! 1, bReader, lineNum, nodeStack); } else if((currentLine.toLowerCase().startsWith("<hj-treepad") && currentLine.endsWith(">")) ) constructFromHjtInputStream(treeInputStream, autoDetectHtmlArticles, ! 2, bReader, lineNum, nodeStack); else { *************** *** 165,169 **** String title, typeString, content; JreepadNode babyNode; ! children = new Vector(); this.content = ""; --- 166,170 ---- String title, typeString, content; JreepadNode babyNode; ! removeAllChildren(); this.content = ""; *************** *** 234,243 **** // Process the nearest start tag ! babyNode = new JreepadNode(this); //System.out.println("\n\nJust before passing to baby: content is:\n"+currentXmlContent); currentXmlContent = babyNode.recursiveCreateFromXmlStream(bReader, currentXmlContent.substring(startTagOffset), depth+1); //System.out.println("\n\nJust after passing to baby: content is:\n"+currentXmlContent); ! children.add(babyNode); } --- 235,244 ---- // Process the nearest start tag ! babyNode = new JreepadNode(); //System.out.println("\n\nJust before passing to baby: content is:\n"+currentXmlContent); currentXmlContent = babyNode.recursiveCreateFromXmlStream(bReader, currentXmlContent.substring(startTagOffset), depth+1); //System.out.println("\n\nJust after passing to baby: content is:\n"+currentXmlContent); ! add(babyNode); } *************** *** 259,265 **** private void constructFromHjtInputStream(InputStreamReader treeInputStream, boolean autoDetectHtmlArticles, ! int hjtFileFormat, BufferedReader bReader, int lineNum, Stack nodeStack, ! Vector children ! ) throws IOException { int depthMarker; --- 260,264 ---- private void constructFromHjtInputStream(InputStreamReader treeInputStream, boolean autoDetectHtmlArticles, ! int hjtFileFormat, BufferedReader bReader, int lineNum, Stack nodeStack) throws IOException { int depthMarker; *************** *** 296,301 **** // Now, having established the content and the title and the depth, we'll create the child ! babyNode = new JreepadNode(titleLine, currentContent.substring(0, Math.max(currentContent.length()-1,0)), ! (JreepadNode)(nodeStack.peek())); // babyNode = new JreepadNode(titleLine, currentContent.substring(0, Math.max(currentContent.length()-2,0)), // (JreepadNode)(nodeStack.peek())); --- 295,299 ---- // Now, having established the content and the title and the depth, we'll create the child ! babyNode = new JreepadNode(titleLine, currentContent.substring(0, Math.max(currentContent.length()-1,0))); // babyNode = new JreepadNode(titleLine, currentContent.substring(0, Math.max(currentContent.length()-2,0)), // (JreepadNode)(nodeStack.peek())); *************** *** 320,324 **** nodeStack.pop(); ! ((JreepadNode)(nodeStack.peek())).addChild(babyNode); nodeStack.push(babyNode); } --- 318,322 ---- nodeStack.pop(); ! ((JreepadNode)(nodeStack.peek())).add(babyNode); nodeStack.push(babyNode); } *************** *** 327,330 **** --- 325,329 ---- } // End of constructor from HJT FileInputStream + /* private void OLDVERSIONconstructFromInputStream(InputStreamReader treeInputStream, boolean autoDetectHtmlArticles) throws IOException { *************** *** 408,411 **** --- 407,411 ---- } // End of constructor from FileInputStream + */ public String toString() *************** *** 472,476 **** ret.append(articleToHtml(exportMode, urlsToLinks, anchorName, anchorType)); ! if(children.size()>0) ret.append("\n<dl>"); for(int i=0; i<children.size(); i++) --- 472,476 ---- ret.append(articleToHtml(exportMode, urlsToLinks, anchorName, anchorType)); ! if(getChildCount()>0) ret.append("\n<dl>"); for(int i=0; i<children.size(); i++) *************** *** 479,483 **** ret.append(thisKid.exportAsHtml(exportMode, urlsToLinks, anchorName+"/"+htmlSpecialChars(thisKid.getTitle()), anchorType)); } ! if(children.size()>0) ret.append("\n</dl>"); ret.append("</dd>"); --- 479,483 ---- ret.append(thisKid.exportAsHtml(exportMode, urlsToLinks, anchorName+"/"+htmlSpecialChars(thisKid.getTitle()), anchorType)); } ! if(getChildCount()>0) ret.append("\n</dl>"); ret.append("</dd>"); *************** *** 703,715 **** } ! public void addChild(JreepadNode child) { if(articleMode==ARTICLEMODE_SOFTLINK) { ! softLinkTarget.addChild(child); return; } ! children.add(child); ! child.setParent(this); } public JreepadNode removeChild(int child) // Can be used to delete, OR to 'get' one for moving --- 703,714 ---- } ! public void add(JreepadNode child) { if(articleMode==ARTICLEMODE_SOFTLINK) { ! softLinkTarget.add(child); return; } ! super.add(child); } public JreepadNode removeChild(int child) // Can be used to delete, OR to 'get' one for moving *************** *** 720,726 **** } ! if(child<0 || child > children.size()) return null; ! ! JreepadNode ret = (JreepadNode)children.remove(child); return ret; } --- 719,724 ---- } ! JreepadNode ret = (JreepadNode)getChildAt(child); ! remove(child); return ret; } *************** *** 731,738 **** return softLinkTarget.getChildAt(child); } ! if(child<0 || child>= children.size()) ! return null; ! else ! return (JreepadNode)children.get(child); } public int getChildCount() --- 729,733 ---- return softLinkTarget.getChildAt(child); } ! return super.getChildAt(child); } public int getChildCount() *************** *** 742,746 **** return softLinkTarget.getChildCount(); } ! return children.size(); } public boolean indent() --- 737,741 ---- return softLinkTarget.getChildCount(); } ! return super.getChildCount(); } public boolean indent() *************** *** 750,757 **** if(pos<1) return false; // Get sibling node just above, and move self to there. ! getParentNode().removeChild(pos); ! JreepadNode newParent = (JreepadNode)getParentNode().getChildAt(pos-1); ! newParent.addChild(this); ! setParent(newParent); return true; } --- 745,752 ---- if(pos<1) return false; // Get sibling node just above, and move self to there. ! MutableTreeNode oldParent = (MutableTreeNode)getParent(); ! DefaultMutableTreeNode newParent = (DefaultMutableTreeNode)oldParent.getChildAt(pos-1); ! removeFromParent(); ! newParent.add(this); return true; } *************** *** 768,772 **** p.removeChild(getIndex()); pp.insert(this, ppos+1); - setParent(pp); // Also (as in the original treepad) move all the later siblings so they're children of this node --- 763,766 ---- *************** *** 785,792 **** return; } ! if(child<1 || child>= children.size()) return; ! children.add(child-1, children.remove(child)); } public void moveChildDown(int child) --- 779,786 ---- return; } ! if(child<1 || child>= getChildCount()) return; ! insert(removeChild(child), child-1); } public void moveChildDown(int child) *************** *** 797,822 **** return; } ! if(child<0 || child>= children.size()-1) return; ! children.add(child+1, children.remove(child)); } public void moveUp() { ! if(getParentNode()==null) return; int index = getIndex(); if(index<1) return; removeFromParent(); ! getParentNode().insert(this, index-1); } public void moveDown() { ! if(getParentNode()==null) return; int index = getIndex(); ! if(index<0 || index >= getParentNode().getChildCount()-1) return; removeFromParent(); ! getParentNode().insert(this, index+1); } public JreepadNode addChild() --- 791,818 ---- return; } ! if(child<0 || child>= getChildCount()-1) return; ! insert(removeChild(child), child+1); } public void moveUp() { ! MutableTreeNode parent = (MutableTreeNode)getParent(); ! if(parent==null) return; int index = getIndex(); if(index<1) return; removeFromParent(); ! parent.insert(this, index-1); } public void moveDown() { ! MutableTreeNode parent = (MutableTreeNode)getParent(); ! if(parent==null) return; int index = getIndex(); ! if(index<0 || index >= parent.getChildCount()-1) return; removeFromParent(); ! parent.insert(this, index+1); } public JreepadNode addChild() *************** *** 826,832 **** return softLinkTarget.addChild(); } ! JreepadNode theChild = new JreepadNode(this); ! children.add(theChild); ! theChild.setParent(this); return theChild; } --- 822,827 ---- return softLinkTarget.addChild(); } ! JreepadNode theChild = new JreepadNode(); ! add(theChild); return theChild; } *************** *** 837,843 **** return softLinkTarget.addChild(index); } ! JreepadNode theChild = new JreepadNode(this); ! children.add(index, theChild); ! theChild.setParent(this); return theChild; } --- 832,837 ---- return softLinkTarget.addChild(index); } ! JreepadNode theChild = new JreepadNode(); ! insert(theChild, index); return theChild; } *************** *** 849,856 **** return softLinkTarget.getIndex(child); } ! for(int i=0; i<getChildCount(); i++) ! if(((JreepadNode)child).equals(getChildAt(i))) ! return i; ! return -1; } public int getIndex() --- 843,847 ---- return softLinkTarget.getIndex(child); } ! return super.getIndex(child); } public int getIndex() *************** *** 867,877 **** return softLinkTarget.isNodeInSubtree(n); } ! for(int i=0; i<getChildCount(); i++) ! { ! JreepadNode aChild = (JreepadNode)getChildAt(i); ! if(aChild.equals(n) || aChild.isNodeInSubtree(n)) ! return true; ! } ! return false; } --- 858,862 ---- return softLinkTarget.isNodeInSubtree(n); } ! return isNodeDescendant(n); } *************** *** 903,909 **** Object[] childrenArray = children.toArray(); java.util.Arrays.sort(childrenArray, ourSortComparator); ! children = new Vector(); for(int i=0; i<childrenArray.length; i++) ! children.add((JreepadNode)childrenArray[i]); } private static class OurSortComparator implements Comparator, Serializable --- 888,894 ---- Object[] childrenArray = children.toArray(); java.util.Arrays.sort(childrenArray, ourSortComparator); ! removeAllChildren(); for(int i=0; i<childrenArray.length; i++) ! add((JreepadNode)childrenArray[i]); } private static class OurSortComparator implements Comparator, Serializable *************** *** 926,934 **** */ } public int OLDSIMPLEcompareTo(Object o) { return getTitle().compareToIgnoreCase( ((JreepadNode)o).getTitle()); ! } // The following function is a halfway-house on the way to "natural numerical ordering" public int compareTo(Object o) --- 911,920 ---- */ } + /* public int OLDSIMPLEcompareTo(Object o) { return getTitle().compareToIgnoreCase( ((JreepadNode)o).getTitle()); ! }*/ // The following function is a halfway-house on the way to "natural numerical ordering" public int compareTo(Object o) *************** *** 958,965 **** // End of: Stuff to use Java's built-in mergesort - public boolean getAllowsChildren() { return true; } // Required by TreeNode interface public boolean isLeaf() { ! return getChildCount()==0; // Is this the correct behaviour? } --- 944,950 ---- // End of: Stuff to use Java's built-in mergesort public boolean isLeaf() { ! return (getChildCount()==0); } *************** *** 970,983 **** return softLinkTarget.children(); } ! return new JreepadNodeEnumeration(); } // Required by TreeNode interface public JreepadNode getParentNode() { ! return parentNode; ! } ! public TreeNode getParent() ! { ! return parentNode; } --- 955,964 ---- return softLinkTarget.children(); } ! return super.children(); } // Required by TreeNode interface public JreepadNode getParentNode() { ! return (JreepadNode)getParent(); } *************** *** 990,994 **** return; } ! removeChild(child); } public void remove(MutableTreeNode node) --- 971,975 ---- return; } ! super.remove(child); } public void remove(MutableTreeNode node) *************** *** 999,1019 **** return; } ! removeChild(getIndex((JreepadNode)node)); ! } ! public void removeFromParent() ! { ! if(parentNode != null) ! parentNode.remove(this); ! } ! public void setParent(MutableTreeNode parent) ! { ! parentNode = (JreepadNode)parent; // Do we need to do anything more at this point? } - public void setUserObject(Object object) - { - // ? - setContent(object.toString()); - } public void insert(MutableTreeNode child, int index) { --- 980,986 ---- return; } ! super.remove(node); } public void insert(MutableTreeNode child, int index) { *************** *** 1023,1027 **** return; } ! children.insertElementAt((JreepadNode)child, index); } --- 990,994 ---- return; } ! super.insert(child, index); } *************** *** 1040,1044 **** contentString.append(currentLine + "\n"); // Then just create the node ! addChild(new JreepadNode(nodeName, contentString.toString(), this)); } --- 1007,1011 ---- contentString.append(currentLine + "\n"); // Then just create the node ! add(new JreepadNode(nodeName, contentString.toString())); } *************** *** 1046,1053 **** public JreepadNode getCopy() { ! JreepadNode ret = new JreepadNode(getTitle(), getContent(), null); for(int i=0; i<getChildCount(); i++) { ! ret.addChild(((JreepadNode)getChildAt(i)).getCopy()); } return ret; --- 1013,1020 ---- public JreepadNode getCopy() { ! JreepadNode ret = new JreepadNode(getTitle(), getContent()); for(int i=0; i<getChildCount(); i++) { ! ret.add(((JreepadNode)getChildAt(i)).getCopy()); } return ret; *************** *** 1433,1449 **** protected JreepadNode makeSoftLink() { ! JreepadNode link; ! getParentNode().addChild(link = new JreepadNode(getParentNode())); link.makeMeASoftLinkTo(this); return link; } - public class JreepadNodeEnumeration implements Enumeration - { - private int i=0; - public boolean hasMoreElements() { return i<getChildCount(); } - public Object nextElement() { return getChildAt(i++); } - } // This enumerator class is required by the TreeNode interface - /* // Listens for edits that can be undone. --- 1400,1409 ---- protected JreepadNode makeSoftLink() { ! JreepadNode link = new JreepadNode(); ! getParentNode().add(link); link.makeMeASoftLinkTo(this); return link; } /* // Listens for edits that can be undone. |
From: PeWu <pe...@us...> - 2007-01-15 14:44:49
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv3597/src/jreepad Modified Files: JreepadTreeModel.java Log Message: refactoring: Simplified JreepadTreeModel - inherit instead of copypaste Index: JreepadTreeModel.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadTreeModel.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JreepadTreeModel.java 3 May 2004 13:17:44 -0000 1.1 --- JreepadTreeModel.java 15 Jan 2007 14:44:45 -0000 1.2 *************** *** 1,284 **** package jreepad; ! import javax.swing.*; ! import javax.swing.tree.*; ! import javax.swing.event.*; ! import java.awt.event.*; ! ! public class JreepadTreeModel implements TreeModel ! { ! private JreepadNode root; ! protected EventListenerList listenerList = new EventListenerList(); ! public JreepadTreeModel(JreepadNode root) ! { ! this.root = root; ! } ! public JreepadTreeModel() ! { ! this(new JreepadNode()); ! } ! public Object getChild(Object parent, int index) ! { ! return ((JreepadNode)parent).getChildAt(index); ! } ! public int getChildCount(Object parent) ! { ! return ((JreepadNode)parent).getChildCount(); ! } ! public int getIndexOfChild(Object parent, Object child) ! { ! return ((JreepadNode)parent).getIndex((JreepadNode)child); ! } ! public Object getRoot() ! { ! return root; ! } ! public boolean isLeaf(Object node) ! { ! return ((JreepadNode)node).isLeaf(); ! } ! public void addTreeModelListener(TreeModelListener l) { ! listenerList.add(TreeModelListener.class, l); ! } ! public void removeTreeModelListener(TreeModelListener l) { ! listenerList.remove(TreeModelListener.class, l); ! } ! public void valueForPathChanged(TreePath path, Object newValue) ! { ! ((JreepadNode)path.getLastPathComponent()).setTitle((String)newValue); ! } ! ! ! public void setRoot(JreepadNode root) ! { ! this.root = root; ! } ! ! ! ! ! ! ! ! // Fire notifications - copied directly from DefaultTreeModel ! /** ! * Invoke this method if you've modified the TreeNodes upon which this ! * model depends. The model will notify all of its listeners that the ! * model has changed below the node <code>node</code> (PENDING). ! */ ! public void reload(TreeNode node) { ! if(node != null) { ! fireTreeStructureChanged(this, getPathToRoot(node), null, null); ! } ! } ! /** ! * Invoke this method after you've changed how node is to be ! * represented in the tree. ! */ ! public void nodeChanged(TreeNode node) { ! if(listenerList != null && node != null) { ! TreeNode parent = node.getParent(); ! ! if(parent != null) { ! int anIndex = parent.getIndex(node); ! if(anIndex != -1) { ! int[] cIndexs = new int[1]; ! ! cIndexs[0] = anIndex; ! nodesChanged(parent, cIndexs); ! } ! } ! else if (node == getRoot()) { ! nodesChanged(node, null); ! } ! } ! } ! /** ! * Invoke this method after you've inserted some TreeNodes into ! * node. childIndices should be the index of the new elements and ! * must be sorted in ascending order. ! */ ! public void nodesWereInserted(TreeNode node, int[] childIndices) { ! if(listenerList != null && node != null && childIndices != null ! && childIndices.length > 0) { ! int cCount = childIndices.length; ! Object[] newChildren = new Object[cCount]; ! ! for(int counter = 0; counter < cCount; counter++) ! newChildren[counter] = node.getChildAt(childIndices[counter]); ! fireTreeNodesInserted(this, getPathToRoot(node), childIndices, ! newChildren); ! } ! } ! ! /** ! * Invoke this method after you've removed some TreeNodes from ! * node. childIndices should be the index of the removed elements and ! * must be sorted in ascending order. And removedChildren should be ! * the array of the children objects that were removed. ! */ ! public void nodesWereRemoved(TreeNode node, int[] childIndices, ! Object[] removedChildren) { ! if(node != null && childIndices != null) { ! fireTreeNodesRemoved(this, getPathToRoot(node), childIndices, ! removedChildren); ! } ! } ! /** ! * Invoke this method after you've changed how the children identified by ! * childIndicies are to be represented in the tree. ! */ ! public void nodesChanged(TreeNode node, int[] childIndices) { ! if(node != null) { ! if (childIndices != null) { ! int cCount = childIndices.length; ! ! if(cCount > 0) { ! Object[] cChildren = new Object[cCount]; ! ! for(int counter = 0; counter < cCount; counter++) ! cChildren[counter] = node.getChildAt ! (childIndices[counter]); ! fireTreeNodesChanged(this, getPathToRoot(node), ! childIndices, cChildren); ! } ! } ! else if (node == getRoot()) { ! fireTreeNodesChanged(this, getPathToRoot(node), null, null); ! } ! } ! } ! ! protected void fireTreeNodesChanged(Object source, Object[] path, ! int[] childIndices, ! Object[] children) { ! // Guaranteed to return a non-null array ! Object[] listeners = listenerList.getListenerList(); ! TreeModelEvent e = null; ! // Process the listeners last to first, notifying ! // those that are interested in this event ! for (int i = listeners.length-2; i>=0; i-=2) { ! if (listeners[i]==TreeModelListener.class) { ! // Lazily create the event: ! if (e == null) ! e = new TreeModelEvent(source, path, ! childIndices, children); ! ((TreeModelListener)listeners[i+1]).treeNodesChanged(e); ! } ! } ! } ! protected void fireTreeNodesInserted(Object source, Object[] path, ! int[] childIndices, ! Object[] children) { ! // Guaranteed to return a non-null array ! Object[] listeners = listenerList.getListenerList(); ! TreeModelEvent e = null; ! // Process the listeners last to first, notifying ! // those that are interested in this event ! for (int i = listeners.length-2; i>=0; i-=2) { ! if (listeners[i]==TreeModelListener.class) { ! // Lazily create the event: ! if (e == null) ! e = new TreeModelEvent(source, path, ! childIndices, children); ! ((TreeModelListener)listeners[i+1]).treeNodesInserted(e); ! } ! } ! } ! protected void fireTreeNodesRemoved(Object source, Object[] path, ! int[] childIndices, ! Object[] children) { ! // Guaranteed to return a non-null array ! Object[] listeners = listenerList.getListenerList(); ! TreeModelEvent e = null; ! // Process the listeners last to first, notifying ! // those that are interested in this event ! for (int i = listeners.length-2; i>=0; i-=2) { ! if (listeners[i]==TreeModelListener.class) { ! // Lazily create the event: ! if (e == null) ! e = new TreeModelEvent(source, path, ! childIndices, children); ! ((TreeModelListener)listeners[i+1]).treeNodesRemoved(e); ! } ! } ! } ! protected void fireTreeStructureChanged(Object source, Object[] path, ! int[] childIndices, ! Object[] children) { ! // Guaranteed to return a non-null array ! Object[] listeners = listenerList.getListenerList(); ! TreeModelEvent e = null; ! // Process the listeners last to first, notifying ! // those that are interested in this event ! for (int i = listeners.length-2; i>=0; i-=2) { ! if (listeners[i]==TreeModelListener.class) { ! // Lazily create the event: ! if (e == null) ! e = new TreeModelEvent(source, path, ! childIndices, children); ! ((TreeModelListener)listeners[i+1]).treeStructureChanged(e); ! } ! } ! } ! /** ! * Builds the parents of node up to and including the root node, ! * where the original node is the last element in the returned array. ! * The length of the returned array gives the node's depth in the ! * tree. ! * ! * @param aNode the TreeNode to get the path for ! * @param an array of TreeNodes giving the path from the root to the ! * specified node. */ ! public TreeNode[] getPathToRoot(TreeNode aNode) { ! return getPathToRoot(aNode, 0); } /** ! * Builds the parents of node up to and including the root node, ! * where the original node is the last element in the returned array. ! * The length of the returned array gives the node's depth in the ! * tree. ! * ! * @param aNode the TreeNode to get the path for ! * @param depth an int giving the number of steps already taken towards ! * the root (on recursive calls), used to size the returned array ! * @return an array of TreeNodes giving the path from the root to the ! * specified node */ ! protected TreeNode[] getPathToRoot(TreeNode aNode, int depth) { ! TreeNode[] retNodes; ! // This method recurses, traversing towards the root in order ! // size the array. On the way back, it fills in the nodes, ! // starting from the root and working back to the original node. ! ! /* Check for null, in case someone passed in a null node, or ! they passed in an element that isn't rooted at root. */ ! if(aNode == null) { ! if(depth == 0) ! return null; ! else ! retNodes = new TreeNode[depth]; ! } ! else { ! depth++; ! if(aNode == root) ! retNodes = new TreeNode[depth]; ! else ! retNodes = getPathToRoot(aNode.getParent(), depth); ! retNodes[retNodes.length - depth] = aNode; ! } ! return retNodes; ! } ! ! ! public void insertNodeInto(JreepadNode child, JreepadNode parent, int index) { ! // Does this function need to remove the child from its prior location? ! // parent. } ! ! } // End of: class JreepadTreeModel --- 1,32 ---- package jreepad; ! import javax.swing.tree.DefaultTreeModel; ! import javax.swing.tree.TreePath; + /** + * The tree model. + * + * @version $Id$ + */ + public class JreepadTreeModel extends DefaultTreeModel + { /** ! * Creates the model. ! * ! * @param root root node of the tree */ ! public JreepadTreeModel(JreepadNode root) ! { ! super(root); } /** ! * Sets the title of the given node to the given value. */ ! public void valueForPathChanged(TreePath path, Object newValue) { ! JreepadNode node = (JreepadNode)path.getLastPathComponent(); ! node.setTitle((String)newValue); ! nodeChanged(node); } ! } |
From: Dan S. <dan...@us...> - 2007-01-14 19:43:40
|
Update of /cvsroot/jreepad/jreepad/lib In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv14395/lib Added Files: gnu-regexp-1.1.4-lib.jar Log Message: Added gnu regexp lib. Note that I had to change the JAR filename slightly (by adding "-lib") to get round the weird CVS problem "Assertion `key != ((void *)0)' failed". --- NEW FILE: gnu-regexp-1.1.4-lib.jar --- (This appears to be a binary file; contents omitted.) |
From: PeWu <pe...@us...> - 2007-01-14 17:10:39
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv18551/src/jreepad Modified Files: JreepadView.java Added Files: TreeView.java Log Message: refactoring: extracted TreeView from JreepadView to manage the tree component Index: JreepadView.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadView.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** JreepadView.java 14 Jan 2007 00:21:59 -0000 1.32 --- JreepadView.java 14 Jan 2007 17:10:21 -0000 1.33 *************** *** 20,29 **** package jreepad; ! import javax.swing.*; ! import javax.swing.tree.*; ! import javax.swing.table.*; ! import javax.swing.event.*; ! import javax.swing.undo.*; ! import javax.swing.text.*; import org.philwilson.JTextile; --- 20,73 ---- package jreepad; ! import java.awt.Color; ! import java.awt.Dimension; ! import java.awt.event.ComponentEvent; ! import java.awt.event.ComponentListener; ! import java.awt.event.KeyAdapter; ! import java.awt.event.KeyEvent; ! import java.io.BufferedReader; ! import java.io.File; ! import java.io.FileInputStream; ! import java.io.IOException; ! import java.io.InputStreamReader; ! import java.util.Vector; ! ! import javax.swing.Box; ! import javax.swing.BoxLayout; ! import javax.swing.JComponent; ! import javax.swing.JEditorPane; ! import javax.swing.JOptionPane; ! import javax.swing.JScrollPane; ! import javax.swing.JSplitPane; ! import javax.swing.JTable; ! import javax.swing.JTree; ! import javax.swing.event.CaretEvent; ! import javax.swing.event.CaretListener; ! import javax.swing.event.ChangeEvent; ! import javax.swing.event.ChangeListener; ! import javax.swing.event.DocumentEvent; ! import javax.swing.event.DocumentListener; ! import javax.swing.event.TableModelEvent; ! import javax.swing.event.TableModelListener; ! import javax.swing.event.TreeModelEvent; ! import javax.swing.event.TreeModelListener; ! import javax.swing.event.TreeSelectionEvent; ! import javax.swing.event.TreeSelectionListener; ! import javax.swing.event.UndoableEditEvent; ! import javax.swing.event.UndoableEditListener; ! import javax.swing.table.DefaultTableModel; ! import javax.swing.text.AbstractDocument; ! import javax.swing.text.BadLocationException; ! import javax.swing.text.BoxView; ! import javax.swing.text.ComponentView; ! import javax.swing.text.Document; ! import javax.swing.text.Element; ! import javax.swing.text.IconView; ! import javax.swing.text.LabelView; ! import javax.swing.text.StyleConstants; ! import javax.swing.text.StyledEditorKit; ! import javax.swing.text.View; ! import javax.swing.text.ViewFactory; ! import javax.swing.tree.TreePath; import org.philwilson.JTextile; *************** *** 34,44 **** import edu.stanford.ejalbert.exception.UnsupportedOperatingSystemException; - import java.awt.*; - import java.awt.event.*; - import java.util.Enumeration; - import java.util.Vector; - import java.io.*; - import java.awt.print.*; - public class JreepadView extends Box implements TableModelListener { --- 78,81 ---- *************** *** 91,98 **** private JreepadNode root; private JreepadNode currentNode; - private JreepadNode currentDragDropNode; - private TreeNode topNode; private JreepadTreeModel treeModel; ! private JTree tree; private JScrollPane treeView; private JScrollPane articleView; --- 128,133 ---- private JreepadNode root; private JreepadNode currentNode; private JreepadTreeModel treeModel; ! private TreeView tree; private JScrollPane treeView; private JScrollPane articleView; *************** *** 155,179 **** treeModel.addTreeModelListener(new JreepadTreeModelListener()); ! tree = new JTree(treeModel){ ! public void cancelEditing() ! { ! super.cancelEditing(); // if we can override this perhaps we can prevent blank nodes...? ! JreepadNode lastEditedNode = (JreepadNode)(tree.getSelectionPath().getLastPathComponent()); ! if(lastEditedNode.getTitle().equals("")) ! lastEditedNode.setTitle("<Untitled node>"); ! } ! }; ! tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); ! tree.setExpandsSelectedPaths(true); ! tree.setInvokesStopCellEditing(true); ! tree.setEditable(true); ! ! tree.setModel(treeModel); ! ! DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer(); ! renderer.setOpenIcon(null); ! renderer.setClosedIcon(null); ! renderer.setLeafIcon(null); ! tree.setCellRenderer(renderer); searcher = new JreepadSearcher(root); --- 190,194 ---- treeModel.addTreeModelListener(new JreepadTreeModelListener()); ! tree = new TreeView(treeModel); searcher = new JreepadSearcher(root); *************** *** 199,262 **** }); - // Fiddle with the cell editor - to ensure that when editing a new node, you shouldn't be able to leave a blank title - tree.getCellEditor().addCellEditorListener(new CellEditorListener() - { - public void editingCanceled(ChangeEvent e) - { - ensureNodeTitleIsNotEmpty(e); - } - public void editingStopped(ChangeEvent e) - { - ensureNodeTitleIsNotEmpty(e); - } - }); - - // Add mouse listener - this will be used to implement drag-and-drop, context menu (?), etc - MouseListener ml = new MouseAdapter() - { - public void mousePressed(MouseEvent e) - { - TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); - if(selPath != null) - { - currentDragDropNode = (JreepadNode)selPath.getLastPathComponent(); - setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - } - } - public void mouseReleased(MouseEvent e) - { - TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); - // System.out.println("Mouse released: path = " + selPath); - if(selPath != null) - { - if(currentDragDropNode != null && - currentDragDropNode.getParentNode() != null && - currentDragDropNode.getParentNode() != (JreepadNode)selPath.getLastPathComponent() && - currentDragDropNode != (JreepadNode)selPath.getLastPathComponent()) - { - // Then we need to perform a drag-and-drop operation! - moveNode(currentDragDropNode, (JreepadNode)selPath.getLastPathComponent()); - - // Ensure that the destination node is open - tree.setSelectionPath(selPath.pathByAddingChild(currentDragDropNode)); - } - } - setCursor(Cursor.getDefaultCursor()); - currentDragDropNode = null; - } - public void mouseClicked(MouseEvent e) - { - TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); - if(selPath != null) - { - if(e.isPopupTrigger()) - { - // Now we can implement the pop-up content menu - System.out.println("Context menu would be launched here!"); - } - } - } - }; - tree.addMouseListener(ml); tree.addKeyListener(new KeyAdapter(){public void keyPressed(KeyEvent kee) { --- 214,217 ---- *************** *** 471,516 **** } - public void moveNode(JreepadNode node, JreepadNode newParent) - { - // 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; - } - - //DEL storeForUndo(); - - JreepadNode oldParent = node.getParentNode(); - - // Now make a note of the expanded/collapsed state of the subtree of the moving node - boolean thisOnesExpanded = tree.isExpanded(tree.getSelectionPath()); - Enumeration enumer; - Vector expanded; - if(thisOnesExpanded) - { - enumer = tree.getExpandedDescendants(tree.getSelectionPath()); - expanded = new Vector(); - while(enumer.hasMoreElements()) - { - expanded.add((TreePath)enumer.nextElement()); - // System.out.println(expanded.lastElement()); - } - } - - node.removeFromParent(); - newParent.addChild(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 - // if(newParent.getChildCount()==1) - - - // Reapply the expanded/collapsed states - - } public void indentCurrentNode() --- 426,430 ---- *************** *** 522,526 **** } - int nodeRow = tree.getLeadSelectionRow(); TreePath parentPath = tree.getSelectionPath().getParentPath(); int pos = currentNode.getIndex(); --- 436,439 ---- *************** *** 746,799 **** public void expandAllCurrentNode() { ! expandAll(currentNode, tree.getLeadSelectionPath()); ! } ! public void expandAll(JreepadNode thisNode, TreePath tp) ! { ! // It's at this point that we expand the current element ! tree.expandPath(tp); ! ! Enumeration getKids = thisNode.children(); ! JreepadNode thisKid; ! while(getKids.hasMoreElements()) ! { ! thisKid = (JreepadNode)getKids.nextElement(); ! expandAll(thisKid, tp.pathByAddingChild(thisKid)); ! } } public void collapseAllCurrentNode() { ! collapseAll(currentNode, tree.getLeadSelectionPath()); ! } ! public void collapseAll(JreepadNode thisNode, TreePath tp) ! { ! Enumeration getKids = thisNode.children(); ! JreepadNode thisKid; ! while(getKids.hasMoreElements()) ! { ! thisKid = (JreepadNode)getKids.nextElement(); ! collapseAll(thisKid, tp.pathByAddingChild(thisKid)); ! } ! // It's at this point that we collapse the current element ! tree.collapsePath(tp); } - public TreePath[] getAllExpandedPaths() { ! if(root.getChildCount()==0) ! return new TreePath[] {new TreePath(root)}; ! ! Enumeration getPaths = tree.getExpandedDescendants(new TreePath(root)); ! TreePath thisKid; ! Vector allPaths = new Vector(); ! while(getPaths.hasMoreElements()) ! { ! thisKid = (TreePath)getPaths.nextElement(); ! allPaths.add(thisKid); ! } ! TreePath[] ret = new TreePath[allPaths.size()]; ! for(int i=0; i<ret.length; i++) ! ret[i] = (TreePath)allPaths.get(i); ! return ret; } --- 659,672 ---- public void expandAllCurrentNode() { ! tree.expandAll(currentNode, tree.getLeadSelectionPath()); } public void collapseAllCurrentNode() { ! tree.collapseAll(currentNode, tree.getLeadSelectionPath()); } public TreePath[] getAllExpandedPaths() { ! return tree.getAllExpandedPaths(); } *************** *** 801,808 **** public void expandPaths(TreePath[] paths) { ! for(int i=0; i<paths.length; i++) ! { ! tree.expandPath(paths[i]); ! } } --- 674,678 ---- public void expandPaths(TreePath[] paths) { ! tree.expandPaths(paths); } *************** *** 1478,1497 **** // End of: functions which should allow us to switch between JEditorPane and JTable - private void ensureNodeTitleIsNotEmpty(ChangeEvent e) - { - TreeCellEditor theEditor = (TreeCellEditor)tree.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(tree, "<Untitled node>", true, true, false, 1); - // thatNode.setTitle("<Untitled node>"); - } - } public void editNodeTitleAction() --- 1348,1352 ---- *************** *** 1528,1534 **** { warnAboutUnsaved = true; ! Object[] parentPath = e.getPath(); // Parent of the changed node(s) ! int[] children = e.getChildIndices(); // Indices of the changed node(s) ! JreepadNode parent = (JreepadNode)(parentPath[parentPath.length-1]); tree.repaint(); } --- 1383,1389 ---- { warnAboutUnsaved = true; ! // Object[] parentPath = e.getPath(); // Parent of the changed node(s) ! // int[] children = e.getChildIndices(); // Indices of the changed node(s) ! // JreepadNode parent = (JreepadNode)(parentPath[parentPath.length-1]); tree.repaint(); } --- NEW FILE: TreeView.java --- /* Jreepad - personal information manager. Copyright (C) 2004 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.awt.Cursor; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Enumeration; import java.util.Vector; import javax.swing.JTree; import javax.swing.event.CellEditorListener; import javax.swing.event.ChangeEvent; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.TreeCellEditor; import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; /** * The GUI component that displays the tree. * * @version $Id$ */ public class TreeView extends JTree { private JreepadTreeModel treeModel; public TreeView(JreepadTreeModel treeModel) { super(treeModel); this.treeModel = treeModel; getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); setExpandsSelectedPaths(true); setInvokesStopCellEditing(true); setEditable(true); DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer(); renderer.setOpenIcon(null); renderer.setClosedIcon(null); renderer.setLeafIcon(null); setCellRenderer(renderer); // Fiddle with the cell editor - to ensure that when editing a new node, you shouldn't be // able to leave a blank title getCellEditor().addCellEditorListener(new CellEditorListener() { public void editingCanceled(ChangeEvent e) { ensureNodeTitleIsNotEmpty(e); } public void editingStopped(ChangeEvent e) { ensureNodeTitleIsNotEmpty(e); } }); // Add mouse listener - this will be used to implement drag-and-drop, context menu (?), etc addMouseListener(new TreeViewMouseListener()); } public void cancelEditing() { super.cancelEditing(); // if we can override this perhaps we can prevent blank nodes...? 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) { // 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; } // DEL storeForUndo(); JreepadNode oldParent = node.getParentNode(); // Now make a note of the expanded/collapsed state of the subtree of the moving node boolean thisOnesExpanded = isExpanded(getSelectionPath()); Enumeration enumer; Vector expanded; if (thisOnesExpanded) { enumer = getExpandedDescendants(getSelectionPath()); expanded = new Vector(); while (enumer.hasMoreElements()) { expanded.add((TreePath)enumer.nextElement()); // System.out.println(expanded.lastElement()); } } node.removeFromParent(); newParent.addChild(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 // if(newParent.getChildCount()==1) // Reapply the expanded/collapsed states } public void expandAll(JreepadNode thisNode, TreePath tp) { // It's at this point that we expand the current element expandPath(tp); Enumeration getKids = thisNode.children(); JreepadNode thisKid; while (getKids.hasMoreElements()) { thisKid = (JreepadNode)getKids.nextElement(); expandAll(thisKid, tp.pathByAddingChild(thisKid)); } } public void collapseAll(JreepadNode thisNode, TreePath tp) { Enumeration getKids = thisNode.children(); JreepadNode thisKid; while (getKids.hasMoreElements()) { thisKid = (JreepadNode)getKids.nextElement(); collapseAll(thisKid, tp.pathByAddingChild(thisKid)); } // It's at this point that we collapse the current element collapsePath(tp); } public TreePath[] getAllExpandedPaths() { JreepadNode root = (JreepadNode)treeModel.getRoot(); if (root.getChildCount() == 0) return new TreePath[] { new TreePath(root) }; Enumeration getPaths = getExpandedDescendants(new TreePath(root)); TreePath thisKid; Vector allPaths = new Vector(); while (getPaths.hasMoreElements()) { thisKid = (TreePath)getPaths.nextElement(); allPaths.add(thisKid); } TreePath[] ret = new TreePath[allPaths.size()]; for (int i = 0; i < ret.length; i++) ret[i] = (TreePath)allPaths.get(i); return ret; } // THIS FUNCTION SEEMS TO HAVE NO EFFECT, ON MY MACHINE AT LEAST! WHAT'S GOING ON? public void expandPaths(TreePath[] paths) { for (int i = 0; i < paths.length; i++) { expandPath(paths[i]); } } /** * Mouse control for the Tree View. */ private class TreeViewMouseListener extends MouseAdapter { private JreepadNode currentDragDropNode; public void mousePressed(MouseEvent e) { TreePath selPath = getPathForLocation(e.getX(), e.getY()); if (selPath != null) { currentDragDropNode = (JreepadNode)selPath.getLastPathComponent(); setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } } public void mouseReleased(MouseEvent e) { TreePath selPath = getPathForLocation(e.getX(), e.getY()); // System.out.println("Mouse released: path = " + selPath); if (selPath != null) { if (currentDragDropNode != null && currentDragDropNode.getParentNode() != null && currentDragDropNode.getParentNode() != (JreepadNode)selPath .getLastPathComponent() && currentDragDropNode != (JreepadNode)selPath.getLastPathComponent()) { // Then we need to perform a drag-and-drop operation! moveNode(currentDragDropNode, (JreepadNode)selPath.getLastPathComponent()); // Ensure that the destination node is open setSelectionPath(selPath.pathByAddingChild(currentDragDropNode)); } } setCursor(Cursor.getDefaultCursor()); currentDragDropNode = null; } public void mouseClicked(MouseEvent e) { TreePath selPath = getPathForLocation(e.getX(), e.getY()); if (selPath != null) { if (e.isPopupTrigger()) { // Now we can implement the pop-up content menu System.out.println("Context menu would be launched here!"); } } } } } |
From: PeWu <pe...@us...> - 2007-01-14 16:59:21
|
Update of /cvsroot/jreepad/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv14128 Added Files: .cvsignore Log Message: added .cvsignore for build and dist directories --- NEW FILE: .cvsignore --- build dist |
From: PeWu <pe...@us...> - 2007-01-14 16:58:28
|
Update of /cvsroot/jreepad/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv13732 Added Files: .project .classpath Log Message: added eclipse project files --- NEW FILE: .project --- <?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>jreepad</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> </projectDescription> --- NEW FILE: .classpath --- <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="lib" path="lib/AppleJavaExtensions.jar"/> <classpathentry kind="lib" path="lib/BrowserLauncher2-10rc4.jar"/> <classpathentry kind="lib" path="lib/gnu-regexp-1.1.4.jar"/> <classpathentry kind="lib" path="lib/JTextile-1.2.jar"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="output" path="build"/> </classpath> |
From: PeWu <pe...@us...> - 2007-01-14 03:39:30
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv20660/src/jreepad Modified Files: JreepadNode.java JreepadView.java JreepadViewer.java Log Message: Changed build to use jars with external libraries Index: JreepadView.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadView.java,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** JreepadView.java 25 Aug 2006 11:11:30 -0000 1.31 --- JreepadView.java 14 Jan 2007 00:21:59 -0000 1.32 *************** *** 25,30 **** import javax.swing.event.*; import javax.swing.undo.*; - import javax.swing.text.BadLocationException; import javax.swing.text.*; import java.awt.*; import java.awt.event.*; --- 25,37 ---- import javax.swing.event.*; import javax.swing.undo.*; import javax.swing.text.*; + + import org.philwilson.JTextile; + + import edu.stanford.ejalbert.BrowserLauncher; + import edu.stanford.ejalbert.exception.BrowserLaunchingExecutionException; + import edu.stanford.ejalbert.exception.BrowserLaunchingInitializingException; + import edu.stanford.ejalbert.exception.UnsupportedOperatingSystemException; + import java.awt.*; import java.awt.event.*; *************** *** 69,73 **** } ! private static short paraRightMargin = 0; static class JPParagraphView extends javax.swing.text.ParagraphView { --- 76,80 ---- } ! private static short paraRightMargin = 0; static class JPParagraphView extends javax.swing.text.ParagraphView { *************** *** 98,102 **** private JEditorPane editorPaneHtml; private JTable editorPaneCsv; ! // Undo features --- 105,109 ---- private JEditorPane editorPaneHtml; private JTable editorPaneCsv; ! // Undo features *************** *** 121,125 **** this(new JreepadNode("<Untitled node>", "", null)); } ! public JreepadView(JreepadNode root) { --- 128,132 ---- this(new JreepadNode("<Untitled node>", "", null)); } ! public JreepadView(JreepadNode root) { *************** *** 144,148 **** this.root = root; ! treeModel = new JreepadTreeModel(root); treeModel.addTreeModelListener(new JreepadTreeModelListener()); --- 151,155 ---- this.root = root; ! treeModel = new JreepadTreeModel(root); treeModel.addTreeModelListener(new JreepadTreeModelListener()); *************** *** 161,165 **** tree.setInvokesStopCellEditing(true); tree.setEditable(true); ! tree.setModel(treeModel); --- 168,172 ---- tree.setInvokesStopCellEditing(true); tree.setEditable(true); ! tree.setModel(treeModel); *************** *** 183,194 **** tree.getLastSelectedPathComponent(); if (node == null) return; ! // UNDO DEVELOPMENT: // System.out.println("TreeSelectionListener:valueChanged"); // undoMgr.discardAllEdits(); ! setCurrentNode(node); } ! }); // Fiddle with the cell editor - to ensure that when editing a new node, you shouldn't be able to leave a blank title --- 190,201 ---- tree.getLastSelectedPathComponent(); if (node == null) return; ! // UNDO DEVELOPMENT: // System.out.println("TreeSelectionListener:valueChanged"); // undoMgr.discardAllEdits(); ! setCurrentNode(node); } ! }); // Fiddle with the cell editor - to ensure that when editing a new node, you shouldn't be able to leave a blank title *************** *** 223,234 **** if(selPath != null) { ! if(currentDragDropNode != null && ! currentDragDropNode.getParentNode() != null && ! currentDragDropNode.getParentNode() != (JreepadNode)selPath.getLastPathComponent() && currentDragDropNode != (JreepadNode)selPath.getLastPathComponent()) { // Then we need to perform a drag-and-drop operation! moveNode(currentDragDropNode, (JreepadNode)selPath.getLastPathComponent()); ! // Ensure that the destination node is open tree.setSelectionPath(selPath.pathByAddingChild(currentDragDropNode)); --- 230,241 ---- if(selPath != null) { ! if(currentDragDropNode != null && ! currentDragDropNode.getParentNode() != null && ! currentDragDropNode.getParentNode() != (JreepadNode)selPath.getLastPathComponent() && currentDragDropNode != (JreepadNode)selPath.getLastPathComponent()) { // Then we need to perform a drag-and-drop operation! moveNode(currentDragDropNode, (JreepadNode)selPath.getLastPathComponent()); ! // Ensure that the destination node is open tree.setSelectionPath(selPath.pathByAddingChild(currentDragDropNode)); *************** *** 251,255 **** } }; ! tree.addMouseListener(ml); tree.addKeyListener(new KeyAdapter(){public void keyPressed(KeyEvent kee) { --- 258,262 ---- } }; ! tree.addMouseListener(ml); tree.addKeyListener(new KeyAdapter(){public void keyPressed(KeyEvent kee) { *************** *** 265,270 **** } // System.out.println("Tree detected a keypress: " + kee.getKeyText(kee.getKeyCode()) + " (key code "+ kee.getKeyCode()+")"); ! }}); ! treeView.setViewportView(tree); --- 272,277 ---- } // System.out.println("Tree detected a keypress: " + kee.getKeyText(kee.getKeyCode()) + " (key code "+ kee.getKeyCode()+")"); ! }}); ! treeView.setViewportView(tree); *************** *** 287,291 **** if(currentNode.getArticleMode() != JreepadNode.ARTICLEMODE_ORDINARY) return; // i.e. we are only relevant when in plain-text mode ! if(!editorPanePlainText.getText().equals(currentNode.getContent())) { --- 294,298 ---- if(currentNode.getArticleMode() != JreepadNode.ARTICLEMODE_ORDINARY) return; // i.e. we are only relevant when in plain-text mode ! if(!editorPanePlainText.getText().equals(currentNode.getContent())) { *************** *** 352,356 **** // System.out.println("articleView viewport size: " + articleView.getViewport().getSize()); // System.out.println(); ! switch(mode) { --- 359,363 ---- // System.out.println("articleView viewport size: " + articleView.getViewport().getSize()); // System.out.println(); ! switch(mode) { *************** *** 373,377 **** editorPaneHtml.setPreferredSize(articleView.getViewport().getExtentSize()); editorPaneHtml.setSize(articleView.getViewport().getExtentSize()); ! validate(); repaint(); // System.out.println("editorPane size: " + editorPane.getSize()); --- 380,384 ---- editorPaneHtml.setPreferredSize(articleView.getViewport().getExtentSize()); editorPaneHtml.setSize(articleView.getViewport().getExtentSize()); ! validate(); repaint(); // System.out.println("editorPane size: " + editorPane.getSize()); *************** *** 383,387 **** private void setViewBoth() ! { ensureCorrectArticleRenderMode(); splitPane.setLeftComponent(treeView); --- 390,394 ---- private void setViewBoth() ! { ensureCorrectArticleRenderMode(); splitPane.setLeftComponent(treeView); *************** *** 402,407 **** this.remove(treeView); ensureCorrectArticleRenderMode(); ! this.add(articleView); ! articleView.setSize(getSize()); } /* --- 409,414 ---- this.remove(treeView); ensureCorrectArticleRenderMode(); ! this.add(articleView); ! articleView.setSize(getSize()); } /* *************** *** 423,427 **** if(currentNode.getArticleMode() == JreepadNode.ARTICLEMODE_ORDINARY) currentNode.setContent(getEditorPaneText()); ! return; } --- 430,434 ---- if(currentNode.getArticleMode() == JreepadNode.ARTICLEMODE_ORDINARY) currentNode.setContent(getEditorPaneText()); ! return; } *************** *** 472,478 **** return; } ! //DEL storeForUndo(); ! JreepadNode oldParent = node.getParentNode(); --- 479,485 ---- return; } ! //DEL storeForUndo(); ! JreepadNode oldParent = node.getParentNode(); *************** *** 498,508 **** 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 // if(newParent.getChildCount()==1) ! ! // Reapply the expanded/collapsed states ! } --- 505,515 ---- 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 // if(newParent.getChildCount()==1) ! ! // Reapply the expanded/collapsed states ! } *************** *** 519,527 **** int pos = currentNode.getIndex(); if(pos<1) return; ! //DEL storeForUndo(); ! JreepadNode newParent = ((JreepadNode)currentNode.getParent().getChildAt(pos-1)); ! if(currentNode.indent()) { --- 526,534 ---- int pos = currentNode.getIndex(); if(pos<1) return; ! //DEL storeForUndo(); ! JreepadNode newParent = ((JreepadNode)currentNode.getParent().getChildAt(pos-1)); ! if(currentNode.indent()) { *************** *** 562,566 **** { TreePath nodePath = tree.getSelectionPath(); ! if(currentNode.equals(root)) { --- 569,573 ---- { TreePath nodePath = tree.getSelectionPath(); ! if(currentNode.equals(root)) { *************** *** 568,572 **** return; } ! //DEL storeForUndo(); currentNode.moveUp(); --- 575,579 ---- return; } ! //DEL storeForUndo(); currentNode.moveUp(); *************** *** 589,607 **** tree.setSelectionPath(nodePath); } ! private void notForRootNode() { // FIXME: If there are no child nodes, assume the user needs some advice about adding nodes if(root.isLeaf()) ! JOptionPane.showMessageDialog(this, ! JreepadViewer.lang.getString("MSG_ONLY_ON_CHILDNODES"), JreepadViewer.lang.getString("TITLE_ONLY_ON_CHILDNODES") , JOptionPane.INFORMATION_MESSAGE); ! else return; ! // JOptionPane.showMessageDialog(this, ! // "The root node is currently selected - you can only perform this operation on child nodes.", "Root node is selected" , // JOptionPane.INFORMATION_MESSAGE); } ! protected String getContentForNewNode() { --- 596,614 ---- tree.setSelectionPath(nodePath); } ! private void notForRootNode() { // FIXME: If there are no child nodes, assume the user needs some advice about adding nodes if(root.isLeaf()) ! JOptionPane.showMessageDialog(this, ! JreepadViewer.lang.getString("MSG_ONLY_ON_CHILDNODES"), JreepadViewer.lang.getString("TITLE_ONLY_ON_CHILDNODES") , JOptionPane.INFORMATION_MESSAGE); ! else return; ! // JOptionPane.showMessageDialog(this, ! // "The root node is currently selected - you can only perform this operation on child nodes.", "Root node is selected" , // JOptionPane.INFORMATION_MESSAGE); } ! protected String getContentForNewNode() { *************** *** 611,615 **** return ""; } ! private java.text.DateFormat dateFormat = java.text.DateFormat.getDateInstance(); private String getCurrentDate() --- 618,622 ---- return ""; } ! private java.text.DateFormat dateFormat = java.text.DateFormat.getDateInstance(); private String getCurrentDate() *************** *** 617,626 **** return dateFormat.format(new java.util.Date()); } ! public void insertDate() { if(currentNode.getArticleMode() != JreepadNode.ARTICLEMODE_ORDINARY) return; // May want to fix this later - allow other modes to have the date inserted... ! //DEL storeForUndo(); String theDate = getCurrentDate(); --- 624,633 ---- return dateFormat.format(new java.util.Date()); } ! public void insertDate() { if(currentNode.getArticleMode() != JreepadNode.ARTICLEMODE_ORDINARY) return; // May want to fix this later - allow other modes to have the date inserted... ! //DEL storeForUndo(); String theDate = getCurrentDate(); *************** *** 629,637 **** try { ! editorPanePlainText.setText(doc.getText(0, here) + theDate + ! doc.getText(here, doc.getLength() - here)); ! editorPaneHtml.setText(doc.getText(0, here) + theDate + ! doc.getText(here, doc.getLength() - here)); ! editorPanePlainText.setCaretPosition(here + theDate.length()); } catch(BadLocationException e) --- 636,644 ---- try { ! editorPanePlainText.setText(doc.getText(0, here) + theDate + ! doc.getText(here, doc.getLength() - here)); ! editorPaneHtml.setText(doc.getText(0, here) + theDate + ! doc.getText(here, doc.getLength() - here)); ! editorPanePlainText.setCaretPosition(here + theDate.length()); } catch(BadLocationException e) *************** *** 640,644 **** } } ! public JreepadNode addNodeAbove() { --- 647,651 ---- } } ! public JreepadNode addNodeAbove() { *************** *** 690,694 **** TreePath nodePath = tree.getSelectionPath(); treeModel.nodesWereInserted(currentNode, new int[]{currentNode.getIndex(ret)}); ! // tree.setSelectionPath(nodePath.pathByAddingChild(ret)); tree.scrollPathToVisible(nodePath.pathByAddingChild(ret)); --- 697,701 ---- TreePath nodePath = tree.getSelectionPath(); treeModel.nodesWereInserted(currentNode, new int[]{currentNode.getIndex(ret)}); ! // tree.setSelectionPath(nodePath.pathByAddingChild(ret)); tree.scrollPathToVisible(nodePath.pathByAddingChild(ret)); *************** *** 731,740 **** // System.out.println(currentNode.toFullString()); } ! public void returnFocusToTree() { tree.requestFocus(); } ! public void expandAllCurrentNode() { --- 738,747 ---- // System.out.println(currentNode.toFullString()); } ! public void returnFocusToTree() { tree.requestFocus(); } ! public void expandAllCurrentNode() { *************** *** 745,749 **** // It's at this point that we expand the current element tree.expandPath(tp); ! Enumeration getKids = thisNode.children(); JreepadNode thisKid; --- 752,756 ---- // It's at this point that we expand the current element tree.expandPath(tp); ! Enumeration getKids = thisNode.children(); JreepadNode thisKid; *************** *** 830,834 **** tree.expandPath(tree.getSelectionPath()); } ! public void addChild(JreepadNode newKid) { --- 837,841 ---- tree.expandPath(tree.getSelectionPath()); } ! public void addChild(JreepadNode newKid) { *************** *** 871,875 **** } } ! public static JreepadPrefs getPrefs() { --- 878,882 ---- } } ! public static JreepadPrefs getPrefs() { *************** *** 881,885 **** prefs.save(); } ! /* --- 888,892 ---- prefs.save(); } ! /* *************** *** 894,898 **** if(!canWeUndo()) return; ! // Swap the old root / selectionpath / expandedpaths for the current ones JreepadNode tempRoot = root; --- 901,905 ---- if(!canWeUndo()) return; ! // Swap the old root / selectionpath / expandedpaths for the current ones JreepadNode tempRoot = root; *************** *** 939,948 **** if(url==null || url.length()==0) url = currentNode.getTitle(); ! if((url == null) && (currentNode.getArticleMode()==JreepadNode.ARTICLEMODE_ORDINARY)) { try { ! String text = getEditorPaneText(); int startpos = editorPanePlainText.getCaretPosition(); --- 946,955 ---- if(url==null || url.length()==0) url = currentNode.getTitle(); ! if((url == null) && (currentNode.getArticleMode()==JreepadNode.ARTICLEMODE_ORDINARY)) { try { ! String text = getEditorPaneText(); int startpos = editorPanePlainText.getCaretPosition(); *************** *** 985,989 **** try { ! String text = getEditorPaneText(); int startpos = editorPanePlainText.getCaretPosition(); --- 992,996 ---- try { ! String text = getEditorPaneText(); int startpos = editorPanePlainText.getCaretPosition(); *************** *** 1068,1072 **** return; } ! // Strip quotes off if(url.length()>2 && url.startsWith("\"") && url.endsWith("\"")) --- 1075,1079 ---- return; } ! // Strip quotes off if(url.length()>2 && url.startsWith("\"") && url.endsWith("\"")) *************** *** 1077,1089 **** { if(!followTreepadInternalLink(url)) ! JOptionPane.showMessageDialog(this, ! JreepadViewer.lang.getString("MSG_NODE_NOT_FOUND"), JreepadViewer.lang.getString("TITLE_NODE_NOT_FOUND"), JOptionPane.ERROR_MESSAGE); return; } ! // It's probably a web-link, so let's do something to it and then try and launch it ! /* --- 1084,1096 ---- { if(!followTreepadInternalLink(url)) ! JOptionPane.showMessageDialog(this, ! JreepadViewer.lang.getString("MSG_NODE_NOT_FOUND"), JreepadViewer.lang.getString("TITLE_NODE_NOT_FOUND"), JOptionPane.ERROR_MESSAGE); return; } ! // It's probably a web-link, so let's do something to it and then try and launch it ! /* *************** *** 1115,1129 **** else surl.append(curl[i]); ! try ! { ! BrowserLauncher.openURL(surl.toString()); ! } ! catch(IOException err) ! { ! JOptionPane.showMessageDialog(this, "I/O error while opening URL:\n"+surl+"\n\nThe \"BrowserLauncher\" used to open a URL is an open-source Java library \nseparate from Jreepad itself - i.e. a separate Sourceforge project. \nIt may be a good idea to submit a bug report to\nhttp://sourceforge.net/projects/browserlauncher\n\nIf you do, please remember to supply information about the operating system\nyou are using - which type, and which version.", "Error" , JOptionPane.ERROR_MESSAGE); ! } // } } public boolean followTreepadInternalLink(String url) { --- 1122,1157 ---- else surl.append(curl[i]); ! try ! { ! new BrowserLauncher(null).openURLinBrowser(surl.toString()); ! } ! catch (BrowserLaunchingInitializingException e) ! { ! displayBrowserLauncherException(e, surl.toString()); ! } ! catch (BrowserLaunchingExecutionException e) ! { ! displayBrowserLauncherException(e, surl.toString()); ! } ! catch (UnsupportedOperatingSystemException e) ! { ! displayBrowserLauncherException(e, surl.toString()); ! } // } } + private void displayBrowserLauncherException(Exception e, String url) + { + JOptionPane.showMessageDialog(this, "Error while opening URL:\n" + url + "\n" + + e.getMessage() + "\n\n" + + "The \"BrowserLauncher\" used to open a URL is an open-source Java library \n" + + "separate from Jreepad itself - i.e. a separate Sourceforge project. \n" + + "It may be a good idea to submit a bug report to\n" + + "http://browserlaunch2.sourceforge.net/\n\n" + + "If you do, please remember to supply information about the operating system\n" + + "you are using - which type, and which version.", "Error", + JOptionPane.ERROR_MESSAGE); + } + public boolean followTreepadInternalLink(String url) { *************** *** 1185,1189 **** else newPath = new TreePath(newNode); ! // Now we need to select it... how do we do that? tree.setSelectionPath(newPath); --- 1213,1217 ---- else newPath = new TreePath(newNode); ! // Now we need to select it... how do we do that? tree.setSelectionPath(newPath); *************** *** 1231,1235 **** } return null; ! } // End of: Searching (for wikilike action) --- 1259,1263 ---- } return null; ! } // End of: Searching (for wikilike action) *************** *** 1243,1247 **** warnAboutUnsaved = yo; } ! // public void setTreeFont(Font f) // { --- 1271,1275 ---- warnAboutUnsaved = yo; } ! // public void setTreeFont(Font f) // { *************** *** 1273,1281 **** public void setArticleMode(int newMode) { ! // System.out.println("\n\n\nnode content : " + currentNode.getContent() // + "\neditorPanePlainText contains: " + editorPanePlainText.getText()); ! copyEditorPaneContentToNodeContent = false; // Disables store-for-undo ! currentNode.setContent(editorPanePlainText.getText()); /* --- 1301,1309 ---- public void setArticleMode(int newMode) { ! // System.out.println("\n\n\nnode content : " + currentNode.getContent() // + "\neditorPanePlainText contains: " + editorPanePlainText.getText()); ! copyEditorPaneContentToNodeContent = false; // Disables store-for-undo ! currentNode.setContent(editorPanePlainText.getText()); /* *************** *** 1298,1302 **** { case JreepadNode.ARTICLEMODE_ORDINARY: ! // DELETEME - PLAINTEXT SHOULD NOT BE AFFECTED BY OTHERS editorPanePlainText.setText(currentNode.getContent()); break; --- 1326,1330 ---- { case JreepadNode.ARTICLEMODE_ORDINARY: ! // DELETEME - PLAINTEXT SHOULD NOT BE AFFECTED BY OTHERS editorPanePlainText.setText(currentNode.getContent()); break; *************** *** 1332,1336 **** String[][] rowData = currentNode.interpretContentAsCsv(); String[] columnNames = null; ! // System.out.println("articleToJTable(): rows=" + rowData.length + ", cols="+rowData[0].length); initJTable(rowData, columnNames); --- 1360,1364 ---- String[][] rowData = currentNode.interpretContentAsCsv(); String[] columnNames = null; ! // System.out.println("articleToJTable(): rows=" + rowData.length + ", cols="+rowData[0].length); initJTable(rowData, columnNames); *************** *** 1342,1346 **** for(int i=0; i<columnNames.length; i++) columnNames[i] = " "; ! // System.out.println("articleToJTable(s): rows=" + rowData.length + ", cols="+rowData[0].length); initJTable(rowData, columnNames); --- 1370,1374 ---- for(int i=0; i<columnNames.length; i++) columnNames[i] = " "; ! // System.out.println("articleToJTable(s): rows=" + rowData.length + ", cols="+rowData[0].length); initJTable(rowData, columnNames); *************** *** 1350,1354 **** { editorPaneCsv = new JTable(new ArticleTableModel(rowData, columnNames)); ! // editorPaneCsv = new JTable(new ArticleTableModel(rowData, columnNames), // (getCurrentNode().tblColModel==null ? new ArticleTableColumnModel(): getCurrentNode().tblColModel)); // editorPaneCsv = new JTable(rowData, columnNames); --- 1378,1382 ---- { editorPaneCsv = new JTable(new ArticleTableModel(rowData, columnNames)); ! // editorPaneCsv = new JTable(new ArticleTableModel(rowData, columnNames), // (getCurrentNode().tblColModel==null ? new ArticleTableColumnModel(): getCurrentNode().tblColModel)); // editorPaneCsv = new JTable(rowData, columnNames); *************** *** 1454,1463 **** TreeCellEditor theEditor = (TreeCellEditor)tree.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("")) { --- 1482,1491 ---- TreeCellEditor theEditor = (TreeCellEditor)tree.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("")) { *************** *** 1540,1545 **** super(); } ! ! public boolean isCellEditable(int row, int col) { return false; --- 1568,1573 ---- super(); } ! ! public boolean isCellEditable(int row, int col) { return false; *************** *** 1568,1577 **** implements UndoableEditListener { public void undoableEditHappened(UndoableEditEvent e) { ! //System.out.println("Undoable event is " + (e.getEdit().isSignificant()?"":"NOT ") + "significant"); //System.out.println("Undoable event source: " + e.getEdit()); //Remember the edit and update the menus. ! if(copyEditorPaneContentToNodeContent){ //System.out.println("Storing undoable event for node " + getCurrentNode().getTitle()); --- 1596,1605 ---- implements UndoableEditListener { public void undoableEditHappened(UndoableEditEvent e) { ! //System.out.println("Undoable event is " + (e.getEdit().isSignificant()?"":"NOT ") + "significant"); //System.out.println("Undoable event source: " + e.getEdit()); //Remember the edit and update the menus. ! if(copyEditorPaneContentToNodeContent){ //System.out.println("Storing undoable event for node " + getCurrentNode().getTitle()); *************** *** 1585,1591 **** getCurrentNode().undoMgr.addEdit(e.getEdit()); } ! ! ! //undoAction.updateUndoState(); //redoAction.updateRedoState(); --- 1613,1619 ---- getCurrentNode().undoMgr.addEdit(e.getEdit()); } ! ! ! //undoAction.updateUndoState(); //redoAction.updateRedoState(); *************** *** 1607,1611 **** initColListener(); } ! private void initColListener(){ addColumnModelListener(new TableColumnModelListener() --- 1635,1639 ---- initColListener(); } ! private void initColListener(){ addColumnModelListener(new TableColumnModelListener() *************** *** 1618,1622 **** }); } ! private void storeColumnModel() { --- 1646,1650 ---- }); } ! private void storeColumnModel() { *************** *** 1624,1628 **** getCurrentNode().tblColModel = this; } ! } // End of: class ArticleTableColumnModel */ --- 1652,1656 ---- getCurrentNode().tblColModel = this; } ! } // End of: class ArticleTableColumnModel */ Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** JreepadViewer.java 25 Aug 2006 11:11:30 -0000 1.42 --- JreepadViewer.java 14 Jan 2007 00:23:19 -0000 1.43 *************** *** 31,34 **** --- 31,35 ---- import java.io.*; import java.util.*; + import java.net.MalformedURLException; import java.net.URL; import java.awt.datatransfer.*; *************** *** 38,41 **** --- 39,48 ---- // For reflection and Mac OSX specific things [...1712 lines suppressed...] */ --- 2691,2695 ---- textField.addCaretListener(cl); } ! } // End of class DSpinner */ *************** *** 2743,2747 **** } public void handleQuit(ApplicationEvent ae) { ! // // You MUST setHandled(false) if you want to delay or cancel the quit. // This is important for cross-platform development -- have a universal quit --- 2749,2753 ---- } public void handleQuit(ApplicationEvent ae) { ! // // You MUST setHandled(false) if you want to delay or cancel the quit. // This is important for cross-platform development -- have a universal quit Index: JreepadNode.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadNode.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** JreepadNode.java 12 Mar 2006 15:46:16 -0000 1.18 --- JreepadNode.java 14 Jan 2007 00:20:41 -0000 1.19 *************** *** 27,30 **** --- 27,32 ---- import javax.swing.undo.*; + import org.philwilson.JTextile; + public class JreepadNode implements Serializable, TreeNode, MutableTreeNode, Comparable { *************** *** 84,88 **** Stack nodeStack = new Stack(); nodeStack.push(this); ! String currentLine = bReader.readLine(); // Read the first line, check for treepadness --- 86,90 ---- Stack nodeStack = new Stack(); nodeStack.push(this); ! String currentLine = bReader.readLine(); // Read the first line, check for treepadness *************** *** 111,119 **** else if((currentLine.toLowerCase().startsWith("<treepad") && currentLine.endsWith(">")) ) { ! constructFromHjtInputStream(treeInputStream, autoDetectHtmlArticles, 1, bReader, lineNum, nodeStack, children); } else if((currentLine.toLowerCase().startsWith("<hj-treepad") && currentLine.endsWith(">")) ) ! constructFromHjtInputStream(treeInputStream, autoDetectHtmlArticles, 2, bReader, lineNum, nodeStack, children); else --- 113,121 ---- else if((currentLine.toLowerCase().startsWith("<treepad") && currentLine.endsWith(">")) ) { ! constructFromHjtInputStream(treeInputStream, autoDetectHtmlArticles, 1, bReader, lineNum, nodeStack, children); } else if((currentLine.toLowerCase().startsWith("<hj-treepad") && currentLine.endsWith(">")) ) ! constructFromHjtInputStream(treeInputStream, autoDetectHtmlArticles, 2, bReader, lineNum, nodeStack, children); else *************** *** 155,161 **** private String recursiveCreateFromXmlStream(BufferedReader bReader, String currentXmlContent, int depth) throws IOException { ! // System.out.println("XMLparse recursive: depth "+depth); ! // String currentXmlContent should BEGIN with the <node> tag. This is assumed, and if not true may cause problems! String currentLine; --- 157,163 ---- private String recursiveCreateFromXmlStream(BufferedReader bReader, String currentXmlContent, int depth) throws IOException { ! // System.out.println("XMLparse recursive: depth "+depth); ! // String currentXmlContent should BEGIN with the <node> tag. This is assumed, and if not true may cause problems! String currentLine; *************** *** 204,210 **** // We're reading CONTENT into the current node. currentXmlContent += currentLine; ! // System.out.println("\n\nThe content that I'm currently trying to process is:\n"+currentXmlContent); ! // Look out for <node which tells us we're starting a child startTagOffset = currentXmlContent.indexOf("<node"); --- 206,212 ---- // We're reading CONTENT into the current node. currentXmlContent += currentLine; ! // System.out.println("\n\nThe content that I'm currently trying to process is:\n"+currentXmlContent); ! // Look out for <node which tells us we're starting a child startTagOffset = currentXmlContent.indexOf("<node"); *************** *** 227,231 **** if(readingContent) this.content += xmlUnescapeChars(currentXmlContent.substring(0, startTagOffset)); ! // Having found a child node, we want to STOP adding anything to the current node's content (e.g. newlines...) readingContent = false; --- 229,233 ---- if(readingContent) this.content += xmlUnescapeChars(currentXmlContent.substring(0, startTagOffset)); ! // Having found a child node, we want to STOP adding anything to the current node's content (e.g. newlines...) readingContent = false; *************** *** 234,243 **** babyNode = new JreepadNode(this); //System.out.println("\n\nJust before passing to baby: content is:\n"+currentXmlContent); ! currentXmlContent = babyNode.recursiveCreateFromXmlStream(bReader, currentXmlContent.substring(startTagOffset), depth+1); //System.out.println("\n\nJust after passing to baby: content is:\n"+currentXmlContent); children.add(babyNode); } ! startTagOffset = currentXmlContent.indexOf("<node"); endTagOffset = currentXmlContent.indexOf("</node>"); --- 236,245 ---- babyNode = new JreepadNode(this); //System.out.println("\n\nJust before passing to baby: content is:\n"+currentXmlContent); ! currentXmlContent = babyNode.recursiveCreateFromXmlStream(bReader, currentXmlContent.substring(startTagOffset), depth+1); //System.out.println("\n\nJust after passing to baby: content is:\n"+currentXmlContent); children.add(babyNode); } ! startTagOffset = currentXmlContent.indexOf("<node"); endTagOffset = currentXmlContent.indexOf("</node>"); *************** *** 256,260 **** ! private void constructFromHjtInputStream(InputStreamReader treeInputStream, boolean autoDetectHtmlArticles, int hjtFileFormat, BufferedReader bReader, int lineNum, Stack nodeStack, Vector children --- 258,262 ---- ! private void constructFromHjtInputStream(InputStreamReader treeInputStream, boolean autoDetectHtmlArticles, int hjtFileFormat, BufferedReader bReader, int lineNum, Stack nodeStack, Vector children *************** *** 269,273 **** while( (hjtFileFormat == 2 || (dtLine = bReader.readLine())!=null) ! && (nodeLine = bReader.readLine())!=null && (titleLine = bReader.readLine())!=null && (depthLine = bReader.readLine())!=null) { --- 271,275 ---- while( (hjtFileFormat == 2 || (dtLine = bReader.readLine())!=null) ! && (nodeLine = bReader.readLine())!=null && (titleLine = bReader.readLine())!=null && (depthLine = bReader.readLine())!=null) { *************** *** 335,339 **** Stack nodeStack = new Stack(); nodeStack.push(this); ! int hjtFileFormat = -1; --- 337,341 ---- Stack nodeStack = new Stack(); nodeStack.push(this); ! int hjtFileFormat = -1; *************** *** 347,355 **** else throw new IOException("\"<Treepad>\" tag not found at beginning of file!\n(This can be caused by having the wrong character set specified.)"); ! dtLine = "dt=text"; while( (hjtFileFormat == 2 || (dtLine = bReader.readLine())!=null) ! && (nodeLine = bReader.readLine())!=null && (titleLine = bReader.readLine())!=null && (depthLine = bReader.readLine())!=null) { --- 349,357 ---- else throw new IOException("\"<Treepad>\" tag not found at beginning of file!\n(This can be caused by having the wrong character set specified.)"); ! dtLine = "dt=text"; while( (hjtFileFormat == 2 || (dtLine = bReader.readLine())!=null) ! && (nodeLine = bReader.readLine())!=null && (titleLine = bReader.readLine())!=null && (depthLine = bReader.readLine())!=null) { *************** *** 498,502 **** return ret.toString(); } ! public String articleToHtml(int exportMode, boolean urlsToLinks, String anchorName, int anchorType) { --- 500,504 ---- return ret.toString(); } ! public String articleToHtml(int exportMode, boolean urlsToLinks, String anchorName, int anchorType) { *************** *** 530,534 **** { case EXPORT_HTML_PREFORMATTED: ! return "<pre>" + (urlsToLinks ? urlsToHtmlLinksAndHtmlSpecialChars(getContent(), anchorType) : htmlSpecialChars(getContent()) ) + "</pre>"; --- 532,536 ---- { case EXPORT_HTML_PREFORMATTED: ! return "<pre>" + (urlsToLinks ? urlsToHtmlLinksAndHtmlSpecialChars(getContent(), anchorType) : htmlSpecialChars(getContent()) ) + "</pre>"; *************** *** 547,551 **** } } ! private static String htmlSpecialChars(String in) { --- 549,553 ---- } } ! private static String htmlSpecialChars(String in) { *************** *** 561,565 **** return ret.toString(); } ! // Search through the String, replacing URI-like substrings (containing ://) with HTML links private String urlsToHtmlLinksAndHtmlSpecialChars(String in, int anchorType) --- 563,567 ---- return ret.toString(); } ! // Search through the String, replacing URI-like substrings (containing ://) with HTML links private String urlsToHtmlLinksAndHtmlSpecialChars(String in, int anchorType) *************** *** 577,581 **** // if(c!=CharacterIterator.DONE && currentWord.length()==0) // continue; ! // Check if the current word is a URL - do weird stuff to it if so, else just output it if(currentWord.toString().indexOf("://")>0) --- 579,583 ---- // if(c!=CharacterIterator.DONE && currentWord.length()==0) // continue; ! // Check if the current word is a URL - do weird stuff to it if so, else just output it if(currentWord.toString().indexOf("://")>0) *************** *** 621,627 **** else if(c==CharacterIterator.DONE); else out.append(c); ! currentWord.setLength(0); ! if(c==CharacterIterator.DONE) break; --- 623,629 ---- else if(c==CharacterIterator.DONE); else out.append(c); ! currentWord.setLength(0); ! if(c==CharacterIterator.DONE) break; *************** *** 691,695 **** { StringBuffer ret = new StringBuffer("dt=Text\n<node>\n"); ! ret.append(getTitle() + "\n" + (currentDepth++) + "\n" + getContent() + "\n" // + (currentDepth==1?"ROOTNODEMANIA":"\n") // Not sure why I need to be slightly unusual with the root node... --- 693,697 ---- { StringBuffer ret = new StringBuffer("dt=Text\n<node>\n"); ! ret.append(getTitle() + "\n" + (currentDepth++) + "\n" + getContent() + "\n" // + (currentDepth==1?"ROOTNODEMANIA":"\n") // Not sure why I need to be slightly unusual with the root node... *************** *** 719,723 **** if(child<0 || child > children.size()) return null; ! JreepadNode ret = (JreepadNode)children.remove(child); return ret; --- 721,725 ---- if(child<0 || child > children.size()) return null; ! JreepadNode ret = (JreepadNode)children.remove(child); return ret; *************** *** 805,809 **** int index = getIndex(); if(index<1) return; ! removeFromParent(); getParentNode().insert(this, index-1); --- 807,811 ---- int index = getIndex(); if(index<1) return; ! removeFromParent(); getParentNode().insert(this, index-1); *************** *** 814,818 **** int index = getIndex(); if(index<0 || index >= getParentNode().getChildCount()-1) return; ! removeFromParent(); getParentNode().insert(this, index+1); --- 816,820 ---- int index = getIndex(); if(index<0 || index >= getParentNode().getChildCount()-1) return; ! removeFromParent(); getParentNode().insert(this, index+1); *************** *** 840,844 **** return theChild; } ! public int getIndex(TreeNode child) { --- 842,846 ---- return theChild; } ! public int getIndex(TreeNode child) { *************** *** 858,862 **** return getParent().getIndex(this); } ! public boolean isNodeInSubtree(JreepadNode n) { --- 860,864 ---- return getParent().getIndex(this); } ! public boolean isNodeInSubtree(JreepadNode n) { *************** *** 873,877 **** return false; } ! public void sortChildren() { --- 875,879 ---- return false; } ! public void sortChildren() { *************** *** 961,965 **** return getChildCount()==0; // Is this the correct behaviour? } ! public Enumeration children() { --- 963,967 ---- return getChildCount()==0; // Is this the correct behaviour? } ! public Enumeration children() { *************** *** 1051,1055 **** return ret; } ! public JreepadNode getChildByTitle(String title) { --- 1053,1057 ---- return ret; } ! public JreepadNode getChildByTitle(String title) { *************** *** 1073,1077 **** if(charWidth < 2) return; ! StringBuffer ret = new StringBuffer(); StringCharacterIterator iter = new StringCharacterIterator(content); --- 1075,1079 ---- if(charWidth < 2) return; ! StringBuffer ret = new StringBuffer(); StringCharacterIterator iter = new StringCharacterIterator(content); *************** *** 1087,1094 **** } ret.append(c); ! } content = ret.toString(); } ! public synchronized void stripAllTags() { --- 1089,1096 ---- } ret.append(c); ! } content = ret.toString(); } ! public synchronized void stripAllTags() { *************** *** 1109,1113 **** else if(on) ret.append(c); ! } content = ret.toString(); } --- 1111,1115 ---- else if(on) ret.append(c); ! } content = ret.toString(); } *************** *** 1180,1184 **** int parseMode = CSVPARSE_MODE_EXPECTINGDATA; StringBuffer curData = new StringBuffer(); ! // Go through once to determine the number of rows and columns StringCharacterIterator iter = new StringCharacterIterator(theContent); --- 1182,1186 ---- int parseMode = CSVPARSE_MODE_EXPECTINGDATA; StringBuffer curData = new StringBuffer(); ! // Go through once to determine the number of rows and columns StringCharacterIterator iter = new StringCharacterIterator(theContent); *************** *** 1320,1324 **** return stripControlChars(ret); } ! public String toXmlNoHeader(String encoding, int depth, boolean incChildren) { --- 1322,1326 ---- return stripControlChars(ret); } ! public String toXmlNoHeader(String encoding, int depth, boolean incChildren) { *************** *** 1449,1456 **** implements UndoableEditListener { public void undoableEditHappened(UndoableEditEvent e) { ! //System.out.println("Undoable event is " + (e.getEdit().isSignificant()?"":"NOT ") + "significant"); //System.out.println("Undoable event source: " + e.getEdit()); ! //Remember the edit and update the menus. undoMgr.addEdit(e.getEdit()); --- 1451,1458 ---- implements UndoableEditListener { public void undoableEditHappened(UndoableEditEvent e) { ! //System.out.println("Undoable event is " + (e.getEdit().isSignificant()?"":"NOT ") + "significant"); //System.out.println("Undoable event source: " + e.getEdit()); ! //Remember the edit and update the menus. undoMgr.addEdit(e.getEdit()); |
From: PeWu <pe...@us...> - 2007-01-14 03:39:30
|
Update of /cvsroot/jreepad/jreepad/lib In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv14844/lib Added Files: BrowserLauncher2-10rc4.jar Log Message: Changed build to use jars with external libraries --- NEW FILE: BrowserLauncher2-10rc4.jar --- (This appears to be a binary file; contents omitted.) |
From: PeWu <pe...@us...> - 2007-01-14 03:39:30
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27142/src/jreepad Removed Files: BrowserLauncher.java JTextile.java Log Message: Changed build to use jars with external libraries --- BrowserLauncher.java DELETED --- --- JTextile.java DELETED --- |
From: PeWu <pe...@us...> - 2007-01-14 03:39:29
|
Update of /cvsroot/jreepad/jreepad/lib In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv13400/lib Added Files: jarbundler-1.9.jar Log Message: Changed build to use jars with external libraries --- NEW FILE: jarbundler-1.9.jar --- (This appears to be a binary file; contents omitted.) |