Skip to content

Commit

Permalink
v3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Mararsh committed Sep 30, 2018
1 parent 3719582 commit c6f81bf
Show file tree
Hide file tree
Showing 27 changed files with 616 additions and 217 deletions.
2 changes: 1 addition & 1 deletion MyBox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>mara</groupId>
<artifactId>MyBox</artifactId>
<version>3.3</version>
<version>3.4</version>
<packaging>jar</packaging>

<name>MyBox</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ public boolean stageClosing() {
alert.setTitle(getMyStage().getTitle());
alert.setContentText(AppVaribles.getMessage("TaskRunning"));
Optional<ButtonType> result = alert.showAndWait();
logger.debug(result.get());
if (result.get() == ButtonType.OK && task != null) {
task.cancel();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ protected String handleCurrentFile() {
}
ImageFileWriters.writeImageFile(target, targetFormat, currentParameters.finalTargetName);
generatedFiles.add(currentParameters.finalTargetName);
return AppVaribles.getMessage("Succeeded");
return AppVaribles.getMessage("Successful");
} catch (Exception e) {
logger.error(e.toString());
return AppVaribles.getMessage("Failed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class ImagesCombinePdfController extends ImageBaseController {

private final ObservableList<ImageFileInformation> sourceImages = FXCollections.observableArrayList();
private final String ImagesCombinePdfPathKey, ImageCombineLoadImagesKey, ImageCombineTargetPathKey;
private final String ImageCombineSizeKey, ImageCombineMarginsKey;
private final String ImageCombineSizeKey, ImageCombineMarginsKey, AuthorKey;
private final int snapSize = 150;
private File targetFile;

Expand Down Expand Up @@ -119,6 +119,7 @@ public ImagesCombinePdfController() {
ImageCombineTargetPathKey = "ImageCombineTargetPathKey";
ImageCombineMarginsKey = "ImageCombineMarginsKey";
ImageCombineSizeKey = "ImageCombineSizeKey";
AuthorKey = "AuthorKey";
}

@Override
Expand Down Expand Up @@ -209,6 +210,7 @@ public void changed(ObservableValue<? extends String> observable, String oldValu
}
}
});

saveButton.disableProperty().bind(
Bindings.isEmpty(sourceImages)
.or(Bindings.isEmpty(targetFileInput.textProperty()))
Expand Down Expand Up @@ -378,6 +380,14 @@ public void changed(ObservableValue<? extends String> ov,

}

authorInput.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
AppVaribles.setConfigValue(AuthorKey, newValue);
}
});
authorInput.setText(AppVaribles.getConfigValue(AuthorKey, System.getProperty("user.name")));

}

