jreepad-cvs Mailing List for Jreepad - Java Treepad Editor
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-09-28 21:54:46
|
Update of /cvsroot/jreepad/jreepad/src/jreepad/io In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv31373/src/jreepad/io Modified Files: AutoDetectReader.java XmlReader.java XmlWriter.java Log Message: Using SAX for reading and writing XML Index: AutoDetectReader.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/AutoDetectReader.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AutoDetectReader.java 28 Sep 2007 14:29:22 -0000 1.3 --- AutoDetectReader.java 28 Sep 2007 21:54:41 -0000 1.4 *************** *** 58,76 **** if (currentLine.startsWith("<?xml")) { - // 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); } --- 58,61 ---- Index: XmlReader.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/XmlReader.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** XmlReader.java 3 Apr 2007 12:41:30 -0000 1.4 --- XmlReader.java 28 Sep 2007 21:54:41 -0000 1.5 *************** *** 20,27 **** package jreepad.io; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; ! import java.io.InputStreamReader; import jreepad.JreepadArticle; --- 20,29 ---- package jreepad.io; import java.io.IOException; import java.io.InputStream; ! ! import javax.xml.parsers.ParserConfigurationException; ! import javax.xml.parsers.SAXParser; ! import javax.xml.parsers.SAXParserFactory; import jreepad.JreepadArticle; *************** *** 30,33 **** --- 32,39 ---- import jreepad.JreepadTreeModel; + import org.xml.sax.Attributes; + import org.xml.sax.SAXException; + import org.xml.sax.helpers.DefaultHandler; + /** * Reads XML input into Jreepad. *************** *** 37,273 **** public class XmlReader implements JreepadReader { ! private String encoding; ! ! public XmlReader() ! { ! this(null); ! } ! ! public XmlReader(String encoding) ! { ! this.encoding = encoding; ! } public JreepadTreeModel 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); ! JreepadTreeModel document = new JreepadTreeModel(readNode(reader, currentXmlContent, 0).node); document.setFileType(JreepadPrefs.FILETYPE_XML); - document.setEncoding(encoding); return document; } ! // 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.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)); ! ! // 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.getArticle().setContent(content); ! return new ReturnValue(returnFromBaby, node); ! } ! else ! { ! if (readingContent) ! { ! content += xmlUnescapeChars(currentXmlContent.substring(0, startTagOffset)); ! node.getArticle().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.getArticle().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; } } --- 43,131 ---- public class XmlReader implements JreepadReader { ! public static final String NODE_TAG = "node"; ! public static final String TITLE_ATTRIBUTE = "title"; ! public static final String TYPE_ATTRIBUTE = "type"; public JreepadTreeModel read(InputStream in) throws IOException { ! SAXParserFactory factory = SAXParserFactory.newInstance(); ! Handler handler = null; ! try { ! SAXParser parser = factory.newSAXParser(); ! handler = new Handler(); ! parser.parse(in, handler); ! } ! catch (ParserConfigurationException e) ! { ! throw new IOException(e); ! } ! catch (SAXException e) ! { ! throw new IOException(e); } ! JreepadTreeModel document = new JreepadTreeModel(handler.getRoot()); document.setFileType(JreepadPrefs.FILETYPE_XML); return document; } ! private class Handler extends DefaultHandler { + JreepadNode root = null; + JreepadNode currentNode = null; + StringBuffer content = null; + int articleMode; ! public void characters(char[] ch, int start, int length) throws SAXException { ! if (content != null) ! content.append(ch, start, length); ! } ! public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException ! { ! if (!qName.equals(NODE_TAG)) ! throw new SAXException("Unknown tag " + qName); ! // Save node content ! if (currentNode != null && content != null) ! currentNode.getArticle().setContent(content.toString()); ! content = new StringBuffer(); ! String title = attributes.getValue(TITLE_ATTRIBUTE); ! String type = attributes.getValue(TYPE_ATTRIBUTE); ! JreepadNode newNode = new JreepadNode(title, ""); ! if (currentNode != null) ! currentNode.add(newNode); ! currentNode = newNode; ! if (root == null) ! root = currentNode; ! int articleMode = JreepadArticle.ARTICLEMODE_ORDINARY; ! if (type.equals("text/csv")) ! articleMode = JreepadArticle.ARTICLEMODE_CSV; ! else if (type.equals("text/html")) ! articleMode = JreepadArticle.ARTICLEMODE_HTML; ! else if (type.equals("text/textile")) ! articleMode = JreepadArticle.ARTICLEMODE_TEXTILEHTML; ! //else if (type.equals("application/x-jreepad-softlink")) ! // articleMode = JreepadArticle.ARTICLEMODE_SOFTLINK; ! currentNode.getArticle().setArticleMode(articleMode); ! } ! public void endElement(String uri, String localName, String qName) throws SAXException ! { ! if (content != null) ! currentNode.getArticle().setContent(content.toString()); ! currentNode = currentNode.getParentNode(); ! content = null; ! } ! public JreepadNode getRoot() { ! return root; } } Index: XmlWriter.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/XmlWriter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** XmlWriter.java 26 Mar 2007 11:49:24 -0000 1.5 --- XmlWriter.java 28 Sep 2007 21:54:41 -0000 1.6 *************** *** 22,33 **** import java.io.IOException; import java.io.OutputStream; - import java.io.OutputStreamWriter; - import java.io.Writer; import java.util.Enumeration; import jreepad.JreepadArticle; import jreepad.JreepadNode; import jreepad.JreepadTreeModel; /** * Writes the Jreepad tree as XML. --- 22,40 ---- import java.io.IOException; import java.io.OutputStream; import java.util.Enumeration; + import javax.xml.transform.TransformerConfigurationException; + import javax.xml.transform.sax.SAXTransformerFactory; + import javax.xml.transform.sax.TransformerHandler; + import javax.xml.transform.stream.StreamResult; + import jreepad.JreepadArticle; import jreepad.JreepadNode; import jreepad.JreepadTreeModel; + import org.xml.sax.ContentHandler; + import org.xml.sax.SAXException; + import org.xml.sax.helpers.AttributesImpl; + /** * Writes the Jreepad tree as XML. *************** *** 38,46 **** implements JreepadWriter { ! private String encoding; ! public XmlWriter(String encoding) { ! this.encoding = encoding; } --- 45,58 ---- implements JreepadWriter { ! public static final String NODE_TAG = "node"; ! public static final String TITLE_ATTRIBUTE = "title"; ! public static final String TYPE_ATTRIBUTE = "type"; ! public static final String NSU = ""; ! private AttributesImpl attributes = new AttributesImpl(); ! public XmlWriter() { ! attributes.addAttribute("", "", TITLE_ATTRIBUTE, "", ""); ! attributes.addAttribute("", "", TYPE_ATTRIBUTE, "", ""); } *************** *** 48,117 **** throws IOException { ! Writer writer = new OutputStreamWriter(out, encoding); ! writer.write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n"); ! writeNode(writer, document.getRootNode(), 0, true); ! writer.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.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; 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(); } } --- 60,124 ---- throws IOException { ! StreamResult result = new StreamResult(out); ! SAXTransformerFactory factory = (SAXTransformerFactory)SAXTransformerFactory.newInstance(); ! TransformerHandler handler; ! try ! { ! handler = factory.newTransformerHandler(); ! } ! catch (TransformerConfigurationException e) ! { ! throw new IOException(e); ! } ! handler.setResult(result); ! ! try ! { ! write(handler, document); ! } ! catch (SAXException e) ! { ! throw new IOException(e); ! } } ! private void write(ContentHandler handler, JreepadTreeModel document) throws SAXException { ! handler.startDocument(); ! writeNode(handler, document.getRootNode()); ! handler.endDocument(); ! } + private void writeNode(ContentHandler handler, JreepadNode node) throws SAXException + { + String type; switch (node.getArticle().getArticleMode()) { case JreepadArticle.ARTICLEMODE_HTML: ! type = "text/html"; break; case JreepadArticle.ARTICLEMODE_TEXTILEHTML: ! type = "text/textile"; break; case JreepadArticle.ARTICLEMODE_CSV: ! type = "text/csv"; break; default: ! type = "text/plain"; break; } ! attributes.setValue(0, node.getTitle()); ! attributes.setValue(1, type); ! handler.startElement(NSU, NODE_TAG, NODE_TAG, attributes); ! String content = node.getContent(); ! handler.characters(content.toCharArray(), 0, content.length()); ! Enumeration kids = node.children(); ! while (kids.hasMoreElements()) ! writeNode(handler, (JreepadNode)kids.nextElement()); ! ! handler.endElement(NSU, NODE_TAG, NODE_TAG); } } |
From: PeWu <pe...@us...> - 2007-09-28 21:54:46
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv31373/src/jreepad Modified Files: find.java JreepadViewer.java Log Message: Using SAX for reading and writing XML Index: find.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/find.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** find.java 26 Mar 2007 11:49:24 -0000 1.8 --- find.java 28 Sep 2007 21:54:41 -0000 1.9 *************** *** 31,38 **** import java.awt.print.*; */ ! import java.io.*; import javax.swing.tree.TreePath; - import java.util.Vector; import jreepad.io.AutoDetectReader; --- 31,42 ---- import java.awt.print.*; */ ! import java.io.File; ! import java.io.FileInputStream; ! import java.io.IOException; ! import java.io.InputStream; ! import java.io.ObjectInputStream; ! import java.util.Vector; import javax.swing.tree.TreePath; import jreepad.io.AutoDetectReader; *************** *** 198,204 **** // De-serialize the prefs file (i.e. load it)... JreepadPrefs jreepref; ! ObjectInputStream prefsLoader = new ObjectInputStream(new FileInputStream(prefsFile)); ! jreepref = (JreepadPrefs)prefsLoader.readObject(); ! prefsLoader.close(); // ...and take some data from it --- 202,208 ---- // De-serialize the prefs file (i.e. load it)... JreepadPrefs jreepref; ! ObjectInputStream prefsLoader = new ObjectInputStream(new FileInputStream(prefsFile)); ! jreepref = (JreepadPrefs)prefsLoader.readObject(); ! prefsLoader.close(); // ...and take some data from it *************** *** 232,246 **** // Load the file to be searched JreepadNode root = new JreepadNode(); ! try ! { InputStream in = new FileInputStream(userFile); JreepadReader reader = new AutoDetectReader(encoding, false); root = reader.read(in).getRootNode(); ! } ! catch(IOException err) ! { ! System.out.println("File input error: " + err); ! System.exit(1); ! } --- 236,250 ---- // Load the file to be searched JreepadNode root = new JreepadNode(); ! try ! { InputStream in = new FileInputStream(userFile); JreepadReader reader = new AutoDetectReader(encoding, false); root = reader.read(in).getRootNode(); ! } ! catch(IOException err) ! { ! System.out.println("File input error: " + err); ! System.exit(1); ! } *************** *** 248,258 **** JreepadSearcher searcher = new JreepadSearcher(root); searcher.performSearch(inNodes, inArticles, new TreePath(root), ! orNotAnd, caseSensitive, maxResults); JreepadSearcher.JreepadSearchResult[] res = searcher.getSearchResults(); if(res.length==0) { ! System.out.println("No matches."); ! System.exit(1); } --- 252,262 ---- JreepadSearcher searcher = new JreepadSearcher(root); searcher.performSearch(inNodes, inArticles, new TreePath(root), ! orNotAnd, caseSensitive, maxResults); JreepadSearcher.JreepadSearchResult[] res = searcher.getSearchResults(); if(res.length==0) { ! System.out.println("No matches."); ! System.exit(1); } *************** *** 277,281 **** JreepadWriter writer; if (outputFormat == OUTPUT_XML) ! writer= new XmlWriter(outputEncoding); else writer= new TreepadWriter(outputEncoding); --- 281,285 ---- JreepadWriter writer; if (outputFormat == OUTPUT_XML) ! writer= new XmlWriter(); else writer= new TreepadWriter(outputEncoding); Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** JreepadViewer.java 15 Apr 2007 10:46:45 -0000 1.63 --- JreepadViewer.java 28 Sep 2007 21:54:41 -0000 1.64 *************** *** 80,83 **** --- 80,84 ---- import jreepad.io.AutoDetectReader; + import jreepad.io.EncryptedWriter; import jreepad.io.HtmlWriter; import jreepad.io.JreepadReader; *************** *** 85,88 **** --- 86,90 ---- import jreepad.io.TreepadWriter; [...1552 lines suppressed...] ae.setHandled(true); ! } ! public void handleQuit(ApplicationEvent ae) { // // You MUST setHandled(false) if you want to delay or cancel the quit. *************** *** 2405,2409 **** ae.setHandled(false); quit(); ! } */ } \ No newline at end of file --- 2422,2426 ---- ae.setHandled(false); quit(); ! } */ } \ No newline at end of file |
From: PeWu <pe...@us...> - 2007-09-28 14:29:28
|
Update of /cvsroot/jreepad/jreepad/src/jreepad/io In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv28006/src/jreepad/io Modified Files: AutoDetectReader.java Added Files: EncryptedWriter.java EncryptedReader.java Log Message: Added experimental encrypted file format Index: AutoDetectReader.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/AutoDetectReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AutoDetectReader.java 3 Apr 2007 12:41:30 -0000 1.2 --- AutoDetectReader.java 28 Sep 2007 14:29:22 -0000 1.3 *************** *** 24,27 **** --- 24,28 ---- import jreepad.JreepadTreeModel; + import jreepad.ui.PasswordDialog; /** *************** *** 37,44 **** --- 38,48 ---- TreepadReader treepadReader; + EncryptedReader encryptedReader; + public AutoDetectReader(String encoding, boolean autoDetectHtmlArticles) { xmlReader = new XmlReader(); treepadReader = new TreepadReader(encoding, autoDetectHtmlArticles); + encryptedReader = new EncryptedReader(this); // Use this reader as the underlying reader } *************** *** 52,56 **** 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 --- 56,60 ---- in.reset(); // reset stream, so the specific readers read from the beginning ! if (currentLine.startsWith("<?xml")) { // Try and find out what character encoding to use *************** *** 81,84 **** --- 85,96 ---- return treepadReader.read(in); } + else if (currentLine.startsWith(EncryptedWriter.HEADER)) + { + String password = PasswordDialog.showPasswordDialog("This file is encrypted. Please enter password:"); + if (password == null) + throw new IOException("Could not decrypt. No password entered."); + encryptedReader.setPassword(password); + return encryptedReader.read(in); + } else { --- NEW FILE: EncryptedReader.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.security.GeneralSecurityException; import java.security.Key; import javax.crypto.Cipher; import javax.crypto.CipherInputStream; import javax.crypto.spec.SecretKeySpec; import jreepad.JreepadPrefs; import jreepad.JreepadTreeModel; /** * Reads encrypted input into Jreepad. This reader is constructed with * any other reader as the actual file format which will used when decrypted. * * @version $Id: EncryptedReader.java,v 1.1 2007/09/28 14:29:22 pewu Exp $ */ public class EncryptedReader implements JreepadReader { private JreepadReader reader; private String password = ""; public EncryptedReader(JreepadReader reader) { this.reader = reader; } public JreepadTreeModel read(InputStream in) throws IOException { // Read header while (in.read() != '\n'); Cipher cipher = null; try { cipher = Cipher.getInstance(EncryptedWriter.ALGORITHM); Key key = new SecretKeySpec(password.getBytes(), EncryptedWriter.ALGORITHM); cipher.init(Cipher.DECRYPT_MODE, key); } catch (GeneralSecurityException e) { throw new IOException(e.toString()); } InputStream in2 = new CipherInputStream(in, cipher); JreepadTreeModel document; try { document = reader.read(in2); } catch (IOException e) { throw new IOException("Password incorrect or read problem occurred", e); } document.setFileType(JreepadPrefs.FILETYPE_XML_ENCRYPTED); document.setPassword(password); return document; } public void setPassword(String password) { this.password = password; } } --- NEW FILE: EncryptedWriter.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.security.GeneralSecurityException; import java.security.Key; import javax.crypto.Cipher; import javax.crypto.CipherOutputStream; import javax.crypto.spec.SecretKeySpec; import jreepad.JreepadTreeModel; /** * Writes an encrypted file. This writer is constructed with * any other writer as the actual file format which will be encrypted. * * @version $Id: EncryptedWriter.java,v 1.1 2007/09/28 14:29:22 pewu Exp $ */ public class EncryptedWriter implements JreepadWriter { static final String ALGORITHM = "Blowfish"; static final String HEADER = "JreepadEncrypted"; private JreepadWriter writer; private String password = ""; public EncryptedWriter(JreepadWriter writer) { this.writer = writer; } public void write(OutputStream out, JreepadTreeModel document) throws IOException { out.write(HEADER.getBytes()); out.write("\n".getBytes()); Cipher cipher = null; try { cipher = Cipher.getInstance(ALGORITHM); Key key = new SecretKeySpec(password.getBytes(), ALGORITHM); cipher.init(Cipher.ENCRYPT_MODE, key); } catch (GeneralSecurityException e) { throw new IOException(e.toString()); } OutputStream out2 = new CipherOutputStream(out, cipher); writer.write(out2, document); } public void setPassword(String password) { this.password = password; } } |
From: PeWu <pe...@us...> - 2007-09-28 14:29:27
|
Update of /cvsroot/jreepad/jreepad/src/jreepad/ui In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv28006/src/jreepad/ui Modified Files: SaveFileChooser.java Added Files: PasswordDialog.java Log Message: Added experimental encrypted file format --- NEW FILE: PasswordDialog.java --- package jreepad.ui; import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPasswordField; public class PasswordDialog extends JDialog implements PropertyChangeListener { private JOptionPane optionPane; private JPasswordField pwdField1; private JPasswordField pwdField2; private String password = null; public PasswordDialog(String message, boolean confirm) { super((Frame)null, "Enter password", true); pwdField1 = new JPasswordField(); Object[] array; if (confirm) { pwdField2 = new JPasswordField(); array = new Object[] { new JLabel(message), pwdField1, new JLabel("confirm:"), pwdField2 }; } else { array = new Object[] { new JLabel(message), pwdField1 }; } optionPane = new JOptionPane(array, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); optionPane.addPropertyChangeListener(this); setContentPane(optionPane); pack(); setLocationRelativeTo(null); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { optionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION)); } }); } /** * Dialog button was pressed. */ public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if (isVisible() && JOptionPane.VALUE_PROPERTY.equals(prop)) { Object value = optionPane.getValue(); if (value == JOptionPane.UNINITIALIZED_VALUE) return; optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE); if (value.equals(Integer.valueOf(JOptionPane.OK_OPTION))) { String pwd1 = new String(pwdField1.getPassword()); if (pwdField2 != null) { String pwd2 = new String(pwdField2.getPassword()); if (!pwd1.equals(pwd2)) { JOptionPane.showMessageDialog(this, "The passwords do not match"); return; } } password = new String(pwdField1.getPassword()); } setVisible(false); } } /** * Returns entered password or null if Cancel was pressed. */ public String getPassword() { return password; } /** * Shows password dialog. * @param message message to show in the dialog (e.g. "Please enter password:") * @param confirm whether to show second confirmation password field * @return enetered password or null if Cancel was pressed */ public static String showPasswordDialog(String message, boolean confirm) { PasswordDialog dialog = new PasswordDialog(message, confirm); dialog.setVisible(true); dialog.dispose(); // We don't need the dialog anymore return dialog.getPassword(); } public static String showPasswordDialog(String message) { return showPasswordDialog(message, false); } public static String showPasswordDialog(boolean confirm) { return showPasswordDialog("Please enter password:", confirm); } public static String showPasswordDialog() { return showPasswordDialog(false); } } Index: SaveFileChooser.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/ui/SaveFileChooser.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SaveFileChooser.java 3 Apr 2007 12:41:30 -0000 1.3 --- SaveFileChooser.java 28 Sep 2007 14:29:22 -0000 1.4 *************** *** 24,27 **** --- 24,32 ---- public static final FileFilter TREEPAD_FILE_FILTER = new ExtensionFileFilter("Treepad file (*.hjt)", "hjt"); + /** + * File filter for Jreepad Encrypted XML .jree files. + */ + public static final FileFilter JREEPAD_ENCRYPTED_FILE_FILTER = new ExtensionFileFilter("Jreepad Encrypted XML file (*.jree) [EXPERIMENTAL]", "jree"); + private int defaultFileFormat; *************** *** 31,34 **** --- 36,40 ---- addChoosableFileFilter(JREEPAD_FILE_FILTER); + addChoosableFileFilter(JREEPAD_ENCRYPTED_FILE_FILTER); addChoosableFileFilter(TREEPAD_FILE_FILTER); *************** *** 38,41 **** --- 44,50 ---- setFileFilter(TREEPAD_FILE_FILTER); break; + case JreepadPrefs.FILETYPE_XML_ENCRYPTED: + setFileFilter(JREEPAD_ENCRYPTED_FILE_FILTER); + break; case JreepadPrefs.FILETYPE_XML: // default default: *************** *** 55,58 **** --- 64,69 ---- if (getFileFilter() == SaveFileChooser.TREEPAD_FILE_FILTER) return JreepadPrefs.FILETYPE_HJT; + if (getFileFilter() == SaveFileChooser.JREEPAD_ENCRYPTED_FILE_FILTER) + return JreepadPrefs.FILETYPE_XML_ENCRYPTED; return defaultFileFormat; } |
From: PeWu <pe...@us...> - 2007-09-28 14:29:26
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv28006/src/jreepad Modified Files: JreepadTreeModel.java JreepadPrefs.java Log Message: Added experimental encrypted file format Index: JreepadPrefs.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadPrefs.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** JreepadPrefs.java 12 Apr 2007 21:23:23 -0000 1.27 --- JreepadPrefs.java 28 Sep 2007 14:29:22 -0000 1.28 *************** *** 123,126 **** --- 123,127 ---- public static final int FILETYPE_XML = 0; public static final int FILETYPE_HJT = 1; + public static final int FILETYPE_XML_ENCRYPTED = 2; int mainFileType; public static final String[] mainFileTypes = {"Jreepad XML","Treepad HJT"}; Index: JreepadTreeModel.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadTreeModel.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** JreepadTreeModel.java 3 Apr 2007 12:41:30 -0000 1.6 --- JreepadTreeModel.java 28 Sep 2007 14:29:22 -0000 1.7 *************** *** 29,32 **** --- 29,37 ---- /** + * Password for saving encrypted files. + */ + private String password = null; + + /** * True if the current document content has been saved. */ *************** *** 115,117 **** --- 120,132 ---- this.encoding = encoding; } + + public String getPassword() + { + return password; + } + + public void setPassword(String password) + { + this.password = password; + } } |
From: Dan S. <dan...@us...> - 2007-04-15 10:46:51
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv7885/src/jreepad Modified Files: JreepadViewer.java Log Message: Fiddled with the format of the "about" box, added a member to JreepadViewer to represent the version number. Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** JreepadViewer.java 14 Apr 2007 21:42:31 -0000 1.62 --- JreepadViewer.java 15 Apr 2007 10:46:45 -0000 1.63 *************** *** 93,96 **** --- 93,99 ---- public class JreepadViewer extends JFrame // implements ApplicationListener { + // Jreepad version, to appear in "about" box etc + public static String version = "1.6 rc1"; + private static Vector theApps = new Vector(1,1); private Box toolBar, toolBarIconic; *************** *** 1821,1833 **** { JOptionPane.showMessageDialog(this, lang.getString("HELP_ABOUT") + "\n" + ! "\nJreepad \u00A9 2004 Dan Stowell" + ! "\n" + ! "\nJreepad project website:" + ! "\n http://jreepad.sourceforge.net" + "\n" + ! "\nTreepad website:" + ! "\n http://www.treepad.com" , "About Jreepad", --- 1824,1833 ---- { JOptionPane.showMessageDialog(this, + "Jreepad v " + version + "\n\n" + lang.getString("HELP_ABOUT") + "\n" + ! "\nJreepad \u00A9 2004-2007 Dan Stowell" + "\n" + ! "\nhttp://jreepad.sourceforge.net" , "About Jreepad", |
From: Dan S. <dan...@us...> - 2007-04-15 10:46:50
|
Update of /cvsroot/jreepad/jreepad/src/jreepad/lang In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv7885/src/jreepad/lang Modified Files: JreepadStrings.properties Log Message: Fiddled with the format of the "about" box, added a member to JreepadViewer to represent the version number. Index: JreepadStrings.properties =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/lang/JreepadStrings.properties,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** JreepadStrings.properties 14 Apr 2007 21:42:31 -0000 1.7 --- JreepadStrings.properties 15 Apr 2007 10:46:46 -0000 1.8 *************** *** 215,221 **** HELP_DRAGDROP=DRAG-AND-DROP:\n\nOne of the easiest ways to manage the structure\nof your Treepad file is to drag the nodes around\nusing the mouse.\n\nClick on a node's title, and, keeping the mouse\nbutton held down, move the mouse to where you\nwant the node to be moved to. Then release the\nmouse button, and the node will be moved to its\nnew position in the tree. HELP_DATEFORMAT_TITLE=Date formats ! HELP_DATEFORMAT=<html><h1>Date formats</h1><p>You can specify your preferred date format using standard Java date formatting commands. Here are some examples:</p><table border="1"><tr><th>Command</th><th>Example output</th></tr><tr><td>yyyy.MM.dd G 'at' HH:mm:ss z</td><td>2001.07.04 AD at 12:08:56 PDT</td></tr><tr><td>EEE, MMM d, ''yy</td><td>Wed, Jul 4, '01</td></tr><tr><td>h:mm a</td><td>12:08 PM</td></tr><tr><td>hh 'o''clock' a, zzzz</td><td>12 o'clock PM, Pacific Daylight Time</td></tr><tr><td>K:mm a, z</td><td>0:08 PM, PDT</td></tr></table><p>A complete guide to the formatting is available online at: <br>www.javadocs.org/SimpleDateFormat</p><p>Leave the box blank to use the system default formatting.</p></html> HELP_LINKS_TITLE=Links in Jreepad HELP_LINKS=Select any piece of text in an article,\nthen choose "Actions > Follow link in article".\n\nTYPES OF LINK:\n\n"Normal" link - We've tested these types of link:\n Web: e.g. http://jreepad.sourceforge.net\n Email: e.g. mailto:bi...@mi...\n FTP: e.g. ftp://ftp.compaq.com/pub/\n File: e.g. file:///Users/harold/Documents/stripes.jpg\n\nWiki link - If the selected text is a WikiWord (i.e. if \n it LooksLikeThis with no spaces and some capital \n letters somewhere in the middle) OR begins \n with "[[" and ends with "]]" then \n Jreepad will search for a node of the same \n title, and jump directly to it. If one \n isn't found then it'll create one \n for you. Try it!\n\nTreepad link - Treepad Lite uses links which begin \n with \"node://\", and specify the exact path\n to a different node within the same file.\n e.g. \"node://TreePad manual/Using Treepad\" HELP_LICENSE= Jreepad - personal information manager.\n Copyright \u00A9 2004 Dan Stowell\n\nThis program is free software; you can redistribute it and/or\nmodify it under the terms of the GNU General Public License\nas published by the Free Software Foundation; either version 2\nof the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nThe full license can be read online here: ! HELP_ABOUT=Jreepad is an open-source Java program\ndesigned to provide the functionality\n(including file interoperability) of\na Windows program called \"Treepad Lite\",\npart of the \"Treepad\" suite of software \nwritten by Henk Hagedoorn. \ No newline at end of file --- 215,221 ---- HELP_DRAGDROP=DRAG-AND-DROP:\n\nOne of the easiest ways to manage the structure\nof your Treepad file is to drag the nodes around\nusing the mouse.\n\nClick on a node's title, and, keeping the mouse\nbutton held down, move the mouse to where you\nwant the node to be moved to. Then release the\nmouse button, and the node will be moved to its\nnew position in the tree. HELP_DATEFORMAT_TITLE=Date formats ! HELP_DATEFORMAT=<html><h1>Date formats</h1><p>You can specify your preferred date format using standard Java date formatting commands.<br>Here are some examples:</p><table border="1"><tr><th>Command</th><th>Example output</th></tr><tr><td>yyyy.MM.dd G 'at' HH:mm:ss z</td><td>2001.07.04 AD at 12:08:56 PDT</td></tr><tr><td>EEE, MMM d, ''yy</td><td>Wed, Jul 4, '01</td></tr><tr><td>h:mm a</td><td>12:08 PM</td></tr><tr><td>hh 'o''clock' a, zzzz</td><td>12 o'clock PM, Pacific Daylight Time</td></tr><tr><td>K:mm a, z</td><td>0:08 PM, PDT</td></tr></table><p>A complete guide to the formatting is available online at: <br>www.javadocs.org/SimpleDateFormat</p><p>Leave the box blank to use the system default formatting.</p></html> HELP_LINKS_TITLE=Links in Jreepad HELP_LINKS=Select any piece of text in an article,\nthen choose "Actions > Follow link in article".\n\nTYPES OF LINK:\n\n"Normal" link - We've tested these types of link:\n Web: e.g. http://jreepad.sourceforge.net\n Email: e.g. mailto:bi...@mi...\n FTP: e.g. ftp://ftp.compaq.com/pub/\n File: e.g. file:///Users/harold/Documents/stripes.jpg\n\nWiki link - If the selected text is a WikiWord (i.e. if \n it LooksLikeThis with no spaces and some capital \n letters somewhere in the middle) OR begins \n with "[[" and ends with "]]" then \n Jreepad will search for a node of the same \n title, and jump directly to it. If one \n isn't found then it'll create one \n for you. Try it!\n\nTreepad link - Treepad Lite uses links which begin \n with \"node://\", and specify the exact path\n to a different node within the same file.\n e.g. \"node://TreePad manual/Using Treepad\" HELP_LICENSE= Jreepad - personal information manager.\n Copyright \u00A9 2004 Dan Stowell\n\nThis program is free software; you can redistribute it and/or\nmodify it under the terms of the GNU General Public License\nas published by the Free Software Foundation; either version 2\nof the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nThe full license can be read online here: ! HELP_ABOUT=Jreepad originally inspired by a\nWindows program called \"Treepad Lite\"\nwritten by Henk Hagedoorn. \ No newline at end of file |
From: Dan S. <dan...@us...> - 2007-04-15 10:46:49
|
Update of /cvsroot/jreepad/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv7885 Modified Files: build.xml Log Message: Fiddled with the format of the "about" box, added a member to JreepadViewer to represent the version number. Index: build.xml =================================================================== RCS file: /cvsroot/jreepad/jreepad/build.xml,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** build.xml 14 Jan 2007 00:18:51 -0000 1.10 --- build.xml 15 Apr 2007 10:46:45 -0000 1.11 *************** *** 5,9 **** </description> ! <property name="curVersion" value="1.6dev" /> --- 5,9 ---- </description> ! <property name="curVersion" value="1.6rc1" /> |
From: Dan S. <dan...@us...> - 2007-04-14 21:42:37
|
Update of /cvsroot/jreepad/jreepad/src/jreepad/lang In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv25132/src/jreepad/lang Modified Files: JreepadStrings.properties Log Message: Added an "info" box to give information about the date formatting option Index: JreepadStrings.properties =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/lang/JreepadStrings.properties,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** JreepadStrings.properties 1 Mar 2007 12:10:59 -0000 1.6 --- JreepadStrings.properties 14 Apr 2007 21:42:31 -0000 1.7 *************** *** 209,216 **** --- 209,219 ---- #------------------------------------------------------------------------ + INFO=Info HELP_KEYBOARD_TITLE=Keyboard help HELP_KEYBOARD= HELP_DRAGDROP_TITLE=Drag-and-drop HELP_DRAGDROP=DRAG-AND-DROP:\n\nOne of the easiest ways to manage the structure\nof your Treepad file is to drag the nodes around\nusing the mouse.\n\nClick on a node's title, and, keeping the mouse\nbutton held down, move the mouse to where you\nwant the node to be moved to. Then release the\nmouse button, and the node will be moved to its\nnew position in the tree. + HELP_DATEFORMAT_TITLE=Date formats + HELP_DATEFORMAT=<html><h1>Date formats</h1><p>You can specify your preferred date format using standard Java date formatting commands. Here are some examples:</p><table border="1"><tr><th>Command</th><th>Example output</th></tr><tr><td>yyyy.MM.dd G 'at' HH:mm:ss z</td><td>2001.07.04 AD at 12:08:56 PDT</td></tr><tr><td>EEE, MMM d, ''yy</td><td>Wed, Jul 4, '01</td></tr><tr><td>h:mm a</td><td>12:08 PM</td></tr><tr><td>hh 'o''clock' a, zzzz</td><td>12 o'clock PM, Pacific Daylight Time</td></tr><tr><td>K:mm a, z</td><td>0:08 PM, PDT</td></tr></table><p>A complete guide to the formatting is available online at: <br>www.javadocs.org/SimpleDateFormat</p><p>Leave the box blank to use the system default formatting.</p></html> HELP_LINKS_TITLE=Links in Jreepad HELP_LINKS=Select any piece of text in an article,\nthen choose "Actions > Follow link in article".\n\nTYPES OF LINK:\n\n"Normal" link - We've tested these types of link:\n Web: e.g. http://jreepad.sourceforge.net\n Email: e.g. mailto:bi...@mi...\n FTP: e.g. ftp://ftp.compaq.com/pub/\n File: e.g. file:///Users/harold/Documents/stripes.jpg\n\nWiki link - If the selected text is a WikiWord (i.e. if \n it LooksLikeThis with no spaces and some capital \n letters somewhere in the middle) OR begins \n with "[[" and ends with "]]" then \n Jreepad will search for a node of the same \n title, and jump directly to it. If one \n isn't found then it'll create one \n for you. Try it!\n\nTreepad link - Treepad Lite uses links which begin \n with \"node://\", and specify the exact path\n to a different node within the same file.\n e.g. \"node://TreePad manual/Using Treepad\" |
From: Dan S. <dan...@us...> - 2007-04-14 21:42:37
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv25132/src/jreepad Modified Files: JreepadViewer.java PrefsDialog.java Log Message: Added an "info" box to give information about the date formatting option Index: PrefsDialog.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/PrefsDialog.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PrefsDialog.java 1 Mar 2007 12:10:59 -0000 1.2 --- PrefsDialog.java 14 Apr 2007 21:42:31 -0000 1.3 *************** *** 47,50 **** --- 47,52 ---- private JButton prefsOkButton; private JButton prefsCancelButton; + private JButton prefsDateInfoButton; + private PrefsDialog self; // bleh - yucky but needed by actionlistener public PrefsDialog(Frame owner) *************** *** 52,68 **** super(owner, JreepadViewer.lang.getString("PREFS_WINDOWTITLE"), true); setVisible(false); ! ! Box vBox = Box.createVerticalBox(); vBox.setAlignmentX(Component.LEFT_ALIGNMENT); Box genPrefVBox = Box.createVerticalBox(); vBox.setAlignmentX(Component.LEFT_ALIGNMENT); genPrefVBox.add(loadLastFileOnOpenCheckBox = new JCheckBox(JreepadViewer.lang .getString("PREFS_LOADLASTFILEONOPEN"), getPrefs().loadLastFileOnOpen)); loadLastFileOnOpenCheckBox.setHorizontalAlignment(SwingConstants.LEFT); loadLastFileOnOpenCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT); genPrefVBox.add(autoDateNodesCheckBox = new JCheckBox(JreepadViewer.lang .getString("PREFS_AUTODATE_NODES"), getPrefs().autoDateInArticles)); autoDateNodesCheckBox.setHorizontalAlignment(SwingConstants.LEFT); autoDateNodesCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT); genPrefVBox.add(autoDetectHtmlCheckBox = new JCheckBox(JreepadViewer.lang .getString("PREFS_AUTODETECT_HTML"), getPrefs().autoDetectHtmlArticles)); --- 54,98 ---- super(owner, JreepadViewer.lang.getString("PREFS_WINDOWTITLE"), true); setVisible(false); ! self = this; ! ! Box hBox, vBox; ! ! vBox = Box.createVerticalBox(); vBox.setAlignmentX(Component.LEFT_ALIGNMENT); Box genPrefVBox = Box.createVerticalBox(); vBox.setAlignmentX(Component.LEFT_ALIGNMENT); + genPrefVBox.add(loadLastFileOnOpenCheckBox = new JCheckBox(JreepadViewer.lang .getString("PREFS_LOADLASTFILEONOPEN"), getPrefs().loadLastFileOnOpen)); loadLastFileOnOpenCheckBox.setHorizontalAlignment(SwingConstants.LEFT); loadLastFileOnOpenCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT); + genPrefVBox.add(autoDateNodesCheckBox = new JCheckBox(JreepadViewer.lang .getString("PREFS_AUTODATE_NODES"), getPrefs().autoDateInArticles)); autoDateNodesCheckBox.setHorizontalAlignment(SwingConstants.LEFT); autoDateNodesCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT); + + hBox = Box.createHorizontalBox(); + hBox.setAlignmentX(Component.LEFT_ALIGNMENT); + hBox.add(new JLabel(JreepadViewer.lang.getString("PREFS_DATEFORMAT_LABEL"), SwingConstants.LEFT)); + dateFormatField = new JTextField(getPrefs().dateFormat, 20); + hBox.add(dateFormatField); + //hBox.add(new JLabel("(" + JreepadViewer.lang.getString("PREFS_DATEFORMAT_LABEL2") + ")", SwingConstants.LEFT)); + + hBox.add(prefsDateInfoButton = new JButton(JreepadViewer.lang.getString("INFO"))); + prefsDateInfoButton.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + JOptionPane.showMessageDialog(self, + JreepadViewer.lang.getString("HELP_DATEFORMAT") + , + JreepadViewer.lang.getString("HELP_DATEFORMAT_TITLE"), + JOptionPane.INFORMATION_MESSAGE); + } + }); + + genPrefVBox.add(hBox); + genPrefVBox.add(autoDetectHtmlCheckBox = new JCheckBox(JreepadViewer.lang .getString("PREFS_AUTODETECT_HTML"), getPrefs().autoDetectHtmlArticles)); *************** *** 70,74 **** autoDetectHtmlCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT); ! Box hBox = Box.createHorizontalBox(); hBox.setAlignmentX(Component.LEFT_ALIGNMENT); // hBox.add(Box.createGlue()); --- 100,104 ---- autoDetectHtmlCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT); ! hBox = Box.createHorizontalBox(); hBox.setAlignmentX(Component.LEFT_ALIGNMENT); // hBox.add(Box.createGlue()); *************** *** 99,110 **** showGreenStripCheckBox.setHorizontalAlignment(SwingConstants.LEFT); - hBox = Box.createHorizontalBox(); - hBox.setAlignmentX(Component.LEFT_ALIGNMENT); - hBox.add(new JLabel(JreepadViewer.lang.getString("PREFS_DATEFORMAT_LABEL"), SwingConstants.LEFT)); - dateFormatField = new JTextField(getPrefs().dateFormat, 30); - hBox.add(dateFormatField); - hBox.add(new JLabel("(" + JreepadViewer.lang.getString("PREFS_DATEFORMAT_LABEL2") + ")", SwingConstants.LEFT)); - genPrefVBox.add(hBox); - JPanel genPanel = new JPanel(); genPanel.setAlignmentX(Component.LEFT_ALIGNMENT); --- 129,132 ---- Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** JreepadViewer.java 12 Apr 2007 21:23:23 -0000 1.61 --- JreepadViewer.java 14 Apr 2007 21:42:31 -0000 1.62 *************** *** 2279,2282 **** --- 2279,2283 ---- } + /* // Replacement for the "JSpinner" which is not available in Java 1.3 or 1.2 |
From: Dan S. <dan...@us...> - 2007-04-12 21:23:27
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv13685/src/jreepad Modified Files: JreepadPrefs.java JreepadView.java JreepadViewer.java Log Message: Fixed request #1699525 and #1699524 re the convenience of the "Edit node title" action Index: JreepadView.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadView.java,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** JreepadView.java 21 Mar 2007 10:40:35 -0000 1.47 --- JreepadView.java 12 Apr 2007 21:23:23 -0000 1.48 *************** *** 254,257 **** --- 254,258 ---- // editorPane.setSize(articleView.getSize()); // editorPane.setSize(articleView.getViewport().getViewSize()); + getPrefs().viewWhich = JreepadPrefs.VIEW_BOTH; } private void setViewTreeOnly() *************** *** 260,263 **** --- 261,265 ---- this.add(treeView); treeView.setSize(getSize()); + getPrefs().viewWhich = JreepadPrefs.VIEW_TREE; } private void setViewArticleOnly() *************** *** 268,271 **** --- 270,274 ---- this.add(articlePane); articlePane.setSize(getSize()); + getPrefs().viewWhich = JreepadPrefs.VIEW_ARTICLE; } *************** *** 937,940 **** --- 940,948 ---- public void editNodeTitleAction() { + if(getPrefs().viewWhich == JreepadPrefs.VIEW_ARTICLE) + { + setViewMode(JreepadPrefs.VIEW_BOTH); + } + tree.startEditingAtPath(tree.getSelectionPath()); } Index: JreepadPrefs.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadPrefs.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** JreepadPrefs.java 26 Mar 2007 11:49:24 -0000 1.26 --- JreepadPrefs.java 12 Apr 2007 21:23:23 -0000 1.27 *************** *** 152,156 **** autoSave = prefs.getBoolean("AUTOSAVE", false); ! viewWhich = prefs.getInt("VIEWWHICH", 0); viewToolbar = prefs.getBoolean("VIEWTOOLBAR", true); --- 152,156 ---- autoSave = prefs.getBoolean("AUTOSAVE", false); ! viewWhich = prefs.getInt("VIEWWHICH", VIEW_BOTH); viewToolbar = prefs.getBoolean("VIEWTOOLBAR", true); Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.60 retrieving revision 1.61 diff -C2 -d -r1.60 -r1.61 *** JreepadViewer.java 12 Apr 2007 20:32:57 -0000 1.60 --- JreepadViewer.java 12 Apr 2007 21:23:23 -0000 1.61 *************** *** 557,560 **** --- 557,561 ---- addChildMenuItem.setAccelerator(KeyStroke.getKeyStroke('D', MENU_MASK)); newFromClipboardMenuItem.setAccelerator(KeyStroke.getKeyStroke('M', MENU_MASK)); + editNodeTitleMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0)); upMenuItem.setMnemonic('u'); upMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, MENU_MASK | java.awt.Event.ALT_MASK)); |
From: Dan S. <dan...@us...> - 2007-04-12 20:33:03
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv25051/src/jreepad Modified Files: JreepadViewer.java Log Message: Small fix to appearance of hard-wrap menu action Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** JreepadViewer.java 3 Apr 2007 12:41:30 -0000 1.59 --- JreepadViewer.java 12 Apr 2007 20:32:57 -0000 1.60 *************** *** 623,627 **** actionsMenu.add(new JSeparator()); ! characterWrapArticleMenuItem = new JMenuItem(lang.getString("MENUITEM_HARDWRAP1") + getPrefs().characterWrapWidth + lang.getString("MENUITEM_HARDWRAP2")); //); characterWrapArticleMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { wrapContentToCharWidth(); }}); actionsMenu.add(characterWrapArticleMenuItem); --- 623,627 ---- actionsMenu.add(new JSeparator()); ! characterWrapArticleMenuItem = new JMenuItem(lang.getString("MENUITEM_HARDWRAP1") + " " + getPrefs().characterWrapWidth + " " + lang.getString("MENUITEM_HARDWRAP2")); //); characterWrapArticleMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { wrapContentToCharWidth(); }}); actionsMenu.add(characterWrapArticleMenuItem); |
From: PeWu <pe...@us...> - 2007-04-03 12:41:43
|
Update of /cvsroot/jreepad/jreepad/src/jreepad/ui In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27250/src/jreepad/ui Modified Files: SaveFileChooser.java Log Message: Fixes to the file saving and loading code Index: SaveFileChooser.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/ui/SaveFileChooser.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SaveFileChooser.java 26 Mar 2007 13:28:16 -0000 1.2 --- SaveFileChooser.java 3 Apr 2007 12:41:30 -0000 1.3 *************** *** 24,35 **** public static final FileFilter TREEPAD_FILE_FILTER = new ExtensionFileFilter("Treepad file (*.hjt)", "hjt"); public SaveFileChooser(int defaultFileFormat) { addChoosableFileFilter(JREEPAD_FILE_FILTER); addChoosableFileFilter(TREEPAD_FILE_FILTER); ! if (defaultFileFormat == JreepadPrefs.FILETYPE_XML) ! setFileFilter(JREEPAD_FILE_FILTER); ! else setFileFilter(TREEPAD_FILE_FILTER); } --- 24,59 ---- public static final FileFilter TREEPAD_FILE_FILTER = new ExtensionFileFilter("Treepad file (*.hjt)", "hjt"); + private int defaultFileFormat; + public SaveFileChooser(int defaultFileFormat) { + this.defaultFileFormat = defaultFileFormat; + addChoosableFileFilter(JREEPAD_FILE_FILTER); addChoosableFileFilter(TREEPAD_FILE_FILTER); ! ! switch (defaultFileFormat) ! { ! case JreepadPrefs.FILETYPE_HJT: setFileFilter(TREEPAD_FILE_FILTER); + break; + case JreepadPrefs.FILETYPE_XML: // default + default: + setFileFilter(JREEPAD_FILE_FILTER); + break; + } + } + + /** + * Returns the selected file type or the default file type + * if "All files" filter is selected. + */ + public int getFileType() + { + if (getFileFilter() == SaveFileChooser.JREEPAD_FILE_FILTER) + return JreepadPrefs.FILETYPE_XML; + if (getFileFilter() == SaveFileChooser.TREEPAD_FILE_FILTER) + return JreepadPrefs.FILETYPE_HJT; + return defaultFileFormat; } |
From: PeWu <pe...@us...> - 2007-04-03 12:41:43
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27250/src/jreepad Modified Files: JreepadTreeModel.java JreepadViewer.java Log Message: Fixes to the file saving and loading code Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** JreepadViewer.java 26 Mar 2007 13:28:16 -0000 1.58 --- JreepadViewer.java 3 Apr 2007 12:41:30 -0000 1.59 *************** *** 1281,1286 **** setCursor(Cursor.getDefaultCursor()); updateUndoRedoMenuState(); - validate(); - repaint(); } // End of: openAction() --- 1281,1284 ---- *************** *** 1307,1310 **** --- 1305,1310 ---- getPrefs().exportLocation = getPrefs().importLocation = file; setTitleBasedOnFilename(file.getName()); + validate(); + repaint(); return true; } *************** *** 1343,1351 **** { int fileType = getPrefs().mainFileType; File saveLocation = document.getSaveLocation(); if(askForFilename || saveLocation==null || (saveLocation.isFile() && !saveLocation.canWrite())) { // Ask for filename ! JFileChooser fileChooser = new SaveFileChooser(getPrefs().mainFileType); fileChooser.setCurrentDirectory(getPrefs().openLocation); --- 1343,1354 ---- { int fileType = getPrefs().mainFileType; + if (document.getSaveLocation() != null) + fileType = document.getFileType(); + File saveLocation = document.getSaveLocation(); if(askForFilename || saveLocation==null || (saveLocation.isFile() && !saveLocation.canWrite())) { // Ask for filename ! SaveFileChooser fileChooser = new SaveFileChooser(getPrefs().mainFileType); fileChooser.setCurrentDirectory(getPrefs().openLocation); *************** *** 1358,1365 **** } saveLocation = fileChooser.getSelectedFile(); ! if (fileChooser.getFileFilter() == SaveFileChooser.JREEPAD_FILE_FILTER) ! fileType = JreepadPrefs.FILETYPE_XML; ! else if (fileChooser.getFileFilter() == SaveFileChooser.TREEPAD_FILE_FILTER) ! fileType = JreepadPrefs.FILETYPE_HJT; } getPrefs().openLocation = saveLocation; // Remember the file's directory --- 1361,1365 ---- } saveLocation = fileChooser.getSelectedFile(); ! fileType = fileChooser.getFileType(); } getPrefs().openLocation = saveLocation; // Remember the file's directory *************** *** 1383,1386 **** --- 1383,1387 ---- else writer = new TreepadWriter(encoding); + OutputStream fos = new FileOutputStream(saveLocation); writer.write(fos, document); *************** *** 1391,1395 **** --- 1392,1401 ---- appleAppCode, appleAppCode); } + + // When calling "Save As..." remember the _new_ file settings document.setSaveLocation(saveLocation); + document.setFileType(fileType); + document.setEncoding(encoding); + updateWindowTitle(); addToOpenRecentMenu(saveLocation); Index: JreepadTreeModel.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadTreeModel.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** JreepadTreeModel.java 26 Mar 2007 11:49:24 -0000 1.5 --- JreepadTreeModel.java 3 Apr 2007 12:41:30 -0000 1.6 *************** *** 21,25 **** * Format of the loaded file. */ ! private int fileFormat = -1; /** --- 21,25 ---- * Format of the loaded file. */ ! private int fileType = -1; /** *************** *** 91,97 **** } ! public void setFileFormat(int fileFormat) { ! this.fileFormat = fileFormat; } --- 91,97 ---- } ! public void setFileType(int fileType) { ! this.fileType = fileType; } *************** *** 101,107 **** } ! public int getFileFormat() { ! return fileFormat; } --- 101,107 ---- } ! public int getFileType() { ! return fileType; } |
From: PeWu <pe...@us...> - 2007-04-03 12:41:43
|
Update of /cvsroot/jreepad/jreepad/src/jreepad/io In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27250/src/jreepad/io Modified Files: TreepadReader.java AutoDetectReader.java XmlReader.java Log Message: Fixes to the file saving and loading code Index: AutoDetectReader.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/AutoDetectReader.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AutoDetectReader.java 20 Jan 2007 13:01:19 -0000 1.1 --- AutoDetectReader.java 3 Apr 2007 12:41:30 -0000 1.2 *************** *** 23,27 **** import java.io.InputStream; ! import jreepad.JreepadNode; /** --- 23,27 ---- import java.io.InputStream; ! import jreepad.JreepadTreeModel; /** *************** *** 43,47 **** } ! public JreepadNode read(InputStream in) throws IOException { --- 43,47 ---- } ! public JreepadTreeModel read(InputStream in) throws IOException { Index: XmlReader.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/XmlReader.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** XmlReader.java 26 Mar 2007 11:49:24 -0000 1.3 --- XmlReader.java 3 Apr 2007 12:41:30 -0000 1.4 *************** *** 79,83 **** JreepadTreeModel document = new JreepadTreeModel(readNode(reader, currentXmlContent, 0).node); ! document.setFileFormat(JreepadPrefs.FILETYPE_XML); document.setEncoding(encoding); return document; --- 79,83 ---- JreepadTreeModel document = new JreepadTreeModel(readNode(reader, currentXmlContent, 0).node); ! document.setFileType(JreepadPrefs.FILETYPE_XML); document.setEncoding(encoding); return document; Index: TreepadReader.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/TreepadReader.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TreepadReader.java 26 Mar 2007 11:49:24 -0000 1.3 --- TreepadReader.java 3 Apr 2007 12:41:30 -0000 1.4 *************** *** 123,127 **** JreepadTreeModel document = new JreepadTreeModel(rootNode); ! document.setFileFormat(JreepadPrefs.FILETYPE_HJT); document.setEncoding(encoding); return document; --- 123,127 ---- JreepadTreeModel document = new JreepadTreeModel(rootNode); ! document.setFileType(JreepadPrefs.FILETYPE_HJT); document.setEncoding(encoding); return document; |
From: PeWu <pe...@us...> - 2007-03-26 13:41:55
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv23286/src/jreepad Modified Files: OSXAdapter.java JreepadViewer.java Log Message: refactoring: minor refactoring of open and save functions Index: OSXAdapter.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/OSXAdapter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** OSXAdapter.java 12 Mar 2006 12:05:48 -0000 1.5 --- OSXAdapter.java 26 Mar 2007 13:28:16 -0000 1.6 *************** *** 3,13 **** File: OSXAdapter.java ! Abstract: A single class with clear, static entry points for ! hooking existing preferences, about, quit functionality from an existing Java app into handlers for the Mac OS X ! application menu. Useful for developers looking to support ! multiple platforms with a single codebase, and support Mac OS X features with minimal impact. ! Version: 1.1 --- 3,13 ---- File: OSXAdapter.java ! Abstract: A single class with clear, static entry points for ! hooking existing preferences, about, quit functionality from an existing Java app into handlers for the Mac OS X ! application menu. Useful for developers looking to support ! multiple platforms with a single codebase, and support Mac OS X features with minimal impact. ! Version: 1.1 *************** *** 26,30 **** provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following ! text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple --- 26,30 ---- provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following ! text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple *************** *** 50,56 **** POSSIBILITY OF SUCH DAMAGE. ! Copyright © 2004 Apple Computer, Inc., All Rights Reserved ! */ package jreepad; --- 50,56 ---- POSSIBILITY OF SUCH DAMAGE. ! Copyright � 2004 Apple Computer, Inc., All Rights Reserved ! */ package jreepad; *************** *** 67,76 **** // reference to the app where the existing quit, about, prefs code is private JreepadViewer mainApp; ! private OSXAdapter (JreepadViewer inApp) { mainApp = inApp; } ! ! // implemented handler methods. These are basically hooks into existing // functionality from the main app, as if it came over from another platform. public void handleAbout(ApplicationEvent ae) { --- 67,76 ---- // reference to the app where the existing quit, about, prefs code is private JreepadViewer mainApp; ! private OSXAdapter (JreepadViewer inApp) { mainApp = inApp; } ! ! // implemented handler methods. These are basically hooks into existing // functionality from the main app, as if it came over from another platform. public void handleAbout(ApplicationEvent ae) { *************** *** 82,86 **** } } ! public void handlePreferences(ApplicationEvent ae) { if (mainApp != null) { --- 82,86 ---- } } ! public void handlePreferences(ApplicationEvent ae) { if (mainApp != null) { *************** *** 91,105 **** } } ! // Added by Dan public void handleOpenFile(ApplicationEvent ae) { //System.err.println("Jreepad.handleOpenFile() - ApplicationEvent is " + ae); ! mainApp.openHjtFile(new java.io.File(ae.getFilename())); } ! public void handleQuit(ApplicationEvent ae) { if (mainApp != null) { ! /* / You MUST setHandled(false) if you want to delay or cancel the quit. / This is important for cross-platform development -- have a universal quit --- 91,105 ---- } } ! // Added by Dan public void handleOpenFile(ApplicationEvent ae) { //System.err.println("Jreepad.handleOpenFile() - ApplicationEvent is " + ae); ! mainApp.openFile(new java.io.File(ae.getFilename())); } ! public void handleQuit(ApplicationEvent ae) { if (mainApp != null) { ! /* / You MUST setHandled(false) if you want to delay or cancel the quit. / This is important for cross-platform development -- have a universal quit *************** *** 114,127 **** } } ! ! // The main entry-point for this functionality. This is the only method // that needs to be called at runtime, and it can easily be done using ! // reflection (see JreepadViewer.java) public static void registerMacOSXApplication(JreepadViewer inApp) { if (theApplication == null) { theApplication = new com.apple.eawt.Application(); ! } ! if (theAdapter == null) { theAdapter = new OSXAdapter(inApp); --- 114,127 ---- } } ! ! // The main entry-point for this functionality. This is the only method // that needs to be called at runtime, and it can easily be done using ! // reflection (see JreepadViewer.java) public static void registerMacOSXApplication(JreepadViewer inApp) { if (theApplication == null) { theApplication = new com.apple.eawt.Application(); ! } ! if (theAdapter == null) { theAdapter = new OSXAdapter(inApp); *************** *** 129,135 **** theApplication.addApplicationListener(theAdapter); } ! ! // Another static entry point for EAWT functionality. Enables the ! // "Preferences..." menu item in the application menu. public static void enablePrefs(boolean enabled) { if (theApplication == null) { --- 129,135 ---- theApplication.addApplicationListener(theAdapter); } ! ! // Another static entry point for EAWT functionality. Enables the ! // "Preferences..." menu item in the application menu. public static void enablePrefs(boolean enabled) { if (theApplication == null) { Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** JreepadViewer.java 26 Mar 2007 11:49:24 -0000 1.57 --- JreepadViewer.java 26 Mar 2007 13:28:16 -0000 1.58 *************** *** 75,79 **** import javax.swing.SpinnerNumberModel; import javax.swing.UIManager; - import javax.swing.filechooser.FileFilter; import javax.swing.undo.CannotRedoException; import javax.swing.undo.CannotUndoException; --- 75,78 ---- *************** *** 86,90 **** import jreepad.io.TreepadWriter; import jreepad.io.XmlWriter; - import jreepad.ui.ExtensionFileFilter; import jreepad.ui.SaveFileChooser; import edu.stanford.ejalbert.BrowserLauncher; --- 85,88 ---- *************** *** 178,191 **** public static final int appleAppCode = 0x4A524545; - /** - * File filter for Jreepad XML .jree files. - */ - private static final FileFilter JREEPAD_FILE_FILTER = new ExtensionFileFilter("Jreepad XML file (*.jree)", "jree"); - - /** - * File filter for Treepad .hjt files. - */ - private static final FileFilter TREEPAD_FILE_FILTER = new ExtensionFileFilter("Treepad file (*.hjt)", "hjt"); - public JreepadViewer() { --- 176,179 ---- *************** *** 298,330 **** if(firstTimeFile != null && firstTimeFile.isFile()) ! { ! try ! { ! getPrefs().openLocation = firstTimeFile; // Remember the open directory ! content.remove(theJreepad); ! ! InputStream in = new FileInputStream(firstTimeFile); ! JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! document = reader.read(in); ! document.setSaveLocation(firstTimeFile); ! theJreepad = new JreepadView(document); ! ! getPrefs().exportLocation = getPrefs().importLocation = firstTimeFile; ! content.add(theJreepad); ! searchDialog.setJreepad(theJreepad); ! ! setTitleBasedOnFilename(firstTimeFile.getName()); ! } ! catch(IOException err) ! { ! 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); ! setTitleBasedOnFilename(""); ! } ! } // Set close operation --- 286,290 ---- if(firstTimeFile != null && firstTimeFile.isFile()) ! openFile(firstTimeFile); // Set close operation *************** *** 1314,1354 **** fileChooser.setCurrentDirectory(getPrefs().openLocation); ! if(fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) ! { ! openHjtFile(fileChooser.getSelectedFile()); ! } ! } // End of: openAction() ! protected void openHjtFile(File f) ! { ! try ! { ! setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); ! getPrefs().openLocation = f; ! content.remove(theJreepad); ! ! InputStream in = new FileInputStream(f); ! JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! document = reader.read(in); ! document.setSaveLocation(f); ! theJreepad = new JreepadView(document); ! content.add(theJreepad); ! searchDialog.setJreepad(theJreepad); ! addToOpenRecentMenu(f); ! setTitleBasedOnFilename(f.getName()); ! validate(); ! repaint(); ! //DEL theJreepad.clearUndoCache(); ! setCursor(Cursor.getDefaultCursor()); ! } ! catch(IOException err) ! { ! setCursor(Cursor.getDefaultCursor()); ! JOptionPane.showMessageDialog(this, err, lang.getString("TITLE_FILE_ERROR") , JOptionPane.ERROR_MESSAGE); ! } ! updateUndoRedoMenuState(); ! } // End of: openHjtFile() private class SaveAction extends AbstractAction --- 1274,1312 ---- fileChooser.setCurrentDirectory(getPrefs().openLocation); ! if(fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) ! return; ! setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); ! openFile(fileChooser.getSelectedFile()); ! setCursor(Cursor.getDefaultCursor()); ! updateUndoRedoMenuState(); ! validate(); ! repaint(); ! } // End of: openAction() ! public boolean openFile(File file) ! { ! getPrefs().openLocation = file; // Remember the open directory ! try ! { ! InputStream in = new FileInputStream(file); ! JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! document = reader.read(in); ! document.setSaveLocation(file); ! } ! catch(IOException e) ! { ! JOptionPane.showMessageDialog(this, e, lang.getString("MSG_LOAD_FILE_FAILED") , JOptionPane.ERROR_MESSAGE); ! return false; ! } ! content.remove(theJreepad); ! theJreepad = new JreepadView(document); ! content.add(theJreepad); ! searchDialog.setJreepad(theJreepad); + getPrefs().exportLocation = getPrefs().importLocation = file; + setTitleBasedOnFilename(file.getName()); + return true; + } private class SaveAction extends AbstractAction *************** *** 1389,1400 **** { // Ask for filename ! JFileChooser fileChooser = new SaveFileChooser(); fileChooser.setCurrentDirectory(getPrefs().openLocation); - fileChooser.addChoosableFileFilter(JREEPAD_FILE_FILTER); - fileChooser.addChoosableFileFilter(TREEPAD_FILE_FILTER); - if (getPrefs().mainFileType == JreepadPrefs.FILETYPE_XML) - fileChooser.setFileFilter(JREEPAD_FILE_FILTER); - else - fileChooser.setFileFilter(TREEPAD_FILE_FILTER); fileChooser.setSelectedFile(new File(document.getRootNode().getTitle() + --- 1347,1352 ---- { // Ask for filename ! JFileChooser fileChooser = new SaveFileChooser(getPrefs().mainFileType); fileChooser.setCurrentDirectory(getPrefs().openLocation); fileChooser.setSelectedFile(new File(document.getRootNode().getTitle() + *************** *** 1406,1412 **** } saveLocation = fileChooser.getSelectedFile(); ! if (fileChooser.getFileFilter() == JREEPAD_FILE_FILTER) fileType = JreepadPrefs.FILETYPE_XML; ! else if (fileChooser.getFileFilter() == TREEPAD_FILE_FILTER) fileType = JreepadPrefs.FILETYPE_HJT; } --- 1358,1364 ---- } saveLocation = fileChooser.getSelectedFile(); ! if (fileChooser.getFileFilter() == SaveFileChooser.JREEPAD_FILE_FILTER) fileType = JreepadPrefs.FILETYPE_XML; ! else if (fileChooser.getFileFilter() == SaveFileChooser.TREEPAD_FILE_FILTER) fileType = JreepadPrefs.FILETYPE_HJT; } *************** *** 2017,2021 **** File f; FileOpeningActionListener(File f) {this.f = f;} ! public void actionPerformed(ActionEvent e) {openHjtFile(f);} } // End of: private class FileOpeningActionListener extends ActionListener --- 1969,1973 ---- File f; FileOpeningActionListener(File f) {this.f = f;} ! public void actionPerformed(ActionEvent e) {openFile(f);} } // End of: private class FileOpeningActionListener extends ActionListener |
From: PeWu <pe...@us...> - 2007-03-26 13:41:55
|
Update of /cvsroot/jreepad/jreepad/src/jreepad/ui In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv23286/src/jreepad/ui Modified Files: SaveFileChooser.java Log Message: refactoring: minor refactoring of open and save functions Index: SaveFileChooser.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/ui/SaveFileChooser.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SaveFileChooser.java 20 Mar 2007 10:18:17 -0000 1.1 --- SaveFileChooser.java 26 Mar 2007 13:28:16 -0000 1.2 *************** *** 6,9 **** --- 6,12 ---- import javax.swing.JFileChooser; import javax.swing.JOptionPane; + import javax.swing.filechooser.FileFilter; + + import jreepad.JreepadPrefs; public class SaveFileChooser extends JFileChooser *************** *** 11,14 **** --- 14,37 ---- protected static final ResourceBundle LANG = ResourceBundle.getBundle("jreepad.lang.JreepadStrings"); + /** + * File filter for Jreepad XML .jree files. + */ + public static final FileFilter JREEPAD_FILE_FILTER = new ExtensionFileFilter("Jreepad XML file (*.jree)", "jree"); + + /** + * File filter for Treepad .hjt files. + */ + public static final FileFilter TREEPAD_FILE_FILTER = new ExtensionFileFilter("Treepad file (*.hjt)", "hjt"); + + public SaveFileChooser(int defaultFileFormat) + { + addChoosableFileFilter(JREEPAD_FILE_FILTER); + addChoosableFileFilter(TREEPAD_FILE_FILTER); + if (defaultFileFormat == JreepadPrefs.FILETYPE_XML) + setFileFilter(JREEPAD_FILE_FILTER); + else + setFileFilter(TREEPAD_FILE_FILTER); + } + public void approveSelection() { |
From: PeWu <pe...@us...> - 2007-03-26 11:49:29
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv12176/src/jreepad Modified Files: find.java JreepadTreeModel.java JreepadPrefs.java JreepadViewer.java Log Message: Save files in the same format and with the same encoding as opened Index: JreepadPrefs.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadPrefs.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** JreepadPrefs.java 23 Mar 2007 09:37:36 -0000 1.25 --- JreepadPrefs.java 26 Mar 2007 11:49:24 -0000 1.26 *************** *** 121,126 **** public boolean addQuotesToCsvOutput; ! static final int FILETYPE_XML = 0; ! static final int FILETYPE_HJT = 1; int mainFileType; public static final String[] mainFileTypes = {"Jreepad XML","Treepad HJT"}; --- 121,126 ---- public boolean addQuotesToCsvOutput; ! public static final int FILETYPE_XML = 0; ! public static final int FILETYPE_HJT = 1; int mainFileType; public static final String[] mainFileTypes = {"Jreepad XML","Treepad HJT"}; Index: find.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/find.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** find.java 26 Jan 2007 21:47:55 -0000 1.7 --- find.java 26 Mar 2007 11:49:24 -0000 1.8 *************** *** 236,240 **** InputStream in = new FileInputStream(userFile); JreepadReader reader = new AutoDetectReader(encoding, false); ! root = reader.read(in); } catch(IOException err) --- 236,240 ---- InputStream in = new FileInputStream(userFile); JreepadReader reader = new AutoDetectReader(encoding, false); ! root = reader.read(in).getRootNode(); } catch(IOException err) *************** *** 280,284 **** else writer= new TreepadWriter(outputEncoding); ! writer.write(System.out, resultsParent); break; case OUTPUT_TITLES: --- 280,284 ---- else writer= new TreepadWriter(outputEncoding); ! writer.write(System.out, new JreepadTreeModel(resultsParent)); break; case OUTPUT_TITLES: Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** JreepadViewer.java 23 Mar 2007 09:37:36 -0000 1.56 --- JreepadViewer.java 26 Mar 2007 11:49:24 -0000 1.57 *************** *** 306,310 **** InputStream in = new FileInputStream(firstTimeFile); JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! document = new JreepadTreeModel(reader.read(in)); document.setSaveLocation(firstTimeFile); theJreepad = new JreepadView(document); --- 306,310 ---- InputStream in = new FileInputStream(firstTimeFile); JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! document = reader.read(in); document.setSaveLocation(firstTimeFile); theJreepad = new JreepadView(document); *************** *** 1329,1333 **** InputStream in = new FileInputStream(f); JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! document = new JreepadTreeModel(reader.read(in)); document.setSaveLocation(f); theJreepad = new JreepadView(document); --- 1329,1333 ---- InputStream in = new FileInputStream(f); JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! document = reader.read(in); document.setSaveLocation(f); theJreepad = new JreepadView(document); *************** *** 1418,1429 **** setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); // Write to either HJT or XML JreepadWriter writer; if(fileType == JreepadPrefs.FILETYPE_XML) ! writer = new XmlWriter(getPrefs().getEncoding()); else ! writer = new TreepadWriter(getPrefs().getEncoding()); OutputStream fos = new FileOutputStream(saveLocation); ! writer.write(fos, document.getRootNode()); fos.close(); --- 1418,1436 ---- setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + // Select default application encoding or document encoding + String encoding; + if (askForFilename || document.getEncoding() == null) + encoding = getPrefs().getEncoding(); + else + encoding = document.getEncoding(); + // Write to either HJT or XML JreepadWriter writer; if(fileType == JreepadPrefs.FILETYPE_XML) ! writer = new XmlWriter(encoding); else ! writer = new TreepadWriter(encoding); OutputStream fos = new FileOutputStream(saveLocation); ! writer.write(fos, document); fos.close(); *************** *** 1466,1470 **** JreepadWriter writer = new TreepadWriter(getPrefs().getEncoding()); OutputStream fos = new FileOutputStream(getPrefs().backupLocation); ! writer.write(fos, document.getRootNode()); fos.close(); --- 1473,1477 ---- JreepadWriter writer = new TreepadWriter(getPrefs().getEncoding()); OutputStream fos = new FileOutputStream(getPrefs().backupLocation); ! writer.write(fos, document); fos.close(); *************** *** 1527,1531 **** InputStream in = new FileInputStream(getPrefs().importLocation); JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! theJreepad.addChild(reader.read(in)); break; case FILE_FORMAT_TEXT: --- 1534,1538 ---- InputStream in = new FileInputStream(getPrefs().importLocation); JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! theJreepad.addChild(reader.read(in).getRootNode()); break; case FILE_FORMAT_TEXT: *************** *** 1618,1622 **** if (writer != null) { ! writer.write(fos, theJreepad.getCurrentNode()); fos.close(); } --- 1625,1629 ---- if (writer != null) { ! writer.write(fos, new JreepadTreeModel(theJreepad.getCurrentNode())); fos.close(); } Index: JreepadTreeModel.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadTreeModel.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** JreepadTreeModel.java 23 Mar 2007 09:37:36 -0000 1.4 --- JreepadTreeModel.java 26 Mar 2007 11:49:24 -0000 1.5 *************** *** 19,22 **** --- 19,32 ---- /** + * Format of the loaded file. + */ + private int fileFormat = -1; + + /** + * Encoding of the loaded file. + */ + private String encoding = null; + + /** * True if the current document content has been saved. */ *************** *** 81,87 **** --- 91,117 ---- } + public void setFileFormat(int fileFormat) + { + this.fileFormat = fileFormat; + } + public File getSaveLocation() { return saveLocation; } + + public int getFileFormat() + { + return fileFormat; + } + + public String getEncoding() + { + return encoding; + } + + public void setEncoding(String encoding) + { + this.encoding = encoding; + } } |
Update of /cvsroot/jreepad/jreepad/src/jreepad/io In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv12176/src/jreepad/io Modified Files: TreepadReader.java HtmlWriter.java JreepadWriter.java JreepadReader.java TreepadWriter.java XmlReader.java XmlWriter.java Log Message: Save files in the same format and with the same encoding as opened Index: HtmlWriter.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/HtmlWriter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** HtmlWriter.java 26 Jan 2007 21:47:56 -0000 1.2 --- HtmlWriter.java 26 Mar 2007 11:49:24 -0000 1.3 *************** *** 29,32 **** --- 29,33 ---- import jreepad.JreepadArticle; import jreepad.JreepadNode; + import jreepad.JreepadTreeModel; /** *************** *** 67,77 **** * 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(); } --- 68,78 ---- * Writes the tree to the output stream starting from selected node. * @param out output stream ! * @param document document to export */ ! public void write(OutputStream out, JreepadTreeModel document) throws IOException { Writer writer = new OutputStreamWriter(out, encoding); ! write(writer, document.getRootNode()); out.close(); } Index: XmlWriter.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/XmlWriter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** XmlWriter.java 26 Jan 2007 21:47:56 -0000 1.4 --- XmlWriter.java 26 Mar 2007 11:49:24 -0000 1.5 *************** *** 28,31 **** --- 28,32 ---- import jreepad.JreepadArticle; import jreepad.JreepadNode; + import jreepad.JreepadTreeModel; /** *************** *** 44,53 **** } ! 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); writer.close(); } --- 45,54 ---- } ! public void write(OutputStream out, JreepadTreeModel document) throws IOException { Writer writer = new OutputStreamWriter(out, encoding); writer.write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n"); ! writeNode(writer, document.getRootNode(), 0, true); writer.close(); } Index: JreepadWriter.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/JreepadWriter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** JreepadWriter.java 20 Jan 2007 13:01:35 -0000 1.2 --- JreepadWriter.java 26 Mar 2007 11:49:24 -0000 1.3 *************** *** 23,27 **** import java.io.OutputStream; ! import jreepad.JreepadNode; /** --- 23,27 ---- import java.io.OutputStream; ! import jreepad.JreepadTreeModel; /** *************** *** 33,36 **** public interface JreepadWriter { ! public void write(OutputStream out, JreepadNode node) throws IOException; } --- 33,36 ---- public interface JreepadWriter { ! public void write(OutputStream out, JreepadTreeModel document) throws IOException; } Index: TreepadReader.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/TreepadReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TreepadReader.java 26 Jan 2007 21:47:56 -0000 1.2 --- TreepadReader.java 26 Mar 2007 11:49:24 -0000 1.3 *************** *** 28,31 **** --- 28,33 ---- import jreepad.JreepadArticle; import jreepad.JreepadNode; + import jreepad.JreepadPrefs; + import jreepad.JreepadTreeModel; /** *************** *** 49,53 **** } ! public JreepadNode read(InputStream in) throws IOException { --- 51,55 ---- } ! public JreepadTreeModel read(InputStream in) throws IOException { *************** *** 119,123 **** nodeStack.push(newNode); } ! return rootNode; } --- 121,129 ---- nodeStack.push(newNode); } ! ! JreepadTreeModel document = new JreepadTreeModel(rootNode); ! document.setFileFormat(JreepadPrefs.FILETYPE_HJT); ! document.setEncoding(encoding); ! return document; } Index: TreepadWriter.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/TreepadWriter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TreepadWriter.java 20 Jan 2007 13:01:35 -0000 1.2 --- TreepadWriter.java 26 Mar 2007 11:49:24 -0000 1.3 *************** *** 27,30 **** --- 27,31 ---- import jreepad.JreepadNode; + import jreepad.JreepadTreeModel; /** *************** *** 44,53 **** } ! 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(); } --- 45,54 ---- } ! public void write(OutputStream out, JreepadTreeModel document) throws IOException { Writer writer = new OutputStreamWriter(out, encoding); writer.write("<Treepad version 2.7>\n"); ! writeNode(writer, document.getRootNode(), 0); writer.close(); } Index: JreepadReader.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/JreepadReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** JreepadReader.java 20 Jan 2007 13:01:19 -0000 1.2 --- JreepadReader.java 26 Mar 2007 11:49:24 -0000 1.3 *************** *** 23,27 **** import java.io.InputStream; ! import jreepad.JreepadNode; /** --- 23,27 ---- import java.io.InputStream; ! import jreepad.JreepadTreeModel; /** *************** *** 33,36 **** public interface JreepadReader { ! public JreepadNode read(InputStream in) throws IOException; } --- 33,36 ---- public interface JreepadReader { ! public JreepadTreeModel read(InputStream in) throws IOException; } Index: XmlReader.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/io/XmlReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** XmlReader.java 26 Jan 2007 21:47:55 -0000 1.2 --- XmlReader.java 26 Mar 2007 11:49:24 -0000 1.3 *************** *** 27,30 **** --- 27,32 ---- import jreepad.JreepadArticle; import jreepad.JreepadNode; + import jreepad.JreepadPrefs; + import jreepad.JreepadTreeModel; /** *************** *** 47,51 **** } ! public JreepadNode read(InputStream in) throws IOException { --- 49,53 ---- } ! public JreepadTreeModel read(InputStream in) throws IOException { *************** *** 76,80 **** // now: " + currentXmlContent); ! return readNode(reader, currentXmlContent, 0).node; } --- 78,85 ---- // now: " + currentXmlContent); ! JreepadTreeModel document = new JreepadTreeModel(readNode(reader, currentXmlContent, 0).node); ! document.setFileFormat(JreepadPrefs.FILETYPE_XML); ! document.setEncoding(encoding); ! return document; } |
From: PeWu <pe...@us...> - 2007-03-23 09:37:41
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv28832/src/jreepad Modified Files: JreepadTreeModel.java JreepadPrefs.java JreepadViewer.java Log Message: Moved the path to the currently open file (savedLocation) to JreepadTreeModel Index: JreepadPrefs.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadPrefs.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** JreepadPrefs.java 1 Mar 2007 12:10:59 -0000 1.24 --- JreepadPrefs.java 23 Mar 2007 09:37:36 -0000 1.25 *************** *** 41,45 **** { Preferences prefs; ! File openLocation, saveLocation, importLocation, exportLocation, backupLocation; boolean seenLicense; --- 41,45 ---- { Preferences prefs; ! File openLocation, importLocation, exportLocation, backupLocation; boolean seenLicense; *************** *** 77,81 **** Vector openRecentList; int openRecentListLength; ! File getMostRecentFile() // This is used, specifically, by the command-line "find" tool { if(openRecentList.size()==0) --- 77,81 ---- Vector openRecentList; int openRecentListLength; ! File getMostRecentFile() { if(openRecentList.size()==0) *************** *** 143,147 **** openLocation = new File(prefs.get("OPENLOCATION", System.getProperty("user.home"))); - saveLocation = new File(prefs.get("SAVELOCATION", System.getProperty("user.home"))); importLocation = new File(prefs.get("IMPORTLOCATION", System.getProperty("user.home"))); exportLocation = new File(prefs.get("EXPORTLOCATION", System.getProperty("user.home"))); --- 143,146 ---- *************** *** 253,257 **** { prefs.put("OPENLOCATION",""+openLocation); - prefs.put("SAVELOCATION", ""+saveLocation); prefs.put("IMPORTLOCATION", ""+importLocation); prefs.put("EXPORTLOCATION", ""+exportLocation); --- 252,255 ---- Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** JreepadViewer.java 21 Mar 2007 10:40:35 -0000 1.55 --- JreepadViewer.java 23 Mar 2007 09:37:36 -0000 1.56 *************** *** 268,272 **** yield(); // ...then if the saveLocation != null, trigger saveAction() ! if(getPrefs().autoSave && getPrefs().saveLocation != null) new SaveAction().actionPerformed(null); else --- 268,272 ---- yield(); // ...then if the saveLocation != null, trigger saveAction() ! if(getPrefs().autoSave && document.getSaveLocation() != null) new SaveAction().actionPerformed(null); else *************** *** 294,299 **** if(fileNameToLoad != "") firstTimeFile = new File(fileNameToLoad); ! else if(getPrefs().loadLastFileOnOpen && getPrefs().saveLocation != null) ! firstTimeFile = getPrefs().saveLocation; if(firstTimeFile != null && firstTimeFile.isFile()) --- 294,299 ---- if(fileNameToLoad != "") firstTimeFile = new File(fileNameToLoad); ! else if(getPrefs().loadLastFileOnOpen && getPrefs().getMostRecentFile() != null) ! firstTimeFile = getPrefs().getMostRecentFile(); if(firstTimeFile != null && firstTimeFile.isFile()) *************** *** 301,319 **** try { ! getPrefs().openLocation = firstTimeFile; content.remove(theJreepad); ! 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; content.add(theJreepad); searchDialog.setJreepad(theJreepad); ! getPrefs().saveLocation = getPrefs().openLocation; ! setTitleBasedOnFilename(getPrefs().openLocation.getName()); ! document.setContentSaved(true); } catch(IOException err) --- 301,318 ---- try { ! getPrefs().openLocation = firstTimeFile; // Remember the open directory content.remove(theJreepad); ! InputStream in = new FileInputStream(firstTimeFile); JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); document = new JreepadTreeModel(reader.read(in)); + document.setSaveLocation(firstTimeFile); theJreepad = new JreepadView(document); ! getPrefs().exportLocation = getPrefs().importLocation = firstTimeFile; content.add(theJreepad); searchDialog.setJreepad(theJreepad); ! setTitleBasedOnFilename(firstTimeFile.getName()); } catch(IOException err) *************** *** 328,333 **** } } - else - getPrefs().saveLocation = null; // Set close operation --- 327,330 ---- *************** *** 360,372 **** setVisible(true); ! // If loading the last-saved file, expand the nodes we last had open ! if(fileNameToLoad == "" ! && getPrefs().loadLastFileOnOpen ! && getPrefs().saveLocation != null ! && getPrefs().treePathCollection != null ! && getPrefs().treePathCollection.paths != null) ! { ! theJreepad.expandPaths(getPrefs().treePathCollection.paths); ! } theJreepad.returnFocusToTree(); } --- 357,364 ---- setVisible(true); ! // If loading the last-saved file, expand the nodes we last had open ! if(document.getSaveLocation() != null) ! theJreepad.expandPaths(getPrefs().treePathCollection.paths); ! theJreepad.returnFocusToTree(); } *************** *** 1281,1285 **** private boolean askAndSave(String prompt) { ! if (document == null || document.isContentSaved()) return true; int answer = JOptionPane.showConfirmDialog(this, prompt, --- 1273,1277 ---- private boolean askAndSave(String prompt) { ! if (document.isContentSaved()) return true; int answer = JOptionPane.showConfirmDialog(this, prompt, *************** *** 1305,1309 **** document = new JreepadTreeModel(); theJreepad = new JreepadView(document); - getPrefs().saveLocation = null; content.add(theJreepad); searchDialog.setJreepad(theJreepad); --- 1297,1300 ---- *************** *** 1336,1353 **** content.remove(theJreepad); ! 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; content.add(theJreepad); searchDialog.setJreepad(theJreepad); ! addToOpenRecentMenu(getPrefs().openLocation); ! setTitleBasedOnFilename(getPrefs().openLocation.getName()); validate(); repaint(); - document.setContentSaved(true); //DEL theJreepad.clearUndoCache(); setCursor(Cursor.getDefaultCursor()); --- 1327,1343 ---- content.remove(theJreepad); ! InputStream in = new FileInputStream(f); JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); document = new JreepadTreeModel(reader.read(in)); + document.setSaveLocation(f); theJreepad = new JreepadView(document); content.add(theJreepad); searchDialog.setJreepad(theJreepad); ! addToOpenRecentMenu(f); ! setTitleBasedOnFilename(f.getName()); validate(); repaint(); //DEL theJreepad.clearUndoCache(); setCursor(Cursor.getDefaultCursor()); *************** *** 1395,1403 **** { int fileType = getPrefs().mainFileType; ! if(askForFilename || getPrefs().saveLocation==null || (getPrefs().saveLocation.isFile() && !getPrefs().saveLocation.canWrite())) { // Ask for filename JFileChooser fileChooser = new SaveFileChooser(); ! fileChooser.setCurrentDirectory(getPrefs().saveLocation); fileChooser.addChoosableFileFilter(JREEPAD_FILE_FILTER); fileChooser.addChoosableFileFilter(TREEPAD_FILE_FILTER); --- 1385,1394 ---- { int fileType = getPrefs().mainFileType; ! File saveLocation = document.getSaveLocation(); ! if(askForFilename || saveLocation==null || (saveLocation.isFile() && !saveLocation.canWrite())) { // Ask for filename JFileChooser fileChooser = new SaveFileChooser(); ! fileChooser.setCurrentDirectory(getPrefs().openLocation); fileChooser.addChoosableFileFilter(JREEPAD_FILE_FILTER); fileChooser.addChoosableFileFilter(TREEPAD_FILE_FILTER); *************** *** 1414,1418 **** return; // No file chosen } ! getPrefs().saveLocation = fileChooser.getSelectedFile(); if (fileChooser.getFileFilter() == JREEPAD_FILE_FILTER) fileType = JreepadPrefs.FILETYPE_XML; --- 1405,1409 ---- return; // No file chosen } ! saveLocation = fileChooser.getSelectedFile(); if (fileChooser.getFileFilter() == JREEPAD_FILE_FILTER) fileType = JreepadPrefs.FILETYPE_XML; *************** *** 1420,1423 **** --- 1411,1415 ---- fileType = JreepadPrefs.FILETYPE_HJT; } + getPrefs().openLocation = saveLocation; // Remember the file's directory // Save the file *************** *** 1432,1445 **** else writer = new TreepadWriter(getPrefs().getEncoding()); ! OutputStream fos = new FileOutputStream(getPrefs().saveLocation); writer.write(fos, document.getRootNode()); fos.close(); if(MAC_OS_X){ ! com.apple.eio.FileManager.setFileTypeAndCreator(getPrefs().saveLocation.toString(), appleAppCode, appleAppCode); } ! document.setContentSaved(true); updateWindowTitle(); savePreferencesFile(); setCursor(Cursor.getDefaultCursor()); --- 1424,1438 ---- else writer = new TreepadWriter(getPrefs().getEncoding()); ! OutputStream fos = new FileOutputStream(saveLocation); writer.write(fos, document.getRootNode()); fos.close(); if(MAC_OS_X){ ! com.apple.eio.FileManager.setFileTypeAndCreator(saveLocation.toString(), appleAppCode, appleAppCode); } ! document.setSaveLocation(saveLocation); updateWindowTitle(); + addToOpenRecentMenu(saveLocation); savePreferencesFile(); setCursor(Cursor.getDefaultCursor()); *************** *** 1502,1506 **** private void updateWindowTitle() { ! setTitle(windowTitle + ((document == null || document.isContentSaved())?"":"*") + (getPrefs().autoSave?" ["+lang.getString("AUTOSAVE_ACTIVE")+"]":"")); } --- 1495,1499 ---- private void updateWindowTitle() { ! setTitle(windowTitle + (document.isContentSaved()?"":"*") + (getPrefs().autoSave?" ["+lang.getString("AUTOSAVE_ACTIVE")+"]":"")); } Index: JreepadTreeModel.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadTreeModel.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** JreepadTreeModel.java 21 Mar 2007 09:40:52 -0000 1.3 --- JreepadTreeModel.java 23 Mar 2007 09:37:36 -0000 1.4 *************** *** 1,4 **** --- 1,6 ---- package jreepad; + import java.io.File; + import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; *************** *** 12,15 **** --- 14,22 ---- { /** + * The location, where the document was last saved. + */ + private File saveLocation = null; + + /** * True if the current document content has been saved. */ *************** *** 67,69 **** --- 74,87 ---- this.contentSaved = contentSaved; } + + public void setSaveLocation(File saveLocation) + { + this.saveLocation = saveLocation; + setContentSaved(true); + } + + public File getSaveLocation() + { + return saveLocation; + } } |
From: PeWu <pe...@us...> - 2007-03-21 10:40:41
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv2551/src/jreepad Modified Files: TreeView.java JreepadViewer.java JreepadView.java Log Message: cleanup: Removed unneeded code Index: JreepadView.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadView.java,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** JreepadView.java 21 Mar 2007 09:40:52 -0000 1.46 --- JreepadView.java 21 Mar 2007 10:40:35 -0000 1.47 *************** *** 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)); --- 427,430 ---- *************** *** 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)); --- 449,452 ---- *************** *** 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)}); --- 458,461 ---- *************** *** 893,897 **** currentNode.getArticle().wrapContentToCharWidth(charWidth); currentArticleView.reloadArticle(); - treeModel.setContentSaved(false); } --- 890,893 ---- *************** *** 901,905 **** currentNode.getArticle().stripAllTags(); currentArticleView.reloadArticle(); - treeModel.setContentSaved(false); } --- 897,900 ---- Index: TreeView.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/TreeView.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TreeView.java 15 Mar 2007 12:46:05 -0000 1.4 --- TreeView.java 21 Mar 2007 10:40:35 -0000 1.5 *************** *** 27,34 **** 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; --- 27,31 ---- *************** *** 43,47 **** public class TreeView extends JTree { - private static final String UNTITLED_NODE_TEXT = "<Untitled node>"; private JreepadTreeModel treeModel; --- 40,43 ---- *************** *** 62,103 **** 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(); - } - - public void editingStopped(ChangeEvent e) - { - ensureNodeTitleIsNotEmpty(); - } - }); - // 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_TEXT); - } - - private void ensureNodeTitleIsNotEmpty() - { - TreeCellEditor theEditor = getCellEditor(); - String newTitle = (String) (theEditor.getCellEditorValue()); - - if (newTitle.equals("")) - theEditor.getTreeCellEditorComponent(this, UNTITLED_NODE_TEXT, - true, true, false, 1); - } - public void moveNode(JreepadNode node, JreepadNode newParent) { --- 58,65 ---- Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** JreepadViewer.java 21 Mar 2007 09:40:52 -0000 1.54 --- JreepadViewer.java 21 Mar 2007 10:40:35 -0000 1.55 *************** *** 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); --- 535,547 ---- JMenuItem addAboveMenuItem = new JMenuItem(lang.getString("MENUITEM_ADDABOVE")); //"Add sibling above"); ! addAboveMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { theJreepad.addNodeAbove(); 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(); 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(); updateWindowTitle(); }}); editMenu.add(addChildMenuItem); *************** *** 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); --- 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(); 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(); updateWindowTitle(); }}); editMenu.add(downMenuItem); *************** *** 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); --- 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(); 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(); updateWindowTitle(); }}); editMenu.add(outdentMenuItem); *************** *** 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); --- 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(); 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(); updateWindowTitle(); }}); actionsMenu.add(sortRecursiveMenuItem); *************** *** 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(); } }); --- 931,943 ---- // Add the actions to the toolbar buttons upButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.moveCurrentNodeUp(); repaint(); theJreepad.returnFocusToTree(); updateWindowTitle();} }); downButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.moveCurrentNodeDown(); repaint(); theJreepad.returnFocusToTree(); updateWindowTitle();} }); indentButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.indentCurrentNode(); repaint(); theJreepad.returnFocusToTree(); updateWindowTitle();} }); outdentButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.outdentCurrentNode(); repaint(); theJreepad.returnFocusToTree(); updateWindowTitle(); } }); *************** *** 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(); } }); --- 945,953 ---- addAboveButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.addNodeAbove(); repaint(); updateWindowTitle();} }); addBelowButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.addNodeBelow(); repaint(); updateWindowTitle();} }); addButton.addActionListener(new ActionListener(){ ! public void actionPerformed(ActionEvent e){ theJreepad.addNode(); repaint(); updateWindowTitle();} }); removeButton.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(); } }); --- 1038,1066 ---- public void actionPerformed(ActionEvent e){ theJreepad.moveCurrentNodeUp(); repaint(); theJreepad.returnFocusToTree(); ! updateWindowTitle();} }); downIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.moveCurrentNodeDown(); repaint(); theJreepad.returnFocusToTree(); ! updateWindowTitle();} }); indentIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.indentCurrentNode(); repaint(); theJreepad.returnFocusToTree(); ! updateWindowTitle();} }); outdentIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.outdentCurrentNode(); repaint(); theJreepad.returnFocusToTree(); ! updateWindowTitle(); } }); addAboveIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.addNodeAbove(); repaint(); /* theJreepad.returnFocusToTree(); */ ! updateWindowTitle();} }); addBelowIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.addNodeBelow(); repaint(); /* theJreepad.returnFocusToTree(); */ ! updateWindowTitle();} }); addIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.addNode(); repaint(); /* theJreepad.returnFocusToTree(); */ ! updateWindowTitle();} }); removeIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ deleteNodeAction(); } }); *************** *** 1547,1551 **** return; } - document.setContentSaved(false); updateWindowTitle(); } --- 1547,1550 ---- *************** *** 1905,1909 **** theJreepad.removeNode(); theJreepad.returnFocusToTree(); - document.setContentSaved(false); updateWindowTitle(); } --- 1904,1907 ---- |
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; + } } |
From: PeWu <pe...@us...> - 2007-03-20 10:18:22
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv2400/src/jreepad Modified Files: JreepadViewer.java Log Message: Use Action interface for saveAction. Added possibility to choose file format in the save dialog. Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** JreepadViewer.java 15 Mar 2007 12:46:19 -0000 1.52 --- JreepadViewer.java 20 Mar 2007 10:18:17 -0000 1.53 *************** *** 21,41 **** package jreepad; ! import javax.swing.*; ! import javax.swing.undo.*; ! import java.awt.*; ! import java.awt.event.*; ! import java.io.*; ! import java.util.*; import java.net.URL; ! import java.awt.datatransfer.*; ! ! //import javax.swing.plaf.metal.MetalIconFactory; // For icons ! ! 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.lang.reflect.*; import jreepad.io.AutoDetectReader; --- 21,82 ---- package jreepad; ! import java.awt.Color; ! import java.awt.Container; ! import java.awt.Cursor; ! import java.awt.Dimension; ! import java.awt.Event; ! import java.awt.Toolkit; ! import java.awt.datatransfer.Clipboard; ! import java.awt.datatransfer.DataFlavor; ! import java.awt.datatransfer.Transferable; ! import java.awt.event.ActionEvent; ! import java.awt.event.ActionListener; ! import java.awt.event.KeyEvent; ! import java.awt.event.WindowAdapter; ! import java.awt.event.WindowEvent; ! import java.io.DataOutputStream; ! import java.io.File; ! import java.io.FileInputStream; ! import java.io.FileOutputStream; ! import java.io.IOException; ! import java.io.InputStream; ! import java.io.InputStreamReader; ! import java.io.OutputStream; ! import java.io.OutputStreamWriter; ! import java.io.Reader; ! import java.lang.reflect.Method; import java.net.URL; ! import java.util.ListIterator; ! import java.util.ResourceBundle; ! import java.util.Vector; ! import javax.swing.AbstractAction; ! import javax.swing.Box; ! import javax.swing.BoxLayout; ! import javax.swing.Icon; ! import javax.swing.ImageIcon; ! import javax.swing.JButton; ! import javax.swing.JCheckBox; ! import javax.swing.JCheckBoxMenuItem; ! import javax.swing.JComboBox; ! import javax.swing.JDialog; ! import javax.swing.JFileChooser; ! import javax.swing.JFrame; ! import javax.swing.JLabel; ! import javax.swing.JMenu; ! import javax.swing.JMenuBar; ! import javax.swing.JMenuItem; ! import javax.swing.JOptionPane; ! import javax.swing.JPanel; ! import javax.swing.JSeparator; ! import javax.swing.JSpinner; ! import javax.swing.JTextField; ! import javax.swing.KeyStroke; ! import javax.swing.SpinnerNumberModel; ! import javax.swing.UIManager; ! import javax.swing.filechooser.FileFilter; ! import javax.swing.undo.CannotRedoException; ! import javax.swing.undo.CannotUndoException; ! import javax.swing.undo.UndoManager; import jreepad.io.AutoDetectReader; *************** *** 45,48 **** --- 86,95 ---- import jreepad.io.TreepadWriter; import jreepad.io.XmlWriter; + import jreepad.ui.ExtensionFileFilter; + import jreepad.ui.SaveFileChooser; + import edu.stanford.ejalbert.BrowserLauncher; + import edu.stanford.ejalbert.exception.BrowserLaunchingExecutionException; + import edu.stanford.ejalbert.exception.BrowserLaunchingInitializingException; + import edu.stanford.ejalbert.exception.UnsupportedOperatingSystemException; public class JreepadViewer extends JFrame // implements ApplicationListener *************** *** 76,80 **** private JButton newIconButton; private JButton openIconButton; - private JButton saveIconButton; private JButton addAboveIconButton; private JButton addBelowIconButton; --- 123,126 ---- *************** *** 131,134 **** --- 177,190 ---- public static final int appleAppCode = 0x4A524545; + /** + * File filter for Jreepad XML .jree files. + */ + private static final FileFilter JREEPAD_FILE_FILTER = new ExtensionFileFilter("Jreepad XML file (*.jree)", "jree"); + + /** + * File filter for Treepad .hjt files. + */ + private static final FileFilter TREEPAD_FILE_FILTER = new ExtensionFileFilter("Treepad file (*.hjt)", "hjt"); + public JreepadViewer() { *************** *** 211,216 **** // ...then if the saveLocation != null, trigger saveAction() if(getPrefs().autoSave && getPrefs().saveLocation != null) ! saveAction(); ! else updateWindowTitle(); } --- 267,272 ---- // ...then if the saveLocation != null, trigger saveAction() if(getPrefs().autoSave && getPrefs().saveLocation != null) ! new SaveAction().actionPerformed(null); ! else updateWindowTitle(); } *************** *** 348,358 **** fileMenu.add(openRecentMenu); ! JMenuItem saveMenuItem = new JMenuItem(lang.getString("MENUITEM_SAVE")); //"Save"); ! saveMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {saveAction();}}); ! fileMenu.add(saveMenuItem); ! ! JMenuItem saveAsMenuItem = new JMenuItem(lang.getString("MENUITEM_SAVEAS")); //"Save as..."); ! saveAsMenuItem.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {saveAsAction();}}); ! fileMenu.add(saveAsMenuItem); JMenuItem backupToMenuItem = new JMenuItem(lang.getString("MENUITEM_BACKUPTO")); //"Backup to..."); --- 404,409 ---- fileMenu.add(openRecentMenu); ! fileMenu.add(new SaveAction()); // Save ! fileMenu.add(new SaveAction(true)); // Save As JMenuItem backupToMenuItem = new JMenuItem(lang.getString("MENUITEM_BACKUPTO")); //"Backup to..."); *************** *** 403,409 **** openMenuItem.setAccelerator(KeyStroke.getKeyStroke('O', MENU_MASK)); openRecentMenu.setMnemonic('R'); - saveMenuItem.setMnemonic('S'); - saveMenuItem.setAccelerator(KeyStroke.getKeyStroke('S', MENU_MASK)); - saveAsMenuItem.setMnemonic('A'); printSubtreeMenuItem.setMnemonic('P'); printSubtreeMenuItem.setAccelerator(KeyStroke.getKeyStroke('P', MENU_MASK)); --- 454,457 ---- *************** *** 916,923 **** // Save current ! saveIconButton = new JButton(); ! saveIconButton.setToolTipText(lang.getString("TOOLBAR_SAVE")); saveIconButton.setBorderPainted(false); ! saveIconButton.setIcon(this.getIcon("Save16.gif")); // Insert node before --- 964,970 ---- // Save current ! JButton saveIconButton = new JButton(new SaveAction()); saveIconButton.setBorderPainted(false); ! saveIconButton.setText(null); // Ignore action text // Insert node before *************** *** 984,989 **** openIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ openAction(); } }); - saveIconButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e){ saveAction(); } }); upIconButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theJreepad.moveCurrentNodeUp(); repaint(); --- 1031,1034 ---- *************** *** 1224,1239 **** } ! private void newAction() { ! if(warnAboutUnsaved()) { ! int answer = JOptionPane.showConfirmDialog(this, lang.getString("PROMPT_SAVE_BEFORE_NEW"), ! "Save?" , JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); ! if(answer == JOptionPane.CANCEL_OPTION) ! return; ! else if(answer == JOptionPane.YES_OPTION) ! if(!saveAction()) ! return; // This cancels "New" if the save action failed or was cancelled } content.remove(theJreepad); theJreepad = new JreepadView(new JreepadNode("<Untitled node>",theJreepad.getContentForNewNode())); --- 1269,1301 ---- } ! /** ! * 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; ! * false if the user clicked "Cancel" or the save failed ! */ ! private boolean askAndSave(String prompt) { ! if (!warnAboutUnsaved()) ! return true; ! int answer = JOptionPane.showConfirmDialog(this, prompt, ! "Save?" , JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); ! if(answer == JOptionPane.CANCEL_OPTION) ! return false; ! if(answer == JOptionPane.YES_OPTION) { ! SaveAction saveAction = new SaveAction(); ! saveAction.actionPerformed(null); ! if (!saveAction.isSuccessful()) ! return false; } + return true; + } + + private void newAction() + { + if (!askAndSave(lang.getString("PROMPT_SAVE_BEFORE_NEW"))) + return; + content.remove(theJreepad); theJreepad = new JreepadView(new JreepadNode("<Untitled node>",theJreepad.getContentForNewNode())); *************** *** 1252,1265 **** private void openAction() { ! if(warnAboutUnsaved()) ! { ! int answer = JOptionPane.showConfirmDialog(this, lang.getString("PROMPT_SAVE_BEFORE_OPEN"), ! "Save?" , JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); ! if(answer == JOptionPane.CANCEL_OPTION) ! return; ! else if(answer == JOptionPane.YES_OPTION) ! if(!saveAction()) ! return; // This cancels quit if the save action failed or was cancelled ! } fileChooser.setCurrentDirectory(getPrefs().openLocation); --- 1314,1319 ---- private void openAction() { ! if (!askAndSave(lang.getString("PROMPT_SAVE_BEFORE_OPEN"))) ! return; fileChooser.setCurrentDirectory(getPrefs().openLocation); *************** *** 1302,1390 **** ! private boolean saveAction() { ! if(getPrefs().saveLocation==null || (getPrefs().saveLocation.isFile() && !getPrefs().saveLocation.canWrite())) ! { ! return saveAsAction(); ! } ! try ! { ! 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(), ! appleAppCode, appleAppCode); ! } ! setWarnAboutUnsaved(false); ! updateWindowTitle(); ! savePreferencesFile(); ! setCursor(Cursor.getDefaultCursor()); ! return true; } ! catch(IOException err) { ! setCursor(Cursor.getDefaultCursor()); ! JOptionPane.showMessageDialog(this, err, lang.getString("TITLE_FILE_ERROR") , JOptionPane.ERROR_MESSAGE); } ! return false; ! } ! private boolean saveAsAction() ! { ! try { ! fileChooser.setCurrentDirectory(getPrefs().saveLocation); ! fileChooser.setSelectedFile(new File(theJreepad.getRootJreepadNode().getTitle() + ! (getPrefs().mainFileType==JreepadPrefs.FILETYPE_XML?".jree":".hjt") )); ! if(fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION && checkOverwrite(fileChooser.getSelectedFile())) ! { ! if(fileChooser.getSelectedFile().isFile() && !fileChooser.getSelectedFile().canWrite()) { ! JOptionPane.showMessageDialog(this, lang.getString("MSG_FILE_NOT_WRITEABLE"), lang.getString("TITLE_FILE_ERROR") , JOptionPane.ERROR_MESSAGE); ! return saveAsAction(); } ! setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); ! 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(), ! appleAppCode, appleAppCode); } - setWarnAboutUnsaved(false); - setTitleBasedOnFilename(getPrefs().saveLocation.getName()); - savePreferencesFile(); - setCursor(Cursor.getDefaultCursor()); - return true; - } - else - return false; } ! catch(IOException err) { ! setCursor(Cursor.getDefaultCursor()); ! JOptionPane.showMessageDialog(this, err, lang.getString("TITLE_FILE_ERROR") , JOptionPane.ERROR_MESSAGE); } ! return false; ! } // End of: saveAsAction() private boolean backupToAction() --- 1356,1456 ---- ! private class SaveAction extends AbstractAction { ! private boolean askForFilename; ! private boolean successful = false; ! public SaveAction() ! { ! this(false); } ! ! public SaveAction(boolean askForFilename) { ! super(askForFilename ? lang.getString("MENUITEM_SAVEAS") : lang.getString("MENUITEM_SAVE"), ! getIcon("Save16.gif")); ! this.askForFilename = askForFilename; ! ! if (askForFilename) ! { ! putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_A)); ! putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('A', MENU_MASK)); ! } ! else ! { ! putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_S)); ! putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('S', MENU_MASK)); ! putValue(SHORT_DESCRIPTION, lang.getString("TOOLBAR_SAVE")); ! } } ! ! public void actionPerformed(ActionEvent e) { ! int fileType = getPrefs().mainFileType; ! if(askForFilename || getPrefs().saveLocation==null || (getPrefs().saveLocation.isFile() && !getPrefs().saveLocation.canWrite())) { ! // Ask for filename ! JFileChooser fileChooser = new SaveFileChooser(); ! fileChooser.setCurrentDirectory(getPrefs().saveLocation); ! fileChooser.addChoosableFileFilter(JREEPAD_FILE_FILTER); ! fileChooser.addChoosableFileFilter(TREEPAD_FILE_FILTER); ! if (getPrefs().mainFileType == JreepadPrefs.FILETYPE_XML) ! fileChooser.setFileFilter(JREEPAD_FILE_FILTER); ! else ! 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) ! { ! successful = false; ! return; // No file chosen ! } ! getPrefs().saveLocation = fileChooser.getSelectedFile(); ! if (fileChooser.getFileFilter() == JREEPAD_FILE_FILTER) ! fileType = JreepadPrefs.FILETYPE_XML; ! else if (fileChooser.getFileFilter() == TREEPAD_FILE_FILTER) ! fileType = JreepadPrefs.FILETYPE_HJT; } ! // Save the file ! try ! { ! setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); ! // Write to either HJT or XML ! JreepadWriter writer; ! if(fileType == 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(), ! appleAppCode, appleAppCode); ! } ! setWarnAboutUnsaved(false); ! updateWindowTitle(); ! savePreferencesFile(); ! setCursor(Cursor.getDefaultCursor()); ! successful = true; ! } ! catch(IOException err) ! { ! setCursor(Cursor.getDefaultCursor()); ! JOptionPane.showMessageDialog(JreepadViewer.this, err, lang.getString("TITLE_FILE_ERROR") , JOptionPane.ERROR_MESSAGE); ! successful = false; } } ! ! public boolean isSuccessful() { ! return successful; } ! } private boolean backupToAction() *************** *** 1665,1678 **** // ! if(warnAboutUnsaved()) ! { ! int answer = JOptionPane.showConfirmDialog(this, lang.getString("PROMPT_SAVE_BEFORE_QUIT"), ! lang.getString("TITLE_SAVEPROMPT") , JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); ! if(answer == JOptionPane.CANCEL_OPTION) ! return; ! else if(answer == JOptionPane.YES_OPTION) ! if(!saveAction()) ! return; // This cancels quit if the save action failed or was cancelled ! } // Save preferences - including window position and size, and open/closed state of the current tree's nodes --- 1731,1736 ---- // ! if (!askAndSave(lang.getString("PROMPT_SAVE_BEFORE_QUIT"))) ! return; // Save preferences - including window position and size, and open/closed state of the current tree's nodes *************** *** 1855,1861 **** { // If file doesn't already exist then fine ! if(!theFile.isFile()) return true; // Else we need to confirm ! return (JOptionPane.showConfirmDialog(this, lang.getString("PROMPT_CONFIRM_OVERWRITE1")+theFile.getName()+lang.getString("PROMPT_CONFIRM_OVERWRITE2"), lang.getString("TITLE_CONFIRM_OVERWRITE"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION); --- 1913,1921 ---- { // If file doesn't already exist then fine ! if(theFile == null || !theFile.exists()) ! return true; ! // Else we need to confirm ! return (JOptionPane.showConfirmDialog(this, lang.getString("PROMPT_CONFIRM_OVERWRITE1")+" "+theFile.getName()+" "+lang.getString("PROMPT_CONFIRM_OVERWRITE2"), lang.getString("TITLE_CONFIRM_OVERWRITE"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION); *************** *** 2350,2354 **** - /* // Methods required by Apple's "ApplicationListener" interface --- 2410,2413 ---- |
From: PeWu <pe...@us...> - 2007-03-20 10:18:22
|
Update of /cvsroot/jreepad/jreepad/src/jreepad/ui In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv2108/src/jreepad/ui Log Message: Directory /cvsroot/jreepad/jreepad/src/jreepad/ui added to the repository |
From: PeWu <pe...@us...> - 2007-03-20 10:18:22
|
Update of /cvsroot/jreepad/jreepad/src/jreepad/ui In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv2400/src/jreepad/ui Added Files: SaveFileChooser.java ExtensionFileFilter.java Log Message: Use Action interface for saveAction. Added possibility to choose file format in the save dialog. --- NEW FILE: ExtensionFileFilter.java --- package jreepad.ui; import java.io.File; import javax.swing.filechooser.FileFilter; /** * File filter, which accepts only files with the given extension. */ public class ExtensionFileFilter extends FileFilter { /** * Description of this filter. */ private String description; /** * Allowed extension. */ private String extension; /** * Lowercase version of the extension. */ private String lowercaseExtension; public ExtensionFileFilter(String description, String extension) { this.description = description; this.extension = extension; this.lowercaseExtension = extension.toLowerCase(); } /** * Tests whether the given file has the appropriate extension. */ public boolean accept(File f) { if (f == null) return false; if (f.isDirectory()) return true; String fileName = f.getName(); int i = fileName.lastIndexOf('.'); if (i <= 0 || i >= fileName.length() - 1) return false; String fileExtension = fileName.substring(i + 1).toLowerCase(); if (fileExtension.equals(lowercaseExtension)) return true; return false; } /** * Returns the description of this filter. */ public String getDescription() { return description; } /** * Returns the filtered file extension. */ public String getExtension() { return extension; } } --- NEW FILE: SaveFileChooser.java --- package jreepad.ui; import java.io.File; import java.util.ResourceBundle; import javax.swing.JFileChooser; import javax.swing.JOptionPane; public class SaveFileChooser extends JFileChooser { protected static final ResourceBundle LANG = ResourceBundle.getBundle("jreepad.lang.JreepadStrings"); public void approveSelection() { if (!checkOverwrite(getSelectedFile())) return; // User doesn't want to overwrite the file if (getSelectedFile().isFile() && !getSelectedFile().canWrite()) { JOptionPane.showMessageDialog(this, LANG.getString("MSG_FILE_NOT_WRITEABLE"), LANG.getString("TITLE_FILE_ERROR"), JOptionPane.ERROR_MESSAGE); return; // Can't write selected file } super.approveSelection(); } private boolean checkOverwrite(File theFile) { // If file doesn't already exist then fine if (theFile == null || !theFile.exists()) return true; // Else we need to confirm return (JOptionPane.showConfirmDialog(this, LANG.getString("PROMPT_CONFIRM_OVERWRITE1") + " " + theFile.getName() + " " + LANG.getString("PROMPT_CONFIRM_OVERWRITE2"), LANG.getString("TITLE_CONFIRM_OVERWRITE"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION); } } |