logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psm...@apache.org
Subject cvs commit: jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw ReceiverTreeCellRenderer.java
Date Mon, 23 Jun 2003 03:49:03 GMT
psmith      2003/06/22 20:49:03

  Modified:    src/java/org/apache/log4j/chainsaw
                        ReceiverTreeCellRenderer.java
  Log:
  Removed the internal Formatter interface and chain as it was
  getting hard to manage.  Once the Tree is more stable, will consider
  revisting it, but for now the if/else logic isn't too complex.
  
  Revision  Changes    Path
  1.5       +37 -99    jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ReceiverTreeCellRenderer.java
  
  Index: ReceiverTreeCellRenderer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ReceiverTreeCellRenderer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ReceiverTreeCellRenderer.java	23 Jun 2003 02:55:16 -0000	1.4
  +++ ReceiverTreeCellRenderer.java	23 Jun 2003 03:49:03 -0000	1.5
  @@ -57,10 +57,6 @@
   
   import java.awt.Component;
   
  -import java.util.ArrayList;
  -import java.util.Collection;
  -import java.util.Iterator;
  -
   import javax.swing.Icon;
   import javax.swing.ImageIcon;
   import javax.swing.JTree;
  @@ -80,57 +76,9 @@
     private Icon inactiveReceiverIcon =
       new ImageIcon(ChainsawIcons.ICON_INACTIVE_RECEIVER);
     private Icon rootIcon = new ImageIcon(ChainsawIcons.ANIM_NET_CONNECT);
  -  private FormatterChain chain;
   
     public ReceiverTreeCellRenderer() {
       super();
  -    chain = new FormatterChain();
  -    chain.add(
  -      new Formatter() {
  -        public String formatDetail(Object o) {
  -          if (!(o instanceof NetworkBased)) {
  -            return null;
  -          }
  -
  -          NetworkBased networkBased = (NetworkBased) o;
  -
  -          StringBuffer buf = new StringBuffer(networkBased.getName());
  -
  -          if (o instanceof AddressBased) {
  -            buf.append("::").append(((AddressBased) o).getAddress());
  -          }
  -
  -          if (o instanceof PortBased) {
  -            PortBased portBased = (PortBased) o;
  -
  -            buf.append("::").append(portBased.getPort());
  -          }
  -
  -          buf.append(" ").append("(")
  -             .append(networkBased.isActive() ? "running" : "inactive").append(
  -            ")");
  -
  -          return buf.toString();
  -        }
  -      });
  -
  -    chain.add(
  -      new Formatter() {
  -        public String formatDetail(Object o) {
  -          if (o == ReceiversTreeModel.NoReceiversNode.getUserObject()) {
  -            return o.toString();
  -          }
  -
  -          return null;
  -        }
  -      });
  -
  -    chain.add(
  -      new Formatter() {
  -        public String formatDetail(Object o) {
  -          return "(Unknown Type) :: " + o;
  -        }
  -      });
     }
   
     public Component getTreeCellRendererComponent(
  @@ -140,67 +88,57 @@
         tree, value, selected, expanded, leaf, row, hasFocus);
   
       DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
  -    Object obj = node.getUserObject();
  -    setText(obj.toString());
  +    Object o = node.getUserObject();
  +    setText(o.toString());
   
  -    if (tree.getModel().getRoot().equals(value)) {
  -      setIcon(rootIcon);
  -    } else {
  -      setText(chain.formatDetail(obj));
  -    }
  +    /**
  +     * Deal with Text
  +     */
  +    if ((o instanceof NetworkBased)) {
  +      NetworkBased networkBased = (NetworkBased) o;
   
  -    if (obj instanceof NetworkBased) {
  -      NetworkBased networkBased = (NetworkBased) obj;
  +      StringBuffer buf = new StringBuffer(networkBased.getName());
   
  -      if (networkBased.isActive()) {
  -        if ((obj instanceof Pauseable) && !((Pauseable) obj).isPaused()) {
  -          setIcon(activeReceiverIcon);
  -        } else {
  -          setIcon(inactiveReceiverIcon);
  -        }
  -      } else {
  +      if (o instanceof AddressBased) {
  +        buf.append("::").append(((AddressBased) o).getAddress());
         }
  -    } else if (obj == ReceiversTreeModel.NoReceiversNode.getUserObject()) {
  -      setIcon(null);
  -    }
   
  -    return this;
  -  }
  +      if (o instanceof PortBased) {
  +        PortBased portBased = (PortBased) o;
   
  -  private static interface Formatter {
  -    /**
  -     * Returns a formatted string for the receiver or null if it cannot.
  -     * @param receiver
  -     * @return
  -     */
  -    public String formatDetail(Object networkBased);
  -  }
  +        buf.append("::").append(portBased.getPort());
  +      }
   
  -  private static class FormatterChain implements Formatter {
  -    private Collection collection = new ArrayList();
  +      buf.append(" ").append("(")
  +         .append(networkBased.isActive() ? "running" : "inactive").append(")");
   
  -    /**
  -     * @param formatter
  -     */
  -    public void add(Formatter formatter) {
  -      collection.add(formatter);
  +      setText(buf.toString());
  +    } else if (
  +      o == ((ReceiversTreeModel) tree.getModel()).getRootNode().getUserObject()) {
  +      setText(o.toString());
  +    } else {
  +      setText("(Unknown Type) :: " + o);
       }
   
  -    /* (non-Javadoc)
  -     * @see org.apache.log4j.chainsaw.ChainsawToolBarAndMenus.ReceiverTreeCellRenderer.ReceiverFormatter#formatDetail(org.apache.log4j.plugins.Receiver)
  +    /**
  +     * Now deal with Icon
        */
  -    public String formatDetail(Object receiver) {
  -      for (Iterator iter = collection.iterator(); iter.hasNext();) {
  -        ReceiverTreeCellRenderer.Formatter item =
  -          (ReceiverTreeCellRenderer.Formatter) iter.next();
  -        String detail = item.formatDetail(receiver);
  +    if (o instanceof NetworkBased) {
  +      NetworkBased networkBased = (NetworkBased) o;
   
  -        if (detail != null) {
  -          return detail;
  +      if (networkBased.isActive()) {
  +        if ((o instanceof Pauseable) && !((Pauseable) o).isPaused()) {
  +          setIcon(activeReceiverIcon);
  +        } else {
  +          setIcon(inactiveReceiverIcon);
           }
  +      } else {
         }
  -
  -      return null;
  +    } else if (
  +      o == ((ReceiversTreeModel) tree.getModel()).getRootNode().getUserObject()) {
  +      setIcon(rootIcon);
       }
  +
  +    return this;
     }
   }
  
  
  

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


Mime
View raw message