Search in sources :

Example 1 with LengthUnits

use of org.freeplane.core.ui.LengthUnits in project freeplane by freeplane.

the class MAttributeController method performSetColumnWidth.

@Override
public void performSetColumnWidth(final NodeAttributeTableModel model, final int col, final Quantity<LengthUnits> width) {
    final Quantity<LengthUnits> oldWidth = model.getLayout().getColumnWidth(col);
    if (width.equals(oldWidth)) {
        return;
    }
    final IActor actor = new SetAttributeColumnWidthActor(col, oldWidth, width, model);
    Controller.getCurrentModeController().execute(actor, model.getNode().getMap());
}
Also used : LengthUnits(org.freeplane.core.ui.LengthUnits) IActor(org.freeplane.core.undo.IActor)

Example 2 with LengthUnits

use of org.freeplane.core.ui.LengthUnits in project freeplane by freeplane.

the class IconController method getStyleIconSize.

private Quantity<LengthUnits> getStyleIconSize(final MapModel map, final Collection<IStyle> styleKeys) {
    final MapStyleModel model = MapStyleModel.getExtension(map);
    for (IStyle styleKey : styleKeys) {
        final NodeModel styleNode = model.getStyleNode(styleKey);
        if (styleNode == null) {
            continue;
        }
        final Quantity<LengthUnits> iconSize = styleNode.getSharedData().getIcons().getIconSize();
        if (iconSize == null) {
            continue;
        }
        return iconSize;
    }
    return DEFAULT_ICON_SIZE;
}
Also used : IStyle(org.freeplane.features.styles.IStyle) NodeModel(org.freeplane.features.map.NodeModel) LengthUnits(org.freeplane.core.ui.LengthUnits) MapStyleModel(org.freeplane.features.styles.MapStyleModel)

Example 3 with LengthUnits

use of org.freeplane.core.ui.LengthUnits in project freeplane by freeplane.

the class NodeStyleBuilder method registerAttributeHandlers.

