Search in sources :

Example 86 with MapModel

use of org.freeplane.features.map.MapModel in project freeplane by freeplane.

the class ManageMapConditionalStylesAction method actionPerformed.

public void actionPerformed(ActionEvent e) {
    final Controller controller = Controller.getCurrentController();
    final MapModel map = controller.getMap();
    final ConditionalStyleModel conditionalStyleModel = getConditionalStyleModel();
    Component pane = createConditionalStylePane(map, conditionalStyleModel);
    Controller.getCurrentModeController().startTransaction();
    try {
        final int confirmed = JOptionPane.showConfirmDialog(controller.getMapViewManager().getMapViewComponent(), pane, TextUtils.getText(TextUtils.removeMnemonic("ManageConditionalStylesAction.text")), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
        if (JOptionPane.OK_OPTION == confirmed) {
            LogicalStyleController.getController().refreshMap(map);
            Controller.getCurrentModeController().commit();
        } else {
            Controller.getCurrentModeController().rollback();
        }
    } catch (RuntimeException ex) {
        ex.printStackTrace();
        Controller.getCurrentModeController().rollback();
    }
}
Also used : ConditionalStyleModel(org.freeplane.features.styles.ConditionalStyleModel) MapModel(org.freeplane.features.map.MapModel) LogicalStyleController(org.freeplane.features.styles.LogicalStyleController) Controller(org.freeplane.features.mode.Controller) Component(java.awt.Component)

Example 87 with MapModel

use of org.freeplane.features.map.MapModel in project freeplane by freeplane.

the class NewUserStyleAction method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    final String styleName = JOptionPane.showInputDialog(TextUtils.getText("enter_new_style_name"));
    if (styleName == null) {
        return;
    }
    final Controller controller = Controller.getCurrentController();
    final NodeModel selectedNode = controller.getSelection().getSelected();
    final MapModel map = controller.getMap();
    final MapStyleModel styleModel = MapStyleModel.getExtension(map);
    final MapModel styleMap = styleModel.getStyleMap();
    final IStyle newStyle = StyleFactory.create(styleName);
    if (null != styleModel.getStyleNode(newStyle)) {
        UITools.errorMessage(TextUtils.getText("style_already_exists"));
        return;
    }
    final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
    final NodeModel newNode = new NodeModel(styleMap);
    newNode.setUserObject(newStyle);
    final LogicalStyleController styleController = LogicalStyleController.getController();
    final ArrayList<IStyle> styles = new ArrayList<IStyle>(styleController.getStyles(selectedNode));
    for (int i = styles.size() - 1; i >= 0; i--) {
        IStyle style = styles.get(i);
        if (MapStyleModel.DEFAULT_STYLE.equals(style)) {
            continue;
        }
        final NodeModel styleNode = styleModel.getStyleNode(style);
        if (styleNode == null) {
            continue;
        }
        Controller.getCurrentModeController().copyExtensions(LogicalStyleKeys.NODE_STYLE, styleNode, newNode);
    }
    Controller.getCurrentModeController().copyExtensions(LogicalStyleKeys.NODE_STYLE, selectedNode, newNode);
    Controller.getCurrentModeController().copyExtensions(Keys.ICONS, selectedNode, newNode);
    NodeModel userStyleParentNode = styleModel.getStyleNodeGroup(styleMap, MapStyleModel.STYLES_USER_DEFINED);
    if (userStyleParentNode == null) {
        userStyleParentNode = new NodeModel(styleMap);
        userStyleParentNode.setUserObject(new StyleTranslatedObject(MapStyleModel.STYLES_USER_DEFINED));
        mapController.insertNode(userStyleParentNode, styleMap.getRootNode(), false, false, true);
    }
    mapController.insertNode(newNode, userStyleParentNode, false, false, true);
    mapController.select(newNode);
    final IActor actor = new IActor() {

        public void undo() {
            styleModel.removeStyleNode(newNode);
            styleController.refreshMap(map);
        }

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

        public void act() {
            styleModel.addStyleNode(newNode);
            styleController.refreshMap(map);
        }
    };
    Controller.getCurrentModeController().execute(actor, styleMap);
}
Also used : MapStyleModel(org.freeplane.features.styles.MapStyleModel) MMapController(org.freeplane.features.map.mindmapmode.MMapController) LogicalStyleController(org.freeplane.features.styles.LogicalStyleController) ArrayList(java.util.ArrayList) MapModel(org.freeplane.features.map.MapModel) Controller(org.freeplane.features.mode.Controller) LogicalStyleController(org.freeplane.features.styles.LogicalStyleController) MMapController(org.freeplane.features.map.mindmapmode.MMapController) IStyle(org.freeplane.features.styles.IStyle) StyleTranslatedObject(org.freeplane.features.styles.StyleTranslatedObject) NodeModel(org.freeplane.features.map.NodeModel) IActor(org.freeplane.core.undo.IActor)

