logging-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sde...@apache.org
Subject svn commit: r930178 - /logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
Date Fri, 02 Apr 2010 07:07:14 GMT
Author: sdeboy
Date: Fri Apr  2 07:07:14 2010
New Revision: 930178

URL: http://svn.apache.org/viewvc?rev=930178&view=rev
Log:
Chainsaw refine focus combobox updates
 - ensure entries added to refine focus combobox are inserted at the top of the combobox (and
that they are restored after exit & restart in the same order)

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=930178&r1=930177&r2=930178&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 Fri Apr 
2 07:07:14 2010
@@ -986,8 +986,8 @@ public class LogPanel extends DockablePa
                   Object item = filterCombo.getSelectedItem();
                   if (item != null && !item.toString().trim().equals("")) {
                     ExpressionRule.getRule(item.toString());
-                    //add to the combo box
-                    filterCombo.addItem(item);
+                    //add entry as first row of the combo box
+                    filterCombo.insertItemAt(item, 0);
                   }
                 //valid expression, reset background color in case we were previously an
invalid expression
                 filterText.setBackground(UIManager.getColor("TextField.background"));
@@ -1684,7 +1684,8 @@ public class LogPanel extends DockablePa
                 savedVector = (Vector) in.readObject();
                 for(int i = 0 ; i < savedVector.size() ; i++){
                     Object item = savedVector.get(i);
-                    filterCombo.addItem(item);
+                    //insert each row at index zero (so last row in vector will be row zero)
+                    filterCombo.insertItemAt(item, 0);
                 }
                 if (versionNumber > 1) {
                     //update prefModel columns to include defaults
@@ -3378,6 +3379,7 @@ public class LogPanel extends DockablePa
         private AutoFilterComboBoxModel model = new AutoFilterComboBoxModel();
         //editor component
         private final JTextField textField = new JTextField();
+        private String lastTextToMatch;
 
         public AutoFilterComboBox(Collection entries) {
             if (entries != null) {
@@ -3394,17 +3396,23 @@ public class LogPanel extends DockablePa
         }
 
         public Vector getModelData() {
-            return new Vector(allEntries);
+            //reverse the model order, because it will be un-reversed when we reload it from
saved settings
+            Vector vector = new Vector();
+            for (Iterator iter = allEntries.iterator();iter.hasNext();) {
+                vector.insertElementAt(iter.next(), 0);
+            }
+            return vector;
         }
 
         private void refilter() {
-            //only refilter if we're not bypassing filtering
-            if (bypassFiltering) {
+            //only refilter if we're not bypassing filtering AND the text has changed since
the last call to refilter
+            String textToMatch = getEditor().getItem().toString();
+            if (bypassFiltering || (lastTextToMatch != null && lastTextToMatch.equals(textToMatch)))
{
                 return;
             }
+            lastTextToMatch = textToMatch;
             displayedEntries.clear();
             bypassFiltering = true;
-            String textToMatch = getEditor().getItem().toString();
                 model.removeAllElements();
                 List entriesCopy = new ArrayList(allEntries);
                 for (Iterator iter = entriesCopy.iterator();iter.hasNext();) {
@@ -3501,7 +3509,7 @@ public class LogPanel extends DockablePa
                 }
                 bypassFiltering = true;
                 displayedEntries.add(index, obj);
-                allEntries.add(obj);
+                allEntries.add(index, obj);
                 fireIntervalAdded(this, index, index);
                 bypassFiltering = false;
                 refilter();



Mime
View raw message