private void registerAttributeHandlers(final ReadManager reader) {
    final IAttributeHandler colorHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setColor(node, ColorUtils.stringToColor(value, NodeStyleModel.getColor(node)));
        }
    };
    final IAttributeHandler alphaHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setColor(node, ColorUtils.alphaToColor(value, NodeStyleModel.getColor(node)));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "COLOR", colorHandler);
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "ALPHA", alphaHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "COLOR", colorHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "ALPHA", alphaHandler);
    final IAttributeHandler bgHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setBackgroundColor(node, ColorUtils.stringToColor(value, NodeStyleModel.getBackgroundColor(node)));
        }
    };
    final IAttributeHandler bgAlphaHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setBackgroundColor(node, ColorUtils.alphaToColor(value, NodeStyleModel.getBackgroundColor(node)));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BACKGROUND_COLOR", bgHandler);
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BACKGROUND_ALPHA", bgAlphaHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BACKGROUND_COLOR", bgHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BACKGROUND_ALPHA", bgAlphaHandler);
    final IAttributeHandler shapeHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setShape(node, value);
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "STYLE", shapeHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "STYLE", shapeHandler);
    final IAttributeHandler shapeHorizontalMarginHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setShapeHorizontalMargin(node, Quantity.fromString(value, LengthUnits.px));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "SHAPE_HORIZONTAL_MARGIN", shapeHorizontalMarginHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "SHAPE_HORIZONTAL_MARGIN", shapeHorizontalMarginHandler);
    final IAttributeHandler shapeVerticalMarginHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setShapeVerticalMargin(node, Quantity.fromString(value, LengthUnits.px));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "SHAPE_VERTICAL_MARGIN", shapeVerticalMarginHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "SHAPE_VERTICAL_MARGIN", shapeVerticalMarginHandler);
    final IAttributeHandler uniformShapeHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setShapeUniform(node, Boolean.valueOf(value));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "UNIFORM_SHAPE", uniformShapeHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "UNIFORM_SHAPE", uniformShapeHandler);
    reader.addAttributeHandler("font", "SIZE", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final FontProperties fp = (FontProperties) userObject;
            fp.fontSize = Integer.parseInt(value.toString());
        }
    });
    reader.addAttributeHandler("font", "NAME", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final FontProperties fp = (FontProperties) userObject;
            fp.fontName = value;
        }
    });
    reader.addAttributeHandler("font", "BOLD", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final FontProperties fp = (FontProperties) userObject;
            fp.isBold = value.equals("true");
        }
    });
    reader.addAttributeHandler("font", "STRIKETHROUGH", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final FontProperties fp = (FontProperties) userObject;
            fp.isStrikedThrough = value.equals("true");
        }
    });
    reader.addAttributeHandler("font", "ITALIC", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final FontProperties fp = (FontProperties) userObject;
            fp.isItalic = value.equals("true");
        }
    });
    final IAttributeHandler nodenumberingHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setNodeNumbering(node, value.equals("true"));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "NUMBERED", nodenumberingHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "NUMBERED", nodenumberingHandler);
    final IAttributeHandler formatHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setNodeFormat(node, value);
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "FORMAT", formatHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "FORMAT", formatHandler);
    if (FreeplaneVersion.getVersion().isOlderThan(new FreeplaneVersion(1, 3, 0))) {
        // compatibility for a view 1.2.X preview versions - remove after release 1.3
        reader.addAttributeHandler(NodeBuilder.XML_NODE, "TEMPLATE", formatHandler);
        reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "TEMPLATE", formatHandler);
    }
    // save to 1.1: MAX_WIDTH="200" MAX_WIDTH_QUANTITY="200.0 px"
    // save: MAX_WIDTH="200.0 px"
    final IAttributeHandler nodeMaxNodeWidthQuantityHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            Quantity<LengthUnits> width = Quantity.fromString(value, LengthUnits.px);
            NodeSizeModel.setMaxNodeWidth(node, width);
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "MAX_WIDTH_QUANTITY", nodeMaxNodeWidthQuantityHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "MAX_WIDTH_QUANTITY", nodeMaxNodeWidthQuantityHandler);
    final IAttributeHandler nodeMaxNodeWidthHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            if (NodeSizeModel.getMaxNodeWidth(node) == null) {
                nodeMaxNodeWidthQuantityHandler.setAttribute(node, value);
            }
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "MAX_WIDTH", nodeMaxNodeWidthHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "MAX_WIDTH", nodeMaxNodeWidthHandler);
    final IAttributeHandler nodeIconSizeHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            Quantity<LengthUnits> iconSize = Quantity.fromString(value, LengthUnits.px);
            node.getSharedData().getIcons().setIconSize(iconSize);
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "ICON_SIZE", nodeIconSizeHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "ICON_SIZE", nodeIconSizeHandler);
    final IAttributeHandler nodeMinNodeWidthQuantityHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            Quantity<LengthUnits> width = Quantity.fromString(value, LengthUnits.px);
            NodeSizeModel.setNodeMinWidth(node, width);
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "MIN_WIDTH_QUANTITY", nodeMinNodeWidthQuantityHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "MIN_WIDTH_QUANTITY", nodeMinNodeWidthQuantityHandler);
    final IAttributeHandler nodeMinWidthHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            if (NodeSizeModel.getMinNodeWidth(node) == null) {
                nodeMinNodeWidthQuantityHandler.setAttribute(node, value);
            }
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "MIN_WIDTH", nodeMinWidthHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "MIN_WIDTH", nodeMinWidthHandler);
    final IAttributeHandler textAlignHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setHorizontalTextAlignment(node, HorizontalTextAlignment.valueOf(value));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "TEXT_ALIGN", textAlignHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "TEXT_ALIGN", textAlignHandler);
    final IAttributeHandler borderWidthMatchesEdgeWidthHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeBorderModel.setBorderWidthMatchesEdgeWidth(node, Boolean.valueOf(value));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BORDER_WIDTH_LIKE_EDGE", borderWidthMatchesEdgeWidthHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BORDER_WIDTH_LIKE_EDGE", borderWidthMatchesEdgeWidthHandler);
    final IAttributeHandler borderWidthHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeBorderModel.setBorderWidth(node, Quantity.fromString(value, LengthUnits.px));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BORDER_WIDTH", borderWidthHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BORDER_WIDTH", borderWidthHandler);
    final IAttributeHandler borderDashMatchesEdgeDashHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeBorderModel.setBorderDashMatchesEdgeDash(node, Boolean.valueOf(value));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BORDER_DASH_LIKE_EDGE", borderDashMatchesEdgeDashHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BORDER_DASH_LIKE_EDGE", borderDashMatchesEdgeDashHandler);
    final IAttributeHandler borderDashHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeBorderModel.setBorderDash(node, DashVariant.valueOf(value));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BORDER_DASH", borderDashHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BORDER_DASH", borderDashHandler);
    final IAttributeHandler borderColorMatchesEdgeColorHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeBorderModel.setBorderColorMatchesEdgeColor(node, Boolean.valueOf(value));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BORDER_COLOR_LIKE_EDGE", borderColorMatchesEdgeColorHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BORDER_COLOR_LIKE_EDGE", borderColorMatchesEdgeColorHandler);
    final IAttributeHandler borderColorHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeBorderModel.setBorderColor(node, ColorUtils.stringToColor(value, NodeBorderModel.getBorderColor(node)));
        }
    };
    final IAttributeHandler borderColorAlphaHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeBorderModel.setBorderColor(node, ColorUtils.alphaToColor(value, NodeBorderModel.getBorderColor(node)));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BORDER_COLOR", borderColorHandler);
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BORDER_COLOR_ALPHA", borderColorAlphaHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BORDER_COLOR", borderColorHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BORDER_COLOR_ALPHA", borderColorAlphaHandler);
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) LengthUnits(org.freeplane.core.ui.LengthUnits) IAttributeHandler(org.freeplane.core.io.IAttributeHandler) FreeplaneVersion(org.freeplane.core.util.FreeplaneVersion)

