net.sourceforge.plantuml.salt.Positionner2 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plantuml-mit Show documentation
Show all versions of plantuml-mit Show documentation
PlantUML is a component that allows to quickly write diagrams from text.
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
package net.sourceforge.plantuml.salt;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import net.sourceforge.plantuml.salt.element.Element;
public class Positionner2 {
private int row;
private int col;
private int maxRow;
private int maxCol;
private final Map positions = new LinkedHashMap();
private Cell last;
public void add(Terminated element) {
addWithoutMove(element.getElement());
final Terminator terminator = element.getTerminator();
if (terminator == Terminator.NEWCOL) {
moveNextColumn();
} else {
moveNextRow();
}
}
private void moveNextColumn() {
col++;
}
private void moveNextRow() {
row++;
col = 0;
}
private void addWithoutMove(Element elmt) {
last = new Cell(row, col);
positions.put(elmt, last);
updateMax();
}
public void mergeLeft(Terminator terminator) {
updateMax();
if (terminator == Terminator.NEWCOL) {
col++;
} else {
row++;
col = 0;
}
last.mergeLeft();
}
private void updateMax() {
if (row > maxRow) {
maxRow = row;
}
if (col > maxCol) {
maxCol = col;
}
}
public Map getAll() {
return Collections.unmodifiableMap(positions);
}
public final int getNbRows() {
return maxRow + 1;
}
public final int getNbCols() {
return maxCol + 1;
}
}