mirror of https://github.com/sipwise/jitsi.git
The following IRC control codes are now supported: * Bold * Italics * Underline * Normal (clears all outstanding codes) * Color (foreground and background) * 16 colors (00 up to and including 15)fix-message-formatting
parent
9241928247
commit
16f5f552d1
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.protocol.irc;
|
||||
|
||||
/**
|
||||
* IRC color codes that can be specified in the color control code.
|
||||
*
|
||||
* @author Danny van Heumen
|
||||
*/
|
||||
public enum Color
|
||||
{
|
||||
WHITE("White"),
|
||||
BLACK("Black"),
|
||||
BLUE("Navy"),
|
||||
GREEN("Green"),
|
||||
RED("Red"),
|
||||
BROWN("Maroon"),
|
||||
PURPLE("Purple"),
|
||||
ORANGE("Orange"),
|
||||
YELLOW("Yellow"),
|
||||
LIGHT_GREEN("Lime"),
|
||||
TEAL("Teal"),
|
||||
LIGHT_CYAN("Cyan"),
|
||||
LIGHT_BLUE("RoyalBlue"),
|
||||
PINK("Fuchsia"),
|
||||
GREY("Grey"),
|
||||
LIGHT_GREY("Silver");
|
||||
|
||||
/**
|
||||
* Instance containing the html representation of this color.
|
||||
*/
|
||||
private String html;
|
||||
|
||||
/**
|
||||
* Constructor for enum entries.
|
||||
*
|
||||
* @param html HTML representation for color
|
||||
*/
|
||||
private Color(String html)
|
||||
{
|
||||
this.html = html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML representation of this color.
|
||||
*
|
||||
* @return returns html representation or null if none exist
|
||||
*/
|
||||
public String getHtml()
|
||||
{
|
||||
return this.html;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.protocol.irc;
|
||||
|
||||
/**
|
||||
* Enum with available IRC control characters.
|
||||
*
|
||||
* @author Danny van Heumen
|
||||
*/
|
||||
public enum ControlChar
|
||||
{
|
||||
BOLD('\u0002', "b"),
|
||||
COLOR('\u0003', "font"),
|
||||
NORMAL('\u000F', null),
|
||||
ITALICS('\u001D', "i"),
|
||||
UNDERLINE('\u001F', "u");
|
||||
|
||||
/**
|
||||
* The IRC control code.
|
||||
*/
|
||||
private char code;
|
||||
|
||||
/**
|
||||
* HTML tag that expresses the specific formatting requirement.
|
||||
*/
|
||||
private String tag;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param code the control code
|
||||
*/
|
||||
private ControlChar(char code, String htmlTag)
|
||||
{
|
||||
this.code = code;
|
||||
this.tag = htmlTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find enum instance by IRC control code.
|
||||
*
|
||||
* @param code IRC control code
|
||||
* @return returns enum instance or null if no instance was found
|
||||
*/
|
||||
public static ControlChar byCode(char code)
|
||||
{
|
||||
for (ControlChar controlChar : values())
|
||||
{
|
||||
if (controlChar.getCode() == code)
|
||||
return controlChar;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the IRC control code.
|
||||
*
|
||||
* @return returns the IRC control code
|
||||
*/
|
||||
public char getCode()
|
||||
{
|
||||
return this.code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML start tag, optionally including extra parameters.
|
||||
*
|
||||
* @param addition optional addition to be included before closing the start
|
||||
* tag
|
||||
* @return returns HTML start tag.
|
||||
*/
|
||||
public String getHtmlStart(String... addition)
|
||||
{
|
||||
StringBuilder tag = new StringBuilder("<" + this.tag);
|
||||
for (String add : addition)
|
||||
{
|
||||
tag.append(" ");
|
||||
tag.append(add);
|
||||
}
|
||||
tag.append('>');
|
||||
return tag.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML end tag.
|
||||
*
|
||||
* @return returns the HTML end tag
|
||||
*/
|
||||
public String getHtmlEnd()
|
||||
{
|
||||
return "</" + this.tag + ">";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.protocol.irc;
|
||||
|
||||
import junit.framework.*;
|
||||
|
||||
/**
|
||||
* @author Danny van Heumen
|
||||
*/
|
||||
public class ColorTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public void testHtmlRepresentation()
|
||||
{
|
||||
Assert.assertEquals("White", Color.WHITE.getHtml());
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.protocol.irc;
|
||||
|
||||
import junit.framework.*;
|
||||
|
||||
/**
|
||||
* @author Danny van Heumen
|
||||
*/
|
||||
public class ControlCharTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testFindByControlCharUnknown()
|
||||
{
|
||||
Assert.assertNull(ControlChar.byCode(' '));
|
||||
}
|
||||
|
||||
public void testFindByControlCharBold()
|
||||
{
|
||||
Assert.assertSame(ControlChar.BOLD, ControlChar.byCode('\u0002'));
|
||||
}
|
||||
|
||||
public void testGetHtmlStartSimple()
|
||||
{
|
||||
Assert.assertEquals("<b>", ControlChar.BOLD.getHtmlStart());
|
||||
}
|
||||
|
||||
public void testGetHtmlStartAdvanced()
|
||||
{
|
||||
Assert.assertEquals("<b bla=\"foo\">",
|
||||
ControlChar.BOLD.getHtmlStart("bla=\"foo\""));
|
||||
}
|
||||
|
||||
public void testGetHtmlEnd()
|
||||
{
|
||||
Assert.assertEquals("</b>", ControlChar.BOLD.getHtmlEnd());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue