Some fixups, escape colors prior to unescaping.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@1767 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -63,13 +63,16 @@ public class Label implements SwingConstants, LabelStyleConstants
|
|||||||
public static final Pattern COLOR_PATTERN =
|
public static final Pattern COLOR_PATTERN =
|
||||||
Pattern.compile("#([Xx]|[0-9A-Fa-f]{6}+)");
|
Pattern.compile("#([Xx]|[0-9A-Fa-f]{6}+)");
|
||||||
|
|
||||||
|
private static final Pattern ESCAPED_PATTERN =
|
||||||
|
Pattern.compile("#''([Xx]|[0-9A-Fa-f]{6}+)");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter out any color tags from the specified text.
|
* Filter out any color tags from the specified text.
|
||||||
*/
|
*/
|
||||||
public static String filterColors (String txt)
|
public static String filterColors (String txt)
|
||||||
{
|
{
|
||||||
return (txt == null) ? null
|
if (txt == null) return null;
|
||||||
: COLOR_PATTERN.matcher(txt).replaceAll("");
|
return COLOR_PATTERN.matcher(txt).replaceAll("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,13 +81,18 @@ public class Label implements SwingConstants, LabelStyleConstants
|
|||||||
*/
|
*/
|
||||||
public static String escapeColors (String txt)
|
public static String escapeColors (String txt)
|
||||||
{
|
{
|
||||||
StringBuffer buf = new StringBuffer();
|
if (txt == null) return null;
|
||||||
Matcher m = COLOR_PATTERN.matcher(txt);
|
return COLOR_PATTERN.matcher(txt).replaceAll("#''$1");
|
||||||
while (m.find()) {
|
}
|
||||||
m.appendReplacement(buf, "#''" + m.group(1));
|
|
||||||
}
|
/**
|
||||||
m.appendTail(buf);
|
* Un-escape special tags so that they again look correct. Called by
|
||||||
return buf.toString();
|
* rendering components that do not understand the color tags
|
||||||
|
* to filter colors and unescape any escaped colors.
|
||||||
|
*/
|
||||||
|
public static String unescapeColors (String txt)
|
||||||
|
{
|
||||||
|
return unescapeColors(filterColors(txt), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,14 +100,9 @@ public class Label implements SwingConstants, LabelStyleConstants
|
|||||||
*/
|
*/
|
||||||
private static String unescapeColors (String txt, boolean restore)
|
private static String unescapeColors (String txt, boolean restore)
|
||||||
{
|
{
|
||||||
|
if (txt == null) return null;
|
||||||
String prefix = restore ? "#" : "%";
|
String prefix = restore ? "#" : "%";
|
||||||
StringBuffer buf = new StringBuffer();
|
return ESCAPED_PATTERN.matcher(txt).replaceAll(prefix + "$1");
|
||||||
Matcher m = Pattern.compile("#''([Xx]|[0-9A-Fa-f]{6}+)").matcher(txt);
|
|
||||||
while (m.find()) {
|
|
||||||
m.appendReplacement(buf, prefix + m.group(1));
|
|
||||||
}
|
|
||||||
m.appendTail(buf);
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user