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);
}
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);
}
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));
}
}
}
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);
}
Aggregations