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