Search in sources :

Example 26 with Topic

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

the class ElementRoot method calcBlockSize.

@Override
@Nonnull
public Dimension2D calcBlockSize(@Nonnull final MindMapPanelConfig cfg, @Nonnull final Dimension2D size, final boolean childrenOnly) {
    final double insetV = cfg.getScale() * cfg.getFirstLevelVerticalInset();
    final double insetH = cfg.getScale() * cfg.getFirstLevelHorizontalInset();
    final Dimension2D result = size;
    double leftWidth = 0.0d;
    double leftHeight = 0.0d;
    double rightWidth = 0.0d;
    double rightHeight = 0.0d;
    boolean nonfirstOnLeft = false;
    boolean nonfirstOnRight = false;
    for (final Topic t : this.model.getChildren()) {
        final ElementLevelFirst w = assertNotNull((ElementLevelFirst) t.getPayload());
        w.calcBlockSize(cfg, result, false);
        if (w.isLeftDirection()) {
            leftWidth = Math.max(leftWidth, result.getWidth());
            leftHeight += result.getHeight();
            if (nonfirstOnLeft) {
                leftHeight += insetV;
            } else {
                nonfirstOnLeft = true;
            }
        } else {
            rightWidth = Math.max(rightWidth, result.getWidth());
            rightHeight += result.getHeight();
            if (nonfirstOnRight) {
                rightHeight += insetV;
            } else {
                nonfirstOnRight = true;
            }
        }
    }
    if (!childrenOnly) {
        leftWidth += nonfirstOnLeft ? insetH : 0.0d;
        rightWidth += nonfirstOnRight ? insetH : 0.0d;
    }
    this.leftBlockSize.setSize(leftWidth, leftHeight);
    this.rightBlockSize.setSize(rightWidth, rightHeight);
    if (childrenOnly) {
        result.setSize(leftWidth + rightWidth, Math.max(leftHeight, rightHeight));
    } else {
        result.setSize(leftWidth + rightWidth + this.bounds.getWidth(), Math.max(this.bounds.getHeight(), Math.max(leftHeight, rightHeight)));
    }
    return result;
}
Also used : Dimension2D(java.awt.geom.Dimension2D) Topic(com.igormaznitsa.mindmap.model.Topic) Nonnull(javax.annotation.Nonnull)

Example 27 with Topic

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

the class MindMapUtils method isTopicVisible.

public static boolean isTopicVisible(@Nonnull final Topic topic) {
    boolean result = true;
    Topic current = topic.getParent();
    while (current != null) {
        if (isCollapsed(current)) {
            result = false;
            break;
        }
        current = current.getParent();
    }
    return result;
}
Also used : Topic(com.igormaznitsa.mindmap.model.Topic)

Example 28 with Topic

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

the class MindMapUtils method removeSuccessorsAndDuplications.

/**
 * Remove duplications and successors for presented topics in array.
 * @param topics array to be processed
 * @return resulted array
 * @since 1.3.1
 */
@Nonnull
@MustNotContainNull
public static Topic[] removeSuccessorsAndDuplications(@Nonnull @MustNotContainNull final Topic... topics) {
    final List<Topic> result = new ArrayList<Topic>();
    for (final Topic t : topics) {
        final Iterator<Topic> iterator = result.iterator();
        while (iterator.hasNext()) {
            final Topic listed = iterator.next();
            if (listed == t || listed.hasAncestor(t)) {
                iterator.remove();
            }
        }
        result.add(t);
    }
    return result.toArray(new Topic[result.size()]);
}
Also used : ArrayList(java.util.ArrayList) Topic(com.igormaznitsa.mindmap.model.Topic) Nonnull(javax.annotation.Nonnull) MustNotContainNull(com.igormaznitsa.meta.annotation.MustNotContainNull)

Example 29 with Topic

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

the class MindMapUtils method ensureVisibility.

public static boolean ensureVisibility(@Nonnull final Topic topic) {
    boolean result = false;
    Topic current = topic.getParent();
    while (current != null) {
        if (isCollapsed(current)) {
            result |= setCollapsed(current, false);
        }
        current = current.getParent();
    }
    return result;
}
Also used : Topic(com.igormaznitsa.mindmap.model.Topic)

Example 30 with Topic

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

the class MindMapUtils method findFirstVisibleAncestor.

@Nullable
public static Topic findFirstVisibleAncestor(@Nullable final Topic topic) {
    if (topic == null) {
        return null;
    }
    final Topic[] path = topic.getPath();
    Topic lastVisible = null;
    if (path.length > 0) {
        for (final Topic t : path) {
            lastVisible = t;
            final boolean collapsed = Boolean.parseBoolean(t.getAttribute(ATTR_COLLAPSED.getText()));
            if (collapsed) {
                break;
            }
        }
    }
    return lastVisible;
}
Also used : Topic(com.igormaznitsa.mindmap.model.Topic) Nullable(javax.annotation.Nullable)

Aggregations

Topic (com.igormaznitsa.mindmap.model.Topic)34 Nonnull (javax.annotation.Nonnull)10 Nullable (javax.annotation.Nullable)10 MindMap (com.igormaznitsa.mindmap.model.MindMap)9 ArrayList (java.util.ArrayList)6 File (java.io.File)5 MustNotContainNull (com.igormaznitsa.meta.annotation.MustNotContainNull)3 ExtraFile (com.igormaznitsa.mindmap.model.ExtraFile)3 Dimension2D (java.awt.geom.Dimension2D)3 DefaultTreeCellRenderer (javax.swing.tree.DefaultTreeCellRenderer)3 ExtraTopic (com.igormaznitsa.mindmap.model.ExtraTopic)2 MMapURI (com.igormaznitsa.mindmap.model.MMapURI)2 MindMapPanel (com.igormaznitsa.mindmap.swing.panel.MindMapPanel)2 AbstractCollapsableElement (com.igormaznitsa.mindmap.swing.panel.ui.AbstractCollapsableElement)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 Element (org.w3c.dom.Element)2 Extra (com.igormaznitsa.mindmap.model.Extra)1 ExtraNote (com.igormaznitsa.mindmap.model.ExtraNote)1 MindMapController (com.igormaznitsa.mindmap.model.MindMapController)1