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