aboutsummaryrefslogtreecommitdiff
path: root/engine/src/core/com/jme3/font/ColorTags.java
diff options
context:
space:
mode:
authorScott Barta <sbarta@google.com>2012-03-01 12:35:35 -0800
committerScott Barta <sbarta@google.com>2012-03-01 12:40:08 -0800
commit59b2e6871c65f58fdad78cd7229c292f6a177578 (patch)
tree2d4e7bfc05b93f40b34675d77e403dd1c25efafd /engine/src/core/com/jme3/font/ColorTags.java
parentf9b30489e75ac1eabc365064959804e99534f7ab (diff)
downloadjmonkeyengine-59b2e6871c65f58fdad78cd7229c292f6a177578.tar.gz
Adds the jMonkeyEngine library to the build.
Adds the jMonkeyEngine open source 3D game engine to the build. This is built as a static library and is only used by the Finsky client. Change-Id: I06a3f054df7b8a67757267d884854f70c5a16ca0
Diffstat (limited to 'engine/src/core/com/jme3/font/ColorTags.java')
-rw-r--r--engine/src/core/com/jme3/font/ColorTags.java91
1 files changed, 91 insertions, 0 deletions
diff --git a/engine/src/core/com/jme3/font/ColorTags.java b/engine/src/core/com/jme3/font/ColorTags.java
new file mode 100644
index 0000000..01f15c3
--- /dev/null
+++ b/engine/src/core/com/jme3/font/ColorTags.java
@@ -0,0 +1,91 @@
+package com.jme3.font;
+
+import com.jme3.math.ColorRGBA;
+import java.util.LinkedList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Contains the color information tagged in a text string
+ * Format: \#rgb#
+ * \#rgba#
+ * \#rrggbb#
+ * \#rrggbbaa#
+ * @author YongHoon
+ */
+class ColorTags {
+ private static final Pattern colorPattern = Pattern.compile("\\\\#([0-9a-fA-F]{8})#|\\\\#([0-9a-fA-F]{6})#|" +
+ "\\\\#([0-9a-fA-F]{4})#|\\\\#([0-9a-fA-F]{3})#");
+ private LinkedList<Range> colors = new LinkedList<Range>();
+ private String text;
+
+ ColorTags() { }
+
+ ColorTags(String seq) {
+ setText(seq);
+ }
+
+ /**
+ * @return text without color tags
+ */
+ String getPlainText() {
+ return text;
+ }
+
+ LinkedList<Range> getTags() {
+ return colors;
+ }
+
+ void setText(final String charSeq) {
+ colors.clear();
+ if (charSeq == null) {
+ return;
+ }
+ Matcher m = colorPattern.matcher(charSeq);
+ if (m.find()) {
+ StringBuilder builder = new StringBuilder(charSeq.length()-7);
+ int startIndex = 0;
+ do {
+ String colorStr = null;
+ for (int i = 1; i <= 4 && colorStr==null; i++) {
+ colorStr = m.group(i);
+ }
+ builder.append(charSeq.subSequence(startIndex, m.start()));
+ Range range = new Range(builder.length(), colorStr);
+ startIndex = m.end();
+ colors.add(range);
+ } while (m.find());
+ builder.append(charSeq.subSequence(startIndex, charSeq.length()));
+ text = builder.toString();
+ } else {
+ text = charSeq;
+ }
+ }
+
+ class Range {
+ int start;
+ ColorRGBA color;
+ Range(int start, String colorStr) {
+ this.start = start;
+ this.color = new ColorRGBA();
+ if (colorStr.length() >= 6) {
+ color.set(Integer.parseInt(colorStr.subSequence(0,2).toString(), 16) / 255f,
+ Integer.parseInt(colorStr.subSequence(2,4).toString(), 16) / 255f,
+ Integer.parseInt(colorStr.subSequence(4,6).toString(), 16) / 255f,
+ 1);
+ if (colorStr.length() == 8) {
+ color.a = Integer.parseInt(colorStr.subSequence(6,8).toString(), 16) / 255f;
+ }
+ } else {
+ color.set(Integer.parseInt(Character.toString(colorStr.charAt(0)), 16) / 15f,
+ Integer.parseInt(Character.toString(colorStr.charAt(1)), 16) / 15f,
+ Integer.parseInt(Character.toString(colorStr.charAt(2)), 16) / 15f,
+ 1);
+ if (colorStr.length() == 4) {
+ color.a = Integer.parseInt(Character.toString(colorStr.charAt(3)), 16) / 15f;
+ }
+ }
+
+ }
+ }
+}