source: trunk/src/org/expeditee/items/Tooltip.java@ 1480

Last change on this file since 1480 was 1102, checked in by davidb, 6 years ago

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

  • Property svn:executable set to *
File size: 2.0 KB
Line 
1package org.expeditee.items;
2
3import java.util.Collection;
4import java.util.HashMap;
5import java.util.LinkedList;
6import java.util.List;
7import java.util.Map;
8
9import org.expeditee.settings.templates.TemplateSettings;
10
11/**
12 * TODO: Comment. cts16
13 *
14 * @author cts16
15 */
16public class Tooltip {
17
18 /** TODO: Comment. cts16 */
19 private Map<Text, Item> _tooltipItems = new HashMap<Text, Item>();
20
21 /** TODO: Comment. cts16 */
22 Tooltip()
23 {
24 }
25
26 /** TODO: Comment. cts16 */
27 public Text addTooltip(String content, final Item toItem)
28 {
29 if(content.trim().toLowerCase().startsWith("text") && content.contains(":")) {
30 content = content.substring(content.indexOf(':') + 1);
31 }
32 final Text tooltip = TemplateSettings.TooltipTemplate.get().copy();
33 tooltip.setWidth(Integer.MAX_VALUE); // Tooltip shouldn't be width-limited
34 tooltip.setText(content);
35 return addTooltip(tooltip, toItem);
36 }
37
38 /** TODO: Comment. cts16 */
39 public Text addTooltip(final Text tooltip, final Item toItem)
40 {
41 _tooltipItems.put(tooltip, toItem);
42 return tooltip;
43 }
44
45 /** TODO: Comment. cts16 */
46 public Collection<Text> getTooltips()
47 {
48 return _tooltipItems.keySet();
49 }
50
51 /** TODO: Comment. cts16 */
52 public List<String> asStringList()
53 {
54 final List<String> ret = new LinkedList<String>();
55 for(final Text tooltip: _tooltipItems.keySet()) ret.add(tooltip.getText());
56 return ret;
57 }
58
59 /** TODO: Comment. cts16 */
60 public int getWidth()
61 {
62 int max = 0;
63 for(final Text tooltip: _tooltipItems.keySet()) {
64 if(tooltip.getBoundsWidth() > max) max = tooltip.getBoundsWidth();
65 }
66 return max;
67 }
68
69 /** TODO: Comment. cts16 */
70 public int getHeight()
71 {
72 int max = 0;
73 for(final Text tooltip: _tooltipItems.keySet()) {
74 if(tooltip.getBoundsWidth() > max) max = tooltip.getBoundsHeight();
75 }
76 return max;
77 }
78
79 /** TODO: Comment. cts16 */
80 public int getCollectiveHeight()
81 {
82 int height = 0;
83 for(final Text tooltip: _tooltipItems.keySet()) height += tooltip.getBoundsHeight();
84 return height;
85 }
86}
Note: See TracBrowser for help on using the repository browser.