Search in sources :

Example 1 with MapReader

use of org.freeplane.features.map.MapReader in project freeplane by freeplane.

the class MapStyleModel method createStyleMap.

void createStyleMap(final MapModel parentMap, MapStyleModel mapStyleModel, final String styleMapStr) {
    final ModeController modeController = Controller.getCurrentModeController();
    MapModel styleMap = new StyleMapModel(parentMap.getIconRegistry(), AttributeRegistry.getRegistry(parentMap));
    styleMap.createNewRoot();
    final MapReader mapReader = modeController.getMapController().getMapReader();
    final Reader styleReader = new StringReader(styleMapStr);
    NodeModel root;
    try {
        Map<Object, Object> hints = new HashMap<Object, Object>();
        hints.put(Hint.MODE, Mode.FILE);
        hints.put(NodeBuilder.FOLDING_LOADED, Boolean.TRUE);
        root = mapReader.createNodeTreeFromXml(styleMap, styleReader, hints);
        NodeStyleModel.setShapeConfiguration(root, ShapeConfigurationModel.NULL_SHAPE.withShape(NodeStyleModel.Shape.oval).withUniform(true));
        NodeStyleModel.createNodeStyleModel(root).setFontSize(24);
        styleMap.setRoot(root);
        final Quantity<LengthUnits> styleBlockGap = ResourceController.getResourceController().getLengthQuantityProperty("style_block_gap");
        LocationModel.createLocationModel(root).setVGap(styleBlockGap);
        insertStyleMap(parentMap, styleMap);
        NodeModel predefinedStyleParentNode = createStyleGroupNode(styleMap, STYLES_PREDEFINED);
        createStyleGroupNode(styleMap, STYLES_USER_DEFINED);
        createStyleGroupNode(styleMap, STYLES_AUTOMATIC_LAYOUT);
        if (styleNodes.get(DEFAULT_STYLE) == null) {
            final NodeModel newNode = new NodeModel(DEFAULT_STYLE, styleMap);
            predefinedStyleParentNode.insert(newNode, 0);
            addStyleNode(newNode);
        }
        NodeModel defaultStyleModel = styleNodes.get(DEFAULT_STYLE);
        if (maxNodeWidth != null && null == NodeSizeModel.getMaxNodeWidth(defaultStyleModel))
            NodeSizeModel.setMaxNodeWidth(defaultStyleModel, maxNodeWidth);
        if (minNodeWidth != null && null == NodeSizeModel.getMinNodeWidth(defaultStyleModel))
            NodeSizeModel.setNodeMinWidth(defaultStyleModel, minNodeWidth);
        if (styleNodes.get(DETAILS_STYLE) == null) {
            final NodeModel newNode = new NodeModel(DETAILS_STYLE, styleMap);
            predefinedStyleParentNode.insert(newNode, 1);
            addStyleNode(newNode);
        }
        if (styleNodes.get(ATTRIBUTE_STYLE) == null) {
            final NodeModel newNode = new NodeModel(ATTRIBUTE_STYLE, styleMap);
            final int defaultFontSize = 9;
            NodeStyleModel.createNodeStyleModel(newNode).setFontSize(defaultFontSize);
            predefinedStyleParentNode.insert(newNode, 2);
            addStyleNode(newNode);
        }
        FontSizeExtension fontSizeExtension = parentMap.getExtension(FontSizeExtension.class);
        if (fontSizeExtension != null) {
            NodeStyleModel.createNodeStyleModel(styleNodes.get(ATTRIBUTE_STYLE)).setFontSize(fontSizeExtension.fontSize);
        }
        if (styleNodes.get(NOTE_STYLE) == null) {
            final NodeModel newNode = new NodeModel(NOTE_STYLE, styleMap);
            NodeStyleModel.createNodeStyleModel(newNode).setBackgroundColor(Color.WHITE);
            predefinedStyleParentNode.insert(newNode, 3);
            addStyleNode(newNode);
        }
        if (styleNodes.get(FLOATING_STYLE) == null) {
            final NodeModel newNode = new NodeModel(FLOATING_STYLE, styleMap);
            EdgeModel.createEdgeModel(newNode).setStyle(EdgeStyle.EDGESTYLE_HIDDEN);
            CloudModel.createModel(newNode).setShape(CloudModel.Shape.ROUND_RECT);
            predefinedStyleParentNode.insert(newNode, 4);
            addStyleNode(newNode);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : LengthUnits(org.freeplane.core.ui.LengthUnits) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Reader(java.io.Reader) StringReader(java.io.StringReader) MapReader(org.freeplane.features.map.MapReader) ModeController(org.freeplane.features.mode.ModeController) MapModel(org.freeplane.features.map.MapModel) Hint(org.freeplane.features.map.MapWriter.Hint) NodeModel(org.freeplane.features.map.NodeModel) MapReader(org.freeplane.features.map.MapReader) StringReader(java.io.StringReader) FontSizeExtension(org.freeplane.features.attribute.FontSizeExtension)

Aggregations

Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LengthUnits (org.freeplane.core.ui.LengthUnits)1 FontSizeExtension (org.freeplane.features.attribute.FontSizeExtension)1 MapModel (org.freeplane.features.map.MapModel)1 MapReader (org.freeplane.features.map.MapReader)1 Hint (org.freeplane.features.map.MapWriter.Hint)1 NodeModel (org.freeplane.features.map.NodeModel)1 ModeController (org.freeplane.features.mode.ModeController)1