Skip to content

Commit

Permalink
First release complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Trakis committed Aug 9, 2023
1 parent 59e3b71 commit 3716655
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 69 deletions.
1 change: 1 addition & 0 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
</dependencies>
<properties>
<itext.version>8.0.1</itext.version>
<slf4j.version>2.0.7</slf4j.version>
<ikonli.version>12.3.1</ikonli.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<javafx.version>21-ea+24</javafx.version>
Expand Down
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<itext.version>8.0.1</itext.version>
<javafx.version>21-ea+24</javafx.version>
<ikonli.version>12.3.1</ikonli.version>
<slf4j.version>2.0.7</slf4j.version>
</properties>


Expand Down Expand Up @@ -63,6 +64,17 @@
<artifactId>ikonli-lineawesome-pack</artifactId>
<version>${ikonli.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>


</dependencies>
Expand Down
128 changes: 80 additions & 48 deletions src/main/java/opt/ltpost/controllers/PostLabelsSignController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
package opt.ltpost.controllers;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.time.LocalDate;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
Expand All @@ -33,7 +36,9 @@
import javafx.stage.FileChooser;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
import opt.ltpost.model.ModelPdf;
import opt.ltpost.model.ModelPrefs;
import opt.ltpost.model.blogic.PdfData;
import org.controlsfx.control.Notifications;

/**
Expand All @@ -42,15 +47,16 @@
* @author Trakis
*/
public class PostLabelsSignController implements Initializable {

private Stage mainStage;
private ModelPrefs modelPrefs;
private ModelPdf modelPdf;
private Long stampPointX;
private Long stampPointY;
private Long stampWidth;
private Long stampDateFontSize;
private Long stampSignatureImageHeight;

@FXML
private VBox vBoxInfoContainer;
@FXML
Expand Down Expand Up @@ -95,17 +101,18 @@ public void initialize(URL url, ResourceBundle rb) {
*
* @param primaryStage
*/
public void initParameters(Stage primaryStage, ModelPrefs modelPrefs) {
public void initParameters(Stage primaryStage, ModelPrefs modelPrefs, ModelPdf modelPdf) {
this.mainStage = primaryStage;
this.modelPrefs = modelPrefs;
this.modelPdf = modelPdf;

// set date picker object to todays date
DPicker_DateSigned.setValue(LocalDate.now());

loadFormWithDataWithSaveRecords();

}

@FXML
private void onClickPostLabelLocation_Browse(ActionEvent event) {

Expand All @@ -118,38 +125,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.setPostLabelLocationKey(KKLDBFile.getAbsolutePath());

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) {
//
Expand All @@ -161,42 +168,50 @@ 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");
try {
modelPdf.signPDFFile(getData());
} catch (IOException ex) {

showWarningMessage(ex.getMessage(), "Signing Process");

}

}

/**
* Fill in all form fields with the data stored in local
*/
private void loadFormWithDataWithSaveRecords() {
//initial values, before user saves it to the register
stampPointX = 20L;
stampPointY = 20L;
stampPointX = -3L;
stampPointY = 30L;
stampWidth = 350L;
stampDateFontSize = 20L;
stampDateFontSize = 10L;
stampSignatureImageHeight = 20L;

// define settings for Sliders
setGenericSliderParameter(-20, 50, Slider_StampPointX);
setGenericSliderParameter(-20, 50, Slider_StampPointY);
setGenericSliderParameter(300, 400, Slider_StampWidth);
setGenericSliderParameter(10, 40, Slider_StampDateSize);
setGenericSliderParameter(10, 50, Slider_StampSignatureHeight);
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);

// fill info to locations text boxes
txtBox_PostLabelLocation.setText(modelPrefs.getPostLabelLocationKey());
txtBox_PostLabelLocation.setText(modelPrefs.getPostLabelLocation());
txtBox_SignedPostLabelFolderLocation.setText(modelPrefs.getSignedPostLabelFolderLocation());
txtBox_SignatureImageLocation.setText(modelPrefs.getSignatureImageLocation());

Expand All @@ -206,25 +221,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 {
Expand All @@ -249,7 +264,7 @@ public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
Label_StampPointX.setText("(" + Double.valueOf(Slider_StampPointX.getValue()).longValue() + ")");
}
});

Slider_StampPointY.valueProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
Expand All @@ -260,7 +275,7 @@ public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
Label_StampPointY.setText("(" + Double.valueOf(Slider_StampPointY.getValue()).longValue() + ")");
}
});

Slider_StampWidth.valueProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
Expand All @@ -271,7 +286,7 @@ public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
Label_StampWidth.setText("(" + Double.valueOf(Slider_StampWidth.getValue()).longValue() + ")");
}
});

Slider_StampSignatureHeight.valueProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
Expand All @@ -282,7 +297,7 @@ public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
Label_StampSignatureHeight.setText("(" + Double.valueOf(Slider_StampSignatureHeight.getValue()).longValue() + ")");
}
});

Slider_StampDateSize.valueProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
Expand All @@ -293,7 +308,7 @@ public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
Label_StampDateSize.setText("(" + Double.valueOf(Slider_StampDateSize.getValue()).longValue() + ")");
}
});

}

/**
Expand All @@ -311,19 +326,36 @@ private void showWarningMessage(String message, String title) {
// notify.darkStyle();
notify.showWarning();
}

private void setGenericSliderParameter(double min, double max, Slider sliderToChange) {
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(5);
sliderToChange.setMinorTickCount(0);
sliderToChange.setBlockIncrement(5);

sliderToChange.setMajorTickUnit(majorTickUnit);
sliderToChange.setMinorTickCount(minorTickCount);
sliderToChange.setBlockIncrement(10);
}


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());
data.setStampWidth(Double.valueOf(Slider_StampWidth.getValue()).longValue());
data.setStampDateFontSize(Double.valueOf(Slider_StampDateSize.getValue()).longValue());
data.setSignedDate(DPicker_DateSigned.getValue());

// DPicker_DateSigned.getValue()
return data;
}

}
38 changes: 38 additions & 0 deletions src/main/java/opt/ltpost/model/ModelPdf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2023 Trakis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package opt.ltpost.model;

import java.io.IOException;
import opt.ltpost.model.blogic.PdfData;
import opt.ltpost.model.blogic.PdfSign;

/**
*
* @author Trakis
*/
public class ModelPdf {

public void checkPDF(String filePath) {

}

public void signPDFFile(PdfData pdfData) throws IOException {
PdfSign pdfSign = new PdfSign();
pdfSign.create(pdfData);
}

}
4 changes: 2 additions & 2 deletions src/main/java/opt/ltpost/model/ModelPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ModelPrefs {
*
* @param key - URL
*/
public void setPostLabelLocationKey(String key) {
public void setPostLabelLocation(String key) {
OSRegister.setKey(OSRegister.keyNames.POST_LABEL_LOCATION, key);
}

Expand All @@ -38,7 +38,7 @@ public void setPostLabelLocationKey(String key) {
*
* @return URL
*/
public String getPostLabelLocationKey() {
public String getPostLabelLocation() {
return OSRegister.getKey(OSRegister.keyNames.POST_LABEL_LOCATION);
}

Expand Down
Loading

0 comments on commit 3716655

Please sign in to comment.