Search in sources :

Example 1 with MTextController

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

the class MClipboardController method getFlavorHandler.

private IDataFlavorHandler getFlavorHandler(final Transferable t) {
    if (t.isDataFlavorSupported(MindMapNodesSelection.mindMapNodesFlavor)) {
        try {
            final String textFromClipboard = t.getTransferData(MindMapNodesSelection.mindMapNodesFlavor).toString();
            return new MindMapNodesFlavorHandler(textFromClipboard);
        } catch (final UnsupportedFlavorException e) {
        } catch (final IOException e) {
        }
    }
    final ResourceController resourceController = ResourceController.getResourceController();
    DataFlavor supportedHtmlFlavor = getSupportedHtmlFlavor(t);
    if (supportedHtmlFlavor != null) {
        try {
            final String textFromClipboard = t.getTransferData(supportedHtmlFlavor).toString();
            if (textFromClipboard.charAt(0) != 65533) {
                if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                    final MTextController textController = (MTextController) TextController.getController();
                    final boolean richText = textController.useRichTextInEditor(RESOURCES_REMIND_USE_RICH_TEXT_IN_NEW_NODES);
                    if (richText) {
                        final boolean structuredHtmlImport = resourceController.getBooleanProperty("structured_html_import");
                        final IDataFlavorHandler htmlFlavorHandler;
                        if (structuredHtmlImport) {
                            htmlFlavorHandler = new StructuredHtmlFlavorHandler(textFromClipboard);
                        } else {
                            htmlFlavorHandler = new DirectHtmlFlavorHandler(textFromClipboard);
                        }
                        return htmlFlavorHandler;
                    }
                }
            }
        } catch (final UnsupportedFlavorException e) {
        } catch (final IOException e) {
        }
    }
    if (t.isDataFlavorSupported(MindMapNodesSelection.fileListFlavor)) {
        try {
            final List<File> fileList = castToFileList(t.getTransferData(MindMapNodesSelection.fileListFlavor));
            if (!shouldIgnoreFileListFlavor(fileList))
                return new FileListFlavorHandler(fileList);
        } catch (final UnsupportedFlavorException e) {
        } catch (final IOException e) {
        }
    }
    if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        try {
            final String plainTextFromClipboard = t.getTransferData(DataFlavor.stringFlavor).toString();
            return new StringFlavorHandler(plainTextFromClipboard);
        } catch (final UnsupportedFlavorException e) {
        } catch (final IOException e) {
        }
    }
    if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
        try {
            Image image = (Image) t.getTransferData(DataFlavor.imageFlavor);
            return new ImageFlavorHandler(image);
        } catch (final UnsupportedFlavorException e) {
        } catch (final IOException e) {
        }
    }
    return null;
}
Also used : IOException(java.io.IOException) Image(java.awt.Image) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) DataFlavor(java.awt.datatransfer.DataFlavor) ResourceController(org.freeplane.core.resources.ResourceController) MTextController(org.freeplane.features.text.mindmapmode.MTextController) File(java.io.File)

Example 2 with MTextController

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

the class TimeManagement method createDateFormatChooser.

