Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / src / javajs / swing / JTextPane.java
1 package javajs.swing;
2
3 import javajs.util.SB;
4
5 /**
6  * A simple implementation of a Swing JTextPane. 
7  * Operates as its own Document; no attributes
8  * 
9  * @author hansonr
10  *
11  */
12 public class JTextPane extends JComponent implements Document {
13
14         public JTextPane() {
15                 super("txtJTP");
16                 text = "";
17         }
18         
19         public Document getDocument() {
20                 return this;
21         }
22
23         @Override
24   public void insertString(int i, String s, Object object) {
25                 i = Math.min(i, text.length());
26                 text = text.substring(0, i) + s + text.substring(i);
27         }
28
29         @Override
30         public String toHTML() {
31                 SB sb = new SB();
32                 sb.append("<textarea type=text id='" + id + "' class='JTextPane' style='" + getCSSstyle(98, 98) + "'>"+ text + "</textarea>");
33                 return sb.toString();
34         }
35
36 }