/*
 * ErrorSink.java
 *
 * This class just accumulates error messages on startup so they be displayed in 
 * one group.
 *
 * Jim Frankenberger
 * USDA-ARS, West Lafayette IN
 * jrf@purdue.edu
 *
 * Created on September 24, 2004, 2:45 PM
 */

package ex1;


import javax.swing.*;

/**
 * This class just accumulates error messages on startup so they be displayed in 
 * one group.
 *
 * @author  jrf
 */
public class ErrorSink {
    static private String estr = "";
    
    static private String outd = "";
    
    static private int outCount = 0;
    
    /** Creates a new instance of ErrorSink. This is only done once for the  whole application. */
    public ErrorSink() {
        
    }
    
    /**
     * Adds an error string to big buffer
     *  @param s String to add, newline is appended
     */
    static public void add(String s) {
        estr = estr.concat(s) + "\n";
    }
    
    /**
     * Adds an outdate file message to the big buffer.
     * @param input String to add, newline appended.
     */
    static public void outDate(String input)
    {
        if(outCount < 5) outd += input + "\n";
        outCount++;
    }
    
    /*
     * Displays the current error string in JOptionPane dialog. Doe nothing if there
     * is no string to display.
     *
     */

	/**
	 *
	 */
	
    static public void display() {
        if(outCount > 5) outd += "And " + (outCount - 5) + " others.";
        if (estr.length()>0) JOptionPane.showMessageDialog(null, estr, 
                "Error/Warning Messages", JOptionPane.ERROR_MESSAGE); 
        if(outd.length() > 0) JOptionPane.showMessageDialog(null, outd,
                    "Outdated File", JOptionPane.INFORMATION_MESSAGE);
    }
    
}