private JComboBox createDateFormatChooser() {
    class DateFormatComboBoxElement {

        private final PatternFormat dateFormat;

        DateFormatComboBoxElement(PatternFormat dateFormat) {
            this.dateFormat = dateFormat;
        }

        PatternFormat getDateFormat() {
            return dateFormat;
        }

        public String toString() {
            return dateFormat.formatObject(getCalendarDate()).toString();
        }
    }
    final String dateFormatPattern = ResourceController.getResourceController().getProperty("date_format");
    final Vector<DateFormatComboBoxElement> values = new Vector<DateFormatComboBoxElement>();
    final List<PatternFormat> datePatterns = FormatController.getController().getDateFormats();
    int selectedIndex = 0;
    for (int i = 0; i < datePatterns.size(); ++i) {
        final PatternFormat patternFormat = datePatterns.get(i);
        values.add(new DateFormatComboBoxElement(patternFormat));
        if (patternFormat.getPattern().equals(dateFormatPattern)) {
            selectedIndex = i;
        }
    }
    if (!datePatterns.isEmpty()) {
        dateFormat = datePatterns.get(selectedIndex);
    }
    final JComboBox dateFormatChooser = new JComboBoxWithBorder(values);
    dateFormatChooser.setFocusable(false);
    if (!datePatterns.isEmpty()) {
        dateFormatChooser.setSelectedIndex(selectedIndex);
    }
    dateFormatChooser.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            dateFormat = ((DateFormatComboBoxElement) e.getItem()).getDateFormat();
            final Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
            if (focusOwner instanceof JTable) {
                JTable table = (JTable) focusOwner;
                final int[] selectedRows = table.getSelectedRows();
                final int[] selectedColumns = table.getSelectedColumns();
                for (int r : selectedRows) for (int c : selectedColumns) {
                    Object date = table.getValueAt(r, c);
                    if (date instanceof FormattedDate) {
                        final FormattedDate fd = (FormattedDate) date;
                        if (!fd.getDateFormat().equals(dateFormat)) {
                            table.setValueAt(new FormattedDate(fd, dateFormat.getPattern()), r, c);
                        }
                    }
                }
            } else {
                ModeController mController = Controller.getCurrentModeController();
                for (final NodeModel node : mController.getMapController().getSelectedNodes()) {
                    final MTextController textController = (MTextController) TextController.getController();
                    Object date = node.getUserObject();
                    if (date instanceof FormattedDate) {
                        final FormattedDate fd = (FormattedDate) date;
                        if (!fd.getDateFormat().equals(dateFormat)) {
                            textController.setNodeObject(node, new FormattedDate(fd, dateFormat.getPattern()));
                        }
                    }
                }
            }
        }
    });
    dateFormatChooser.setAlignmentX(Component.LEFT_ALIGNMENT);
    return dateFormatChooser;
}
Also used : ItemEvent(java.awt.event.ItemEvent) JComboBox(javax.swing.JComboBox) PatternFormat(org.freeplane.features.format.PatternFormat) ModeController(org.freeplane.features.mode.ModeController) FormattedDate(org.freeplane.features.format.FormattedDate) NodeModel(org.freeplane.features.map.NodeModel) JTable(javax.swing.JTable) ItemListener(java.awt.event.ItemListener) MTextController(org.freeplane.features.text.mindmapmode.MTextController) JComboBoxWithBorder(org.freeplane.core.ui.components.JComboBoxWithBorder) Component(java.awt.Component) JComponent(javax.swing.JComponent) JTextComponent(javax.swing.text.JTextComponent) Vector(java.util.Vector)

Example 3 with MTextController

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

the class TimeManagement method insertTime.

void insertTime(final Dialog dialog, final JButton appendButton) {
    FormattedDate date = getCalendarDate();
    final String dateAsString = dateFormat.formatObject(date).toString();
    final Window parentWindow;
    if (dialog != null) {
        parentWindow = (Window) dialog.getParent();
    } else {
        parentWindow = SwingUtilities.getWindowAncestor(appendButton);
    }
    final Component mostRecentFocusOwner = parentWindow.getMostRecentFocusOwner();
    if (mostRecentFocusOwner instanceof JTextComponent && !(mostRecentFocusOwner.getClass().getName().contains("JSpinField"))) {
        final JTextComponent textComponent = (JTextComponent) mostRecentFocusOwner;
        textComponent.replaceSelection(dateAsString);
        return;
    }
    if (mostRecentFocusOwner instanceof JTable) {
        JTable table = (JTable) mostRecentFocusOwner;
        final int[] selectedRows = table.getSelectedRows();
        final int[] selectedColumns = table.getSelectedColumns();
        for (int r : selectedRows) for (int c : selectedColumns) table.setValueAt(date, r, c);
    } else {
        ModeController mController = Controller.getCurrentModeController();
        for (final NodeModel node : mController.getMapController().getSelectedNodes()) {
            final MTextController textController = (MTextController) TextController.getController();
            textController.setNodeObject(node, date);
        }
    }
}
Also used : Window(java.awt.Window) FormattedDate(org.freeplane.features.format.FormattedDate) NodeModel(org.freeplane.features.map.NodeModel) JTable(javax.swing.JTable) JTextComponent(javax.swing.text.JTextComponent) ModeController(org.freeplane.features.mode.ModeController) MTextController(org.freeplane.features.text.mindmapmode.MTextController) Component(java.awt.Component) JComponent(javax.swing.JComponent) JTextComponent(javax.swing.text.JTextComponent)