Example 88 with MapModel

use of org.freeplane.features.map.MapModel in project freeplane by freeplane.

the class MTextController method setImageByFileChooser.

public void setImageByFileChooser() {
    boolean picturesAmongSelecteds = false;
    final ModeController modeController = Controller.getCurrentModeController();
    for (final NodeModel node : modeController.getMapController().getSelectedNodes()) {
        final URI link = NodeLinks.getLink(node);
        if (link != null) {
            final String linkString = link.toString();
            final String lowerCase = linkString.toLowerCase();
            if (lowerCase.endsWith(".png") || lowerCase.endsWith(".jpg") || lowerCase.endsWith(".jpeg") || lowerCase.endsWith(".gif")) {
                picturesAmongSelecteds = true;
                final String encodedLinkString = HtmlUtils.unicodeToHTMLUnicodeEntity(linkString);
                final String strText = "<html><img src=\"" + encodedLinkString + "\">";
                ((MLinkController) LinkController.getController()).setLink(node, (URI) null, LinkController.LINK_ABSOLUTE);
                setNodeText(node, strText);
            }
        }
    }
    if (picturesAmongSelecteds) {
        return;
    }
    final Controller controller = modeController.getController();
    final ViewController viewController = controller.getViewController();
    final NodeModel selectedNode = modeController.getMapController().getSelectedNode();
    final MapModel map = selectedNode.getMap();
    final File file = map.getFile();
    if (file == null && LinkController.getLinkType() == LinkController.LINK_RELATIVE_TO_MINDMAP) {
        JOptionPane.showMessageDialog(viewController.getCurrentRootComponent(), TextUtils.getText("not_saved_for_image_error"), "Freeplane", JOptionPane.WARNING_MESSAGE);
        return;
    }
    final ExampleFileFilter filter = new ExampleFileFilter();
    filter.addExtension("jpg");
    filter.addExtension("jpeg");
    filter.addExtension("png");
    filter.addExtension("gif");
    filter.setDescription(TextUtils.getText("bitmaps"));
    final UrlManager urlManager = modeController.getExtension(UrlManager.class);
    final JFileChooser chooser = urlManager.getFileChooser(null, false);
    chooser.setFileFilter(filter);
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setAccessory(new BitmapImagePreview(chooser));
    final int returnVal = chooser.showOpenDialog(viewController.getCurrentRootComponent());
    if (returnVal != JFileChooser.APPROVE_OPTION) {
        return;
    }
    final File input = chooser.getSelectedFile();
    URI uri = input.toURI();
    if (uri == null) {
        return;
    }
    // bad hack: try to interpret file as http link
    if (!input.exists()) {
        uri = LinkController.toRelativeURI(map.getFile(), input, LinkController.LINK_RELATIVE_TO_MINDMAP);
        if (uri == null || !"http".equals(uri.getScheme())) {
            UITools.errorMessage(TextUtils.format("file_not_found", input.toString()));
            return;
        }
    } else if (LinkController.getLinkType() != LinkController.LINK_ABSOLUTE) {
        uri = LinkController.toLinkTypeDependantURI(map.getFile(), input);
    }
    String uriString = uri.toString();
    if (uriString.startsWith("http:/")) {
        uriString = "http://" + uriString.substring("http:/".length());
    }
    final String strText = "<html><img src=\"" + uriString + "\">";
    setNodeText(selectedNode, strText);
}
Also used : UrlManager(org.freeplane.features.url.UrlManager) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) MapModel(org.freeplane.features.map.MapModel) MMapController(org.freeplane.features.map.mindmapmode.MMapController) MapController(org.freeplane.features.map.MapController) MIconController(org.freeplane.features.icon.mindmapmode.MIconController) IconController(org.freeplane.features.icon.IconController) Controller(org.freeplane.features.mode.Controller) TextController(org.freeplane.features.text.TextController) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) NodeStyleController(org.freeplane.features.nodestyle.NodeStyleController) FormatController(org.freeplane.features.format.FormatController) LogicalStyleController(org.freeplane.features.styles.LogicalStyleController) ResourceController(org.freeplane.core.resources.ResourceController) ViewController(org.freeplane.features.ui.ViewController) LinkController(org.freeplane.features.link.LinkController) ModeController(org.freeplane.features.mode.ModeController) MNodeStyleController(org.freeplane.features.nodestyle.mindmapmode.MNodeStyleController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) ScannerController(org.freeplane.features.format.ScannerController) URI(java.net.URI) NodeModel(org.freeplane.features.map.NodeModel) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) JFileChooser(javax.swing.JFileChooser) ViewController(org.freeplane.features.ui.ViewController) BitmapImagePreview(org.freeplane.core.ui.components.BitmapImagePreview) ExampleFileFilter(org.freeplane.core.ui.ExampleFileFilter) File(java.io.File)

