package thisandthat;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.Document;
import javax.swing.text.EditorKit;
import javax.swing.text.StyledEditorKit;

public class Test extends DefaultStyledDocument {

	/**
	 * UID
	 */
	private static final long serialVersionUID = -6487470088190937699L;

    @Override
	public void insertString(int offset, String str, AttributeSet a)
			throws BadLocationException {
    	System.out.println(a.toString());
    	if(str.charAt(0) == 10) {
    		super.insertString(offset, System.getProperty("line.separator")
    				+ "??-?" + System.getProperty("line.separator"), a);
    	} else {
    		super.insertString(offset, str, a);
    	}
    }

    @Override
	public void remove(int offset, int length) throws BadLocationException {
    	super.remove(offset, length);
    }
    
    public static void main(String a[]) {
    	EditorKit editorKit = new StyledEditorKit() {
    		/**
			 * UID
			 */
			private static final long serialVersionUID = 97277660839524601L;

			@Override
			public Document createDefaultDocument() {
    			return new Test();
    		}
    	};
    	final JEditorPane edit = new JEditorPane();
        edit.setEditorKitForContentType("abc", editorKit);
	    edit.setContentType("abc");
	 
        JFrame frame = new JFrame("Syntax Highlighting");
	    frame.getContentPane().add(new JScrollPane(edit));
	    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    frame.setSize(600, 300);
	    frame.setVisible(true);
	}
}