Example 4 with MTextController

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

the class FormulaTextTransformer method createEditor.

public EditNodeBase createEditor(final NodeModel node, final EditNodeBase.IEditControl editControl, String text, final boolean editLong) {
    MTextController textController = MTextController.getController();
    if (textController.isTextFormattingDisabled(node))
        return null;
    final KeyEvent firstKeyEvent = textController.getEventQueue().getFirstEvent();
    if (firstKeyEvent != null) {
        if (firstKeyEvent.getKeyChar() == '=') {
            text = "=";
        } else {
            return null;
        }
    }
    if (text.startsWith("=")) {
        JEditorPane textEditor = new JEditorPane();
        textEditor.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
        final JRestrictedSizeScrollPane scrollPane = new JRestrictedSizeScrollPane(textEditor);
        scrollPane.setMinimumSize(new Dimension(0, 60));
        final EditNodeDialog editNodeDialog = new FormulaEditor(node, text, firstKeyEvent, editControl, false, textEditor);
        editNodeDialog.setTitle(TextUtils.getText("formula_editor"));
        textEditor.setContentType("text/groovy");
        final String fontName = ResourceController.getResourceController().getProperty(FormulaEditor.GROOVY_EDITOR_FONT);
        final int fontSize = ResourceController.getResourceController().getIntProperty(FormulaEditor.GROOVY_EDITOR_FONT_SIZE);
        textEditor.setFont(new Font(fontName, Font.PLAIN, fontSize));
        return editNodeDialog;
    }
    return null;
}
Also used : KeyEvent(java.awt.event.KeyEvent) JRestrictedSizeScrollPane(org.freeplane.core.ui.components.JRestrictedSizeScrollPane) JEditorPane(javax.swing.JEditorPane) MTextController(org.freeplane.features.text.mindmapmode.MTextController) Dimension(java.awt.Dimension) EditNodeDialog(org.freeplane.features.text.mindmapmode.EditNodeDialog) Font(java.awt.Font)

Example 5 with MTextController

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

the class MMapController method addFreeNode.

public NodeModel addFreeNode(final Point pt, final boolean newNodeIsLeft) {
    final ModeController modeController = Controller.getCurrentModeController();
    final TextController textController = TextController.getController();
    if (textController instanceof MTextController) {
        ((MTextController) textController).stopEditing();
        modeController.forceNewTransaction();
    }
    final NodeModel target = getRootNode();
    final NodeModel targetNode = target;
    final boolean parentFolded = isFolded(targetNode);
    if (parentFolded) {
        unfold(targetNode);
    }
    if (!isWriteable(target)) {
        UITools.errorMessage(TextUtils.getText("node_is_write_protected"));
        return null;
    }
    final NodeModel newNode = newNode("", target.getMap());
    LogicalStyleModel.createExtension(newNode).setStyle(MapStyleModel.FLOATING_STYLE);
    newNode.addExtension(modeController.getExtension(FreeNode.class));
    if (!addNewNode(newNode, target, target.getChildCount(), newNodeIsLeft))
        return null;
    final Quantity<LengthUnits> x = LengthUnits.pixelsInPt(pt.x);
    final Quantity<LengthUnits> y = LengthUnits.pixelsInPt(pt.y);
    ((MLocationController) MLocationController.getController(modeController)).moveNodePosition(newNode, x, y);
    final Component component = Controller.getCurrentController().getMapViewManager().getComponent(newNode);
    if (component == null)
        return newNode;
    component.addFocusListener(new FocusListener() {

        public void focusLost(FocusEvent e) {
        }

        public void focusGained(FocusEvent e) {
            e.getComponent().removeFocusListener(this);
            ((MTextController) textController).edit(newNode, targetNode, true, false, false);
        }
    });
    select(newNode);
    return newNode;
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) LengthUnits(org.freeplane.core.ui.LengthUnits) MLocationController(org.freeplane.features.nodelocation.mindmapmode.MLocationController) MTextController(org.freeplane.features.text.mindmapmode.MTextController) TextController(org.freeplane.features.text.TextController) FreeNode(org.freeplane.features.map.FreeNode) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) MTextController(org.freeplane.features.text.mindmapmode.MTextController) Component(java.awt.Component) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

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