You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ps...@apache.org on 2003/04/30 10:47:29 UTC
cvs commit: jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw FileLoadAction.java
psmith 2003/04/30 01:47:29
Modified: src/java/org/apache/log4j/chainsaw FileLoadAction.java
Log:
actually Implemented this action so it does something. Uses an
XMLDecoder to digest the file into a Collection of events and posts
them to the configured LogUI's ChainsawAppenderHandler.
Revision Changes Path
1.2 +53 -5 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/FileLoadAction.java
Index: FileLoadAction.java
===================================================================
RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/FileLoadAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FileLoadAction.java 30 Apr 2003 04:20:59 -0000 1.1
+++ FileLoadAction.java 30 Apr 2003 08:47:29 -0000 1.2
@@ -6,10 +6,16 @@
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
+import java.io.File;
+import java.io.IOException;
+import java.util.Vector;
import javax.swing.AbstractAction;
import javax.swing.Action;
-import javax.swing.Icon;
+import javax.swing.JFileChooser;
+import javax.swing.filechooser.FileFilter;
+
+import org.apache.log4j.xml.XMLDecoder;
/**
* Allows the user to specify a particular file to open
@@ -21,21 +27,63 @@
class FileLoadAction extends AbstractAction {
/**
+ * This action must have a reference to a LogUI
+ * window so that it can append the events it loads
*
*/
- public FileLoadAction() {
+ public FileLoadAction(LogUI parent) {
super("Load");
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_L));
putValue(Action.SHORT_DESCRIPTION, "Loads an XML event file");
+// TODO be nice if this also had an Icon
+ this.parent = parent;
}
- /* (non-Javadoc)
+ /*
+ * When the user chooses the Load action,
+ * a File chooser is presented to allow them to
+ * find an XML file to load events from.
+ *
+ * Any events decoded from this file are added to
+ * one of the tabs.
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
+
+ JFileChooser chooser = new JFileChooser();
+
+ chooser.setAcceptAllFileFilterUsed(true);
- System.out.println("Load action");
+ chooser.setFileFilter(new FileFilter() {
+ public boolean accept(File f) {
+ return f.getName().toLowerCase().endsWith(".xml");
+ }
+
+ public String getDescription() {
+ return "XML files (*.xml)";
+ }
+ });
+
+ chooser.showOpenDialog(parent);
+
+ File selectedFile = chooser.getSelectedFile();
+
+ if (selectedFile != null) {
+ XMLDecoder decoder = new XMLDecoder();
+ try {
+ Vector events = decoder.decode(selectedFile);
+ // TODO Ensure the events have location info
+ parent.handler.appendBatch(events);
+ } catch (IOException e1) {
+ // TODO Handle the error with a nice msg
+ e1.printStackTrace();
+ }
+ }
+
}
-
+
+ private LogUI parent;
}
+
+
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org