Search in sources :

Example 1 with TransformationException

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

the class AttributeConditionController method getValuesForProperty.

public ComboBoxModel getValuesForProperty(final Object selectedItem, TranslatedObject simpleCond) {
    final MapModel map = Controller.getCurrentController().getMap();
    final AttributeRegistry registry = AttributeRegistry.getRegistry(map);
    try {
        final AttributeRegistryElement element = registry.getElement(selectedItem.toString());
        final SortedComboBoxModel list = element.getValues();
        SortedComboBoxModel linkedList = new SortedComboBoxModel();
        for (int i = 0; i < list.getSize(); i++) {
            final Object value = list.getElementAt(i);
            final TextController textController = TextController.getController();
            if (!textController.isFormula(value, null, null)) {
                try {
                    final Object transformedValue = textController.getTransformedObject(value, map.getRootNode(), null);
                    linkedList.add(transformedValue);
                } catch (TransformationException e) {
                    LogUtils.severe(e);
                }
            }
        }
        values.setExtensionList(linkedList);
    } catch (NoSuchElementException e) {
        values.setExtensionList(null);
    }
    return values;
}
Also used : TransformationException(org.freeplane.features.text.TransformationException) TextController(org.freeplane.features.text.TextController) TranslatedObject(org.freeplane.core.resources.TranslatedObject) MapModel(org.freeplane.features.map.MapModel) SortedComboBoxModel(org.freeplane.core.util.collection.SortedComboBoxModel) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with TransformationException

use of org.freeplane.features.text.TransformationException 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)

Aggregations

TextController (org.freeplane.features.text.TextController)2 TransformationException (org.freeplane.features.text.TransformationException)2 NoSuchElementException (java.util.NoSuchElementException)1 Matcher (java.util.regex.Matcher)1 TranslatedObject (org.freeplane.core.resources.TranslatedObject)1 SortedComboBoxModel (org.freeplane.core.util.collection.SortedComboBoxModel)1 MapModel (org.freeplane.features.map.MapModel)1 NodeModel (org.freeplane.features.map.NodeModel)1 MMapController (org.freeplane.features.map.mindmapmode.MMapController)1 ModeController (org.freeplane.features.mode.ModeController)1