Search in sources :

Example 1 with IconFactory

use of org.freeplane.features.icon.factory.IconFactory 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 IconFactory

use of org.freeplane.features.icon.factory.IconFactory in project freeplane by freeplane.

the class MenuIconScaling method scaleIcon.

static void scaleIcon(final AbstractButton actionComponent) {
    final Icon icon = actionComponent.getIcon();
    final IconFactory imageIconFactory = IconFactory.getInstance();
    if (icon != null && imageIconFactory.canScaleIcon(icon)) {
        final Font font = actionComponent.getFont();
        final int fontHeight = actionComponent.getFontMetrics(font).getHeight();
        final Quantity<LengthUnits> iconHeight = new Quantity<LengthUnits>(1.2 * fontHeight, LengthUnits.px);
        actionComponent.setIcon(FreeplaneIconFactory.toImageIcon(imageIconFactory.getScaledIcon(icon, iconHeight)));
    }
}
Also used : LengthUnits(org.freeplane.core.ui.LengthUnits) Quantity(org.freeplane.core.util.Quantity) Icon(javax.swing.Icon) Font(java.awt.Font) IconFactory(org.freeplane.features.icon.factory.IconFactory) FreeplaneIconFactory(org.freeplane.core.ui.svgicons.FreeplaneIconFactory)

Example 3 with IconFactory

use of org.freeplane.features.icon.factory.IconFactory in project freeplane by freeplane.

the class TypedListCellRenderer method getListCellRendererComponent.

@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    final Icon icon;
    if (value instanceof String) {
        icon = textIcon;
    } else if (value instanceof FormattedDate) {
        final FormattedDate fd = (FormattedDate) value;
        if (fd.containsTime())
            icon = dateTimeIcon;
        else
            icon = dateIcon;
    } else if (value instanceof URI) {
        icon = linkIcon;
    } else if (value instanceof Number) {
        icon = numberIcon;
    } else if (value instanceof ObjectAndIcon) {
        icon = ((ObjectAndIcon) value).getIcon();
    } else
        icon = null;
    final IconFactory iconFactory = IconFactory.getInstance();
    if (icon != null && iconFactory.canScaleIcon(icon)) {
        final int fontSize = getFont().getSize();
        setIcon(iconFactory.getScaledIcon(icon, new Quantity<LengthUnits>(fontSize, LengthUnits.px)));
    } else
        setIcon(icon);
    return this;
}
Also used : FormattedDate(org.freeplane.features.format.FormattedDate) Quantity(org.freeplane.core.util.Quantity) Icon(javax.swing.Icon) URI(java.net.URI) IconFactory(org.freeplane.features.icon.factory.IconFactory)

Example 4 with IconFactory

use of org.freeplane.features.icon.factory.IconFactory in project freeplane by freeplane.

the class MultipleImage method addLinkIcon.

public void addLinkIcon(Icon icon, NodeModel node) {
    final Quantity<LengthUnits> iconHeight = IconController.getController().getIconSize(node);
    final IconFactory iconFactory = IconFactory.getInstance();
    final Icon scaledIcon = iconFactory.canScaleIcon(icon) ? iconFactory.getScaledIcon(icon, iconHeight) : icon;
    mIcons.add(scaledIcon);
    mUIIcons.add(null);
}
Also used : LengthUnits(org.freeplane.core.ui.LengthUnits) Icon(javax.swing.Icon) UIIcon(org.freeplane.features.icon.UIIcon) IconFactory(org.freeplane.features.icon.factory.IconFactory)

Aggregations

Icon (javax.swing.Icon)4 IconFactory (org.freeplane.features.icon.factory.IconFactory)4 Quantity (org.freeplane.core.util.Quantity)3 URI (java.net.URI)2 LengthUnits (org.freeplane.core.ui.LengthUnits)2 Component (java.awt.Component)1 Font (java.awt.Font)1 FreeplaneIconFactory (org.freeplane.core.ui.svgicons.FreeplaneIconFactory)1 IAttributeTableModel (org.freeplane.features.attribute.IAttributeTableModel)1 FormattedDate (org.freeplane.features.format.FormattedDate)1 UIIcon (org.freeplane.features.icon.UIIcon)1 HighlightedTransformedObject (org.freeplane.features.text.HighlightedTransformedObject)1 TextController (org.freeplane.features.text.TextController)1