use of org.freeplane.features.text.HighlightedTransformedObject in project freeplane by freeplane.
the class AttributeTableCellRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
final Component rendererComponent = super.getTableCellRendererComponent(table, value, hasFocus, isSelected, row, column);
final AttributeTable attributeTable = (AttributeTable) table;
zoom = attributeTable.getZoom();
final IAttributeTableModel attributeTableModel = (IAttributeTableModel) table.getModel();
final String originalText = value == null ? null : value.toString();
String text = originalText;
Icon icon;
if (column == 1 && value != null) {
try {
// evaluate values only
final TextController textController = TextController.getController();
Object transformedObject = textController.getTransformedObject(value, attributeTableModel.getNode(), null);
text = transformedObject.toString();
if (transformedObject instanceof HighlightedTransformedObject && TextController.isMarkTransformedTextSet()) {
setBorder(BorderFactory.createLineBorder(Color.GREEN));
}
} catch (Exception e) {
text = TextUtils.format("MainView.errorUpdateText", originalText, e.getLocalizedMessage());
setBorder(BorderFactory.createLineBorder(Color.RED));
}
if (value instanceof URI) {
icon = ((AttributeTable) table).getLinkIcon((URI) value);
} else {
icon = null;
}
} else {
icon = null;
}
final Icon scaledIcon;
final IconFactory iconFactory = IconFactory.getInstance();
if (icon != null && iconFactory.canScaleIcon(icon)) {
final int fontSize = getFont().getSize();
scaledIcon = iconFactory.getScaledIcon(icon, new Quantity<LengthUnits>(fontSize, LengthUnits.px));
} else
scaledIcon = icon;
if (scaledIcon != getIcon()) {
setIcon(scaledIcon);
}
setText(text);
if (text != originalText) {
final String toolTip = HtmlUtils.isHtmlNode(originalText) ? text : HtmlUtils.plainToHTML(originalText);
setToolTipText(toolTip);
} else {
final int prefWidth = getPreferredSize().width;
final int width = table.getColumnModel().getColumn(column).getWidth();
if (prefWidth > width) {
final String toolTip = HtmlUtils.isHtmlNode(text) ? text : HtmlUtils.plainToHTML(text);
setToolTipText(toolTip);
} else {
setToolTipText(null);
}
}
setOpaque(hasFocus);
return rendererComponent;
}
use of org.freeplane.features.text.HighlightedTransformedObject in project freeplane by freeplane.
the class MainView method updateText.
public void updateText(NodeModel nodeModel) {
final NodeView nodeView = getNodeView();
if (nodeView == null)
return;
final ModeController modeController = nodeView.getMap().getModeController();
final TextController textController = TextController.getController(modeController);
isShortened = textController.isMinimized(nodeModel);
final Object userObject = nodeModel.getUserObject();
String text;
try {
final Object transformedContent = textController.getTransformedObject(nodeModel);
if (nodeView.isSelected()) {
nodeView.getMap().getModeController().getController().getViewController().addObjectTypeInfo(transformedContent);
}
Icon icon = textController.getIcon(transformedContent, nodeModel, userObject);
putClientProperty(TEXT_RENDERING_ICON, icon);
text = transformedContent.toString();
textModified = transformedContent instanceof HighlightedTransformedObject ? TextModificationState.HIGHLIGHT : TextModificationState.NONE;
} catch (Throwable e) {
LogUtils.warn(e.getMessage(), e);
text = TextUtils.format("MainView.errorUpdateText", String.valueOf(userObject), e.getLocalizedMessage());
textModified = TextModificationState.FAILURE;
}
if (isShortened) {
text = textController.getShortText(text);
}
text = convertTextToHtmlLink(text, nodeModel);
updateText(text);
}
Aggregations