Skip to content
Snippets Groups Projects
Commit d886f81e authored by Leonard Kupper's avatar Leonard Kupper
Browse files

Update from master.

parents 03da4ee9 f7dddf25
No related branches found
No related tags found
1 merge request!39App restructuring
......@@ -8,8 +8,8 @@ import java.util.Objects;
/**
* Simple representation of a legend.
* @author Leonard Kupper
* @version 2019.08.29
* @author Leonard Kupper, Andrey Ruzhanskiy
* @version 2019.09.25
*/
public class Legend implements Renderable {
......@@ -17,7 +17,9 @@ public class Legend implements Renderable {
private BrailleLanguage.Language mLanguage;
private Map<String, Map<String, String>> mStringExplanationLists = new LinkedHashMap<>();
private Map<String, Map<Texture<Boolean>, String>> mTextureExplanationLists = new LinkedHashMap<>();
private String mColumnViewTitle;
private Map<String, Map<String, String>> mColumnView = new LinkedHashMap<>();
private int mTextureExampleWidthCells = 1;
private int mTextureExampleHeightCells = 1;
......@@ -85,6 +87,40 @@ public class Legend implements Renderable {
mStringExplanationLists.get(groupName).put(symbol, descriptionText);
}
/**
* Add a column to the columnview.
* @param columnName Name of column.
* @param explanations {@link Map} of symbols and descriptions inside the column.
*/
public void addColumn(final String columnName, final Map<String, String> explanations) {
mColumnView.put(columnName, explanations);
}
/**
* Set the columnview title.
* @param columnViewTitle The title for the columnview.
*/
public void setColumnViewTitle(final String columnViewTitle) {
this.mColumnViewTitle = columnViewTitle;
}
/**
* Getter for the column-view.
* @return {@link Map} representing the columnview.
*/
public Map<String, Map<String, String>> getColumnView() {
return mColumnView;
}
/**
* Getter for the columnview-title.
* @return {@link String} representing the columnview-title.
*/
public String getColumnViewTitle() {
return mColumnViewTitle;
}
/**
* Add a texture and the associated description text to the legend.
* @param groupName The name of the header under which explanations of this group will be placed. (e.g. "Series")
......
......@@ -5,24 +5,24 @@ import de.tudresden.inf.mci.brailleplot.layout.RasterCanvas;
import de.tudresden.inf.mci.brailleplot.layout.Rectangle;
import de.tudresden.inf.mci.brailleplot.printabledata.MatrixData;
import de.tudresden.inf.mci.brailleplot.rendering.language.BrailleLanguage;
import java.util.Map;
import static java.lang.Integer.max;
import static java.lang.StrictMath.min;
/**
* A rasterizer that is able to draw a legend on a new page.
* @author Leonard Kupper
* @version 2019.08.28
* @author Leonard Kupper, Andrey Ruzhanskiy
* @version 2019.09.25
*/
public class LegendRasterizer implements Rasterizer<Legend> {
private RasterCanvas mCanvas;
private Legend mLegend;
private BrailleLanguage.Language mLanguage;
private String mLegendKeyword; // title for the legend
private static final int MIN_TEXT_WIDTH_CELLS = 10; // how much space should be available for an explanation text at least. (To avoid excessive line breaking)
private static final int EXPLANATION_TEXT_INDENTATION_CELLS = 1; // indentation for explanation texts.
private BrailleLanguage.Language mLanguage;
private String mLegendKeyword; // title for the legend
private static final BrailleLanguage.Language EXPLANATION_LIST_LANGUAGE = BrailleLanguage.Language.DE_BASISSCHRIFT;
// Sub rasterizers
......@@ -43,7 +43,7 @@ public class LegendRasterizer implements Rasterizer<Legend> {
mLegendKeyword = mCanvas.getRepresentation().getProperty("general.legendKeyword").toString();
// Create a fresh page on the canvas.
MatrixData<Boolean> page = canvas.getNewPage();
canvas.getNewPage();
Rectangle referenceCellArea = canvas.getCellRectangle();
try {
......@@ -52,7 +52,6 @@ public class LegendRasterizer implements Rasterizer<Legend> {
setLanguage(legend.getLanguage());
writeLine(mLegendKeyword + " " + legend.getTitle(), referenceCellArea);
// Texture explanation lists
for (Map.Entry<String, Map<Texture<Boolean>, String>> list : legend.getTextureExplanationGroups().entrySet()) {
String groupName = list.getKey();
......@@ -85,6 +84,41 @@ public class LegendRasterizer implements Rasterizer<Legend> {
moveIndentation(referenceCellArea, -1 * EXPLANATION_TEXT_INDENTATION_CELLS); // reset indentation
}
// Columnview
if (legend.getColumnView().size() > 0) {
setLanguage(legend.getLanguage());
writeLine(legend.getColumnViewTitle(), referenceCellArea);
for (Map.Entry<String, Map<String, String>> list : legend.getColumnView().entrySet()) {
Rectangle columnCellArea = new Rectangle(referenceCellArea);
setLanguage(legend.getLanguage());
writeLine(list.getKey(), columnCellArea);
int maxWidth = 0;
for (Map.Entry<String, String> explanation : list.getValue().entrySet()) {
String symbol = explanation.getKey();
String description = explanation.getValue();
String textToWrite = symbol + " " + description;
setLanguage(EXPLANATION_LIST_LANGUAGE);
try {
int usedWidth = writeLine(textToWrite, columnCellArea);
if (usedWidth > maxWidth) {
maxWidth = usedWidth;
}
} catch (Rectangle.OutOfSpaceException e) {
referenceCellArea.removeFromLeft(maxWidth + 1);
maxWidth = 0;
columnCellArea = new Rectangle(referenceCellArea);
columnCellArea.removeFromTop(1);
int usedWidth = writeLine(textToWrite, columnCellArea);
if (usedWidth > maxWidth) {
maxWidth = usedWidth;
}
}
}
referenceCellArea.removeFromLeft(maxWidth + 1 + EXPLANATION_TEXT_INDENTATION_CELLS);
}
}
} catch (Rectangle.OutOfSpaceException e) {
throw new InsufficientRenderingAreaException("The amount of data in the legend does not fit on the format.", e);
}
......@@ -142,7 +176,7 @@ public class LegendRasterizer implements Rasterizer<Legend> {
cellArea.setWidth(cellArea.getWidth() - indent);
}
private void writeLine(final String text, final Rectangle cellArea) throws InsufficientRenderingAreaException, Rectangle.OutOfSpaceException {
private int writeLine(final String text, final Rectangle cellArea) throws InsufficientRenderingAreaException, Rectangle.OutOfSpaceException {
if (cellArea.getWidth() < MIN_TEXT_WIDTH_CELLS) {
throw new InsufficientRenderingAreaException("Not enough space for legend text.");
}
......@@ -151,6 +185,7 @@ public class LegendRasterizer implements Rasterizer<Legend> {
int textHeight = max(1, (int) Math.ceil(textLength / cellArea.getWidth()));
Rectangle textLineDotArea = mCanvas.toDotRectangle(cellArea.removeFromTop(textHeight));
mTextRasterizer.rasterize(new BrailleText(text, textLineDotArea, getLanguage()), mCanvas);
return min(textLength, cellArea.intWrapper().getWidth());
}
private void setLanguage(final BrailleLanguage.Language language) {
......@@ -160,5 +195,4 @@ public class LegendRasterizer implements Rasterizer<Legend> {
private BrailleLanguage.Language getLanguage() {
return mLanguage;
}
}
......@@ -57,7 +57,7 @@ format.default.margin.right=0
### Diagram Formatting
### ==================
representation.general.brailleLanguage=DE_BASISSCHRIFT
representation.general.brailleLanguage=DE_KURZSCHRIFT
representation.general.nonexistentDataText=n/a
representation.general.legendKeyword=Legende:
representation.general.maxTitleHeight=2
......
......@@ -56,7 +56,7 @@ format.default.margin.right=10
### Diagram Formatting
### ==================
representation.general.brailleLanguage=DE_BASISSCHRIFT
representation.general.brailleLanguage=DE_KURZSCHRIFT
representation.general.nonexistentDataText=n/a
representation.general.legendKeyword=Legende:
representation.general.maxTitleHeight=2
......
......@@ -45,7 +45,7 @@ format.default.margin.right=0
### Diagram Formatting
### ==================
representation.general.brailleLanguage=DE_BASISSCHRIFT
representation.general.brailleLanguage=DE_KURZSCHRIFT
representation.general.nonexistentDataText=n/a
representation.general.legendKeyword=Legende:
representation.general.maxTitleHeight=2
......
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment