+ /**
+ * If true, the document has been edited.
+ */
+ private boolean dirty = false;
+
+ /**
+ * The default color for the TEditor class.
+ */
+ private CellAttributes defaultColor = null;
+
+ /**
+ * The text highlighter to use.
+ */
+ private Highlighter highlighter = new Highlighter();
+
+ /**
+ * The tab stop size.
+ */
+ private int tabSize = 8;
+
+ /**
+ * If true, backspace at an indent level goes back a full indent level.
+ * If false, backspace always goes back one column.
+ */
+ private boolean backspaceUnindents = false;
+
+ /**
+ * If true, save files with tab characters. If false, convert tabs to
+ * spaces when saving files.
+ */
+ private boolean saveWithTabs = false;
+
+ // ------------------------------------------------------------------------
+ // Constructors -----------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * Construct a new Document from an existing text string.
+ *
+ * @param str the text string
+ * @param defaultColor the color for unhighlighted text
+ */
+ public Document(final String str, final CellAttributes defaultColor) {
+ this.defaultColor = defaultColor;
+
+ // Set colors to resemble the Borland IDE colors, but for Java
+ // language keywords.
+ highlighter.setJavaColors();
+
+ String [] rawLines = str.split("\n");
+ for (int i = 0; i < rawLines.length; i++) {
+ lines.add(new Line(rawLines[i], this.defaultColor, highlighter));
+ }
+ }
+
+ /**
+ * Private constructor used by dup().
+ */
+ private Document() {
+ // NOP
+ }
+
+ // ------------------------------------------------------------------------
+ // Document ---------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * Create a duplicate instance.
+ *
+ * @return duplicate intance
+ */
+ public Document dup() {
+ Document other = new Document();
+ for (Line line: lines) {
+ other.lines.add(line.dup());
+ }
+ other.lineNumber = lineNumber;
+ other.overwrite = overwrite;
+ other.dirty = dirty;
+ other.defaultColor = defaultColor;
+ other.highlighter.setTo(highlighter);
+ return other;
+ }
+