psmith      2003/10/02 20:55:52

  Modified:    src/java/org/apache/log4j/chainsaw
                        LogPanelPreferenceModel.java
  Log:
  Preference model now tracks selected columns.
  
  Revision  Changes    Path
  1.4       +63 -0     
jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogPanelPreferenceModel.java
  
  Index: LogPanelPreferenceModel.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogPanelPreferenceModel.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LogPanelPreferenceModel.java      2 Oct 2003 08:28:56 -0000       1.3
  +++ LogPanelPreferenceModel.java      3 Oct 2003 03:55:52 -0000       1.4
  @@ -53,15 +53,18 @@
   
   import org.apache.log4j.chainsaw.prefs.SettingsManager;
   
  +import java.beans.PropertyChangeEvent;
   import java.beans.PropertyChangeListener;
   import java.beans.PropertyChangeSupport;
   
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Collections;
  +import java.util.HashSet;
   import java.util.Iterator;
   import java.util.Map;
   import java.util.Properties;
  +import java.util.Set;
   
   
   /**
  @@ -92,6 +95,7 @@
       new PropertyChangeSupport(this);
     private String dateFormatPattern = ISO8601;
     private boolean levelIcons = true;
  +  private Set visibleColumns = new HashSet(ChainsawColumns.getColumnsNames());
   
     /**
      * Returns the Date Pattern string for the alternate date formatter.
  @@ -154,6 +158,32 @@
     public void apply(LogPanelPreferenceModel that) {
       setDateFormatPattern(that.getDateFormatPattern());
       setLevelIcons(that.isLevelIcons());
  +    
  +    /**
  +     * First, iterate and ADD new columns, (this means notifications of adds go out 
first
  +     * add to the end
  +     */
  +    for (Iterator iter = that.visibleColumns.iterator(); iter.hasNext();) {
  +             String column = (String) iter.next();
  +             if(!this.visibleColumns.contains(column)){
  +                     setColumnVisible(column, true);
  +             }
  +     }
  +     /**
  +      * Now go through and apply removals
  +      */
  +     /**
  +      * this copy is needed to stop ConcurrentModificationException
  +      */
  +     Set thisSet = new HashSet(this.visibleColumns);
  +     for (Iterator iter = thisSet.iterator(); iter.hasNext();) {
  +             String column = (String) iter.next();
  +             if(!that.visibleColumns.contains(column)){
  +                     setColumnVisible(column, false);
  +             }
  +     }
  +     
  +
     }
   
     /**
  @@ -179,5 +209,38 @@
       boolean oldVal = this.levelIcons;
       this.levelIcons = levelIcons;
       propertySupport.firePropertyChange("levelIcons", oldVal, this.levelIcons);
  +  }
  +
  +  /**
  +   * Returns true if the named column should be made visible otherwise
  +   * false.
  +   * @param columnName
  +   * @return
  +   */
  +  public boolean isColumnVisible(String columnName) {
  +    return visibleColumns.contains(columnName);
  +  }
  +
  +  public void setColumnVisible(String columnName, boolean isVisible) {
  +    boolean oldValue = visibleColumns.contains(columnName);
  +    boolean newValue = isVisible;
  +
  +    if (isVisible) {
  +      visibleColumns.add(columnName);
  +    } else {
  +      visibleColumns.remove(columnName);
  +    }
  +
  +    propertySupport.firePropertyChange(
  +      new PropertyChangeEvent(
  +        this, "visibleColumns", new Boolean(oldValue), new Boolean(newValue)));
  +  }
  +
  +  /**
  +   * Toggles the state between visible, non-visible for a particular Column name
  +   * @param string
  +   */
  +  public void toggleColumn(String column) {
  +    setColumnVisible(column, !isColumnVisible(column));
     }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to