/*
 * KommentarListe.java
 *
 * Created on 14. März 2001, 17:09
 */


import java.util.Hashtable;
import java.util.Enumeration;
import java.util.Vector;
import java.io.PrintWriter;



/**
 *
 * @author  Dr. Jan-Torsten Milde, Universität Bielefeld
 * @version
 */

public class KommentarListe extends Hashtable {
    private String currentLetter = "";
    private Vector KEYS = new Vector();


    /** Creates new KommentarListe */
    public KommentarListe() {
        initWerther();
        //this.print();
    }

    public void add (String k, String v) {
        if (!KEYS.contains(k.toLowerCase())) {
            KEYS.addElement(k.toLowerCase());
        }
        this.put(k,v);
    }


    public void initWerther() {
        this.add("komplett", "");

        // 1-tes Buch
        this.add("vorrede", "");

        this.add("04-05-71", "");
        this.add("10-05-71", "");
        this.add("12-05-71", "");
        this.add("13-05-71", "");
        this.add("15-05-71", "");
        this.add("22-05-71", "");
        this.add("26-05-71", "");
        this.add("30-05-71", "");

        this.add("16-06-71", "");
        this.add("19-06-71", "");
        this.add("29-06-71", "");

        this.add("01-07-71", "");
        this.add("06-07-71", "");
        this.add("08-07-71", "");
        this.add("10-07-71", "");
        this.add("11-07-71", "");
        this.add("13-07-71", "");
        this.add("16-07-71", "");
        this.add("18-07-71", "");
        this.add("19-07-71", "");
        this.add("20-07-71", "");
        this.add("24-07-71", "");
        this.add("26-07-71", "");
        this.add("30-07-71", "");

        this.add("08-08-71", "");
        this.add("10-08-71", "");
        this.add("12-08-71", "");
        this.add("15-08-71", "");
        this.add("18-08-71", "");
        this.add("21-08-71", "");
        this.add("22-08-71", "");
        this.add("28-08-71", "");
        this.add("30-08-71", "");

        this.add("03-09-71", "");
        this.add("10-09-71", "");

        // 2-tes Buch
        this.add("20-10-71", "");
        this.add("26-11-71", "");
        this.add("24-12-71", "");

        this.add("08-01-72", "");
        this.add("20-01-72", "");

        this.add("08-02-72", "");
        this.add("17-02-72", "");
        this.add("20-02-72", "");

        this.add("15-03-72", "");
        this.add("16-03-72", "");
        this.add("24-03-72", "");

        this.add("19-04-72", "");

        this.add("05-05-72", "");
        this.add("09-05-72", "");
        this.add("25-05-72", "");

        this.add("11-06-72", "");
        this.add("16-06-72", "");
        this.add("18-06-72", "");

        this.add("29-07-72", "");

        this.add("04-08-72", "");
        this.add("21-08-72", "");

        this.add("03-09-72", "");
        this.add("04-09-72", "");
        this.add("05-09-72", "");
        this.add("06-09-72", "");
        this.add("12-09-72", "");
        this.add("15-09-72", "");

        this.add("10-10-72", "");
        this.add("12-10-72", "");
        this.add("26-10-72", "");
        this.add("27-10-72", "");
        this.add("30-10-72", "");

        this.add("03-11-72", "");
        this.add("08-11-72", "");
        this.add("15-11-72", "");
        this.add("21-11-72", "");
        this.add("22-11-72", "");
        this.add("24-11-72", "");
        this.add("26-11-72", "");
        this.add("30-11-72", "");

        this.add("01-12-72", "");
        this.add("04-12-72", "");
        this.add("06-12-72", "");

        this.add("bericht 1", "");

        this.add("12-12-72", "");
        this.add("14-12-72", "");
        this.add("20-12-72", "");

        this.add("bericht 2", "");
        this.add("ossian", "");
        this.add("abschied", "");
        this.add("ende", "");

        currentLetter = "vorrede";
    }

    public void nextLetter() {
        if ((KEYS != null) && (!(KEYS.isEmpty()))) {
            int last = KEYS.size()-1;
            if (KEYS.contains(currentLetter)) {
                int index = KEYS.indexOf(currentLetter);
                if (index == last) {
                    index = -1;
                }
                currentLetter = (String)KEYS.elementAt(index+1);
            }
        }
    }

    public void previousLetter() {
        if ((KEYS != null) && (!(KEYS.isEmpty()))) {
            int last = KEYS.size()-1;
            if (KEYS.contains(currentLetter)) {
                int index = KEYS.indexOf(currentLetter);
                if (index == 0) {
                    index = (last+1);
                }
                currentLetter = (String)KEYS.elementAt(index-1);
            }
        }
    }

    public void setCurrentLetter (String s) {
        currentLetter = s.toLowerCase();
    }

    public String getCurrentLetter() {
        return (currentLetter);
    }

    public void setCurrentComment(String s) {
        if (this.containsKey(currentLetter)) {
            this.add(currentLetter, s);
        }
    }

    public String getCurrentComment() {
        if (this.containsKey(currentLetter)) {
            String r = (String)(this.get(currentLetter));
            return(r);
        } else {
            return ("");
        }
    }

    public void print () {
        Enumeration e = this.elements();
        while (e.hasMoreElements()) {
            String s = (String)e.nextElement();
        }
    }

    public String toString() {
        String result = "";
        result += "<werther>";
        Enumeration keys = (this.KEYS).elements();
        while (keys.hasMoreElements()) {
            String k = (String)keys.nextElement();

            result += "<letter L-NUM=\"";
            result += k;
            result += "\">";

            result += "<kommentar><text>";
            result += (String)(this.get(k));
            result += "</text></kommentar>";

            result += "</letter>";
        }
        result += "</werther>";

        return(result);
    }

    public String toHTMLString(boolean isSyn) {
        String result = "";
        result += "<html>";
        result += "<body Background=\"../../../../Grafik/papier2.jpg\" link=\"#000000\" vlink=\"#000000\" alink=\"#FF0000\">";
        result += getHTMLHeader(isSyn);
        Enumeration keys = (this.KEYS).elements();
        while (keys.hasMoreElements()) {
            String k = (String)keys.nextElement();

            result += "<div STYLE=\"font-family:Verdana;     font-size:9pt;     text-align:right;    margin-top:.1em;    margin-bottom:.3em;      padding:0px 6px\">";
            result += k;
            result += "</div>";

            result += "<div STYLE=\"font-family:Verdana;     font-size:9pt;     margin-top:.1em;    margin-bottom:.5em;      padding:0px 6px\">";
            String line = (String)(this.get(k)) + "\n\n";
            result += this.expandNewlines(line);
            result += "</div>";
        }

        result += "<center><img BORDER=\"0\" src=\"../../../../Grafik/qustrich.gif\"></center>";
        result += "</body>";
        result += "</html>";

        return(result);
    }

    private String expandNewlines (String s) {
        String result = "";
        if (s != null) {
            int idx = s.indexOf("\n\n");
            if (idx > -1) {
                while (idx > -1) {
                    if (idx > 0) {
                        String bs = s.substring(0, idx) + "<br><br>\n";
                        result += bs;
                    }
                    if ((idx+1) < s.length()) {
                        s = s.substring(idx+1);
                        idx = s.indexOf("\n\n");
                    } else {
                        idx = -1;
                    }
                }
            } else {
                result = s;
            }
        }
        return (result);
    }

    private String getHTMLHeader (boolean isSyn) {
        if (isSyn) {
            return (
            "<DIV STYLE=\"background-color:#CCCCCC\">" +
            "<table cellspacing=\"0\" cellpadding=\"2\" width=\"100%\" border=\"0\">" +
            "<tr>" +
            "<td width=\"90%\"><SPAN STYLE=\"font-size:12pt;    font-family:Verdana;    font-weight:bold;    margin-bottom:.5em;\"><font color=\"#3D3D3D\">Eigene Eintr&auml;ge</font></SPAN></td>" +
            "<td ALIGN=\"center\" VALIGN=\"middle\"><A TARGET=\"_parent\" href=\"../inhalt.htm\"><IMG BORDER=\"0\" ALT=\"Zur &Uuml;bersicht\" SRC=\"../../../../Grafik/home.gif\"></A></td>" +
            "<td ALIGN=\"center\" VALIGN=\"middle\"><IMG BORDER=\"0\" SRC=\"../../../../Grafik/ungleihh.gif\"></td>" +
            "<td ALIGN=\"center\" VALIGN=\"middle\"><A TARGET=\"_parent\" href=\"../komplett/eintrag0.htm\"><IMG BORDER=\"0\" ALT=\"Zur Einzelebene\" SRC=\"../../../../Grafik/einzel.gif\"></A></td>" + 
            "<td ALIGN=\"center\" VALIGN=\"middle\"><IMG BORDER=\"0\" ALT=\"Keine Druckfassung\" src=\"../../../../Grafik/printer0.gif\"></td>" +
            "</tr>" +
            "</table>" +
            "</DIV>" +
            ""

            );
        } else {
            return (
            "<DIV STYLE=\"background-color:#CCCCCC\">" +
            "<table cellspacing=\"0\" cellpadding=\"2\" width=\"100%\" border=\"0\">" +
            "<tr>" +
            "<td width=\"90%\"><SPAN STYLE=\"font-size:12pt;    font-family:Verdana;    font-weight:bold;    margin-bottom:.5em;\"><font color=\"#3D3D3D\">Eigene Eintr&auml;ge</font></SPAN></td>" +
            "<td ALIGN=\"center\" VALIGN=\"middle\"><A TARGET=\"_parent\" href=\"../inhalt.htm\"><IMG BORDER=\"0\" ALT=\"Zur &Uuml;bersicht\" SRC=\"../../../../Grafik/home.gif\"></A></td>" +
            "<td ALIGN=\"center\" VALIGN=\"middle\"><A TARGET=\"_parent\" href=\"../werther.htm\"><IMG BORDER=\"0\" ALT=\"Zur Synopse\" SRC=\"../../../../Grafik/ungleich.gif\"></A></td>" +
            "<td ALIGN=\"center\" VALIGN=\"middle\"><IMG BORDER=\"0\" SRC=\"../../../../Grafik/einzelh.gif\"></td>" +
            "<td ALIGN=\"center\" VALIGN=\"middle\"><IMG BORDER=\"0\" ALT=\"Keine Druckfassung\" src=\"../../../../Grafik/printer0.gif\"></td>" +
            "</tr>" +
            "</table>" +
            "</DIV>" +
            ""
            );
        }
    }

}
