Author: psmith
Date: Tue Jul 10 15:18:23 2007
New Revision: 555100
URL: http://svn.apache.org/viewvc?view=rev&rev=555100
Log:
Committing patch for Bug 42789 supplied by Isuru Suriarachchi
which allows saving of previous log filter expressions for named LogPanels.
This change uses a serialization version number to support previous older
versions of serialized settings.
Modified:
logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
Modified:
logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
URL:
http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java?view=diff&rev=555100&r1=555099&r2=555100
==============================================================================
---
logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
(original)
+++
logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
Tue Jul 10 15:18:23 2007
@@ -90,6 +90,7 @@
import javax.swing.JSeparator;
import javax.swing.JSplitPane;
import javax.swing.JTable;
+import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToolBar;
@@ -186,6 +187,7 @@
[EMAIL PROTECTED] Scott Deboy (sdeboy at apache.org)
[EMAIL PROTECTED] Paul Smith (psmith at apache.org)
[EMAIL PROTECTED] Stephen Pain
+ [EMAIL PROTECTED] Isuru Suriarachchi
*
*/
public class LogPanel extends DockablePanel implements EventBatchListener,
@@ -233,9 +235,11 @@
static final String TABLE_COLUMN_WIDTHS = "table.columns.widths";
static final String COLUMNS_EXTENSION = ".columns";
static final String COLORS_EXTENSION = ".colors";
+ private static final int LOG_PANEL_SERIALIZATION_VERSION_NUMBER = 1;
private int previousLastIndex = -1;
private final DateFormat timestampExpressionFormat = new
SimpleDateFormat(Constants.TIMESTAMP_RULE_FORMAT);
private final Logger logger = LogManager.getLogger(LogPanel.class);
+ private final Vector filterExpressionVector;
/**
* Creates a new LogPanel object. If a LogPanel with this identifier has
@@ -893,16 +897,17 @@
upperLeftPanel.add(filterLabel);
//hold a reference to the combobox model so that we can check to prevent
duplicates
- final Vector v = new Vector();
+ //final Vector filterExpressionVector = new Vector();
+ filterExpressionVector = new Vector();
//add (hopefully useful) default filters
- v.add("LEVEL == TRACE");
- v.add("LEVEL >= DEBUG");
- v.add("LEVEL >= INFO");
- v.add("LEVEL >= WARN");
- v.add("LEVEL >= ERROR");
- v.add("LEVEL == FATAL");
+ filterExpressionVector.add("LEVEL == TRACE");
+ filterExpressionVector.add("LEVEL >= DEBUG");
+ filterExpressionVector.add("LEVEL >= INFO");
+ filterExpressionVector.add("LEVEL >= WARN");
+ filterExpressionVector.add("LEVEL >= ERROR");
+ filterExpressionVector.add("LEVEL == FATAL");
- final JComboBox filterCombo = new JComboBox(v);
+ final JComboBox filterCombo = new JComboBox(filterExpressionVector);
filterCombo.setSelectedIndex(-1);
final JTextField filterText;
@@ -930,7 +935,7 @@
}
//should be 'valid expression' check
- if (!(v.contains(filterCombo.getSelectedItem()))) {
+ if
(!(filterExpressionVector.contains(filterCombo.getSelectedItem()))) {
filterCombo.addItem(filterCombo.getSelectedItem());
}
}
@@ -952,6 +957,25 @@
JPanel upperRightPanel =
new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
+ //Adding a button to clear filter expressions which are currently
remembered by Chainsaw...
+ final JButton clearButton = new JButton("Clear expression");
+ clearButton.setToolTipText("Click here to remove the selected expression
from the list");
+ clearButton.addActionListener(
+ new AbstractAction() {
+ public void actionPerformed(ActionEvent e){
+ String selectedItem =
filterCombo.getSelectedItem().toString();
+ if (e.getSource() == clearButton &&
!selectedItem.equals("")){
+ if (filterExpressionVector.contains(selectedItem)){
+ filterExpressionVector.remove(selectedItem);
+ }
+ filterCombo.setSelectedIndex(-1);
+ }
+ }
+ }
+ );
+
+ upperRightPanel.add(clearButton);
+
upperPanel.add(upperRightPanel, BorderLayout.EAST);
/*
@@ -1439,7 +1463,30 @@
Point p = (Point)in.readObject();
undockedFrame.setLocation(p.x, p.y);
undockedFrame.setSize(((Dimension)in.readObject()));
- } catch (EOFException eof){}
+
+ int versionNumber = 0;
+ Vector savedVector;
+
+ //this version number is checked to identify whether there is
a Vector comming next
+ try {
+ versionNumber = in.readInt();
+ } catch (EOFException eof){
+ }
+
+ //read the vector only if the version number is greater than
0. higher version numbers can be
+ //used in the future to save more data structures
+ if (versionNumber > 0){
+ savedVector = (Vector) in.readObject();
+ for(int i = 0 ; i < savedVector.size() ; i++){
+ Object item = savedVector.get(i);
+ if(!filterExpressionVector.contains(item)){
+ filterExpressionVector.add(item);
+ }
+ }
+ }
+
+ } catch (EOFException eof){
+ }
} catch (Exception e) {
e.printStackTrace();
// TODO need to log this..
@@ -1496,11 +1543,14 @@
FileWriter w = new FileWriter(xmlFile);
s = stream.createObjectOutputStream(w);
s.writeObject(preferenceModel);
- s.writeInt(lowerPanel.getDividerLocation());
+ s.writeInt(lowerPanel.getDividerLocation());
s.writeInt(nameTreeAndMainPanelSplit.getDividerLocation());
s.writeObject(detailLayout.getConversionPattern());
s.writeObject(undockedFrame.getLocation());
s.writeObject(undockedFrame.getSize());
+ //this is a version number written to the file to identify that there
is a Vector serialized after this
+ s.writeInt(LOG_PANEL_SERIALIZATION_VERSION_NUMBER);
+ s.writeObject(filterExpressionVector);
} catch (Exception ex) {
ex.printStackTrace();
// TODO need to log this..