1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| public class BalloonMessageRenderer extends JLabel implements ListCellRenderer {
TchatConfig _config = null;
@Override
public Component getListCellRendererComponent(JList list, Object obj, int index, boolean isSelected, boolean cellHasFocus) {
Message curMsg = (Message) obj;
_config = TchatConfigBuilder.getInstance().getTchatConfig(curMsg.getThreadId());
Balloon balloon = new Balloon(curMsg, list.getWidth);
if (balloon != null && balloon.getImage() != null) {
setIcon(new ImageIcon(balloon.getImage()));
setSmsPosition(curMsg.isEmmit());
setFont(_config.getDateFont());
setForeground(_config.getDateColor());
setTextDate(index, list, curMsg);
setOpaque(false);
}
return this;
}}
public class Balloon extends MessageDrawer {
private void buildSmsBalloon() throws IOException {
String body = ((Sms) _msg).getBody();
int column = getColumn(body, _widthDefault);
int row = getRow(((Sms) _msg).getBody(), column);
int height = _metrics.getHeight();
if(row == 1 && height < 20){
}else{
row = (row * height) - 14;
}
//Redimensionne une bulle au dimension demandé
balloonBuilder(row, column);
//Dessine le texte sur la nouvelle image
writeString(((Sms) _msg).getBody(), getXBorder(), 3, _config.getBodyFont());
addIconProperties();
}
}
public class MessageDrawer extends JLabel {
protected void writeString(String text, int xStart, int yStart, Font font) {
Graphics2D graf = _image.createGraphics();
graf.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graf.setColor(_config.getBodyColor());
graf.setFont(font);
//cas où le texte du sms tiens sur plusieurs lignes
if (getLenghtMsg(text) > _image.getWidth() - spaceBorder) {
String stringTmp = text.trim();
for (int i = 1; stringTmp.length() > 0; i++) {
//Determine la chaine de caractere adapter à la largeur de la bulle
String newString = StringUtil.cutter(stringTmp, _image.getWidth() - spaceBorder, _metrics);
//Dessine le texte sur la bulle
graf = drawMessage(graf, newString, xStart, (((_metrics.getHeight()) * i) + yStart));
if (newString.length() > 0) {
if (!newString.endsWith("-")) {
stringTmp = stringTmp.substring(newString.length()).trim();
} else {
stringTmp = stringTmp.substring(newString.length() - 1);
}
}
}
} else {
graf = drawMessage(graf, text, xStart, _metrics.getHeight() + yStart);
}
//graf.dispose();
}
} |