Search in sources :

Example 21 with MTextController

use of org.freeplane.features.text.mindmapmode.MTextController in project freeplane by freeplane.

the class ImportFolderStructureAction method addNode.

/**
 */
private NodeModel addNode(final NodeModel target, final String nodeContent, final String link) {
    final NodeModel node = ((MMapController) Controller.getCurrentModeController().getMapController()).addNewNode(target, target.getChildCount(), target.isNewChildLeft());
    ((MTextController) TextController.getController()).setNodeText(node, nodeContent);
    ((MLinkController) LinkController.getController()).setLink(node, link, LinkController.LINK_ABSOLUTE);
    return node;
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) MMapController(org.freeplane.features.map.mindmapmode.MMapController) MTextController(org.freeplane.features.text.mindmapmode.MTextController)

Example 22 with MTextController

use of org.freeplane.features.text.mindmapmode.MTextController in project freeplane by freeplane.

the class ExportBranchAction method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    final NodeModel existingNode = Controller.getCurrentModeController().getMapController().getSelectedNode();
    final Controller controller = Controller.getCurrentController();
    final MapModel parentMap = controller.getMap();
    if (parentMap == null || existingNode == null || existingNode.isRoot()) {
        controller.getViewController().err("Could not export branch.");
        return;
    }
    if (parentMap.getFile() == null) {
        controller.getViewController().out("You must save the current map first!");
        ((MModeController) Controller.getCurrentModeController()).save();
    }
    JFileChooser chooser;
    final File file = parentMap.getFile();
    if (file == null) {
        return;
    }
    chooser = new JFileChooser(file.getParentFile());
    chooser.setSelectedFile(new File(createFileName(TextController.getController().getShortPlainText(existingNode))));
    if (((MFileManager) UrlManager.getController()).getFileFilter() != null) {
        chooser.addChoosableFileFilter(((MFileManager) UrlManager.getController()).getFileFilter());
    }
    final int returnVal = chooser.showSaveDialog(controller.getViewController().getCurrentRootComponent());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File chosenFile = chooser.getSelectedFile();
        final String ext = FileUtils.getExtension(chosenFile.getName());
        if (!ext.equals(org.freeplane.features.url.UrlManager.FREEPLANE_FILE_EXTENSION_WITHOUT_DOT)) {
            chosenFile = new File(chosenFile.getParent(), chosenFile.getName() + org.freeplane.features.url.UrlManager.FREEPLANE_FILE_EXTENSION);
        }
        try {
            Compat.fileToUrl(chosenFile);
        } catch (final MalformedURLException ex) {
            UITools.errorMessage(TextUtils.getText("invalid_url"));
            return;
        }
        if (chosenFile.exists()) {
            final int overwriteMap = JOptionPane.showConfirmDialog(controller.getMapViewManager().getMapViewComponent(), TextUtils.getText("map_already_exists"), "Freeplane", JOptionPane.YES_NO_OPTION);
            if (overwriteMap != JOptionPane.YES_OPTION) {
                return;
            }
        }
        /*
			 * Now make a copy from the node, remove the node from the map and
			 * create a new Map with the node as root, store the new Map, add
			 * the copy of the node to the parent, and set a link from the copy
			 * to the new Map.
			 */
        final NodeModel parent = existingNode.getParentNode();
        final File oldFile = parentMap.getFile();
        final URI newUri = LinkController.toLinkTypeDependantURI(oldFile, chosenFile);
        final URI oldUri = LinkController.toLinkTypeDependantURI(chosenFile, file);
        ((MLinkController) LinkController.getController()).setLink(existingNode, oldUri, LinkController.LINK_ABSOLUTE);
        final int nodePosition = parent.getIndex(existingNode);
        final ModeController modeController = Controller.getCurrentModeController();
        modeController.undoableResolveParentExtensions(LogicalStyleKeys.NODE_STYLE, existingNode);
        final MMapController mMapController = (MMapController) modeController.getMapController();
        mMapController.deleteNode(existingNode);
        {
            final IActor actor = new IActor() {

                private final boolean wasFolded = existingNode.isFolded();

                public void undo() {
                    PersistentNodeHook.removeMapExtensions(existingNode);
                    existingNode.setMap(parentMap);
                    existingNode.setFolded(wasFolded);
                }

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

                public void act() {
                    existingNode.setFolded(false);
                }
            };
            Controller.getCurrentModeController().execute(actor, parentMap);
        }
        mMapController.newModel(existingNode);
        final MapModel newMap = existingNode.getMap();
        IExtension[] oldExtensions = newMap.getRootNode().getSharedExtensions().values().toArray(new IExtension[] {});
        for (final IExtension extension : oldExtensions) {
            final Class<? extends IExtension> clazz = extension.getClass();
            if (MapExtensions.isMapExtension(clazz)) {
                existingNode.removeExtension(clazz);
            }
        }
        final Collection<IExtension> newExtensions = parentMap.getRootNode().getSharedExtensions().values();
        for (final IExtension extension : newExtensions) {
            final Class<? extends IExtension> clazz = extension.getClass();
            if (MapExtensions.isMapExtension(clazz)) {
                existingNode.addExtension(extension);
            }
        }
        ((MFileManager) UrlManager.getController()).save(newMap, chosenFile);
        final NodeModel newNode = mMapController.addNewNode(parent, nodePosition, existingNode.isLeft());
        ((MTextController) TextController.getController()).setNodeText(newNode, existingNode.getText());
        modeController.undoableCopyExtensions(LogicalStyleKeys.NODE_STYLE, existingNode, newNode);
        newMap.getFile();
        ((MLinkController) LinkController.getController()).setLink(newNode, newUri, LinkController.LINK_ABSOLUTE);
        newMap.destroy();
        existingNode.setParent(null);
        mMapController.select(newNode);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) MMapController(org.freeplane.features.map.mindmapmode.MMapController) MapModel(org.freeplane.features.map.MapModel) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) MTextController(org.freeplane.features.text.mindmapmode.MTextController) MMapController(org.freeplane.features.map.mindmapmode.MMapController) LinkController(org.freeplane.features.link.LinkController) Controller(org.freeplane.features.mode.Controller) TextController(org.freeplane.features.text.TextController) ModeController(org.freeplane.features.mode.ModeController) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) URI(java.net.URI) NodeModel(org.freeplane.features.map.NodeModel) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) JFileChooser(javax.swing.JFileChooser) IExtension(org.freeplane.core.extension.IExtension) IActor(org.freeplane.core.undo.IActor) MTextController(org.freeplane.features.text.mindmapmode.MTextController) File(java.io.File) MModeController(org.freeplane.features.mode.mindmapmode.MModeController)

