Unsubscribe

On Sun, Oct 25, 2009 at 05:42, <sdeboy@apache.org> wrote:
Author: sdeboy
Date: Sun Oct 25 07:42:21 2009
New Revision: 829505

URL: http://svn.apache.org/viewvc?rev=829505&view=rev
Log:
Add new 'marker' feature
Marker is displayed as an icon that appears in the first displayed column (using 'about' icon currently)

Ctrl-F2 or double-click: toggle a marker on or off
F2: search for next marker
Shift-F2: search for previous marker
Ctrl-Shift-F2: clear all markers

To facilitate search, rendering & toggle of markers, adding a marker temporarily adds a new property to events that have the marker set called 'log4j.marker' (value 'true')'.

Also added a new method to LoggingEvent:
public Object removeProperty(String propName)
to facilitate removal of this temporary property when the marker is un-set for a loggingevent

Modified:
   logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawConstants.java
   logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java
   logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java
   logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/EventContainer.java
   logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
   logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java
   logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/icons/ChainsawIcons.java
   logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/WelcomePanel.html

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawConstants.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawConstants.java?rev=829505&r1=829504&r2=829505&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawConstants.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawConstants.java Sun Oct 25 07:42:21 2009
@@ -79,7 +79,9 @@

  static final String LEVEL_DISPLAY = "level.display";
  static final String LEVEL_DISPLAY_ICONS = "icons";
-  static final String LEVEL_DISPLAY_TEXT = "text";
+  static final String LEVEL_DISPLAY_TEXT = "text";
+
+  static final String MARKER_PROPERTY_NAME = "log4j.marker";

  static final String DATETIME_FORMAT = "EEE MMM dd HH:mm:ss z yyyy";


Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java?rev=829505&r1=829504&r2=829505&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java Sun Oct 25 07:42:21 2009
@@ -333,7 +333,21 @@
    }
  }

-  public int getColumnCount() {
+    public void removePropertyFromEvents(String propName) {
+        for (Iterator iter = unfilteredList.iterator();iter.hasNext();) {
+            LoggingEvent event = (LoggingEvent)iter.next();
+            event.removeProperty(propName);
+        }
+        for (int i=0;i<filteredList.size();i++) {
+            LoggingEvent event = (LoggingEvent)filteredList.get(i);
+            Object result = event.removeProperty(propName);
+            if (result != null) {
+                fireRowUpdated(i);
+            }
+        }
+    }
+
+    public int getColumnCount() {
    return columnNames.size();
  }

@@ -549,7 +563,11 @@
  }});
  }

-  /**
+    public void fireRowUpdated(int row) {
+        fireTableRowsUpdated(row, row);
+    }
+
+    /**
  * @param e
  */
  private void fireNewKeyColumnAdded(NewKeyEvent e) {

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java?rev=829505&r1=829504&r2=829505&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java Sun Oct 25 07:42:21 2009
@@ -75,6 +75,10 @@
  private final Action closeAction;
  private final Action findNextAction;
  private final Action findPreviousAction;
+  private final Action findNextMarkerAction;
+  private final Action findPreviousMarkerAction;
+  private final Action toggleMarkerAction;
+  private final Action clearAllMarkersAction;
  private final Action pauseAction;
  private final Action showPreferencesAction;
  private final Action showColorPanelAction;
@@ -114,7 +118,7 @@
  private final JMenu activeTabMenu = new JMenu("Current tab");
  private final JPanel findPanel;

-  ChainsawToolBarAndMenus(final LogUI logui) {
+    ChainsawToolBarAndMenus(final LogUI logui) {
    this.logui = logui;
    toolbar = new JToolBar(SwingConstants.HORIZONTAL);
    menuBar = new JMenuBar();
@@ -124,6 +128,10 @@
    findField = new JTextField();
    findNextAction = getFindNextAction();
    findPreviousAction = getFindPreviousAction();
+    findNextMarkerAction = createFindNextMarkerAction();
+    findPreviousMarkerAction = createFindPreviousMarkerAction();
+    toggleMarkerAction = createToggleMarkerAction();
+    clearAllMarkersAction = createClearAllMarkersAction();
    customExpressionPanelAction = createCustomExpressionPanelAction();
    showPreferencesAction = createShowPreferencesAction();
    showColorPanelAction = createShowColorPanelAction();
@@ -155,7 +163,8 @@

    logPanelSpecificActions =
      new Action[] {
-        pauseAction, findNextAction, findPreviousAction, clearAction,
+        pauseAction, findNextAction, findPreviousAction, findNextMarkerAction, findPreviousMarkerAction,
+        toggleMarkerAction, clearAllMarkersAction, clearAction,
        fileMenu.getFileSaveAction(), toggleDetailPaneAction,
        showPreferencesAction, showColorPanelAction, undockAction,
        toggleLogTreeAction, toggleScrollToBottomAction, changeModelAction,
@@ -250,6 +259,78 @@
     return action;
   }

+     private Action createFindNextMarkerAction() {
+       Action action =
+         new AbstractAction("Find next marker") {
+           public void actionPerformed(ActionEvent e) {
+             if (logui.getCurrentLogPanel() != null) {
+               logui.getCurrentLogPanel().findNextMarker();
+             }
+           }
+         };
+
+       action.putValue(Action.SHORT_DESCRIPTION, "Searches for the next marker from the current location");
+       action.putValue("enabled", Boolean.TRUE);
+       action.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_N));
+       action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("F2"));
+
+       return action;
+     }
+
+    private Action createFindPreviousMarkerAction() {
+      Action action =
+        new AbstractAction("Find previous marker") {
+          public void actionPerformed(ActionEvent e) {
+            if (logui.getCurrentLogPanel() != null) {
+              logui.getCurrentLogPanel().findPreviousMarker();
+            }
+          }
+        };
+
+      action.putValue(Action.SHORT_DESCRIPTION, "Searches for the previous marker from the current location");
+      action.putValue("enabled", Boolean.TRUE);
+      action.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_P));
+      action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F2,  InputEvent.SHIFT_MASK));
+
+      return action;
+    }
+
+    private Action createToggleMarkerAction() {
+      Action action =
+        new AbstractAction("Toggle marker") {
+          public void actionPerformed(ActionEvent e) {
+            if (logui.getCurrentLogPanel() != null) {
+              logui.getCurrentLogPanel().toggleMarker();
+            }
+          }
+        };
+
+      action.putValue(Action.SHORT_DESCRIPTION, "Toggle marker for selected row");
+      action.putValue("enabled", Boolean.TRUE);
+      action.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_T));
+      action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F2,  InputEvent.CTRL_MASK));
+
+      return action;
+    }
+
+    private Action createClearAllMarkersAction() {
+      Action action =
+        new AbstractAction("Clear all markers") {
+          public void actionPerformed(ActionEvent e) {
+            if (logui.getCurrentLogPanel() != null) {
+              logui.getCurrentLogPanel().clearAllMarkers();
+            }
+          }
+        };
+
+      action.putValue(Action.SHORT_DESCRIPTION, "Removes all markers");
+      action.putValue("enabled", Boolean.TRUE);
+      action.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_R));
+      action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F2,  InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK));
+
+      return action;
+    }
+
   /**
   * DOCUMENT ME!
   */
@@ -412,6 +493,13 @@
    activeTabMenu.addSeparator();
    activeTabMenu.add(new CopyEventsToClipboardAction(logui));
    activeTabMenu.add(new JMenuItem(clearAction));
+
+    activeTabMenu.addSeparator();
+    activeTabMenu.add(new JMenuItem(toggleMarkerAction));
+    activeTabMenu.add(new JMenuItem(findNextMarkerAction));
+    activeTabMenu.add(new JMenuItem(findPreviousMarkerAction));
+    activeTabMenu.add(new JMenuItem(clearAllMarkersAction));
+
    activeTabMenu.addSeparator();
    activeTabMenu.add(toggleScrollToBottomMenuItem);
    activeTabMenu.add(menuItemUseRightMouse);

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/EventContainer.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/EventContainer.java?rev=829505&r1=829504&r2=829505&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/EventContainer.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/EventContainer.java Sun Oct 25 07:42:21 2009
@@ -140,6 +140,11 @@
   */
  void fireTableEvent(int begin, int end, int count);

+    /**
+     * A row was updated
+     * @param row
+     */
+  void fireRowUpdated(int row);
  /**
   * Allow a forced notification of the EventCountListeners
   *
@@ -157,4 +162,10 @@
   * @param e
   */
  int getRowIndex(LoggingEvent e);
