Search in sources :

Example 1 with StyleTranslatedObject

use of org.freeplane.features.styles.StyleTranslatedObject in project freeplane by freeplane.

the class DeleteUserStyleAction method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    final ModeController modeController = Controller.getCurrentModeController();
    final Controller controller = modeController.getController();
    final NodeModel selected = controller.getSelection().getSelected();
    if (selected.depth() < 2) {
        UITools.errorMessage(TextUtils.getText("can_not_delete_style_group"));
        return;
    }
    final MapModel map = selected.getMap();
    final MapStyleModel styleModel = MapStyleModel.getExtension(map);
    final NodeModel styleNodeGroup = styleModel.getStyleNodeGroup(selected);
    if (!((StyleTranslatedObject) styleNodeGroup.getUserObject()).getObject().equals("styles.user-defined")) {
        UITools.errorMessage(TextUtils.getText("can_not_delete_predefined_style"));
        return;
    }
    final MMapController mapController = (MMapController) modeController.getMapController();
    mapController.deleteNode(selected);
    final IActor actor = new IActor() {

        public void undo() {
            styleModel.addStyleNode(selected);
        }

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

        public void act() {
            styleModel.removeStyleNode(selected);
        }
    };
    Controller.getCurrentModeController().execute(actor, map);
}
Also used : StyleTranslatedObject(org.freeplane.features.styles.StyleTranslatedObject) NodeModel(org.freeplane.features.map.NodeModel) MapStyleModel(org.freeplane.features.styles.MapStyleModel) MMapController(org.freeplane.features.map.mindmapmode.MMapController) IActor(org.freeplane.core.undo.IActor) ModeController(org.freeplane.features.mode.ModeController) MapModel(org.freeplane.features.map.MapModel) MMapController(org.freeplane.features.map.mindmapmode.MMapController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController)

Example 2 with StyleTranslatedObject

use of org.freeplane.features.styles.StyleTranslatedObject in project freeplane by freeplane.

the class NewUserStyleAction method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    final String styleName = JOptionPane.showInputDialog(TextUtils.getText("enter_new_style_name"));
    if (styleName == null) {
        return;
    }
    final Controller controller = Controller.getCurrentController();
    final NodeModel selectedNode = controller.getSelection().getSelected();
    final MapModel map = controller.getMap();
    final MapStyleModel styleModel = MapStyleModel.getExtension(map);
    final MapModel styleMap = styleModel.getStyleMap();
    final IStyle newStyle = StyleFactory.create(styleName);
    if (null != styleModel.getStyleNode(newStyle)) {
        UITools.errorMessage(TextUtils.getText("style_already_exists"));
        return;
    }
    final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
    final NodeModel newNode = new NodeModel(styleMap);
    newNode.setUserObject(newStyle);
    final LogicalStyleController styleController = LogicalStyleController.getController();
    final ArrayList<IStyle> styles = new ArrayList<IStyle>(styleController.getStyles(selectedNode));
    for (int i = styles.size() - 1; i >= 0; i--) {
        IStyle style = styles.get(i);
        if (MapStyleModel.DEFAULT_STYLE.equals(style)) {
            continue;
        }
        final NodeModel styleNode = styleModel.getStyleNode(style);
        if (styleNode == null) {
            continue;
        }
        Controller.getCurrentModeController().copyExtensions(LogicalStyleKeys.NODE_STYLE, styleNode, newNode);
    }
    Controller.getCurrentModeController().copyExtensions(LogicalStyleKeys.NODE_STYLE, selectedNode, newNode);
    Controller.getCurrentModeController().copyExtensions(Keys.ICONS, selectedNode, newNode);
    NodeModel userStyleParentNode = styleModel.getStyleNodeGroup(styleMap, MapStyleModel.STYLES_USER_DEFINED);
    if (userStyleParentNode == null) {
        userStyleParentNode = new NodeModel(styleMap);
        userStyleParentNode.setUserObject(new StyleTranslatedObject(MapStyleModel.STYLES_USER_DEFINED));
        mapController.insertNode(userStyleParentNode, styleMap.getRootNode(), false, false, true);
    }
    mapController.insertNode(newNode, userStyleParentNode, false, false, true);
    mapController.select(newNode);
    final IActor actor = new IActor() {

        public void undo() {
            styleModel.removeStyleNode(newNode);
            styleController.refreshMap(map);
        }

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

        public void act() {
            styleModel.addStyleNode(newNode);
            styleController.refreshMap(map);
        }
    };
    Controller.getCurrentModeController().execute(actor, styleMap);
}
Also used : MapStyleModel(org.freeplane.features.styles.MapStyleModel) MMapController(org.freeplane.features.map.mindmapmode.MMapController) LogicalStyleController(org.freeplane.features.styles.LogicalStyleController) ArrayList(java.util.ArrayList) MapModel(org.freeplane.features.map.MapModel) Controller(org.freeplane.features.mode.Controller) LogicalStyleController(org.freeplane.features.styles.LogicalStyleController) MMapController(org.freeplane.features.map.mindmapmode.MMapController) IStyle(org.freeplane.features.styles.IStyle) StyleTranslatedObject(org.freeplane.features.styles.StyleTranslatedObject) NodeModel(org.freeplane.features.map.NodeModel) IActor(org.freeplane.core.undo.IActor)

Example 3 with StyleTranslatedObject

use of org.freeplane.features.styles.StyleTranslatedObject in project freeplane by freeplane.

the class NodeTextBuilder method writeAttributes.

