Applied style fixes.

fix-message-formatting
Danny van Heumen 11 years ago
parent 02e9304973
commit c878830f7b

@ -4,8 +4,8 @@
/**
* IRC contact implementation.
*
* @author danny
*
* @author Danny van Heumen
*/
public class ContactIrcImpl
extends AbstractContact
@ -14,7 +14,7 @@ public class ContactIrcImpl
* Parent provider.
*/
private ProtocolProviderServiceIrcImpl provider;
/**
* Contact id.
*/
@ -32,21 +32,28 @@ public class ContactIrcImpl
/**
* Constructor.
*
*
* @param provider Protocol provider service instance.
* @param id Contact id.
* @param parentGroup The parent group of the contact.
*/
public ContactIrcImpl(ProtocolProviderServiceIrcImpl provider, String id,
ContactGroupIrcImpl parentGroup, PresenceStatus initialStatus)
{
if (provider == null)
{
throw new IllegalArgumentException("provider cannot be null");
}
this.provider = provider;
if (id == null)
{
throw new IllegalArgumentException("id cannot be null");
}
this.id = id;
if (parentGroup == null)
{
throw new IllegalArgumentException("parentGroup cannot be null");
}
this.parentGroup = parentGroup;
this.presence =
initialStatus == null ? IrcStatusEnum.ONLINE : initialStatus;
@ -54,7 +61,7 @@ public ContactIrcImpl(ProtocolProviderServiceIrcImpl provider, String id,
/**
* Get contact id (a.k.a. address)
*
*
* @return returns id
*/
@Override
@ -65,7 +72,7 @@ public String getAddress()
/**
* Get contact display name.
*
*
* @return returns display name
*/
@Override
@ -75,8 +82,8 @@ public String getDisplayName()
}
/**
* Get contact image (avatar)
*
* Get contact image (avatar).
*
* @return returns image data
*/
@Override
@ -87,7 +94,7 @@ public byte[] getImage()
/**
* Get presence status.
*
*
* @return returns presence status
*/
@Override
@ -98,19 +105,21 @@ public PresenceStatus getPresenceStatus()
/**
* Set a new presence status for contact.
*
*
* @param status new presence status (cannot be null)
*/
protected void setPresenceStatus(PresenceStatus status)
{
if (status == null)
{
throw new IllegalArgumentException("status cannot be null");
}
this.presence = status;
}
/**
* Get parent contact group.
*
*
* @return returns parent contact group
*/
@Override
@ -121,7 +130,7 @@ public ContactGroup getParentContactGroup()
/**
* Get protocol provider service.
*
*
* @return returns IRC protocol provider service.
*/
@Override
@ -132,7 +141,7 @@ public ProtocolProviderService getProtocolProvider()
/**
* Is persistent contact.
*
*
* @return Returns true if contact is persistent, or false otherwise.
*/
@Override
@ -145,7 +154,7 @@ public boolean isPersistent()
/**
* Is contact resolved.
*
*
* @return Returns true if contact is resolved, or false otherwise.
*/
@Override
@ -160,7 +169,7 @@ public boolean isResolved()
/**
* Get persistent data (if any).
*
*
* @return returns persistent data if available or null otherwise.
*/
@Override
@ -171,7 +180,7 @@ public String getPersistentData()
/**
* Get status message.
*
*
* @return returns status message
*/
@Override

@ -9,16 +9,21 @@
/**
* Some IRC-related utility methods.
*
*
* @author Danny van Heumen
*/
public final class Utils
{
/**
* Logger
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(Utils.class);
/**
* Index indicating the end of the color code.
*/
private static final int INDEX_END_COLOR_CODE = 3;
/**
* Private constructor since we do not need to construct anything.
*/
@ -28,18 +33,20 @@ private Utils()
/**
* Parse IRC text message and process possible control codes.
*
* TODO Support for color 99 (Transparent)
* TODO Support for wrapping around after color 15?
*
*
* TODO Support for color 99 (Transparent) TODO Support for wrapping around
* after color 15?
*
* @param text the message
* @return returns the processed message or null if text message was null,
* since there is nothing to modify there
*/
public static String parse(String text)
public static String parse(final String text)
{
if (text == null)
{
return null;
}
FormattedTextBuilder builder = new FormattedTextBuilder();
for (int i = 0; i < text.length(); i++)
@ -86,9 +93,11 @@ public static String parse(String text)
foreground = parseForegroundColor(text.substring(i + 1));
i += 2;
// FIXME IAE thrown in case of missing background color.
// This should be ignored. It is no error.
// parse background color code
background = parseBackgroundColor(text.substring(i + 1));
i += 3;
i += INDEX_END_COLOR_CODE;
}
catch (IllegalArgumentException e)
{
@ -125,11 +134,11 @@ public static String parse(String text)
/**
* Parse background color code starting with the separator.
*
*
* @param text the text starting with the background color (separator)
* @return returns the background color
*/
private static Color parseBackgroundColor(String text)
private static Color parseBackgroundColor(final String text)
{
try
{
@ -154,23 +163,25 @@ private static Color parseBackgroundColor(String text)
{
// No background color defined, ignoring ...
throw new IllegalArgumentException(
"value isn't a background color code: " + text.substring(1, 3));
"value isn't a background color code: "
+ text.substring(1, INDEX_END_COLOR_CODE));
}
catch (ArrayIndexOutOfBoundsException e)
{
LOGGER.info("Specified IRC color is not a known color code.", e);
throw new IllegalArgumentException("background color value "
+ text.substring(1, 3) + " is not a known color");
+ text.substring(1, INDEX_END_COLOR_CODE)
+ " is not a known color");
}
}
/**
* Parse foreground color and return corresponding Color instance.
*
*
* @param text the text to parse, starting with color code
* @return returns Color instance
*/
private static Color parseForegroundColor(String text)
private static Color parseForegroundColor(final String text)
{
try
{
@ -186,6 +197,8 @@ private static Color parseForegroundColor(String text)
}
catch (NumberFormatException e)
{
// FIXME correctly print out color code (as a number or hex number)
// FIXME wrap around color codes?
// Invalid text color value
LOGGER.trace("Invalid foreground color code encountered.");
throw new IllegalArgumentException(
@ -199,17 +212,37 @@ private static Color parseForegroundColor(String text)
}
}
public static String formatMessage(String message)
/**
* Format message as normal HTML-formatted message.
*
* @param message original IRC message
* @return returns HTML-formatted normal message
*/
public static String formatMessage(final String message)
{
return message;
}
public static String formatNotice(String message, String user)
/**
* Format message as HTML-formatted notice.
*
* @param message original IRC message
* @param user user nick name
* @return returns HTML-formatted notice
*/
public static String formatNotice(final String message, final String user)
{
return "<i>" + user + "</i>: " + message;
}
public static String formatAction(String message, String user)
/**
* Format message as HTML-formatted action.
*
* @param message original IRC message
* @param user user nick name
* @return returns HTML-formatted action
*/
public static String formatAction(final String message, final String user)
{
return "<b>*" + user + "</b> " + message;
}

Loading…
Cancel
Save