+
+  /**
+   * Remove property from all events in container
+   * @param propName the property name to remove
+   */
+  void removePropertyFromEvents(String propName);
 }

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?rev=829505&r1=829504&r2=829505&view=diff
==============================================================================
--- 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 Sun Oct 25 07:42:21 2009
@@ -230,6 +230,7 @@
  private Point currentPoint;
  private boolean paused = false;
  private Rule findRule;
+  private Rule findMarkerRule;
  private final JPanel findPanel;
  private JTextField findField;
  private final int dividerSize;
@@ -559,6 +560,13 @@
     */
    tableModel = new ChainsawCyclicBufferTableModel(cyclicBufferSize);
    table = new JSortTable(tableModel);
+
+    //we've mapped f2, shift f2 and ctrl-f2 to marker-related actions, unmap them from the table
+    table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("F2"), "none");
+    table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, InputEvent.SHIFT_MASK), "none");
+    table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, InputEvent.CTRL_MASK), "none");
+    table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK), "none");
+
    //add a listener to update the 'refine focus'
    tableModel.addNewKeyListener(new NewKeyListener() {
               public void newKeyAdded(NewKeyEvent e) {
@@ -681,6 +689,7 @@
    table.setAutoCreateColumnsFromModel(false);

    table.addMouseMotionListener(new TableColumnDetailMouseListener());
+    table.addMouseListener(new TableMarkerListener());

    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

@@ -1022,7 +1031,8 @@

        }
    });
