sdeboy 2003/06/16 00:24:40
Modified: src/java/org/apache/log4j/chainsaw
ChainsawCyclicBufferTableModel.java LogUI.java
ColorDisplaySelector.java
ChainsawToolBarAndMenus.java
Log:
Updated detail text display to work with a single-row table.
Changed L&F code - now a change to L&F is applied on restart.
Modified colorFilter tablemodel update code.
Revision Changes Path
1.16 +138 -2
jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java
Index: ChainsawCyclicBufferTableModel.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ChainsawCyclicBufferTableModel.java 14 Jun 2003 21:30:44 -0000 1.15
+++ ChainsawCyclicBufferTableModel.java 16 Jun 2003 07:24:40 -0000 1.16
@@ -49,10 +49,18 @@
package org.apache.log4j.chainsaw;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
import org.apache.log4j.helpers.LogLog;
+import org.apache.log4j.spi.LocationInfo;
+import org.apache.log4j.spi.LoggingEvent;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
@@ -80,6 +88,8 @@
implements EventContainer {
final List unfilteredList;
final List filteredList;
+ private static final DateFormat DATE_FORMATTER =
+ new SimpleDateFormat(ChainsawConstants.DATETIME_FORMAT);
private Vector countListeners = new Vector();
private boolean currentSortAscending;
private int currentSortColumn;
@@ -249,11 +259,137 @@
}
public Vector getAllEvents() {
+ Vector v = new Vector();
synchronized (syncLock) {
- Vector v = new Vector(unfilteredList);
+ Iterator iter = unfilteredList.iterator();
- return v;
+ while (iter.hasNext()) {
+ v.add(getEvent((Vector)iter.next()));
+ }
}
+
+ return v;
+ }
+
+public LoggingEvent getEvent(Vector v) {
+ Integer ID = new
Integer(v.get(ChainsawColumns.getColumnsNames().indexOf(ChainsawConstants.ID_COL_NAME)).toString());
+ ListIterator iter = ChainsawColumns.getColumnsNames().listIterator();
+ String column = null;
+ int index = -1;
+
+ //iterate through all column names and set the value from the unfiltered event
+ long timeStamp = 0L;
+ Logger logger = null;
+ String level = null;
+ String threadName = "";
+ Object message = null;
+ String ndc = "";
+ Hashtable mdc = null;
+ String[] exception = null;
+ String className = "";
+ String methodName = "";
+ String fileName = "";
+ String lineNumber = "";
+ Hashtable properties = null;
+ boolean hadIDProperty = false;
+
+ String value = null;
+
+ while (iter.hasNext()) {
+ column = (String) iter.next();
+ index = ChainsawColumns.getColumnsNames().indexOf(column);
+ value = v.get(index).toString();
+
+ if (column.equalsIgnoreCase(ChainsawConstants.LOGGER_COL_NAME)) {
+ logger = Logger.getLogger(value);
+ }
+
+ if (column.equalsIgnoreCase(ChainsawConstants.TIMESTAMP_COL_NAME)) {
+ try {
+ timeStamp = DATE_FORMATTER.parse(value).getTime();
+ } catch (ParseException pe) {
+ pe.printStackTrace();
+
+ //ignore...leave as 0L
+ }
+ }
+
+ if (column.equalsIgnoreCase(ChainsawConstants.LEVEL_COL_NAME)) {
+ level = value;
+ }
+
+ if (column.equalsIgnoreCase(ChainsawConstants.THREAD_COL_NAME)) {
+ threadName = value;
+ }
+
+ if (column.equalsIgnoreCase(ChainsawConstants.NDC_COL_NAME)) {
+ ndc = value;
+ }
+
+ if (column.equalsIgnoreCase(ChainsawConstants.MESSAGE_COL_NAME)) {
+ message = value;
+ }
+
+ if (column.equalsIgnoreCase(ChainsawConstants.MDC_COL_NAME)) {
+ mdc = new Hashtable();
+
+ StringTokenizer t = new StringTokenizer(value, ",");
+
+ while (t.hasMoreElements()) {
+ StringTokenizer t2 = new StringTokenizer(t.nextToken(), "=");
+ mdc.put(t2.nextToken(), t2.nextToken());
+ }
+ }
+
+ if (column.equalsIgnoreCase(ChainsawConstants.THROWABLE_COL_NAME)) {
+ exception = new String[] { value };
+ }
+
+ if (column.equalsIgnoreCase(ChainsawConstants.CLASS_COL_NAME)) {
+ className = value;
+ }
+
+ if (column.equalsIgnoreCase(ChainsawConstants.METHOD_COL_NAME)) {
+ methodName = value;
+ }
+
+ if (column.equalsIgnoreCase(ChainsawConstants.FILE_COL_NAME)) {
+ fileName = value;
+ }
+
+ if (column.equalsIgnoreCase(ChainsawConstants.LINE_COL_NAME)) {
+ lineNumber = value;
+ }
+
+ if (column.equalsIgnoreCase(ChainsawConstants.PROPERTIES_COL_NAME)) {
+ properties = new Hashtable();
+
+ StringTokenizer t = new StringTokenizer(value, ",");
+
+ while (t.hasMoreElements()) {
+ StringTokenizer t2 = new StringTokenizer(t.nextToken(), "=");
+ String propertyName = t2.nextToken();
+
+ if (propertyName.equalsIgnoreCase(ChainsawConstants.LOG4J_ID_KEY)) {
+ hadIDProperty = true;
+ }
+
+ properties.put(propertyName, t2.nextToken());
+ }
+ }
+ }
+
+ //if log4jid property did not exist, set it (will be used during reconstruction)
+ if (!hadIDProperty) {
+ properties.put(ChainsawConstants.LOG4J_ID_KEY, ID.toString());
+ }
+
+ Level levelImpl = Level.toLevel(level);
+
+ return new LoggingEvent(
+ logger.getName(), logger, timeStamp, levelImpl, threadName, message, ndc,
+ mdc, exception,
+ new LocationInfo(fileName, className, methodName, lineNumber), properties);
}
public int getRowIndex(Vector v) {
1.96 +76 -49
jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/LogUI.java
Index: LogUI.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/LogUI.java,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -r1.95 -r1.96
--- LogUI.java 16 Jun 2003 03:16:12 -0000 1.95
+++ LogUI.java 16 Jun 2003 07:24:40 -0000 1.96
@@ -122,6 +122,7 @@
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButtonMenuItem;
@@ -142,6 +143,7 @@
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableColumnModelEvent;
import javax.swing.event.TableColumnModelListener;
+import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
@@ -183,9 +185,9 @@
private static final String LOOK_AND_FEEL = "LookAndFeel";
private static final String STATUS_BAR = "StatusBar";
private static final String COLUMNS_EXTENSION = ".columns";
- private static ChainsawSplash splash = null;
+ private static ChainsawSplash splash;
ChainsawTabbedPane tabbedPane;
- JToolBar toolbar;
+ private JToolBar toolbar;
private final ChainsawStatusBar statusBar = new ChainsawStatusBar();
private final Map tableModelMap = new HashMap();
private final Map tableMap = new HashMap();
@@ -197,9 +199,10 @@
private final Map scrollMap = new HashMap();
private final Map levelMap = new HashMap();
ChainsawAppenderHandler handler;
- ChainsawToolBarAndMenus tbms;
- private ChainsawAbout aboutBox = null;
+ private ChainsawToolBarAndMenus tbms;
+ private ChainsawAbout aboutBox;
private final SettingsManager sm = SettingsManager.getInstance();
+ private String lookAndFeelClassName;
/**
* Set to true, if and only if the GUI has completed
@@ -249,14 +252,6 @@
public static void main(String[] args) {
showSplash();
- try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- } catch (Exception e) {
- e.printStackTrace();
-
- return;
- }
-
LogUI logUI = new LogUI();
logUI.handler = new ChainsawAppenderHandler(logUI);
@@ -285,13 +280,13 @@
* etc etc.
*/
public void loadSettings(LoadSettingsEvent event) {
- final String lookAndFeel = event.getSetting(LogUI.LOOK_AND_FEEL);
+ lookAndFeelClassName = event.getSetting(LogUI.LOOK_AND_FEEL);
- if (lookAndFeel != null) {
+ if (lookAndFeelClassName != null) {
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
- changeLookAndFeel(lookAndFeel);
+ applyLookAndFeel(lookAndFeelClassName);
}
});
}
@@ -334,28 +329,30 @@
* layout, table columns, and sets itself viewable.
*/
public void activateViewer() {
-
/**
* Get all the SocketReceivers and configure a new SocketNodeEventListener
* so we can get notified of new Sockets
*/
- List list = PluginRegistry.getPlugins(LogManager.getLoggerRepository(),
SocketReceiver.class);
- final SocketNodeEventListener socketListener = new SocketNodeEventListener(){
+ List list =
+ PluginRegistry.getPlugins(
+ LogManager.getLoggerRepository(), SocketReceiver.class);
+ final SocketNodeEventListener socketListener =
+ new SocketNodeEventListener() {
+ public void socketOpened(String remoteInfo) {
+ statusBar.remoteConnectionReceived(remoteInfo);
+ }
- public void socketOpened(String remoteInfo) {
- statusBar.remoteConnectionReceived(remoteInfo);
- }
+ public void socketClosedEvent(Exception e) {
+ statusBar.setMessage("Collection lost! :: " + e.getMessage());
+ }
+ };
- public void socketClosedEvent(Exception e) {
- statusBar.setMessage("Collection lost! :: " + e.getMessage());
-
- }};
for (Iterator iter = list.iterator(); iter.hasNext();) {
SocketReceiver item = (SocketReceiver) iter.next();
LogLog.debug("Adding listener for " + item.getName());
item.setListener(socketListener);
}
-
+
initGUI();
List utilList = UtilLoggingLevel.getAllPossibleLevels();
@@ -945,26 +942,33 @@
}
/**
- * Changes the Look And Feel of the App
+ * Modify the saved Look And Feel - does not update the currently used Look And
Feel
+ * @param string The FQN of the LookAndFeel
+ */
+ public void setLookAndFeel(String lookAndFeelClassName) {
+ this.lookAndFeelClassName = lookAndFeelClassName;
+ JOptionPane.showMessageDialog(
+ getContentPane(),
+ "Restart application for the new Look and Feel to take effect.",
+ "Look and Feel Updated", JOptionPane.INFORMATION_MESSAGE);
+ }
+
+ /**
+ * Changes the currently used Look And Feel of the App
* @param string The FQN of the LookANdFeel
*/
- protected void changeLookAndFeel(String lookAndFeelClassName) {
+ private void applyLookAndFeel(String lookAndFeelClassName) {
LogLog.debug("Setting L&F -> " + lookAndFeelClassName);
- String currentLookAndFeelClassName =
- UIManager.getLookAndFeel().getClass().getName();
-
- if (!lookAndFeelClassName.equals(currentLookAndFeelClassName)) {
- try {
- UIManager.setLookAndFeel(lookAndFeelClassName);
- SwingUtilities.updateComponentTreeUI(this);
+ try {
+ UIManager.setLookAndFeel(lookAndFeelClassName);
+ SwingUtilities.updateComponentTreeUI(this);
- if (tbms != null) {
- tbms.stateChange();
- }
- } catch (Exception e) {
- LogLog.error("Failed to change L&F", e);
+ if (tbms != null) {
+ tbms.stateChange();
}
+ } catch (Exception e) {
+ LogLog.error("Failed to change L&F", e);
}
}
@@ -1066,10 +1070,18 @@
renderer.setColorFilter(colorFilter);
- colorFilter.addFilterChangedListener(tableModel);
-
table.setDefaultRenderer(Object.class, renderer);
+ //if the color filter changes, trigger the tablemodel update
+ colorFilter.addFilterChangedListener(
+ new FilterChangedListener() {
+ public void filterChanged() {
+ if (tableModel instanceof AbstractTableModel) {
+ ((AbstractTableModel) tableModel).fireTableDataChanged();
+ }
+ }
+ });
+
final DetailFieldSelector detailFieldSelector =
new DetailFieldSelector(
ident, new Vector(ChainsawColumns.getColumnsNames()), displayFilter);
@@ -1097,7 +1109,12 @@
thisItem.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent evt) {
- Vector lastSelected = tableModel.getRow(table.getSelectedRow());
+ Vector lastSelected = null;
+
+ if (table.getSelectedRow() > -1) {
+ lastSelected = tableModel.getRow(table.getSelectedRow());
+ }
+
colorDisplaySelector.applyColorUpdateForColumn(colName);
colorDisplaySelector.applyColorFilters(colName);
@@ -1127,7 +1144,12 @@
thisItem.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent evt) {
- Vector lastSelected = tableModel.getRow(table.getSelectedRow());
+ Vector lastSelected = null;
+
+ if (table.getSelectedRow() > -1) {
+ lastSelected = tableModel.getRow(table.getSelectedRow());
+ }
+
colorDisplaySelector.applyDisplayUpdateForColumn(colName);
colorDisplaySelector.applyDisplayFilters(colName);
@@ -1260,7 +1282,12 @@
override.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent evt) {
- Vector lastSelected = tableModel.getRow(table.getSelectedRow());
+ Vector lastSelected = null;
+
+ if (table.getSelectedRow() > -1) {
+ lastSelected = tableModel.getRow(table.getSelectedRow());
+ }
+
displayFilter.setCustomFilterOverride(override.isSelected());
if (lastSelected != null) {
@@ -1276,7 +1303,7 @@
});
override.setToolTipText(
- "<html>Unchecked: Apply custom filter to displayed rows<br>Checked: Apply
custom filter to ALL rows (override display filter setting)</html>");
+ "<html>Unchecked: Apply QuickFilter to displayed rows<br>Checked: Apply
QuickFilter to ALL rows (override display filter setting)</html>");
JPanel upperRightPanel =
new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
@@ -1356,8 +1383,8 @@
new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
if (
- (evt.getFirstIndex() == evt.getLastIndex())
- || (evt.getValueIsAdjusting())) {
+ ((evt.getFirstIndex() == evt.getLastIndex())
+ && (evt.getFirstIndex() > 0)) || (evt.getValueIsAdjusting())) {
return;
}
@@ -2001,7 +2028,7 @@
*/
class DetailPaneUpdater {
private int selectedRow = -1;
- private int lastRow;
+ private int lastRow = -1;
private final JEditorPane pane;
private final EventContainer model;
1.7 +1 -1
jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ColorDisplaySelector.java
Index: ColorDisplaySelector.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ColorDisplaySelector.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ColorDisplaySelector.java 14 Jun 2003 21:30:44 -0000 1.6
+++ ColorDisplaySelector.java 16 Jun 2003 07:24:40 -0000 1.7
@@ -378,7 +378,7 @@
System.out.println(
"removing display filter for level: " + level + " column "
+ selectedColumn + " value: " + selectedValue);
- ;
+
removeDisplayFilter(
new DisplayFilterEntry(
selectedColumn, selectedValue, level));
1.33 +2 -2
jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java
Index: ChainsawToolBarAndMenus.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- ChainsawToolBarAndMenus.java 16 Jun 2003 05:10:36 -0000 1.32
+++ ChainsawToolBarAndMenus.java 16 Jun 2003 07:24:40 -0000 1.33
@@ -899,7 +899,7 @@
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
- logui.changeLookAndFeel(lfInfo.getClassName());
+ logui.setLookAndFeel(lfInfo.getClassName());
}
});
}
@@ -1319,7 +1319,7 @@
setBorder(m_highlighted);
}
}
-
+
public void mouseExited(MouseEvent e) {
m_border = m_inactive;
setBorder(m_inactive);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]