package com.dua3.utility.swing;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.text.StyledDocument;

import com.dua3.utility.text.MarkDownStyle;
import com.dua3.utility.text.MarkDownTest;
import com.dua3.utility.text.MarkDownUtil;
import com.dua3.utility.text.RichText;

public class SwingUtilTest extends JFrame {

	private static final long serialVersionUID = 1L;

	public static void main(String[] args) throws Exception {
        SwingUtil.setNativeLookAndFeel(SwingUtilTest.class.getSimpleName());

        String testfile = args.length == 0 ? "syntax.md" : args[0];
        SwingUtilTest inst = new SwingUtilTest(testfile);
        inst.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        inst.setSize(new Dimension(800,600));
        inst.setVisible(true);
    }

    public SwingUtilTest(String testfile) throws Exception {
        super("Swing Utilities test");
        JTabbedPane tabs = new JTabbedPane();
        add(tabs);
        tabs.add("MarkDown Test", new MdTestPanel(testfile));
        pack();
    }

    static class MdTestPanel extends JPanel {
        private static final long serialVersionUID = 1L;

        private JTextPane mdComponent = new JTextPane();
        private JTextArea sourceComponent = new JTextArea();

        public MdTestPanel(String testfile) throws Exception {
            setLayout(new BorderLayout());
            String mdSource = MarkDownTest.getTestData(testfile);

            JTabbedPane tabs = new JTabbedPane();
            add(tabs, BorderLayout.CENTER);
            tabs.add("preview", new JScrollPane(mdComponent));
            tabs.add("source", new JScrollPane(sourceComponent));

            setSource(mdSource);
        }

        void setSource(String mdSource) {
            sourceComponent.setText(mdSource);
            RichText richtext = MarkDownUtil.convert(mdSource);
			StyledDocument doc = StyledDocumentBuilder.toStyledDocument(richtext, MarkDownStyle::getAttributes);
            mdComponent.setDocument(doc);
        }

    }
}

@@ -312,24 +312,85 @@
 ocument;%0D%0A%0D%0A
+import org.slf4j.Logger;%0D%0Aimport org.slf4j.LoggerFactory;%0D%0A%0D%0A
 import com.d
@@ -418,24 +418,24 @@
 DownStyle;%0D%0A
-
 import com.d
@@ -652,16 +652,103 @@
  1L;%0D%0A%0D%0A
+    private static final Logger LOG = LoggerFactory.getLogger(SwingUtilTest.class);%0D%0A%0D%0A
 %09public 
@@ -791,32 +791,80 @@
 ws Exception %7B%0D%0A
+%09    LOG.info(%22setting native look and feel%22);%0D%0A
         SwingUti
@@ -996,16 +996,68 @@
 gs%5B0%5D;%0D%0A
+        LOG.info(%22test file is '%7B%7D'%22, testfile);%0D%0A%0D%0A
         
@@ -1215,24 +1215,65 @@
 800,600));%0D%0A
+        LOG.info(%22instance created%22);%0D%0A%0D%0A
         inst
@@ -2280,24 +2280,65 @@
 dSource) %7B%0D%0A
+            LOG.info(%22setting source%22);%0D%0A
             
@@ -2365,32 +2365,88 @@
 ext(mdSource);%0D%0A
+            LOG.info(%22creating RichText from source%22);%0D%0A
             Rich
@@ -2494,16 +2494,80 @@
 urce);%0D%0A
+            LOG.info(%22converting RichText to StyledDocument%22);%0D%0A
 %09%09%09Style
@@ -2659,24 +2659,84 @@
 tributes);%0D%0A
+            LOG.info(%22updating document in UI component%22);%0D%0A
             
@@ -2762,24 +2762,61 @@
 ment(doc);%0D%0A
+            LOG.info(%22source set%22);%0D%0A
         %7D%0D%0A%0D

add logging