Example 23 with MTextController

use of org.freeplane.features.text.mindmapmode.MTextController in project freeplane by freeplane.

the class MMapController method startEditingAfterSelect.

private void startEditingAfterSelect(final NodeModel newNode) {
    final Component component = Controller.getCurrentController().getMapViewManager().getComponent(newNode);
    if (component == null)
        return;
    component.addFocusListener(new FocusListener() {

        public void focusLost(FocusEvent e) {
        }

        public void focusGained(FocusEvent e) {
            e.getComponent().removeFocusListener(this);
            final TextController textController = TextController.getController();
            ((MTextController) textController).edit(newNode, newNode.getParentNode(), true, false, false);
        }
    });
}
Also used : MTextController(org.freeplane.features.text.mindmapmode.MTextController) TextController(org.freeplane.features.text.TextController) Component(java.awt.Component) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 24 with MTextController

use of org.freeplane.features.text.mindmapmode.MTextController in project freeplane by freeplane.

the class EditNodeTextField method show.

/* (non-Javadoc)
	 * @see org.freeplane.view.swing.map.INodeTextField#show()
	 */
@SuppressWarnings("serial")
@Override
public void show(final RootPaneContainer frame) {
    final ModeController modeController = Controller.getCurrentModeController();
    final IMapViewManager viewController = modeController.getController().getMapViewManager();
    final MTextController textController = (MTextController) TextController.getController(modeController);
    nodeView = (NodeView) SwingUtilities.getAncestorOfClass(NodeView.class, parent);
    font = parent.getFont();
    zoom = viewController.getZoom();
    if (zoom != 1F) {
        final float fontSize = (int) (Math.rint(font.getSize() * zoom));
        font = font.deriveFont(fontSize);
    }
    final HTMLEditorKit kit = new ScaledEditorKit() {

        @Override
        public void write(Writer out, Document doc, int pos, int len) throws IOException, BadLocationException {
            if (doc instanceof HTMLDocument) {
                HTMLWriter w = new SHTMLWriter(out, (HTMLDocument) doc, pos, len);
                w.write();
            } else {
                super.write(out, doc, pos, len);
            }
        }
    };
    textfield.setEditorKit(kit);
    final InputMap inputMap = textfield.getInputMap();
    final ActionMap actionMap = textfield.getActionMap();
    actionMap.put(DefaultEditorKit.pasteAction, pasteAction);
    inputMap.put((KeyStroke) boldAction.getValue(Action.ACCELERATOR_KEY), "boldAction");
    actionMap.put("boldAction", boldAction);
    inputMap.put((KeyStroke) italicAction.getValue(Action.ACCELERATOR_KEY), "italicAction");
    actionMap.put("italicAction", italicAction);
    inputMap.put((KeyStroke) underlineAction.getValue(Action.ACCELERATOR_KEY), "underlineAction");
    actionMap.put("underlineAction", underlineAction);
    inputMap.put((KeyStroke) redAction.getValue(Action.ACCELERATOR_KEY), "redAction");
    actionMap.put("redAction", redAction);
    inputMap.put((KeyStroke) greenAction.getValue(Action.ACCELERATOR_KEY), "greenAction");
    actionMap.put("greenAction", greenAction);
    inputMap.put((KeyStroke) blueAction.getValue(Action.ACCELERATOR_KEY), "blueAction");
    actionMap.put("blueAction", blueAction);
    inputMap.put((KeyStroke) blackAction.getValue(Action.ACCELERATOR_KEY), "blackAction");
    actionMap.put("blackAction", blackAction);
    inputMap.put((KeyStroke) defaultColorAction.getValue(Action.ACCELERATOR_KEY), "defaultColorAction");
    actionMap.put("defaultColorAction", defaultColorAction);
    inputMap.put((KeyStroke) removeFormattingAction.getValue(Action.ACCELERATOR_KEY), "removeFormattingAction");
    actionMap.put("removeFormattingAction", removeFormattingAction);
    final Color nodeTextColor = parent.getForeground();
    textfield.setCaretColor(nodeTextColor);
    final StringBuilder ruleBuilder = new StringBuilder(100);
    ruleBuilder.append("body {");
    final int labelHorizontalAlignment = parent.getHorizontalAlignment();
    ruleBuilder.append(new CssRuleBuilder().withCSSFont(font, UITools.FONT_SCALE_FACTOR).withColor(nodeTextColor).withBackground(getBackground()).withAlignment(labelHorizontalAlignment));
    ruleBuilder.append("}\n");
    final HTMLDocument document = (HTMLDocument) textfield.getDocument();
    final StyleSheet styleSheet = document.getStyleSheet();
    styleSheet.addRule(ruleBuilder.toString());
    textfield.setText(text);
    final MapView mapView = nodeView.getMap();
    if (!mapView.isValid())
        mapView.validate();
    final NodeStyleController nsc = NodeStyleController.getController(modeController);
    maxWidth = Math.max(mapView.getZoomed(nsc.getMaxWidth(node).toBaseUnitsRounded()), parent.getWidth());
    final Icon icon = parent.getIcon();
    if (icon != null) {
        maxWidth -= mapView.getZoomed(icon.getIconWidth());
        maxWidth -= mapView.getZoomed(parent.getIconTextGap());
    }
    Insets parentInsets = parent.getZoomedInsets();
    maxWidth -= parentInsets.left + parentInsets.right;
    extraWidth = ResourceController.getResourceController().getIntProperty("editor_extra_width", 80);
    extraWidth = mapView.getZoomed(extraWidth);
    final TextFieldListener textFieldListener = new TextFieldListener();
    this.textFieldListener = textFieldListener;
    textfield.addFocusListener(textFieldListener);
    textfield.addKeyListener(textFieldListener);
    textfield.addMouseListener(textFieldListener);
    mapViewChangeListener = new MapViewChangeListener();
    Controller.getCurrentController().getMapViewManager().addMapViewChangeListener(mapViewChangeListener);
    SpellCheckerController.getController().enableAutoSpell(textfield, true);
    mapView.scrollNodeToVisible(nodeView);
    assert (parent.isValid());
    final int nodeWidth = parent.getWidth();
    final int textFieldBorderWidth = 2;
    textfield.setBorder(new MatteBorder(textFieldBorderWidth, textFieldBorderWidth, textFieldBorderWidth, textFieldBorderWidth, nodeView.getSelectedColor()));
    final Dimension textFieldMinimumSize = textfield.getPreferredSize();
    textFieldMinimumSize.width += 1;
    if (textFieldMinimumSize.width < extraWidth)
        textFieldMinimumSize.width = extraWidth;
    if (textFieldMinimumSize.width < 10)
        textFieldMinimumSize.width = 10;
    if (textFieldMinimumSize.width > maxWidth) {
        textFieldMinimumSize.width = maxWidth;
        setLineWrap();
        textFieldMinimumSize.height = textfield.getPreferredSize().height;
    }
    final ZoomableLabelUI parentUI = (ZoomableLabelUI) parent.getUI();
    final LayoutData layoutData = parentUI.getLayoutData(parent);
    Rectangle iconR = layoutData.iconR;
    final Rectangle textR = layoutData.textR;
    int textFieldX = parentInsets.left - textFieldBorderWidth + (iconR.width > 0 ? textR.x - iconR.x : 0);
    final EventBuffer eventQueue = MTextController.getController().getEventQueue();
    KeyEvent firstEvent = eventQueue.getFirstEvent();
    Point mouseEventPoint = null;
    if (firstEvent == null) {
        MouseEvent currentEvent = eventQueue.getMouseEvent();
        if (currentEvent != null) {
            MouseEvent mouseEvent = (MouseEvent) currentEvent;
            if (mouseEvent.getComponent().equals(parent)) {
                mouseEventPoint = mouseEvent.getPoint();
                mouseEventPoint.x -= textR.x;
                mouseEventPoint.y -= textR.y;
            }
        }
    }
    textFieldMinimumSize.width = Math.max(textFieldMinimumSize.width, nodeWidth - textFieldX - (parentInsets.right - textFieldBorderWidth));
    textFieldMinimumSize.height = Math.max(textFieldMinimumSize.height, textR.height);
    textfield.setSize(textFieldMinimumSize.width, textFieldMinimumSize.height);
    final int textY = Math.max(textR.y - (textFieldMinimumSize.height - textR.height) / 2, 0);
    final Dimension newParentSize = new Dimension(textFieldX + textFieldMinimumSize.width + parentInsets.right, 2 * textY + textFieldMinimumSize.height);
    horizontalSpace = newParentSize.width - textFieldMinimumSize.width;
    verticalSpace = 2 * textY;
    final int widthAddedToParent = newParentSize.width - parent.getWidth();
    final Point location = new Point(textR.x - textFieldBorderWidth, textY);
    final int widthAddedToTextField = textFieldMinimumSize.width - (textR.width + 2 * textFieldBorderWidth);
    if (widthAddedToTextField > 0) {
        switch(labelHorizontalAlignment) {
            case SwingConstants.CENTER:
                location.x -= (widthAddedToTextField - widthAddedToParent) / 2;
                if (mouseEventPoint != null)
                    mouseEventPoint.x += widthAddedToTextField / 2;
                break;
            case SwingConstants.RIGHT:
                location.x -= widthAddedToTextField - widthAddedToParent;
                if (mouseEventPoint != null)
                    mouseEventPoint.x += widthAddedToTextField;
                break;
        }
    }
    keepNodePosition();
    parent.setPreferredSize(newParentSize);
    parent.setText("");
    parent.setHorizontalAlignment(JLabel.LEFT);
    if (!layoutMapOnTextChange) {
        mapView.doLayout();
        UITools.convertPointToAncestor(parent, location, mapView);
    }
    textfield.setBounds(location.x, location.y, textFieldMinimumSize.width, textFieldMinimumSize.height);
    if (layoutMapOnTextChange)
        parent.add(textfield, 0);
    else
        mapView.add(textfield, 0);
    redispatchKeyEvents(textfield, firstEvent);
    if (firstEvent == null) {
        int pos = document.getLength();
        if (mouseEventPoint != null)
            pos = textfield.viewToModel(mouseEventPoint);
        textfield.setCaretPosition(pos);
    }
    document.addDocumentListener(documentListener);
    if (textController.isMinimized(node)) {
        layout();
    }
    textfield.repaint();
    textfield.requestFocusInWindow();
}
Also used : Insets(java.awt.Insets) HTMLDocument(javax.swing.text.html.HTMLDocument) Rectangle(java.awt.Rectangle) EventBuffer(org.freeplane.features.text.mindmapmode.EventBuffer) ModeController(org.freeplane.features.mode.ModeController) ScaledEditorKit(org.freeplane.core.ui.components.html.ScaledEditorKit) HTMLDocument(javax.swing.text.html.HTMLDocument) Document(javax.swing.text.Document) KeyEvent(java.awt.event.KeyEvent) SHTMLWriter(com.lightdev.app.shtm.SHTMLWriter) MatteBorder(javax.swing.border.MatteBorder) ZoomableLabelUI(org.freeplane.view.swing.map.ZoomableLabelUI) MapView(org.freeplane.view.swing.map.MapView) HTMLWriter(javax.swing.text.html.HTMLWriter) SHTMLWriter(com.lightdev.app.shtm.SHTMLWriter) MouseEvent(java.awt.event.MouseEvent) CssRuleBuilder(org.freeplane.core.ui.components.html.CssRuleBuilder) ActionMap(javax.swing.ActionMap) Color(java.awt.Color) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) Dimension(java.awt.Dimension) Point(java.awt.Point) Point(java.awt.Point) IMapViewManager(org.freeplane.features.ui.IMapViewManager) StyleSheet(javax.swing.text.html.StyleSheet) IMapViewChangeListener(org.freeplane.features.ui.IMapViewChangeListener) LayoutData(org.freeplane.view.swing.map.ZoomableLabelUI.LayoutData) NodeStyleController(org.freeplane.features.nodestyle.NodeStyleController) InputMap(javax.swing.InputMap) MTextController(org.freeplane.features.text.mindmapmode.MTextController) Icon(javax.swing.Icon) HTMLWriter(javax.swing.text.html.HTMLWriter) Writer(java.io.Writer) SHTMLWriter(com.lightdev.app.shtm.SHTMLWriter)

