package nxm.sys.test;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

import javax.swing.JTextArea;

/**
 * This is a test handler that is used by test_plot_wh_gui
 * It will provide the ability to log to a JTextArea that is provided via the {@link #addTextArea(JTextArea)} method.
 * @author Kevin Esterheld
 * @since 3.9.2
 */
public class CustomHandlerWhGui extends Handler {

  private List<JTextArea> textAreas;

  @Override
  public void publish (LogRecord record) {
    for(JTextArea textArea : textAreas) {
      textArea.append(record.getLevel() + ":" + record.getMessage() + "\n");
    }
  }

  /** CustomHandlerWhGui default constructor */
  public CustomHandlerWhGui () {
    this.textAreas = new ArrayList<>();
  }

  @Override
  public void flush () {
    // TODO Auto-generated method stub

  }

  @Override
  public void close () throws SecurityException {
    // TODO Auto-generated method stub

  }

  /**
   * Add a JTextArea to receive logs for this handler.
   * @param textArea The JTextArea to log to.
   */
  public void addTextArea(JTextArea textArea) {
    textAreas.add(textArea);
  }
}