Example 89 with MapModel

use of org.freeplane.features.map.MapModel in project freeplane by freeplane.

the class StyleControlGroup method addEdgeColoringControls.

private void addEdgeColoringControls(final DefaultFormBuilder formBuilder) {
    TranslatedObject[] automaticLayoutTypes = TranslatedObject.fromEnum(AutomaticEdgeColor.class.getSimpleName() + ".", AutomaticEdgeColor.Rule.class);
    mAutomaticEdgeColorComboBox = new JComboBoxWithBorder(automaticLayoutTypes);
    DefaultComboBoxModel automaticEdgeColorComboBoxModel = (DefaultComboBoxModel) mAutomaticEdgeColorComboBox.getModel();
    automaticEdgeColorComboBoxModel.addElement(AUTOMATIC_LAYOUT_DISABLED);
    automaticEdgeColorComboBoxModel.setSelectedItem(AUTOMATIC_LAYOUT_DISABLED);
    mAutomaticEdgeColorComboBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (internalChange)
                return;
            final ModeController modeController = Controller.getCurrentModeController();
            AutomaticEdgeColorHook hook = modeController.getExtension(AutomaticEdgeColorHook.class);
            TranslatedObject selectedItem = (TranslatedObject) mAutomaticEdgeColorComboBox.getSelectedItem();
            final MapModel map = Controller.getCurrentController().getMap();
            final AutomaticEdgeColor oldExtension = (AutomaticEdgeColor) hook.getMapHook(map);
            final int colorCount = oldExtension == null ? 0 : oldExtension.getColorCounter();
            final NodeModel rootNode = map.getRootNode();
            hook.undoableDeactivateHook(rootNode);
            if (!selectedItem.equals(AUTOMATIC_LAYOUT_DISABLED)) {
                final AutomaticEdgeColor newExtension = new AutomaticEdgeColor((AutomaticEdgeColor.Rule) selectedItem.getObject(), colorCount);
                hook.undoableActivateHook(rootNode, newExtension);
            }
        }
    });
    appendLabeledComponent(formBuilder, "AutomaticEdgeColorHookAction.text", mAutomaticEdgeColorComboBox);
    mEditEdgeColorsBtn = TranslatedElementFactory.createButton("editEdgeColors");
    mEditEdgeColorsBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final MEdgeController edgeController = (MEdgeController) modeController.getExtension(EdgeController.class);
            edgeController.editEdgeColorConfiguration(Controller.getCurrentController().getMap());
        }
    });
    formBuilder.appendLineGapRow();
    formBuilder.nextLine();
    formBuilder.appendRow(FormSpecs.PREF_ROWSPEC);
    formBuilder.setColumn(1);
    formBuilder.append(mEditEdgeColorsBtn, 7);
    formBuilder.nextLine();
}
Also used : AutomaticEdgeColorHook(org.freeplane.features.edge.AutomaticEdgeColorHook) ActionEvent(java.awt.event.ActionEvent) TranslatedObject(org.freeplane.core.resources.TranslatedObject) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ModeController(org.freeplane.features.mode.ModeController) MapModel(org.freeplane.features.map.MapModel) AutomaticEdgeColor(org.freeplane.features.edge.AutomaticEdgeColor) NodeModel(org.freeplane.features.map.NodeModel) ActionListener(java.awt.event.ActionListener) JComboBoxWithBorder(org.freeplane.core.ui.components.JComboBoxWithBorder) MEdgeController(org.freeplane.features.edge.mindmapmode.MEdgeController)

