Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/model/StyledStringBuffer.java')
-rw-r--r--plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/model/StyledStringBuffer.java110
1 files changed, 110 insertions, 0 deletions
diff --git a/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/model/StyledStringBuffer.java b/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/model/StyledStringBuffer.java
new file mode 100644
index 000000000..eb0b82526
--- /dev/null
+++ b/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/model/StyledStringBuffer.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.internal.debug.ui.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.swt.graphics.RGB;
+
+class StyledStringBuffer {
+
+ private final StringBuffer bf = new StringBuffer();
+ private final ArrayList<Style> styles = new ArrayList<Style>();
+
+ static class Style {
+ int pos;
+ int len;
+ int font;
+ RGB bg;
+ RGB fg;
+ }
+
+ StyledStringBuffer append(int pos, int font, RGB bg, RGB fg) {
+ Style x = new Style();
+ x.pos = pos;
+ x.len = bf.length() - pos;
+ x.font = font;
+ x.bg = bg;
+ x.fg = fg;
+ styles.add(x);
+ return this;
+ }
+
+ StyledStringBuffer append(String s) {
+ bf.append(s);
+ return this;
+ }
+
+ StyledStringBuffer append(char ch) {
+ bf.append(ch);
+ return this;
+ }
+
+ StyledStringBuffer append(int i) {
+ bf.append(i);
+ return this;
+ }
+
+ StyledStringBuffer append(String s, int font) {
+ Style x = new Style();
+ x.pos = bf.length();
+ x.len = s.length();
+ x.font = font;
+ styles.add(x);
+ bf.append(s);
+ return this;
+ }
+
+ StyledStringBuffer append(String s, int font, RGB bg, RGB fg) {
+ Style x = new Style();
+ x.pos = bf.length();
+ x.len = s.length();
+ x.font = font;
+ x.bg = bg;
+ x.fg = fg;
+ styles.add(x);
+ bf.append(s);
+ return this;
+ }
+
+ StyledStringBuffer append(StyledStringBuffer s) {
+ int offs = bf.length();
+ for (Style y : s.styles) {
+ Style x = new Style();
+ x.pos = y.pos + offs;
+ x.len = y.len;
+ x.font = y.font;
+ x.bg = y.bg;
+ x.fg = y.fg;
+ styles.add(x);
+ }
+ bf.append(s.bf);
+ return this;
+ }
+
+ StringBuffer getStringBuffer() {
+ return bf;
+ }
+
+ Collection<Style> getStyle() {
+ return styles;
+ }
+
+ int length() {
+ return bf.length();
+ }
+
+ @Override
+ public String toString() {
+ return bf.toString();
+ }
+}

Back to the top