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 2003/11/10 03:15:25 UTC

cvs commit: jakarta-log4j/src/java/org/apache/log4j/chainsaw/color ColorPanel.java

sdeboy      2003/11/09 18:15:25

  Modified:    src/java/org/apache/log4j/chainsaw/rule
                        ExpressionRuleContext.java ExpressionRule.java
                        RuleFactory.java NotRule.java AndRule.java
                        InFixToPostFix.java
               src/java/org/apache/log4j/chainsaw/color ColorPanel.java
  Added:       src/java/org/apache/log4j/chainsaw/rule ExistsRule.java
  Log:
  * added an 'exists' operator to the set of rules and added support for the operator in ExpressionRule
  * removed default preview panel from color panel
  * modified color panel layout 
  * Modified infix to postfix converter to throw an illegalargumentexception if the stack was empty
  
  Revision  Changes    Path
  1.2       +1 -1      jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/ExpressionRuleContext.java
  
  Index: ExpressionRuleContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/ExpressionRuleContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ExpressionRuleContext.java	9 Nov 2003 09:59:27 -0000	1.1
  +++ ExpressionRuleContext.java	10 Nov 2003 02:15:24 -0000	1.2
  @@ -107,6 +107,7 @@
       operatorModel.addElement("==");
       operatorModel.addElement("~=");
       operatorModel.addElement("LIKE");
  +    operatorModel.addElement("EXISTS");
       operatorModel.addElement("<");
       operatorModel.addElement(">");
       operatorModel.addElement("<=");
  @@ -296,7 +297,6 @@
       if (text.substring(0, currentPosition).toUpperCase().endsWith("MDC.")) {
         return "MDC";
       }
  -
       return null;
     }
   
  
  
  
  1.6       +2 -2      jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/ExpressionRule.java
  
  Index: ExpressionRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/ExpressionRule.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ExpressionRule.java	9 Nov 2003 09:59:27 -0000	1.5
  +++ ExpressionRule.java	10 Nov 2003 02:15:24 -0000	1.6
  @@ -127,8 +127,8 @@
         }
       }
   
  -    if (!(stack.peek() instanceof Rule)) {
  -      throw new RuntimeException("invalid expression: " + expression);
  +    if ((stack.size() == 0) || (!(stack.peek() instanceof Rule))) {
  +      throw new IllegalArgumentException("invalid expression: " + expression);
       } else {
         return (Rule) stack.pop();
       }
  
  
  
  1.6       +6 -0      jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/RuleFactory.java
  
  Index: RuleFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/RuleFactory.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RuleFactory.java	9 Nov 2003 09:59:27 -0000	1.5
  +++ RuleFactory.java	10 Nov 2003 02:15:24 -0000	1.6
  @@ -69,6 +69,7 @@
     private static final String EQUALS_RULE = "==";
     private static final String PARTIAL_TEXT_MATCH_RULE = "~=";
     private static final String LIKE_RULE = "like";
  +  private static final String EXISTS_RULE = "exists";
     private static final String LESS_THAN_RULE = "<";
     private static final String GREATER_THAN_RULE = ">";
     private static final String LESS_THAN_EQUALS_RULE = "<=";
  @@ -81,6 +82,7 @@
       rules.add(EQUALS_RULE);
       rules.add(PARTIAL_TEXT_MATCH_RULE);
       rules.add(LIKE_RULE);
  +    rules.add(EXISTS_RULE);
       rules.add(LESS_THAN_RULE);
       rules.add(GREATER_THAN_RULE);
       rules.add(LESS_THAN_EQUALS_RULE);
  @@ -124,6 +126,10 @@
   
       if (LIKE_RULE.equalsIgnoreCase(symbol)) {
         return LikeRule.getRule(stack);
  +    }
  +
  +    if (EXISTS_RULE.equalsIgnoreCase(symbol)) {
  +      return ExistsRule.getRule(stack);
       }
   
       if (LESS_THAN_RULE.equals(symbol)) {
  
  
  
  1.4       +2 -2      jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/NotRule.java
  
  Index: NotRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/NotRule.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NotRule.java	9 Nov 2003 09:59:27 -0000	1.3
  +++ NotRule.java	10 Nov 2003 02:15:24 -0000	1.4
  @@ -61,8 +61,8 @@
   public class NotRule extends AbstractRule {
     private final Rule rule;
   
  -  private NotRule(Rule firstParam) {
  -    this.rule = firstParam;
  +  private NotRule(Rule rule) {
  +    this.rule = rule;
     }
   
     public static Rule getRule(Rule rule) {
  
  
  
  1.4       +6 -6      jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/AndRule.java
  
  Index: AndRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/AndRule.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AndRule.java	9 Nov 2003 09:59:27 -0000	1.3
  +++ AndRule.java	10 Nov 2003 02:15:24 -0000	1.4
  @@ -60,12 +60,12 @@
    * @author Scott Deboy <sd...@apache.org>
    */
   public class AndRule extends AbstractRule {
  -  private final Rule firstParam;
  -  private final Rule secondParam;
  +  private final Rule firstRule;
  +  private final Rule secondRule;
   
  -  private AndRule(Rule firstParam, Rule secondParam) {
  -    this.firstParam = firstParam;
  -    this.secondParam = secondParam;
  +  private AndRule(Rule firstRule, Rule secondRule) {
  +    this.firstRule = firstRule;
  +    this.secondRule = secondRule;
     }
   
     public static Rule getRule(Stack stack) {
  @@ -80,6 +80,6 @@
     }
   
     public boolean evaluate(LoggingEvent event) {
  -    return (firstParam.evaluate(event) && secondParam.evaluate(event));
  +    return (firstRule.evaluate(event) && secondRule.evaluate(event));
     }
   }
  
  
  
  1.5       +3 -1      jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/InFixToPostFix.java
  
  Index: InFixToPostFix.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/InFixToPostFix.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- InFixToPostFix.java	9 Nov 2003 09:59:27 -0000	1.4
  +++ InFixToPostFix.java	10 Nov 2003 02:15:24 -0000	1.5
  @@ -79,6 +79,7 @@
       operators.add("||");
       operators.add("&&");
       operators.add("like");
  +    operators.add("exists");
       operators.add("<");
       operators.add(">");
       operators.add("<=");
  @@ -99,7 +100,8 @@
       precedenceMap.put("==", new Integer(3));
       precedenceMap.put("~=", new Integer(3));
       precedenceMap.put("like", new Integer(3));
  -
  +    precedenceMap.put("exists", new Integer(3));
  +    
       precedenceMap.put("||", new Integer(2));
       precedenceMap.put("&&", new Integer(2));
   
  
  
  
  1.1                  jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/ExistsRule.java
  
  Index: ExistsRule.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
  
  package org.apache.log4j.chainsaw.rule;
  
  import org.apache.log4j.chainsaw.LoggingEventFieldResolver;
  import org.apache.log4j.spi.LoggingEvent;
  
  import java.util.Stack;
  
  /**
   * A Rule class implementing a not null (and not empty string) check.
   * 
   * @author Scott Deboy <sd...@apache.org>
   */
  public class ExistsRule extends AbstractRule {
    private static final LoggingEventFieldResolver resolver = LoggingEventFieldResolver.getInstance();
    private final String field;
  
    private ExistsRule(String field) {
      this.field = field;
    }
  
    public static Rule getRule(String field) {
        return new ExistsRule(field);
    }
    
    public static Rule getRule(Stack stack) {
      return new ExistsRule(stack.pop().toString());
    }
  
    public boolean evaluate(LoggingEvent event) {
      String p2 = resolver.getValue(field, event).toString();
  
      return (!(p2.equals("")));
    }
  }
  
  
  
  1.2       +43 -39    jakarta-log4j/src/java/org/apache/log4j/chainsaw/color/ColorPanel.java
  
  Index: ColorPanel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/color/ColorPanel.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ColorPanel.java	9 Nov 2003 09:59:28 -0000	1.1
  +++ ColorPanel.java	10 Nov 2003 02:15:25 -0000	1.2
  @@ -63,11 +63,11 @@
   import java.awt.Graphics;
   import java.awt.GridLayout;
   import java.awt.event.ActionEvent;
  -
   import java.util.ArrayList;
   import java.util.List;
   
   import javax.swing.AbstractAction;
  +import javax.swing.BorderFactory;
   import javax.swing.BoxLayout;
   import javax.swing.DefaultListCellRenderer;
   import javax.swing.DefaultListModel;
  @@ -84,11 +84,12 @@
   import javax.swing.event.ListSelectionEvent;
   import javax.swing.event.ListSelectionListener;
   
  +
   /**
    * Panel which updates a RuleColorizer, allowing the user to build expression-based
    * color rules.
  - * 
  - * @author Scott Deboy <sd...@apache.org> 
  + *
  + * @author Scott Deboy <sd...@apache.org>
    */
   public class ColorPanel extends JPanel {
     private static final String ADD_TEXT = "Add-->";
  @@ -104,6 +105,10 @@
       this.colorizer = colorizer;
   
       final JColorChooser chooser = new JColorChooser();
  +    //setting the preview panel to an undisplayed label effectively removes the default
  +    //preview panel from the chooser 
  +    JLabel l = new JLabel();
  +    chooser.setPreviewPanel(l);
   
       listModel = new DefaultListModel();
   
  @@ -136,16 +141,13 @@
       leftCenterPanel.setLayout(
         new BoxLayout(leftCenterPanel, BoxLayout.Y_AXIS));
   
  -    JPanel expressionClearPanel = new JPanel();
  -    expressionClearPanel.setLayout(
  -      new BoxLayout(expressionClearPanel, BoxLayout.Y_AXIS));
  -
       JPanel expressionPanel = new JPanel();
       expressionPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
   
       leftPanel.add(new JLabel("Rule:"), BorderLayout.NORTH);
   
       final JTextField expression = new JTextField(30);
  +    expression.setToolTipText("Press ctrl-space or right mouse button for expression context menu");
       final Color defaultExpressionBackground = expression.getBackground();
       final Color defaultExpressionForeground = expression.getForeground();
   
  @@ -153,22 +155,12 @@
         new ExpressionRuleContext(filterModel, expression));
       expressionPanel.add(expression);
   
  -    JPanel addUpdatePanel = new JPanel();
  -    addUpdatePanel.setLayout(new BoxLayout(addUpdatePanel, BoxLayout.X_AXIS));
  -
  -    addUpdatePanel.add(new JLabel(" "));
  +    JPanel addUpdatePanel = new JPanel(new GridLayout(2, 1));
   
       final JButton addUpdateButton = new JButton(ADD_TEXT);
       addUpdatePanel.add(addUpdateButton);
   
  -    expressionPanel.add(addUpdatePanel);
  -
  -    expressionClearPanel.add(expressionPanel);
  -
  -    JPanel clearPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
  -
       JButton clearButton = new JButton("Clear");
  -    clearPanel.add(clearButton);
       clearButton.addActionListener(
         new AbstractAction() {
           public void actionPerformed(ActionEvent evt) {
  @@ -181,9 +173,11 @@
           }
         });
   
  -    expressionClearPanel.add(clearPanel);
  +    addUpdatePanel.add(clearButton);
   
  -    leftCenterPanel.add(expressionClearPanel);
  +    expressionPanel.add(addUpdatePanel);
  +
  +    leftCenterPanel.add(expressionPanel);
   
       JPanel chooserPanel = new JPanel();
       chooserPanel.add(chooser);
  @@ -252,7 +246,13 @@
       updownPanel.add(updownLabelPanel);
       updownPanel.add(downPanel);
   
  -    add(updownPanel);
  +    JPanel centerRightPanel = new JPanel();
  +    centerRightPanel.setLayout(
  +      new BoxLayout(centerRightPanel, BoxLayout.X_AXIS));
  +
  +    centerRightPanel.setBorder(BorderFactory.createEtchedBorder());
  +
  +    centerRightPanel.add(updownPanel);
   
       upButton.addActionListener(
         new AbstractAction() {
  @@ -330,28 +330,31 @@
       addUpdateButton.addActionListener(
         new AbstractAction() {
           public void actionPerformed(ActionEvent evt) {
  -          ColorRuleHolder holder =
  -            new ColorRuleHolder(
  -              expression.getText(),
  -              new ColorRule(
  -                ExpressionRule.getRule(expression.getText()),
  -                chooser.getColor()));
  -
  -          if (addMode) {
  -            listModel.addElement(holder);
  -          } else {
  -            int index = list.getSelectionModel().getMaxSelectionIndex();
  -            listModel.remove(index);
  -            listModel.add(index, holder);
  -          }
  +          try {
  +            ColorRuleHolder holder =
  +              new ColorRuleHolder(
  +                expression.getText(),
  +                new ColorRule(
  +                  ExpressionRule.getRule(expression.getText()),
  +                  expression.getBackground(), expression.getForeground()));
   
  -          int index = listModel.indexOf(holder);
  -          list.getSelectionModel().setSelectionInterval(index, index);
  +            if (addMode) {
  +              listModel.addElement(holder);
  +            } else {
  +              int index = list.getSelectionModel().getMaxSelectionIndex();
  +              listModel.remove(index);
  +              listModel.add(index, holder);
  +            }
  +
  +            int index = listModel.indexOf(holder);
  +            list.getSelectionModel().setSelectionInterval(index, index);
  +          } catch (IllegalArgumentException iae) {
  +            //invalid expression - can't add
  +          }
           }
         });
   
       JPanel rightPanel = new JPanel(new BorderLayout());
  -
       rightPanel.add(new JLabel("Rules:"), BorderLayout.NORTH);
       rightPanel.add(scrollPane, BorderLayout.CENTER);
   
  @@ -367,7 +370,8 @@
           }
         });
   
  -    add(rightPanel);
  +    centerRightPanel.add(rightPanel);
  +    add(centerRightPanel);
     }
   
     void applyRules() {
  
  
  

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