Example 90 with MapModel

use of org.freeplane.features.map.MapModel in project freeplane by freeplane.

the class XmlImporter method newMap.

private void newMap(final InputStream in, final File outputFile) throws IOException, XMLException, MalformedURLException {
    final Reader reader = new XsltPipeReaderFactory(xsltResource).getReader(in);
    final ModeController modeController = Controller.getCurrentModeController();
    final MapController mapController = modeController.getMapController();
    final MapModel map = new MMapModel();
    modeController.getMapController().getMapReader().createNodeTreeFromXml(map, reader, Mode.FILE);
    final URL mapUrl = Compat.fileToUrl(outputFile);
    map.setURL(mapUrl);
    map.setSaved(false);
    mapController.fireMapCreated(map);
    mapController.newMapView(map);
}
Also used : MMapModel(org.freeplane.features.map.mindmapmode.MMapModel) Reader(java.io.Reader) ModeController(org.freeplane.features.mode.ModeController) MMapModel(org.freeplane.features.map.mindmapmode.MMapModel) MapModel(org.freeplane.features.map.MapModel) XsltPipeReaderFactory(org.freeplane.core.util.XsltPipeReaderFactory) URL(java.net.URL) MapController(org.freeplane.features.map.MapController)

Aggregations

MapModel (org.freeplane.features.map.MapModel)143 NodeModel (org.freeplane.features.map.NodeModel)47 ModeController (org.freeplane.features.mode.ModeController)35 Controller (org.freeplane.features.mode.Controller)31 IActor (org.freeplane.core.undo.IActor)27 MMapModel (org.freeplane.features.map.mindmapmode.MMapModel)16 LogicalStyleController (org.freeplane.features.styles.LogicalStyleController)16 IUndoHandler (org.freeplane.core.undo.IUndoHandler)15 AttributeRegistry (org.freeplane.features.attribute.AttributeRegistry)14 IStyle (org.freeplane.features.styles.IStyle)14 File (java.io.File)13 MMapController (org.freeplane.features.map.mindmapmode.MMapController)13 URL (java.net.URL)12 MModeController (org.freeplane.features.mode.mindmapmode.MModeController)11 MapStyleModel (org.freeplane.features.styles.MapStyleModel)10 IMapViewManager (org.freeplane.features.ui.IMapViewManager)10 MapController (org.freeplane.features.map.MapController)9 URI (java.net.URI)8 ResourceController (org.freeplane.core.resources.ResourceController)8 IOException (java.io.IOException)7