📄 jreepadview.java
字号:
{ // Ask the child to search its descendents childPath = findChildTitled(text, childPath); if(childPath!=null) return childPath; } } return null; } // End of: Searching (for wikilike action) public boolean warnAboutUnsaved() { return warnAboutUnsaved; } void setWarnAboutUnsaved(boolean yo) { warnAboutUnsaved = yo; } // public void setTreeFont(Font f)// {// ((DefaultTreeCellRenderer)tree.getCellRenderer()).setFont(f);// }// public void setArticleFont(Font f)// {// editorPane.setFont(f);// } public void wrapContentToCharWidth(int charWidth) { //DEL storeForUndo(); currentNode.wrapContentToCharWidth(charWidth); editorPanePlainText.setText(currentNode.getContent()); editorPaneHtml.setText(currentNode.getContent()); setWarnAboutUnsaved(true); } public void stripAllTags() { //DEL storeForUndo(); currentNode.stripAllTags(); editorPanePlainText.setText(currentNode.getContent()); editorPaneHtml.setText(currentNode.getContent()); setWarnAboutUnsaved(true); } 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());/* 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 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())); }catch(Exception e){ editorPaneHtml.setText(currentNode.getContent()); } break; case JreepadNode.ARTICLEMODE_CSV: articleToJTable(currentNode.getContent()); break; default: return; } currentNode.setArticleMode(newMode); ensureCorrectArticleRenderMode(); getEditorPaneComponent().repaint(); copyEditorPaneContentToNodeContent = true; // Re-enables store-for-undo } public void ensureCorrectArticleRenderMode() { articleView.setViewportView(getEditorPaneComponent()); } public void articleToJTable() { String[][] rowData = currentNode.interpretContentAsCsv(); String[] columnNames = null; // System.out.println("articleToJTable(): rows=" + rowData.length + ", cols="+rowData[0].length); 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++) columnNames[i] = " "; // System.out.println("articleToJTable(s): rows=" + rowData.length + ", cols="+rowData[0].length); initJTable(rowData, columnNames); } private void initJTable(String[][] rowData, String[] columnNames) { 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);// editorPaneCsv.setModel(new ArticleTableModel()); editorPaneCsv.getModel().addTableModelListener(this); editorPaneCsv.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); editorPaneCsv.setGridColor(Color.GRAY); editorPaneCsv.setShowGrid(true); editorPaneCsv.setShowVerticalLines(true); editorPaneCsv.setShowHorizontalLines(true); } // The following functions allow us to use either a JEditorPane or a JTable to display article data JComponent getEditorPaneComponent() { 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.getArticleMode()) { case JreepadNode.ARTICLEMODE_ORDINARY: return editorPanePlainText; case JreepadNode.ARTICLEMODE_HTML: case JreepadNode.ARTICLEMODE_TEXTILEHTML: return editorPaneHtml; case JreepadNode.ARTICLEMODE_CSV: return editorPaneCsv; default: System.err.println("getEditorPaneComponent() says: JreepadNode.getArticleMode() returned an unrecognised value"); return null; } } 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: System.err.println("getEditorPaneText() says: JreepadNode.getArticleMode() returned an unrecognised value"); return null; } } void setEditorPaneText(String s) { try{ editorPanePlainText.setText(s); }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.getArticleMode()) { case JreepadNode.ARTICLEMODE_ORDINARY: break; case JreepadNode.ARTICLEMODE_HTML: editorPaneHtml.setText(s); break; case JreepadNode.ARTICLEMODE_TEXTILEHTML: try{ editorPaneHtml.setText(JTextile.textile(s)); }catch(Exception e){ editorPaneHtml.setText(s); } break; case JreepadNode.ARTICLEMODE_CSV: articleToJTable(s); 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 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() { tree.startEditingAtPath(tree.getSelectionPath()); } public String jTableContentToCsv() { int w = editorPaneCsv.getColumnCount(); int h = editorPaneCsv.getRowCount(); StringBuffer csv = new StringBuffer(); String quoteMark = getPrefs().addQuotesToCsvOutput ? "\"" : ""; for(int i=0; i<h; i++) { for(int j=0; j<(w-1); j++) csv.append(quoteMark + (String)editorPaneCsv.getValueAt(i,j) + quoteMark + ","); csv.append(quoteMark + (String)editorPaneCsv.getValueAt(i,w-1) + quoteMark + "\n"); } return csv.toString(); } // Called by the TableModelListener interface public void tableChanged(TableModelEvent e) { // System.out.println(" -- tableChanged() -- "); if(currentNode.getArticleMode() == JreepadNode.ARTICLEMODE_CSV) currentNode.setContent(jTableContentToCsv()); } class JreepadTreeModelListener implements TreeModelListener { public void treeNodesChanged(TreeModelEvent e) { 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(); } public void treeNodesInserted(TreeModelEvent e) { warnAboutUnsaved = true; Object[] parentPath = e.getPath(); // Parent of the new node(s) int[] children = e.getChildIndices(); // Indices of the new node(s) JreepadNode parent = (JreepadNode)(parentPath[parentPath.length-1]); tree.expandPath(e.getTreePath()); tree.scrollPathToVisible(e.getTreePath()); tree.repaint(); } public void treeNodesRemoved(TreeModelEvent e) { warnAboutUnsaved = true; Object[] parentPath = e.getPath(); // Parent of the removed node(s) int[] children = e.getChildIndices(); // Indices the node(s) had before they were removed JreepadNode parent = (JreepadNode)(parentPath[parentPath.length-1]); tree.repaint(); } public void treeStructureChanged(TreeModelEvent e) { warnAboutUnsaved = true; Object[] parentPath = e.getPath(); // Parent of the changed node(s) JreepadNode parent = (JreepadNode)(parentPath[parentPath.length-1]); tree.repaint(); } } // End of: class JreepadTreeModelListener class ArticleTableModel extends DefaultTableModel { public ArticleTableModel(Object[][] data, Object[] columnNames){ super(data, columnNames); } public ArticleTableModel(){ super(); } public boolean isCellEditable(int row, int col) { return false; } } // 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 //This one listens for edits that can be undone. protected class JreepadUndoableEditListener 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()); //System.out.println(" Event is " + e.getEdit().getPresentationName() ); //if(getCurrentNode().lastEditStyle != e.getEdit().getPresentationName()){ // System.out.println(" This is a SIGNIFICANT change."); //} //System.out.println(" Content: " + getCurrentNode().getContent()); //System.out.println(" Node undoMgr: " + getCurrentNode().undoMgr); //Thread.currentThread().dumpStack(); getCurrentNode().undoMgr.addEdit(e.getEdit()); } //undoAction.updateUndoState(); //redoAction.updateRedoState(); } }/* class ArticleTableColumnModel extends DefaultTableColumnModel { public ArticleTableColumnModel(){ super(); initColListener(); } private void initColListener(){ addColumnModelListener(new TableColumnModelListener() { public void columnAdded(TableColumnModelEvent e){ storeColumnModel(); } public void columnMarginChanged(ChangeEvent e){ storeColumnModel(); } public void columnMoved(TableColumnModelEvent e){ storeColumnModel(); } public void columnRemoved(TableColumnModelEvent e){ storeColumnModel(); } public void columnSelectionChanged(ListSelectionEvent e){ storeColumnModel();} }); } private void storeColumnModel() { // Simply store the TableColumnModel in the node, for future reference getCurrentNode().tblColModel = this; } } // End of: class ArticleTableColumnModel*/}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -