Search in sources :

Example 1 with ExtraFile

use of com.igormaznitsa.mindmap.model.ExtraFile in project netbeans-mmd-plugin by raydac.

the class MapUtils method findTopicsRelatedToFile.

@Nonnull
@MustNotContainNull
public static List<Topic> findTopicsRelatedToFile(@Nullable final File baseFolder, @Nonnull final File file, @Nonnull final MindMap map) {
    final List<Topic> result = new ArrayList<>();
    final Path theFile = file.isAbsolute() ? file.toPath() : new File(baseFolder, file.getAbsolutePath()).toPath();
    final boolean folder = file.isDirectory();
    for (final Topic t : map) {
        final ExtraFile linkToFile = (ExtraFile) t.getExtras().get(Extra.ExtraType.FILE);
        if (linkToFile != null) {
            final MMapURI uri = linkToFile.getAsURI();
            final Path linkFile = uri.asFile(baseFolder).toPath();
            if (folder) {
                if (linkFile.startsWith(theFile)) {
                    result.add(t);
                }
            } else if (linkFile.equals(theFile)) {
                result.add(t);
            }
        }
    }
    return result;
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) Topic(com.igormaznitsa.mindmap.model.Topic) File(java.io.File) ExtraFile(com.igormaznitsa.mindmap.model.ExtraFile) MMapURI(com.igormaznitsa.mindmap.model.MMapURI) ExtraFile(com.igormaznitsa.mindmap.model.ExtraFile) Nonnull(javax.annotation.Nonnull) MustNotContainNull(com.igormaznitsa.meta.annotation.MustNotContainNull)

Example 2 with ExtraFile

use of com.igormaznitsa.mindmap.model.ExtraFile in project netbeans-mmd-plugin by raydac.

the class IconBlock method paint.

public void paint(@Nonnull final MMGraphics gfx) {
    final int numberOfIcons = this.model.getNumberOfExtras();
    if (numberOfIcons != 0) {
        double offsetX = this.bounds.getX();
        final int offsetY = (int) Math.round(this.bounds.getY());
        final double scaledIconWidth = ScalableIcon.BASE_WIDTH * this.scale;
        for (final Extra<?> e : this.currentExtras) {
            final ScalableIcon ico;
            switch(e.getType()) {
                case FILE:
                    ico = findIconForFileType((ExtraFile) e);
                    break;
                case LINK:
                    final String uri = ((ExtraLink) e).getAsString();
                    ico = uri.startsWith("mailto:") ? ScalableIcon.LINK_EMAIL : ScalableIcon.LINK;
                    break;
                case NOTE:
                    ico = ScalableIcon.TEXT;
                    break;
                case TOPIC:
                    ico = ScalableIcon.TOPIC;
                    break;
                default:
                    // NOI18N
                    throw new Error("Unexpected extras");
            }
            if (scaledIconWidth >= 1.0d) {
                gfx.drawImage(ico.getImage(this.scale), (int) Math.round(offsetX), offsetY);
                offsetX += scaledIconWidth;
            }
        }
    }
}
Also used : ScalableIcon(com.igormaznitsa.mindmap.swing.panel.utils.ScalableIcon) ExtraFile(com.igormaznitsa.mindmap.model.ExtraFile) ExtraLink(com.igormaznitsa.mindmap.model.ExtraLink)

Example 3 with ExtraFile

use of com.igormaznitsa.mindmap.model.ExtraFile in project netbeans-mmd-plugin by raydac.

the class ExplorerTree method addTreeAsTopic.