public void writeAttributes(final ITreeWriter writer, final Object userObject, final String tag) {
    if (!NodeWriter.shouldWriteSharedContent(writer))
        return;
    final NodeModel node = (NodeModel) userObject;
    final Object data = node.getUserObject();
    if (data == null)
        return;
    final Class<? extends Object> dataClass = data.getClass();
    if (dataClass.equals(StyleTranslatedObject.class)) {
        writer.addAttribute(NodeTextBuilder.XML_NODE_LOCALIZED_TEXT, ((StyleTranslatedObject) data).getObject().toString());
        return;
    }
    if (dataClass.equals(TranslatedObject.class)) {
        writer.addAttribute(NodeTextBuilder.XML_NODE_LOCALIZED_TEXT, ((TranslatedObject) data).getObject().toString());
        return;
    }
    final boolean forceFormatting = Boolean.TRUE.equals(writer.getHint(MapWriter.WriterHint.FORCE_FORMATTING));
    if (forceFormatting) {
        final String text = TextController.getController().getTransformedTextNoThrow(data, node, data);
        if (!HtmlUtils.isHtmlNode(text)) {
            writer.addAttribute(NodeTextBuilder.XML_NODE_TEXT, text.replace('\0', ' '));
        } else {
            node.addExtension(new TransformedXMLExtension(text));
        }
    } else {
        final String text = data.toString();
        if (node.getXmlText() == null) {
            writer.addAttribute(NodeTextBuilder.XML_NODE_TEXT, text.replace('\0', ' '));
        }
        if (!(data instanceof String || data instanceof StyleString)) {
            writer.addAttribute(XML_NODE_OBJECT, TypeReference.toSpec(data));
        }
    }
}
Also used : StyleTranslatedObject(org.freeplane.features.styles.StyleTranslatedObject) NodeModel(org.freeplane.features.map.NodeModel) StyleString(org.freeplane.features.styles.StyleString) StyleTranslatedObject(org.freeplane.features.styles.StyleTranslatedObject) TranslatedObject(org.freeplane.core.resources.TranslatedObject) StyleTranslatedObject(org.freeplane.features.styles.StyleTranslatedObject) IFormattedObject(org.freeplane.features.format.IFormattedObject) TranslatedObject(org.freeplane.core.resources.TranslatedObject) StyleString(org.freeplane.features.styles.StyleString)

Example 4 with StyleTranslatedObject

use of org.freeplane.features.styles.StyleTranslatedObject in project freeplane by freeplane.

the class NewUserStyleAction method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    final String styleName = JOptionPane.showInputDialog(TextUtils.getText("enter_new_style_name"));
    if (styleName == null) {
        return;
    }
    final Controller controller = Controller.getCurrentController();
    final NodeModel selectedNode = controller.getSelection().getSelected();
    final MapModel map = controller.getMap();
    final MapStyleModel styleModel = MapStyleModel.getExtension(map);
    final IStyle style = StyleFactory.create(styleName);
    if (null != styleModel.getStyleNode(style)) {
        UITools.errorMessage(TextUtils.getText("style_already_exists"));
        return;
    }
    final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
    final NodeModel newNode = new NodeModel(map);
    newNode.setUserObject(style);
    Controller.getCurrentModeController().copyExtensions(LogicalStyleKeys.NODE_STYLE, selectedNode, newNode);
    Controller.getCurrentModeController().copyExtensions(Keys.ICONS, selectedNode, newNode);
    NodeModel userStyleParentNode = styleModel.getStyleNodeGroup(map, MapStyleModel.STYLES_USER_DEFINED);
    if (userStyleParentNode == null) {
        userStyleParentNode = new NodeModel(map);
        userStyleParentNode.setUserObject(new StyleTranslatedObject(MapStyleModel.STYLES_USER_DEFINED));
        mapController.insertNode(userStyleParentNode, map.getRootNode(), false, false, true);
    }
    mapController.insertNode(newNode, userStyleParentNode, false, false, true);
    mapController.select(newNode);
    final IActor actor = new IActor() {

        public void undo() {
            styleModel.removeStyleNode(newNode);
        }

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

        public void act() {
            styleModel.addStyleNode(newNode);
        }
    };
    Controller.getCurrentModeController().execute(actor, map);
}
Also used : IStyle(org.freeplane.features.styles.IStyle) StyleTranslatedObject(org.freeplane.features.styles.StyleTranslatedObject) NodeModel(org.freeplane.features.map.NodeModel) MapStyleModel(org.freeplane.features.styles.MapStyleModel) MMapController(org.freeplane.features.map.mindmapmode.MMapController) IActor(org.freeplane.core.undo.IActor) MapModel(org.freeplane.features.map.MapModel) Controller(org.freeplane.features.mode.Controller) MMapController(org.freeplane.features.map.mindmapmode.MMapController)

Aggregations

NodeModel (org.freeplane.features.map.NodeModel)4 StyleTranslatedObject (org.freeplane.features.styles.StyleTranslatedObject)4 IActor (org.freeplane.core.undo.IActor)3 MapModel (org.freeplane.features.map.MapModel)3 MMapController (org.freeplane.features.map.mindmapmode.MMapController)3 Controller (org.freeplane.features.mode.Controller)3 MapStyleModel (org.freeplane.features.styles.MapStyleModel)3 IStyle (org.freeplane.features.styles.IStyle)2 ArrayList (java.util.ArrayList)1 TranslatedObject (org.freeplane.core.resources.TranslatedObject)1 IFormattedObject (org.freeplane.features.format.IFormattedObject)1 ModeController (org.freeplane.features.mode.ModeController)1 LogicalStyleController (org.freeplane.features.styles.LogicalStyleController)1 StyleString (org.freeplane.features.styles.StyleString)1