further API cleanup

This commit is contained in:
jomu
2016-06-15 10:55:09 +00:00
parent 1cd84cfa3b
commit e76d72b31c
10 changed files with 47 additions and 53 deletions

View File

@ -4,11 +4,11 @@ package de.muehlencord.shared.pdf;
*
* @author joern.muehlencord
*/
public abstract class CellValue {
abstract class CellValue {
public abstract int getColSize();
protected abstract int getColSize();
public abstract float getCellPadding();
protected abstract float getCellPadding();
}

View File

@ -40,7 +40,7 @@ class DefaultTableRow extends TableRow {
}
@Override
protected void addColumn(TextElement element, Float p) {
protected void addColumn(TextElement element, float p) {
row.add(element);
padding.add(p);
}
@ -62,7 +62,7 @@ class DefaultTableRow extends TableRow {
}
@Override
protected Float getCellPadding(int columnPos) {
protected float getCellPadding(int columnPos) {
Float currentPadding = padding.get(columnPos);
if (currentPadding == null) {
return 0F;

View File

@ -1,17 +0,0 @@
package de.muehlencord.shared.pdf;
/**
*
* @author joern.muehlencord
*/
interface ListTemplate {
public void createList (String listName, String varName);
public boolean isList();
public String getListName();
public String getVarName();
}

View File

@ -18,6 +18,7 @@ public class PDFImageContent extends Content {
@Expose
private Float scale = null;
@Expose
private String base64CodedImage = null;
@ -36,34 +37,34 @@ public class PDFImageContent extends Content {
this.base64CodedImage = ImageUtil.getEncodedString(img);
}
public PDFImageContent(PDFDocument document, Float x, Float y, String contentString) throws IOException {
public PDFImageContent(PDFDocument document, float x, float y, String contentString) throws IOException {
super(document, x, y);
this.base64CodedImage = contentString;
}
public PDFImageContent(PDFDocument document, Float x, Float y, File file) throws IOException {
public PDFImageContent(PDFDocument document, float x, float y, File file) throws IOException {
super(document, x, y);
this.base64CodedImage = ImageUtil.getEncodedString(ImageIO.read(file));
}
public PDFImageContent(PDFDocument document, Float x, Float y, BufferedImage img) throws IOException {
public PDFImageContent(PDFDocument document, float x, float y, BufferedImage img) throws IOException {
super(document, x, y);
this.base64CodedImage = ImageUtil.getEncodedString(img);
}
public PDFImageContent(PDFDocument document, Float x, Float y, Float scale, String contentString) throws IOException {
public PDFImageContent(PDFDocument document, float x, float y, float scale, String contentString) throws IOException {
super(document, x, y);
this.scale = scale;
this.base64CodedImage = contentString;
}
public PDFImageContent(PDFDocument document, Float x, Float y, Float scale, File file) throws IOException {
public PDFImageContent(PDFDocument document, float x, float y, float scale, File file) throws IOException {
super(document, x, y);
this.scale = scale;
this.base64CodedImage = ImageUtil.getEncodedString(ImageIO.read(file));
}
public PDFImageContent(PDFDocument document, Float x, Float y, Float scale, BufferedImage img) throws IOException {
public PDFImageContent(PDFDocument document, float x, float y, float scale, BufferedImage img) throws IOException {
super(document, x, y);
this.scale = scale;
this.base64CodedImage = ImageUtil.getEncodedString(img);
@ -81,7 +82,7 @@ public class PDFImageContent extends Content {
}
/* *** getter / setter */
public Float getScale() {
public float getScale() {
if (scale == null) {
return 1F;
} else {

View File

@ -42,6 +42,21 @@ public class PDFTableContent extends Content {
this.headerFont = hf;
this.data = new ArrayList<>();
}
public PDFTableContent addHeader(String headerText, int colSize) {
this.header.add(headerText, colSize);
return this;
}
public PDFTableContent addHeader(String headerText, int colSize, float padding) {
this.header.add(headerText, colSize, padding);
return this;
}
public PDFTableContent addHeader(String headerText, int colSize, PDFTextAlignment alignment) {
this.header.add(headerText, colSize, alignment);
return this;
}
public PDFTableContent addRow() {
DefaultTableRow newRow = new DefaultTableRow();
@ -85,7 +100,7 @@ public class PDFTableContent extends Content {
return this;
}
public PDFTableContent addColumn(String text, PDFTextAlignment alignment, Float padding) throws ConfigurationException {
public PDFTableContent addColumn(String text, PDFTextAlignment alignment, float padding) throws ConfigurationException {
if (data.isEmpty()) {
throw new ConfigurationException ("Need to call newRow first");
}
@ -108,7 +123,7 @@ public class PDFTableContent extends Content {
PDFont hFont = document.getFont(headerFont.getFontName());
PDFont standardFont = document.getFont(document.getStandardFont().getFontName());
int xOffSet = 0;
for (int i = 0; i < getHeaders().size(); i++) {
for (int i = 0; i < header.size(); i++) {
xOffSet -= header.getColumnSize(i);
}
int yOffset = document.getStandardFont().getFontSize() * -1 - document.getStandardFont().getPadding();
@ -177,8 +192,4 @@ public class PDFTableContent extends Content {
public PDFFont getHeaderFont() {
return headerFont;
}
public TableHeader getHeaders() {
return header;
}
}

View File

@ -21,12 +21,12 @@ public class PDFTextContent extends Content {
this.textLines = new LinkedList<>();
}
public PDFTextContent(PDFDocument doc, Float x, Float y) {
public PDFTextContent(PDFDocument doc, float x, float y) {
super(doc, x, y);
this.textLines = new LinkedList<>();
}
public PDFTextContent(PDFDocument doc, Float x, Float y, String text) {
public PDFTextContent(PDFDocument doc, float x, float y, String text) {
super(doc, x, y);
this.textLines = new LinkedList<>();
this.textLines.add(new TextElement(text));

View File

@ -8,7 +8,7 @@ import java.util.List;
*
* @author joern.muehlencord
*/
public class TableHeader {
class TableHeader {
@Expose
private final List<CellValue> headerCells;
@ -22,7 +22,7 @@ public class TableHeader {
return this;
}
public TableHeader add(String headerText, int colSize, Float padding) {
public TableHeader add(String headerText, int colSize, float padding) {
headerCells.add (new TextCellValue (headerText, colSize));
return this;
}
@ -66,7 +66,7 @@ public class TableHeader {
}
}
public Float getCellPadding(int pos) {
protected float getCellPadding(int pos) {
return headerCells.get(pos).getCellPadding();
}

View File

@ -16,7 +16,7 @@ abstract class TableRow {
protected abstract PDFTextAlignment getAlignment(int columnPos);
protected abstract Float getCellPadding (int columnPos);
protected abstract float getCellPadding (int columnPos);
protected abstract String getListName();
@ -24,7 +24,7 @@ abstract class TableRow {
protected abstract void addColumn(TextElement element);
protected abstract void addColumn(TextElement element, Float padding);
protected abstract void addColumn(TextElement element, float padding);
}

View File

@ -6,7 +6,7 @@ import com.google.gson.annotations.Expose;
*
* @author joern.muehlencord
*/
public class TextCellValue extends CellValue {
class TextCellValue extends CellValue {
@Expose
private final TextElement cellValue;

View File

@ -49,9 +49,9 @@ public class PDFDocumentTest {
doc.addContent(informationContent);
PDFTableContent informationContent2 = new PDFTableContent(doc, doc.getStandardFont());
informationContent2.getHeaders()
.add("Kunden-Nr", 100)
.add("${invoice.customerNumber}", 100);
informationContent2
.addHeader("Kunden-Nr", 100)
.addHeader("${invoice.customerNumber}", 100);
informationContent2.addRow("Rechnungs-Nr.:", "${invoice.invoiceNumber}")
.addRow("Ausgabe: ", "Dezember")
.addRow("Rechnungsdatum:", "${invoice.invoiceDate?date}");
@ -65,21 +65,20 @@ public class PDFDocumentTest {
doc.addContent(invoiceInfoInformation);
PDFTableContent invoiceLines = new PDFTableContent(doc, doc.getFontByAlias("bold"));
invoiceLines.getHeaders()
.add("Menge", 50)
.add("Beschreibung", 300)
.add("Einzelpreis", 80, PDFTextAlignment.RIGHT)
.add("Summe", 80, PDFTextAlignment.RIGHT);
invoiceLines.addHeader("Menge", 50, 10F)
.addHeader("Beschreibung", 300, 10F)
.addHeader("Einzelpreis", 80, PDFTextAlignment.RIGHT)
.addHeader("Summe", 80, PDFTextAlignment.RIGHT);
invoiceLines.addRow()
.addColumn("1000", PDFTextAlignment.RIGHT, 5F)
.addColumn("Anzeige Hövelhofer Rundschau")
.addColumn("10,00 €", PDFTextAlignment.RIGHT)
.addColumn("10,00 €", PDFTextAlignment.RIGHT);
invoiceLines.addListRow("invoice.invoiceLines", "invoiceline")
.addColumn("${invoiceline.amount}", PDFTextAlignment.RIGHT, 5F )
.addColumn("${invoiceline.amount}", PDFTextAlignment.RIGHT, 5F)
.addColumn("${invoiceline.description}")
.addColumn("${invoiceline.price}", PDFTextAlignment.RIGHT)
.addColumn("${invoiceline.total}", PDFTextAlignment.RIGHT);
.addColumn("${invoiceline.total}", PDFTextAlignment.RIGHT);
invoiceLines.addRow()
.addColumn("2", PDFTextAlignment.RIGHT, 5F)
.addColumn("Anzeige Hövelhofer Rundschau")