Search in sources :

Example 1 with HighlightedTransformedObject

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;
}
Also used : TextController(org.freeplane.features.text.TextController) Quantity(org.freeplane.core.util.Quantity) URI(java.net.URI) HighlightedTransformedObject(org.freeplane.features.text.HighlightedTransformedObject) IAttributeTableModel(org.freeplane.features.attribute.IAttributeTableModel) HighlightedTransformedObject(org.freeplane.features.text.HighlightedTransformedObject) Icon(javax.swing.Icon) Component(java.awt.Component) IconFactory(org.freeplane.features.icon.factory.IconFactory)

Example 2 with HighlightedTransformedObject

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);
}
Also used : HighlightedTransformedObject(org.freeplane.features.text.HighlightedTransformedObject) TextController(org.freeplane.features.text.TextController) HighlightedTransformedObject(org.freeplane.features.text.HighlightedTransformedObject) ModeController(org.freeplane.features.mode.ModeController) Icon(javax.swing.Icon) UIIcon(org.freeplane.features.icon.UIIcon) MindIcon(org.freeplane.features.icon.MindIcon)

Aggregations

Icon (javax.swing.Icon)2 HighlightedTransformedObject (org.freeplane.features.text.HighlightedTransformedObject)2 TextController (org.freeplane.features.text.TextController)2 Component (java.awt.Component)1 URI (java.net.URI)1 Quantity (org.freeplane.core.util.Quantity)1 IAttributeTableModel (org.freeplane.features.attribute.IAttributeTableModel)1 MindIcon (org.freeplane.features.icon.MindIcon)1 UIIcon (org.freeplane.features.icon.UIIcon)1 IconFactory (org.freeplane.features.icon.factory.IconFactory)1 ModeController (org.freeplane.features.mode.ModeController)1