further API cleanup
This commit is contained in:
@ -4,11 +4,11 @@ package de.muehlencord.shared.pdf;
|
|||||||
*
|
*
|
||||||
* @author joern.muehlencord
|
* @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();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,7 +40,7 @@ class DefaultTableRow extends TableRow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addColumn(TextElement element, Float p) {
|
protected void addColumn(TextElement element, float p) {
|
||||||
row.add(element);
|
row.add(element);
|
||||||
padding.add(p);
|
padding.add(p);
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ class DefaultTableRow extends TableRow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Float getCellPadding(int columnPos) {
|
protected float getCellPadding(int columnPos) {
|
||||||
Float currentPadding = padding.get(columnPos);
|
Float currentPadding = padding.get(columnPos);
|
||||||
if (currentPadding == null) {
|
if (currentPadding == null) {
|
||||||
return 0F;
|
return 0F;
|
||||||
|
|||||||
@ -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();
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -18,6 +18,7 @@ public class PDFImageContent extends Content {
|
|||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
private Float scale = null;
|
private Float scale = null;
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
private String base64CodedImage = null;
|
private String base64CodedImage = null;
|
||||||
|
|
||||||
@ -36,34 +37,34 @@ public class PDFImageContent extends Content {
|
|||||||
this.base64CodedImage = ImageUtil.getEncodedString(img);
|
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);
|
super(document, x, y);
|
||||||
this.base64CodedImage = contentString;
|
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);
|
super(document, x, y);
|
||||||
this.base64CodedImage = ImageUtil.getEncodedString(ImageIO.read(file));
|
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);
|
super(document, x, y);
|
||||||
this.base64CodedImage = ImageUtil.getEncodedString(img);
|
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);
|
super(document, x, y);
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
this.base64CodedImage = contentString;
|
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);
|
super(document, x, y);
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
this.base64CodedImage = ImageUtil.getEncodedString(ImageIO.read(file));
|
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);
|
super(document, x, y);
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
this.base64CodedImage = ImageUtil.getEncodedString(img);
|
this.base64CodedImage = ImageUtil.getEncodedString(img);
|
||||||
@ -81,7 +82,7 @@ public class PDFImageContent extends Content {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* *** getter / setter */
|
/* *** getter / setter */
|
||||||
public Float getScale() {
|
public float getScale() {
|
||||||
if (scale == null) {
|
if (scale == null) {
|
||||||
return 1F;
|
return 1F;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -43,6 +43,21 @@ public class PDFTableContent extends Content {
|
|||||||
this.data = new ArrayList<>();
|
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() {
|
public PDFTableContent addRow() {
|
||||||
DefaultTableRow newRow = new DefaultTableRow();
|
DefaultTableRow newRow = new DefaultTableRow();
|
||||||
data.add(newRow);
|
data.add(newRow);
|
||||||
@ -85,7 +100,7 @@ public class PDFTableContent extends Content {
|
|||||||
return this;
|
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()) {
|
if (data.isEmpty()) {
|
||||||
throw new ConfigurationException ("Need to call newRow first");
|
throw new ConfigurationException ("Need to call newRow first");
|
||||||
}
|
}
|
||||||
@ -108,7 +123,7 @@ public class PDFTableContent extends Content {
|
|||||||
PDFont hFont = document.getFont(headerFont.getFontName());
|
PDFont hFont = document.getFont(headerFont.getFontName());
|
||||||
PDFont standardFont = document.getFont(document.getStandardFont().getFontName());
|
PDFont standardFont = document.getFont(document.getStandardFont().getFontName());
|
||||||
int xOffSet = 0;
|
int xOffSet = 0;
|
||||||
for (int i = 0; i < getHeaders().size(); i++) {
|
for (int i = 0; i < header.size(); i++) {
|
||||||
xOffSet -= header.getColumnSize(i);
|
xOffSet -= header.getColumnSize(i);
|
||||||
}
|
}
|
||||||
int yOffset = document.getStandardFont().getFontSize() * -1 - document.getStandardFont().getPadding();
|
int yOffset = document.getStandardFont().getFontSize() * -1 - document.getStandardFont().getPadding();
|
||||||
@ -177,8 +192,4 @@ public class PDFTableContent extends Content {
|
|||||||
public PDFFont getHeaderFont() {
|
public PDFFont getHeaderFont() {
|
||||||
return headerFont;
|
return headerFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TableHeader getHeaders() {
|
|
||||||
return header;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,12 +21,12 @@ public class PDFTextContent extends Content {
|
|||||||
this.textLines = new LinkedList<>();
|
this.textLines = new LinkedList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PDFTextContent(PDFDocument doc, Float x, Float y) {
|
public PDFTextContent(PDFDocument doc, float x, float y) {
|
||||||
super(doc, x, y);
|
super(doc, x, y);
|
||||||
this.textLines = new LinkedList<>();
|
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);
|
super(doc, x, y);
|
||||||
this.textLines = new LinkedList<>();
|
this.textLines = new LinkedList<>();
|
||||||
this.textLines.add(new TextElement(text));
|
this.textLines.add(new TextElement(text));
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author joern.muehlencord
|
* @author joern.muehlencord
|
||||||
*/
|
*/
|
||||||
public class TableHeader {
|
class TableHeader {
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
private final List<CellValue> headerCells;
|
private final List<CellValue> headerCells;
|
||||||
@ -22,7 +22,7 @@ public class TableHeader {
|
|||||||
return this;
|
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));
|
headerCells.add (new TextCellValue (headerText, colSize));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ public class TableHeader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Float getCellPadding(int pos) {
|
protected float getCellPadding(int pos) {
|
||||||
return headerCells.get(pos).getCellPadding();
|
return headerCells.get(pos).getCellPadding();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ abstract class TableRow {
|
|||||||
|
|
||||||
protected abstract PDFTextAlignment getAlignment(int columnPos);
|
protected abstract PDFTextAlignment getAlignment(int columnPos);
|
||||||
|
|
||||||
protected abstract Float getCellPadding (int columnPos);
|
protected abstract float getCellPadding (int columnPos);
|
||||||
|
|
||||||
protected abstract String getListName();
|
protected abstract String getListName();
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ abstract class TableRow {
|
|||||||
|
|
||||||
protected abstract void addColumn(TextElement element);
|
protected abstract void addColumn(TextElement element);
|
||||||
|
|
||||||
protected abstract void addColumn(TextElement element, Float padding);
|
protected abstract void addColumn(TextElement element, float padding);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import com.google.gson.annotations.Expose;
|
|||||||
*
|
*
|
||||||
* @author joern.muehlencord
|
* @author joern.muehlencord
|
||||||
*/
|
*/
|
||||||
public class TextCellValue extends CellValue {
|
class TextCellValue extends CellValue {
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
private final TextElement cellValue;
|
private final TextElement cellValue;
|
||||||
|
|||||||
@ -49,9 +49,9 @@ public class PDFDocumentTest {
|
|||||||
doc.addContent(informationContent);
|
doc.addContent(informationContent);
|
||||||
|
|
||||||
PDFTableContent informationContent2 = new PDFTableContent(doc, doc.getStandardFont());
|
PDFTableContent informationContent2 = new PDFTableContent(doc, doc.getStandardFont());
|
||||||
informationContent2.getHeaders()
|
informationContent2
|
||||||
.add("Kunden-Nr", 100)
|
.addHeader("Kunden-Nr", 100)
|
||||||
.add("${invoice.customerNumber}", 100);
|
.addHeader("${invoice.customerNumber}", 100);
|
||||||
informationContent2.addRow("Rechnungs-Nr.:", "${invoice.invoiceNumber}")
|
informationContent2.addRow("Rechnungs-Nr.:", "${invoice.invoiceNumber}")
|
||||||
.addRow("Ausgabe: ", "Dezember")
|
.addRow("Ausgabe: ", "Dezember")
|
||||||
.addRow("Rechnungsdatum:", "${invoice.invoiceDate?date}");
|
.addRow("Rechnungsdatum:", "${invoice.invoiceDate?date}");
|
||||||
@ -65,11 +65,10 @@ public class PDFDocumentTest {
|
|||||||
doc.addContent(invoiceInfoInformation);
|
doc.addContent(invoiceInfoInformation);
|
||||||
|
|
||||||
PDFTableContent invoiceLines = new PDFTableContent(doc, doc.getFontByAlias("bold"));
|
PDFTableContent invoiceLines = new PDFTableContent(doc, doc.getFontByAlias("bold"));
|
||||||
invoiceLines.getHeaders()
|
invoiceLines.addHeader("Menge", 50, 10F)
|
||||||
.add("Menge", 50)
|
.addHeader("Beschreibung", 300, 10F)
|
||||||
.add("Beschreibung", 300)
|
.addHeader("Einzelpreis", 80, PDFTextAlignment.RIGHT)
|
||||||
.add("Einzelpreis", 80, PDFTextAlignment.RIGHT)
|
.addHeader("Summe", 80, PDFTextAlignment.RIGHT);
|
||||||
.add("Summe", 80, PDFTextAlignment.RIGHT);
|
|
||||||
invoiceLines.addRow()
|
invoiceLines.addRow()
|
||||||
.addColumn("1000", PDFTextAlignment.RIGHT, 5F)
|
.addColumn("1000", PDFTextAlignment.RIGHT, 5F)
|
||||||
.addColumn("Anzeige Hövelhofer Rundschau")
|
.addColumn("Anzeige Hövelhofer Rundschau")
|
||||||
|
|||||||
Reference in New Issue
Block a user