package com.lightdev.app.shtm;

import java.io.IOException;
import java.io.StringReader;
import java.util.List;

import javax.swing.event.DocumentListener;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.Highlighter;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyledDocument;

import sml_editor.swingui.EditorMouseListener;

public class SGSHTMLEditorTextPane extends DocumentPane {

	private SHTMLEditorPane editorPane;

	public SGSHTMLEditorTextPane(Object object, Object object2) {
		// TODO Auto-generated constructor stub
		super();
		this.editorPane = super.getEditor();
	}

	// from GSHTMLEditorTextPane.java
	public void addTagList(String string) {
		// TODO Auto-generated method stub
		
	}

	public List<String> getTagNames() {
		// TODO Auto-generated method stub
		return null;
	}

	public void paste(boolean b) {
		// TODO Auto-generated method stub
		
	}

	public void setDocumentListener(DocumentListener docListener) {
		// TODO Auto-generated method stub
		
	}

	public void setMouseListener(EditorMouseListener mouseListener) {
		// TODO Auto-generated method stub
		
	}

	public void updateText() {
		// TODO Auto-generated method stub
		
	}

	public int getCaretPosition() {
		// TODO Auto-generated method stub
		return editorPane.getCaretPosition();
		
	}

	public void setEditorKit(SHTMLEditorKit htmlKit) {
		// TODO Auto-generated method stub
		this.editorPane.setEditorKit(htmlKit);
	}

	public void setText(String source) {
		// TODO Auto-generated method stub
//		super.setDocumentText(source);
		final SHTMLEditorKit kit = (SHTMLEditorKit) editorPane.getEditorKit();
		final SHTMLDocument doc = (SHTMLDocument) kit.createEmptyDocument();

		StringReader in = new StringReader(source);
		try {
			kit.read(in, doc, 0);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (BadLocationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		in.close();
//		doc.addDocumentListener(super);
		super.setDocument(doc);
	}

	public void select(int index, int i) {
		// TODO Auto-generated method stub
		this.editorPane.select(index, i);
	}

	public void replaceSelection(String queryReplacePaneText) {
		// TODO Auto-generated method stub
		this.editorPane.replaceSelection(queryReplacePaneText);
	}

	public String getText() {
		// TODO Auto-generated method stub
		return this.editorPane.getText();
	}

	public void copy() {
		// TODO Auto-generated method stub
		this.editorPane.copy();
	}

	public void cut() {
		// TODO Auto-generated method stub
		this.editorPane.cut();
	}

	public void setCaretPosition(int index) {
		// TODO Auto-generated method stub
		this.editorPane.setCaretPosition(index);
	}

	public Highlighter getHighlighter() {
		// TODO Auto-generated method stub
		return this.editorPane.getHighlighter();
	}

	public int getSelectionStart() {
		// TODO Auto-generated method stub
		return this.editorPane.getSelectionStart();
	}

	public int getSelectionEnd() {
		// TODO Auto-generated method stub
		return this.editorPane.getSelectionEnd();
	}

	public StyledDocument getStyledDocument() { // JTextPane
		// TODO Auto-generated method stub
		return null;
	}

	public String getText(int left, int i) throws BadLocationException {
		// TODO Auto-generated method stub
		return this.editorPane.getText(left, i);
	}

	public void setEditable(boolean b) {
		// TODO Auto-generated method stub
		this.setEditable(b);
	}

	public void setSelectionStart(int start) {
		// TODO Auto-generated method stub
		this.setSelectionStart(start);
	}

	public void setSelectionEnd(int end) {
		// TODO Auto-generated method stub
		this.setSelectionEnd(end);
	}

	public AttributeSet getCharacterAttributes() {
		// TODO Auto-generated method stub
		return this.getCharacterAttributes();
	}

	public void setCharacterAttributes(SimpleAttributeSet sasText, boolean b) {
		// TODO Auto-generated method stub
		this.setCharacterAttributes(sasText, b);
	}

}
