use of org.freeplane.features.map.ITooltipProvider in project freeplane by freeplane.
the class ModeController method createToolTip.
public String createToolTip(final NodeModel node, Component view) {
// perhaps we should use the solution presented in the 3rd answer at
// http://stackoverflow.com/questions/3355469/1-pixel-table-border-in-jtextpane-using-html
// html/css example: http://www.wer-weiss-was.de/theme35/article3555660.html
final String style = //
"<style type='text/css'>" + // FIXME: copy from NoteController.setNoteTooltip() ?
" body { font-size: 10pt; }" + "</style>";
final StringBuilder text = new StringBuilder("<html><head>" + style + "</head><body>");
boolean tooltipSet = false;
for (final ITooltipProvider provider : toolTip.values()) {
String value = provider.getTooltip(this, node, view);
if (value == null) {
continue;
}
value = value.replace("<html>", "<div>");
value = value.replaceAll("\\s*</?(body|head)>", "");
value = value.replace("<td>", "<td style='background-color: white'>");
value = value.replace("</html>", "</div>");
if (tooltipSet) {
text.append("<br>");
}
text.append(value);
tooltipSet = true;
}
if (tooltipSet) {
text.append("</body></html>");
// System.err.println("tooltip=" + text);
return text.toString();
}
return null;
}
use of org.freeplane.features.map.ITooltipProvider in project freeplane by freeplane.
the class TextController method registerNodeTextTooltip.
private void registerNodeTextTooltip() {
modeController.addToolTipProvider(NODE_TOOLTIP, new ITooltipProvider() {
public String getTooltip(final ModeController modeController, NodeModel node, Component view) {
if (!ShortenedTextModel.isShortened(node)) {
return null;
}
final NodeStyleController style = (NodeStyleController) modeController.getExtension(NodeStyleController.class);
final Font font = style.getFont(node);
final StringBuilder rule = new StringBuilder();
rule.append("font-family: " + font.getFamily() + ";");
rule.append("font-size: " + font.getSize() + "pt;");
rule.append("margin-top:0;");
if (font.isItalic()) {
rule.append("font-style: italic; ");
}
if (font.isBold()) {
rule.append("font-weight: bold; ");
}
final Color nodeTextColor = view.getForeground();
rule.append("color: ").append(ColorUtils.colorToString(nodeTextColor)).append(";");
final Object data = node.getUserObject();
String text;
try {
text = getTransformedText(data, node, data);
} catch (Exception e) {
text = TextUtils.format("MainView.errorUpdateText", data, e.getLocalizedMessage());
rule.append("color:red;");
}
if (!HtmlUtils.isHtmlNode(text)) {
text = HtmlUtils.plainToHTML(text);
}
final String tooltipText = text.replaceFirst("<body>", "<body><div style=\"" + rule + "\">").replaceFirst("</body>", "</div></body>");
return tooltipText;
}
});
}
Aggregations