use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.
the class MMapMouseListener method mouseClicked.
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && Compat.isCtrlEvent(e)) {
final MapView mapView = (MapView) e.getComponent();
final Object object = mapView.detectCollision(new Point(originX, originY));
if (object != null)
return;
final ModeController modeController = Controller.getCurrentModeController();
final IExtension freeNode = modeController.getExtension(FreeNode.class);
if (freeNode != null && modeController instanceof MModeController) {
final JComponent rootContent = mapView.getRoot().getMainView();
final Point contentPt = new Point();
UITools.convertPointToAncestor(rootContent, contentPt, mapView);
final float zoom = mapView.getZoom();
final Point eventPoint = e.getPoint();
int x = (int) ((eventPoint.x - contentPt.x) / zoom);
final int y = (int) ((eventPoint.y - contentPt.y) / zoom);
final int rootContentNormalWidth = (int) (rootContent.getWidth() / zoom);
final boolean newNodeIsLeft = x < rootContentNormalWidth / 2;
if (newNodeIsLeft) {
x = rootContentNormalWidth - x;
}
final Point pt = new Point(x, y);
((MMapController) modeController.getMapController()).addFreeNode(pt, newNodeIsLeft);
}
} else
super.mouseClicked(e);
}
use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.
the class NodeProxy method appendAsCloneImpl.
private Node appendAsCloneImpl(NodeModel toBeCloned, boolean withSubtree) {
final NodeModel target = getDelegate();
final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
if (toBeCloned.getParentNode() == null || toBeCloned.isRoot())
throw new IllegalArgumentException("can't clone root node or node without parent");
if (!toBeCloned.getMap().equals(getDelegate().getMap()))
throw new IllegalArgumentException("can't clone a node from another map");
if (toBeCloned.subtreeContainsCloneOf(target))
throw new IllegalArgumentException("can't clone a node which has this node as child");
final NodeModel clone = withSubtree ? toBeCloned.cloneTree() : toBeCloned.cloneContent();
mapController.addNewNode(clone, target, target.getChildCount(), target.isNewChildLeft());
return new NodeProxy(clone, getScriptContext());
}
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 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.map.mindmapmode.MMapController in project freeplane by freeplane.
the class MTextController method splitNode.
public void splitNode(final NodeModel node, final int caretPosition, final String newText) {
if (node.isRoot()) {
return;
}
final String oldText = node.getText();
final String futureText = newText != null ? newText : oldText;
final String[] strings = getContent(futureText, caretPosition);
if (strings == null) {
final String mayBePlainText = makePlainIfNoFormattingFound(futureText);
if (!Objects.equals(mayBePlainText, oldText))
setNodeObject(node, mayBePlainText);
return;
}
final String newUpperContent = makePlainIfNoFormattingFound(strings[0]);
final String newLowerContent = makePlainIfNoFormattingFound(strings[1]);
setNodeObject(node, newUpperContent);
final NodeModel parent = node.getParentNode();
final ModeController modeController = Controller.getCurrentModeController();
final NodeModel lowerNode = ((MMapController) modeController.getMapController()).addNewNode(parent, parent.getIndex(node) + 1, node.isLeft());
final MNodeStyleController nodeStyleController = (MNodeStyleController) NodeStyleController.getController();
nodeStyleController.copyStyle(node, lowerNode);
setNodeObject(lowerNode, newLowerContent);
}
use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.
the class MTextController method joinNodes.
public void joinNodes(final List<NodeModel> selectedNodes, final String separator) {
if (selectedNodes.isEmpty())
return;
final NodeModel selectedNode = selectedNodes.get(0);
for (final NodeModel node : selectedNodes) {
if (node != selectedNode && node.subtreeContainsCloneOf(selectedNode)) {
UITools.errorMessage(TextUtils.getText("cannot_move_into_child_node"));
return;
}
}
String joinedContent = "";
final Controller controller = Controller.getCurrentController();
boolean isHtml = false;
final LinkedHashSet<MindIcon> icons = new LinkedHashSet<MindIcon>();
for (final NodeModel node : selectedNodes) {
final String nodeContent = node.getText();
icons.addAll(node.getIcons());
final boolean isHtmlNode = HtmlUtils.isHtmlNode(nodeContent);
joinedContent = addContent(joinedContent, isHtml, nodeContent, isHtmlNode, separator);
if (node != selectedNode) {
final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
mapController.moveNodes(node.getChildren(), selectedNode, selectedNode.getChildCount());
mapController.deleteNode(node);
}
isHtml = isHtml || isHtmlNode;
}
controller.getSelection().selectAsTheOnlyOneSelected(selectedNode);
setNodeText(selectedNode, joinedContent);
final MIconController iconController = (MIconController) IconController.getController();
iconController.removeAllIcons(selectedNode);
for (final MindIcon icon : icons) {
iconController.addIcon(selectedNode, icon);
}
}
Aggregations