Skip to content

Commit

Permalink
v1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Mararsh committed Jul 3, 2018
1 parent 1e8a446 commit a860d1a
Show file tree
Hide file tree
Showing 48 changed files with 935 additions and 304 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>1.8</version>
<version>1.9</version>
<packaging>jar</packaging>

<name>MyBox</name>
Expand Down
4 changes: 2 additions & 2 deletions MyBox/src/main/java/mara/mybox/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import mara.mybox.controller.BaseController;
import mara.mybox.objects.AppVaribles;
import mara.mybox.objects.CommonValues;
import mara.mybox.image.ImageTools;
import mara.mybox.image.ImageValueTools;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -39,7 +39,7 @@ public void start(Stage stage) throws Exception {
configFile.createNewFile();
}
AppVaribles.CurrentBundle = CommonValues.BundleDefault;
ImageTools.registrySupportedImageFormats();
ImageValueTools.registrySupportedImageFormats();

FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.MyboxFxml), AppVaribles.CurrentBundle);
Pane pane = fxmlLoader.load();
Expand Down
22 changes: 22 additions & 0 deletions MyBox/src/main/java/mara/mybox/controller/BaseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,28 @@ public void showImage(String filename) {
}
}

public void showImageManufacture(String filename) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.ImageManufactureFxml), AppVaribles.CurrentBundle);
Pane root = fxmlLoader.load();
ImageManufactureController controller = fxmlLoader.getController();
controller.loadImage(filename);

Stage stage = new Stage();
controller.setMyStage(stage);
stage.setTitle(AppVaribles.getMessage("AppTitle"));
stage.initModality(Modality.NONE);
stage.initStyle(StageStyle.DECORATED);
stage.initOwner(null);
stage.getIcons().add(CommonValues.AppIcon);
stage.setScene(new Scene(root));
stage.show();

} catch (Exception e) {
logger.error(e.toString());
}
}

public void openLoadingStage(final Task<?> task, Modality block) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.LoadingFxml), AppVaribles.CurrentBundle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static mara.mybox.objects.AppVaribles.getMessage;
import mara.mybox.objects.ImageAttributes;
import mara.mybox.tools.FxmlTools;
import mara.mybox.image.ImageTools;
import mara.mybox.image.ImageValueTools;
import org.apache.pdfbox.rendering.ImageType;

