logging-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sde...@apache.org
Subject svn commit: r673720 - /logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
Date Thu, 03 Jul 2008 15:50:38 GMT
Author: sdeboy
Date: Thu Jul  3 08:50:38 2008
New Revision: 673720

URL: http://svn.apache.org/viewvc?rev=673720&view=rev
Log:
Change background of search and refine focus fields to light-red if an invalid expression
is entered, reset background color to default when valid or empty

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?rev=673720&r1=673719&r2=673720&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 Thu Jul 
3 08:50:38 2008
@@ -18,6 +18,7 @@
 package org.apache.log4j.chainsaw;
 
 import java.awt.BorderLayout;
+import java.awt.Color;
 import java.awt.Component;
 import java.awt.Container;
 import java.awt.Dimension;
@@ -98,6 +99,7 @@
 import javax.swing.ListSelectionModel;
 import javax.swing.SwingConstants;
 import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
 import javax.swing.WindowConstants;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.DocumentEvent;
@@ -239,6 +241,7 @@
   private final DateFormat timestampExpressionFormat = new SimpleDateFormat(Constants.TIMESTAMP_RULE_FORMAT);
   private final Logger logger = LogManager.getLogger(LogPanel.class);
   private final Vector filterExpressionVector;
+  private static final Color INVALID_EXPRESSION_BACKGROUND = new Color(251, 186, 186);
 
   /**
    * Creates a new LogPanel object.  If a LogPanel with this identifier has
@@ -935,10 +938,13 @@
             if (e.getActionCommand().equals("comboBoxEdited")) {
               try {
                 //verify the expression is valid
-                ExpressionRule.getRule(
-                  filterCombo.getSelectedItem().toString());
+                ExpressionRule.getRule(filterCombo.getSelectedItem().toString());
+                //valid expression, reset background color in case we were previously an
invalid expression
+                filterText.setBackground(UIManager.getColor("TextField.background"));
               } catch (IllegalArgumentException iae) {
-                //don't add expressions that aren't valid
+                  //don't add expressions that aren't valid
+                  //invalid expression, change background of the field
+                  filterText.setBackground(INVALID_EXPRESSION_BACKGROUND);
                 return;
               }
 
@@ -1771,9 +1777,11 @@
   }
 
   public boolean updateRule(String ruleText) {
-    if ((ruleText == null) || (ruleText.equals(""))) {
+    if ((ruleText == null) || (ruleText.trim().equals(""))) {
       findRule = null;
       colorizer.setFindRule(null);
+      //reset background color in case we were previously an invalid expression
+      findField.setBackground(UIManager.getColor("TextField.background"));
       findField.setToolTipText(
         "Enter expression - right click or ctrl-space for menu");
       return false;
@@ -1785,10 +1793,13 @@
           "Enter expression - right click or ctrl-space for menu");
         findRule = ExpressionRule.getRule(ruleText);
         colorizer.setFindRule(findRule);
-
+        //valid expression, reset background color in case we were previously an invalid
expression
+        findField.setBackground(UIManager.getColor("TextField.background"));
         return true;
       } catch (IllegalArgumentException re) {
         findField.setToolTipText(re.getMessage());
+        //invalid expression, change background of the field
+        findField.setBackground(INVALID_EXPRESSION_BACKGROUND);
         colorizer.setFindRule(null);
 
         return false;
@@ -2474,7 +2485,9 @@
      * Update refinement rule based on the entered expression.
      */
     private void setFilter() {
-      if (filterText.getText().equals("")) {
+      if (filterText.getText().trim().equals("")) {
+        //reset background color in case we were previously an invalid expression
+        filterText.setBackground(UIManager.getColor("TextField.background"));
         ruleMediator.setRefinementRule(null);
         filterText.setToolTipText(defaultToolTip);
       } else {
@@ -2482,7 +2495,11 @@
           ruleMediator.setRefinementRule(
             ExpressionRule.getRule(filterText.getText()));
           filterText.setToolTipText(defaultToolTip);
+          //valid expression, reset background color in case we were previously an invalid
expression
+          filterText.setBackground(UIManager.getColor("TextField.background"));
         } catch (IllegalArgumentException iae) {
+          //invalid expression, change background of the field
+          filterText.setBackground(INVALID_EXPRESSION_BACKGROUND);
           filterText.setToolTipText(iae.getMessage());
         }
       }



Mime
View raw message