Skip to content

Commit

Permalink
v3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Mararsh committed Oct 15, 2018
1 parent ca7e92f commit dada1da
Show file tree
Hide file tree
Showing 69 changed files with 8,907 additions and 4,188 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.7</version>
<version>3.8</version>
<packaging>jar</packaging>

<name>MyBox</name>
Expand Down
2 changes: 1 addition & 1 deletion MyBox/src/main/java/mara/mybox/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void start(Stage stage) throws Exception {
FXMLLoader fxmlLoader;
Pane pane;
if (imageFile != null) {
fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.ImageManufactureFxml), AppVaribles.CurrentBundle);
fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.ImageManufactureFileFxml), AppVaribles.CurrentBundle);
pane = fxmlLoader.load();
final ImageManufactureController imageController = (ImageManufactureController) fxmlLoader.getController();
imageController.loadImage(imageFile);
Expand Down
88 changes: 83 additions & 5 deletions MyBox/src/main/java/mara/mybox/controller/BaseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.DirectoryChooser;
Expand Down Expand Up @@ -59,6 +60,8 @@ public class BaseController implements Initializable {

protected static final Logger logger = LogManager.getLogger();

final protected String TempDirKey;

protected List<FileChooser.ExtensionFilter> fileExtensionFilter;

protected String myFxml, parentFxml, currentStatus, baseTitle;
Expand All @@ -70,7 +73,7 @@ public class BaseController implements Initializable {
protected Popup popup;

protected boolean isPreview, targetIsFile, paused;
protected File sourceFile, targetPath;
protected File sourceFile, targetPath, tempdir;
protected List<File> sourceFiles;
protected ObservableList<FileInformation> sourceFilesInformation;
protected String finalTargetName;
Expand Down Expand Up @@ -99,7 +102,7 @@ public class BaseController implements Initializable {
@FXML
protected VBox paraBox;
@FXML
protected TextField previewInput, acumFromInput, digitInput;
protected TextField previewInput, acumFromInput, digitInput, tempDirInput;
@FXML
protected CheckBox fillZero, subdirCheck, appendDensity, appendColor, appendCompressionType, appendQuality, appendSize;
@FXML
Expand All @@ -117,7 +120,7 @@ public BaseController() {
appendDensityKey = "appendDensity";
appendQualityKey = "appendQuality";
appendSizeKey = "appendSize";

TempDirKey = "TempDirKey";
}

@Override
Expand All @@ -133,6 +136,15 @@ public void initialize(URL url, ResourceBundle rb) {
mainMenuController.setParentController(this);
}

if (thisPane != null) {
thisPane.setOnKeyReleased(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
keyEventsHandler(event);
}
});
}

if (sourceFileInput != null) {
sourceFileInput.textProperty().addListener(new ChangeListener<String>() {
@Override
Expand Down Expand Up @@ -259,19 +271,63 @@ public void changed(ObservableValue<? extends String> observable, String oldValu
FxmlTools.setNonnegativeValidation(acumFromInput);
}

if (tempDirInput != null) {
tempDirInput.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
try {
final File file = new File(newValue);
tempDirInput.setStyle(null);
AppVaribles.setConfigValue(TempDirKey, file.getPath());

tempdir = file;
} catch (Exception e) {
}
}

});
tempDirInput.setText(AppVaribles.getConfigValue(TempDirKey, System.getProperty("user.home")));
}
initializeNext();
} catch (Exception e) {
logger.error(e.toString());
}
}

protected void keyEventsHandler(KeyEvent event) {
String key = event.getText();
if (key == null || key.isEmpty()) {
return;
}
if (event.isControlDown()) {
if ("m".equals(key) || "M".equals(key)) { // ctrl-m
if (mainMenuController != null) {
mainMenuController.getShowCommentsCheck().setSelected(!mainMenuController.getShowCommentsCheck().isSelected());
mainMenuController.checkShowComments();
}
}
}
}

protected void initializeNext() {

}

public void setInterfaceStyle(Scene scene, String style) {
try {
if (scene != null && style != null) {
scene.getStylesheets().clear();
scene.getStylesheets().add(getClass().getResource(style).toExternalForm());
// thisPane.getStylesheets().add(getClass().getResource(CommonValues.MyBoxStyle).toExternalForm());
}
} catch (Exception e) {
// logger.error(e.toString());
}
}