/**
Expand Down Expand Up @@ -127,7 +127,7 @@ protected void checkImageFormat() {
attributes.setImageFormat(imageFormat);
AppVaribles.setConfigValue("imageFormat", imageFormat);

String[] compressionTypes = ImageTools.getCompressionTypes(imageFormat, attributes.getColorSpace());
String[] compressionTypes = ImageValueTools.getCompressionTypes(imageFormat, attributes.getColorSpace());
checkCompressionTypes(compressionTypes);

if (compressionTypes != null && "jpg".equals(imageFormat)) {
Expand Down Expand Up @@ -191,7 +191,7 @@ protected void checkImageColor() {
}

// if ("tif".equals(imageFormat) || "bmp".equals(imageFormat)) {
String[] compressionTypes = ImageTools.getCompressionTypes(attributes.getImageFormat(), attributes.getColorSpace());
String[] compressionTypes = ImageValueTools.getCompressionTypes(attributes.getImageFormat(), attributes.getColorSpace());
checkCompressionTypes(compressionTypes);
// }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ protected void selectSourceFile() {
fileChooser.setInitialDirectory(path);
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
sourceFile = fileChooser.showOpenDialog(getMyStage());
sourceFileInput.setText(sourceFile.getAbsolutePath());
if (sourceFileInput != null) {
sourceFileInput.setText(sourceFile.getAbsolutePath());
} else {
sourceFileChanged(sourceFile);
}
} catch (Exception e) {
// logger.error(e.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import javafx.stage.Modality;
import javafx.stage.Stage;
import static mara.mybox.controller.BaseController.logger;
import mara.mybox.image.ImageConverter.KeepRatioType;
import mara.mybox.objects.AppVaribles;
import static mara.mybox.objects.AppVaribles.getMessage;
import mara.mybox.objects.CommonValues;
Expand All @@ -43,15 +44,6 @@ public class ImageConverterAttributesController extends ImageAttributesBaseContr
@FXML
protected HBox ratioBox, ratioBaseBox;

public static class RatioAdjustion {

public static int BaseOnWidth = 0;
public static int BaseOnHeight = 1;
public static int BaseOnLarger = 2;
public static int BaseOnSmaller = 3;
public static int None = 9;
}

@Override
protected void initializeNext2() {

Expand Down Expand Up @@ -123,15 +115,15 @@ protected void checkRatioAdjustion() {
String s = selected.getText();
AppVaribles.setConfigValue("ic_ratioAdjustion", s);
if (getMessage("BaseOnWidth").equals(s)) {
attributes.setRatioAdjustion(RatioAdjustion.BaseOnWidth);
attributes.setRatioAdjustion(KeepRatioType.BaseOnWidth);
} else if (getMessage("BaseOnHeight").equals(s)) {
attributes.setRatioAdjustion(RatioAdjustion.BaseOnHeight);
attributes.setRatioAdjustion(KeepRatioType.BaseOnHeight);
} else if (getMessage("BaseOnLarger").equals(s)) {
attributes.setRatioAdjustion(RatioAdjustion.BaseOnLarger);
attributes.setRatioAdjustion(KeepRatioType.BaseOnLarger);
} else if (getMessage("BaseOnSamller").equals(s)) {
attributes.setRatioAdjustion(RatioAdjustion.BaseOnSmaller);
attributes.setRatioAdjustion(KeepRatioType.BaseOnSmaller);
} else {
attributes.setRatioAdjustion(RatioAdjustion.None);
attributes.setRatioAdjustion(KeepRatioType.None);
}
} catch (Exception e) {
logger.error(e.toString());
Expand All @@ -154,22 +146,29 @@ protected void checkRatio() {
if (ratioX == ratioY) {
return;
}
if (attributes.getRatioAdjustion() == RatioAdjustion.BaseOnWidth) {
yInput.setText(Math.round(x * sourceY / sourceX) + "");
} else if (attributes.getRatioAdjustion() == RatioAdjustion.BaseOnHeight) {
xInput.setText(Math.round(y * sourceX / sourceY) + "");
} else if (attributes.getRatioAdjustion() == RatioAdjustion.BaseOnLarger) {
if (ratioX > ratioY) {
switch (attributes.getRatioAdjustion()) {
case KeepRatioType.BaseOnWidth:
yInput.setText(Math.round(x * sourceY / sourceX) + "");
} else {
break;
case KeepRatioType.BaseOnHeight:
xInput.setText(Math.round(y * sourceX / sourceY) + "");
}
} else if (attributes.getRatioAdjustion() == RatioAdjustion.BaseOnSmaller) {
if (ratioX > ratioY) {
xInput.setText(Math.round(y * sourceX / sourceY) + "");
} else {
yInput.setText(Math.round(x * sourceY / sourceX) + "");
}
break;
case KeepRatioType.BaseOnLarger:
if (ratioX > ratioY) {
yInput.setText(Math.round(x * sourceY / sourceX) + "");
} else {
xInput.setText(Math.round(y * sourceX / sourceY) + "");
}
break;
case KeepRatioType.BaseOnSmaller:
if (ratioX > ratioY) {
xInput.setText(Math.round(y * sourceX / sourceY) + "");
} else {
yInput.setText(Math.round(x * sourceY / sourceX) + "");
}
break;
default:
break;
}
} catch (Exception e) {
// logger.error(e.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package mara.mybox.controller;

import java.awt.Desktop;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import javafx.application.Platform;
Expand All @@ -27,12 +26,11 @@
import static mara.mybox.controller.BaseController.logger;
import mara.mybox.image.ImageConverter;
import mara.mybox.image.ImageGrayTools;
import mara.mybox.image.ImageTools;
import mara.mybox.imagefile.ImageFileWriters;
import mara.mybox.objects.AppVaribles;
import mara.mybox.objects.ImageAttributes;
import mara.mybox.tools.FxmlTools;
import static mara.mybox.tools.FxmlTools.badStyle;
import mara.mybox.imagefile.ImageFileWriters;
import org.apache.pdfbox.rendering.ImageType;

/**
Expand Down Expand Up @@ -116,7 +114,7 @@ public void changed(ObservableValue<? extends String> observable, String oldValu

@FXML
private void showImage(ActionEvent event) {
showImage(sourceFile.getAbsolutePath());
showImageManufacture(sourceFile.getAbsolutePath());
}

@FXML
Expand Down Expand Up @@ -153,16 +151,8 @@ protected Void call() {
bufferImage = ImageIO.read(sourceFile);
targetFile = makeFilename();

// logger.debug("gray:" + BufferedImage.TYPE_BYTE_GRAY + " binary: " + BufferedImage.TYPE_BYTE_BINARY);
// logger.debug("argb:" + BufferedImage.TYPE_INT_ARGB + " rgb: " + BufferedImage.TYPE_INT_RGB);
int color = ImageTools.getColorType(bufferImage);
BufferedImage newImage = bufferImage;
if (attributes.getSourceWidth() != attributes.getTargetWidth()
|| attributes.getSourceHeight() != attributes.getTargetHeight()) {
Image scaledImage = bufferImage.getScaledInstance(attributes.getTargetWidth(), attributes.getTargetHeight(), BufferedImage.SCALE_DEFAULT);
newImage = ImageConverter.toBufferedImage(scaledImage, color);
// logger.debug("newImage color:" + ImageTools.getColorType(newImage));
}
BufferedImage newImage = ImageConverter.resizeImage(bufferImage, attributes.getTargetWidth(), attributes.getTargetHeight());
int color = bufferImage.getType();
if (ImageType.BINARY == attributes.getColorSpace()) {
if (attributes.getBinaryConversion() == ImageAttributes.BinaryConversion.BINARY_THRESHOLD
&& attributes.getThreshold() >= 0) {
Expand All @@ -173,8 +163,8 @@ protected Void call() {
} else if (color != BufferedImage.TYPE_BYTE_GRAY && ImageType.GRAY == attributes.getColorSpace()) {
newImage = ImageGrayTools.color2Gray(newImage);
}
// logger.debug("Colored converted:" + ImageTools.getColorType(newImage));

// ImageIO.write(newImage, attributes.getImageFormat(), new File(targetFile));
ImageFileWriters.writeImageFile(newImage, attributes, targetFile);

} catch (Exception e) {
Expand All @@ -189,7 +179,7 @@ protected void succeeded() {
Platform.runLater(new Runnable() {
@Override
public void run() {
showImage(targetFile);
showImageManufacture(targetFile);
try {
} catch (Exception e) {
logger.error(e.toString());
Expand Down
Loading

0 comments on commit a860d1a

Please sign in to comment.