Search in sources :

Example 1 with Quantity

use of org.freeplane.core.util.Quantity in project freeplane by freeplane.

the class MIconController method changeIconSize.

public void changeIconSize(final NodeModel node, final Quantity<LengthUnits> iconSize) {
    final IActor actor = new IActor() {

        private Quantity<LengthUnits> oldIconSize;

        public void act() {
            oldIconSize = node.getSharedData().getIcons().getIconSize();
            node.getSharedData().getIcons().setIconSize(iconSize);
            Controller.getCurrentModeController().getMapController().nodeChanged(node, NodeModel.NODE_ICON_SIZE, null, iconSize);
        }

        public String getDescription() {
            return "changeIconSize";
        }

        public void undo() {
            node.getSharedData().getIcons().setIconSize(oldIconSize);
            Controller.getCurrentModeController().getMapController().nodeChanged(node, NodeModel.NODE_ICON_SIZE, oldIconSize, null);
        }
    };
    Controller.getCurrentModeController().execute(actor, node.getMap());
}
Also used : IActor(org.freeplane.core.undo.IActor) Quantity(org.freeplane.core.util.Quantity)

Example 2 with Quantity

use of org.freeplane.core.util.Quantity 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 Quantity

use of org.freeplane.core.util.Quantity in project freeplane by freeplane.

the class QuantityProperty method addChangeListeners.

private void addChangeListeners() {
    numberSpinner.addChangeListener(new ChangeListener() {

        public void stateChanged(final ChangeEvent pE) {
            firePropertyChangeEvent();
        }
    });
    unitBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                final U newUnit = getCurrentUnit();
                double value = (Double) numberSpinner.getValue();
                final Quantity<U> newQuantity = new Quantity<U>(value, currentUnit).in(newUnit);
                currentUnit = newUnit;
                if (value != newQuantity.value)
                    numberSpinner.setValue(newQuantity.value);
                else
                    firePropertyChangeEvent();
            }
        }
    });
}
Also used : ItemEvent(java.awt.event.ItemEvent) ChangeEvent(javax.swing.event.ChangeEvent) Quantity(org.freeplane.core.util.Quantity) ChangeListener(javax.swing.event.ChangeListener) ItemListener(java.awt.event.ItemListener)

Example 4 with Quantity

use of org.freeplane.core.util.Quantity 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)

Aggregations

Quantity (org.freeplane.core.util.Quantity)4 Icon (javax.swing.Icon)2 IconFactory (org.freeplane.features.icon.factory.IconFactory)2 Font (java.awt.Font)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 URI (java.net.URI)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1 LengthUnits (org.freeplane.core.ui.LengthUnits)1 FreeplaneIconFactory (org.freeplane.core.ui.svgicons.FreeplaneIconFactory)1 IActor (org.freeplane.core.undo.IActor)1 FormattedDate (org.freeplane.features.format.FormattedDate)1