public void setInterfaceStyle(String style) {
try {
if (thisPane != null) {
if (thisPane != null && style != null) {
thisPane.getStylesheets().clear();
thisPane.getStylesheets().add(getClass().getResource(style).toExternalForm());
// thisPane.getStylesheets().add(getClass().getResource(CommonValues.MyBoxStyle).toExternalForm());
Expand Down Expand Up @@ -371,6 +427,28 @@ protected void openTarget(ActionEvent event) {
}
}

@FXML
protected void selectTemp(ActionEvent event) {
try {
DirectoryChooser chooser = new DirectoryChooser();
File path = new File(AppVaribles.getConfigValue(TempDirKey, System.getProperty("user.home")));
if (!path.isDirectory()) {
path = new File(System.getProperty("user.home"));
}
chooser.setInitialDirectory(path);
File directory = chooser.showDialog(getMyStage());
if (directory == null) {
return;
}
AppVaribles.setConfigValue(LastPathKey, directory.getPath());
AppVaribles.setConfigValue(TempDirKey, directory.getPath());

tempDirInput.setText(directory.getPath());
} catch (Exception e) {
logger.error(e.toString());
}
}

@FXML
protected void startProcess(ActionEvent event) {
}
Expand Down Expand Up @@ -773,7 +851,7 @@ public void handle(WindowEvent event) {

public void openImageManufactureInNew(String filename) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.ImageManufactureFxml), AppVaribles.CurrentBundle);
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.ImageManufactureFileFxml), AppVaribles.CurrentBundle);
Pane root = fxmlLoader.load();
final ImageManufactureController controller = fxmlLoader.getController();
Stage stage = new Stage();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package mara.mybox.controller;

import java.util.Arrays;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.ComboBox;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.stage.Modality;
import static mara.mybox.controller.BaseController.logger;
import mara.mybox.objects.CommonValues;
import mara.mybox.tools.FxmlImageTools;
import static mara.mybox.tools.FxmlTools.badStyle;

/**
* @Author Mara
* @CreateDate 2018-10-11
* @Description
* @License Apache License Version 2.0
*/
public class ImageManufactureAddMarginsController extends ImageManufactureController {

protected int addMarginWidth;

@FXML
protected ColorPicker addMarginsColorPicker;
@FXML
protected ComboBox addMarginBox;
@FXML
protected CheckBox addMarginsTopCheck, addMarginsBottomCheck, addMarginsLeftCheck, addMarginsRightCheck;
@FXML
protected Button addMarginsOkButton, transForAddMarginsButton;

public ImageManufactureAddMarginsController() {
}

@Override
protected void initializeNext2() {
try {
initCommon();
initAddMarginsTab();
} catch (Exception e) {
logger.error(e.toString());
}
}

@Override
protected void initInterface() {
try {
if (values == null || values.getImage() == null) {
return;
}
super.initInterface();

isSettingValues = true;

if (CommonValues.NoAlphaImages.contains(values.getImageInfo().getImageFormat())) {
transForAddMarginsButton.setDisable(true);
} else {
transForAddMarginsButton.setDisable(false);
}

isSettingValues = false;
} catch (Exception e) {
logger.debug(e.toString());
}

}

protected void initAddMarginsTab() {
try {
addMarginBox.getItems().addAll(Arrays.asList("5", "10", "2", "15", "20", "30", "1"));
addMarginBox.valueProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue ov, String oldValue, String newValue) {
try {
addMarginWidth = Integer.valueOf(newValue);
if (addMarginWidth > 0) {
addMarginBox.getEditor().setStyle(null);
} else {
addMarginWidth = 0;
addMarginBox.getEditor().setStyle(badStyle);
}

} catch (Exception e) {
addMarginWidth = 0;
addMarginBox.getEditor().setStyle(badStyle);
}
}
});
addMarginBox.getSelectionModel().select(0);

addMarginsOkButton.disableProperty().bind(
addMarginBox.getEditor().styleProperty().isEqualTo(badStyle)
);

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

@FXML
public void addMarginsTransparentAction() {
addMarginsColorPicker.setValue(Color.TRANSPARENT);
}

@FXML
public void addMarginsBlackAction() {
addMarginsColorPicker.setValue(Color.BLACK);
}

@FXML
public void addMarginsWhiteAction() {
addMarginsColorPicker.setValue(Color.WHITE);
}

@FXML
public void addMarginsAction() {
task = new Task<Void>() {
@Override
protected Void call() throws Exception {
final Image newImage = FxmlImageTools.addMarginsFx(values.getCurrentImage(),
addMarginsColorPicker.getValue(), addMarginWidth,
addMarginsTopCheck.isSelected(), addMarginsBottomCheck.isSelected(),
addMarginsLeftCheck.isSelected(), addMarginsRightCheck.isSelected());
Platform.runLater(new Runnable() {
@Override
public void run() {
values.setUndoImage(values.getCurrentImage());
values.setCurrentImage(newImage);
imageView.setImage(newImage);
setImageChanged(true);
setBottomLabel();
}
});
return null;
}
};
openHandlingStage(task, Modality.WINDOW_MODAL);
Thread thread = new Thread(task);
thread.setDaemon(true);
thread.start();

}

}
Loading

0 comments on commit dada1da

Please sign in to comment.