Search in sources :

Example 1 with NoteModel

use of org.freeplane.features.note.NoteModel in project freeplane by freeplane.

the class NodeViewFactory method updateNoteViewer.

void updateNoteViewer(NodeView nodeView) {
    ZoomableLabel note = (ZoomableLabel) nodeView.getContent(NodeView.NOTE_VIEWER_POSITION);
    String oldText = note != null ? note.getText() : null;
    String newText = null;
    if (nodeView.getMap().showNotes()) {
        final NodeModel model = nodeView.getModel();
        final NoteModel extension = NoteModel.getNote(model);
        if (extension != null)
            newText = extension.getHtml();
    }
    if (oldText == null && newText == null) {
        return;
    }
    final ZoomableLabel view;
    if (oldText != null && newText != null) {
        view = (ZoomableLabel) nodeView.getContent(NodeView.NOTE_VIEWER_POSITION);
    } else if (oldText == null && newText != null) {
        view = NodeViewFactory.getInstance().createNoteViewer();
        nodeView.addContent(view, NodeView.NOTE_VIEWER_POSITION);
    } else {
        assert (oldText != null && newText == null);
        nodeView.removeContent(NodeView.NOTE_VIEWER_POSITION);
        return;
    }
    view.setFont(nodeView.getMap().getDefaultNoteFont());
    view.updateText(newText);
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) NoteModel(org.freeplane.features.note.NoteModel)

Example 2 with NoteModel

use of org.freeplane.features.note.NoteModel in project freeplane by freeplane.

the class NodeViewFactory method updateNoteViewer.

void updateNoteViewer(NodeView nodeView, int minNodeWidth, int maxNodeWidth) {
    ZoomableLabel note = (ZoomableLabel) nodeView.getContent(NodeView.NOTE_VIEWER_POSITION);
    String oldText = note != null ? note.getText() : null;
    String newText = null;
    if (nodeView.getMap().showNotes()) {
        final NodeModel model = nodeView.getModel();
        final NoteModel extension = NoteModel.getNote(model);
        if (extension != null)
            newText = extension.getHtml();
    }
    if (oldText == null && newText == null) {
        return;
    }
    final ZoomableLabel view;
    if (oldText != null && newText != null) {
        view = (ZoomableLabel) nodeView.getContent(NodeView.NOTE_VIEWER_POSITION);
    } else if (oldText == null && newText != null) {
        view = NodeViewFactory.getInstance().createNoteViewer();
        nodeView.addContent(view, NodeView.NOTE_VIEWER_POSITION);
    } else {
        assert (oldText != null && newText == null);
        nodeView.removeContent(NodeView.NOTE_VIEWER_POSITION);
        return;
    }
    final MapView map = nodeView.getMap();
    view.setFont(map.getNoteFont());
    view.setForeground(map.getNoteForeground());
    view.setBackground(map.getNoteBackground());
    view.setHorizontalAlignment(map.getNoteHorizontalAlignment());
    view.updateText(newText);
    view.setMinimumWidth(minNodeWidth);
    view.setMaximumWidth(maxNodeWidth);
    view.revalidate();
    map.repaint();
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) NoteModel(org.freeplane.features.note.NoteModel)

Example 3 with NoteModel

use of org.freeplane.features.note.NoteModel in project freeplane by freeplane.

the class MNoteController method setNoteText.

public void setNoteText(final NodeModel node, final String newText) {
    final String oldText = getNoteText(node);
    if (oldText == newText || null != oldText && oldText.equals(newText)) {
        return;
    }
    final IActor actor = new IActor() {

        public void act() {
            setText(newText);
        }

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

        private void setText(final String text) {
            final boolean enabled = !(text == null || text.equals(""));
            if (enabled) {
                final NoteModel note = NoteModel.createNote(node);
                note.setHtml(text);
                node.addExtension(note);
            } else {
                if (null != node.getExtension(NoteModel.class)) {
                    node.removeExtension(NoteModel.class);
                }
            }
            Controller.getCurrentModeController().getMapController().nodeChanged(node, NodeModel.NOTE_TEXT, oldText, text);
            if (noteManager != null)
                noteManager.updateEditor();
        }

        public void undo() {
            setText(oldText);
        }
    };
    Controller.getCurrentModeController().execute(actor, node.getMap());
}
Also used : IActor(org.freeplane.core.undo.IActor) NoteModel(org.freeplane.features.note.NoteModel)

Aggregations

NoteModel (org.freeplane.features.note.NoteModel)3 NodeModel (org.freeplane.features.map.NodeModel)2 IActor (org.freeplane.core.undo.IActor)1