use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.
the class SplitNode method splitNode.
private void splitNode(final NodeModel node) {
if (node.isRoot()) {
return;
}
final String text = node.getText();
final String[] parts = splitNode(text);
if (parts == null || parts.length == 1) {
return;
}
final ModeController c = Controller.getCurrentModeController();
int firstPartNumber = 0;
while (parts[firstPartNumber] == null) {
firstPartNumber++;
}
((MTextController) TextController.getController()).setNodeText(node, parts[firstPartNumber]);
final NodeModel parent = node.getParentNode();
final int nodePosition = parent.getIndex(node) + 1;
for (int i = parts.length - 1; i > firstPartNumber; i--) {
final MMapController mapController = (MMapController) c.getMapController();
final String part = parts[i];
if (part == null) {
continue;
}
final NodeModel lowerNode = mapController.addNewNode(parent, nodePosition, node.isLeft());
((MTextController) TextController.getController()).setNodeText(lowerNode, part);
final MNodeStyleController nodeStyleController = (MNodeStyleController) NodeStyleController.getController();
nodeStyleController.copyStyle(node, lowerNode);
mapController.setFolded(lowerNode, !lowerNode.isFolded());
}
}
use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.
the class SplitToWordsAction method actionPerformed.
@Override
protected void actionPerformed(ActionEvent e, NodeModel node) {
final ModeController modeController = Controller.getCurrentModeController();
MTextController textController = (MTextController) modeController.getExtension(TextController.class);
final MMapController mapController = (MMapController) modeController.getMapController();
String details;
try {
details = textController.getTransformedObject(node).toString();
} catch (TransformationException e1) {
return;
}
String plainText = HtmlUtils.htmlToPlain(details).trim();
int nodeCountInLine;
boolean newNode;
if (leaveOriginalNodeEmpty) {
nodeCountInLine = 0;
newNode = true;
textController.setNodeText(node, "");
} else {
nodeCountInLine = -1;
newNode = false;
}
NodeModel currentNode = node;
final Matcher matcher = compiledWordPattern.matcher(plainText);
while (matcher.find()) {
String word = matcher.group();
final String currentText;
if (newNode) {
if (nodeCountInLine == nodeNumberInLine) {
nodeCountInLine = 0;
currentNode = node;
}
currentNode = mapController.addNewNode(currentNode, currentNode.getChildCount(), currentNode.isLeft());
nodeCountInLine++;
currentText = "";
} else if (nodeCountInLine == -1) {
nodeCountInLine = 0;
currentNode = node;
currentText = "";
} else
currentText = currentNode.getText() + ' ';
boolean auxiliaryWord = auxiliaryWords.contains(word.toLowerCase());
if (!auxiliaryWord) {
textController.setNodeText(currentNode, currentText + capitalize(word));
newNode = true;
} else {
textController.setNodeText(currentNode, currentText + word);
newNode = false;
}
}
if (saveOriginalTextAsDetails) {
textController.setDetails(currentNode, HtmlUtils.isHtmlNode(details) ? details : HtmlUtils.plainToHTML(details));
textController.setIsMinimized(currentNode, true);
}
}
use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.
the class OnlineDocumentationAction method actionPerformed.
public void actionPerformed(final ActionEvent event) {
try {
final URL url = new URL(nodeAndMapReference.getMapReference());
if (url == null)
return;
UITools.executeWhenNodeHasFocus(new Runnable() {
@Override
public void run() {
try {
if (nodeAndMapReference.hasFreeplaneFileExtension()) {
Controller.getCurrentController().selectMode(MModeController.MODENAME);
MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
mapController.newDocumentationMap(url);
if (nodeAndMapReference.hasNodeReference())
mapController.select(nodeAndMapReference.getNodeReference());
} else {
Controller.getCurrentController().getViewController().openDocument(url);
}
} catch (final Exception e1) {
LogUtils.severe(e1);
}
}
});
} catch (MalformedURLException ex) {
ex.printStackTrace();
}
}
use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.
the class NewLevelStyleAction method actionPerformed.
public void actionPerformed(final ActionEvent e) {
final MapModel map = Controller.getCurrentController().getMap();
final MapStyleModel styleModel = MapStyleModel.getExtension(map);
NodeModel levelStyleParentNode = styleModel.getStyleNodeGroup(map, MapStyleModel.STYLES_AUTOMATIC_LAYOUT);
final String styleName = "AutomaticLayout.level," + levelStyleParentNode.getChildCount();
final IStyle styleObject = StyleFactory.create(TranslatedObject.format(styleName));
final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
final NodeModel node = new NodeModel(map);
node.setUserObject(styleObject);
mapController.insertNode(node, levelStyleParentNode, false, false, true);
mapController.select(node);
final IActor actor = new IActor() {
public void undo() {
styleModel.removeStyleNode(node);
}
public String getDescription() {
return "NewLevelStyle";
}
public void act() {
styleModel.addStyleNode(node);
}
};
Controller.getCurrentModeController().execute(actor, map);
}
use of org.freeplane.features.map.mindmapmode.MMapController 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