use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.
the class MFileManager method save.
/**
*@deprecated -- use MMapIO
*/
@Deprecated
public boolean save(final MapModel map, final File file) {
if (file == null) {
return saveAs(map);
}
try {
if (null == map.getExtension(BackupFlag.class)) {
map.addExtension(new BackupFlag());
backup(file);
}
final String lockingUser = tryToLock(map, file);
if (lockingUser != null) {
UITools.informationMessage(Controller.getCurrentController().getViewController().getCurrentRootComponent(), TextUtils.format("map_locked_by_save_as", file.getName(), lockingUser));
return false;
}
} catch (final Exception e) {
UITools.informationMessage(Controller.getCurrentController().getViewController().getCurrentRootComponent(), TextUtils.format("locking_failed_by_save_as", file.getName()));
return false;
}
final URL urlBefore = map.getURL();
final boolean saved = saveInternal((MMapModel) map, file, false);
if (!saved) {
return false;
}
map.setReadOnly(false);
final URL urlAfter = map.getURL();
final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
mapController.fireMapChanged(new MapChangeEvent(this, map, UrlManager.MAP_URL, urlBefore, urlAfter));
mapController.setSaved(map, true);
return true;
}
use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.
the class MModeControllerFactory method createAddIns.
private void createAddIns() {
final StyleEditorPanel panel = new StyleEditorPanel(modeController, uiFactory, true);
final JScrollPane styleScrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
UITools.setScrollbarIncrement(styleScrollPane);
final JComponent tabs = (JComponent) modeController.getUserInputListenerFactory().getToolBar("/format").getComponent(1);
tabs.add(TextUtils.getText("format_panel"), styleScrollPane);
new AttributePanelManager(modeController);
new HierarchicalIcons();
new AutomaticLayoutController();
new BlinkingNodeHook();
SummaryNode.install();
final MMapController mapController = (MMapController) modeController.getMapController();
mapController.addMapLifeCycleListener(new SummaryNodeMapUpdater(modeController, mapController));
final AlwaysUnfoldedNode alwaysUnfoldedNode = new AlwaysUnfoldedNode();
modeController.addAction(new SetAlwaysUnfoldedNodeFlagsAction(alwaysUnfoldedNode));
modeController.addAction(new RemoveAllAlwaysUnfoldedNodeFlagsAction(alwaysUnfoldedNode));
FreeNode.install();
new CreationModificationDatePresenter();
modeController.addExtension(ReminderHook.class, new ReminderHook(modeController));
new AutomaticEdgeColorHook();
new ViewerController();
PresentationController.install(modeController);
modeController.addAction(new AddAttributeAction());
modeController.addAction(new RemoveFirstAttributeAction());
modeController.addAction(new RemoveLastAttributeAction());
modeController.addAction(new RemoveAllAttributesAction());
modeController.addAction(new AddExternalImageAction());
modeController.addAction(new RemoveExternalImageAction());
modeController.addAction(new ChangeExternalImageAction());
modeController.addAction(new ShowFormatPanelAction());
modeController.addAction(new FitToPage());
modeController.addAction(new UpdateCheckAction());
MEncryptionController.install(new MEncryptionController(modeController));
modeController.addAction(new IconSelectionPlugin());
modeController.addAction(new NewParentNode());
modeController.addAction(new SaveAll());
modeController.addAction(new SortNodes());
modeController.addAction(new SplitNode());
new ChangeNodeLevelController(modeController);
NodeHistory.install(modeController);
modeController.addAction(new ImportXmlFile());
modeController.addAction(new ImportMindmanagerFiles());
}
use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.
the class DeleteLevelStyleAction method actionPerformed.
public void actionPerformed(final ActionEvent e) {
final SModeController modeController = (SModeController) Controller.getCurrentModeController();
final MapModel map = Controller.getCurrentController().getMap();
final MapStyleModel styleModel = MapStyleModel.getExtension(map);
NodeModel levelStyleParentNode = styleModel.getStyleNodeGroup(map, MapStyleModel.STYLES_AUTOMATIC_LAYOUT);
final int childNumber = levelStyleParentNode.getChildCount() - 1;
if (childNumber < 1) {
UITools.errorMessage(TextUtils.getText("can_not_delete_root_style"));
return;
}
final String styleName = "AutomaticLayout.level," + childNumber;
final IStyle styleObject = StyleFactory.create(TranslatedObject.format(styleName));
final MMapController mapController = (MMapController) modeController.getMapController();
final NodeModel node = styleModel.getStyleNode(styleObject);
mapController.deleteNode(node);
final IActor actor = new IActor() {
public void undo() {
styleModel.addStyleNode(node);
}
public String getDescription() {
return "DeleteStyle";
}
public void act() {
styleModel.removeStyleNode(node);
}
};
Controller.getCurrentModeController().execute(actor, map);
}
use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.
the class ExportBranchAction method actionPerformed.
public void actionPerformed(final ActionEvent e) {
final NodeModel existingNode = Controller.getCurrentModeController().getMapController().getSelectedNode();
final Controller controller = Controller.getCurrentController();
final MapModel parentMap = controller.getMap();
if (parentMap == null || existingNode == null || existingNode.isRoot()) {
controller.getViewController().err("Could not export branch.");
return;
}
if (parentMap.getFile() == null) {
controller.getViewController().out("You must save the current map first!");
((MModeController) Controller.getCurrentModeController()).save();
}
JFileChooser chooser;
final File file = parentMap.getFile();
if (file == null) {
return;
}
chooser = new JFileChooser(file.getParentFile());
chooser.setSelectedFile(new File(createFileName(TextController.getController().getShortPlainText(existingNode))));
if (((MFileManager) UrlManager.getController()).getFileFilter() != null) {
chooser.addChoosableFileFilter(((MFileManager) UrlManager.getController()).getFileFilter());
}
final int returnVal = chooser.showSaveDialog(controller.getViewController().getCurrentRootComponent());
if (returnVal == JFileChooser.APPROVE_OPTION) {
File chosenFile = chooser.getSelectedFile();
final String ext = FileUtils.getExtension(chosenFile.getName());
if (!ext.equals(org.freeplane.features.url.UrlManager.FREEPLANE_FILE_EXTENSION_WITHOUT_DOT)) {
chosenFile = new File(chosenFile.getParent(), chosenFile.getName() + org.freeplane.features.url.UrlManager.FREEPLANE_FILE_EXTENSION);
}
try {
Compat.fileToUrl(chosenFile);
} catch (final MalformedURLException ex) {
UITools.errorMessage(TextUtils.getText("invalid_url"));
return;
}
if (chosenFile.exists()) {
final int overwriteMap = JOptionPane.showConfirmDialog(controller.getMapViewManager().getMapViewComponent(), TextUtils.getText("map_already_exists"), "Freeplane", JOptionPane.YES_NO_OPTION);
if (overwriteMap != JOptionPane.YES_OPTION) {
return;
}
}
/*
* Now make a copy from the node, remove the node from the map and
* create a new Map with the node as root, store the new Map, add
* the copy of the node to the parent, and set a link from the copy
* to the new Map.
*/
final NodeModel parent = existingNode.getParentNode();
final File oldFile = parentMap.getFile();
final URI newUri = LinkController.toLinkTypeDependantURI(oldFile, chosenFile);
final URI oldUri = LinkController.toLinkTypeDependantURI(chosenFile, file);
((MLinkController) LinkController.getController()).setLink(existingNode, oldUri, LinkController.LINK_ABSOLUTE);
final int nodePosition = parent.getIndex(existingNode);
final ModeController modeController = Controller.getCurrentModeController();
modeController.undoableResolveParentExtensions(LogicalStyleKeys.NODE_STYLE, existingNode);
final MMapController mMapController = (MMapController) modeController.getMapController();
mMapController.deleteNode(existingNode);
{
final IActor actor = new IActor() {
private final boolean wasFolded = existingNode.isFolded();
public void undo() {
PersistentNodeHook.removeMapExtensions(existingNode);
existingNode.setMap(parentMap);
existingNode.setFolded(wasFolded);
}
public String getDescription() {
return "ExportBranchAction";
}
public void act() {
existingNode.setFolded(false);
}
};
Controller.getCurrentModeController().execute(actor, parentMap);
}
mMapController.newModel(existingNode);
final MapModel newMap = existingNode.getMap();
IExtension[] oldExtensions = newMap.getRootNode().getSharedExtensions().values().toArray(new IExtension[] {});
for (final IExtension extension : oldExtensions) {
final Class<? extends IExtension> clazz = extension.getClass();
if (MapExtensions.isMapExtension(clazz)) {
existingNode.removeExtension(clazz);
}
}
final Collection<IExtension> newExtensions = parentMap.getRootNode().getSharedExtensions().values();
for (final IExtension extension : newExtensions) {
final Class<? extends IExtension> clazz = extension.getClass();
if (MapExtensions.isMapExtension(clazz)) {
existingNode.addExtension(extension);
}
}
((MFileManager) UrlManager.getController()).save(newMap, chosenFile);
final NodeModel newNode = mMapController.addNewNode(parent, nodePosition, existingNode.isLeft());
((MTextController) TextController.getController()).setNodeText(newNode, existingNode.getText());
modeController.undoableCopyExtensions(LogicalStyleKeys.NODE_STYLE, existingNode, newNode);
newMap.getFile();
((MLinkController) LinkController.getController()).setLink(newNode, newUri, LinkController.LINK_ABSOLUTE);
newMap.destroy();
existingNode.setParent(null);
mMapController.select(newNode);
}
}
use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.
the class RevertAction method actionPerformed.
/*
* (non-Javadoc)
* @see
* java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(final ActionEvent ev) {
Controller controller = Controller.getCurrentController();
final MMapController mapController = (MMapController) controller.getModeController().getMapController();
try {
mapController.restoreCurrentMap();
} catch (final Exception e) {
LogUtils.severe(e);
}
}
Aggregations