Example 4 with LengthUnits

use of org.freeplane.core.ui.LengthUnits in project freeplane by freeplane.

the class NodeStyleController method getStyleMinWidth.

private Quantity<LengthUnits> getStyleMinWidth(final MapModel map, final Collection<IStyle> styleKeys) {
    final MapStyleModel model = MapStyleModel.getExtension(map);
    for (IStyle styleKey : styleKeys) {
        final NodeModel styleNode = model.getStyleNode(styleKey);
        if (styleNode == null) {
            continue;
        }
        final NodeSizeModel sizeModel = NodeSizeModel.getModel(styleNode);
        if (sizeModel == null) {
            continue;
        }
        final Quantity<LengthUnits> minWidth = sizeModel.getMinNodeWidth();
        if (minWidth == null) {
            continue;
        }
        return minWidth;
    }
    return DEFAULT_MINIMUM_WIDTH;
}
Also used : IStyle(org.freeplane.features.styles.IStyle) NodeModel(org.freeplane.features.map.NodeModel) LengthUnits(org.freeplane.core.ui.LengthUnits) MapStyleModel(org.freeplane.features.styles.MapStyleModel)

Example 5 with LengthUnits

use of org.freeplane.core.ui.LengthUnits in project freeplane by freeplane.

the class NodeStyleController method getMaxWidth.

public Quantity<LengthUnits> getMaxWidth(NodeModel node) {
    final MapModel map = node.getMap();
    final LogicalStyleController styleController = LogicalStyleController.getController(modeController);
    final Collection<IStyle> style = styleController.getStyles(node);
    final Quantity<LengthUnits> maxTextWidth = getMaxNodeWidth(map, style);
    return maxTextWidth;
}
Also used : IStyle(org.freeplane.features.styles.IStyle) LengthUnits(org.freeplane.core.ui.LengthUnits) LogicalStyleController(org.freeplane.features.styles.LogicalStyleController) MapModel(org.freeplane.features.map.MapModel)

Aggregations

LengthUnits (org.freeplane.core.ui.LengthUnits)30 NodeModel (org.freeplane.features.map.NodeModel)10 IStyle (org.freeplane.features.styles.IStyle)9 BooleanProperty (org.freeplane.core.resources.components.BooleanProperty)6 MapModel (org.freeplane.features.map.MapModel)5 ModeController (org.freeplane.features.mode.ModeController)5 MapStyleModel (org.freeplane.features.styles.MapStyleModel)5 IActor (org.freeplane.core.undo.IActor)4 MapController (org.freeplane.features.map.MapController)4 LogicalStyleController (org.freeplane.features.styles.LogicalStyleController)4 Color (java.awt.Color)2 Icon (javax.swing.Icon)2 IconController (org.freeplane.features.icon.IconController)2 IconFactory (org.freeplane.features.icon.factory.IconFactory)2 MLocationController (org.freeplane.features.nodelocation.mindmapmode.MLocationController)2 NodeSizeModel (org.freeplane.features.nodestyle.NodeSizeModel)2 Shape (org.freeplane.features.nodestyle.NodeStyleModel.Shape)2 MTextController (org.freeplane.features.text.mindmapmode.MTextController)2 MainView (org.freeplane.view.swing.map.MainView)2 NodeView (org.freeplane.view.swing.map.NodeView)2