+ // ------------------------------------------------------------------------
+ // Constructors -----------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * Construct a new Line from an existing text string, and highlight
+ * certain strings.
+ *
+ * @param str the text string
+ * @param defaultColor the color for unhighlighted text
+ * @param highlighter the highlighter to use
+ */
+ public Line(final String str, final CellAttributes defaultColor,
+ final Highlighter highlighter) {
+
+ this.defaultColor = defaultColor;
+ this.highlighter = highlighter;
+
+ this.rawText = new StringBuilder();
+ int col = 0;
+ for (int i = 0; i < str.length(); i++) {
+ char ch = str.charAt(i);
+ if (ch == '\t') {
+ // Expand tabs
+ int j = col % 8;
+ do {
+ rawText.append(' ');
+ j++;
+ col++;
+ } while ((j % 8) != 0);
+ continue;
+ }
+ if ((ch <= 0x20) || (ch == 0x7F)) {
+ // Replace all other C0 bytes with CP437 glyphs.
+ rawText.append(GraphicsChars.CP437[(int) ch]);
+ col++;
+ continue;
+ }
+
+ rawText.append(ch);
+ col++;
+ }
+
+ scanLine();
+ }
+
+ /**
+ * Construct a new Line from an existing text string.
+ *
+ * @param str the text string
+ * @param defaultColor the color for unhighlighted text
+ */
+ public Line(final String str, final CellAttributes defaultColor) {
+ this(str, defaultColor, null);
+ }
+
+ /**
+ * Private constructor used by dup().
+ */
+ private Line() {
+ // NOP
+ }
+
+ // ------------------------------------------------------------------------
+ // Line -------------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * Create a duplicate instance.
+ *
+ * @return duplicate intance
+ */
+ public Line dup() {
+ Line other = new Line();
+ other.defaultColor = defaultColor;
+ other.highlighter = highlighter;
+ other.position = position;
+ other.screenPosition = screenPosition;
+ other.rawText = new StringBuilder(rawText);
+ other.scanLine();
+ return other;
+ }
+