Example 25 with MTextController

use of org.freeplane.features.text.mindmapmode.MTextController in project freeplane by freeplane.

the class MNodeMotionListener method mouseClicked.

@Override
public void mouseClicked(final MouseEvent e) {
    boolean shoudResetPosition = e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2 && doubleClickTimer.getDelay() > 0;
    if (shoudResetPosition) {
        final MainView mainView = (MainView) e.getComponent();
        if (mainView.getMouseArea().equals(MouseArea.MOTION)) {
            final Controller controller = Controller.getCurrentController();
            MLocationController locationController = (MLocationController) LocationController.getController(controller.getModeController());
            if (e.getModifiersEx() == 0) {
                final NodeView nodeV = getNodeView(e);
                final NodeModel node = nodeV.getModel();
                locationController.moveNodePosition(node, LocationModel.DEFAULT_HGAP, LocationModel.DEFAULT_SHIFT_Y);
                return;
            }
            if (Compat.isCtrlEvent(e)) {
                final NodeView nodeV = getNodeView(e);
                NodeModel childDistanceContainer = nodeV.getParentView().getChildDistanceContainer().getModel();
                locationController.setMinimalDistanceBetweenChildren(childDistanceContainer, LocationModel.DEFAULT_VGAP);
                return;
            }
        } else {
            if (Compat.isPlainEvent(e) && !isInFoldingRegion(e)) {
                final MTextController textController = MTextController.getController();
                textController.getEventQueue().activate(e);
                textController.edit(FirstAction.EDIT_CURRENT, false);
            }
        }
    }
    super.mouseClicked(e);
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) MainView(org.freeplane.view.swing.map.MainView) MLocationController(org.freeplane.features.nodelocation.mindmapmode.MLocationController) MTextController(org.freeplane.features.text.mindmapmode.MTextController) MTextController(org.freeplane.features.text.mindmapmode.MTextController) ResourceController(org.freeplane.core.resources.ResourceController) MMapController(org.freeplane.features.map.mindmapmode.MMapController) MapController(org.freeplane.features.map.MapController) LocationController(org.freeplane.features.nodelocation.LocationController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) MLocationController(org.freeplane.features.nodelocation.mindmapmode.MLocationController) NodeView(org.freeplane.view.swing.map.NodeView)