private void checkPageSize() {
Expand Down Expand Up @@ -836,7 +846,7 @@ protected void saveAction(ActionEvent event) {
protected Void call() throws Exception {
try {
int count = 0;
try (PDDocument document = new PDDocument()) {
try (PDDocument document = new PDDocument(AppVaribles.PdfMemUsage)) {
PDPageContentStream content;
PDFont font = PdfTools.getFont(document, fontBox.getSelectionModel().getSelectedItem());
PDDocumentInformation info = new PDDocumentInformation();
Expand Down
67 changes: 63 additions & 4 deletions MyBox/src/main/java/mara/mybox/controller/MainMenuController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.awt.Desktop;
import java.io.File;
import java.io.FileWriter;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
Expand All @@ -15,6 +16,8 @@
import mara.mybox.objects.CommonValues;
import mara.mybox.tools.FxmlTools;
import static mara.mybox.controller.BaseController.logger;
import static mara.mybox.objects.AppVaribles.getConfigValue;
import org.apache.pdfbox.io.MemoryUsageSetting;

/**
* @Author Mara
Expand All @@ -29,7 +32,7 @@ public class MainMenuController extends BaseController {
@FXML
private RadioMenuItem chineseMenuItem, englishMenuItem;
@FXML
private RadioMenuItem replaceWhiteMenu, replaceBlackMenu;
private RadioMenuItem replaceWhiteMenu, replaceBlackMenu, pdf500mbRadio, pdf1gbRadio, pdf2gbRadio, pdfUnlimitRadio;
@FXML
private CheckMenuItem showCommentsCheck, stopAlarmCheck;
@FXML
Expand All @@ -54,6 +57,22 @@ protected void initializeNext() {
replaceWhiteMenu.setSelected(true);
}

String pm = getConfigValue("PdfMemDefault", "1GB");
switch (pm) {
case "1GB":
pdf1gbRadio.setSelected(true);
break;
case "2GB":
pdf2gbRadio.setSelected(true);
break;
case "unlimit":
pdfUnlimitRadio.setSelected(true);
break;
case "500MB":
default:
pdf500mbRadio.setSelected(true);
}

settingsMenu.setOnShowing(new EventHandler<Event>() {
@Override
public void handle(Event e) {
Expand Down Expand Up @@ -110,6 +129,48 @@ private void replaceBlackAction(ActionEvent event) {
AppVaribles.alphaAsBlack = true;
}

@FXML
private void PdfMem500MB(ActionEvent event) {
AppVaribles.setConfigValue("PdfMemDefault", "500MB");
AppVaribles.PdfMemUsage = MemoryUsageSetting.setupMixed(500 * 1024 * 1024, -1);
}

@FXML
private void PdfMem1GB(ActionEvent event) {
AppVaribles.setConfigValue("PdfMemDefault", "1GB");
AppVaribles.PdfMemUsage = MemoryUsageSetting.setupMixed(1024 * 1024 * 1024, -1);
}

@FXML
private void PdfMem2GB(ActionEvent event) {
AppVaribles.setConfigValue("PdfMemDefault", "2GB");
AppVaribles.PdfMemUsage = MemoryUsageSetting.setupMixed(2048 * 1024 * 1024, -1);
}

@FXML
private void pdfMemUnlimit(ActionEvent event) {
AppVaribles.setConfigValue("PdfMemDefault", "unlimit");
AppVaribles.PdfMemUsage = MemoryUsageSetting.setupMixed(-1, -1);
}

@FXML
private void clearSettings(ActionEvent event) {
try {
File configFile = new File(CommonValues.UserConfigFile);
if (!configFile.exists()) {
configFile.createNewFile();
} else {
try (FileWriter fileWriter = new FileWriter(configFile)) {
fileWriter.write("");
fileWriter.flush();
}
popInformation(AppVaribles.getMessage("Successful"));
}
} catch (Exception e) {
popError(e.toString());
}
}

@FXML
private void exit(ActionEvent event) {
// This statement is internel call to close the stage, so itself can not tigger stageClosing()
Expand Down Expand Up @@ -432,9 +493,7 @@ public boolean stageReloading() {
try {
// logger.debug("stageReloading");

parentController.stageClosing();

return true;
return parentController.stageClosing();

} catch (Exception e) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
public class PdfCompressImagesController extends PdfBaseController {

protected String PdfCompressImagesSourcePathKey;
protected String PdfCompressImagesSourcePathKey, AuthorKey;
protected int jpegQuality, format, threshold;
protected File targetFile;

Expand All @@ -65,7 +65,7 @@ public static class PdfImageFormat {
public PdfCompressImagesController() {
PdfCompressImagesSourcePathKey = "PdfCompressImagesSourcePathKey";
targetPathKey = "PDFCompressImagesPathKey";

AuthorKey = "AuthorKey";
}

@Override
Expand Down Expand Up @@ -129,6 +129,14 @@ public void changed(ObservableValue<? extends String> observable, String oldValu
});
checkThreshold();

authorInput.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
AppVaribles.setConfigValue(AuthorKey, newValue);
}
});
authorInput.setText(AppVaribles.getConfigValue(AuthorKey, System.getProperty("user.name")));

}

protected void checkFormat() {
Expand Down Expand Up @@ -312,7 +320,8 @@ public void run() {

private void handleCurrentFile() {
try {
try (PDDocument doc = PDDocument.load(currentParameters.sourceFile, currentParameters.password)) {
try (PDDocument doc = PDDocument.load(currentParameters.sourceFile,
currentParameters.password, AppVaribles.PdfMemUsage)) {
document = doc;
if (currentParameters.acumDigit < 1) {
currentParameters.acumDigit = (doc.getNumberOfPages() + "").length();
Expand All @@ -324,14 +333,15 @@ private void handleCurrentFile() {
Splitter splitter = new Splitter();
splitter.setStartPage(currentParameters.startPage + 1);
splitter.setEndPage(currentParameters.toPage + 1);
splitter.setMemoryUsageSetting(AppVaribles.PdfMemUsage);
splitter.setSplitAtPage(currentParameters.toPage - currentParameters.startPage + 1);
try (PDDocument newDoc = splitter.split(document).get(0)) {
newDoc.save(targetFile);
}
}

currentParameters.currentTotalHandled = 0;
try (PDDocument doc = PDDocument.load(targetFile)) {
try (PDDocument doc = PDDocument.load(targetFile, AppVaribles.PdfMemUsage)) {
PDDocumentInformation info = new PDDocumentInformation();
info.setCreationDate(Calendar.getInstance());
info.setModificationDate(Calendar.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import mara.mybox.image.ImageGrayTools;
import mara.mybox.imagefile.ImageFileWriters;
import mara.mybox.tools.ValueTools;
import org.apache.pdfbox.io.MemoryUsageSetting;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.ImageType;
import org.apache.pdfbox.rendering.PDFRenderer;
Expand Down Expand Up @@ -123,7 +124,8 @@ protected Void call() {

private void handleCurrentFile() {
try {
try (PDDocument doc = PDDocument.load(currentParameters.sourceFile, currentParameters.password)) {
try (PDDocument doc = PDDocument.load(currentParameters.sourceFile, currentParameters.password,
AppVaribles.PdfMemUsage)) {
if (actualParameters.acumDigit < 1) {
actualParameters.acumDigit = (doc.getNumberOfPages() + "").length();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import mara.mybox.imagefile.ImageFileWriters;
import mara.mybox.tools.ValueTools;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.io.MemoryUsageSetting;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDResources;
Expand Down Expand Up @@ -135,7 +136,8 @@ protected Void call() {

private void handleCurrentFile() {
try {
try (PDDocument doc = PDDocument.load(currentParameters.sourceFile, currentParameters.password)) {
try (PDDocument doc = PDDocument.load(currentParameters.sourceFile, currentParameters.password,
AppVaribles.PdfMemUsage)) {
if (currentParameters.acumDigit < 1) {
currentParameters.acumDigit = (doc.getNumberOfPages() + "").length();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import mara.mybox.objects.AppVaribles;
import mara.mybox.tools.FileTools;
import static mara.mybox.tools.FxmlTools.badStyle;
import org.apache.pdfbox.io.MemoryUsageSetting;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;

Expand Down Expand Up @@ -127,7 +128,8 @@ private void handleCurrentFile() {
finalTargetName = currentParameters.targetPath + "/"
+ currentParameters.targetPrefix + ".txt";
FileWriter writer = new FileWriter(finalTargetName, false);
try (PDDocument doc = PDDocument.load(currentParameters.sourceFile, currentParameters.password)) {
try (PDDocument doc = PDDocument.load(currentParameters.sourceFile, currentParameters.password,
AppVaribles.PdfMemUsage)) {
if (currentParameters.acumDigit < 1) {
currentParameters.acumDigit = (doc.getNumberOfPages() + "").length();
}
Expand Down
Loading

0 comments on commit c6f81bf

Please sign in to comment.