Search in sources :

Example 71 with IActor

use of org.freeplane.core.undo.IActor in project freeplane by freeplane.

the class MapStyle method setBackgroundColor.

public void setBackgroundColor(final MapStyleModel model, final Color color) {
    final Color actionColor = ColorUtils.makeNonTransparent(color);
    final Color oldColor = model.getBackgroundColor();
    if (actionColor == oldColor || actionColor != null && actionColor.equals(oldColor)) {
        return;
    }
    final IActor actor = new IActor() {

        public void act() {
            model.setBackgroundColor(actionColor);
            Controller.getCurrentModeController().getMapController().fireMapChanged(new MapChangeEvent(MapStyle.this, Controller.getCurrentController().getMap(), MapStyle.RESOURCES_BACKGROUND_COLOR, oldColor, actionColor));
        }

        public String getDescription() {
            return "MapStyle.setBackgroundColor";
        }

        public void undo() {
            model.setBackgroundColor(oldColor);
            Controller.getCurrentModeController().getMapController().fireMapChanged(new MapChangeEvent(MapStyle.this, Controller.getCurrentController().getMap(), MapStyle.RESOURCES_BACKGROUND_COLOR, actionColor, oldColor));
        }
    };
    Controller.getCurrentModeController().execute(actor, Controller.getCurrentController().getMap());
}
Also used : Color(java.awt.Color) IActor(org.freeplane.core.undo.IActor) MapChangeEvent(org.freeplane.features.map.MapChangeEvent)

Example 72 with IActor

use of org.freeplane.core.undo.IActor in project freeplane by freeplane.

the class MapStyle method setProperty.

public void setProperty(final MapModel model, final String key, final String newValue) {
    final MapStyleModel styleModel = MapStyleModel.getExtension(model);
    final String oldValue = styleModel.getProperty(key);
    if (oldValue == newValue || oldValue != null && oldValue.equals(newValue)) {
        return;
    }
    IActor actor = new IActor() {

        public void undo() {
            setPropertyWithoutUndo(model, key, oldValue);
        }

        public String getDescription() {
            return "set map style property";
        }

        public void act() {
            setPropertyWithoutUndo(model, key, newValue);
        }

        private void setPropertyWithoutUndo(final MapModel model, final String key, final String newValue) {
            styleModel.setProperty(key, newValue);
            Controller.getCurrentModeController().getMapController().fireMapChanged(new MapChangeEvent(MapStyle.this, model, key, oldValue, newValue));
        }
    };
    Controller.getCurrentModeController().execute(actor, model);
}
Also used : IActor(org.freeplane.core.undo.IActor) MapModel(org.freeplane.features.map.MapModel) MapChangeEvent(org.freeplane.features.map.MapChangeEvent)

Example 73 with IActor

use of org.freeplane.core.undo.IActor in project freeplane by freeplane.

the class UndoableNamedElementCollection method removeCurrentElement.

public void removeCurrentElement() {
    final int currentElementIndex = collection.getCurrentElementIndex();
    final T removedElement = collection.getCurrentElement();
    IActor actor = new IActor() {

        @Override
        public String getDescription() {
            return "removeCurrentElement";
        }

        @Override
        public void act() {
            collection.selectCurrentElement(currentElementIndex);
            collection.removeCurrentElement();
        }

        @Override
        public void undo() {
            collection.selectCurrentElement(currentElementIndex - 1);
            collection.add(removedElement);
        }
    };
    controller.execute(actor, mapModel);
}
Also used : IActor(org.freeplane.core.undo.IActor)

Example 74 with IActor

use of org.freeplane.core.undo.IActor in project freeplane by freeplane.

the class UndoableNamedElementCollection method add.

public void add(final String name) {
    final int currentElementIndex = collection.getCurrentElementIndex();
    IActor actor = new IActor() {

        @Override
        public String getDescription() {
            return "add";
        }

        @Override
        public void act() {
            collection.selectCurrentElement(currentElementIndex);
            collection.add(name);
        }

        @Override
        public void undo() {
            collection.selectCurrentElement(currentElementIndex + 1);
            collection.removeCurrentElement();
            collection.selectCurrentElement(currentElementIndex);
        }
    };
    controller.execute(actor, mapModel);
}
Also used : IActor(org.freeplane.core.undo.IActor)

Example 75 with IActor

use of org.freeplane.core.undo.IActor 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

IActor (org.freeplane.core.undo.IActor)123 NodeModel (org.freeplane.features.map.NodeModel)30 ModeController (org.freeplane.features.mode.ModeController)28 MapModel (org.freeplane.features.map.MapModel)27 MapController (org.freeplane.features.map.MapController)11 AttributeRegistry (org.freeplane.features.attribute.AttributeRegistry)10 Color (java.awt.Color)8 Point (java.awt.Point)6 MMapController (org.freeplane.features.map.mindmapmode.MMapController)6 NodeStyleModel (org.freeplane.features.nodestyle.NodeStyleModel)6 Controller (org.freeplane.features.mode.Controller)5 IStyle (org.freeplane.features.styles.IStyle)5 MapStyleModel (org.freeplane.features.styles.MapStyleModel)5 NoSuchElementException (java.util.NoSuchElementException)4 LengthUnits (org.freeplane.core.ui.LengthUnits)4 AttributeRegistryElement (org.freeplane.features.attribute.AttributeRegistryElement)4 Date (java.util.Date)3 IExtension (org.freeplane.core.extension.IExtension)3 IUndoHandler (org.freeplane.core.undo.IUndoHandler)3 EdgeModel (org.freeplane.features.edge.EdgeModel)3