Search in sources :

Example 11 with TextController

use of org.freeplane.features.text.TextController in project freeplane by freeplane.

the class MTextController method editDetails.

public void editDetails(final NodeModel nodeModel, InputEvent e, final boolean editLong) {
    final Controller controller = Controller.getCurrentController();
    stopEditing();
    Controller.getCurrentModeController().setBlocked(true);
    String text = DetailTextModel.getDetailTextText(nodeModel);
    final boolean isNewNode = text == null;
    if (isNewNode) {
        final MTextController textController = MTextController.getController();
        textController.setDetails(nodeModel, "<html>");
        text = "";
    }
    final EditNodeBase.IEditControl editControl = new EditNodeBase.IEditControl() {

        @Override
        public void cancel() {
            if (isNewNode) {
                final String detailText = DetailTextModel.getDetailTextText(nodeModel);
                final MModeController modeController = (MModeController) Controller.getCurrentModeController();
                if (detailText != null)
                    modeController.undo();
                modeController.resetRedo();
            }
            stop();
        }

        @Override
        public void ok(final String newText) {
            if (HtmlUtils.isEmpty(newText))
                if (isNewNode) {
                    final MModeController modeController = (MModeController) Controller.getCurrentModeController();
                    modeController.undo();
                    modeController.resetRedo();
                } else {
                    keepNodePosition();
                    setDetailsHtmlText(nodeModel, null);
                }
            else {
                keepNodePosition();
                setDetailsHtmlText(nodeModel, newText);
            }
            stop();
        }

        private void keepNodePosition() {
            Controller.getCurrentController().getSelection().keepNodePosition(nodeModel, 0, 0);
        }

        @Override
        public void split(final String newText, final int position) {
        }

        private void stop() {
            Controller.getCurrentModeController().setBlocked(false);
            mCurrentEditor = null;
        }

        @Override
        public boolean canSplit() {
            return false;
        }

        @Override
        public EditedComponent getEditType() {
            return EditedComponent.DETAIL;
        }
    };
    mCurrentEditor = createEditor(nodeModel, editControl, text, false, editLong, true);
    final RootPaneContainer frame = (RootPaneContainer) SwingUtilities.getWindowAncestor(controller.getMapViewManager().getMapViewComponent());
    mCurrentEditor.show(frame);
}
Also used : RootPaneContainer(javax.swing.RootPaneContainer) MMapController(org.freeplane.features.map.mindmapmode.MMapController) MapController(org.freeplane.features.map.MapController) MIconController(org.freeplane.features.icon.mindmapmode.MIconController) IconController(org.freeplane.features.icon.IconController) Controller(org.freeplane.features.mode.Controller) TextController(org.freeplane.features.text.TextController) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) NodeStyleController(org.freeplane.features.nodestyle.NodeStyleController) FormatController(org.freeplane.features.format.FormatController) LogicalStyleController(org.freeplane.features.styles.LogicalStyleController) ResourceController(org.freeplane.core.resources.ResourceController) ViewController(org.freeplane.features.ui.ViewController) LinkController(org.freeplane.features.link.LinkController) ModeController(org.freeplane.features.mode.ModeController) MNodeStyleController(org.freeplane.features.nodestyle.mindmapmode.MNodeStyleController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) ScannerController(org.freeplane.features.format.ScannerController) IEditControl(org.freeplane.features.text.mindmapmode.EditNodeBase.IEditControl) IEditControl(org.freeplane.features.text.mindmapmode.EditNodeBase.IEditControl) MModeController(org.freeplane.features.mode.mindmapmode.MModeController)

Example 12 with TextController

use of org.freeplane.features.text.TextController 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);
    }
}
Also used : TransformationException(org.freeplane.features.text.TransformationException) NodeModel(org.freeplane.features.map.NodeModel) Matcher(java.util.regex.Matcher) TextController(org.freeplane.features.text.TextController) MMapController(org.freeplane.features.map.mindmapmode.MMapController) ModeController(org.freeplane.features.mode.ModeController)

Example 13 with TextController

use of org.freeplane.features.text.TextController in project freeplane by freeplane.

the class NodeView method numberingChanged.

// updates children, starting from firstChangedIndex, if necessary.
private void numberingChanged(int firstChangedIndex) {
    final TextController textController = TextController.getController(getMap().getModeController());
    if (firstChangedIndex > 0 || textController.getNodeNumbering(getModel())) {
        final Component[] components = getComponents();
        for (int i = firstChangedIndex; i < components.length; i++) {
            if (components[i] instanceof NodeView) {
                final NodeView view = (NodeView) components[i];
                final MainView childMainView = view.getMainView();
                if (childMainView != null) {
                    childMainView.updateText(view.getModel());
                    view.numberingChanged(0);
                }
            }
        }
    }
}
Also used : TextController(org.freeplane.features.text.TextController) Component(java.awt.Component) JComponent(javax.swing.JComponent) INodeView(org.freeplane.features.map.INodeView) Point(java.awt.Point)

Example 14 with TextController

use of org.freeplane.features.text.TextController in project freeplane by freeplane.

the class NoteViewMouseListener method mouseClicked.

@Override
public void mouseClicked(MouseEvent e) {
    if (e.getClickCount() == 2) {
        TextController controller = TextController.getController();
        if (controller.canEdit()) {
            NodeModel node = new NodeSelector().getRelatedNodeView(e).getModel();
            ((MNoteController) NoteController.getController()).editNoteInDialog(node);
        }
    } else
        super.mouseClicked(e);
}
Also used : MNoteController(org.freeplane.features.note.mindmapmode.MNoteController) NodeModel(org.freeplane.features.map.NodeModel) TextController(org.freeplane.features.text.TextController) NodeSelector(org.freeplane.view.swing.ui.NodeSelector)

Example 15 with TextController

use of org.freeplane.features.text.TextController in project freeplane by freeplane.

the class MainView method updateText.

public void updateText(NodeModel nodeModel) {
    final NodeView nodeView = getNodeView();
    if (nodeView == null)
        return;
    final ModeController modeController = nodeView.getMap().getModeController();
    final TextController textController = TextController.getController(modeController);
    isShortened = textController.isMinimized(nodeModel);
    final Object userObject = nodeModel.getUserObject();
    String text;
    try {
        final Object transformedContent = textController.getTransformedObject(nodeModel);
        if (nodeView.isSelected()) {
            nodeView.getMap().getModeController().getController().getViewController().addObjectTypeInfo(transformedContent);
        }
        Icon icon = textController.getIcon(transformedContent, nodeModel, userObject);
        putClientProperty(TEXT_RENDERING_ICON, icon);
        text = transformedContent.toString();
        textModified = transformedContent instanceof HighlightedTransformedObject ? TextModificationState.HIGHLIGHT : TextModificationState.NONE;
    } catch (Throwable e) {
        LogUtils.warn(e.getMessage(), e);
        text = TextUtils.format("MainView.errorUpdateText", String.valueOf(userObject), e.getLocalizedMessage());
        textModified = TextModificationState.FAILURE;
    }
    if (isShortened) {
        text = textController.getShortText(text);
    }
    text = convertTextToHtmlLink(text, nodeModel);
    updateText(text);
}
Also used : HighlightedTransformedObject(org.freeplane.features.text.HighlightedTransformedObject) TextController(org.freeplane.features.text.TextController) HighlightedTransformedObject(org.freeplane.features.text.HighlightedTransformedObject) ModeController(org.freeplane.features.mode.ModeController) Icon(javax.swing.Icon) UIIcon(org.freeplane.features.icon.UIIcon) MindIcon(org.freeplane.features.icon.MindIcon)

Aggregations

TextController (org.freeplane.features.text.TextController)17 NodeModel (org.freeplane.features.map.NodeModel)6 ModeController (org.freeplane.features.mode.ModeController)6 Component (java.awt.Component)4 JPopupMenu (javax.swing.JPopupMenu)3 IconController (org.freeplane.features.icon.IconController)3 LinkController (org.freeplane.features.link.LinkController)3 Controller (org.freeplane.features.mode.Controller)3 NodeStyleController (org.freeplane.features.nodestyle.NodeStyleController)3 LogicalStyleController (org.freeplane.features.styles.LogicalStyleController)3 FocusEvent (java.awt.event.FocusEvent)2 FocusListener (java.awt.event.FocusListener)2 Icon (javax.swing.Icon)2 FreeplaneToolBar (org.freeplane.core.ui.components.FreeplaneToolBar)2 ClipboardController (org.freeplane.features.clipboard.ClipboardController)2 CloudController (org.freeplane.features.cloud.CloudController)2 EdgeController (org.freeplane.features.edge.EdgeController)2 FilterController (org.freeplane.features.filter.FilterController)2 MapController (org.freeplane.features.map.MapController)2 MMapController (org.freeplane.features.map.mindmapmode.MMapController)2