summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoSmileyElement.java
blob: 8bd303183f0ef967422df36a6fca15ca04aeb457 (plain)
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
69
70
71
72
73
74
75
76
package org.madore.damlengine;

import org.w3c.dom.*;

public final class TodoSmileyElement extends TodoDefaultElement {

    public enum Type {
	SMILE("smile", new String(Character.toChars(0x263A)), "Smile", "Sourire"), 
	WINK("wink", new String(Character.toChars(0x1F609)), "Wink", "Clin d'\u0153il"), 
	SURPRISED("surprised", new String(Character.toChars(0x1F632)), "Surprised", "Surpris"), 
	SAD("sad", new String(Character.toChars(0x2639)), "Sad", "Triste"), 
	COOL("cool", new String(Character.toChars(0x1F60E)), "Cool", "Cool"), 
	BIGGRIN("biggrin", new String(Character.toChars(0x1F601)), "Big grin", "Grand sourire"), 
	CONFUSED("confused", new String(Character.toChars(0x1F615)), "Confused", "Troubl\u00e9"), 
	CRAZY("crazy", new String(Character.toChars(0x1F61D)), "Crazy", "Fou"), 
	NEUTRAL("neutral", new String(Character.toChars(0x1F610)), "Non-grin", "Sans sourire"), 
	TWISTED("twisted", new String(Character.toChars(0x1F621)), "Twisted", "Tordu"), 
	CRY("cry", new String(Character.toChars(0x1F622)), "Crying", "Pleure"), 
	EVIL("evil", new String(Character.toChars(0x1F608)), "Evil", "Mauvais");
	final String emotion;
	final String altText;
	final String enName;
	final String frName;
	Type(String emotion, String altText,
	     String enName, String frName) {
	    this.emotion = emotion;
	    this.altText = altText;
	    this.enName = enName;
	    this.frName = frName;
	}
    }

    public static class Factory extends TodoElement.Factory {
	final Type t;
	public Factory(Type t) {
	    super();
	    this.t = t;
	}
	@Override
	public TodoSmileyElement newItem(Element node,
					 Context ctx,
					 TodoItem caller) {
	    return new TodoSmileyElement(t, node, ctx, caller);
	}
    }

    final Type t;

    public TodoSmileyElement(Type t,
			     Element node,
			     Context ctx,
			     TodoItem caller) {
	super(node, ctx, caller);
	this.t = t;
    }

    @Override
    public void handleNodeOnly() {
	String lang = LangHelper.getLangRec(node);
	Element img = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "img");
	img.setAttributeNS(null, "src",
			   "data:image/png;base64,"
			   + Base64.encode(DamlEngine.class.getResourceAsStream("images/smileys/"+t.emotion+".png")));
	img.setAttributeNS(null, "class",
			   "smiley");
	img.setAttributeNS(null, "alt", t.altText);
	img.setAttributeNS(null, "height", "15");
	img.setAttributeNS(null, "width", "15");
	if ( lang != null && lang.equals("en") )
	    img.setAttributeNS(null, "title", t.enName);
	else if ( lang != null && lang.equals("fr") )
	    img.setAttributeNS(null, "title", t.frName);
	node.getParentNode().replaceChild(img, node);
    }

}