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 sd...@apache.org on 2004/03/15 09:33:49 UTC

cvs commit: logging-log4j/src/java/org/apache/log4j/chainsaw ChainsawCyclicBufferTableModel.java LogPanel.java EventContainer.java JSortTable.java ChainsawToolBarAndMenus.java

sdeboy      2004/03/15 00:33:49

  Modified:    src/java/org/apache/log4j/chainsaw
                        ChainsawCyclicBufferTableModel.java LogPanel.java
                        EventContainer.java JSortTable.java
                        ChainsawToolBarAndMenus.java
  Log:
  Implemented expression-based find support
  
  - main menu and docked/undocked panels now share the same find text field (as a tab is selected, the find textfield in the main toolbar is replaced with the active tab's find textfield) - ensures find expressions matched active panel
  - modified filter text check thread - now avoids updating the filter if the text hasn't changed
  
  NOTES:
  - press ctrl-space or right mouse to activate the find textfield's context menu (expression help)
  - expression errors are reported in tool tip
  - find is -relative- to the selected row (press ctrl-home to search from the top)
  - 'scroll to bottom' is bypassed if there is ANY text in the find field
  - typing in the find field doesn't automatically perform the find - press F3 or the find button (reverse find will be added later)
  - to re-activate 'scroll to bottom', clear the find field
  - find history (similar to pressing enter in 'refine focus' combo box to store expression) will be added later
  - will add an ANY keyword to replace the previous find capability - search across all fields
  
  Revision  Changes    Path
  1.23      +11 -36    logging-log4j/src/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java
  
  Index: ChainsawCyclicBufferTableModel.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- ChainsawCyclicBufferTableModel.java	27 Feb 2004 16:47:29 -0000	1.22
  +++ ChainsawCyclicBufferTableModel.java	15 Mar 2004 08:33:49 -0000	1.23
  @@ -26,7 +26,6 @@
   import java.util.HashSet;
   import java.util.Iterator;
   import java.util.List;
  -import java.util.ListIterator;
   import java.util.Set;
   
   import javax.swing.ProgressMonitor;
  @@ -118,6 +117,17 @@
       }
     }
     
  +  public int find(Rule rule, int startLocation) {
  +      synchronized(filteredList) {
  +        for (int i=startLocation; i<filteredList.size(); i++) {
  +            if (rule.evaluate((LoggingEvent)filteredList.get(i))) {
  +                return i;
  +            }
  +        }
  +      }
  +      return -1;
  +  }
  +  
     /**
      * @param l
      */
  @@ -227,41 +237,6 @@
       }
       fireTableDataChanged();
       notifyCountListeners();
  -  }
  -
  -  /**
  -   * @deprecated - should this be replaced with a Refinement filter?
  -   *
  -   * If not it should be replaced with something inside LogPanel, a Finder class, it should not be in the Model.
  -   */
  -  public int find(int startRow, String text) {
  -    if (text == null) {
  -      text = "";
  -    } else {
  -      text = text.toLowerCase();
  -    }
  -
  -    int currentRow = -1;
  -
  -    synchronized (filteredList) {
  -      ListIterator iter = filteredList.listIterator();
  -
  -      while (iter.hasNext()) {
  -        currentRow++;
  -
  -        LoggingEvent event = (LoggingEvent) iter.next();
  -
  -        if (currentRow < startRow) {
  -          continue;
  -        }
  -
  -        if (event.getMessage().toString().toLowerCase().indexOf(text) > 0) {
  -          return currentRow;
  -        }
  -      }
  -    }
  -
  -    return -1;
     }
   
     public List getAllEvents() {
  
  
  
  1.57      +86 -62    logging-log4j/src/java/org/apache/log4j/chainsaw/LogPanel.java
  
  Index: LogPanel.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/LogPanel.java,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- LogPanel.java	10 Mar 2004 08:32:38 -0000	1.56
  +++ LogPanel.java	15 Mar 2004 08:33:49 -0000	1.57
  @@ -121,6 +121,7 @@
   import org.apache.log4j.helpers.LogLog;
   import org.apache.log4j.rule.ExpressionRule;
   import org.apache.log4j.rule.ExpressionRuleContext;
  +import org.apache.log4j.rule.Rule;
   import org.apache.log4j.spi.LoggingEvent;
   import org.apache.log4j.spi.LoggingEventFieldResolver;
   
  @@ -207,11 +208,14 @@
     private double lastDetailPanelSplitLocation = DEFAULT_DETAIL_SPLIT_LOCATION;
     private int previousLogTreePanelSplitLocation;
     private double lastLogTreePanelSplitLocation = DEFAULT_LOG_TREE_SPLIT_LOCATION;
  +  private boolean bypassScroll;
   
     private Point currentPoint;
     private boolean scroll;
  -  private boolean bypassScroll;
     private boolean paused = false;
  +  private Rule findRule;
  +  private final JPanel findPanel;
  +  private JTextField findField;
   
     /**
      * Creates a new LogPanel object.  If a LogPanel with this identifier has
  @@ -228,6 +232,8 @@
   
       scroll = true;
   
  +    findPanel = new JPanel();
  +
       final Map columnNameKeywordMap = new HashMap();
       columnNameKeywordMap.put(
         ChainsawConstants.CLASS_COL_NAME, LoggingEventFieldResolver.CLASS_FIELD);
  @@ -1266,8 +1272,8 @@
       tableModel.notifyCountListeners();
   
       if (rowAdded) {
  -      int currentRow = table.getSelectedRow();
   
  +      int currentRow = table.getSelectedRow();
         if (tableModel.isSortEnabled()) {
           tableModel.sort();
         }
  @@ -1279,9 +1285,12 @@
           table.scrollToBottom(
             table.columnAtPoint(table.getVisibleRect().getLocation()));
         } else {
  -        table.scrollToRow(
  -          currentRow, table.columnAtPoint(
  -            table.getVisibleRect().getLocation()));
  +        if (!bypassScroll) {
  +            table.scrollToRow(
  +            currentRow, table.columnAtPoint(
  +                table.getVisibleRect().getLocation()));
  +        }
  +        //always update detail pane (since we may be using a cyclic buffer which is full)
           detailPaneUpdater.setSelectedRow(currentRow);
         }
       }
  @@ -1436,21 +1445,14 @@
     }
   
     /**
  -   * Finds the row with the specified text, and ensures it is made visible
  -   *
  -   * @param text
  -   */
  -  void find(String text) {
  -    find(table.getSelectedRow(), text);
  -  }
  -
  -  /**
      * Undocks this DockablePanel by removing the panel from the LogUI window
      * and placing it inside it's own JFrame.
      */
     void undock() {
       setDocked(false);
       externalPanel.removeAll();
  +    findPanel.removeAll();
  +    findPanel.add(findField);
   
       externalPanel.add(undockedToolbar, BorderLayout.NORTH);
       externalPanel.add(nameTreeAndMainPanelSplit, BorderLayout.CENTER);
  @@ -1519,6 +1521,25 @@
       return tableModel.isCyclic();
     }
   
  +  public boolean updateRule(String ruleText) {
  +    if (ruleText == null || (ruleText != null && ruleText.equals(""))) {
  +        findRule = null;
  +        bypassScroll = false;
  +        findField.setToolTipText("Enter expression - right click or ctrl-space for menu");
  +        return false;
  +    } else {
  +        bypassScroll = true;
  +        try {
  +            findField.setToolTipText("Enter expression - right click or ctrl-space for menu");
  +            findRule = ExpressionRule.getRule(ruleText);
  +            return true;
  +        } catch (RuntimeException re) {
  +            findField.setToolTipText(re.getMessage());
  +            return false;            
  +        }
  +    }
  +  }
  +
     /**
      * Display the detail pane, using the last known divider location
      */
  @@ -1680,34 +1701,29 @@
       toolbar.add(dockClearButton);
       toolbar.addSeparator();
   
  -    final JTextField findField = ChainsawToolBarAndMenus.createFindField();
  +    findField = new JTextField();
  +    findField.addKeyListener(new ExpressionRuleContext(filterModel, findField));
  +
       findField.getDocument().addDocumentListener(
         new DocumentListener() {
           public void insertUpdate(DocumentEvent e) {
  -          findInUndocked(false);
  +            updateRule(findField.getText());
           }
   
           public void removeUpdate(DocumentEvent e) {
  -          findInUndocked(false);
  +            updateRule(findField.getText());
           }
   
           public void changedUpdate(DocumentEvent e) {
  -          findInUndocked(false);
  -        }
  -
  -        private void findInUndocked(boolean next) {
  -          if (next) {
  -            findNext(findField.getText());
  -          } else {
  -            find(findField.getText());
  -          }
  +            updateRule(findField.getText());
           }
  +        
         });
   
       final Action undockedFindAction =
         new AbstractAction() {
           public void actionPerformed(ActionEvent e) {
  -          findNext(findField.getText());
  +          find();
           }
         };
   
  @@ -1727,7 +1743,17 @@
         KeyStroke.getKeyStroke("F3"), undockedFindAction.getValue(Action.NAME));
   
       toolbar.add(undockedFindNextButton);
  -    toolbar.add(findField);
  +    
  +    Dimension findSize = new Dimension(132, 24);
  +    Dimension findPanelSize = new Dimension(144, 26);
  +    findPanel.setPreferredSize(findPanelSize);
  +    findPanel.setMaximumSize(findPanelSize);
  +    findPanel.setMinimumSize(findPanelSize);
  +    findField.setPreferredSize(findSize);
  +    findField.setMaximumSize(findSize);
  +    findField.setMinimumSize(findSize);
  +
  +    toolbar.add(findPanel);
   
       toolbar.addSeparator();
   
  @@ -1799,35 +1825,25 @@
     }
   
     /**
  -   * Finds the row with the specified text starting at the specified row, and
  -   * ensures it is made visible
  -   *
  -   * @param row
  -   * @param text
  -   */
  -  private void find(int row, String text) {
  -    final int newRow = tableModel.find(row, text);
  -
  -    if (text.length() == 0) {
  -      bypassScroll = false;
  -    } else {
  -      bypassScroll = true;
  -    }
  -
  -    table.scrollToRow(
  -      newRow, table.columnAtPoint(table.getVisibleRect().getLocation()));
  -  }
  -
  -  /**
  -   * Finds the next row with the specified text, and ensures it is made
  +   * Finds the next row matching the current find rule, and ensures it is made
      * visible
  -   *
  -   * @param text
  +   * 
      */
  -  private void findNext(String text) {
  -    find(table.getSelectedRow() + 1, text);
  +  public void find() {
  +    if (findRule != null) {
  +        try {
  +            final int nextRow = tableModel.find(findRule, table.getSelectedRow() + 1);
  +            if (nextRow > -1) {
  +                table.scrollToRow(
  +                nextRow, table.columnAtPoint(table.getVisibleRect().getLocation()));
  +                findField.setToolTipText("Enter an expression");
  +            }
  +        } catch (IllegalArgumentException iae) {
  +            findField.setToolTipText(iae.getMessage());
  +        }
  +    }
     }
  -
  +  
     /**
      * Docks this DockablePanel by hiding the JFrame and placing the Panel back
      * inside the LogUI window.
  @@ -2052,6 +2068,10 @@
         });
     }
   
  +  public JTextField getFindTextField() {
  +    return findField;
  +  }
  +
     /**
      * Load panel color settings
      */
  @@ -2131,7 +2151,7 @@
   
       filterModel.processNewLoggingEvent(eventType, event);
     }
  -
  +  
     /**
      * This class receives notification when the Refine focus text field is
      * updated, where a backgrounh thread periodically wakes up and checks if
  @@ -2147,8 +2167,9 @@
       private final Thread delayThread;
       private final long CHECK_PERIOD = 1000;
       private final String defaultToolTip;
  +    private String lastFilterText = null;
   
  -    private DelayedFilterTextDocumentListener(JTextField filterText) {
  +    private DelayedFilterTextDocumentListener(final JTextField filterText) {
         super();
         this.filterText = filterText;
         this.defaultToolTip = filterText.getToolTipText();
  @@ -2173,7 +2194,10 @@
                     // they stopped typing recently, but have stopped for at least
                     // 1 sample period. lets apply the filter
                     //                LogLog.debug("Typed something recently applying filter");
  -                  setFilter();
  +                  if (filterText.getText() != lastFilterText) {
  +                    lastFilterText = filterText.getText();
  +                    setFilter();
  +                  }
                   } else {
                     // they stopped typing a while ago, let's forget about it
                     //                LogLog.debug(
  @@ -2459,11 +2483,11 @@
           LoggingEvent event = tableModel.getRow(selectedRow);
   
           if (event != null) {
  -          StringBuffer buf = new StringBuffer();
  -          buf.append(detailLayout.getHeader())
  -             .append(detailLayout.format(event)).append(
  -            detailLayout.getFooter());
  -          text = buf.toString();
  +            StringBuffer buf = new StringBuffer();
  +            buf.append(detailLayout.getHeader())
  +               .append(detailLayout.format(event)).append(
  +              detailLayout.getFooter());
  +            text = buf.toString();
           }
         }
   
  
  
  
  1.12      +4 -4      logging-log4j/src/java/org/apache/log4j/chainsaw/EventContainer.java
  
  Index: EventContainer.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/EventContainer.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- EventContainer.java	27 Feb 2004 16:47:29 -0000	1.11
  +++ EventContainer.java	15 Mar 2004 08:33:49 -0000	1.12
  @@ -88,12 +88,12 @@
     public int getMaxSize();
   
     /**
  -   * Locates a row number, starting from startRow, containing the text
  -   * within any column.
  +   * Locates a row number, starting from startRow, matching the rule provided
  +   * 
  +   * @param rule
      * @param startRow
  -   * @param text
      */
  -  int find(int startRow, String text);
  +  int find(Rule rule, int startRow);
   
     /**
      * Returns a copied list of all the event in the model.
  
  
  
  1.9       +1 -0      logging-log4j/src/java/org/apache/log4j/chainsaw/JSortTable.java
  
  Index: JSortTable.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/JSortTable.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JSortTable.java	27 Feb 2004 16:47:29 -0000	1.8
  +++ JSortTable.java	15 Mar 2004 08:33:49 -0000	1.9
  @@ -98,6 +98,7 @@
             if ((row > -1) && (row < getRowCount())) {
               try {
                 setRowSelectionInterval(row, row);
  +              scrollRectToVisible(getCellRect(row, col +1, true));
               } catch (IllegalArgumentException iae) {
               }
                //ignore..out of bounds
  
  
  
  1.35      +53 -68    logging-log4j/src/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java
  
  Index: ChainsawToolBarAndMenus.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- ChainsawToolBarAndMenus.java	27 Feb 2004 16:47:29 -0000	1.34
  +++ ChainsawToolBarAndMenus.java	15 Mar 2004 08:33:49 -0000	1.35
  @@ -38,6 +38,7 @@
   import javax.swing.JMenu;
   import javax.swing.JMenuBar;
   import javax.swing.JMenuItem;
  +import javax.swing.JPanel;
   import javax.swing.JRadioButtonMenuItem;
   import javax.swing.JTextField;
   import javax.swing.JToolBar;
  @@ -60,7 +61,7 @@
    */
   class ChainsawToolBarAndMenus implements ChangeListener {
       private final SmallToggleButton showReceiversButton;
  -    final JTextField findTextField;
  +    private final JTextField findField;
       private final Action changeModelAction;
       private final Action clearAction;
       private final Action closeAction;
  @@ -92,6 +93,7 @@
       private final SmallToggleButton toggleCyclicButton = new SmallToggleButton();
       private final Action[] logPanelSpecificActions;
       private final JMenu activeTabMenu = new JMenu("Current tab");
  +    private final JPanel findPanel;
   
       ChainsawToolBarAndMenus(final LogUI logui) {
           this.logui = logui;
  @@ -100,7 +102,7 @@
           fileMenu = new FileMenu(logui);
           closeAction = createCloseHelpAction();
           changeModelAction = createChangeModelAction();
  -        findTextField = createFindField();
  +        findField = new JTextField();
           findNextAction = setupFindFieldsAndActions();
           showPreferencesAction = createShowPreferencesAction();
           showColorPanelAction = createShowColorPanelAction();
  @@ -111,6 +113,16 @@
           undockAction = createUndockAction();
           showReceiversAction = createShowReceiversAction();
           showReceiversButton = new SmallToggleButton(showReceiversAction);
  +        
  +        findPanel = new JPanel();
  +        Dimension findSize = new Dimension(132, 24);
  +        Dimension findPanelSize = new Dimension(144, 26);
  +        findPanel.setPreferredSize(findPanelSize);
  +        findPanel.setMaximumSize(findPanelSize);
  +        findPanel.setMinimumSize(findPanelSize);
  +        findField.setPreferredSize(findSize);
  +        findField.setMaximumSize(findSize);
  +        findField.setMinimumSize(findSize);
   
           toggleDetailPaneAction = createToggleDetailPaneAction();
           createMenuBar();
  @@ -253,33 +265,6 @@
           return action;
       }
   
  -    private void createFindDocListener(final JTextField field) {
  -        field.getDocument().addDocumentListener(new DocumentListener() {
  -                public void insertUpdate(DocumentEvent e) {
  -                    find(false);
  -                }
  -
  -                public void removeUpdate(DocumentEvent e) {
  -                    find(false);
  -                }
  -
  -                public void changedUpdate(DocumentEvent e) {
  -                    find(false);
  -                }
  -            });
  -    }
  -
  -    static JTextField createFindField() {
  -        JTextField tf = new JTextField();
  -        Dimension fixedSize = new Dimension(132, 24);
  -        tf.setPreferredSize(fixedSize);
  -        tf.setMaximumSize(fixedSize);
  -        tf.setMinimumSize(fixedSize);
  -        tf.setToolTipText("type in a simple string to find events");
  -
  -        return tf;
  -    }
  -
       private void createMenuBar() {
           JMenuItem menuItemUseRightMouse = new JMenuItem(
                   "Other options available via panel's right mouse button popup menu");
  @@ -422,7 +407,6 @@
                           return;
                       }
   
  -                    String ident = logPanel.getIdentifier();
                       logPanel.setPaused(!logPanel.isPaused());
                       scanState();
                   }
  @@ -612,9 +596,8 @@
   
           toolbar.add(findNextButton);
   
  -        Box findBox = Box.createHorizontalBox();
  -        findBox.add(findTextField);
  -        toolbar.add(findBox);
  +        findPanel.add(findField);
  +        toolbar.add(findPanel);
   
           toolbar.addSeparator();
   
  @@ -645,18 +628,6 @@
           return action;
       }
   
  -    private void find(boolean next) {
  -        LogPanel logPanel = logui.getCurrentLogPanel();
  -
  -        if (logPanel != null) {
  -            if (next) {
  -                logPanel.find(findTextField.getText());
  -            } else {
  -                logPanel.find(findTextField.getText());
  -            }
  -        }
  -    }
  -
       private void scanState() {
           toggleStatusBarCheck.setSelected(logui.isStatusBarVisible());
           toggleShowReceiversCheck.setSelected(logui.getApplicationPreferenceModel()
  @@ -678,7 +649,9 @@
           if (logPanel == null) {
               activateLogPanelActions = false;
               logui.getStatusBar().clear();
  -            findTextField.setEnabled(false);
  +            findField.setEnabled(false);
  +            findPanel.removeAll();
  +            findPanel.add(findField);
               activeTabMenu.setEnabled(false);
               closeAction.setEnabled(true);
               detailPaneButton.setSelected(false);
  @@ -686,7 +659,8 @@
           } else {
               activeTabMenu.setEnabled(true);
               fileMenu.getFileSaveAction().setEnabled(true);
  -            findTextField.setEnabled(true);
  +            findPanel.removeAll();
  +            findPanel.add(logPanel.getFindTextField());
   
               pauseButton.getModel().setSelected(logPanel.isPaused());
               toggleCyclicButton.setSelected(logPanel.isCyclic());
  @@ -695,13 +669,14 @@
               detailPaneButton.getModel().setSelected(logPanel.isDetailVisible());
               toggleLogTreeMenuItem.setSelected(logPanel.isLogTreeVisible());
           }
  -
  +        findPanel.invalidate();
  +        findPanel.revalidate();
  +        findPanel.repaint();
  +        
           for (int i = 0; i < logPanelSpecificActions.length; i++) {
               logPanelSpecificActions[i].setEnabled(activateLogPanelActions);
           }
   
  -        String currentLookAndFeel = UIManager.getLookAndFeel().getClass()
  -                                             .getName();
           String currentLookAndFeelName = UIManager.getLookAndFeel().getName();
   
           for (Iterator iter = lookAndFeelMenus.iterator(); iter.hasNext();) {
  @@ -715,36 +690,46 @@
           }
       }
   
  -    //  ChangeListener getPanelListener() {
  -    //    return panelListener;
  -    //  }
  -    private JCheckBoxMenuItem getDisplayPanelMenuItem(final String panelName) {
  -        final JCheckBoxMenuItem item = new JCheckBoxMenuItem(panelName, true);
  -
  -        final Action action = new AbstractAction(panelName) {
  -                public void actionPerformed(ActionEvent e) {
  -                    logui.displayPanel(panelName, item.isSelected());
  +    private Action setupFindFieldsAndActions() {
  +        findField.getDocument().addDocumentListener(
  +          new DocumentListener() {
  +            public void insertUpdate(DocumentEvent e) {
  +                LogPanel p = logui.getCurrentLogPanel();
  +                if (p != null) {
  +                    p.updateRule(findField.getText());
                   }
  -            };
  +            }
   
  -        item.setAction(action);
  +            public void removeUpdate(DocumentEvent e) {
  +                LogPanel p = logui.getCurrentLogPanel();
  +                if (p != null) {
  +                    p.updateRule(findField.getText());
  +                }
  +            }
   
  -        return item;
  -    }
  +            public void changedUpdate(DocumentEvent e) {
  +                LogPanel p = logui.getCurrentLogPanel();
  +                if (p != null) {
  +                    p.updateRule(findField.getText());
  +                }
  +            }
  +        
  +          });
   
  -    private Action setupFindFieldsAndActions() {
  -        createFindDocListener(findTextField);
   
  -        final Action action = new AbstractAction("Find Next") {
  +        final Action action = new AbstractAction("Find") {
                   public void actionPerformed(ActionEvent e) {
  -                    find(true);
  +                    LogPanel p = logui.getCurrentLogPanel();
  +                    if (p != null) {
  +                        p.find();
  +                    }
                   }
               };
   
           //    action.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_F));
           action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("F3"));
           action.putValue(Action.SHORT_DESCRIPTION,
  -            "Finds the next occurrence of the Find string");
  +            "Finds the next occurrence of the rule from the current row");
           action.putValue(Action.SMALL_ICON, new ImageIcon(ChainsawIcons.FIND));
   
           return action;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org