1 | package org.expeditee.items;
|
---|
2 |
|
---|
3 | import java.util.Collection;
|
---|
4 | import java.util.HashMap;
|
---|
5 | import java.util.LinkedList;
|
---|
6 | import java.util.List;
|
---|
7 | import java.util.Map;
|
---|
8 |
|
---|
9 | import org.expeditee.settings.templates.TemplateSettings;
|
---|
10 |
|
---|
11 | public class Tooltip {
|
---|
12 |
|
---|
13 | Tooltip() { }
|
---|
14 |
|
---|
15 | private Map<Text, Item> tooltipItems = new HashMap<Text, Item>();
|
---|
16 |
|
---|
17 | public Text addTooltip(String content, final Item toItem) {
|
---|
18 | if(content.trim().toLowerCase().startsWith("text") && content.contains(":"))
|
---|
19 | content = content.substring(content.indexOf(':') + 1);
|
---|
20 | final Text tooltip = TemplateSettings.TooltipTemplate.get().copy();
|
---|
21 | tooltip.setText(content);
|
---|
22 | return addTooltip(tooltip, toItem);
|
---|
23 | }
|
---|
24 |
|
---|
25 | public Text addTooltip(final Text tooltip, final Item toItem) {
|
---|
26 | tooltipItems.put(tooltip, toItem);
|
---|
27 | return tooltip;
|
---|
28 | }
|
---|
29 |
|
---|
30 | public Collection<Text> getTooltips() { return tooltipItems.keySet(); }
|
---|
31 |
|
---|
32 | public List<String> asStringList() {
|
---|
33 | final List<String> ret = new LinkedList<String>();
|
---|
34 | for(final Text tooltip: tooltipItems.keySet()) ret.add(tooltip.getText());
|
---|
35 | return ret;
|
---|
36 | }
|
---|
37 |
|
---|
38 | public int getWidth() {
|
---|
39 | int max = 0;
|
---|
40 | for(final Text tooltip: tooltipItems.keySet())
|
---|
41 | if(tooltip.getBoundsWidth() > max) max = tooltip.getBoundsWidth();
|
---|
42 | return max;
|
---|
43 | }
|
---|
44 |
|
---|
45 | public int getHeight() {
|
---|
46 | int max = 0;
|
---|
47 | for(final Text tooltip: tooltipItems.keySet())
|
---|
48 | if(tooltip.getBoundsWidth() > max) max = tooltip.getBoundsHeight();
|
---|
49 | return max;
|
---|
50 | }
|
---|
51 |
|
---|
52 | public int getCollectiveHeight() {
|
---|
53 | int height = 0;
|
---|
54 | for(final Text tooltip: tooltipItems.keySet()) height += tooltip.getBoundsHeight();
|
---|
55 | return height;
|
---|
56 | }
|
---|
57 | }
|
---|