gt:         StringBuilder sb = new StringBuilder();
context: /*
   * Host.java
   *
   * Created on August 9, 2005, 4:37 PM
   *
   */
  
  package eunomia.plugin.gui.hostView;
  
  import eunomia.config.*;
  import eunomia.core.managers.ModuleManager;
  import eunomia.receptor.module.NABFlow.NABFlow;
  import eunomia.util.*;
  import eunomia.flow.*;
  import eunomia.messages.receptor.ModuleHandle;
  import eunomia.plugin.interfaces.GUIModule;
  
  import java.awt.*;
  import java.awt.event.*;
  import java.io.*;
  import java.net.*;
  import java.text.*;
  import java.util.HashMap;
  import java.util.Iterator;
  import javax.swing.*;
  
  import org.jfree.chart.*;
  import org.jfree.chart.axis.*;
  import org.jfree.chart.plot.*;
  import org.jfree.chart.renderer.category.*;
  import org.jfree.ui.*;
  
  
  /**
   *
   * @author Mikhail Sosonkin
   */
  
  public class Host extends JPanel implements ConfigChangeListener,
          ActionListener, Runnable {
      private static Format form;
      private static Font labelFont;
      private static Insets tickLabelInset;
      private static RectangleInsets plotInset;
  
      private InetAddress host;
      
      private JLabel totalData;
      private JLabel inData;
      private JLabel outData;
      private JLabel conCount;
      private JLabel upRate;
      private JLabel downRate;
      private JLabel rangeTopVal;
      private JLabel rangeBotVal;
      private JButton details;
      private JPopupMenu detailsMenu;
      
      private JFreeChart chart;
      private NumberAxis valueAxis;
      private CategoryPlot cPlot;
      private HashMap itemToHandle;
      private GUIModule module;
      
      private boolean firstUpdate;
      
      //data
      private HistoryDisplay historyData;
      private long startTime;
      private long totalBytes, inBytes, outBytes;
      private double outRate, inRate;
      
      static {
          form = DecimalFormat.getInstance();
          labelFont = new Font("SansSerif", Font.PLAIN, 9);
          tickLabelInset = new Insets(20, 0, 20, 0);
          plotInset = new RectangleInsets(0, 0, 0, 2);
      }
      
      public Host(long ip, InetAddress hostAddr, GUIModule mod) {
          module = mod;
          host = hostAddr;
          firstUpdate = true;
          detailsMenu = new JPopupMenu();
          itemToHandle = new HashMap();
          
          addControls();
          
          Dimension dim = getPreferredSize();
          dim.setSize(-1, 90);
          setPreferredSize(dim);
          
          configurationChanged();
          Settings.addConfigChangeListener(this);
      }
      
      public void hostRemoved(){
      }
      
      public void readHost(DataInputStream din) throws IOException {
          startTime = din.readLong();
          totalBytes = din.readLong();
          inBytes = din.readLong();
          outBytes = din.readLong();
          outRate = din.readDouble();
          inRate = din.readDouble();
          
          if(firstUpdate){
              borderThread();
              firstUpdate = false;
          }
          
          historyData.readHistory(din);
      }
      public void updateData() {
          if(isVisible()){
              rangeTopVal.setText(Util.convertBytes(valueAxis.getUpperBound(), true));
              rangeBotVal.setText(Util.convertBytes(valueAxis.getLowerBound(), true));
       
              totalData.setText(Util.convertBytes(totalBytes, true));
              inData.setText(Util.convertBytes(inBytes, true));
              outData.setText(Util.convertBytes(outBytes, true));
              upRate.setText(Util.convertBytesRate(outRate, true));
              downRate.setText(Util.convertBytesRate(inRate, true));
              historyData.updateData();
          }
      }
      
      public void actionPerformed(ActionEvent e) {
          Object o = e.getSource();
          
          if(o == details){
              configurePopupMenu();
              detailsMenu.show(details, 0, 0);
          } else if(itemToHandle.containsKey(o)){
              addToDetails((ModuleHandle)itemToHandle.get(o));
          }
      }
      
      private void addToDetails(ModuleHandle handle){
          ((Main)module).addHostToDetails(Util.getLongIp(host), handle);
      }
      
      private void configurePopupMenu(){
          detailsMenu.removeAll();
          ModuleManager mmon = module.getReceptor().getManager();
          java.util.List hvList = mmon.getModuleList("hostDetails");
          if(hvList.size() > 0){
              Iterator it = hvList.iterator();
              while (it.hasNext()) {
                  GUIModule mod = (GUIModule) it.next();
                  ModuleHandle hand = mmon.getModuleHandle(mod);
                  JMenuItem item = detailsMenu.add(hand.toString());
                  itemToHandle.put(item, hand);
                  item.addActionListener(this);
              }
          } else {
              detailsMenu.add("No hostDetails instances found");
          }
      }
      
      private void addControls(){
          JMenuBar menuBar = new JMenuBar();
          setLayout(new BorderLayout());
          
          JPanel topPanel = new JPanel(new BorderLayout());
          JPanel totalsPanel = new JPanel(new GridLayout(1, 6));
          JPanel consPanel = new JPanel(new GridLayout(2, 4));
          JPanel ratesPanel = new JPanel(new BorderLayout());
          JPanel ratesLabelsPanel = new JPanel(new GridLayout(2, 1));
          JPanel ratesNumbersPanel = new JPanel(new GridLayout(2, 1));
          JPanel graphPanel = new JPanel(new BorderLayout());
          
          totalsPanel.add(makeLabel("Total:"));
          totalsPanel.add(totalData = makeLabel("0"));
          totalsPanel.add(makeLabel("Ingress: "));
          totalsPanel.add(inData = makeLabel("0"));
          totalsPanel.add(makeLabel("Egress: "));
          totalsPanel.add(outData = makeLabel("0"));
          
          ratesLabelsPanel.add(makeLabel("UL: "));
          ratesLabelsPanel.add(makeLabel("DL: "));
          ratesNumbersPanel.add(upRate = makeLabel(""));
          ratesNumbersPanel.add(downRate = makeLabel(""));
          
          ratesPanel.add(ratesLabelsPanel, BorderLayout.WEST);
          ratesPanel.add(ratesNumbersPanel);
          ratesPanel.add(details = new JButton("Details"), BorderLayout.SOUTH);
          
          topPanel.add(totalsPanel, BorderLayout.NORTH);
          
          graphPanel.add(createChart());
          graphPanel.add(ratesPanel, BorderLayout.EAST);
          add(topPanel, BorderLayout.NORTH);
          add(graphPanel);
          
          setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), genHostString("Resolving")));
          
          totalData.setHorizontalAlignment(JLabel.LEFT);
          inData.setHorizontalAlignment(JLabel.LEFT);
          outData.setHorizontalAlignment(JLabel.LEFT);
          
          ratesPanel.setPreferredSize(new Dimension(80, 0));
          details.addActionListener(this);
          details.setFont(labelFont);
          details.setPreferredSize(new Dimension(0, 20));
      }
      
      private void borderThread(){
          new Thread(this).start();
      }
      
      public void run(){
          setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), genHostString(host.getHostName())));
      }
      
      private String genHostString(String hostName){
  