Aggregations

MTextController (org.freeplane.features.text.mindmapmode.MTextController)25 NodeModel (org.freeplane.features.map.NodeModel)11 ModeController (org.freeplane.features.mode.ModeController)8 MMapController (org.freeplane.features.map.mindmapmode.MMapController)7 Component (java.awt.Component)5 KeyEvent (java.awt.event.KeyEvent)5 MLinkController (org.freeplane.features.link.mindmapmode.MLinkController)5 Controller (org.freeplane.features.mode.Controller)5 TextController (org.freeplane.features.text.TextController)5 MLocationController (org.freeplane.features.nodelocation.mindmapmode.MLocationController)4 JComponent (javax.swing.JComponent)3 JPopupMenu (javax.swing.JPopupMenu)3 JTable (javax.swing.JTable)3 ResourceController (org.freeplane.core.resources.ResourceController)3 AttributeController (org.freeplane.features.attribute.AttributeController)3 MAttributeController (org.freeplane.features.attribute.mindmapmode.MAttributeController)3 CloudController (org.freeplane.features.cloud.CloudController)3 MCloudController (org.freeplane.features.cloud.mindmapmode.MCloudController)3 EdgeController (org.freeplane.features.edge.EdgeController)3 MEdgeController (org.freeplane.features.edge.mindmapmode.MEdgeController)3