private void addTreeAsTopic(@Nullable final NodeProject project, @Nonnull final NodeFileOrFolder node, @Nonnull final MMDEditor editor) {
    final File projectFolder = project == null ? null : project.getFolder();
    if (project != null) {
        if (node.findProject() != project) {
            if (!DialogProviderManager.getInstance().getDialogProvider().msgConfirmOkCancel(null, "Different projects", "Opened Map file from another project. File paths will not be relative ones.")) {
                return;
            }
        }
    }
    final List<Topic> targetTopics = new ArrayList<>(Arrays.asList(editor.getMindMapPanel().getSelectedTopics()));
    if (targetTopics.size() > 1) {
        if (!DialogProviderManager.getInstance().getDialogProvider().msgConfirmOkCancel(null, "Multiple selection detected", "New children will be generated for all focused topics.")) {
            return;
        }
    } else {
        if (targetTopics.isEmpty() && editor.getMindMapPanel().getModel().getRoot() != null) {
            if (!DialogProviderManager.getInstance().getDialogProvider().msgConfirmOkCancel(null, "No selected parent", "There is not selected topic. The Root will be used as the parent.")) {
                return;
            }
            targetTopics.add(editor.getMindMapPanel().getModel().getRoot());
        }
    }
    editor.getMindMapPanel().executeModelJobs(new MindMapPanel.ModelJob() {

        @Nonnull
        private Topic recursiveGenerateTopics(@Nullable final File projectFolder, @Nonnull final MindMap model, @Nullable final Topic parent, @Nonnull final NodeFileOrFolder node) {
            final ExtraFile fileLink = new ExtraFile(new MMapURI(projectFolder, node.makeFileForNode(), null));
            final Topic theTopic;
            if (parent == null) {
                theTopic = new Topic(model, null, node.toString(), fileLink);
            } else {
                theTopic = parent.makeChild(node.toString(), null);
                theTopic.setExtra(fileLink);
            }
            if (!node.isLeaf()) {
                final Enumeration<NodeFileOrFolder> children = node.children();
                while (children.hasMoreElements()) {
                    recursiveGenerateTopics(projectFolder, model, theTopic, children.nextElement());
                }
            }
            return theTopic;
        }

        @Override
        public boolean doChangeModel(@Nonnull final MindMap model) {
            Topic createdTopic = null;
            if (targetTopics.isEmpty()) {
                createdTopic = recursiveGenerateTopics(projectFolder, model, null, node);
            } else {
                boolean first = true;
                for (final Topic t : targetTopics) {
                    final Topic generated = recursiveGenerateTopics(projectFolder, model, t, node);
                    if (first) {
                        createdTopic = generated;
                    }
                    first = false;
                }
            }
            if (editor.getMindMapPanel().getSelectedTopics().length == 0 && createdTopic != null) {
                final Topic forfocus = createdTopic;
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        editor.getMindMapPanel().focusTo(forfocus);
                    }
                });
            }
            return true;
        }
    });
}
Also used : MindMap(com.igormaznitsa.mindmap.model.MindMap) Enumeration(java.util.Enumeration) Nonnull(javax.annotation.Nonnull) ArrayList(java.util.ArrayList) MindMapPanel(com.igormaznitsa.mindmap.swing.panel.MindMapPanel) MMapURI(com.igormaznitsa.mindmap.model.MMapURI) Topic(com.igormaznitsa.mindmap.model.Topic) ExtraFile(com.igormaznitsa.mindmap.model.ExtraFile) File(java.io.File) ExtraFile(com.igormaznitsa.mindmap.model.ExtraFile)

Aggregations

ExtraFile (com.igormaznitsa.mindmap.model.ExtraFile)3 MMapURI (com.igormaznitsa.mindmap.model.MMapURI)2 Topic (com.igormaznitsa.mindmap.model.Topic)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Nonnull (javax.annotation.Nonnull)2 MustNotContainNull (com.igormaznitsa.meta.annotation.MustNotContainNull)1 ExtraLink (com.igormaznitsa.mindmap.model.ExtraLink)1 MindMap (com.igormaznitsa.mindmap.model.MindMap)1 MindMapPanel (com.igormaznitsa.mindmap.swing.panel.MindMapPanel)1 ScalableIcon (com.igormaznitsa.mindmap.swing.panel.utils.ScalableIcon)1 Path (java.nio.file.Path)1 Enumeration (java.util.Enumeration)1