[Jreepad-CVS] jreepad/src/jreepad JreepadTreeModel.java, 1.2, 1.3 JreepadViewer.java, 1.53, 1.54 Jr
Brought to you by:
danstowell
From: PeWu <pe...@us...> - 2007-03-21 09:40:57
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9373/src/jreepad Modified Files: JreepadTreeModel.java JreepadViewer.java JreepadView.java JreepadArticle.java Log Message: refactoring: moved unsaved document information to TreeModel; moved creating new article content from JreepadView to JreepadArticle Index: JreepadView.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadView.java,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** JreepadView.java 1 Mar 2007 12:11:00 -0000 1.45 --- JreepadView.java 21 Mar 2007 09:40:52 -0000 1.46 *************** *** 27,33 **** import java.io.IOException; import java.io.InputStreamReader; - import java.text.DateFormat; - import java.text.SimpleDateFormat; - import java.util.Date; import java.util.Vector; --- 27,30 ---- *************** *** 85,90 **** private JreepadSearcher searcher; - private boolean warnAboutUnsaved = false; - // Things concerned with the "undo" function //OLD ATTEMPT private JreepadNode oldRootForUndo, oldCurrentNodeForUndo; --- 82,85 ---- *************** *** 94,101 **** public JreepadView() { ! this(new JreepadNode("<Untitled node>", "")); } ! public JreepadView(JreepadNode root) { super(BoxLayout.X_AXIS); --- 89,96 ---- public JreepadView() { ! this(new JreepadTreeModel()); } ! public JreepadView(JreepadTreeModel treeModel) { super(BoxLayout.X_AXIS); *************** *** 118,124 **** ); ! this.root = root; - treeModel = new JreepadTreeModel(root); treeModel.addTreeModelListener(new JreepadTreeModelListener()); --- 113,119 ---- ); ! this.treeModel = treeModel; ! root = (JreepadNode)treeModel.getRoot(); treeModel.addTreeModelListener(new JreepadTreeModelListener()); *************** *** 174,178 **** public void contentChanged() { ! setWarnAboutUnsaved(true); } }); --- 169,173 ---- public void contentChanged() { ! JreepadView.this.treeModel.setContentSaved(false); } }); *************** *** 295,303 **** } - public JreepadNode getRootJreepadNode() - { - return root; - } - public JreepadNode getCurrentNode() { --- 290,293 ---- *************** *** 412,446 **** } - protected String getContentForNewNode() - { - if(prefs.autoDateInArticles) - return getCurrentDate(); // java.text.DateFormat.getDateInstance().format(new java.util.Date()); - else - return ""; - } - - private String getCurrentDate() - { - DateFormat dateFormat = null; - String format = getPrefs().dateFormat; - - if (!format.equals("")) - { - try - { - dateFormat = new SimpleDateFormat(format); - } - catch (IllegalArgumentException e) - { - // Default format will be set - // TODO: Log this - } - } - if (dateFormat == null) - dateFormat = DateFormat.getDateInstance(); - - return dateFormat.format(new Date()); - } - public void insertDate() { --- 402,405 ---- *************** *** 449,453 **** //DEL storeForUndo(); ! String theDate = getCurrentDate(); editorPanePlainText.insertText(theDate); } --- 408,412 ---- //DEL storeForUndo(); ! String theDate = JreepadArticle.getCurrentDate(); editorPanePlainText.insertText(theDate); } *************** *** 468,472 **** JreepadNode parent = currentNode.getParentNode(); JreepadNode ret = parent.addChild(index); ! ret.getArticle().setContent(getContentForNewNode()); treeModel.nodesWereInserted(parent, new int[]{index}); TreePath newPath = (parentPath.pathByAddingChild(ret)); --- 427,431 ---- JreepadNode parent = currentNode.getParentNode(); JreepadNode ret = parent.addChild(index); ! ret.getArticle().setContent(JreepadArticle.getNewContent()); treeModel.nodesWereInserted(parent, new int[]{index}); TreePath newPath = (parentPath.pathByAddingChild(ret)); *************** *** 491,495 **** 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)); --- 450,454 ---- JreepadNode parent = currentNode.getParentNode(); JreepadNode ret = parent.addChild(index+1); ! ret.getArticle().setContent(JreepadArticle.getNewContent()); treeModel.nodesWereInserted(parent, new int[]{index+1}); tree.startEditingAtPath(parentPath.pathByAddingChild(ret)); *************** *** 501,505 **** //DEL storeForUndo(); JreepadNode ret = currentNode.addChild(); ! ret.getArticle().setContent(getContentForNewNode()); TreePath nodePath = tree.getSelectionPath(); treeModel.nodesWereInserted(currentNode, new int[]{currentNode.getIndex(ret)}); --- 460,464 ---- //DEL storeForUndo(); JreepadNode ret = currentNode.addChild(); ! ret.getArticle().setContent(JreepadArticle.getNewContent()); TreePath nodePath = tree.getSelectionPath(); treeModel.nodesWereInserted(currentNode, new int[]{currentNode.getIndex(ret)}); *************** *** 920,933 **** // End of: Searching (for wikilike action) - public boolean warnAboutUnsaved() - { - return warnAboutUnsaved; - } - - void setWarnAboutUnsaved(boolean yo) - { - warnAboutUnsaved = yo; - } - // public void setTreeFont(Font f) // { --- 879,882 ---- *************** *** 944,948 **** currentNode.getArticle().wrapContentToCharWidth(charWidth); currentArticleView.reloadArticle(); ! setWarnAboutUnsaved(true); } --- 893,897 ---- currentNode.getArticle().wrapContentToCharWidth(charWidth); currentArticleView.reloadArticle(); ! treeModel.setContentSaved(false); } *************** *** 952,956 **** currentNode.getArticle().stripAllTags(); currentArticleView.reloadArticle(); ! setWarnAboutUnsaved(true); } --- 901,905 ---- currentNode.getArticle().stripAllTags(); currentArticleView.reloadArticle(); ! treeModel.setContentSaved(false); } *************** *** 1000,1004 **** public void treeNodesChanged(TreeModelEvent e) { ! warnAboutUnsaved = true; tree.repaint(); } --- 949,953 ---- public void treeNodesChanged(TreeModelEvent e) { ! treeModel.setContentSaved(false); tree.repaint(); } *************** *** 1006,1010 **** public void treeNodesInserted(TreeModelEvent e) { ! warnAboutUnsaved = true; tree.expandPath(e.getTreePath()); tree.scrollPathToVisible(e.getTreePath()); --- 955,959 ---- public void treeNodesInserted(TreeModelEvent e) { ! treeModel.setContentSaved(false); tree.expandPath(e.getTreePath()); tree.scrollPathToVisible(e.getTreePath()); *************** *** 1014,1018 **** public void treeNodesRemoved(TreeModelEvent e) { ! warnAboutUnsaved = true; tree.repaint(); } --- 963,967 ---- public void treeNodesRemoved(TreeModelEvent e) { ! treeModel.setContentSaved(false); tree.repaint(); } *************** *** 1020,1024 **** public void treeStructureChanged(TreeModelEvent e) { ! warnAboutUnsaved = true; tree.repaint(); } --- 969,973 ---- public void treeStructureChanged(TreeModelEvent e) { ! treeModel.setContentSaved(false); tree.repaint(); } Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** JreepadViewer.java 20 Mar 2007 10:18:17 -0000 1.53 --- JreepadViewer.java 21 Mar 2007 09:40:52 -0000 1.54 *************** *** 98,101 **** --- 98,102 ---- private Box toolBar, toolBarIconic; private JreepadView theJreepad; + private JreepadTreeModel document; private Container content; // DEPRECATED private File prefsFile = new File(System.getProperty("user.home"), ".jreepref"); *************** *** 244,248 **** content = getContentPane(); ! theJreepad = new JreepadView(); establishMenus(); --- 245,250 ---- content = getContentPane(); ! document = new JreepadTreeModel(); ! theJreepad = new JreepadView(document); establishMenus(); *************** *** 304,308 **** 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; --- 306,311 ---- InputStream in = new FileInputStream(getPrefs().openLocation); JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! document = new JreepadTreeModel(reader.read(in)); ! theJreepad = new JreepadView(document); getPrefs().saveLocation = getPrefs().exportLocation = getPrefs().importLocation = getPrefs().openLocation; *************** *** 312,316 **** getPrefs().saveLocation = getPrefs().openLocation; setTitleBasedOnFilename(getPrefs().openLocation.getName()); ! setWarnAboutUnsaved(false); } catch(IOException err) --- 315,319 ---- getPrefs().saveLocation = getPrefs().openLocation; setTitleBasedOnFilename(getPrefs().openLocation.getName()); ! document.setContentSaved(true); } catch(IOException err) *************** *** 318,322 **** JOptionPane.showMessageDialog(this, err, lang.getString("MSG_LOAD_FILE_FAILED") , JOptionPane.ERROR_MESSAGE); content.remove(theJreepad); ! theJreepad = new JreepadView(new JreepadNode()); content.add(theJreepad); searchDialog.setJreepad(theJreepad); --- 321,326 ---- JOptionPane.showMessageDialog(this, err, lang.getString("MSG_LOAD_FILE_FAILED") , JOptionPane.ERROR_MESSAGE); content.remove(theJreepad); ! document = new JreepadTreeModel(); ! theJreepad = new JreepadView(document); content.add(theJreepad); searchDialog.setJreepad(theJreepad); *************** *** 531,543 **** JMenuItem addAboveMenuItem = new JMenuItem(lang.getString("MENUITEM_ADDABOVE")); //"Add sibling above"); ! addAboveMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.addNodeAbove(); /* theJreepad.returnFocusToTree(); */ setWarnAboutUnsaved(true); updateWindowTitle();}}); editMenu.add(addAboveMenuItem); JMenuItem addBelowMenuItem = new JMenuItem(lang.getString("MENUITEM_ADDBELOW")); //"Add sibling below"); ! addBelowMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.addNodeBelow(); /* theJreepad.returnFocusToTree(); */ setWarnAboutUnsaved(true); updateWindowTitle();}}); editMenu.add(addBelowMenuItem); JMenuItem addChildMenuItem = new JMenuItem(lang.getString("MENUITEM_ADDCHILD")); //"Add child"); ! addChildMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.addNode(); /* theJreepad.returnFocusToTree(); */ setWarnAboutUnsaved(true);updateWindowTitle(); }}); editMenu.add(addChildMenuItem); --- 535,547 ---- JMenuItem addAboveMenuItem = new JMenuItem(lang.getString("MENUITEM_ADDABOVE")); //"Add sibling above"); ! addAboveMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.addNodeAbove(); /* theJreepad.returnFocusToTree(); */ document.setContentSaved(false); updateWindowTitle();}}); editMenu.add(addAboveMenuItem); JMenuItem addBelowMenuItem = new JMenuItem(lang.getString("MENUITEM_ADDBELOW")); //"Add sibling below"); ! addBelowMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.addNodeBelow(); /* theJreepad.returnFocusToTree(); */ document.setContentSaved(false); updateWindowTitle();}}); editMenu.add(addBelowMenuItem); JMenuItem addChildMenuItem = new JMenuItem(lang.getString("MENUITEM_ADDCHILD")); //"Add child"); ! addChildMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.addNode(); /* theJreepad.returnFocusToTree(); */ document.setContentSaved(false);updateWindowTitle(); }}); editMenu.add(addChildMenuItem); *************** *** 563,571 **** JMenuItem upMenuItem = new JMenuItem(lang.getString("MENUITEM_MOVEUP")); //"Move node up"); ! upMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.moveCurrentNodeUp(); theJreepad.returnFocusToTree(); setWarnAboutUnsaved(true);updateWindowTitle(); }}); editMenu.add(upMenuItem); JMenuItem downMenuItem = new JMenuItem(lang.getString("MENUITEM_MOVEDOWN")); //"Move node down"); ! downMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.moveCurrentNodeDown(); theJreepad.returnFocusToTree(); setWarnAboutUnsaved(true);updateWindowTitle(); }}); editMenu.add(downMenuItem); --- 567,575 ---- JMenuItem upMenuItem = new JMenuItem(lang.getString("MENUITEM_MOVEUP")); //"Move node up"); ! upMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.moveCurrentNodeUp(); theJreepad.returnFocusToTree(); document.setContentSaved(false);updateWindowTitle(); }}); editMenu.add(upMenuItem); JMenuItem downMenuItem = new JMenuItem(lang.getString("MENUITEM_MOVEDOWN")); //"Move node down"); ! downMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.moveCurrentNodeDown(); theJreepad.returnFocusToTree(); document.setContentSaved(false);updateWindowTitle(); }}); editMenu.add(downMenuItem); *************** *** 573,581 **** JMenuItem indentMenuItem = new JMenuItem(lang.getString("MENUITEM_MOVEIN")); //"Indent node (demote)"); ! indentMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.indentCurrentNode(); theJreepad.returnFocusToTree(); setWarnAboutUnsaved(true);updateWindowTitle(); }}); editMenu.add(indentMenuItem); JMenuItem outdentMenuItem = new JMenuItem(lang.getString("MENUITEM_MOVEOUT")); //"Outdent node (promote)"); ! outdentMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.outdentCurrentNode(); theJreepad.returnFocusToTree(); setWarnAboutUnsaved(true);updateWindowTitle(); }}); editMenu.add(outdentMenuItem); --- 577,585 ---- JMenuItem indentMenuItem = new JMenuItem(lang.getString("MENUITEM_MOVEIN")); //"Indent node (demote)"); ! indentMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.indentCurrentNode(); theJreepad.returnFocusToTree(); document.setContentSaved(false);updateWindowTitle(); }}); editMenu.add(indentMenuItem); JMenuItem outdentMenuItem = new JMenuItem(lang.getString("MENUITEM_MOVEOUT")); //"Outdent node (promote)"); ! outdentMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.outdentCurrentNode(); theJreepad.returnFocusToTree(); document.setContentSaved(false);updateWindowTitle(); }}); editMenu.add(outdentMenuItem); *************** *** 682,690 **** JMenuItem sortMenuItem = new JMenuItem(lang.getString("MENUITEM_SORTONELEVEL")); //"Sort children (one level)"); ! sortMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.sortChildren(); setWarnAboutUnsaved(true);updateWindowTitle(); }}); actionsMenu.add(sortMenuItem); JMenuItem sortRecursiveMenuItem = new JMenuItem(lang.getString("MENUITEM_SORTALLLEVELS")); //"Sort children (all levels)"); ! sortRecursiveMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.sortChildrenRecursive(); setWarnAboutUnsaved(true);updateWindowTitle(); }}); actionsMenu.add(sortRecursiveMenuItem); --- 686,694 ---- JMenuItem sortMenuItem = new JMenuItem(lang.getString("MENUITEM_SORTONELEVEL")); //"Sort children (one level)"); ! sortMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.sortChildren(); document.setContentSaved(false);updateWindowTitle(); }}); actionsMenu.add(sortMenuItem); JMenuItem sortRecursiveMenuItem = new JMenuItem(lang.getString("MENUITEM_SORTALLLEVELS")); //"Sort children (all levels)"); ! sortRecursiveMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.sortChildrenRecursive(); document.setContentSaved(false);updateWindowTitle(); }}); actionsMenu.add(sortRecursiveMenuItem); *************** *** 927,939 **** // Add the actions to the toolbar buttons upButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.moveCurrentNodeUp(); repaint(); theJreepad.returnFocusToTree(); setWarnAboutUnsaved(true);updateWindowTitle();} }); downButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.moveCurrentNodeDown(); repaint(); theJreepad.returnFocusToTree(); setWarnAboutUnsaved(true);updateWindowTitle();} }); indentButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.indentCurrentNode(); repaint(); theJreepad.returnFocusToTree(); setWarnAboutUnsaved(true);updateWindowTitle();} }); outdentButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.outdentCurrentNode(); repaint(); theJreepad.returnFocusToTree(); setWarnAboutUnsaved(true);updateWindowTitle(); } }); --- 931,943 ---- // Add the actions to the toolbar buttons upButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.moveCurrentNodeUp(); repaint(); theJreepad.returnFocusToTree(); document.setContentSaved(false);updateWindowTitle();} }); downButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.moveCurrentNodeDown(); repaint(); theJreepad.returnFocusToTree(); document.setContentSaved(false);updateWindowTitle();} }); indentButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.indentCurrentNode(); repaint(); theJreepad.returnFocusToTree(); document.setContentSaved(false);updateWindowTitle();} }); outdentButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.outdentCurrentNode(); repaint(); theJreepad.returnFocusToTree(); document.setContentSaved(false);updateWindowTitle(); } }); *************** *** 941,949 **** addAboveButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.addNodeAbove(); repaint(); /* theJreepad.returnFocusToTree(); */ setWarnAboutUnsaved(true);updateWindowTitle();} }); addBelowButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.addNodeBelow(); repaint(); /* theJreepad.returnFocusToTree(); */ setWarnAboutUnsaved(true);updateWindowTitle();} }); addButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.addNode(); repaint(); /* theJreepad.returnFocusToTree(); */ setWarnAboutUnsaved(true);updateWindowTitle();} }); removeButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ deleteNodeAction(); } }); --- 945,953 ---- addAboveButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.addNodeAbove(); repaint(); /* theJreepad.returnFocusToTree(); */ document.setContentSaved(false);updateWindowTitle();} }); addBelowButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.addNodeBelow(); repaint(); /* theJreepad.returnFocusToTree(); */ document.setContentSaved(false);updateWindowTitle();} }); addButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.addNode(); repaint(); /* theJreepad.returnFocusToTree(); */ document.setContentSaved(false);updateWindowTitle();} }); removeButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ deleteNodeAction(); } }); *************** *** 1034,1062 **** public void actionPerformed(ActionEvent e){ theJreepad.moveCurrentNodeUp(); repaint(); theJreepad.returnFocusToTree(); ! setWarnAboutUnsaved(true);updateWindowTitle();} }); downIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.moveCurrentNodeDown(); repaint(); theJreepad.returnFocusToTree(); ! setWarnAboutUnsaved(true);updateWindowTitle();} }); indentIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.indentCurrentNode(); repaint(); theJreepad.returnFocusToTree(); ! setWarnAboutUnsaved(true);updateWindowTitle();} }); outdentIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.outdentCurrentNode(); repaint(); theJreepad.returnFocusToTree(); ! setWarnAboutUnsaved(true);updateWindowTitle(); } }); addAboveIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.addNodeAbove(); repaint(); /* theJreepad.returnFocusToTree(); */ ! setWarnAboutUnsaved(true);updateWindowTitle();} }); addBelowIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.addNodeBelow(); repaint(); /* theJreepad.returnFocusToTree(); */ ! setWarnAboutUnsaved(true);updateWindowTitle();} }); addIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.addNode(); repaint(); /* theJreepad.returnFocusToTree(); */ ! setWarnAboutUnsaved(true);updateWindowTitle();} }); removeIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ deleteNodeAction(); } }); --- 1038,1066 ---- public void actionPerformed(ActionEvent e){ theJreepad.moveCurrentNodeUp(); repaint(); theJreepad.returnFocusToTree(); ! document.setContentSaved(false);updateWindowTitle();} }); downIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.moveCurrentNodeDown(); repaint(); theJreepad.returnFocusToTree(); ! document.setContentSaved(false);updateWindowTitle();} }); indentIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.indentCurrentNode(); repaint(); theJreepad.returnFocusToTree(); ! document.setContentSaved(false);updateWindowTitle();} }); outdentIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.outdentCurrentNode(); repaint(); theJreepad.returnFocusToTree(); ! document.setContentSaved(false);updateWindowTitle(); } }); addAboveIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.addNodeAbove(); repaint(); /* theJreepad.returnFocusToTree(); */ ! document.setContentSaved(false);updateWindowTitle();} }); addBelowIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.addNodeBelow(); repaint(); /* theJreepad.returnFocusToTree(); */ ! document.setContentSaved(false);updateWindowTitle();} }); addIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.addNode(); repaint(); /* theJreepad.returnFocusToTree(); */ ! document.setContentSaved(false);updateWindowTitle();} }); removeIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ deleteNodeAction(); } }); *************** *** 1270,1274 **** /** ! * Ask the user whether to save the current file. * @param prompt message to display * @return true if the user clicked "Yes" and the save was successful or the user clicked "No" or the file didn't need to be saved; --- 1274,1278 ---- /** ! * Ask the user whether to save the current file if it is unsaved. * @param prompt message to display * @return true if the user clicked "Yes" and the save was successful or the user clicked "No" or the file didn't need to be saved; *************** *** 1277,1281 **** private boolean askAndSave(String prompt) { ! if (!warnAboutUnsaved()) return true; int answer = JOptionPane.showConfirmDialog(this, prompt, --- 1281,1285 ---- private boolean askAndSave(String prompt) { ! if (document == null || document.isContentSaved()) return true; int answer = JOptionPane.showConfirmDialog(this, prompt, *************** *** 1299,1303 **** content.remove(theJreepad); ! theJreepad = new JreepadView(new JreepadNode("<Untitled node>",theJreepad.getContentForNewNode())); getPrefs().saveLocation = null; content.add(theJreepad); --- 1303,1308 ---- content.remove(theJreepad); ! document = new JreepadTreeModel(); ! theJreepad = new JreepadView(document); getPrefs().saveLocation = null; content.add(theJreepad); *************** *** 1307,1311 **** validate(); repaint(); ! setWarnAboutUnsaved(false); updateUndoRedoMenuState(); // theJreepad.clearUndoCache(); --- 1312,1316 ---- validate(); repaint(); ! document.setContentSaved(true); updateUndoRedoMenuState(); // theJreepad.clearUndoCache(); *************** *** 1333,1337 **** InputStream in = new FileInputStream(getPrefs().openLocation); JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! theJreepad = new JreepadView(reader.read(in)); getPrefs().saveLocation = getPrefs().openLocation; --- 1338,1343 ---- InputStream in = new FileInputStream(getPrefs().openLocation); JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! document = new JreepadTreeModel(reader.read(in)); ! theJreepad = new JreepadView(document); getPrefs().saveLocation = getPrefs().openLocation; *************** *** 1343,1347 **** validate(); repaint(); ! setWarnAboutUnsaved(false); //DEL theJreepad.clearUndoCache(); setCursor(Cursor.getDefaultCursor()); --- 1349,1353 ---- validate(); repaint(); ! document.setContentSaved(true); //DEL theJreepad.clearUndoCache(); setCursor(Cursor.getDefaultCursor()); *************** *** 1401,1405 **** fileChooser.setFileFilter(TREEPAD_FILE_FILTER); ! fileChooser.setSelectedFile(new File(theJreepad.getRootJreepadNode().getTitle() + (fileType==JreepadPrefs.FILETYPE_XML?".jree":".hjt"))); if(fileChooser.showSaveDialog(JreepadViewer.this) != JFileChooser.APPROVE_OPTION) --- 1407,1411 ---- fileChooser.setFileFilter(TREEPAD_FILE_FILTER); ! fileChooser.setSelectedFile(new File(document.getRootNode().getTitle() + (fileType==JreepadPrefs.FILETYPE_XML?".jree":".hjt"))); if(fileChooser.showSaveDialog(JreepadViewer.this) != JFileChooser.APPROVE_OPTION) *************** *** 1427,1431 **** writer = new TreepadWriter(getPrefs().getEncoding()); OutputStream fos = new FileOutputStream(getPrefs().saveLocation); ! writer.write(fos, theJreepad.getRootJreepadNode()); fos.close(); --- 1433,1437 ---- writer = new TreepadWriter(getPrefs().getEncoding()); OutputStream fos = new FileOutputStream(getPrefs().saveLocation); ! writer.write(fos, document.getRootNode()); fos.close(); *************** *** 1434,1438 **** appleAppCode, appleAppCode); } ! setWarnAboutUnsaved(false); updateWindowTitle(); savePreferencesFile(); --- 1440,1444 ---- appleAppCode, appleAppCode); } ! document.setContentSaved(true); updateWindowTitle(); savePreferencesFile(); *************** *** 1467,1471 **** JreepadWriter writer = new TreepadWriter(getPrefs().getEncoding()); OutputStream fos = new FileOutputStream(getPrefs().backupLocation); ! writer.write(fos, theJreepad.getRootJreepadNode()); fos.close(); --- 1473,1477 ---- JreepadWriter writer = new TreepadWriter(getPrefs().getEncoding()); OutputStream fos = new FileOutputStream(getPrefs().backupLocation); ! writer.write(fos, document.getRootNode()); fos.close(); *************** *** 1496,1500 **** private void updateWindowTitle() { ! setTitle(windowTitle + (warnAboutUnsaved()?"*":"") + (getPrefs().autoSave?" ["+lang.getString("AUTOSAVE_ACTIVE")+"]":"")); } --- 1502,1506 ---- private void updateWindowTitle() { ! setTitle(windowTitle + ((document == null || document.isContentSaved())?"":"*") + (getPrefs().autoSave?" ["+lang.getString("AUTOSAVE_ACTIVE")+"]":"")); } *************** *** 1541,1545 **** return; } ! setWarnAboutUnsaved(true); updateWindowTitle(); } --- 1547,1551 ---- return; } ! document.setContentSaved(false); updateWindowTitle(); } *************** *** 1899,1903 **** theJreepad.removeNode(); theJreepad.returnFocusToTree(); ! setWarnAboutUnsaved(true); updateWindowTitle(); } --- 1905,1909 ---- theJreepad.removeNode(); theJreepad.returnFocusToTree(); ! document.setContentSaved(false); updateWindowTitle(); } *************** *** 1932,1944 **** } - private boolean warnAboutUnsaved() - { - return theJreepad.warnAboutUnsaved(); - } - private void setWarnAboutUnsaved(boolean yo) - { - theJreepad.setWarnAboutUnsaved(yo); - } - public void wrapContentToCharWidth() { --- 1938,1941 ---- Index: JreepadArticle.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadArticle.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JreepadArticle.java 26 Jan 2007 21:47:55 -0000 1.1 --- JreepadArticle.java 21 Mar 2007 09:40:52 -0000 1.2 *************** *** 21,25 **** --- 21,28 ---- import java.text.CharacterIterator; + import java.text.DateFormat; + import java.text.SimpleDateFormat; import java.text.StringCharacterIterator; + import java.util.Date; import javax.swing.undo.UndoManager; *************** *** 34,37 **** --- 37,45 ---- public class JreepadArticle { + /** + * The default name for unnamed nodes. + */ + public static final String UNTITLED_NODE_TEXT = "<Untitled node>"; + public static final int ARTICLEMODE_ORDINARY = 1; public static final int ARTICLEMODE_HTML = 2; *************** *** 61,70 **** public JreepadArticle() { ! this(""); } public JreepadArticle(String content) { ! this("", content); } --- 69,78 ---- public JreepadArticle() { ! this(getNewContent()); } public JreepadArticle(String content) { ! this(UNTITLED_NODE_TEXT, content); } *************** *** 76,80 **** public JreepadArticle(String title, String content, int articleMode) { ! this.title = title; this.content = content; this.articleMode = articleMode; --- 84,91 ---- public JreepadArticle(String title, String content, int articleMode) { ! if (title == null || title.equals("")) ! this.title = UNTITLED_NODE_TEXT; ! else ! this.title = title; this.content = content; this.articleMode = articleMode; *************** *** 109,113 **** public void setTitle(String title) { ! this.title = title; } --- 120,127 ---- public void setTitle(String title) { ! if (title == null || title.equals("")) ! this.title = UNTITLED_NODE_TEXT; ! else ! this.title = title; } *************** *** 500,502 **** --- 514,554 ---- setContent(o.toString()); } + + /** + * Returns the content for a new node. It is either empty or with a timestamp. + */ + public static String getNewContent() + { + if (JreepadView.getPrefs().autoDateInArticles) + return getCurrentDate(); + return ""; + } + + /** + * Returns the current time and date. The date is formatted acording to the + * preferences. If the format is not set in thepreferences, the default + * format is used. + */ + public static String getCurrentDate() + { + DateFormat dateFormat = null; + String format = JreepadView.getPrefs().dateFormat; + + if (!format.equals("")) + { + try + { + dateFormat = new SimpleDateFormat(format); + } + catch (IllegalArgumentException e) + { + // Default format will be set + // TODO: Log this + } + } + if (dateFormat == null) + dateFormat = DateFormat.getDateInstance(); + + return dateFormat.format(new Date()); + } } Index: JreepadTreeModel.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadTreeModel.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** JreepadTreeModel.java 15 Jan 2007 14:44:45 -0000 1.2 --- JreepadTreeModel.java 21 Mar 2007 09:40:52 -0000 1.3 *************** *** 12,15 **** --- 12,25 ---- { /** + * True if the current document content has been saved. + */ + private boolean contentSaved = false; + + public JreepadTreeModel() + { + this(new JreepadNode()); + } + + /** * Creates the model. * *************** *** 26,32 **** public void valueForPathChanged(TreePath path, Object newValue) { ! JreepadNode node = (JreepadNode)path.getLastPathComponent(); ! node.setTitle((String)newValue); nodeChanged(node); } } --- 36,69 ---- public void valueForPathChanged(TreePath path, Object newValue) { ! JreepadNode node = (JreepadNode) path.getLastPathComponent(); ! node.setTitle((String) newValue); nodeChanged(node); } + + /** + * Returns the root tree node. + */ + public JreepadNode getRootNode() + { + return (JreepadNode) getRoot(); + } + + /** + * Returns true if the current document content has been saved. + */ + public boolean isContentSaved() + { + return contentSaved; + } + + /** + * Sets the information whether the current document content has been saved + * or not. + * + * @param contentSaved + */ + public void setContentSaved(boolean contentSaved) + { + this.contentSaved = contentSaved; + } } |