[Jreepad-CVS] jreepad/src/jreepad JreepadView.java,1.36,1.37
Brought to you by:
danstowell
From: PeWu <pe...@us...> - 2007-02-06 11:10:16
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv32050/src/jreepad Modified Files: JreepadView.java Log Message: refactoring: refactored HtmlViewer and TextileViewer from JreepadView Index: JreepadView.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadView.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** JreepadView.java 5 Feb 2007 10:56:43 -0000 1.36 --- JreepadView.java 6 Feb 2007 11:10:11 -0000 1.37 *************** *** 36,40 **** import javax.swing.BoxLayout; import javax.swing.JComponent; - import javax.swing.JEditorPane; import javax.swing.JOptionPane; import javax.swing.JScrollPane; --- 36,39 ---- *************** *** 44,49 **** 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; --- 43,46 ---- *************** *** 54,65 **** import javax.swing.table.DefaultTableModel; import javax.swing.text.BadLocationException; - import javax.swing.text.Document; import javax.swing.tree.TreePath; import jreepad.editor.ContentChangeListener; import jreepad.editor.PlainTextEditor; ! ! import org.philwilson.JTextile; ! import edu.stanford.ejalbert.BrowserLauncher; import edu.stanford.ejalbert.exception.BrowserLaunchingExecutionException; --- 51,60 ---- import javax.swing.table.DefaultTableModel; import javax.swing.text.BadLocationException; import javax.swing.tree.TreePath; import jreepad.editor.ContentChangeListener; + import jreepad.editor.HtmlViewer; import jreepad.editor.PlainTextEditor; ! import jreepad.editor.TextileViewer; import edu.stanford.ejalbert.BrowserLauncher; import edu.stanford.ejalbert.exception.BrowserLaunchingExecutionException; *************** *** 83,89 **** // private JEditorPane editorPane; private PlainTextEditor editorPanePlainText; ! private JEditorPane editorPaneHtml; private JTable editorPaneCsv; // Undo features --- 78,87 ---- // private JEditorPane editorPane; private PlainTextEditor editorPanePlainText; ! private HtmlViewer editorPaneHtml; ! private TextileViewer editorPaneTextile; private JTable editorPaneCsv; + private JComponent currentArticleView; + // Undo features *************** *** 175,184 **** editorPanePlainText = new PlainTextEditor(root.getArticle()); ! editorPaneHtml = new JEditorPanePlus("text/html", root.getContent()); ! editorPaneHtml.setEditable(false); editorPaneCsv = new JTable(new ArticleTableModel()); editorPaneCsv.getModel().addTableModelListener(this); articleView = new JScrollPane(getEditorPaneComponent(), JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); articleView.addComponentListener(new ComponentListener() { --- 173,184 ---- editorPanePlainText = new PlainTextEditor(root.getArticle()); ! editorPaneHtml = new HtmlViewer(root.getArticle()); ! editorPaneTextile = new TextileViewer(root.getArticle()); editorPaneCsv = new JTable(new ArticleTableModel()); editorPaneCsv.getModel().addTableModelListener(this); articleView = new JScrollPane(getEditorPaneComponent(), JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + + /* XXX Is this really needed? articleView.addComponentListener(new ComponentListener() { *************** *** 208,211 **** --- 208,212 ---- } ); + */ editorPanePlainText.setContentChangeListener(new ContentChangeListener() { *************** *** 246,253 **** } setSize(getSize()); ! editorPanePlainText.setPreferredSize(articleView.getViewport().getExtentSize()); ! editorPanePlainText.setSize(articleView.getViewport().getExtentSize()); ! editorPaneHtml.setPreferredSize(articleView.getViewport().getExtentSize()); ! editorPaneHtml.setSize(articleView.getViewport().getExtentSize()); validate(); repaint(); --- 247,252 ---- } setSize(getSize()); ! currentArticleView.setPreferredSize(articleView.getViewport().getExtentSize()); ! currentArticleView.setSize(articleView.getViewport().getExtentSize()); validate(); repaint(); *************** *** 461,475 **** //DEL storeForUndo(); String theDate = getCurrentDate(); - Document doc = editorPanePlainText.getDocument(); - int here = editorPanePlainText.getCaretPosition(); - try - { - editorPaneHtml.setText(doc.getText(0, here) + theDate + - doc.getText(here, doc.getLength() - here)); - } - catch(BadLocationException e) - { - // Simply ignore this - } editorPanePlainText.insertText(theDate); } --- 460,463 ---- *************** *** 657,660 **** --- 645,650 ---- case JreepadArticle.ARTICLEMODE_HTML: return editorPaneHtml.getSelectedText(); + case JreepadArticle.ARTICLEMODE_TEXTILEHTML: + return editorPaneTextile.getSelectedText(); case JreepadArticle.ARTICLEMODE_ORDINARY: default: *************** *** 1070,1074 **** currentNode.getArticle().wrapContentToCharWidth(charWidth); editorPanePlainText.reloadArticle(); ! editorPaneHtml.setText(currentNode.getContent()); setWarnAboutUnsaved(true); } --- 1060,1065 ---- currentNode.getArticle().wrapContentToCharWidth(charWidth); editorPanePlainText.reloadArticle(); ! editorPaneHtml.reloadArticle(); ! editorPaneTextile.reloadArticle(); setWarnAboutUnsaved(true); } *************** *** 1078,1082 **** currentNode.getArticle().stripAllTags(); editorPanePlainText.reloadArticle(); ! editorPaneHtml.setText(currentNode.getContent()); setWarnAboutUnsaved(true); } --- 1069,1074 ---- currentNode.getArticle().stripAllTags(); editorPanePlainText.reloadArticle(); ! editorPaneHtml.reloadArticle(); ! editorPaneTextile.reloadArticle(); setWarnAboutUnsaved(true); } *************** *** 1091,1125 **** currentNode.getArticle().setContent(editorPanePlainText.getText()); - /* - switch(currentNode.getArticleMode()) - { - case JreepadNode.ARTICLEMODE_ORDINARY: - currentNode.setContent(editorPanePlainText.getText()); - break; - case JreepadNode.ARTICLEMODE_HTML: - currentNode.setContent(editorPaneHtml.getText()); - break; - case JreepadNode.ARTICLEMODE_CSV: - currentNode.setContent(jTableContentToCsv()); - break; - default: - return; - } - */ 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())); ! }catch(Exception e){ ! editorPaneHtml.setText(currentNode.getContent()); ! } break; case JreepadArticle.ARTICLEMODE_CSV: --- 1083,1097 ---- currentNode.getArticle().setContent(editorPanePlainText.getText()); switch(newMode) { case JreepadArticle.ARTICLEMODE_ORDINARY: // DELETEME - PLAINTEXT SHOULD NOT BE AFFECTED BY OTHERS ! editorPanePlainText.reloadArticle(); break; case JreepadArticle.ARTICLEMODE_HTML: ! editorPaneHtml.reloadArticle(); break; case JreepadArticle.ARTICLEMODE_TEXTILEHTML: ! editorPaneTextile.reloadArticle(); break; case JreepadArticle.ARTICLEMODE_CSV: *************** *** 1178,1197 **** { if(currentNode==null) ! 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: System.err.println("getEditorPaneComponent() says: JreepadNode.getArticleMode() returned an unrecognised value"); return null; } } String getEditorPaneText() { --- 1150,1179 ---- { if(currentNode==null) ! { ! currentArticleView = editorPanePlainText; ! return currentArticleView; // 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: ! currentArticleView = editorPanePlainText; ! break; case JreepadArticle.ARTICLEMODE_HTML: + currentArticleView = editorPaneHtml; + break; case JreepadArticle.ARTICLEMODE_TEXTILEHTML: ! currentArticleView = editorPaneTextile; ! break; case JreepadArticle.ARTICLEMODE_CSV: ! currentArticleView = editorPaneCsv; ! break; default: System.err.println("getEditorPaneComponent() says: JreepadNode.getArticleMode() returned an unrecognised value"); return null; } + return currentArticleView; } + String getEditorPaneText() { *************** *** 1203,1207 **** return editorPaneHtml.getText(); case JreepadArticle.ARTICLEMODE_TEXTILEHTML: ! return editorPaneHtml.getText(); case JreepadArticle.ARTICLEMODE_CSV: return jTableContentToCsv(); --- 1185,1189 ---- return editorPaneHtml.getText(); case JreepadArticle.ARTICLEMODE_TEXTILEHTML: ! return editorPaneTextile.getText(); case JreepadArticle.ARTICLEMODE_CSV: return jTableContentToCsv(); *************** *** 1213,1268 **** void setEditorPaneText(JreepadArticle a) { ! String s = a.getContent(); ! try{ ! editorPanePlainText.setArticle(a); ! }catch(Exception ex){ ! // This shouldn't cause a problem. So this try-catch is only for debugging really. ! System.err.println("setEditorPaneText(): Exception during editorPanePlainText.setText(s)"); ! System.err.println("String: " + s); ! 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)); ! }catch(Exception e){ ! editorPaneHtml.setText(s); ! } ! break; ! case JreepadArticle.ARTICLEMODE_CSV: articleToJTable(a); - break; - default: - System.err.println("setEditorPaneText() says: JreepadNode.getArticleMode() returned an unrecognised value"); - return; - } - /* - switch(currentNode.getArticleMode()) - { - case JreepadNode.ARTICLEMODE_ORDINARY: - editorPanePlainText.setText(s); - break; - case JreepadNode.ARTICLEMODE_HTML: - editorPaneHtml.setText(s); - break; - case JreepadNode.ARTICLEMODE_CSV: - articleToJTable(s); - break; - default: - System.err.println("setEditorPaneText() says: JreepadNode.getArticleMode() returned an unrecognised value"); - return; - } - */ } // End of: functions which should allow us to switch between JEditorPane and JTable - public void editNodeTitleAction() { --- 1195,1207 ---- void setEditorPaneText(JreepadArticle a) { ! editorPanePlainText.setArticle(a); ! editorPaneHtml.setArticle(a); ! editorPaneTextile.setArticle(a); ! if (a.getArticleMode() == JreepadArticle.ARTICLEMODE_CSV) articleToJTable(a); } // End of: functions which should allow us to switch between JEditorPane and JTable public void editNodeTitleAction() { *************** *** 1339,1343 **** } - public boolean isCellEditable(int row, int col) { return false; --- 1278,1281 ---- *************** *** 1345,1363 **** } // End of: class ArticleTableModel - - class JEditorPanePlus extends JEditorPane implements DocumentListener { - JEditorPanePlus(String type, String text) { - super(type, text); - } - public void changedUpdate(DocumentEvent e){ - setWarnAboutUnsaved(true); - } - public void insertUpdate(DocumentEvent e){ - setWarnAboutUnsaved(true); - } - public void removeUpdate(DocumentEvent e){ - setWarnAboutUnsaved(true); - } - } // End of class JEditorPanePlus - } \ No newline at end of file --- 1283,1285 ---- |