
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.text.Document;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;

public class CSSNamedColorTest{
  public static void main(String[] args){
    new CSSNamedColorTest();
  }
  
  public CSSNamedColorTest(){
    SwingUtilities.invokeLater(new Runnable(){
      public void run(){
        JEditorPane jEditorPane = new JEditorPane();
        jEditorPane.setEditable(false);
        JScrollPane scrollPane = new JScrollPane(jEditorPane);
        HTMLEditorKit kit = new HTMLEditorKit();
        jEditorPane.setEditorKit(kit);
        StyleSheet styleSheet = kit.getStyleSheet();
        styleSheet.addRule("body {color: #000; font-family:times; margin: 4px; }");
        styleSheet.addRule("#rgb {color: Cyan; font-family:times; margin: 4px; }");
        styleSheet.addRule("#nam {color: #00ffff;}");
        styleSheet.addRule("pre {font : 10px monaco; color : black; background-color : #fafafa; }");
        String htmlString = "<html>"
        		+ "<body>"
        		+ "<h1 id=\"rgb\">Welcome ! using named cyan color</h1>"
        		+ "<h1 id=\"nam\">Welcome with hex cyan coded</h2>"
        		+ "<p>The two lines must have the same color.</p>"
        		+ "<p>First Welcome in black means that the named color is not implemented.</p>"
        		+ "</body>"
        		+ "</html>";
        Document doc = kit.createDefaultDocument();
        jEditorPane.setDocument(doc);
        jEditorPane.setText(htmlString);
        JFrame jf = new JFrame("CSS named colors Test");
        jf.getContentPane().add(scrollPane, BorderLayout.CENTER);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setSize(new Dimension(600,400));
        jf.setLocationRelativeTo(null);
        jf.setVisible(true);
      }
    });
  }
} 