diff --git a/pom.xml b/pom.xml
index 9eb6346..5ec9d02 100644
--- a/pom.xml
+++ b/pom.xml
@@ -44,6 +44,7 @@
pom
+
@@ -52,6 +53,7 @@
11.1.2
+
org.kordamp.ikonli
ikonli-javafx
@@ -63,18 +65,36 @@
org.kordamp.ikonli
ikonli-lineawesome-pack
${ikonli.version}
+
+
+
+ org.kordamp.ikonli
+ ikonli-simpleicons-pack
+ ${ikonli.version}
+
+
+
+ org.kordamp.ikonli
+ ikonli-materialdesign2-pack
+ ${ikonli.version}
+
+
+
+
+
+
- org.slf4j
- slf4j-api
- ${slf4j.version}
-
-
- org.slf4j
- slf4j-simple
- ${slf4j.version}
-
+ org.slf4j
+ slf4j-api
+ ${slf4j.version}
+
+
+ org.slf4j
+ slf4j-simple
+ ${slf4j.version}
+
diff --git a/src/main/java/opt/ltpost/App.java b/src/main/java/opt/ltpost/App.java
index 76a3a10..19f691a 100644
--- a/src/main/java/opt/ltpost/App.java
+++ b/src/main/java/opt/ltpost/App.java
@@ -39,6 +39,9 @@ public void start(Stage stage) throws IOException {
// title
primaryStage.setTitle("LT Post");
+ primaryStage.setMinWidth(810);
+ primaryStage.setMinHeight(500);
+
ModelView.getInstance().showPostLabelSignView();
}
diff --git a/src/main/java/opt/ltpost/controllers/PostLabelsSignController.java b/src/main/java/opt/ltpost/controllers/PostLabelsSignController.java
index cf27dfe..cc0515c 100644
--- a/src/main/java/opt/ltpost/controllers/PostLabelsSignController.java
+++ b/src/main/java/opt/ltpost/controllers/PostLabelsSignController.java
@@ -20,19 +20,23 @@
import java.io.IOException;
import java.net.URL;
import java.time.LocalDate;
+import java.util.Objects;
import java.util.ResourceBundle;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
+import javafx.scene.control.Accordion;
+import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
+import javafx.scene.control.TitledPane;
import javafx.scene.layout.VBox;
+import javafx.scene.paint.Color;
import javafx.stage.FileChooser;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
@@ -40,6 +44,11 @@
import opt.ltpost.model.ModelPrefs;
import opt.ltpost.model.blogic.PdfData;
import org.controlsfx.control.Notifications;
+import org.kordamp.ikonli.javafx.FontIcon;
+import org.kordamp.ikonli.materialdesign2.MaterialDesignA;
+import org.kordamp.ikonli.materialdesign2.MaterialDesignE;
+import org.kordamp.ikonli.materialdesign2.MaterialDesignP;
+import org.kordamp.ikonli.simpleicons.SimpleIcons;
/**
* FXML Controller class
@@ -47,7 +56,7 @@
* @author Trakis
*/
public class PostLabelsSignController implements Initializable {
-
+
private Stage mainStage;
private ModelPrefs modelPrefs;
private ModelPdf modelPdf;
@@ -56,7 +65,7 @@ public class PostLabelsSignController implements Initializable {
private Long stampWidth;
private Long stampDateFontSize;
private Long stampSignatureImageHeight;
-
+
@FXML
private VBox vBoxInfoContainer;
@FXML
@@ -87,6 +96,18 @@ public class PostLabelsSignController implements Initializable {
private Label Label_StampSignatureHeight;
@FXML
private Label Label_StampDateSize;
+ @FXML
+ private Button btt_PostLabelLocation;
+ @FXML
+ private Button btt_SignedPostLabelFolderLocation;
+ @FXML
+ private Button btt_SignDocument;
+ @FXML
+ private Button btt_SignatureImageLocation;
+ @FXML
+ private Accordion Accordion_microAdjustment;
+ @FXML
+ private TitledPane tpl_MicroAdjustments;
/**
* Initializes the controller class.
@@ -108,11 +129,19 @@ public void initParameters(Stage primaryStage, ModelPrefs modelPrefs, ModelPdf m
// set date picker object to todays date
DPicker_DateSigned.setValue(LocalDate.now());
-
+
loadFormWithDataWithSaveRecords();
-
+
+ //design
+ // Set Image to the reload Button
+ FontIcon iconDownload = new FontIcon(MaterialDesignP.POSTAGE_STAMP);
+ iconDownload.setIconColor(Color.GREY);
+ iconDownload.setIconSize(40);
+
+ btt_SignDocument.setGraphic(iconDownload);
+
}
-
+
@FXML
private void onClickPostLabelLocation_Browse(ActionEvent event) {
@@ -125,38 +154,38 @@ private void onClickPostLabelLocation_Browse(ActionEvent event) {
new FileChooser.ExtensionFilter("All Files", "*.*"));
KKLDBFile = fileChooser.showOpenDialog(mainStage);
if (KKLDBFile != null) {
-
+
txtBox_PostLabelLocation.setText(KKLDBFile.getAbsolutePath());
try {
-
+
modelPrefs.setPostLabelLocation(KKLDBFile.getAbsolutePath());
-
+
} catch (Exception e) {
-
+
showWarningMessage("error: " + e, "PostLabelLocation");
}
-
+
}
-
+
}
-
+
@FXML
private void onClickSignedPostLabelFolderLocation_Browse(ActionEvent event) {
-
+
DirectoryChooser directoryChooser = new DirectoryChooser();
//directoryChooser.setInitialDirectory(new File("src"));
File selectedDirectory = directoryChooser.showDialog(mainStage);
txtBox_SignedPostLabelFolderLocation.setText(selectedDirectory.getAbsolutePath());
-
+
try {
modelPrefs.setSignedPostLabelFolderLocation(selectedDirectory.getAbsolutePath());
} catch (Exception e) {
showWarningMessage("error: " + e, "Signed Post Label directory field");
}
-
+
}
-
+
@FXML
private void onClickSignatureImageLocation_Browse(ActionEvent event) {
//
@@ -168,47 +197,74 @@ private void onClickSignatureImageLocation_Browse(ActionEvent event) {
new FileChooser.ExtensionFilter("All Files", "*.*"));
KKLDBFile = fileChooser.showOpenDialog(mainStage);
if (KKLDBFile != null) {
-
+
txtBox_SignatureImageLocation.setText(KKLDBFile.getAbsolutePath());
try {
modelPrefs.setSignatureImageLocation(KKLDBFile.getAbsolutePath());
} catch (Exception e) {
showWarningMessage("error: " + e, "Signature Image");
}
-
+
}
}
-
+
@FXML
private void onClickSignDocument(ActionEvent event) {
- System.out.println("sign document");
+
+ String postLabelLocation;
+ String signatureImageLocation;
+ String signedPostLabelFolderLocation;
+
+ postLabelLocation = txtBox_PostLabelLocation.getText();
+ signatureImageLocation = txtBox_SignatureImageLocation.getText();
+ signedPostLabelFolderLocation = txtBox_SignedPostLabelFolderLocation.getText();
+
+//check fields for null
+ if (postLabelLocation == null || signatureImageLocation == null || signedPostLabelFolderLocation == null) {
+
+ showWarningMessage("Some of the fields are empty!", "Fields issues");
+
+ return;
+
+ }
+// check fields for empty or blank
+ if (postLabelLocation.isEmpty() || signatureImageLocation.isEmpty() || signedPostLabelFolderLocation.isEmpty()
+ || postLabelLocation.isBlank() || signatureImageLocation.isBlank() || signedPostLabelFolderLocation.isBlank()) {
+
+ showWarningMessage("Some of the fields are empty!", "Fields issues");
+
+ return;
+ }
+
try {
modelPdf.signPDFFile(getData());
} catch (IOException ex) {
-
+
showWarningMessage(ex.getMessage(), "Signing Process");
-
+
+ } catch (Exception e) {
+ showWarningMessage(e.getMessage(), "Error");
}
-
+
}
/**
- * Fill in all form fields with the data stored in local
+ * Fill in all form fields with the data stored locally
*/
private void loadFormWithDataWithSaveRecords() {
//initial values, before user saves it to the register
- stampPointX = -3L;
- stampPointY = 30L;
- stampWidth = 350L;
+ stampPointX = 20L;
+ stampPointY = 15L;
+ stampWidth = 200L;
stampDateFontSize = 10L;
stampSignatureImageHeight = 20L;
// define settings for Sliders
- setGenericSliderParameter(-10, 5, Slider_StampPointX,1,0);
- setGenericSliderParameter(20, 50, Slider_StampPointY,5,4);
- setGenericSliderParameter(300, 400, Slider_StampWidth,10,9);
- setGenericSliderParameter(10, 50, Slider_StampSignatureHeight,5,4);
- setGenericSliderParameter(10, 20, Slider_StampDateSize,1,0);
+ setGenericSliderParameter(-20, 40, Slider_StampPointX, 5, 4);
+ setGenericSliderParameter(-20, 40, Slider_StampPointY, 5, 4);
+ setGenericSliderParameter(100, 300, Slider_StampWidth, 20, 0);
+ setGenericSliderParameter(10, 50, Slider_StampSignatureHeight, 5, 4);
+ setGenericSliderParameter(10, 20, Slider_StampDateSize, 1, 0);
// fill info to locations text boxes
txtBox_PostLabelLocation.setText(modelPrefs.getPostLabelLocation());
@@ -221,25 +277,25 @@ private void loadFormWithDataWithSaveRecords() {
} else {
Slider_StampPointX.setValue(stampPointX);
}
-
+
if (modelPrefs.getStampPointY() != null) {
Slider_StampPointY.setValue(modelPrefs.getStampPointY());
} else {
Slider_StampPointY.setValue(stampPointY);
}
-
+
if (modelPrefs.getStampWidth() != null) {
Slider_StampWidth.setValue(modelPrefs.getStampWidth());
} else {
Slider_StampWidth.setValue(stampWidth);
}
-
+
if (modelPrefs.getStampDateFontSize() != null) {
Slider_StampDateSize.setValue(modelPrefs.getStampDateFontSize());
} else {
Slider_StampDateSize.setValue(stampDateFontSize);
}
-
+
if (modelPrefs.getStampSignatureImageHeight() != null) {
Slider_StampSignatureHeight.setValue(modelPrefs.getStampSignatureImageHeight());
} else {
@@ -257,96 +313,107 @@ private void loadFormWithDataWithSaveRecords() {
Slider_StampPointX.valueProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends Number> ov, Number t, Number t1) {
- if (!Slider_StampPointX.isValueChanging()) {
- modelPrefs.setStampPointX(Double.valueOf(Slider_StampPointX.getValue()).longValue());
- }
+ modelPrefs.setStampPointX(Double.valueOf(Slider_StampPointX.getValue()).longValue());
//info label updated with the value
Label_StampPointX.setText("(" + Double.valueOf(Slider_StampPointX.getValue()).longValue() + ")");
+
}
});
-
+
Slider_StampPointY.valueProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends Number> ov, Number t, Number t1) {
- if (!Slider_StampPointY.isValueChanging()) {
- modelPrefs.setStampPointY(Double.valueOf(Slider_StampPointY.getValue()).longValue());
- }
+ modelPrefs.setStampPointY(Double.valueOf(Slider_StampPointY.getValue()).longValue());
//info label updated with the value
Label_StampPointY.setText("(" + Double.valueOf(Slider_StampPointY.getValue()).longValue() + ")");
}
});
-
+
Slider_StampWidth.valueProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends Number> ov, Number t, Number t1) {
- if (!Slider_StampWidth.isValueChanging()) {
- modelPrefs.setStampWidth(Double.valueOf(Slider_StampWidth.getValue()).longValue());
- }
+ modelPrefs.setStampWidth(Double.valueOf(Slider_StampWidth.getValue()).longValue());
//info label updated with the value
Label_StampWidth.setText("(" + Double.valueOf(Slider_StampWidth.getValue()).longValue() + ")");
}
});
-
+
Slider_StampSignatureHeight.valueProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends Number> ov, Number t, Number t1) {
- if (!Slider_StampSignatureHeight.isValueChanging()) {
- modelPrefs.setStampSignatureImageHeight(Double.valueOf(Slider_StampSignatureHeight.getValue()).longValue());
- }
+ modelPrefs.setStampSignatureImageHeight(Double.valueOf(Slider_StampSignatureHeight.getValue()).longValue());
//info label updated with the value
Label_StampSignatureHeight.setText("(" + Double.valueOf(Slider_StampSignatureHeight.getValue()).longValue() + ")");
}
});
-
+
Slider_StampDateSize.valueProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends Number> ov, Number t, Number t1) {
- if (!Slider_StampDateSize.isValueChanging()) {
- modelPrefs.setStampDateFontSize(Double.valueOf(Slider_StampDateSize.getValue()).longValue());
- }
+ modelPrefs.setStampDateFontSize(Double.valueOf(Slider_StampDateSize.getValue()).longValue());
//info label updated with the value
Label_StampDateSize.setText("(" + Double.valueOf(Slider_StampDateSize.getValue()).longValue() + ")");
}
});
-
+
}
/**
- * warning messages method
+ * warning messages
*
* @param message
* @param title
*/
private void showWarningMessage(String message, String title) {
+
+ FontIcon iconNotification = new FontIcon(MaterialDesignE.EXCLAMATION);
+ iconNotification.setIconColor(Color.DARKRED);
+ iconNotification.setIconSize(30);
+
Notifications notify = Notifications.create()
.title(title)
+ .graphic(iconNotification)
.text(message)
.owner(mainStage);
- // notify.darkStyle();
- notify.showWarning();
+
+ notify.show();
}
-
- private void setGenericSliderParameter(double min, double max, Slider sliderToChange,double majorTickUnit,int minorTickCount) {
+
+ /**
+ * General settings for sliders on the form
+ *
+ * @param min
+ * @param max
+ * @param sliderToChange
+ * @param majorTickUnit
+ * @param minorTickCount
+ */
+ private void setGenericSliderParameter(double min, double max, Slider sliderToChange, double majorTickUnit, int minorTickCount) {
sliderToChange.setMin(min);
sliderToChange.setMax(max);
-
+
sliderToChange.setShowTickLabels(true);
sliderToChange.setShowTickMarks(true);
sliderToChange.setSnapToTicks(true);
-
+
sliderToChange.setMajorTickUnit(majorTickUnit);
sliderToChange.setMinorTickCount(minorTickCount);
- sliderToChange.setBlockIncrement(10);
-
+ sliderToChange.setBlockIncrement(5);
+
}
-
+
+ /**
+ * Collect data from the user's form and load it to the object
+ *
+ * @return PDFData object
+ */
private PdfData getData() {
PdfData data = new PdfData();
data.setPostLabelLocation(txtBox_PostLabelLocation.getText());
data.setSignatureImageLocation(txtBox_SignatureImageLocation.getText());
data.setSignedPostLabelFolderLocation(txtBox_SignedPostLabelFolderLocation.getText());
-
+
data.setStampPointX(Double.valueOf(Slider_StampPointX.getValue()).longValue());
data.setStampPointY(Double.valueOf(Slider_StampPointY.getValue()).longValue());
data.setStampSignatureHeight(Double.valueOf(Slider_StampSignatureHeight.getValue()).longValue());
@@ -357,5 +424,5 @@ private PdfData getData() {
// DPicker_DateSigned.getValue()
return data;
}
-
+
}
diff --git a/src/main/java/opt/ltpost/model/blogic/PdfSign.java b/src/main/java/opt/ltpost/model/blogic/PdfSign.java
index 53ad874..a4ce226 100644
--- a/src/main/java/opt/ltpost/model/blogic/PdfSign.java
+++ b/src/main/java/opt/ltpost/model/blogic/PdfSign.java
@@ -22,7 +22,10 @@
import com.itextpdf.kernel.pdf.PdfPage;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;
-import com.itextpdf.kernel.pdf.canvas.parser.PdfTextExtractor;
+import com.itextpdf.kernel.pdf.canvas.parser.PdfCanvasProcessor;
+import com.itextpdf.kernel.pdf.canvas.parser.listener.FilteredEventListener;
+import com.itextpdf.kernel.pdf.canvas.parser.listener.IPdfTextLocation;
+import com.itextpdf.kernel.pdf.canvas.parser.listener.RegexBasedLocationExtractionStrategy;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Image;
import com.itextpdf.layout.element.Paragraph;
@@ -30,6 +33,7 @@
import java.io.File;
import java.io.IOException;
import java.time.format.DateTimeFormatter;
+import java.util.Collection;
/**
*
@@ -45,39 +49,34 @@ public void create(PdfData data) throws IOException {
String dateString = formatter.format(data.getSignedDate());
File filePdf = new File(data.getPostLabelLocation());
-
String fileNameWithoutExt = filePdf.getName().substring(0, filePdf.getName().lastIndexOf("."));
PdfReader reader = new PdfReader(filePdf.getPath());
-
-
-
- PdfWriter writer = new PdfWriter(data.getSignedPostLabelFolderLocation() +"\\"+ fileNameWithoutExt + "_SIGNED.pdf");
+
+ PdfWriter writer = new PdfWriter(data.getSignedPostLabelFolderLocation() + "\\" + fileNameWithoutExt + "_SIGNED.pdf");
PdfDocument pdfDocument = new PdfDocument(reader, writer);
-
- // System.out.println("Info: " + pdfDocument.getDefaultPageSize().toString());
//get number of pages in PDF file
int numberOfPages = pdfDocument.getNumberOfPages();
- System.out.println("numberOfPages:" + numberOfPages);
Document document = new Document(pdfDocument);
-// ImageData image = ImageDataFactory.create("C:\\Users\\gbruz\\Desktop\\EtsyDev\\apuokelio_logo.png");
-// Image imageModel = new Image(image);
-// imageModel.setHeight(20);
ImageData imageSignature = ImageDataFactory.create(data.getSignatureImageLocation());
Image imageModelSignature = new Image(imageSignature);
imageModelSignature.setHeight(data.stampSignatureHeight);
+ FilteredEventListener listener = new FilteredEventListener();
+
for (int i = 1; i <= numberOfPages; i++) {
- System.out.println("current page: " + i);
- PdfPage page = pdfDocument.getPage(i);
- String pdfPageText = PdfTextExtractor.getTextFromPage(page);
- if (pdfPageText.contains(expectedText)) {
- System.out.println("Found signature text");
+ PdfPage currentPage = pdfDocument.getPage(i);
+
+ RegexBasedLocationExtractionStrategy extractionStrategy = new RegexBasedLocationExtractionStrategy(expectedText);
+ new PdfCanvasProcessor(extractionStrategy).processPageContent(currentPage);
+
+ Collection eL = extractionStrategy.getResultantLocations();
+ for (IPdfTextLocation location : eL) {
Text txtA = new Text(dateString)
.setFontSize(data.stampDateFontSize);
@@ -86,18 +85,11 @@ public void create(PdfData data) throws IOException {
.add(txtA)
.add(imageModelSignature)
// .add(imageModel)
- // .setBackgroundColor(ColorConstants.BLACK)
+ // .setBackgroundColor(ColorConstants.BLACK)
.setRotationAngle(Math.toRadians(90));
+ paragrafoA.setFixedPosition(i, location.getRectangle().getX() + data.stampPointX, location.getRectangle().getY() + data.stampPointY, data.stampWidth);
- // paragrafoA.setRotationAngle(Math.toRadians(90));
- // document.showTextAligned(paragrafoA, 200, 100, TextAlignment.LEFT);
- float x = pdfDocument.getDefaultPageSize().getWidth() / 2;
- float y = pdfDocument.getDefaultPageSize().getHeight() / 2;
-
- paragrafoA.setFixedPosition(i, x + data.stampPointX, data.stampPointY, data.stampWidth);
document.add(paragrafoA);
-
- System.out.println("x: " + x + " y: " + y);
}
}
@@ -105,6 +97,7 @@ public void create(PdfData data) throws IOException {
pdfDocument.close();
reader.close();
writer.close();
+
}
}
diff --git a/src/main/resources/opt/ltpost/fxml/PostLabelsSign.fxml b/src/main/resources/opt/ltpost/fxml/PostLabelsSign.fxml
index c6b0aee..b4a19d2 100644
--- a/src/main/resources/opt/ltpost/fxml/PostLabelsSign.fxml
+++ b/src/main/resources/opt/ltpost/fxml/PostLabelsSign.fxml
@@ -15,11 +15,11 @@
-
+
-
+
-
+
@@ -59,11 +54,6 @@
-
-
-
-
-
@@ -72,7 +62,7 @@
-
+
@@ -88,7 +78,7 @@
-
+
@@ -137,7 +127,7 @@
-
+
@@ -154,9 +144,9 @@
-
+
-
+
diff --git a/src/main/resources/opt/ltpost/fxml/RootLayout.fxml b/src/main/resources/opt/ltpost/fxml/RootLayout.fxml
index b242178..739c876 100644
--- a/src/main/resources/opt/ltpost/fxml/RootLayout.fxml
+++ b/src/main/resources/opt/ltpost/fxml/RootLayout.fxml
@@ -5,7 +5,7 @@
-
+