import java.io.*;
import java.awt.* ;
import java.awt.Image.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.io.File;
import java.io.FileNotFoundException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JEditorPane;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;

public class JStoreViewer extends JFrame implements Runnable {
    //String DetailedText = "";
    String line="";
    int URLtype;

    public JStoreViewer(int i,String the_file_text){
        this.getContentPane().setBackground( Color.white);
        URLtype=i;
        line=the_file_text;
    }
    public static void main(String args[]) {
        new Thread(new JStoreViewer(1,"")).start();
    }
    public int stopthread(){
        return 0;
    }

    public void run() {
        setBackground(Color.yellow);
        setTitle("JStore Viewer");
        setSize(600,800);
        setLayout(new BorderLayout()); 
        setLocationRelativeTo(null);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);  
        //  add( htmlLabel,BorderLayout.CENTER);
        //add(new TuringHelp(TuringMachine.thefilename),BorderLayout.CENTER);
        add(buildHtmlPane(line),BorderLayout.CENTER);
        setVisible(true);
        pack();

    }
///////////////////////////////////////////////////////

    public  JPanel buildHtmlPane (String s) {
        JEditorPane editorPane = new JEditorPane();
        editorPane.setEditable(false); 
        editorPane.setContentType("text/html;charset=\"UTF-8\"");
        HTMLEditorKit my_kit = new HTMLEditorKit();
        editorPane.setEditorKit(my_kit); 
        my_kit.getStyleSheet().addRule("body {color:#000000; background-color:#ffffff; font-weight: bold; font-family:times; font-size:14px; margin: 4px; }");
        String the_java_file="<html><pre>";
        if (URLtype==1) {

            try {
                InputStream in = getClass().getResourceAsStream("JStoreServletConnect.java");
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
                String the_currentLine="";
                while ((the_currentLine = br.readLine()) !=null) {
                    the_java_file=the_java_file+the_currentLine+"\n";

                }
                the_java_file=the_java_file+"</pre></html>";
                br.close();

            } catch (IOException e) {
                e.printStackTrace();
            }
            editorPane.setText(the_java_file);
        } else {
            editorPane.setText("<html><pre>"+s+"</pre></html>");
        }

        editorPane.setPreferredSize(new Dimension(800, 800));
        editorPane.setVisible(true);
        JScrollPane scrollPane = new JScrollPane(editorPane);
        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); //SETTING SCHEME FOR HORIZONTAL BAR
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        scrollPane.setVisible(true);
        JPanel leftPane = new JPanel(new BorderLayout());
        leftPane.setVisible(true);
        leftPane.add(scrollPane);//, BorderLayout.PAGE_START);
        return leftPane;
    }

}