-
+    findMarkerRule = ExpressionRule.getRule("prop." + ChainsawConstants.MARKER_PROPERTY_NAME + " exists");
+
    tableModel.addTableModelListener(new TableModelListener() {
               public void tableChanged(TableModelEvent e) {
                       detailPaneUpdater.setSelectedRow(table.getSelectedRow());
@@ -1874,7 +1884,7 @@
        "Enter expression - right click or ctrl-space for menu");
      return false;
    } else {
-      //only turn off scroltobottom when finding something (find not empty)
+      //only turn off scrolltobottom when finding something (find not empty)
      preferenceModel.setScrollToBottom(false);
      try {
        findField.setToolTipText(
@@ -2477,7 +2487,41 @@
    filterModel.processNewLoggingEvent(event);
  }

-  /**
+    public void findNextMarker() {
+      final int nextRow = tableModel.find(findMarkerRule, table.getSelectedRow() + 1, true);
+
+      if (nextRow > -1) {
+        table.scrollToRow(nextRow);
+      }
+    }
+
+    public void findPreviousMarker() {
+        final int previousRow = tableModel.find(findMarkerRule, table.getSelectedRow() - 1, false);
+
+        if (previousRow > -1) {
+          table.scrollToRow(previousRow);
+        }
+    }
+
+    public void clearAllMarkers() {
+        tableModel.removePropertyFromEvents(ChainsawConstants.MARKER_PROPERTY_NAME);
+    }
+
+    public void toggleMarker() {
+        int row = table.getSelectedRow();
+        if (row != -1) {
+          LoggingEvent event = tableModel.getRow(row);
+          Object marker = event.getProperty(ChainsawConstants.MARKER_PROPERTY_NAME);
+          if (marker == null) {
+              event.setProperty(ChainsawConstants.MARKER_PROPERTY_NAME, "true");
+          } else {
+              event.removeProperty(ChainsawConstants.MARKER_PROPERTY_NAME);
+          }
+          tableModel.fireRowUpdated(row);
+        }
+    }
+
+    /**
   * This class receives notification when the Refine focus text field is
   * updated, where a backgrounh thread periodically wakes up and checks if
   * they have stopped typing yet. This ensures that the filtering of the
@@ -2595,6 +2639,24 @@
    }
  }

+  private final class TableMarkerListener extends MouseAdapter {
+      public void mouseClicked(MouseEvent evt) {
+          if (evt.getClickCount() == 2) {
+              int row = table.rowAtPoint(evt.getPoint());
+              if (row != -1) {
+                LoggingEvent event = tableModel.getRow(row);
+                Object marker = event.getProperty(ChainsawConstants.MARKER_PROPERTY_NAME);
+                if (marker == null) {
+                    event.setProperty(ChainsawConstants.MARKER_PROPERTY_NAME, "true");
+                } else {
+                    event.removeProperty(ChainsawConstants.MARKER_PROPERTY_NAME);
+                }
+                tableModel.fireRowUpdated(row);
+              }
+          }
+      }
+  }
+
  /**
   * Update active tooltip
   */

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java?rev=829505&r1=829504&r2=829505&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java Sun Oct 25 07:42:21 2009
@@ -27,12 +27,14 @@

 import javax.swing.BorderFactory;
 import javax.swing.Icon;
+import javax.swing.ImageIcon;
 import javax.swing.JLabel;
 import javax.swing.JTable;
 import javax.swing.SwingConstants;
 import javax.swing.table.DefaultTableCellRenderer;

 import org.apache.log4j.chainsaw.color.Colorizer;
+import org.apache.log4j.chainsaw.icons.ChainsawIcons;
 import org.apache.log4j.chainsaw.icons.LevelIconFactory;
 import org.apache.log4j.helpers.Constants;
 import org.apache.log4j.spi.LoggingEvent;
@@ -60,6 +62,7 @@
  private int loggerPrecision = 0;
  private boolean toolTipsVisible;
  private String dateFormatTZ;
+  private final Icon markerIcon = new ImageIcon(ChainsawIcons.MARKER);

  /**
   * Creates a new TableColorizingRenderer object.
@@ -90,6 +93,9 @@
        isSelected, hasFocus, row, col);
    int colIndex = table.getColumnModel().getColumn(col).getModelIndex() + 1;

+    EventContainer container = (EventContainer) table.getModel();
+    LoggingEvent event = container.getRow(row);
+
    switch (colIndex) {
    case ChainsawColumns.INDEX_ID_COL_NAME:
      idComponent.setText(value.toString());
@@ -150,6 +156,12 @@
    default:
      break;
    }
+    //set the 'info' icon next to the zeroth column if marker is set
+    if (col == 0 && event.getProperty("log4j.marker") != null) {
+        c.setIcon(markerIcon);
+    } else {
+        c.setIcon(null);
+    }

    if (isSelected) {
      return c;
@@ -159,8 +171,6 @@
    Color foreground = null;

    if (colorizer != null) {
-      EventContainer container = (EventContainer) table.getModel();
-      LoggingEvent event = container.getRow(row);

      if (event == null) {
        //ignore...probably changed displayed cols
@@ -206,7 +216,7 @@

  /**
   * Changes the Logger precision.
-   * @param precision
+   * @param loggerPrecisionText
   */
  void setLoggerPrecision(String loggerPrecisionText) {
    try {

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/icons/ChainsawIcons.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/icons/ChainsawIcons.java?rev=829505&r1=829504&r2=829505&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/icons/ChainsawIcons.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/icons/ChainsawIcons.java Sun Oct 25 07:42:21 2009
@@ -85,6 +85,9 @@
  public static final URL HELP =
    ChainsawIcons.class.getClassLoader().getResource(
      BASE_ICON_PATH + "Help16.gif");
+  public static final URL MARKER =
+    ChainsawIcons.class.getClassLoader().getResource(
+      BASE_ICON_PATH + "About16.gif");
  public static final Icon ICON_UP = new ImageIcon(UP);
  public static final Icon ICON_DOWN = new ImageIcon(DOWN);
  public static final Icon ICON_HELP = new ImageIcon(HELP);

Modified: logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/WelcomePanel.html
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/WelcomePanel.html?rev=829505&r1=829504&r2=829505&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/WelcomePanel.html (original)
+++ logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/WelcomePanel.html Sun Oct 25 07:42:21 2009
@@ -84,6 +84,22 @@
    <td width="50" align="center">-</td>
    <td colspan="1">Go to line</td>
 </tr>
+    <tr valign="top" bgcolor="#EEEEEE">
+        <td nowrap class="HotKey">Ctrl-F2 (or double-click on a row)</td>
+        <td width="50" align="center">-</td>
+        <td colspan="1">Toggle marker</td>
+        <td nowrap class="HotKey">F2</td>
+        <td width="50" align="center">-</td>
+        <td colspan="1">Find next marker</td>
+    </tr>
+    <tr valign="top" bgcolor="#EEEEEE">
+        <td nowrap class="HotKey">Shift-F2</td>
+        <td width="50" align="center">-</td>
+        <td colspan="1">Find previous marker</td>
+        <td nowrap class="HotKey">Ctrl-shift-F2</td>
+        <td width="50" align="center">-</td>
+        <td colspan="1">Clear all markers</td>
+    </tr>
 </table></P>
 <!--<p><a href="#TheTop">Back to top</a></p>-->
 <a name="Receivers"></a>