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;
}
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;
}
}
}
}
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;
}
});
}
Aggregations