hello,
please before you all sigh adn start ranting 'search forums first!!' let me just be clear..

ive search the forums, and google and any other place icould imagin finding java code, and although ive found many similar examples i cant find a way that i can integrate such techniques as styledDocuments and such to my specific problem.

im creating an IM for an intranet, i type text into one JTextArea, and when i click send i have the text sent over teh network and appear on the JEditorPane, but i need certain strings replaced by an emoticon, much like every other IM.

below i will post the code im using to parse the code to html formatted code and if someone could please help me integrate a way to replace certaing strings with images BY RELATIVE PATHS!!!

Code:
/**
*ThismethodinitializestxtConv
*
*@returnjavax.swing.JEditorPane
*/
private JEditorPane getTxtConv() {
if (txtConv == null) {
txtConv = new JEditorPane();
txtConv.setContentType("text/html");
txtConv.setPreferredSize(new Dimension(344, 346));
//txtConv.setText("<html><body><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>Start Conversation<br><br></td></tr></table></body></html>");
txtConv.setToolTipText("<html>Messages that have been send and <br>received.</html>");
txtConv.setEditable(false);
}
returntxtConv;
}
...
/**
*ThismethodinitializestheEmoticonHashMap
*
*@returnvoid
*/
privatevoid initializeEmoticons()
{
Emoticons = new HashMap<String, String>();
Emoticons.put(":p", "/gui/smileys/cheeky.png");
Emoticons.put(":P", "/gui/smileys/cheeky.png");
Emoticons.put(":)", "/gui/smileys/happy.png");
Emoticons.put(":(", "/gui/smileys/sad.png");
Emoticons.put(":$", "/gui/smileys/blush.png");
Emoticons.put(":s", "/gui/smileys/confused.png");
Emoticons.put(":S", "/gui/smileys/confused.png");
Emoticons.put(":'(", "/gui/smileys/crying.gif");
}
...
/**
*
*@params-unformattedstring
*@paramtype-0->fromme,1->fromother
*/
publicvoid addMessage(String s, int type)
{
String[] body;
String[] conv =
this.getTxtConv().getText().split("</body>");
String displayName =
"";
if(type == 0)
{
body = s.split(
"\r\n");
displayName =
this.contacts[0].getDisplayName();
}
else
{
String[] parts = s.split(
"\r\n\r\n");
String[] headers = parts[0].split(
"\r\n");
body = parts[1].split(
"\r\n");
displayName = (headers[0].substring(headers[0].indexOf(
" ", 5), headers[0].lastIndexOf(" "))).replace("%20", " ");
}
conv[0] +=
"<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td colspan=\"2\">"
+ displayName +
" says:</td></tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td width=\"100%\">";
for(int i = 0; i < body.length; i++)
{
Object[] EmoticonSet =
Emoticons.keySet().toArray();
for(int j = 0; j < EmoticonSet.length; j++)
{
if(body[i].contains(EmoticonSet[j].toString()))
{
// some how replace string with image
}
}
if(i == 0)
{
conv[0] += body[i];
}
else
{
conv[0] +=
"<br>" + body[i];
}
}
this.getTxtConv().setText(conv[0] + "</td></tr></table></body>" + conv[1]);
}
an example of a String to be formatted is:
header line 1\r\n
header line 2\r\n
\r\n
body line 1\r\n
body line 2 ... :P...\r\n
body line 3