[Jreepad-CVS] jreepad/src/jreepad JreepadArticle.java, NONE, 1.1 JreepadViewer.java, 1.47, 1.48 Jre
Brought to you by:
danstowell
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(); ! } ! } ! */ } |