diff --git a/MyBox/pom.xml b/MyBox/pom.xml
index ecf9cef9b..8410c63cc 100644
--- a/MyBox/pom.xml
+++ b/MyBox/pom.xml
@@ -4,7 +4,7 @@
mara
MyBox
- 4.8
+ 4.9
jar
MyBox
diff --git a/MyBox/src/main/java/mara/mybox/MainApp.java b/MyBox/src/main/java/mara/mybox/MainApp.java
index 921ba4d15..82f216240 100644
--- a/MyBox/src/main/java/mara/mybox/MainApp.java
+++ b/MyBox/src/main/java/mara/mybox/MainApp.java
@@ -6,13 +6,14 @@
import javafx.application.Platform;
import javafx.stage.Stage;
import javax.imageio.ImageIO;
-import mara.mybox.controller.OpenFile;
+import mara.mybox.controller.BaseController;
+import mara.mybox.fxml.FxmlStage;
import mara.mybox.db.DerbyBase;
-import mara.mybox.objects.AppVaribles;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.image.ImageValueTools;
+import mara.mybox.value.AppVaribles;
+import mara.mybox.value.CommonValues;
+import mara.mybox.image.ImageValue;
import mara.mybox.tools.FileTools;
-import static mara.mybox.objects.AppVaribles.logger;
+import static mara.mybox.value.AppVaribles.logger;
/**
* @Author Mara
@@ -30,24 +31,29 @@ public void start(Stage stage) throws Exception {
System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider");
System.setProperty("org.apache.pdfbox.rendering.UsePureJavaCMYKConversion", "true");
- ImageValueTools.registrySupportedImageFormats();
-
- File userPath = new File(CommonValues.UserFilePath);
+ File userPath = new File(CommonValues.AppDataRoot);
if (!userPath.exists()) {
- userPath.mkdirs();
+ if (!userPath.mkdirs()) {
+ FxmlStage.alertError(stage, "Can not find or make user path:\n" + CommonValues.AppDataRoot);
+ return;
+ }
+ }
+ if (CommonValues.AppTempPath.exists()) {
+ FileTools.deleteDir(CommonValues.AppTempPath);
+ }
+ if (!CommonValues.AppTempPath.mkdirs()) {
+ FxmlStage.alertError(stage, "Can not find or make user path:\n" + CommonValues.AppTempPath);
+ return;
}
+
+ // The following 3 statements should be done in this order
DerbyBase.initTables();
AppVaribles.initAppVaribles();
DerbyBase.checkUpdates();
- File tempPath = new File(CommonValues.TempPath);
- if (tempPath.exists()) {
- FileTools.deleteDir(tempPath);
- }
- tempPath.mkdirs();
-
+ ImageValue.registrySupportedImageFormats();
ImageIO.setUseCache(true);
- ImageIO.setCacheDirectory(new File(CommonValues.TempPath));
+ ImageIO.setCacheDirectory(CommonValues.AppTempPath);
String inFile = null;
List paremeters = getParameters().getUnnamed();
@@ -57,11 +63,12 @@ public void start(Stage stage) throws Exception {
}
}
if (inFile != null) {
- if (!OpenFile.openTarget(getClass(), stage, inFile)) {
- OpenFile.openMyBox(getClass(), stage);
+ BaseController controller = FxmlStage.openTarget(getClass(), stage, inFile, false);
+ if (controller == null) {
+ FxmlStage.openMyBox(getClass(), stage);
}
} else {
- OpenFile.openMyBox(getClass(), stage);
+ FxmlStage.openMyBox(getClass(), stage);
}
// https://stackoverflow.com/questions/23527679/trying-to-open-a-javafx-stage-after-calling-platform-exit
diff --git a/MyBox/src/main/java/mara/mybox/controller/AboutController.java b/MyBox/src/main/java/mara/mybox/controller/AboutController.java
index d3be18364..eaaf78454 100644
--- a/MyBox/src/main/java/mara/mybox/controller/AboutController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/AboutController.java
@@ -5,10 +5,10 @@
import javafx.fxml.FXML;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
-import mara.mybox.objects.AppVaribles;
-import mara.mybox.objects.CommonValues;
+import mara.mybox.value.AppVaribles;
+import mara.mybox.value.CommonValues;
import mara.mybox.fxml.FxmlTools;
-import static mara.mybox.objects.AppVaribles.logger;
+import static mara.mybox.value.AppVaribles.logger;
/**
* @Author Mara
diff --git a/MyBox/src/main/java/mara/mybox/controller/AlarmClockController.java b/MyBox/src/main/java/mara/mybox/controller/AlarmClockController.java
index 89f9b0151..b015510f1 100644
--- a/MyBox/src/main/java/mara/mybox/controller/AlarmClockController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/AlarmClockController.java
@@ -26,12 +26,12 @@
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineListener;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.AlarmClock;
-import mara.mybox.objects.AppVaribles;
-import mara.mybox.objects.CommonValues;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.data.AlarmClock;
+import mara.mybox.value.AppVaribles;
+import mara.mybox.value.CommonValues;
import mara.mybox.tools.SoundTools;
-import static mara.mybox.objects.AppVaribles.getMessage;
+import static mara.mybox.value.AppVaribles.getMessage;
import mara.mybox.tools.DateTools;
import mara.mybox.fxml.FxmlTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
@@ -53,7 +53,7 @@ public class AlarmClockController extends BaseController {
@FXML
private CheckBox activeCheck, loopCheck;
@FXML
- private Button playButton, pauseButton, saveButton;
+ private Button playButton, pauseButton;
@FXML
protected Pane alertClockTable;
@FXML
@@ -474,12 +474,14 @@ public void handle(ActionEvent event) {
private void selectSound(ActionEvent event) {
try {
final FileChooser fileChooser = new FileChooser();
- String defaultPath = CommonValues.UserFilePath;
+ String defaultPath = CommonValues.AppDataRoot;
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
defaultPath = "C:\\Windows\\media";
}
- File path = new File(AppVaribles.getUserConfigPath(SystemMediaPathKey, defaultPath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(SystemMediaPathKey, defaultPath);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("wav", "*.wav"));
final File file = fileChooser.showOpenDialog(getMyStage());
if (file == null) {
@@ -500,8 +502,10 @@ private void selectSound(ActionEvent event) {
private void selectMusic(ActionEvent event) {
try {
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(MusicPathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(MusicPathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("mp3", "*.mp3"));
final File file = fileChooser.showOpenDialog(getMyStage());
if (file == null) {
@@ -519,7 +523,8 @@ private void selectMusic(ActionEvent event) {
}
@FXML
- private void saveAlarm(ActionEvent event) {
+ @Override
+ public void saveAction() {
if (currentAlarm == null || !isEdit) {
currentAlarm = new AlarmClock();
currentAlarm.setKey(new Date().getTime());
diff --git a/MyBox/src/main/java/mara/mybox/controller/AlarmClockRunController.java b/MyBox/src/main/java/mara/mybox/controller/AlarmClockRunController.java
index ab39a7405..15876138d 100644
--- a/MyBox/src/main/java/mara/mybox/controller/AlarmClockRunController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/AlarmClockRunController.java
@@ -6,12 +6,12 @@
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javax.sound.sampled.Clip;
-import mara.mybox.objects.AlarmClock;
-import static mara.mybox.objects.AlarmClock.getTypeString;
-import mara.mybox.objects.AppVaribles;
-import mara.mybox.objects.CommonValues;
+import mara.mybox.data.AlarmClock;
+import static mara.mybox.data.AlarmClock.getTypeString;
+import mara.mybox.value.AppVaribles;
+import mara.mybox.value.CommonValues;
import mara.mybox.fxml.FxmlTools;
-import static mara.mybox.objects.AppVaribles.logger;
+import static mara.mybox.value.AppVaribles.logger;
import mara.mybox.tools.SoundTools;
/**
diff --git a/MyBox/src/main/java/mara/mybox/controller/AlarmClockTableController.java b/MyBox/src/main/java/mara/mybox/controller/AlarmClockTableController.java
index 791a7521d..9269878a0 100644
--- a/MyBox/src/main/java/mara/mybox/controller/AlarmClockTableController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/AlarmClockTableController.java
@@ -18,9 +18,10 @@
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
-import mara.mybox.objects.AlarmClock;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.logger;
+import javafx.scene.layout.Region;
+import mara.mybox.data.AlarmClock;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.logger;
import mara.mybox.tools.DateTools;
/**
@@ -124,6 +125,7 @@ private void clearAction(ActionEvent event) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(getBaseTitle());
alert.setContentText(AppVaribles.getMessage("SureClearAlarmClocks"));
+ alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
Optional result = alert.showAndWait();
if (result.get() != ButtonType.OK) {
return;
@@ -138,7 +140,8 @@ private void clearAction(ActionEvent event) {
}
@FXML
- private void deleteAction(ActionEvent event) {
+ @Override
+ public void deleteAction() {
ObservableList selected = alarmClocksView.getSelectionModel().getSelectedItems();
if (selected == null || selected.isEmpty()) {
return;
diff --git a/MyBox/src/main/java/mara/mybox/controller/BaseController.java b/MyBox/src/main/java/mara/mybox/controller/BaseController.java
index 809a57266..aa63888f2 100644
--- a/MyBox/src/main/java/mara/mybox/controller/BaseController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/BaseController.java
@@ -1,5 +1,6 @@
package mara.mybox.controller;
+import mara.mybox.fxml.FxmlStage;
import java.awt.Desktop;
import java.io.File;
import java.net.URL;
@@ -9,7 +10,6 @@
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
-import java.util.concurrent.ScheduledFuture;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ChangeListener;
@@ -30,10 +30,13 @@
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
+import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Pane;
+import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
+import javafx.scene.text.Font;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Modality;
@@ -42,16 +45,16 @@
import javafx.stage.StageStyle;
import javafx.stage.WindowEvent;
import mara.mybox.db.DerbyBase;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.FileInformation;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.value.CommonValues;
+import mara.mybox.data.FileInformation;
import mara.mybox.tools.FileTools;
import mara.mybox.fxml.FxmlTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import static mara.mybox.objects.AppVaribles.logger;
-import static mara.mybox.objects.CommonValues.UserFilePath;
-import mara.mybox.objects.ImageInformation;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.data.ImageInformation;
+import static mara.mybox.value.CommonValues.AppDataRoot;
/**
* @Author Mara
@@ -61,6 +64,8 @@
*/
public class BaseController implements Initializable {
+ protected String TipsLabelKey;
+
protected List fileExtensionFilter;
protected String myFxml, parentFxml, currentStatus, baseTitle;
@@ -71,7 +76,7 @@ public class BaseController implements Initializable {
protected Timer popupTimer, timer;
protected Popup popup;
- protected boolean isPreview, targetIsFile, paused;
+ protected boolean isPreview, targetIsFile, paused, isSettingValues;
protected File sourceFile, targetPath;
protected List sourceFiles;
protected ObservableList sourceFilesInformation;
@@ -95,7 +100,9 @@ public class BaseController implements Initializable {
@FXML
protected OperationController operationBarController;
@FXML
- protected Button previewButton;
+ protected Button newButton, copyButton, deleteButton, saveButton, infoButton, selectAllButton,
+ imageSizeButton, paneSizeButton, zoomInButton, zoomOutButton, okButton, startButton,
+ firstButton, lastButton, previousButton, nextButton, previewButton;
@FXML
protected VBox paraBox;
@FXML
@@ -103,7 +110,7 @@ public class BaseController implements Initializable {
@FXML
protected CheckBox fillZero, subdirCheck, appendDensity, appendColor, appendCompressionType, appendQuality, appendSize;
@FXML
- protected Label bottomLabel;
+ protected Label bottomLabel, tipsLabel;
public BaseController() {
LastPathKey = "LastPathKey";
@@ -139,6 +146,7 @@ public void initialize(URL url, ResourceBundle rb) {
}
if (thisPane != null) {
+ thisPane.setStyle("-fx-font-size: " + AppVaribles.getPaneFontSize() + "px;");
thisPane.setOnKeyReleased(new EventHandler() {
@Override
public void handle(KeyEvent event) {
@@ -147,6 +155,117 @@ public void handle(KeyEvent event) {
});
}
+ setTips();
+ initInputs();
+
+ initializeNext();
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
+ }
+
+ protected void setTips() {
+
+ if (tipsLabel != null && TipsLabelKey != null) {
+ Tooltip tips = new Tooltip(getMessage(TipsLabelKey));
+ tips.setFont(new Font(16));
+ FxmlTools.quickTooltip(tipsLabel, tips);
+ }
+
+ if (okButton != null) {
+ Tooltip tips = new Tooltip("CTRL+g");
+ tips.setFont(new Font(16));
+ FxmlTools.quickTooltip(okButton, tips);
+ }
+
+ if (newButton != null) {
+ Tooltip tips = new Tooltip("CTRL+n");
+ tips.setFont(new Font(16));
+ FxmlTools.quickTooltip(newButton, tips);
+ }
+
+ if (deleteButton != null) {
+ Tooltip tips = new Tooltip("CTRL+d / DELETE");
+ tips.setFont(new Font(16));
+ FxmlTools.quickTooltip(deleteButton, tips);
+ }
+
+ if (copyButton != null) {
+ Tooltip tips = new Tooltip("CTRL+c");
+ tips.setFont(new Font(16));
+ FxmlTools.quickTooltip(copyButton, tips);
+ }
+
+ if (saveButton != null) {
+ Tooltip tips = new Tooltip("CTRL+s");
+ tips.setFont(new Font(16));
+ FxmlTools.quickTooltip(saveButton, tips);
+
+ }
+
+ if (infoButton != null) {
+ Tooltip tips = new Tooltip("CTRL+i");
+ tips.setFont(new Font(16));
+ FxmlTools.quickTooltip(infoButton, tips);
+ }
+
+ if (selectAllButton != null) {
+ Tooltip tips = new Tooltip("CTRL+a");
+ tips.setFont(new Font(16));
+ FxmlTools.quickTooltip(selectAllButton, tips);
+ }
+
+ if (nextButton != null) {
+ Tooltip tips = new Tooltip("PAGE DOWN");
+ tips.setFont(new Font(16));
+ FxmlTools.quickTooltip(nextButton, tips);
+ }
+ if (previousButton != null) {
+ Tooltip tips = new Tooltip("PAGE UP");
+ tips.setFont(new Font(16));
+ FxmlTools.quickTooltip(previousButton, tips);
+ }
+ if (firstButton != null) {
+ Tooltip tips = new Tooltip("HOME");
+ tips.setFont(new Font(16));
+ FxmlTools.quickTooltip(firstButton, tips);
+ }
+ if (lastButton != null) {
+ Tooltip tips = new Tooltip("END");
+ tips.setFont(new Font(16));
+ FxmlTools.quickTooltip(lastButton, tips);
+ }
+
+ if (imageSizeButton != null) {
+ Tooltip tips = new Tooltip("CTRL+1");
+ tips.setFont(new Font(16));
+ FxmlTools.quickTooltip(imageSizeButton, tips);
+ }
+
+ if (paneSizeButton != null) {
+ Tooltip tips = new Tooltip("CTRL+2");
+ tips.setFont(new Font(16));
+ FxmlTools.quickTooltip(paneSizeButton, tips);
+
+ }
+
+ if (zoomInButton != null) {
+ Tooltip tips = new Tooltip("CTRL+3");
+ tips.setFont(new Font(16));
+ FxmlTools.quickTooltip(zoomInButton, tips);
+
+ }
+
+ if (zoomOutButton != null) {
+ Tooltip tips = new Tooltip("CTRL+4");
+ tips.setFont(new Font(16));
+ FxmlTools.quickTooltip(zoomOutButton, tips);
+ }
+ }
+
+ protected void initInputs() {
+ try {
+
if (sourceFileInput != null) {
sourceFileInput.textProperty().addListener(new ChangeListener() {
@Override
@@ -171,7 +290,7 @@ public void changed(ObservableValue extends String> observable, String oldValu
} else {
AppVaribles.setUserConfigValue(sourcePathKey, file.getParent());
if (targetPathInput != null && targetPathInput.getText().isEmpty()) {
- targetPathInput.setText(AppVaribles.getUserConfigValue(targetPathKey, CommonValues.UserFilePath));
+ targetPathInput.setText(AppVaribles.getUserConfigPath(targetPathKey).getAbsolutePath());
}
if (targetPrefixInput != null) {
targetPrefixInput.setText(FileTools.getFilePrefix(file.getName()));
@@ -218,7 +337,7 @@ public void changed(ObservableValue extends String> observable, String oldValu
}
}
});
- targetSelectionController.targetPathInput.setText(AppVaribles.getUserConfigValue(targetPathKey, CommonValues.UserFilePath));
+ targetSelectionController.targetPathInput.setText(AppVaribles.getUserConfigPath(targetPathKey).getAbsolutePath());
}
}
@@ -270,22 +389,126 @@ public void changed(ObservableValue extends String> observable, String oldValu
acumFromInput.setText("1");
}
- 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();
+ String key = event.getText();
+ if (key == null || key.isEmpty()) {
+ return;
+ }
+ switch (key) {
+ case "n":
+ case "N":
+ if (newButton != null && !newButton.isDisabled()) {
+ newAction();
+ }
+ break;
+ case "g":
+ case "G":
+ if (okButton != null && !okButton.isDisabled()) {
+ okAction();
+ }
+ break;
+ case "c":
+ case "C":
+ if (copyButton != null && !copyButton.isDisabled()) {
+ copyAction();
+ }
+ break;
+ case "s":
+ case "S":
+ if (saveButton != null && !saveButton.isDisabled()) {
+ saveAction();
+ }
+ break;
+ case "i":
+ case "I":
+ if (infoButton != null && !infoButton.isDisabled()) {
+ infoAction();
+ }
+ break;
+ case "d":
+ case "D":
+ if (deleteButton != null && !deleteButton.isDisabled()) {
+ deleteAction();
+ }
+ break;
+ case "a":
+ case "A":
+ if (selectAllButton != null && !selectAllButton.isDisabled()) {
+ selectAllAction();
+ }
+ break;
+ case "m":
+ case "M":
+ if (mainMenuController != null) {
+ mainMenuController.getShowCommentsCheck().setSelected(!mainMenuController.getShowCommentsCheck().isSelected());
+ mainMenuController.checkShowComments();
+ }
+ break;
+ case "1":
+ if (imageSizeButton != null && !imageSizeButton.isDisabled()) {
+ imageSize();
+ }
+ break;
+ case "2":
+ if (paneSizeButton != null && !paneSizeButton.isDisabled()) {
+ paneSize();
+ }
+ break;
+ case "3":
+ if (zoomInButton != null && !zoomInButton.isDisabled()) {
+ zoomIn();
+ }
+ break;
+ case "4":
+ if (zoomOutButton != null && !zoomOutButton.isDisabled()) {
+ zoomOut();
+ }
+ break;
+ case "-":
+ setPaneFontSize(AppVaribles.getPaneFontSize() - 1);
+ break;
+ case "=":
+ setPaneFontSize(AppVaribles.getPaneFontSize() + 1);
+ break;
+ }
+
+ } else {
+ if (null != event.getCode()) {
+ switch (event.getCode()) {
+ case DELETE:
+ if (deleteButton != null && !deleteButton.isDisabled()) {
+ deleteAction();
+ }
+ break;
+ case HOME:
+ if (firstButton != null && !firstButton.isDisabled()) {
+ firstAction();
+ }
+ break;
+ case END:
+ if (lastButton != null && !lastButton.isDisabled()) {
+ lastAction();
+ }
+ break;
+ case PAGE_UP:
+ if (previousButton != null && !previousButton.isDisabled()) {
+ previousAction();
+ }
+ break;
+ case PAGE_DOWN:
+ if (nextButton != null && !nextButton.isDisabled()) {
+ nextAction();
+ }
+ break;
+ case F5:
+ closeStage();
+ break;
}
}
}
@@ -319,12 +542,39 @@ public void setInterfaceStyle(String style) {
}
}
+ protected boolean setPaneFontSize(int size) {
+ if (thisPane == null || size < 9 || size > 22
+ || size == AppVaribles.getPaneFontSize()) {
+ return false;
+ }
+ AppVaribles.setPaneFontSize(size);
+ thisPane.setStyle("-fx-font-size: " + size + "px;");
+ if (parentController != null && parentController.getThisPane() != null) {
+ parentController.getThisPane().setStyle("-fx-font-size: " + size + "px;");
+ }
+ return true;
+ }
+
+ public void refresh() {
+ if (parentController != null) {
+ parentController.refresh();
+ }
+ if (myFxml.contains("ImageManufacture") && !myFxml.contains("ImageManufactureBatch")) {
+ reloadStage(CommonValues.ImageManufactureFileFxml, getParentController().getMyStage().getTitle());
+ } else {
+ reloadStage(myFxml, getBaseTitle());
+ }
+
+ }
+
@FXML
protected void selectSourceFile(ActionEvent event) {
try {
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(sourcePathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(sourcePathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
File file = fileChooser.showOpenDialog(getMyStage());
if (file == null) {
@@ -355,8 +605,10 @@ protected void selectTargetPath(ActionEvent event) {
}
try {
DirectoryChooser chooser = new DirectoryChooser();
- File path = new File(AppVaribles.getUserConfigPath(targetPathKey, CommonValues.UserFilePath));
- chooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(targetPathKey);
+ if (path != null) {
+ chooser.setInitialDirectory(path);
+ }
File directory = chooser.showDialog(getMyStage());
if (directory == null) {
return;
@@ -382,7 +634,7 @@ protected void openTarget(ActionEvent event) {
}
if (targetIsFile && finalTargetName != null) {
- OpenFile.openTarget(getClass(), null, finalTargetName);
+ FxmlStage.openTarget(getClass(), null, finalTargetName);
} else {
if (targetSelectionController.targetPathInput != null) {
@@ -411,7 +663,83 @@ protected void openTarget(ActionEvent event) {
}
@FXML
- protected void startProcess(ActionEvent event) {
+ public void okAction() {
+
+ }
+
+ @FXML
+ public void startAction() {
+
+ }
+
+ @FXML
+ public void newAction() {
+
+ }
+
+ @FXML
+ public void copyAction() {
+
+ }
+
+ @FXML
+ public void saveAction() {
+
+ }
+
+ @FXML
+ public void deleteAction() {
+
+ }
+
+ @FXML
+ public void infoAction() {
+
+ }
+
+ @FXML
+ public void selectAllAction() {
+
+ }
+
+ @FXML
+ public void nextAction() {
+
+ }
+
+ @FXML
+ public void previousAction() {
+
+ }
+
+ @FXML
+ public void firstAction() {
+
+ }
+
+ @FXML
+ public void lastAction() {
+
+ }
+
+ @FXML
+ public void imageSize() {
+
+ }
+
+ @FXML
+ public void paneSize() {
+
+ }
+
+ @FXML
+ public void zoomIn() {
+
+ }
+
+ @FXML
+ public void zoomOut() {
+
}
@FXML
@@ -444,20 +772,62 @@ protected void clearSettings(ActionEvent event) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(getBaseTitle());
alert.setContentText(AppVaribles.getMessage("SureClear"));
+ alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
Optional result = alert.showAndWait();
if (result.get() != ButtonType.OK) {
return;
}
DerbyBase.clearData();
- clearTempFiles();
+ cleanAppPath();
AppVaribles.initAppVaribles();
popInformation(AppVaribles.getMessage("Successful"));
}
+ protected void cleanAppPath() {
+ try {
+ File userPath = new File(AppDataRoot);
+ if (userPath.exists()) {
+ File[] files = userPath.listFiles();
+ for (File f : files) {
+ if (f.isFile()) {
+ f.delete();
+ } else if (!CommonValues.AppDataPaths.contains(f)) {
+ FileTools.deleteDir(f);
+ }
+ }
+ }
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
+ }
+
+ protected void clearUserTempFiles() {
+ try {
+ File tempPath = AppVaribles.getUserTempPath();
+ if (tempPath.exists()) {
+ FileTools.deleteDir(tempPath);
+ }
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
+ }
+
+ protected void clearSystemTempFiles() {
+ try {
+ if (CommonValues.AppTempPath.exists()) {
+ FileTools.deleteDir(CommonValues.AppTempPath);
+ } else {
+ CommonValues.AppTempPath.mkdirs();
+ }
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
+ }
+
@FXML
protected void openUserPath(ActionEvent event) {
try {
- Desktop.getDesktop().browse(new File(UserFilePath).toURI());
+ Desktop.getDesktop().browse(new File(AppDataRoot).toURI());
} catch (Exception e) {
logger.error(e.toString());
}
@@ -480,7 +850,7 @@ protected File checkHelps() {
try {
String lang = AppVaribles.getLanguage();
String latest = AppVaribles.getSystemConfigValue("HelpsVersion", "");
- String newVersion = "4.8";
+ String newVersion = "4.9";
boolean updated = latest.equals(newVersion);
if (!updated) {
logger.debug("Updating Helps " + newVersion);
@@ -502,7 +872,7 @@ protected File checkHelps() {
protected void clearHelps() {
try {
- File file = new File(UserFilePath);
+ File file = new File(AppDataRoot);
if (file.exists()) {
File[] files = file.listFiles();
for (File f : files) {
@@ -516,22 +886,6 @@ protected void clearHelps() {
}
}
- protected void clearTempFiles() {
- try {
- File file = new File(UserFilePath);
- if (file.exists()) {
- File[] files = file.listFiles();
- for (File f : files) {
- if (f.isFile()) {
- f.delete();
- }
- }
- }
- } catch (Exception e) {
- logger.error(e.toString());
- }
- }
-
protected void cancelProcess(ActionEvent event) {
paused = false;
if (task != null && task.isRunning()) {
@@ -612,7 +966,7 @@ public BaseController openStage(String newFxml, boolean isOwned, boolean monitor
}
public BaseController openStage(String newFxml, String title, boolean isOwned, boolean monitorClosing) {
- return OpenFile.openNewStage(getClass(), getMyStage(), newFxml, title, isOwned, monitorClosing);
+ return FxmlStage.openNewStage(getClass(), getMyStage(), newFxml, title, isOwned, monitorClosing);
}
public boolean closeStage() {
@@ -626,9 +980,6 @@ public boolean closeStage() {
public boolean stageClosing() {
try {
-// logger.debug("stageClosing:" + getMyStage().getWidth() + "," + myStage.getHeight());
-// logger.debug(Platform.isImplicitExit());
-// logger.debug("stageClosing:" + getClass());
hidePopup();
if (timer != null) {
@@ -638,8 +989,8 @@ public boolean stageClosing() {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(getMyStage().getTitle());
alert.setContentText(AppVaribles.getMessage("TaskRunning"));
+ alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
Optional result = alert.showAndWait();
- logger.debug(result.get());
if (result.get() == ButtonType.OK && task != null) {
task.cancel();
} else {
@@ -647,39 +998,13 @@ public boolean stageClosing() {
}
}
- if (AppVaribles.scheduledTasks != null && !AppVaribles.scheduledTasks.isEmpty()) {
- if (AppVaribles.getUserConfigBoolean("StopAlarmsWhenExit")) {
- for (Long key : AppVaribles.scheduledTasks.keySet()) {
- ScheduledFuture future = AppVaribles.scheduledTasks.get(key);
- future.cancel(true);
- }
- AppVaribles.scheduledTasks = null;
- if (AppVaribles.executorService != null) {
- AppVaribles.executorService.shutdownNow();
- AppVaribles.executorService = null;
- }
- }
-
- } else {
- if (AppVaribles.scheduledTasks != null) {
- AppVaribles.scheduledTasks = null;
- }
- if (AppVaribles.executorService != null) {
- AppVaribles.executorService.shutdownNow();
- AppVaribles.executorService = null;
- }
- }
-
if (backgroundTask != null && backgroundTask.isRunning()) {
backgroundTask.cancel();
}
- if (AppVaribles.scheduledTasks == null) {
- Platform.setImplicitExit(true);
- }
-// logger.debug(Platform.isImplicitExit());
- return true;
+ Platform.setImplicitExit(AppVaribles.scheduledTasks == null);
+ return true;
} catch (Exception e) {
logger.debug(e.toString());
return false;
@@ -688,39 +1013,15 @@ public boolean stageClosing() {
}
public void alertError(String information) {
- try {
- Alert alert = new Alert(Alert.AlertType.ERROR);
- alert.setTitle(getMyStage().getTitle());
- alert.setHeaderText(null);
- alert.setContentText(information);
- alert.showAndWait();
- } catch (Exception e) {
- logger.error(e.toString());
- }
+ FxmlStage.alertError(getMyStage(), information);
}
public void alertWarning(String information) {
- try {
- Alert alert = new Alert(Alert.AlertType.WARNING);
- alert.setTitle(getMyStage().getTitle());
- alert.setHeaderText(null);
- alert.setContentText(information);
- alert.showAndWait();
- } catch (Exception e) {
- logger.error(e.toString());
- }
+ FxmlStage.alertError(getMyStage(), information);
}
public void alertInformation(String information) {
- try {
- Alert alert = new Alert(Alert.AlertType.INFORMATION);
- alert.setTitle(getMyStage().getTitle());
- alert.setHeaderText(null);
- alert.setContentText(information);
- alert.showAndWait();
- } catch (Exception e) {
- logger.error(e.toString());
- }
+ FxmlStage.alertInformation(getMyStage(), information);
}
public void popInformation(String text) {
@@ -843,12 +1144,12 @@ public void setMyStage(Stage myStage) {
}
public void openImageManufacture(String filename) {
- OpenFile.openImageManufacture(getClass(), null, new File(filename));
+ FxmlStage.openImageManufacture(getClass(), null, new File(filename));
}
public void openImageViewer(Image image) {
try {
- final ImageViewerController controller = OpenFile.openImageViewer(getClass(), null);
+ final ImageViewerController controller = FxmlStage.openImageViewer(getClass(), null);
if (controller != null) {
controller.loadImage(image);
}
@@ -859,7 +1160,7 @@ public void openImageViewer(Image image) {
public void openImageViewer(ImageInformation info) {
try {
- final ImageViewerController controller = OpenFile.openImageViewer(getClass(), null);
+ final ImageViewerController controller = FxmlStage.openImageViewer(getClass(), null);
if (controller != null) {
controller.loadImage(info);
}
@@ -869,7 +1170,7 @@ public void openImageViewer(ImageInformation info) {
}
public void openImageViewer(String file) {
- OpenFile.openImageViewer(getClass(), null, new File(file));
+ FxmlStage.openImageViewer(getClass(), null, new File(file));
}
public LoadingController openHandlingStage(Modality block) {
diff --git a/MyBox/src/main/java/mara/mybox/controller/BytesEditerController.java b/MyBox/src/main/java/mara/mybox/controller/BytesEditerController.java
index 4ce7fdb52..84af9d003 100644
--- a/MyBox/src/main/java/mara/mybox/controller/BytesEditerController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/BytesEditerController.java
@@ -17,9 +17,9 @@
import javafx.scene.control.Toggle;
import javafx.stage.Modality;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.FileEditInformation.Line_Break;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.data.FileEditInformation.Line_Break;
import mara.mybox.tools.ByteTools;
import mara.mybox.tools.StringTools;
import mara.mybox.tools.TextTools;
@@ -40,6 +40,8 @@ public class BytesEditerController extends FileEditerController {
private RadioButton bytesNumberRadio, byteRadio;
public BytesEditerController() {
+ TipsLabelKey = "BytesEditerTips";
+
setBytesType();
}
diff --git a/MyBox/src/main/java/mara/mybox/controller/ColorPaletteController.java b/MyBox/src/main/java/mara/mybox/controller/ColorPaletteController.java
index 963bfcba0..bb73864b5 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ColorPaletteController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ColorPaletteController.java
@@ -7,9 +7,9 @@
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
-import static mara.mybox.fxml.FxmlColorTools.rgb2AlphaHex;
-import static mara.mybox.fxml.FxmlColorTools.rgb2Hex;
-import static mara.mybox.objects.AppVaribles.getMessage;
+import static mara.mybox.fxml.FxmlColor.rgb2AlphaHex;
+import static mara.mybox.fxml.FxmlColor.rgb2Hex;
+import static mara.mybox.value.AppVaribles.getMessage;
/**
* @Author Mara
diff --git a/MyBox/src/main/java/mara/mybox/controller/ConvolutionKernelManagerController.java b/MyBox/src/main/java/mara/mybox/controller/ConvolutionKernelManagerController.java
index 7ad292fe8..175953311 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ConvolutionKernelManagerController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ConvolutionKernelManagerController.java
@@ -38,16 +38,17 @@
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
+import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
-import static mara.mybox.objects.AppVaribles.logger;
+import static mara.mybox.value.AppVaribles.logger;
import mara.mybox.db.TableConvolutionKernel;
import mara.mybox.db.TableFloatMatrix;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.ConvolutionKernel;
-import mara.mybox.objects.ConvolutionKernel.Convolution_Type;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.value.CommonValues;
+import mara.mybox.data.ConvolutionKernel;
+import mara.mybox.data.ConvolutionKernel.Convolution_Type;
import mara.mybox.tools.DateTools;
import mara.mybox.fxml.FxmlTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
@@ -63,7 +64,7 @@ public class ConvolutionKernelManagerController extends BaseController {
protected ObservableList tableData = FXCollections.observableArrayList();
private int width, height, type, edge_Op;
- private boolean isSettingValues, matrixValid;
+ private boolean matrixValid;
private GridPane matrixPane;
private TextField[][] matrixInputs;
private float[][] matrixValues;
@@ -75,7 +76,7 @@ public class ConvolutionKernelManagerController extends BaseController {
@FXML
private SplitPane splitPane;
@FXML
- private Button editButton, deleteButton, saveButton, copyButton, gaussButton;
+ private Button editButton, gaussButton;
@FXML
private TableView tableView;
@FXML
@@ -154,11 +155,11 @@ private void loadList() {
if (parentController != null && parentFxml != null) {
if (parentFxml.contains("ImageManufactureConvolution")) {
- ImageManufactureConvolutionController p = (ImageManufactureConvolutionController) parentController;
- p.loadList(records);
- } else if (parentFxml.contains("ImageManufactureBatchConvolution")) {
- ImageManufactureBatchConvolutionController p = (ImageManufactureBatchConvolutionController) parentController;
- p.loadList(records);
+ ImageManufactureEffectsController p = (ImageManufactureEffectsController) parentController;
+ p.loadKernelsList(records);
+ } else if (parentFxml.contains("ImageManufactureBatchEffects")) {
+ ImageManufactureBatchEffectsController p = (ImageManufactureBatchEffectsController) parentController;
+ p.loadKernelsList(records);
}
}
}
@@ -285,13 +286,13 @@ private void checkEdges() {
if (isSettingValues) {
return;
}
- edge_Op = ConvolutionKernel.Edge_Op.FILL_ZERO;
+ edge_Op = ConvolutionKernel.Edge_Op.COPY;
RadioButton selected = (RadioButton) edgesGroup.getSelectedToggle();
if (selected == null) {
return;
}
- if (getMessage("KeepValues").equals(selected.getText())) {
- edge_Op = ConvolutionKernel.Edge_Op.COPY;
+ if (!getMessage("KeepValues").equals(selected.getText())) {
+ edge_Op = ConvolutionKernel.Edge_Op.FILL_ZERO;
}
} catch (Exception e) {
logger.error(e.toString());
@@ -479,7 +480,8 @@ private void editAction() {
}
@FXML
- private void copyAction() {
+ @Override
+ public void copyAction() {
editAction();
nameInput.setDisable(false);
nameInput.setText(kernel.getName() + " mmm");
@@ -487,7 +489,8 @@ private void copyAction() {
}
@FXML
- private void deleteAction(ActionEvent event) {
+ @Override
+ public void deleteAction() {
final List selected = tableView.getSelectionModel().getSelectedItems();
if (selected == null || selected.isEmpty()) {
return;
@@ -495,6 +498,7 @@ private void deleteAction(ActionEvent event) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(getMyStage().getTitle());
alert.setContentText(AppVaribles.getMessage("SureDelete"));
+ alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
ButtonType buttonSure = new ButtonType(AppVaribles.getMessage("Sure"));
ButtonType buttonCancel = new ButtonType(AppVaribles.getMessage("Cancel"));
alert.getButtonTypes().setAll(buttonSure, buttonCancel);
@@ -538,6 +542,7 @@ private void clearAction(ActionEvent event) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(getMyStage().getTitle());
alert.setContentText(AppVaribles.getMessage("SureDelete"));
+ alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
ButtonType buttonSure = new ButtonType(AppVaribles.getMessage("Sure"));
ButtonType buttonCancel = new ButtonType(AppVaribles.getMessage("Cancel"));
alert.getButtonTypes().setAll(buttonSure, buttonCancel);
@@ -689,18 +694,19 @@ private void testAction(ActionEvent event) {
if (!pickKernel()) {
return;
}
- ImageManufactureConvolutionController c
- = (ImageManufactureConvolutionController) openStage(CommonValues.ImageManufactureConvolutionFxml, true);
+ ImageManufactureEffectsController c
+ = (ImageManufactureEffectsController) openStage(CommonValues.ImageManufactureEffectsFxml, false);
c.setParentController(getMyController());
c.setParentFxml(getMyFxml());
c.loadImage(new Image("img/p3.png"));
- c.setTab("convolution");
+ c.setTab("effects");
c.showRef();
- c.selectKernel(kernel);
+ c.applyKernel(kernel);
}
@FXML
- private void saveAction(ActionEvent event) {
+ @Override
+ public void saveAction() {
if (!pickKernel() || name == null || name.isEmpty()) {
return;
}
diff --git a/MyBox/src/main/java/mara/mybox/controller/DirectorySynchronizeController.java b/MyBox/src/main/java/mara/mybox/controller/DirectorySynchronizeController.java
index 2569fb15d..f76c8b353 100644
--- a/MyBox/src/main/java/mara/mybox/controller/DirectorySynchronizeController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/DirectorySynchronizeController.java
@@ -28,11 +28,10 @@
import javafx.scene.layout.VBox;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.FileSynchronizeAttributes;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.data.FileSynchronizeAttributes;
import mara.mybox.tools.DateTools;
import mara.mybox.tools.FileTools;
import mara.mybox.fxml.FxmlTools;
@@ -86,7 +85,7 @@ public DirectorySynchronizeController() {
protected void initializeNext() {
try {
- sourcePathInput.setText(AppVaribles.getUserConfigValue(sourcePathKey, CommonValues.UserFilePath));
+ sourcePathInput.setText(AppVaribles.getUserConfigPath(sourcePathKey).getAbsolutePath());
sourcePathInput.textProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends String> observable,
@@ -102,7 +101,7 @@ public void changed(ObservableValue extends String> observable,
}
});
- targetPathInput.setText(AppVaribles.getUserConfigValue(targetPathKey, CommonValues.UserFilePath));
+ targetPathInput.setText(AppVaribles.getUserConfigPath(targetPathKey).getAbsolutePath());
targetPathInput.textProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends String> observable,
@@ -150,8 +149,10 @@ public void changed(ObservableValue extends Toggle> ov,
protected void selectSourcePath(ActionEvent event) {
try {
DirectoryChooser chooser = new DirectoryChooser();
- File path = new File(AppVaribles.getUserConfigPath(sourcePathKey, CommonValues.UserFilePath));
- chooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(sourcePathKey);
+ if (path != null) {
+ chooser.setInitialDirectory(path);
+ }
File directory = chooser.showDialog(getMyStage());
if (directory == null) {
return;
@@ -173,8 +174,10 @@ protected void selectTargetPath(ActionEvent event) {
}
try {
DirectoryChooser chooser = new DirectoryChooser();
- File path = new File(AppVaribles.getUserConfigPath(targetPathKey, CommonValues.UserFilePath));
- chooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(targetPathKey);
+ if (path != null) {
+ chooser.setInitialDirectory(path);
+ }
File directory = chooser.showDialog(getMyStage());
if (directory == null) {
return;
@@ -295,7 +298,7 @@ protected boolean initAttributes() {
@FXML
@Override
- protected void startProcess(ActionEvent event) {
+ public void startAction() {
try {
if (!initAttributes()) {
return;
@@ -408,7 +411,7 @@ public void handle(ActionEvent event) {
operationBarController.pauseButton.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
- startProcess(event);
+ startAction();
}
});
} else {
@@ -416,7 +419,7 @@ public void handle(ActionEvent event) {
operationBarController.startButton.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
- startProcess(event);
+ startAction();
}
});
operationBarController.pauseButton.setVisible(false);
diff --git a/MyBox/src/main/java/mara/mybox/controller/FileCutController.java b/MyBox/src/main/java/mara/mybox/controller/FileCutController.java
index 9cbc066fd..336928e28 100644
--- a/MyBox/src/main/java/mara/mybox/controller/FileCutController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/FileCutController.java
@@ -16,10 +16,10 @@
import javafx.scene.text.Font;
import mara.mybox.fxml.FxmlTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.FileInformation;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.value.CommonValues;
+import mara.mybox.data.FileInformation;
import mara.mybox.tools.ByteTools;
import mara.mybox.tools.FileTools;
@@ -186,7 +186,7 @@ public void changed(ObservableValue extends String> observable, String oldValu
}
}
});
- targetPathInput.setText(AppVaribles.getUserConfigValue(targetPathKey, CommonValues.UserFilePath));
+ targetPathInput.setText(AppVaribles.getUserConfigPath(targetPathKey).getAbsolutePath());
operationBarController.openTargetButton.disableProperty().bind(Bindings.isEmpty(targetPathInput.textProperty())
.or(targetPathInput.styleProperty().isEqualTo(badStyle))
diff --git a/MyBox/src/main/java/mara/mybox/controller/FileEditerController.java b/MyBox/src/main/java/mara/mybox/controller/FileEditerController.java
index 0b22a229f..e517aa018 100644
--- a/MyBox/src/main/java/mara/mybox/controller/FileEditerController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/FileEditerController.java
@@ -33,19 +33,20 @@
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
+import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.FileChooser;
import javafx.stage.Modality;
import mara.mybox.fxml.FxmlTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.FileEditInformation;
-import mara.mybox.objects.FileEditInformation.Edit_Type;
-import mara.mybox.objects.FileEditInformation.Filter_Type;
-import mara.mybox.objects.FileEditInformation.Line_Break;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.value.CommonValues;
+import mara.mybox.data.FileEditInformation;
+import mara.mybox.data.FileEditInformation.Edit_Type;
+import mara.mybox.data.FileEditInformation.Filter_Type;
+import mara.mybox.data.FileEditInformation.Line_Break;
import mara.mybox.tools.StringTools;
import mara.mybox.tools.TextTools;
@@ -63,7 +64,7 @@ public abstract class FileEditerController extends BaseController {
protected int currentFound, currentPageTmp, lineLocation, objectLocation;
protected long pageSize, currentPage;
protected SimpleBooleanProperty fileChanged;
- protected boolean isSettingValues, findWhole, charsetByUser;
+ protected boolean findWhole, charsetByUser;
protected FileEditInformation sourceInformation, targetInformation;
protected SaveAsType saveAsType;
protected TextArea displayArea;
@@ -98,12 +99,11 @@ public enum SaveAsType {
@FXML
protected Label editLabel, bomLabel, pageLabel, charsetLabel, selectionLabel;
@FXML
- protected Button openButton, createButton, saveButton, charactersButton, linesButton, recoverButton,
- redoButton, undoButton, deleteButton, cutButton, copyButton, pasteButton, selectAllButton,
+ protected Button openButton, createButton, charactersButton, linesButton, recoverButton,
+ redoButton, undoButton, cutButton, pasteButton,
findFirstButton, findPreviousButton, findNextButton, findLastButton, countButton,
- replaceButton, replaceAllButton, filterButton, infoButton, pageSizeButton,
- firstPageButton, perviousPageButton, nextPageButton, lastPageButton, pageGoButton,
- locateObjectButton, locateLineButton;
+ replaceButton, replaceAllButton, filterButton,
+ pageGoButton, locateObjectButton, locateLineButton;
@FXML
protected TextField fromInput, toInput, pageSizeInput, pageInput, filterInput, findInput, replaceInput,
currentLineBreak, objectNumberInput, lineInput;
@@ -335,11 +335,8 @@ protected void checkSaveAsType() {
protected void initEditBar() {
try {
- Tooltip tips = new Tooltip("CTRL+c");
- tips.setFont(new Font(16));
- FxmlTools.quickTooltip(copyButton, tips);
- tips = new Tooltip("CTRL+v");
+ Tooltip tips = new Tooltip("CTRL+v");
tips.setFont(new Font(16));
FxmlTools.quickTooltip(pasteButton, tips);
@@ -351,21 +348,13 @@ protected void initEditBar() {
tips.setFont(new Font(16));
FxmlTools.quickTooltip(undoButton, tips);
- tips = new Tooltip("CTRL+a");
- tips.setFont(new Font(16));
- FxmlTools.quickTooltip(selectAllButton, tips);
-
tips = new Tooltip("CTRL+x");
tips.setFont(new Font(16));
FxmlTools.quickTooltip(cutButton, tips);
- tips = new Tooltip("CTRL+d");
- tips.setFont(new Font(16));
- FxmlTools.quickTooltip(deleteButton, tips);
-
- tips = new Tooltip("CTRL+s");
+ tips = new Tooltip("CTRL+r");
tips.setFont(new Font(16));
- FxmlTools.quickTooltip(saveButton, tips);
+ FxmlTools.quickTooltip(recoverButton, tips);
} catch (Exception e) {
logger.error(e.toString());
@@ -572,6 +561,10 @@ protected void initReplaceTab() {
tips.setFont(new Font(16));
FxmlTools.quickTooltip(findFirstButton, tips);
+ tips = new Tooltip("CTRL+l");
+ tips.setFont(new Font(16));
+ FxmlTools.quickTooltip(findLastButton, tips);
+
tips = new Tooltip("CTRL+n");
tips.setFont(new Font(16));
FxmlTools.quickTooltip(findNextButton, tips);
@@ -580,7 +573,7 @@ protected void initReplaceTab() {
tips.setFont(new Font(16));
FxmlTools.quickTooltip(findPreviousButton, tips);
- tips = new Tooltip("CTRL+r");
+ tips = new Tooltip("CTRL+e");
tips.setFont(new Font(16));
FxmlTools.quickTooltip(replaceButton, tips);
@@ -869,7 +862,11 @@ protected void setSecondAreaSelection() {
}
@FXML
- protected void copyAction() {
+ @Override
+ public void copyAction() {
+ if (!mainArea.isFocused()) {
+ return;
+ }
try {
if (!copyButton.isDisabled()) {
mainArea.copy();
@@ -881,6 +878,9 @@ protected void copyAction() {
@FXML
protected void pasteAction() {
+ if (!mainArea.isFocused()) {
+ return;
+ }
try {
if (!pasteButton.isDisabled()) {
mainArea.paste();
@@ -892,6 +892,9 @@ protected void pasteAction() {
@FXML
protected void cutAction() {
+ if (!mainArea.isFocused()) {
+ return;
+ }
try {
if (!cutButton.isDisabled()) {
mainArea.cut();
@@ -902,7 +905,11 @@ protected void cutAction() {
}
@FXML
- protected void deleteAction() {
+ @Override
+ public void deleteAction() {
+ if (!mainArea.isFocused()) {
+ return;
+ }
try {
if (!deleteButton.isDisabled()) {
mainArea.deleteText(mainArea.getSelection());
@@ -913,7 +920,11 @@ protected void deleteAction() {
}
@FXML
- protected void selectAllAction() {
+ @Override
+ public void selectAllAction() {
+ if (!mainArea.isFocused()) {
+ return;
+ }
try {
if (!selectAllButton.isDisabled()) {
mainArea.selectAll();
@@ -925,6 +936,9 @@ protected void selectAllAction() {
@FXML
protected void redoAction() {
+ if (!mainArea.isFocused()) {
+ return;
+ }
try {
if (!redoButton.isDisabled()) {
mainArea.redo();
@@ -936,6 +950,9 @@ protected void redoAction() {
@FXML
protected void undoAction() {
+ if (!mainArea.isFocused()) {
+ return;
+ }
try {
if (!undoButton.isDisabled()) {
mainArea.undo();
@@ -947,6 +964,9 @@ protected void undoAction() {
@FXML
protected void recoverAction() {
+ if (!mainArea.isFocused()) {
+ return;
+ }
try {
if (!recoverButton.isDisabled() && sourceInformation.getFile() != null) {
loadPage();
@@ -959,58 +979,41 @@ protected void recoverAction() {
@Override
protected void keyEventsHandler(KeyEvent event) {
super.keyEventsHandler(event);
- String key = event.getText();
- if (key == null || key.isEmpty()) {
- return;
- }
if (event.isControlDown()) {
+ String key = event.getText();
+ if (key == null || key.isEmpty()) {
+ return;
+ }
switch (key) {
- case "c":
- case "C":
- if (mainArea.isFocused() && !copyButton.isDisabled()) {
- copyAction();
- }
- break;
- case "v":
- case "V":
- if (mainArea.isFocused() && !pasteButton.isDisabled()) {
- pasteAction();
- }
- break;
- case "z":
- case "Z":
- if (mainArea.isFocused() && !undoButton.isDisabled()) {
- undoAction();
- }
- break;
- case "y":
- case "Y":
- if (mainArea.isFocused() && !redoButton.isDisabled()) {
- redoAction();
- }
- break;
- case "a":
- case "A":
- if (mainArea.isFocused() && !selectAllButton.isDisabled()) {
- selectAllAction();
- }
- break;
- case "x":
- case "X":
- if (mainArea.isFocused() && !cutButton.isDisabled()) {
- cutAction();
- }
- break;
- case "d":
- case "D":
- if (mainArea.isFocused() && !deleteButton.isDisabled()) {
- deleteAction();
- }
- break;
- case "s":
- case "S":
- if (!saveButton.isDisabled()) {
- saveAction();
+ // TextArea itself supports these shortcuts.
+// case "v":
+// case "V":
+// if (mainArea.isFocused() && !pasteButton.isDisabled()) {
+// pasteAction();
+// }
+// break;
+// case "z":
+// case "Z":
+// if (mainArea.isFocused() && !undoButton.isDisabled()) {
+// undoAction();
+// }
+// break;
+// case "y":
+// case "Y":
+// if (mainArea.isFocused() && !redoButton.isDisabled()) {
+// redoAction();
+// }
+// break;
+// case "x":
+// case "X":
+// if (mainArea.isFocused() && !cutButton.isDisabled()) {
+// cutAction();
+// }
+// break;
+ case "r":
+ case "R":
+ if (mainArea.isFocused() && !recoverButton.isDisabled()) {
+ recoverAction();
}
break;
case "f":
@@ -1019,6 +1022,12 @@ protected void keyEventsHandler(KeyEvent event) {
findFirstAction();
}
break;
+ case "l":
+ case "L":
+ if (!findLastButton.isDisabled()) {
+ findLastAction();
+ }
+ break;
case "n":
case "N":
if (!findNextButton.isDisabled()) {
@@ -1031,8 +1040,8 @@ protected void keyEventsHandler(KeyEvent event) {
findPreviousAction();
}
break;
- case "r":
- case "R":
+ case "e":
+ case "E":
if (!replaceButton.isDisabled()) {
replaceAction();
}
@@ -1044,7 +1053,8 @@ protected void keyEventsHandler(KeyEvent event) {
}
@FXML
- protected void pageSizeAction() {
+ @Override
+ public void okAction() {
if (!checkSavingForNextAction()) {
return;
}
@@ -1469,6 +1479,7 @@ protected void replaceAllAction() {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(getMyStage().getTitle());
alert.setContentText(AppVaribles.getMessage("SureReplaceAll"));
+ alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
ButtonType buttonSure = new ButtonType(AppVaribles.getMessage("Sure"));
ButtonType buttonCancel = new ButtonType(AppVaribles.getMessage("Cancel"));
alert.getButtonTypes().setAll(buttonSure, buttonCancel);
@@ -1558,12 +1569,13 @@ protected void filterAction() {
}
@FXML
- protected void nextPageAction() {
+ @Override
+ public void nextAction() {
if (!checkSavingForNextAction()) {
return;
}
if (sourceInformation.getObjectsNumber() <= sourceInformation.getCurrentPageObjectEnd()) {
- nextPageButton.setDisable(true);
+ nextButton.setDisable(true);
} else {
sourceInformation.setCurrentPage(sourceInformation.getCurrentPage() + 1);
currentFound = -1;
@@ -1572,12 +1584,13 @@ protected void nextPageAction() {
}
@FXML
- protected void previousPageAction() {
+ @Override
+ public void previousAction() {
if (!checkSavingForNextAction()) {
return;
}
if (sourceInformation.getCurrentPage() <= 1) {
- perviousPageButton.setDisable(true);
+ previousButton.setDisable(true);
} else {
sourceInformation.setCurrentPage(sourceInformation.getCurrentPage() - 1);
currentFound = -1;
@@ -1586,7 +1599,8 @@ protected void previousPageAction() {
}
@FXML
- protected void firstPageAction() {
+ @Override
+ public void firstAction() {
if (!checkSavingForNextAction()) {
return;
}
@@ -1596,7 +1610,8 @@ protected void firstPageAction() {
}
@FXML
- protected void lastPageAction() {
+ @Override
+ public void lastAction() {
if (!checkSavingForNextAction()) {
return;
}
@@ -1619,7 +1634,8 @@ protected void goPageAction() {
}
@FXML
- protected void infoAction() {
+ @Override
+ public void infoAction() {
}
@@ -1756,8 +1772,10 @@ protected void openAction() {
}
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(FilePathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(FilePathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
final File file = fileChooser.showOpenDialog(getMyStage());
if (file == null) {
@@ -1973,13 +1991,14 @@ protected void updateInterface(boolean changed) {
} else {
getMyStage().setTitle(t);
}
- if (editLabel != null) {
- editLabel.setText("");
- }
if (!formatMainArea()) {
- editLabel.setText(AppVaribles.getMessage("InvalidData"));
+ if (editLabel != null) {
+ editLabel.setText(AppVaribles.getMessage("InvalidData"));
+ }
mainArea.setStyle(badStyle);
return;
+ } else if (editLabel != null) {
+ editLabel.setText("");
}
mainArea.setStyle(null);
String text = mainArea.getText();
@@ -2038,15 +2057,12 @@ protected void updateInterface(boolean changed) {
if (currentBox != null) {
currentBox.setDisable(changed || sourceInformation.isWithBom());
}
- if (editLabel != null && changed) {
- editLabel.setText(AppVaribles.getMessage("PaginateComments"));
- }
if (locateObjectButton != null) {
locateObjectButton.setDisable(changed);
locateLineButton.setDisable(changed);
}
- perviousPageButton.setDisable(sourceInformation.getCurrentPage() <= 1);
- nextPageButton.setDisable(sourceInformation.getObjectsNumber() <= sourceInformation.getCurrentPageObjectEnd());
+ previousButton.setDisable(sourceInformation.getCurrentPage() <= 1);
+ nextButton.setDisable(sourceInformation.getObjectsNumber() <= sourceInformation.getCurrentPageObjectEnd());
if (sourceInformation.getObjectsNumber() % sourceInformation.getPageSize() == 0) {
sourceInformation.setPagesNumber(sourceInformation.getObjectsNumber() / sourceInformation.getPageSize());
} else {
@@ -2084,8 +2100,8 @@ protected void updateInterface(boolean changed) {
}
}
}
- if (pageSizeButton != null) {
- pageSizeButton.setDisable(changed);
+ if (okButton != null) {
+ okButton.setDisable(changed);
}
setSecondArea(text);
@@ -2138,7 +2154,8 @@ protected void countCurrentFound() {
}
@FXML
- protected void saveAction() {
+ @Override
+ public void saveAction() {
if (sourceFile == null) {
saveNew();
} else {
@@ -2148,8 +2165,10 @@ protected void saveAction() {
protected void saveNew() {
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(FilePathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(FilePathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
final File file = fileChooser.showSaveDialog(getMyStage());
if (file == null) {
@@ -2196,6 +2215,7 @@ protected void saveExisted() {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(getMyStage().getTitle());
alert.setContentText(AppVaribles.getMessage("SureOverrideFile"));
+ alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
ButtonType buttonSave = new ButtonType(AppVaribles.getMessage("Save"));
ButtonType buttonSaveAs = new ButtonType(AppVaribles.getMessage("SaveAs"));
ButtonType buttonCancel = new ButtonType(AppVaribles.getMessage("Cancel"));
@@ -2247,8 +2267,10 @@ public void run() {
@FXML
protected void saveAsAction() {
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(FilePathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(FilePathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
final File file = fileChooser.showSaveDialog(getMyStage());
if (file == null) {
@@ -2352,6 +2374,7 @@ public boolean checkSavingForNextAction() {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(getMyStage().getTitle());
alert.setContentText(AppVaribles.getMessage("NeedSaveBeforeAction"));
+ alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
ButtonType buttonSave = new ButtonType(AppVaribles.getMessage("Save"));
ButtonType buttonNotSave = new ButtonType(AppVaribles.getMessage("NotSave"));
ButtonType buttonCancel = new ButtonType(AppVaribles.getMessage("Cancel"));
diff --git a/MyBox/src/main/java/mara/mybox/controller/FileFilterController.java b/MyBox/src/main/java/mara/mybox/controller/FileFilterController.java
index 9141ce73f..326cb29aa 100644
--- a/MyBox/src/main/java/mara/mybox/controller/FileFilterController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/FileFilterController.java
@@ -8,10 +8,9 @@
import javafx.scene.control.TextField;
import javafx.stage.FileChooser;
import javafx.stage.Modality;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.FileEditInformation;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.data.FileEditInformation;
/**
* @Author Mara
@@ -101,10 +100,12 @@ public void run() {
@FXML
@Override
- protected void saveAction() {
+ public void saveAction() {
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(FilePathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(FilePathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
final File file = fileChooser.showSaveDialog(getMyStage());
if (file == null) {
diff --git a/MyBox/src/main/java/mara/mybox/controller/FileMergeController.java b/MyBox/src/main/java/mara/mybox/controller/FileMergeController.java
index e6cc43a28..37eb3050b 100644
--- a/MyBox/src/main/java/mara/mybox/controller/FileMergeController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/FileMergeController.java
@@ -1,5 +1,6 @@
package mara.mybox.controller;
+import mara.mybox.fxml.FxmlStage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -13,10 +14,10 @@
import javafx.fxml.FXML;
import javafx.stage.FileChooser;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.FileInformation;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.value.CommonValues;
+import mara.mybox.data.FileInformation;
import mara.mybox.tools.ByteTools;
/**
@@ -61,8 +62,8 @@ public void changed(ObservableValue extends String> observable, String oldValu
protected void selectTargetFile(ActionEvent event) {
try {
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(targetPathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(targetPathKey);
+ if ( path.exists() ) fileChooser.setInitialDirectory(path);
fileChooser.getExtensionFilters().addAll(CommonValues.PdfExtensionFilter);
final File file = fileChooser.showSaveDialog(getMyStage());
if (file == null) {
@@ -172,13 +173,13 @@ protected void viewFile(File file) {
AppVaribles.getMessage("BytesEditer"), false, true);
controller.openFile(file);
} else {
- OpenFile.openTarget(getClass(), null, file.getAbsolutePath());
+ FxmlStage.openTarget(getClass(), null, file.getAbsolutePath());
}
}
@Override
protected void openTarget(ActionEvent event) {
- OpenFile.openTarget(getClass(), null, targetFile.getAbsolutePath());
+ FxmlStage.openTarget(getClass(), null, targetFile.getAbsolutePath());
}
}
diff --git a/MyBox/src/main/java/mara/mybox/controller/FilesArrangeController.java b/MyBox/src/main/java/mara/mybox/controller/FilesArrangeController.java
index 957232b7e..eec632234 100644
--- a/MyBox/src/main/java/mara/mybox/controller/FilesArrangeController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/FilesArrangeController.java
@@ -27,14 +27,13 @@
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import mara.mybox.fxml.FxmlTools;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.FileSynchronizeAttributes;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.data.FileSynchronizeAttributes;
import mara.mybox.tools.DateTools;
import mara.mybox.tools.FileTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import static mara.mybox.objects.AppVaribles.logger;
+import static mara.mybox.value.AppVaribles.logger;
import mara.mybox.tools.ValueTools;
/**
@@ -126,7 +125,7 @@ protected void initializeNext() {
}
private void initDirTab() {
- sourcePathInput.setText(AppVaribles.getUserConfigValue(sourcePathKey, CommonValues.UserFilePath));
+ sourcePathInput.setText(AppVaribles.getUserConfigPath(sourcePathKey).getAbsolutePath());
sourcePathInput.textProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends String> observable,
@@ -142,7 +141,7 @@ public void changed(ObservableValue extends String> observable,
}
});
- targetPathInput.setText(AppVaribles.getUserConfigValue(targetPathKey, CommonValues.UserFilePath));
+ targetPathInput.setText(AppVaribles.getUserConfigPath(targetPathKey).getAbsolutePath());
targetPathInput.textProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends String> observable,
@@ -294,8 +293,10 @@ private void checkDirType() {
protected void selectSourcePath(ActionEvent event) {
try {
DirectoryChooser chooser = new DirectoryChooser();
- File path = new File(AppVaribles.getUserConfigPath(sourcePathKey, CommonValues.UserFilePath));
- chooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(sourcePathKey);
+ if (path != null) {
+ chooser.setInitialDirectory(path);
+ }
File directory = chooser.showDialog(getMyStage());
if (directory == null) {
return;
@@ -314,8 +315,10 @@ protected void selectTargetPath(ActionEvent event) {
}
try {
DirectoryChooser chooser = new DirectoryChooser();
- File path = new File(AppVaribles.getUserConfigPath(targetPathKey, CommonValues.UserFilePath));
- chooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(targetPathKey);
+ if (path != null) {
+ chooser.setInitialDirectory(path);
+ }
File directory = chooser.showDialog(getMyStage());
if (directory == null) {
return;
@@ -389,7 +392,7 @@ protected boolean initAttributes() {
@FXML
@Override
- protected void startProcess(ActionEvent event) {
+ public void startAction() {
try {
if (!initAttributes()) {
return;
@@ -488,7 +491,7 @@ public void handle(ActionEvent event) {
operationBarController.pauseButton.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
- startProcess(event);
+ startAction();
}
});
@@ -497,7 +500,7 @@ public void handle(ActionEvent event) {
operationBarController.startButton.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
- startProcess(event);
+ startAction();
}
});
operationBarController.pauseButton.setVisible(false);
diff --git a/MyBox/src/main/java/mara/mybox/controller/FilesBatchController.java b/MyBox/src/main/java/mara/mybox/controller/FilesBatchController.java
index 60d6800b6..7a45cb08b 100644
--- a/MyBox/src/main/java/mara/mybox/controller/FilesBatchController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/FilesBatchController.java
@@ -33,13 +33,13 @@
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.util.Callback;
-import mara.mybox.objects.AppVaribles;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.FileInformation;
+import mara.mybox.value.AppVaribles;
+import mara.mybox.value.CommonValues;
+import mara.mybox.data.FileInformation;
import mara.mybox.fxml.FxmlTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import static mara.mybox.objects.AppVaribles.logger;
+import static mara.mybox.value.AppVaribles.getMessage;
+import static mara.mybox.value.AppVaribles.logger;
import mara.mybox.tools.DateTools;
import mara.mybox.tools.ValueTools;
@@ -81,7 +81,7 @@ protected class ProcessParameters {
protected TextField targetSuffixInput;
@FXML
protected Button addFilesButton, addDirectoryButton, insertFilesButton, insertDirectoryButton,
- upButton, downButton, deleteButton, clearButton, openButton;
+ upButton, downButton, clearButton, openButton;
@FXML
protected CheckBox subDirCheck, filesNameCheck;
@FXML
@@ -249,7 +249,7 @@ public void changed(ObservableValue extends String> observable, String oldValu
}
}
});
- targetPathInput.setText(AppVaribles.getUserConfigValue(targetPathKey, CommonValues.UserFilePath));
+ targetPathInput.setText(AppVaribles.getUserConfigPath(targetPathKey).getAbsolutePath());
targetExistGroup.selectedToggleProperty().addListener(new ChangeListener() {
@Override
@@ -333,8 +333,10 @@ protected void insertDirectoryAction(ActionEvent event) {
protected void addFilesAction(int index) {
try {
final FileChooser fileChooser = new FileChooser();
- File defaultPath = new File(AppVaribles.getUserConfigPath(sourcePathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(defaultPath);
+ File defaultPath = AppVaribles.getUserConfigPath(sourcePathKey);
+ if (defaultPath.exists()) {
+ fileChooser.setInitialDirectory(defaultPath);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
List files = fileChooser.showOpenMultipleDialog(getMyStage());
@@ -368,8 +370,10 @@ protected void addFilesAction(int index) {
protected void addDirectoryAction(int index) {
try {
DirectoryChooser dirChooser = new DirectoryChooser();
- File defaultPath = new File(AppVaribles.getUserConfigPath(sourcePathKey, CommonValues.UserFilePath));
- dirChooser.setInitialDirectory(defaultPath);
+ File defaultPath = AppVaribles.getUserConfigPath(sourcePathKey);
+ if (defaultPath != null) {
+ dirChooser.setInitialDirectory(defaultPath);
+ }
File directory = dirChooser.showDialog(getMyStage());
if (directory == null) {
return;
@@ -392,7 +396,8 @@ protected void addDirectoryAction(int index) {
}
@FXML
- protected void deleteAction(ActionEvent event) {
+ @Override
+ public void deleteAction() {
List selected = new ArrayList<>();
selected.addAll(sourceTableView.getSelectionModel().getSelectedIndices());
if (selected.isEmpty()) {
@@ -493,7 +498,7 @@ protected void openTarget(ActionEvent event) {
@FXML
@Override
- protected void startProcess(ActionEvent event) {
+ public void startAction() {
isPreview = false;
makeActualParameters();
currentParameters = actualParameters;
@@ -755,7 +760,7 @@ public void handle(ActionEvent event) {
operationBarController.pauseButton.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
- startProcess(event);
+ startAction();
}
});
paraBox.setDisable(true);
@@ -764,7 +769,7 @@ public void handle(ActionEvent event) {
operationBarController.startButton.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
- startProcess(event);
+ startAction();
}
});
operationBarController.pauseButton.setVisible(false);
diff --git a/MyBox/src/main/java/mara/mybox/controller/FilesRenameController.java b/MyBox/src/main/java/mara/mybox/controller/FilesRenameController.java
index ca2019d8e..8c7ec63e5 100644
--- a/MyBox/src/main/java/mara/mybox/controller/FilesRenameController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/FilesRenameController.java
@@ -24,10 +24,10 @@
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.FileChooser;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.FileInformation;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.data.FileInformation;
import mara.mybox.tools.FileTools;
import mara.mybox.tools.FileTools.FileSortType;
@@ -352,7 +352,7 @@ protected String makeFilename(File file) {
if (accumCheck.isSelected()) {
String pageNumber = currentAccum + "";
if (fillZero.isSelected()) {
- pageNumber = ValueTools.fillNumber(currentAccum, digit);
+ pageNumber = ValueTools.fillLeftZero(currentAccum, digit);
}
filename += pageNumber;
currentAccum++;
diff --git a/MyBox/src/main/java/mara/mybox/controller/FilesTableController.java b/MyBox/src/main/java/mara/mybox/controller/FilesTableController.java
index cfdab7bef..01ac01f44 100644
--- a/MyBox/src/main/java/mara/mybox/controller/FilesTableController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/FilesTableController.java
@@ -16,10 +16,9 @@
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.Pane;
import javafx.stage.FileChooser;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.FileInformation;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.data.FileInformation;
/**
* @Author Mara
@@ -34,7 +33,7 @@ public class FilesTableController extends BaseController {
@FXML
protected Pane filesTablePane;
@FXML
- protected Button addButton, clearButton, deleteButton, upButton, downButton, insertButton;
+ protected Button addButton, clearButton, upButton, downButton, insertButton;
@FXML
protected Button recoveryAllButton, recoverySelectedButton;
@FXML
@@ -100,8 +99,10 @@ void insertAction(ActionEvent event) {
void addAction(int index) {
try {
final FileChooser fileChooser = new FileChooser();
- File defaultPath = new File(AppVaribles.getUserConfigPath(parentController.sourcePathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(defaultPath);
+ File defaultPath = AppVaribles.getUserConfigPath(parentController.sourcePathKey);
+ if (defaultPath.exists()) {
+ fileChooser.setInitialDirectory(defaultPath);
+ }
fileChooser.getExtensionFilters().addAll(parentController.fileExtensionFilter);
List files = fileChooser.showOpenMultipleDialog(getMyStage());
if (files == null || files.isEmpty()) {
@@ -199,7 +200,8 @@ void clearAction(ActionEvent event) {
}
@FXML
- void deleteAction(ActionEvent event) {
+ @Override
+ public void deleteAction() {
List selected = new ArrayList<>();
selected.addAll(filesTableView.getSelectionModel().getSelectedIndices());
if (selected.isEmpty()) {
diff --git a/MyBox/src/main/java/mara/mybox/controller/HtmlEditorController.java b/MyBox/src/main/java/mara/mybox/controller/HtmlEditorController.java
index fe1c871b0..1f05ad44f 100644
--- a/MyBox/src/main/java/mara/mybox/controller/HtmlEditorController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/HtmlEditorController.java
@@ -1,5 +1,6 @@
package mara.mybox.controller;
+import mara.mybox.fxml.FxmlStage;
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
@@ -46,6 +47,7 @@
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Pane;
+import javafx.scene.layout.Region;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.web.HTMLEditor;
@@ -64,15 +66,15 @@
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import static mara.mybox.objects.AppVaribles.logger;
+import static mara.mybox.value.AppVaribles.logger;
import mara.mybox.db.TableBrowserUrls;
-import mara.mybox.imagefile.ImageFileWriters;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
+import mara.mybox.image.file.ImageFileWriters;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.value.CommonValues;
import mara.mybox.tools.FileTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.fxml.FxmlImageTools;
+import mara.mybox.fxml.image.ImageTools;
import mara.mybox.fxml.FxmlTools;
import mara.mybox.tools.NetworkTools;
import static mara.mybox.tools.NetworkTools.checkWeiboPassport;
@@ -99,7 +101,7 @@ public class HtmlEditorController extends BaseController {
private Stage snapingStage;
private LoadingController loadingController;
private float zoomScale;
- protected boolean isSettingValues, loadSynchronously, isFrameSet;
+ protected boolean loadSynchronously, isFrameSet;
protected SimpleBooleanProperty fileChanged;
protected int cols, rows;
protected int lastTextLen;
@@ -560,8 +562,10 @@ protected void openAction() {
}
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(HtmlFilePathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(HtmlFilePathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
final File file = fileChooser.showOpenDialog(getMyStage());
if (file == null) {
@@ -637,13 +641,16 @@ private String getBrowserContents() {
}
@FXML
- protected void saveAction() {
+ @Override
+ public void saveAction() {
try {
isSettingValues = true;
if (sourceFile == null) {
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(HtmlFilePathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(HtmlFilePathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
final File file = fileChooser.showSaveDialog(getMyStage());
if (file == null) {
@@ -678,8 +685,10 @@ protected void saveAsAction() {
try {
isSettingValues = true;
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(HtmlFilePathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(HtmlFilePathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
final File file = fileChooser.showSaveDialog(getMyStage());
if (file == null) {
@@ -730,13 +739,15 @@ private void snapshot(ActionEvent event) {
final FileChooser fileChooser = new FileChooser();
File path;
if (isOneImage) {
- path = new File(AppVaribles.getUserConfigPath(HtmlImagePathKey, CommonValues.UserFilePath));
+ path = AppVaribles.getUserConfigPath(HtmlImagePathKey);
fileChooser.getExtensionFilters().addAll(CommonValues.ImageExtensionFilter);
} else {
- path = new File(AppVaribles.getUserConfigPath(HtmlPdfPathKey, CommonValues.UserFilePath));
+ path = AppVaribles.getUserConfigPath(HtmlPdfPathKey);
fileChooser.getExtensionFilters().addAll(CommonValues.PdfExtensionFilter);
}
- fileChooser.setInitialDirectory(path);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
final File file = fileChooser.showSaveDialog(getMyStage());
if (file == null) {
return;
@@ -870,10 +881,10 @@ public void run() {
Image snapshot = webView.snapshot(parameters, null);
if (totalHeight < snapHeight + snapStep) { // last snap
- snapshot = FxmlImageTools.cropImage(snapshot, 0, snapStep - (totalHeight - snapHeight),
+ snapshot = ImageTools.cropImage(snapshot, 0, snapStep - (totalHeight - snapHeight),
width - 1, (int) snapshot.getHeight() - 1);
} else {
- snapshot = FxmlImageTools.cropImage(snapshot, 0, 0,
+ snapshot = ImageTools.cropImage(snapshot, 0, 0,
width - 1, (int) snapshot.getHeight() - 1);
}
images.add(snapshot);
@@ -884,10 +895,10 @@ public void run() {
loadingController.setInfo(AppVaribles.getMessage("WritingFile"));
boolean success = true;
if (isOneImage) {
- Image finalImage = FxmlImageTools.combineSingleColumn(images);
+ Image finalImage = ImageTools.combineSingleColumn(images);
if (finalImage != null) {
String format = FileTools.getFileSuffix(targetFile.getAbsolutePath());
- final BufferedImage bufferedImage = FxmlImageTools.getBufferedImage(finalImage);
+ final BufferedImage bufferedImage = ImageTools.getBufferedImage(finalImage);
ImageFileWriters.writeImageFile(bufferedImage, format, targetFile.getAbsolutePath());
} else {
success = false;
@@ -896,7 +907,7 @@ public void run() {
success = PdfTools.htmlIntoPdf(images, targetFile, windowSizeCheck.isSelected());
}
if (success && targetFile.exists()) {
- OpenFile.openTarget(getClass(), null, targetFile.getAbsolutePath());
+ FxmlStage.openTarget(getClass(), null, targetFile.getAbsolutePath());
} else {
popError(AppVaribles.getMessage("Failed"));
}
@@ -991,7 +1002,6 @@ public boolean stageReloading() {
@Override
public boolean stageClosing() {
- super.stageClosing();
Platform.runLater(new Runnable() {
@Override
public void run() {
@@ -1009,7 +1019,8 @@ public void run() {
timer.cancel();
}
loadingController = null;
- return true;
+ return super.stageClosing();
+
}
public boolean checkSavingForNextAction() {
@@ -1021,6 +1032,7 @@ public boolean checkSavingForNextAction() {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(getMyStage().getTitle());
alert.setContentText(AppVaribles.getMessage("FileChanged"));
+ alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
ButtonType buttonSave = new ButtonType(AppVaribles.getMessage("Save"));
ButtonType buttonNotSave = new ButtonType(AppVaribles.getMessage("NotSave"));
ButtonType buttonCancel = new ButtonType(AppVaribles.getMessage("Cancel"));
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageAttributesBaseController.java b/MyBox/src/main/java/mara/mybox/controller/ImageAttributesBaseController.java
index 20443537f..313401179 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageAttributesBaseController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageAttributesBaseController.java
@@ -3,18 +3,19 @@
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
+import javafx.scene.control.CheckBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.HBox;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.ImageAttributes;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.data.ImageAttributes;
import mara.mybox.fxml.FxmlTools;
-import mara.mybox.image.ImageValueTools;
+import mara.mybox.image.ImageValue;
import org.apache.pdfbox.rendering.ImageType;
/**
@@ -39,6 +40,8 @@ public class ImageAttributesBaseController extends BaseController {
protected HBox qualityBox, compressBox, colorBox;
@FXML
protected RadioButton rawSelect, pcxSelect;
+ @FXML
+ protected CheckBox ditherCheck;
protected ImageAttributes attributes = new ImageAttributes();
@@ -109,7 +112,7 @@ public void changed(ObservableValue extends Toggle> ov,
checkColorConversion();
}
});
- FxmlTools.setRadioSelected(binaryGroup, AppVaribles.getUserConfigValue(ImageBinaryKey, AppVaribles.getMessage("Default")));
+ FxmlTools.setRadioSelected(binaryGroup, AppVaribles.getUserConfigValue(ImageBinaryKey, AppVaribles.getMessage("OTSU")));
thresholdInput.textProperty().addListener(new ChangeListener() {
@Override
@@ -120,6 +123,15 @@ public void changed(ObservableValue extends String> observable,
});
thresholdInput.setText(AppVaribles.getUserConfigValue(ImageBinaryInputKey, null));
+ ditherCheck.selectedProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue extends Boolean> ov, Boolean oldValue, Boolean newValue) {
+ attributes.setIsDithering(newValue);
+ }
+ });
+ attributes.setIsDithering(ditherCheck.isSelected());
+ FxmlTools.setComments(ditherCheck, new Tooltip(getMessage("DitherComments")));
+
if (pcxSelect != null) {
FxmlTools.quickTooltip(pcxSelect, new Tooltip(getMessage("PcxComments")));
}
@@ -138,7 +150,7 @@ protected void checkImageFormat() {
attributes.setImageFormat(imageFormat);
AppVaribles.setUserConfigValue(ImageFormatKey, imageFormat);
- String[] compressionTypes = ImageValueTools.getCompressionTypes(imageFormat, attributes.getColorSpace());
+ String[] compressionTypes = ImageValue.getCompressionTypes(imageFormat, attributes.getColorSpace());
checkCompressionTypes(compressionTypes);
if (compressionTypes != null && "jpg".equals(imageFormat)) {
@@ -203,7 +215,7 @@ protected void checkImageColor() {
}
// if ("tif".equals(imageFormat) || "bmp".equals(imageFormat)) {
- String[] compressionTypes = ImageValueTools.getCompressionTypes(attributes.getImageFormat(), attributes.getColorSpace());
+ String[] compressionTypes = ImageValue.getCompressionTypes(attributes.getImageFormat(), attributes.getColorSpace());
checkCompressionTypes(compressionTypes);
// }
@@ -285,7 +297,7 @@ protected void checkColorConversion() {
int inputValue;
try {
inputValue = Integer.parseInt(thresholdInput.getText());
- if (inputValue >= 0 && inputValue <= 100) {
+ if (inputValue >= 0 && inputValue <= 255) {
AppVaribles.setUserConfigValue(ImageBinaryInputKey, inputValue + "");
} else {
inputValue = -1;
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageBaseController.java b/MyBox/src/main/java/mara/mybox/controller/ImageBaseController.java
index f780f8953..519db9dd0 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageBaseController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageBaseController.java
@@ -17,29 +17,26 @@
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
-import javafx.fxml.FXMLLoader;
-import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
+import javafx.scene.layout.Region;
import javafx.stage.Modality;
-import javafx.stage.Stage;
-import javafx.stage.StageStyle;
-import javafx.stage.WindowEvent;
import javax.imageio.ImageIO;
-import static mara.mybox.objects.AppVaribles.logger;
+import mara.mybox.fxml.FxmlStage;
+import static mara.mybox.value.AppVaribles.logger;
import mara.mybox.fxml.FxmlTools;
-import mara.mybox.objects.ImageFileInformation;
+import mara.mybox.data.ImageFileInformation;
import mara.mybox.tools.FileTools;
-import mara.mybox.imagefile.ImageFileReaders;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.FileInformation;
-import mara.mybox.objects.ImageAttributes;
-import mara.mybox.objects.ImageInformation;
+import mara.mybox.image.file.ImageFileReaders;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.value.CommonValues;
+import mara.mybox.data.FileInformation;
+import mara.mybox.data.ImageAttributes;
+import mara.mybox.data.ImageInformation;
import mara.mybox.tools.DateTools;
import mara.mybox.tools.ValueTools;
@@ -55,6 +52,7 @@ public abstract class ImageBaseController extends BaseController {
protected Image image;
protected ImageAttributes attributes;
protected Map sizes;
+ protected Map imageData;
protected class ProcessParameters {
@@ -107,7 +105,7 @@ protected void initializeNext2() {
@FXML
@Override
- protected void startProcess(ActionEvent event) {
+ public void startAction() {
isPreview = false;
makeActualParameters();
currentParameters = actualParameters;
@@ -133,6 +131,7 @@ public void loadImage(final File file, final boolean onlyInformation) {
sourceFile = file;
imageInformation = null;
image = null;
+ imageData = null;
final String fileName = file.getPath();
getMyStage().setTitle(getBaseTitle() + " " + fileName);
task = new Task() {
@@ -160,7 +159,7 @@ public void run() {
Platform.runLater(new Runnable() {
@Override
public void run() {
- handleMultipleImages();
+ handleMultipleFramesImage();
}
});
return null;
@@ -204,7 +203,7 @@ public void run() {
public void loadImage(final String fileName) {
try {
sourceFile = new File(fileName).getAbsoluteFile(); // Must convert to AbsoluteFile!
-// popInformation(fileName + "\n" + sourceFile.getAbsolutePath());
+// infoAction(fileName + "\n" + sourceFile.getAbsolutePath());
if (sourceFileInput != null) {
sourceFileInput.setText(sourceFile.getAbsolutePath());
} else {
@@ -215,10 +214,20 @@ public void loadImage(final String fileName) {
}
}
+ public void loadImage(File sourceFile, Image image, ImageInformation imageInformation,
+ Map imageData) {
+ this.sourceFile = sourceFile;
+ this.imageInformation = imageInformation;
+ this.image = image;
+ this.imageData = imageData;
+ afterImageLoaded();
+ }
+
public void loadImage(File sourceFile, Image image, ImageInformation imageInformation) {
this.sourceFile = sourceFile;
this.imageInformation = imageInformation;
this.image = image;
+ imageData = null;
afterImageLoaded();
}
@@ -226,12 +235,14 @@ public void loadImage(ImageInformation imageInformation) {
this.sourceFile = new File(imageInformation.getFilename());
this.imageInformation = imageInformation;
this.image = imageInformation.getImage();
+ imageData = null;
afterImageLoaded();
}
public void loadImage(final Image inImage) {
sourceFile = null;
imageInformation = null;
+ imageData = null;
image = inImage;
afterImageLoaded();
}
@@ -244,76 +255,36 @@ protected void afterImageLoaded() {
}
- protected void handleMultipleImages() {
+ protected void handleMultipleFramesImage() {
}
protected void showImageInformation(ImageInformation info) {
- try {
- if (info == null) {
- return;
- }
- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.ImageInformationFxml), AppVaribles.CurrentBundle);
- Pane root = fxmlLoader.load();
- final ImageInformationController controller = fxmlLoader.getController();
- Stage imageInformationStage = new Stage();
- controller.setMyStage(imageInformationStage);
- imageInformationStage.setOnCloseRequest(new EventHandler() {
- @Override
- public void handle(WindowEvent event) {
- if (!controller.stageClosing()) {
- event.consume();
- }
- }
- });
-
- imageInformationStage.setTitle(getMyStage().getTitle());
- imageInformationStage.initModality(Modality.NONE);
- imageInformationStage.initStyle(StageStyle.DECORATED);
- imageInformationStage.initOwner(null);
- imageInformationStage.getIcons().add(CommonValues.AppIcon);
- imageInformationStage.setScene(new Scene(root));
- imageInformationStage.show();
-
- controller.loadInformation(info);
-
- } catch (Exception e) {
- logger.error(e.toString());
+ if (info == null) {
+ return;
}
+ FxmlStage.openImageInformation(getClass(), null, info);
}
protected void showImageMetaData(ImageInformation info) {
- try {
- if (info == null) {
- return;
- }
- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.ImageMetaDataFxml), AppVaribles.CurrentBundle);
- Pane root = fxmlLoader.load();
- final ImageMetaDataController controller = fxmlLoader.getController();
- Stage imageInformationStage = new Stage();
- controller.setMyStage(imageInformationStage);
- imageInformationStage.setOnCloseRequest(new EventHandler() {
- @Override
- public void handle(WindowEvent event) {
- if (!controller.stageClosing()) {
- event.consume();
- }
- }
- });
-
- imageInformationStage.setTitle(getMyStage().getTitle());
- imageInformationStage.initModality(Modality.NONE);
- imageInformationStage.initStyle(StageStyle.DECORATED);
- imageInformationStage.initOwner(null);
- imageInformationStage.getIcons().add(CommonValues.AppIcon);
- imageInformationStage.setScene(new Scene(root));
- imageInformationStage.show();
+ if (info == null) {
+ return;
+ }
+ FxmlStage.openImageMetaData(getClass(), null, info);
+ }
- controller.loadData(info);
+ protected void showImageStatistic(ImageInformation info) {
+ if (info == null) {
+ return;
+ }
+ FxmlStage.openImageStatistic(getClass(), null, info);
+ }
- } catch (Exception e) {
- logger.error(e.toString());
+ protected void showImageStatistic(Image image) {
+ if (image == null) {
+ return;
}
+ FxmlStage.openImageStatistic(getClass(), null, image);
}
protected void multipleFilesGenerated(final List fileNames) {
@@ -338,6 +309,7 @@ protected void multipleFilesGenerated(final List fileNames) {
}
getMyStage();
alert.setContentText(info);
+ alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
ButtonType buttonOpen = new ButtonType(AppVaribles.getMessage("OpenTargetPath"));
ButtonType buttonBrowse = new ButtonType(AppVaribles.getMessage("Browse"));
ButtonType buttonBrowseNew = new ButtonType(AppVaribles.getMessage("BrowseInNew"));
@@ -347,31 +319,15 @@ protected void multipleFilesGenerated(final List fileNames) {
if (result.get() == buttonOpen) {
Desktop.getDesktop().browse(new File(path).toURI());
} else if (result.get() == buttonBrowse) {
- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.ImagesViewerFxml), AppVaribles.CurrentBundle);
- Pane pane = fxmlLoader.load();
- final ImagesViewerController controller = fxmlLoader.getController();
- controller.setMyStage(myStage);
- myStage.setScene(new Scene(pane));
- controller.setBaseTitle(AppVaribles.getMessage("MultipleImagesViewer"));
- controller.loadImages(fileNames);
+ final ImagesBrowserController controller = FxmlStage.openImagesBrowser(getClass(), getMyStage());
+ if (controller != null && sourceFile != null) {
+ controller.loadImages(fileNames);
+ }
} else if (result.get() == buttonBrowseNew) {
- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.ImagesViewerFxml), AppVaribles.CurrentBundle);
- Pane pane = fxmlLoader.load();
- final ImagesViewerController controller = fxmlLoader.getController();
- Stage stage = new Stage();
- controller.setMyStage(stage);
- stage.setOnCloseRequest(new EventHandler() {
- @Override
- public void handle(WindowEvent event) {
- if (!controller.stageClosing()) {
- event.consume();
- }
- }
- });
- stage.setScene(new Scene(pane));
- stage.show();
- controller.setBaseTitle(AppVaribles.getMessage("MultipleImagesViewer"));
- controller.loadImages(fileNames);
+ final ImagesBrowserController controller = FxmlStage.openImagesBrowser(getClass(), null);
+ if (controller != null && sourceFile != null) {
+ controller.loadImages(fileNames);
+ }
}
} catch (Exception e) {
@@ -533,7 +489,7 @@ public void handle(ActionEvent event) {
|| !new File(currentParameters.finalTargetName).exists()) {
alertInformation(AppVaribles.getMessage("NoDataNotSupported"));
} else {
- openImageManufacture(currentParameters.finalTargetName);
+ openImageViewer(currentParameters.finalTargetName);
}
}
@@ -552,7 +508,7 @@ public void handle(ActionEvent event) {
operationBarController.pauseButton.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
- startProcess(event);
+ startAction();
}
});
paraBox.setDisable(true);
@@ -561,7 +517,7 @@ public void handle(ActionEvent event) {
operationBarController.startButton.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
- startProcess(event);
+ startAction();
}
});
operationBarController.pauseButton.setVisible(false);
@@ -679,4 +635,12 @@ public void setSizes(Map sizes) {
this.sizes = sizes;
}
+ public Map getImageData() {
+ return imageData;
+ }
+
+ public void setImageData(Map imageData) {
+ this.imageData = imageData;
+ }
+
}
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageConverterAttributesController.java b/MyBox/src/main/java/mara/mybox/controller/ImageConverterAttributesController.java
index 7f649b65a..9cbba1bc0 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageConverterAttributesController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageConverterAttributesController.java
@@ -18,12 +18,12 @@
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.image.ImageConvertTools.KeepRatioType;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.ImageAttributes;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.image.ImageConvert.KeepRatioType;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.value.CommonValues;
+import mara.mybox.data.ImageAttributes;
import mara.mybox.fxml.FxmlTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageConverterBatchController.java b/MyBox/src/main/java/mara/mybox/controller/ImageConverterBatchController.java
index 19bf36c44..3bafaf69f 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageConverterBatchController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageConverterBatchController.java
@@ -2,8 +2,8 @@
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleBooleanProperty;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.AppVaribles;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.value.AppVaribles;
import static mara.mybox.fxml.FxmlTools.badStyle;
/**
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageConverterController.java b/MyBox/src/main/java/mara/mybox/controller/ImageConverterController.java
index 67dfd61d8..72c48c5ce 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageConverterController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageConverterController.java
@@ -10,11 +10,11 @@
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javax.imageio.ImageIO;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.image.ImageConvertTools;
-import mara.mybox.imagefile.ImageFileWriters;
-import mara.mybox.objects.AppVaribles;
-import mara.mybox.objects.ImageAttributes;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.image.ImageConvert;
+import mara.mybox.image.file.ImageFileWriters;
+import mara.mybox.value.AppVaribles;
+import mara.mybox.data.ImageAttributes;
import mara.mybox.tools.FileTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
import org.apache.pdfbox.rendering.ImageType;
@@ -57,7 +57,7 @@ protected void initializeNext2() {
@FXML
protected void showImage(ActionEvent event) {
- openImageManufacture(sourceFile.getAbsolutePath());
+ openImageViewer(sourceFile.getAbsolutePath());
}
@Override
@@ -160,7 +160,7 @@ private boolean handleCurrentFile() {
if (currentParameters.finalTargetName == null) {
return false;
}
- bufferedImage = ImageConvertTools.scaleImage(bufferedImage, w, h);
+ bufferedImage = ImageConvert.scaleImage(bufferedImage, w, h);
bufferedImage = ImageFileWriters.convertColor(bufferedImage, attributes);
ImageFileWriters.writeImageFile(bufferedImage, attributes, currentParameters.finalTargetName);
return true;
@@ -208,7 +208,7 @@ protected String makeFilename(int w, int h) {
if (attributes.getBinaryConversion() == ImageAttributes.BinaryConversion.BINARY_THRESHOLD) {
fname += "_" + "BINARY-Threshold";
if (attributes.getThreshold() >= 0) {
- fname += "-" + attributes.getThreshold() + "%";
+ fname += "-" + attributes.getThreshold();
}
} else if (attributes.getBinaryConversion() == ImageAttributes.BinaryConversion.BINARY_OTSU) {
fname += "_" + "BINARY-OTSU";
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageFramesViewerController.java b/MyBox/src/main/java/mara/mybox/controller/ImageFramesViewerController.java
index 66e0e3ac3..30c101bf0 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageFramesViewerController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageFramesViewerController.java
@@ -32,14 +32,14 @@
import javafx.stage.FileChooser;
import javafx.stage.Modality;
import javafx.util.Callback;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.imagefile.ImageFileReaders;
-import mara.mybox.imagefile.ImageFileWriters;
-import mara.mybox.objects.AppVaribles;
-import mara.mybox.objects.CommonValues;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.ImageFileInformation;
-import mara.mybox.objects.ImageInformation;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.image.file.ImageFileReaders;
+import mara.mybox.image.file.ImageFileWriters;
+import mara.mybox.value.AppVaribles;
+import mara.mybox.value.CommonValues;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.data.ImageFileInformation;
+import mara.mybox.data.ImageInformation;
import mara.mybox.tools.FileTools;
import mara.mybox.tools.ValueTools;
@@ -52,12 +52,12 @@
public class ImageFramesViewerController extends ImageBaseController {
protected SimpleBooleanProperty changed;
- protected boolean isSettingValues;
+
protected ObservableList sourceImages = FXCollections.observableArrayList();
@FXML
- protected Button extractButton, infoButton, metaButton, viewButton, editButton;
+ protected Button extractButton, metaButton, viewButton, editButton;
@FXML
protected TableView sourceTable;
@FXML
@@ -196,8 +196,10 @@ protected void checkTableSelected() {
protected void openAction(ActionEvent event) {
try {
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(sourcePathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(sourcePathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
final File file = fileChooser.showOpenDialog(getMyStage());
if (file == null) {
@@ -328,7 +330,8 @@ protected boolean hasSampled() {
}
@FXML
- protected void showInfo() {
+ @Override
+ public void infoAction() {
showImageInformation(sourceTable.getSelectionModel().getSelectedItem());
}
@@ -396,8 +399,10 @@ protected void extractAction() {
}
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(targetPathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(targetPathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(CommonValues.ImageExtensionFilter);
fileChooser.setTitle(getMessage("FilePrefixInput"));
final File targetFile = fileChooser.showSaveDialog(getMyStage());
@@ -418,7 +423,7 @@ protected Void call() throws Exception {
if (task.isCancelled()) {
return null;
}
- filename = filePrefix + "-" + ValueTools.fillNumber(i, digit) + "." + format;
+ filename = filePrefix + "-" + ValueTools.fillLeftZero(i, digit) + "." + format;
BufferedImage bufferedImage = ImageFileReaders.getBufferedImage(selectedImages.get(i));
if (bufferedImage == null) {
continue;
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageGifEditerController.java b/MyBox/src/main/java/mara/mybox/controller/ImageGifEditerController.java
index 8d0c72e8b..a38869f77 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageGifEditerController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageGifEditerController.java
@@ -16,12 +16,12 @@
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.stage.Modality;
-import static mara.mybox.objects.AppVaribles.logger;
+import static mara.mybox.value.AppVaribles.logger;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.objects.AppVaribles;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.imagefile.ImageGifFile;
-import static mara.mybox.objects.AppVaribles.getMessage;
+import mara.mybox.value.AppVaribles;
+import mara.mybox.value.CommonValues;
+import mara.mybox.image.file.ImageGifFile;
+import static mara.mybox.value.AppVaribles.getMessage;
/**
* @Author Mara
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageGifViewerController.java b/MyBox/src/main/java/mara/mybox/controller/ImageGifViewerController.java
index a5d6c3295..02eeb592b 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageGifViewerController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageGifViewerController.java
@@ -21,13 +21,13 @@
import javafx.scene.image.Image;
import javafx.scene.layout.HBox;
import javafx.stage.Modality;
-import static mara.mybox.objects.AppVaribles.logger;
+import static mara.mybox.value.AppVaribles.logger;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.imagefile.ImageFileReaders;
-import mara.mybox.imagefile.ImageGifFile;
-import mara.mybox.objects.AppVaribles;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.ImageFileInformation;
+import mara.mybox.image.file.ImageFileReaders;
+import mara.mybox.image.file.ImageGifFile;
+import mara.mybox.value.AppVaribles;
+import mara.mybox.value.CommonValues;
+import mara.mybox.data.ImageFileInformation;
import mara.mybox.tools.FileTools;
/**
@@ -40,14 +40,13 @@ public class ImageGifViewerController extends ImageViewerController {
protected Image[] images;
protected int currentIndex, interval, fromIndex, toIndex, totalNumber;
- protected boolean isSettingValues;
@FXML
protected ComboBox intervalCBox, frameBox;
@FXML
protected Button pauseButton, extractButton;
@FXML
- protected HBox opBox, extractBox;
+ protected HBox operation4Box;
@FXML
protected Label promptLabel, commentsLabel;
@FXML
@@ -56,15 +55,20 @@ public class ImageGifViewerController extends ImageViewerController {
protected TextField fromInput, toInput;
public ImageGifViewerController() {
+ TipsLabelKey = "GifViewTips";
+
fileExtensionFilter = CommonValues.GifExtensionFilter;
}
@Override
protected void initializeNext2() {
try {
- infoBar.setDisable(true);
- opBox.setDisable(true);
- extractBox.setDisable(true);
+ operation3Box.disableProperty().bind(
+ Bindings.isNull(imageView.imageProperty())
+ );
+ operation4Box.disableProperty().bind(
+ Bindings.isNull(imageView.imageProperty())
+ );
targetTypeBox.getItems().addAll(CommonValues.SupportedImages);
targetTypeBox.getSelectionModel().select(0);
@@ -238,14 +242,8 @@ public void afterImageLoaded() {
try {
super.afterImageLoaded();
if (images == null || images.length == 0) {
- infoBar.setDisable(true);
- opBox.setDisable(true);
- extractBox.setDisable(true);
return;
}
- infoBar.setDisable(false);
- opBox.setDisable(false);
- extractBox.setDisable(false);
showGifImage(0);
List frames = new ArrayList<>();
for (int i = 0; i < images.length; i++) {
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageInformationController.java b/MyBox/src/main/java/mara/mybox/controller/ImageInformationController.java
index 779b9457b..8908fd3fa 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageInformationController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageInformationController.java
@@ -9,10 +9,10 @@
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.ImageFileInformation;
-import mara.mybox.objects.ImageInformation;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.data.ImageFileInformation;
+import mara.mybox.data.ImageInformation;
/**
* @Author Mara
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureArcController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureArcController.java
index 4bd7a49a4..da95fce09 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureArcController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureArcController.java
@@ -13,12 +13,13 @@
import javafx.scene.control.ColorPicker;
import javafx.scene.control.ComboBox;
import javafx.scene.image.Image;
+import javafx.scene.layout.Region;
import javafx.scene.paint.Color;
import javafx.stage.Modality;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.AppVaribles;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.fxml.FxmlImageTools;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.value.AppVaribles;
+import mara.mybox.value.CommonValues;
+import mara.mybox.fxml.image.ImageTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
/**
@@ -63,17 +64,18 @@ protected void initInterface() {
isSettingValues = true;
- if (CommonValues.NoAlphaImages.contains(values.getImageInfo().getImageFormat())) {
+ if (values.getImageInfo() != null
+ && CommonValues.NoAlphaImages.contains(values.getImageInfo().getImageFormat())) {
transForArcButton.setDisable(true);
} else {
transForArcButton.setDisable(false);
}
arcBox.getItems().clear();
- arcBox.getItems().addAll(Arrays.asList(values.getImageInfo().getWidth() / 6 + "",
- values.getImageInfo().getWidth() / 8 + "",
- values.getImageInfo().getWidth() / 4 + "",
- values.getImageInfo().getWidth() / 10 + "",
+ arcBox.getItems().addAll(Arrays.asList((int)values.getImage().getWidth() / 6 + "",
+ (int)values.getImage().getWidth() / 8 + "",
+ (int)values.getImage().getWidth() / 4 + "",
+ (int)values.getImage().getWidth() / 10 + "",
"0", "15", "30", "50", "150", "300", "10", "3"));
arcBox.getSelectionModel().select(0);
@@ -132,7 +134,7 @@ public void arcAction() {
task = new Task() {
@Override
protected Void call() throws Exception {
- final Image newImage = FxmlImageTools.addArc(values.getCurrentImage(), arc, arcColorPicker.getValue());
+ final Image newImage = ImageTools.addArc(values.getCurrentImage(), arc, arcColorPicker.getValue());
if (task.isCancelled()) {
return null;
}
@@ -162,11 +164,12 @@ public void arcAction2() {
if (arc <= 0) {
return;
}
- final Image newImage = FxmlImageTools.addArcFx(values.getCurrentImage(), arc, arcColorPicker.getValue());
+ final Image newImage = ImageTools.addArcFx(values.getCurrentImage(), arc, arcColorPicker.getValue());
if (newImage == null) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(getMyStage().getTitle());
alert.setContentText(AppVaribles.getMessage("ErrorForBigImage"));
+ alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
Optional result = alert.showAndWait();
return;
}
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchAddMarginsController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchAddMarginsController.java
index babce2363..9a95831f6 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchAddMarginsController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchAddMarginsController.java
@@ -11,11 +11,11 @@
import javafx.scene.control.ColorPicker;
import javafx.scene.control.ComboBox;
import javafx.scene.paint.Color;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.AppVaribles;
-import mara.mybox.fxml.FxmlImageTools;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.value.AppVaribles;
+import mara.mybox.fxml.image.ImageTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.image.ImageMarginsTools;
+import mara.mybox.image.ImageMargins;
/**
* @Author Mara
@@ -151,8 +151,8 @@ protected BufferedImage handleImage(BufferedImage source) {
if (!checkMargins()) {
return null;
}
- BufferedImage target = ImageMarginsTools.addMargins(source,
- FxmlImageTools.colorConvert(addMarginsColorPicker.getValue()), addMarginWidth,
+ BufferedImage target = ImageMargins.addMargins(source,
+ ImageTools.colorConvert(addMarginsColorPicker.getValue()), addMarginWidth,
addMarginsTopCheck.isSelected(), addMarginsBottomCheck.isSelected(),
addMarginsLeftCheck.isSelected(), addMarginsRightCheck.isSelected());
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchArcController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchArcController.java
index 3dcb7bb55..fa7c887fe 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchArcController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchArcController.java
@@ -15,10 +15,10 @@
import javafx.scene.control.Tooltip;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.image.ImageConvertTools;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.fxml.FxmlImageTools;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.image.ImageConvert;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.fxml.image.ImageTools;
import mara.mybox.fxml.FxmlTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
@@ -181,8 +181,8 @@ protected BufferedImage handleImage(BufferedImage source) {
if (isPercent) {
value = source.getWidth() * percent / 100;
}
- BufferedImage target = ImageConvertTools.addArc(source, value,
- FxmlImageTools.colorConvert(arcColorPicker.getValue()));
+ BufferedImage target = ImageConvert.addArc(source, value,
+ ImageTools.colorConvert(arcColorPicker.getValue()));
return target;
} catch (Exception e) {
logger.error(e.toString());
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchColorController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchColorController.java
index 63bd93f46..0241cf81e 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchColorController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchColorController.java
@@ -11,12 +11,13 @@
import javafx.scene.control.TextField;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.fxml.FxmlAdjustColorTools.ColorActionType;
-import mara.mybox.fxml.FxmlAdjustColorTools.ColorObjectType;
-import static mara.mybox.objects.AppVaribles.getMessage;
+import static mara.mybox.value.AppVaribles.logger;
+import static mara.mybox.value.AppVaribles.getMessage;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.image.ImageAdjustColorTools;
+import mara.mybox.image.PixelsOperation;
+import mara.mybox.image.ImageScope;
+import mara.mybox.image.PixelsOperation.ColorActionType;
+import mara.mybox.image.PixelsOperation.OperationType;
/**
* @Author Mara
@@ -28,7 +29,7 @@ public class ImageManufactureBatchColorController extends ImageManufactureBatchC
private int colorValue;
private boolean isIncrease;
- private ColorObjectType colorOperationType;
+ private OperationType colorOperationType;
private ColorActionType colorActionType;
@FXML
@@ -70,10 +71,10 @@ protected void initOptionsSection() {
@Override
public void changed(ObservableValue extends Toggle> ov,
Toggle old_toggle, Toggle new_toggle) {
- checkColorObjectType();
+ checkOperationType();
}
});
- checkColorObjectType();
+ checkOperationType();
colorSlider.valueProperty().addListener(new ChangeListener() {
@Override
@@ -106,7 +107,7 @@ public void changed(ObservableValue extends Toggle> ov,
}
}
- private void checkColorObjectType() {
+ private void checkOperationType() {
setRadio.setDisable(false);
invertRadio.setDisable(false);
@@ -116,7 +117,7 @@ private void checkColorObjectType() {
setRadio.setSelected(true);
RadioButton selected = (RadioButton) colorGroup.getSelectedToggle();
if (getMessage("Brightness").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Brightness;
+ colorOperationType = OperationType.Brightness;
colorSlider.setMax(100);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -127,7 +128,7 @@ private void checkColorObjectType() {
filterRadio.setDisable(true);
invertRadio.setDisable(true);
} else if (getMessage("Saturation").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Sauration;
+ colorOperationType = OperationType.Sauration;
colorSlider.setMax(100);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -138,7 +139,7 @@ private void checkColorObjectType() {
filterRadio.setDisable(true);
invertRadio.setDisable(true);
} else if (getMessage("Hue").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Hue;
+ colorOperationType = OperationType.Hue;
colorSlider.setMax(359);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -149,7 +150,7 @@ private void checkColorObjectType() {
filterRadio.setDisable(true);
invertRadio.setDisable(true);
} else if (getMessage("Red").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Red;
+ colorOperationType = OperationType.Red;
colorSlider.setMax(255);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -158,7 +159,7 @@ private void checkColorObjectType() {
colorInput.setText("50");
}
} else if (getMessage("Green").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Green;
+ colorOperationType = OperationType.Green;
colorSlider.setMax(255);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -167,7 +168,7 @@ private void checkColorObjectType() {
colorInput.setText("50");
}
} else if (getMessage("Blue").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Blue;
+ colorOperationType = OperationType.Blue;
colorSlider.setMax(255);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -176,7 +177,7 @@ private void checkColorObjectType() {
colorInput.setText("50");
}
} else if (getMessage("Yellow").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Yellow;
+ colorOperationType = OperationType.Yellow;
colorSlider.setMax(255);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -185,7 +186,7 @@ private void checkColorObjectType() {
colorInput.setText("50");
}
} else if (getMessage("Cyan").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Cyan;
+ colorOperationType = OperationType.Cyan;
colorSlider.setMax(255);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -194,7 +195,7 @@ private void checkColorObjectType() {
colorInput.setText("50");
}
} else if (getMessage("Magenta").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Magenta;
+ colorOperationType = OperationType.Magenta;
colorSlider.setMax(255);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -203,7 +204,7 @@ private void checkColorObjectType() {
colorInput.setText("50");
}
} else if (getMessage("Opacity").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Opacity;
+ colorOperationType = OperationType.Opacity;
colorSlider.setMax(100);
colorSlider.setMin(0);
colorSlider.setBlockIncrement(1);
@@ -216,7 +217,7 @@ private void checkColorObjectType() {
increaseRadio.setDisable(true);
decreaseRadio.setDisable(true);
} else if (getMessage("RGB").equals(selected.getText())) {
- colorOperationType = ColorObjectType.RGB;
+ colorOperationType = OperationType.RGB;
colorSlider.setMax(255);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -267,20 +268,14 @@ protected BufferedImage handleImage(BufferedImage source) {
return null;
}
try {
- float value = colorValue;
- if (colorActionType == ColorActionType.Decrease) {
- value = 0 - colorValue;
- }
+ ImageScope scope = new ImageScope();
+ PixelsOperation pixelsOperation = new PixelsOperation(source, scope,
+ colorOperationType, colorActionType);
switch (colorOperationType) {
+ case Hue:
case Brightness:
case Sauration:
- value = value / 100.0f;
- break;
- case Opacity:
- value = value * 255 / 100.0f;
- break;
- case Hue:
- value = value / 360.0f;
+ pixelsOperation.setFloatPara1(colorValue / 100.0f);
break;
case Red:
case Green:
@@ -289,9 +284,11 @@ protected BufferedImage handleImage(BufferedImage source) {
case Cyan:
case Magenta:
case RGB:
+ case Opacity:
+ pixelsOperation.setIntPara1(colorValue);
break;
}
- BufferedImage target = ImageAdjustColorTools.changeColor(source, colorOperationType, colorActionType, value);
+ BufferedImage target = pixelsOperation.operate();
return target;
} catch (Exception e) {
logger.error(e.toString());
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchController.java
index 04e4e4aa1..4877ce0ae 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchController.java
@@ -16,8 +16,6 @@
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
-import javafx.fxml.FXMLLoader;
-import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import javafx.scene.control.SelectionMode;
@@ -29,18 +27,15 @@
import javafx.scene.control.Tooltip;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
-import javafx.scene.layout.Pane;
import javafx.scene.text.Font;
import javafx.stage.FileChooser;
-import javafx.stage.Stage;
-import javafx.stage.WindowEvent;
import javax.imageio.ImageIO;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.imagefile.ImageFileWriters;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.FileInformation;
+import mara.mybox.fxml.FxmlStage;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.image.file.ImageFileWriters;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.data.FileInformation;
import mara.mybox.tools.FileTools;
import mara.mybox.fxml.FxmlTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
@@ -68,7 +63,7 @@ public class ImageManufactureBatchController extends ImageBaseController {
@FXML
protected TextField targetSuffixInput;
@FXML
- protected Button addButton, upButton, downButton, deleteButton, clearButton, browseButton, openButton, insertButton;
+ protected Button addButton, upButton, downButton, clearButton, browseButton, openButton, insertButton;
@FXML
protected RadioButton blackRadio, whiteRadio;
@@ -189,7 +184,7 @@ public void changed(ObservableValue extends String> observable, String oldValu
}
}
});
- targetPathInput.setText(AppVaribles.getUserConfigValue(targetPathKey, CommonValues.UserFilePath));
+ targetPathInput.setText(AppVaribles.getUserConfigPath(targetPathKey).getAbsolutePath());
targetExistGroup.selectedToggleProperty().addListener(new ChangeListener() {
@Override
@@ -273,8 +268,10 @@ void insertAction(ActionEvent event) {
protected void addAction(int index) {
try {
final FileChooser fileChooser = new FileChooser();
- File defaultPath = new File(AppVaribles.getUserConfigPath(sourcePathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(defaultPath);
+ File defaultPath = AppVaribles.getUserConfigPath(sourcePathKey);
+ if (defaultPath.exists()) {
+ fileChooser.setInitialDirectory(defaultPath);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
List files = fileChooser.showOpenMultipleDialog(getMyStage());
@@ -306,7 +303,8 @@ protected void addAction(int index) {
}
@FXML
- protected void deleteAction(ActionEvent event) {
+ @Override
+ public void deleteAction() {
List selected = new ArrayList<>();
selected.addAll(sourceTable.getSelectionModel().getSelectedIndices());
if (selected.isEmpty()) {
@@ -398,24 +396,10 @@ protected void browseAction() {
if (generatedFiles == null || generatedFiles.isEmpty()) {
return;
}
- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.ImagesViewerFxml), AppVaribles.CurrentBundle);
- Pane pane = fxmlLoader.load();
- final ImagesViewerController controller = fxmlLoader.getController();
- Stage stage = new Stage();
- controller.setMyStage(stage);
- stage.setOnCloseRequest(new EventHandler() {
- @Override
- public void handle(WindowEvent event) {
- if (!controller.stageClosing()) {
- event.consume();
- }
- }
- });
- stage.setScene(new Scene(pane));
- stage.show();
-
- controller.setBaseTitle(AppVaribles.getMessage("MultipleImagesViewer"));
- controller.loadImages(generatedFiles);
+ final ImagesBrowserController controller = FxmlStage.openImagesBrowser(getClass(), null);
+ if (controller != null) {
+ controller.loadImages(generatedFiles);
+ }
} catch (Exception e) {
}
}
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchConvolutionController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchConvolutionController.java
deleted file mode 100644
index 916c9c044..000000000
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchConvolutionController.java
+++ /dev/null
@@ -1,125 +0,0 @@
-package mara.mybox.controller;
-
-import java.awt.image.BufferedImage;
-import java.util.ArrayList;
-import java.util.List;
-import javafx.beans.binding.Bindings;
-import javafx.beans.value.ChangeListener;
-import javafx.beans.value.ObservableValue;
-import javafx.collections.FXCollections;
-import javafx.collections.ObservableList;
-import javafx.event.ActionEvent;
-import javafx.fxml.FXML;
-import javafx.scene.control.ComboBox;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.db.TableConvolutionKernel;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.ConvolutionKernel;
-import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.image.ImageEffectTools;
-
-/**
- * @Author Mara
- * @CreateDate 2018-11-08
- * @Description
- * @License Apache License Version 2.0
- */
-public class ImageManufactureBatchConvolutionController extends ImageManufactureBatchController {
-
- private final ObservableList kernels = FXCollections.observableArrayList();
- private ConvolutionKernel currentKernel;
- private boolean isSettingValues;
-
- @FXML
- private ComboBox kernelBox;
-
- public ImageManufactureBatchConvolutionController() {
-
- }
-
- @Override
- protected void initializeNext2() {
- try {
-
- operationBarController.startButton.disableProperty().bind(Bindings.isEmpty(targetPathInput.textProperty())
- .or(targetPathInput.styleProperty().isEqualTo(badStyle))
- .or(Bindings.isEmpty(sourceFilesInformation))
- .or(Bindings.isEmpty(kernels))
- );
-
- } catch (Exception e) {
- logger.debug(e.toString());
- }
- }
-
- @Override
- protected void initOptionsSection() {
- try {
-
- kernelBox.setVisibleRowCount(10);
- kernelBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener() {
- @Override
- public void changed(ObservableValue ov, Number oldValue, Number newValue) {
- if (isSettingValues) {
- return;
- }
- int index = newValue.intValue();
- if (index < 0 || index >= kernels.size()) {
- return;
- }
- currentKernel = kernels.get(index);
- }
- });
- kernels.addAll(TableConvolutionKernel.read());
- loadList();
-
- } catch (Exception e) {
- logger.error(e.toString());
- }
- }
-
- public void loadList(List records) {
- kernels.clear();
- kernels.addAll(records);
- loadList();
- }
-
- public void loadList() {
- isSettingValues = true;
- kernelBox.getItems().clear();
- if (kernels == null || kernels.isEmpty()) {
- isSettingValues = false;
- return;
- }
- List names = new ArrayList<>();
- for (ConvolutionKernel k : kernels) {
- names.add(k.getName());
- }
- kernelBox.getItems().addAll(names);
- isSettingValues = false;
-
- kernelBox.getSelectionModel().select(0);
- }
-
- @FXML
- private void manageKernels(ActionEvent event) {
- BaseController c = openStage(CommonValues.ConvolutionKernelManagerFxml, true);
- c.setParentController(getMyController());
- c.setParentFxml(getMyFxml());
- }
-
- @Override
- protected BufferedImage handleImage(BufferedImage source) {
- if (currentKernel == null) {
- return null;
- }
- try {
- BufferedImage target = ImageEffectTools.applyConvolution(source, currentKernel);
- return target;
- } catch (Exception e) {
- logger.error(e.toString());
- return null;
- }
- }
-
-}
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchCropController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchCropController.java
index 024f043ed..2d3ea5f28 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchCropController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchCropController.java
@@ -9,9 +9,9 @@
import javafx.scene.control.TextField;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.image.ImageConvertTools;
-import mara.mybox.objects.AppVaribles;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.image.ImageConvert;
+import mara.mybox.value.AppVaribles;
import static mara.mybox.fxml.FxmlTools.badStyle;
/**
@@ -260,7 +260,7 @@ protected BufferedImage handleImage(BufferedImage source) {
errorString = AppVaribles.getMessage("BeyondSize");
return null;
}
- return ImageConvertTools.cropImage(source, x1, y1, x2, y2);
+ return ImageConvert.cropImage(source, x1, y1, x2, y2);
} catch (Exception e) {
logger.error(e.toString());
return null;
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchCutMarginsController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchCutMarginsController.java
index 468853666..b9dfd874f 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchCutMarginsController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchCutMarginsController.java
@@ -14,13 +14,13 @@
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.scene.paint.Color;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.fxml.FxmlImageTools;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.fxml.image.ImageTools;
import mara.mybox.fxml.FxmlTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.image.ImageMarginsTools;
+import mara.mybox.image.ImageMargins;
/**
* @Author Mara
@@ -195,13 +195,13 @@ protected BufferedImage handleImage(BufferedImage source) {
}
BufferedImage target;
if (cutMarginsByWidth) {
- target = ImageMarginsTools.cutMargins(source,
+ target = ImageMargins.cutMargins(source,
cutMarginWidth,
cutMarginsTopCheck.isSelected(), cutMarginsBottomCheck.isSelected(),
cutMarginsLeftCheck.isSelected(), cutMarginsRightCheck.isSelected());
} else {
- target = ImageMarginsTools.cutMargins(source,
- FxmlImageTools.colorConvert(cutMarginsColorPicker.getValue()),
+ target = ImageMargins.cutMargins(source,
+ ImageTools.colorConvert(cutMarginsColorPicker.getValue()),
cutMarginsTopCheck.isSelected(), cutMarginsBottomCheck.isSelected(),
cutMarginsLeftCheck.isSelected(), cutMarginsRightCheck.isSelected());
}
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchEffectsController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchEffectsController.java
index 9c67875b9..cd0cb462c 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchEffectsController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchEffectsController.java
@@ -1,30 +1,42 @@
package mara.mybox.controller;
import java.awt.image.BufferedImage;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
+import javafx.event.ActionEvent;
+import javafx.event.EventHandler;
import javafx.fxml.FXML;
+import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
-import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Tooltip;
+import javafx.scene.input.KeyEvent;
import javafx.scene.layout.HBox;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.fxml.FxmlEffectTools.EffectsOperationType;
-import mara.mybox.image.ImageConvertTools;
-import static mara.mybox.objects.AppVaribles.getMessage;
+import mara.mybox.db.TableConvolutionKernel;
+import mara.mybox.image.ImageConvert;
import mara.mybox.fxml.FxmlTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.image.ImageEffectTools;
-import mara.mybox.image.ImageGrayTools;
-import mara.mybox.objects.ConvolutionKernel;
+import mara.mybox.image.ImageBinary;
+import mara.mybox.image.ImageConvolution;
+import mara.mybox.image.ImageQuantization;
+import mara.mybox.image.ImageContrast;
+import mara.mybox.image.ImageGray;
+import mara.mybox.image.ImageQuantization.QuantizationAlgorithm;
+import mara.mybox.image.PixelsOperation;
+import mara.mybox.image.PixelsOperation.OperationType;
+import static mara.mybox.value.AppVaribles.getMessage;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.value.CommonValues;
+import mara.mybox.data.ConvolutionKernel;
/**
* @Author Mara
@@ -34,25 +46,27 @@
*/
public class ImageManufactureBatchEffectsController extends ImageManufactureBatchController {
- private EffectsOperationType effectType;
- protected int threadholding, threadholdingMin, threadholdingMax, intValue, direction, bwValue;
+ private OperationType effectType;
+ protected int intPara1, intPara2, intPara3;
+ private List kernels;
+ private ConvolutionKernel kernel;
+ private ComboBox intBox, stringBox;
+ private Label intLabel, intLabel2, intLabel3, intLabel4, stringLabel;
+ private CheckBox valueCheck;
+ private TextField intInput, intInput2, intInput3, intInput4;
+ private RadioButton radio1, radio2, radio3, radio4;
+ private ToggleGroup radioGroup;
+ private Button setButton;
+ private QuantizationAlgorithm quantizationAlgorithm;
+ private ImageContrast.ContrastAlgorithm contrastAlgorithm;
@FXML
protected ToggleGroup effectsGroup;
@FXML
- protected HBox thresholdingBox, bwBox;
+ protected HBox setBox;
@FXML
- protected ComboBox intBox, stringBox;
- @FXML
- protected TextField thresholdingInput, thresholdingMinInput, thresholdingMaxInput, bwInput;
- @FXML
- protected RadioButton thresholdingRadio;
- @FXML
- protected Label intLabel, stringLabel, bwLabel1, bwLabel2, bwLabel3;
- @FXML
- protected CheckBox grayCheck;
- @FXML
- private Slider bwSlider;
+ protected RadioButton thresholdingRadio, posterizingRadio, bwRadio,
+ convolutionRadio, contrastRadio;
public ImageManufactureBatchEffectsController() {
@@ -61,15 +75,6 @@ public ImageManufactureBatchEffectsController() {
@Override
protected void initializeNext2() {
try {
-
- operationBarController.startButton.disableProperty().bind(Bindings.isEmpty(targetPathInput.textProperty())
- .or(targetPathInput.styleProperty().isEqualTo(badStyle))
- .or(Bindings.isEmpty(sourceFilesInformation))
- .or(thresholdingInput.styleProperty().isEqualTo(badStyle))
- .or(thresholdingMinInput.styleProperty().isEqualTo(badStyle))
- .or(thresholdingMaxInput.styleProperty().isEqualTo(badStyle))
- );
-
} catch (Exception e) {
logger.debug(e.toString());
}
@@ -88,45 +93,159 @@ public void changed(ObservableValue extends Toggle> ov,
});
checkEffetcsOperationType();
+ FxmlTools.setComments(thresholdingRadio, new Tooltip(getMessage("ThresholdingComments")));
+ FxmlTools.setComments(posterizingRadio, new Tooltip(getMessage("QuantizationComments")));
+ FxmlTools.setComments(bwRadio, new Tooltip(getMessage("BWThresholdComments")));
+
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
+ }
+
+ private void removeTmpControls() {
+ intBox = null;
+ valueCheck = null;
+ intInput = intInput2 = intInput3 = intInput4 = null;
+ intLabel = intLabel2 = intLabel3 = intLabel4 = stringLabel = null;
+ radio1 = radio2 = radio3 = radio4 = null;
+ setButton = null;
+ }
+
+ private void checkEffetcsOperationType() {
+ try {
+ setBox.getChildren().clear();
+ operationBarController.startButton.disableProperty().unbind();
+ removeTmpControls();
+ stringBox = null;
+ radioGroup = null;
+
+ RadioButton selected = (RadioButton) effectsGroup.getSelectedToggle();
+ String selectedString = selected.getText();
+ if (getMessage("Blur").equals(selectedString)) {
+ effectType = OperationType.Blur;
+ makeBlurBox();
+
+ } else if (getMessage("Sharpen").equals(selectedString)) {
+ effectType = OperationType.Sharpen;
+ bindStart();
+
+ } else if (getMessage("Clarity").equals(selectedString)) {
+ effectType = OperationType.Clarity;
+ bindStart();
+
+ } else if (getMessage("EdgeDetection").equals(selectedString)) {
+ effectType = OperationType.EdgeDetect;
+ bindStart();
+
+ } else if (getMessage("Emboss").equals(selectedString)) {
+ effectType = OperationType.Emboss;
+ makeEmbossBox();
+
+ } else if (getMessage("Posterizing").equals(selectedString)) {
+ effectType = OperationType.Quantization;
+ makePosterizingBox();
+
+ } else if (getMessage("Thresholding").equals(selectedString)) {
+ effectType = OperationType.Thresholding;
+ makeThresholdingBox();
+
+ } else if (getMessage("Gray").equals(selectedString)) {
+ effectType = OperationType.Gray;
+ bindStart();
+
+ } else if (getMessage("BlackOrWhite").equals(selectedString)) {
+ effectType = OperationType.BlackOrWhite;
+ makeBlackWhiteBox();
+
+ } else if (getMessage("Sepia").equals(selectedString)) {
+ effectType = OperationType.Sepia;
+ makeSepiaBox();
+
+ } else if (getMessage("Contrast").equals(selectedString)) {
+ effectType = OperationType.Contrast;
+ makeContrastBox();
+
+ } else if (getMessage("Convolution").equals(selectedString)) {
+ effectType = OperationType.Convolution;
+ makeConvolutionBox();
+
+ }
+
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
+ }
+
+ private void bindStart() {
+ operationBarController.startButton.disableProperty().bind(
+ Bindings.isEmpty(targetPathInput.textProperty())
+ .or(targetPathInput.styleProperty().isEqualTo(badStyle))
+ .or(Bindings.isEmpty(sourceFilesInformation))
+ );
+ }
+
+ private void makeBlurBox() {
+ try {
+ intPara1 = 10;
+ intLabel = new Label(getMessage("Radius"));
+ intBox = new ComboBox();
+ intBox.setEditable(true);
+ intBox.setPrefWidth(80);
intBox.valueProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue ov, String oldValue, String newValue) {
- int defaultValue = 0;
- if (null != effectType) {
- switch (effectType) {
- case Blur:
- defaultValue = 1;
- break;
- case Posterizing:
- defaultValue = 32;
- break;
- case Emboss:
- defaultValue = 3;
- break;
- default:
- break;
- }
- }
try {
- String v = newValue;
- int pos = v.indexOf(" ");
- if (pos > 0) {
- v = v.substring(0, pos);
- }
- intValue = Integer.valueOf(v);
- if (intValue > 0) {
+ int v = Integer.valueOf(newValue);
+ if (v > 0) {
+ intPara1 = v;
intBox.getEditor().setStyle(null);
} else {
- intValue = defaultValue;
intBox.getEditor().setStyle(badStyle);
}
} catch (Exception e) {
- intValue = defaultValue;
intBox.getEditor().setStyle(badStyle);
}
}
});
+ intBox.getItems().addAll(Arrays.asList("10", "5", "3", "2", "1", "8", "15", "20", "30"));
+ intBox.getSelectionModel().select(0);
+ stringLabel = new Label(getMessage("Algorithm"));
+ stringBox = new ComboBox();
+ stringBox.valueProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue ov, String oldValue, String newValue) {
+ try {
+ if (getMessage("AverageBlur").equals(newValue)) {
+ kernel = ConvolutionKernel.makeAverageBlur(intPara1);
+ } else {
+ kernel = ConvolutionKernel.makeGaussKernel(intPara1);
+ }
+ stringBox.getEditor().setStyle(null);
+ } catch (Exception e) {
+ stringBox.getEditor().setStyle(badStyle);
+ }
+ }
+ });
+ stringBox.getItems().addAll(Arrays.asList(getMessage("AverageBlur"), getMessage("GaussianBlur")));
+ stringBox.getSelectionModel().select(getMessage("AverageBlur"));
+ setBox.getChildren().addAll(stringLabel, stringBox, intLabel, intBox);
+ operationBarController.startButton.disableProperty().bind(
+ intBox.getEditor().styleProperty().isEqualTo(badStyle)
+ .or(stringBox.getEditor().styleProperty().isEqualTo(badStyle))
+ .or(Bindings.isEmpty(targetPathInput.textProperty()))
+ .or(targetPathInput.styleProperty().isEqualTo(badStyle))
+ .or(Bindings.isEmpty(sourceFilesInformation))
+ );
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
+ }
+ private void makeEmbossBox() {
+ try {
+ intPara1 = ImageConvert.Direction.Top;
+ stringLabel = new Label(getMessage("Direction"));
+ stringBox = new ComboBox();
stringBox.valueProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue ov, String oldValue, String newValue) {
@@ -134,224 +253,488 @@ public void changed(ObservableValue ov, String oldValue, String newValue) {
return;
}
if (getMessage("Top").equals(newValue)) {
- direction = ImageConvertTools.Direction.Top;
+ intPara1 = ImageConvert.Direction.Top;
} else if (getMessage("Bottom").equals(newValue)) {
- direction = ImageConvertTools.Direction.Bottom;
+ intPara1 = ImageConvert.Direction.Bottom;
} else if (getMessage("Left").equals(newValue)) {
- direction = ImageConvertTools.Direction.Top;
+ intPara1 = ImageConvert.Direction.Top;
} else if (getMessage("Right").equals(newValue)) {
- direction = ImageConvertTools.Direction.Right;
+ intPara1 = ImageConvert.Direction.Right;
} else if (getMessage("LeftTop").equals(newValue)) {
- direction = ImageConvertTools.Direction.LeftTop;
+ intPara1 = ImageConvert.Direction.LeftTop;
} else if (getMessage("RightBottom").equals(newValue)) {
- direction = ImageConvertTools.Direction.RightBottom;
+ intPara1 = ImageConvert.Direction.RightBottom;
} else if (getMessage("LeftBottom").equals(newValue)) {
- direction = ImageConvertTools.Direction.LeftBottom;
+ intPara1 = ImageConvert.Direction.LeftBottom;
} else if (getMessage("RightTop").equals(newValue)) {
- direction = ImageConvertTools.Direction.RightTop;
+ intPara1 = ImageConvert.Direction.RightTop;
} else {
- direction = ImageConvertTools.Direction.Top;
+ intPara1 = ImageConvert.Direction.Top;
+ }
+ }
+ });
+ stringBox.getItems().addAll(Arrays.asList(getMessage("Top"), getMessage("Bottom"),
+ getMessage("Left"), getMessage("Right"),
+ getMessage("LeftTop"), getMessage("RightBottom"),
+ getMessage("LeftBottom"), getMessage("RightTop")));
+ stringBox.getSelectionModel().select(getMessage("Top"));
+ intPara2 = 3;
+ intLabel = new Label(getMessage("Radius"));
+ intBox = new ComboBox();
+ intBox.setEditable(false);
+ intBox.setPrefWidth(80);
+ intBox.valueProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue ov, String oldValue, String newValue) {
+ try {
+ int v = Integer.valueOf(newValue);
+ if (v > 0) {
+ intPara2 = v;
+ intBox.getEditor().setStyle(null);
+ } else {
+ intBox.getEditor().setStyle(badStyle);
+ }
+ } catch (Exception e) {
+ intBox.getEditor().setStyle(badStyle);
}
}
});
+ intBox.getItems().addAll(Arrays.asList("3", "5"));
+ intBox.getSelectionModel().select(0);
+ valueCheck = new CheckBox(getMessage("Gray"));
+ valueCheck.setSelected(true);
+ setBox.getChildren().addAll(stringLabel, stringBox, intLabel, intBox, valueCheck);
+ operationBarController.startButton.disableProperty().bind(
+ intBox.getEditor().styleProperty().isEqualTo(badStyle)
+ .or(Bindings.isEmpty(targetPathInput.textProperty()))
+ .or(targetPathInput.styleProperty().isEqualTo(badStyle))
+ .or(Bindings.isEmpty(sourceFilesInformation))
+ .or(stringBox.getEditor().styleProperty().isEqualTo(badStyle))
+ );
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
+ }
- Tooltip tips = new Tooltip("0~255");
-// tips.setFont(new Font(16));
- FxmlTools.quickTooltip(thresholdingInput, tips);
- FxmlTools.quickTooltip(thresholdingMinInput, tips);
- FxmlTools.quickTooltip(thresholdingMaxInput, tips);
+ private void makePosterizingBox() {
+ try {
+ quantizationAlgorithm = QuantizationAlgorithm.RGB_Uniform;
+ stringLabel = new Label(getMessage("Algorithm"));
+ stringBox = new ComboBox();
+ stringBox.valueProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue ov, String oldValue, String newValue) {
+ if (getMessage("RGBUniformQuantization").equals(newValue)) {
+ quantizationAlgorithm = QuantizationAlgorithm.RGB_Uniform;
+ } else if (getMessage("HSBUniformQuantization").equals(newValue)) {
+ quantizationAlgorithm = QuantizationAlgorithm.HSB_Uniform;
+ }
+ }
+ });
+ stringBox.getItems().addAll(Arrays.asList(getMessage("RGBUniformQuantization"),
+ getMessage("HSBUniformQuantization")));
+ stringBox.getSelectionModel().select(getMessage("RGBUniformQuantization"));
+ intPara1 = 64;
+ intLabel = new Label(getMessage("ColorsNumber"));
+ intBox = new ComboBox();
+ intBox.setEditable(false);
+ intBox.setPrefWidth(120);
+ intBox.valueProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue ov, String oldValue, String newValue) {
+ try {
+ int v = Integer.valueOf(newValue);
+ if (v > 0) {
+ intPara1 = v;
+ intBox.getEditor().setStyle(null);
+ } else {
+ intBox.getEditor().setStyle(badStyle);
+ }
+ } catch (Exception e) {
+ intBox.getEditor().setStyle(badStyle);
+ }
+ }
+ });
+ intBox.getItems().addAll(Arrays.asList(
+ "64", "512", "8", "4096", "216", "343", "27", "125", "1000", "729", "1728", "8000"));
+ intBox.getSelectionModel().select(0);
+ valueCheck = new CheckBox(getMessage("Dithering"));
+ valueCheck.setSelected(true);
+ FxmlTools.setComments(valueCheck, new Tooltip(getMessage("DitherComments")));
+ setBox.getChildren().addAll(stringLabel, stringBox, intLabel, intBox, valueCheck);
+ operationBarController.startButton.disableProperty().bind(
+ intBox.getEditor().styleProperty().isEqualTo(badStyle)
+ .or(Bindings.isEmpty(targetPathInput.textProperty()))
+ .or(targetPathInput.styleProperty().isEqualTo(badStyle))
+ .or(Bindings.isEmpty(sourceFilesInformation))
+ .or(stringBox.getEditor().styleProperty().isEqualTo(badStyle))
+ );
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
- tips = new Tooltip(getMessage("ThresholdingComments"));
-// tips.setFont(new Font(16));
- FxmlTools.setComments(thresholdingBox, tips);
- FxmlTools.setComments(thresholdingRadio, tips);
+ }
- thresholdingInput.textProperty().addListener(new ChangeListener() {
+ private void makeThresholdingBox() {
+ try {
+ intPara1 = 128;
+ intLabel = new Label(getMessage("Threshold"));
+ intInput = new TextField();
+ intInput.textProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends String> observable,
String oldValue, String newValue) {
- checkThresholding();
+ try {
+ int v = Integer.valueOf(newValue);
+ if (v >= 0 && v <= 255) {
+ intPara1 = v;
+ intInput.setStyle(null);
+ } else {
+ popError("0~255");
+ intInput.setStyle(badStyle);
+ }
+ } catch (Exception e) {
+ popError("0~255");
+ intInput.setStyle(badStyle);
+ }
}
});
- thresholdingInput.setText("128");
+ intInput.setPrefWidth(100);
+ intInput.setText("128");
+ FxmlTools.quickTooltip(intInput, new Tooltip("0~255"));
+ intPara2 = 0;
+ Label smallValueLabel = new Label(getMessage("SmallValue"));
+ final TextField thresholdingMinInput = new TextField();
thresholdingMinInput.textProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends String> observable,
String oldValue, String newValue) {
- checkThresholding();
+ try {
+ int v = Integer.valueOf(newValue);
+ if (v >= 0 && v <= 255) {
+ intPara2 = v;
+ thresholdingMinInput.setStyle(null);
+ } else {
+ popError("0~255");
+ thresholdingMinInput.setStyle(badStyle);
+ }
+ } catch (Exception e) {
+ popError("0~255");
+ thresholdingMinInput.setStyle(badStyle);
+ }
}
});
+ thresholdingMinInput.setPrefWidth(100);
thresholdingMinInput.setText("0");
+ FxmlTools.quickTooltip(thresholdingMinInput, new Tooltip("0~255"));
+ intPara3 = 255;
+ Label bigValueLabel = new Label(getMessage("BigValue"));
+ final TextField thresholdingMaxInput = new TextField();
thresholdingMaxInput.textProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends String> observable,
String oldValue, String newValue) {
- checkThresholding();
+ try {
+ int v = Integer.valueOf(newValue);
+ if (v >= 0 && v <= 255) {
+ intPara3 = v;
+ thresholdingMaxInput.setStyle(null);
+ } else {
+ popError("0~255");
+ thresholdingMaxInput.setStyle(badStyle);
+ }
+ } catch (Exception e) {
+ popError("0~255");
+ thresholdingMaxInput.setStyle(badStyle);
+ }
}
});
+ thresholdingMaxInput.setPrefWidth(100);
thresholdingMaxInput.setText("255");
+ FxmlTools.quickTooltip(thresholdingMaxInput, new Tooltip("0~255"));
+
+ setBox.getChildren().addAll(intLabel, intInput,
+ bigValueLabel, thresholdingMaxInput,
+ smallValueLabel, thresholdingMinInput);
+ operationBarController.startButton.disableProperty().bind(
+ intInput.styleProperty().isEqualTo(badStyle)
+ .or(Bindings.isEmpty(targetPathInput.textProperty()))
+ .or(targetPathInput.styleProperty().isEqualTo(badStyle))
+ .or(Bindings.isEmpty(sourceFilesInformation))
+ .or(thresholdingMinInput.styleProperty().isEqualTo(badStyle))
+ .or(thresholdingMaxInput.styleProperty().isEqualTo(badStyle))
+ );
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
+
+ }
- bwSlider.valueProperty().addListener(new ChangeListener() {
+ private void makeBlackWhiteBox() {
+ try {
+ intPara2 = 128;
+ intInput = new TextField();
+ intInput.textProperty().addListener(new ChangeListener() {
@Override
- public void changed(ObservableValue extends Number> observable, Number oldValue, Number newValue) {
- bwValue = newValue.intValue();
- bwInput.setText(bwValue + "");
+ public void changed(ObservableValue extends String> observable,
+ String oldValue, String newValue) {
+ try {
+ int v = Integer.valueOf(intInput.getText());
+ if (v >= 0 && v <= 255) {
+ intPara2 = v;
+ intInput.setStyle(null);
+ } else {
+ intInput.setStyle(badStyle);
+ }
+ } catch (Exception e) {
+ intInput.setStyle(badStyle);
+ }
}
});
+ intInput.setPrefWidth(100);
+ intInput.setText("128");
+ FxmlTools.quickTooltip(intInput, new Tooltip("0~255"));
- bwInput.textProperty().addListener(new ChangeListener() {
+ intPara1 = 1;
+ radioGroup = new ToggleGroup();
+ radio1 = new RadioButton(getMessage("OTSU"));
+ radio1.setToggleGroup(radioGroup);
+ radio1.setUserData(1);
+ radio2 = new RadioButton(getMessage("Default"));
+ radio2.setToggleGroup(radioGroup);
+ radio2.setUserData(2);
+ radio3 = new RadioButton(getMessage("Threshold"));
+ radio3.setToggleGroup(radioGroup);
+ radio3.setUserData(3);
+ radioGroup.selectedToggleProperty().addListener(new ChangeListener() {
@Override
- public void changed(ObservableValue extends String> observable,
- String oldValue, String newValue) {
- checkBwInput();
+ public void changed(ObservableValue extends Toggle> ov,
+ Toggle old_toggle, Toggle new_toggle) {
+ if (radioGroup.getSelectedToggle() == null) {
+ return;
+ }
+ intPara1 = (int) ((RadioButton) new_toggle).getUserData();
+ intInput.setDisable(intPara1 != 3);
}
});
+ radio1.setSelected(true);
+ valueCheck = new CheckBox(getMessage("Dithering"));
+ valueCheck.setSelected(true);
+ FxmlTools.setComments(valueCheck, new Tooltip(getMessage("DitherComments")));
+
+ setBox.getChildren().addAll(radio1, radio2, radio3, intInput, valueCheck);
+ operationBarController.startButton.disableProperty().bind(
+ intInput.styleProperty().isEqualTo(badStyle)
+ );
} catch (Exception e) {
logger.error(e.toString());
}
+
}
- private void checkEffetcsOperationType() {
- intLabel.setText("");
- intBox.setDisable(true);
- stringLabel.setText("");
- stringBox.setDisable(true);
- thresholdingBox.setDisable(true);
- thresholdingInput.setStyle(null);
- thresholdingMinInput.setStyle(null);
- thresholdingMaxInput.setStyle(null);
- grayCheck.setDisable(true);
- bwBox.setDisable(true);
- bwInput.setStyle(null);
- RadioButton selected = (RadioButton) effectsGroup.getSelectedToggle();
- if (getMessage("Blur").equals(selected.getText())) {
- effectType = EffectsOperationType.Blur;
- intLabel.setText(getMessage("Radius"));
- intBox.setDisable(false);
- intBox.getItems().clear();
- intBox.getItems().addAll(Arrays.asList("10", "5", "3", "8", "15", "20", "30"));
- intBox.setEditable(true);
- intValue = 10;
- intBox.getSelectionModel().select("10");
- } else if (getMessage("Sharpen").equals(selected.getText())) {
- effectType = EffectsOperationType.Sharpen;
- } else if (getMessage("Clarity").equals(selected.getText())) {
- effectType = EffectsOperationType.Clarity;
- } else if (getMessage("EdgeDetection").equals(selected.getText())) {
- effectType = EffectsOperationType.EdgeDetect;
- } else if (getMessage("Emboss").equals(selected.getText())) {
- effectType = EffectsOperationType.Emboss;
- intLabel.setText(getMessage("Radius"));
- intBox.setDisable(false);
- intBox.getItems().clear();
- intBox.getItems().addAll(Arrays.asList("3", "5"));
- intBox.setEditable(false);
- intValue = 3;
- intBox.getSelectionModel().select("3");
- stringLabel.setText(getMessage("Direction"));
- stringBox.setDisable(false);
- stringBox.getItems().clear();
- stringBox.getItems().addAll(Arrays.asList(getMessage("Top"), getMessage("Bottom"),
- getMessage("Left"), getMessage("Right"),
- getMessage("LeftTop"), getMessage("RightBottom"),
- getMessage("LeftBottom"), getMessage("RightTop")));
- direction = ImageConvertTools.Direction.Top;
- stringBox.getSelectionModel().select(getMessage("Top"));
- grayCheck.setDisable(false);
- } else if (getMessage("Posterizing").equals(selected.getText())) {
- effectType = EffectsOperationType.Posterizing;
- intLabel.setText(getMessage("Size"));
- intBox.setDisable(false);
- intBox.getItems().clear();
- intBox.getItems().addAll(Arrays.asList("64", "32", "128", "16"));
- intBox.setEditable(false);
- intBox.getSelectionModel().select("64");
- } else if (getMessage("Thresholding").equals(selected.getText())) {
- effectType = EffectsOperationType.Thresholding;
- thresholdingBox.setDisable(false);
- checkThresholding();
- } else if (getMessage("Gray").equals(selected.getText())) {
- effectType = EffectsOperationType.Gray;
- } else if (getMessage("BlackOrWhite").equals(selected.getText())) {
- effectType = EffectsOperationType.BlackOrWhite;
- bwBox.setDisable(false);
- bwLabel1.setText(getMessage("Threshold"));
- bwSlider.setMax(99);
- bwSlider.setMin(1);
- bwSlider.setBlockIncrement(1);
- bwSlider.setValue(50);
- bwLabel2.setText("%");
- bwLabel3.setVisible(true);
- checkBwInput();
- } else if (getMessage("Sepia").equals(selected.getText())) {
- effectType = EffectsOperationType.Sepia;
- bwBox.setDisable(false);
- bwLabel1.setText(getMessage("Intensity"));
- bwSlider.setMax(255);
- bwSlider.setMin(0);
- bwSlider.setBlockIncrement(1);
- bwSlider.setValue(80);
- bwLabel2.setText("");
- bwLabel3.setVisible(false);
- checkBwInput();
+ private void makeSepiaBox() {
+ try {
+ intPara1 = 80;
+ intLabel = new Label(getMessage("Intensity"));
+ intInput = new TextField();
+ intInput.textProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue extends String> observable,
+ String oldValue, String newValue) {
+ try {
+ int v = Integer.valueOf(intInput.getText());
+ if (v >= 0 && v <= 255) {
+ intPara1 = v;
+ intInput.setStyle(null);
+ } else {
+ intInput.setStyle(badStyle);
+ popError("0~255");
+ }
+ } catch (Exception e) {
+ popError("0~255");
+ intInput.setStyle(badStyle);
+ }
+ }
+ });
+ intInput.setPrefWidth(100);
+ intInput.setText("80");
+ FxmlTools.quickTooltip(intInput, new Tooltip("0~255"));
+
+ setBox.getChildren().addAll(intLabel, intInput);
+ operationBarController.startButton.disableProperty().bind(
+ intInput.styleProperty().isEqualTo(badStyle)
+ .or(Bindings.isEmpty(targetPathInput.textProperty()))
+ .or(targetPathInput.styleProperty().isEqualTo(badStyle))
+ .or(Bindings.isEmpty(sourceFilesInformation))
+ );
+ } catch (Exception e) {
+ logger.error(e.toString());
}
+
}
- private void checkThresholding() {
+ private void makeConvolutionBox() {
try {
- threadholding = Integer.valueOf(thresholdingInput.getText());
- if (threadholding >= 0 && threadholding <= 255) {
- thresholdingInput.setStyle(null);
- } else {
- thresholdingInput.setStyle(badStyle);
+ stringLabel = new Label(getMessage("ConvolutionKernel"));
+ stringBox = new ComboBox();
+ kernel = null;
+ if (kernels == null) {
+ kernels = TableConvolutionKernel.read();
}
+ loadKernelsList(kernels);
+ stringBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue ov, Number oldValue, Number newValue) {
+ int index = newValue.intValue();
+ if (index < 0 || index >= kernels.size()) {
+ kernel = null;
+ stringBox.getEditor().setStyle(badStyle);
+ return;
+ }
+ kernel = kernels.get(index);
+ stringBox.getEditor().setStyle(null);
+ }
+ });
+ FxmlTools.quickTooltip(stringBox, new Tooltip(getMessage("CTRL+k")));
+ setButton = new Button(getMessage("ManageDot"));
+ setButton.setOnAction(new EventHandler() {
+ @Override
+ public void handle(ActionEvent event) {
+ BaseController c = openStage(CommonValues.ConvolutionKernelManagerFxml, false);
+ c.setParentController(getMyController());
+ c.setParentFxml(getMyFxml());
+ }
+ });
+ setBox.getChildren().addAll(stringLabel, stringBox, setButton);
+ operationBarController.startButton.disableProperty().bind(
+ stringBox.getEditor().styleProperty().isEqualTo(badStyle)
+ .or(Bindings.isEmpty(targetPathInput.textProperty()))
+ .or(targetPathInput.styleProperty().isEqualTo(badStyle))
+ .or(Bindings.isEmpty(sourceFilesInformation))
+ );
} catch (Exception e) {
- thresholdingInput.setStyle(badStyle);
+ logger.error(e.toString());
}
+
+ }
+
+ private void makeContrastBox() {
try {
- threadholdingMin = Integer.valueOf(thresholdingMinInput.getText());
- if (threadholdingMin >= 0 && threadholdingMin <= 255) {
- thresholdingMinInput.setStyle(null);
- } else {
- thresholdingMinInput.setStyle(badStyle);
- }
+ contrastAlgorithm = ImageContrast.ContrastAlgorithm.Gray_Histogram_Equalization;
+ stringLabel = new Label(getMessage("Algorithm"));
+ stringBox = new ComboBox();
+ stringBox.getItems().addAll(Arrays.asList(getMessage("GrayHistogramEqualization"),
+ getMessage("GrayHistogramShifting"),
+ getMessage("LumaHistogramEqualization"), getMessage("BrightnessHistogramEqualization"),
+ getMessage("AdaptiveHistogramEqualization")));
+ stringBox.getSelectionModel().select(0);
+ stringBox.valueProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue ov, String oldValue, String newValue) {
+ if (getMessage("GrayHistogramEqualization").equals(newValue)) {
+ contrastAlgorithm = ImageContrast.ContrastAlgorithm.Gray_Histogram_Equalization;
+ } else if (getMessage("GrayHistogramShifting").equals(newValue)) {
+ contrastAlgorithm = ImageContrast.ContrastAlgorithm.Gray_Histogram_Shifting;
+ } else if (getMessage("LumaHistogramEqualization").equals(newValue)) {
+ contrastAlgorithm = ImageContrast.ContrastAlgorithm.Luma_Histogram_Equalization;
+ } else if (getMessage("BrightnessHistogramEqualization").equals(newValue)) {
+ contrastAlgorithm = ImageContrast.ContrastAlgorithm.HSB_Histogram_Equalization;
+ } else if (getMessage("AdaptiveHistogramEqualization").equals(newValue)) {
+ contrastAlgorithm = ImageContrast.ContrastAlgorithm.Adaptive_Histogram_Equalization;
+ }
+ }
+ });
+
+ intPara1 = 80;
+ intLabel = new Label(getMessage("Offset"));
+ intInput = new TextField();
+ intInput.textProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue extends String> observable,
+ String oldValue, String newValue) {
+ try {
+ int v = Integer.valueOf(intInput.getText());
+ if (v >= 0 && v <= 255) {
+ intPara1 = v;
+ intInput.setStyle(null);
+ } else {
+ intInput.setStyle(badStyle);
+ popError("0~255");
+ }
+ } catch (Exception e) {
+ popError("0~255");
+ }
+ }
+ });
+ intInput.setPrefWidth(100);
+ intInput.setText("80");
+ FxmlTools.quickTooltip(intInput, new Tooltip("0~255"));
+
+ setBox.getChildren().addAll(stringLabel, stringBox, intLabel, intInput);
+ operationBarController.startButton.disableProperty().bind(
+ intInput.styleProperty().isEqualTo(badStyle)
+ .or(stringBox.getEditor().styleProperty().isEqualTo(badStyle))
+ .or(Bindings.isEmpty(targetPathInput.textProperty()))
+ .or(targetPathInput.styleProperty().isEqualTo(badStyle))
+ .or(Bindings.isEmpty(sourceFilesInformation))
+ );
} catch (Exception e) {
- thresholdingMinInput.setStyle(badStyle);
+ logger.error(e.toString());
}
- try {
- threadholdingMax = Integer.valueOf(thresholdingMaxInput.getText());
- if (threadholdingMax >= 0 && threadholdingMax <= 255) {
- thresholdingMaxInput.setStyle(null);
- } else {
- thresholdingMaxInput.setStyle(badStyle);
+ }
+
+ public void applyKernel(ConvolutionKernel kernel) {
+ if (effectType != OperationType.Convolution || stringBox == null) {
+ return;
+ }
+ convolutionRadio.fire();
+ if (stringBox.getItems().contains(kernel.getName())) {
+ stringBox.getSelectionModel().select(kernel.getName());
+ } else {
+ stringBox.getSelectionModel().select(-1);
+ }
+ this.kernel = kernel;
+ okAction();
+ }
+
+ public void loadKernelsList(List records) {
+ if (effectType != OperationType.Convolution || stringBox == null) {
+ return;
+ }
+ kernels = records;
+ stringBox.getItems().clear();
+ if (kernels != null && !kernels.isEmpty()) {
+ List names = new ArrayList<>();
+ for (ConvolutionKernel k : kernels) {
+ names.add(k.getName());
}
- } catch (Exception e) {
- thresholdingMaxInput.setStyle(badStyle);
+ stringBox.getItems().addAll(names);
+ stringBox.getSelectionModel().select(0);
+ stringBox.getEditor().setStyle(null);
+ } else {
+ stringBox.getEditor().setStyle(badStyle);
}
}
- private void checkBwInput() {
- try {
- if (effectType == EffectsOperationType.BlackOrWhite
- && bwInput.getText().trim().isEmpty()) {
- bwInput.setStyle(null);
- bwValue = -1;
+ @Override
+ protected void keyEventsHandler(KeyEvent event) {
+ super.keyEventsHandler(event);
+ if (event.isControlDown()) {
+ String key = event.getText();
+ if (key == null || key.isEmpty()) {
return;
}
- bwValue = Integer.valueOf(bwInput.getText());
- if (bwValue >= 0 && bwValue <= bwSlider.getMax()) {
- bwInput.setStyle(null);
- bwSlider.setValue(bwValue);
- } else {
- bwValue = -1;
- bwInput.setStyle(badStyle);
+ switch (key) {
+ case "k":
+ case "K":
+ if (stringBox != null) {
+ stringBox.show();
+ }
+ break;
}
- } catch (Exception e) {
- bwValue = -1;
- bwInput.setStyle(badStyle);
}
}
@@ -359,41 +742,91 @@ private void checkBwInput() {
protected BufferedImage handleImage(BufferedImage source) {
try {
BufferedImage target = null;
+ PixelsOperation pixelsOperation;
+ ImageConvolution imageConvolution;
if (null != effectType) {
switch (effectType) {
+ case Contrast:
+ ImageContrast imageContrast = new ImageContrast(source, contrastAlgorithm);
+ imageContrast.setIntPara1(intPara1);
+ target = imageContrast.operate();
+ break;
+ case Convolution:
+ if (kernel == null) {
+ int index = stringBox.getSelectionModel().getSelectedIndex();
+ if (kernels == null || kernels.isEmpty() || index < 0) {
+ return null;
+ }
+ kernel = kernels.get(index);
+ }
+ imageConvolution = new ImageConvolution(source, kernel);
+ target = imageConvolution.operate();
+ break;
case Blur:
- target = ImageEffectTools.applyConvolution(source, ConvolutionKernel.makeGaussKernel(intValue));
+ if (kernel == null) {
+ return null;
+ }
+ imageConvolution = new ImageConvolution(source, kernel);
+ target = imageConvolution.operate();
break;
case Sharpen:
- target = ImageEffectTools.applyConvolution(source, ConvolutionKernel.makeSharpen3b());
+ kernel = ConvolutionKernel.makeSharpen3b();
+ imageConvolution = new ImageConvolution(source, kernel);
+ target = imageConvolution.operate();
break;
case Clarity:
- target = ImageEffectTools.applyConvolution(source, ConvolutionKernel.makeUnsharpMasking5());
+ kernel = ConvolutionKernel.makeUnsharpMasking5();
+ imageConvolution = new ImageConvolution(source, kernel);
+ target = imageConvolution.operate();
break;
case EdgeDetect:
- target = ImageEffectTools.applyConvolution(source, ConvolutionKernel.makeEdgeDetection3b());
+ kernel = ConvolutionKernel.makeEdgeDetection3b();
+ imageConvolution = new ImageConvolution(source, kernel);
+ target = imageConvolution.operate();
break;
case Emboss:
- target = ImageEffectTools.applyConvolution(source, ConvolutionKernel.makeEmbossKernel(direction, intValue, grayCheck.isSelected()));
+ kernel = ConvolutionKernel.makeEmbossKernel(intPara1, intPara2, valueCheck.isSelected());
+ imageConvolution = new ImageConvolution(source, kernel);
+ target = imageConvolution.operate();
break;
case Thresholding:
- target = ImageEffectTools.thresholding(ImageConvertTools.removeAlpha(source), threadholding, threadholdingMin, threadholdingMax);
+ pixelsOperation = new PixelsOperation(ImageConvert.removeAlpha(source), effectType);
+ pixelsOperation.setIntPara1(intPara1);
+ pixelsOperation.setIntPara2(intPara2);
+ pixelsOperation.setIntPara3(intPara3);
+ target = pixelsOperation.operate();
break;
- case Posterizing:
- target = ImageEffectTools.posterizing(ImageConvertTools.removeAlpha(source), intValue);
+ case Quantization:
+ int channelSize = (int) Math.round(Math.pow(intPara1, 1.0 / 3.0));
+ ImageQuantization quantization = new ImageQuantization(ImageConvert.removeAlpha(source),
+ quantizationAlgorithm, channelSize);
+ quantization.setIsDithering(valueCheck.isSelected());
+ target = quantization.operate();
break;
case Gray:
- target = ImageGrayTools.color2Gray(source);
+ target = ImageGray.byteGray(source);
break;
case BlackOrWhite:
- if (bwValue < 0) {
- target = ImageGrayTools.color2Binary(source);
- } else {
- target = ImageGrayTools.color2BinaryWithPercentage(source, bwValue);
+ ImageBinary imageBinary;
+ switch (intPara1) {
+ case 2:
+ imageBinary = new ImageBinary(source, -1);
+ break;
+ case 3:
+ imageBinary = new ImageBinary(source, intPara2);
+ break;
+ default:
+ int t = ImageBinary.calculateThreshold(source);
+ imageBinary = new ImageBinary(source, t);
+ break;
}
+ imageBinary.setIsDithering(valueCheck.isSelected());
+ target = imageBinary.operate();
break;
case Sepia:
- target = ImageEffectTools.sepiaImage(source, bwValue);
+ pixelsOperation = new PixelsOperation(source, effectType);
+ pixelsOperation.setIntPara1(intPara1);
+ target = pixelsOperation.operate();
break;
default:
break;
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchReplaceColorController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchReplaceColorController.java
index d8f24405a..cfce44a8c 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchReplaceColorController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchReplaceColorController.java
@@ -17,12 +17,13 @@
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
-import static mara.mybox.objects.AppVaribles.logger;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.fxml.FxmlImageTools;
+import static mara.mybox.value.AppVaribles.logger;
+import static mara.mybox.value.AppVaribles.getMessage;
import mara.mybox.fxml.FxmlTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.image.ImageReplaceColorTools;
+import mara.mybox.image.ImageColor;
+import mara.mybox.image.ImageScope;
+import mara.mybox.image.PixelsOperation;
/**
* @Author Mara
@@ -184,10 +185,25 @@ private void blackForNew(ActionEvent event) {
@Override
protected BufferedImage handleImage(BufferedImage source) {
- BufferedImage target = ImageReplaceColorTools.replaceColor(source,
- FxmlImageTools.colorConvert(oldColorPicker.getValue()),
- FxmlImageTools.colorConvert(newColorPicker.getValue()),
- distance, isColor, excludeCheck.isSelected());
+ ImageScope scope = new ImageScope();
+ if (isColor) {
+ scope.setColorScopeType(ImageScope.ColorScopeType.Color);
+ scope.setColorDistance(distance);
+ } else {
+ scope.setColorScopeType(ImageScope.ColorScopeType.Hue);
+ scope.setHsbDistance(distance / 360.0f);
+ }
+ scope.setColorExcluded(excludeCheck.isSelected());
+ PixelsOperation pixelsOperation = new PixelsOperation(source, scope,
+ PixelsOperation.OperationType.ReplaceColor);
+ pixelsOperation.setColorPara1(ImageColor.converColor(oldColorPicker.getValue()));
+ pixelsOperation.setColorPara2(ImageColor.converColor(newColorPicker.getValue()));
+ BufferedImage target = pixelsOperation.operate();
+
+// BufferedImage target = ImageReplaceColorTools.replaceColor(source,
+// FxmlManufactureTools.colorConvert(oldColorPicker.getValue()),
+// FxmlManufactureTools.colorConvert(newColorPicker.getValue()),
+// distance, isColor, excludeCheck.isSelected());
return target;
}
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchShadowController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchShadowController.java
index 1df90718b..294950f35 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchShadowController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchShadowController.java
@@ -15,10 +15,10 @@
import javafx.scene.control.Tooltip;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.image.ImageConvertTools;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.fxml.FxmlImageTools;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.image.ImageConvert;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.fxml.image.ImageTools;
import mara.mybox.fxml.FxmlTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
@@ -180,7 +180,7 @@ protected BufferedImage handleImage(BufferedImage source) {
value = source.getWidth() * percent / 100;
}
Color color = shadowColorPicker.getValue();
- BufferedImage target = ImageConvertTools.addShadow(source, value, FxmlImageTools.colorConvert(color));
+ BufferedImage target = ImageConvert.addShadow(source, value, ImageTools.colorConvert(color));
return target;
} catch (Exception e) {
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchSizeController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchSizeController.java
index f4ae2cafd..ef929e1ac 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchSizeController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchSizeController.java
@@ -16,10 +16,10 @@
import javafx.scene.layout.Pane;
import javafx.stage.Modality;
import javafx.stage.Stage;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.image.ImageConvertTools;
-import mara.mybox.objects.AppVaribles;
-import mara.mybox.objects.CommonValues;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.image.ImageConvert;
+import mara.mybox.value.AppVaribles;
+import mara.mybox.value.CommonValues;
import static mara.mybox.fxml.FxmlTools.badStyle;
/**
@@ -272,16 +272,16 @@ protected BufferedImage handleImage(BufferedImage source) {
try {
BufferedImage target = null;
if (sizeType == SizeType.Scale) {
- target = ImageConvertTools.scaleImage(source, scale);
+ target = ImageConvert.scaleImage(source, scale);
} else if (sizeType == SizeType.Width) {
- target = ImageConvertTools.scaleImageWidthKeep(source, keepWidth);
+ target = ImageConvert.scaleImageWidthKeep(source, keepWidth);
} else if (sizeType == SizeType.Height) {
- target = ImageConvertTools.scaleImageHeightKeep(source, keepHeight);
+ target = ImageConvert.scaleImageHeightKeep(source, keepHeight);
} else if (sizeType == SizeType.Custom) {
- target = ImageConvertTools.scaleImage(source, customWidth, customHeight);
+ target = ImageConvert.scaleImage(source, customWidth, customHeight);
}
return target;
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchTextController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchTextController.java
index 9d14eb5e7..8ebe41926 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchTextController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchTextController.java
@@ -20,11 +20,11 @@
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.image.ImageConvertTools;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.fxml.FxmlImageTools;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.image.ImageConvert;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.fxml.image.ImageTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
/**
@@ -323,7 +323,7 @@ protected void makeMoreParameters() {
FxFont = Font.font(fontFamily, FontWeight.NORMAL, FontPosture.REGULAR, waterSize);
}
- color = FxmlImageTools.colorConvert(waterColorPicker.getValue());
+ color = ImageTools.colorConvert(waterColorPicker.getValue());
final String msg = waterInput.getText().trim();
final Text text = new Text(msg);
@@ -368,7 +368,7 @@ protected BufferedImage handleImage(BufferedImage source) {
break;
}
- BufferedImage target = ImageConvertTools.addText(source,
+ BufferedImage target = ImageConvert.addText(source,
waterInput.getText().trim(), font, color,
x, y, waterTransparent, waterShadow, waterAngle, false);
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchTransformController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchTransformController.java
index 8709c2ca9..8416d413f 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchTransformController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBatchTransformController.java
@@ -12,10 +12,10 @@
import javafx.scene.control.Slider;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
-import static mara.mybox.objects.AppVaribles.logger;
-import static mara.mybox.objects.AppVaribles.getMessage;
+import static mara.mybox.value.AppVaribles.logger;
+import static mara.mybox.value.AppVaribles.getMessage;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.image.ImageTransformTools;
+import mara.mybox.image.ImageTransform;
/**
* @Author Mara
@@ -167,16 +167,16 @@ protected BufferedImage handleImage(BufferedImage source) {
try {
BufferedImage target = null;
if (transformType == TransformType.Shear) {
- target = ImageTransformTools.shearImage(source, shearX, 0);
+ target = ImageTransform.shearImage(source, shearX, 0);
} else if (transformType == TransformType.VerticalMirror) {
- target = ImageTransformTools.verticalMirrorImage(source);
+ target = ImageTransform.verticalMirrorImage(source);
} else if (transformType == TransformType.HorizontalMirror) {
- target = ImageTransformTools.horizontalMirrorImage(source);
+ target = ImageTransform.horizontalMirrorImage(source);
} else if (transformType == TransformType.Rotate) {
- target = ImageTransformTools.rotateImage(source, rotateAngle);
+ target = ImageTransform.rotateImage(source, rotateAngle);
}
return target;
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBrowseController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBrowseController.java
index d1b064147..18a0eb9dc 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBrowseController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureBrowseController.java
@@ -5,10 +5,11 @@
import javafx.fxml.FXML;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Toggle;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
+import javafx.scene.control.ToolBar;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.value.AppVaribles;
import mara.mybox.fxml.FxmlTools;
+import static mara.mybox.value.AppVaribles.getMessage;
/**
* @Author Mara
@@ -20,6 +21,9 @@ public class ImageManufactureBrowseController extends ImageManufactureController
final protected String ImageSortTypeKey;
+ @FXML
+ protected ToolBar navBar;
+
public ImageManufactureBrowseController() {
ImageSortTypeKey = "ImageSortType";
}
@@ -44,8 +48,10 @@ protected void initInterface() {
isSettingValues = true;
- navBar.setDisable(false);
- checkImageNevigator();
+ if (sourceFile != null && navBox != null) {
+ navBox.setDisable(false);
+ checkImageNevigator();
+ }
isSettingValues = false;
} catch (Exception e) {
@@ -79,6 +85,7 @@ public void nextAction() {
return;
}
if (nextFile != null) {
+ setImageChanged(false);
loadImage(nextFile.getAbsoluteFile(), false);
}
}
@@ -90,6 +97,7 @@ public void previousAction() {
return;
}
if (previousFile != null) {
+ setImageChanged(false);
loadImage(previousFile.getAbsoluteFile(), false);
}
}
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureColorController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureColorController.java
index 856fba7af..eead11533 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureColorController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureColorController.java
@@ -20,15 +20,15 @@
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Modality;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.fxml.FxmlAdjustColorTools;
-import mara.mybox.fxml.FxmlAdjustColorTools.ColorActionType;
-import mara.mybox.fxml.FxmlAdjustColorTools.ColorObjectType;
+import static mara.mybox.value.AppVaribles.logger;
import mara.mybox.fxml.FxmlTools;
-import mara.mybox.objects.CommonValues;
+import mara.mybox.value.CommonValues;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.ImageScope;
+import mara.mybox.fxml.image.PixelsOperation;
+import mara.mybox.image.ImageColor;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.image.PixelsOperation.ColorActionType;
+import mara.mybox.image.PixelsOperation.OperationType;
/**
* @Author Mara
@@ -39,7 +39,7 @@
public class ImageManufactureColorController extends ImageManufactureController {
protected int colorValue;
- private ColorObjectType colorOperationType;
+ private OperationType colorOperationType;
private ColorActionType colorActionType;
@FXML
@@ -98,17 +98,17 @@ public void changed(ObservableValue extends String> observable,
colorPicker.setValue(Color.TRANSPARENT);
- Tooltip tips = new Tooltip("CTRL+a");
+ Tooltip tips = new Tooltip("CTRL+q");
tips.setFont(new Font(16));
- FxmlTools.quickTooltip(increaseButton, tips);
+ FxmlTools.quickTooltip(setButton, tips);
- tips = new Tooltip("CTRL+q");
+ tips = new Tooltip("CTRL+w");
tips.setFont(new Font(16));
- FxmlTools.quickTooltip(decreaseButton, tips);
+ FxmlTools.quickTooltip(increaseButton, tips);
- tips = new Tooltip("CTRL+w");
+ tips = new Tooltip("CTRL+e");
tips.setFont(new Font(16));
- FxmlTools.quickTooltip(setButton, tips);
+ FxmlTools.quickTooltip(decreaseButton, tips);
colorPicker.setValue(Color.TRANSPARENT);
@@ -131,7 +131,8 @@ protected void initInterface() {
checkColorInput();
isSettingValues = true;
- if (CommonValues.NoAlphaImages.contains(values.getImageInfo().getImageFormat())) {
+ if (values.getImageInfo() != null
+ && CommonValues.NoAlphaImages.contains(values.getImageInfo().getImageFormat())) {
opacityRadio.setDisable(true);
// opacityRadio.setPrefWidth(0);
} else {
@@ -154,12 +155,10 @@ private void checkColorOperationType() {
increaseButton.setDisable(false);
filterButton.setDisable(false);
invertButton.setDisable(false);
- if (scope != null) {
- scope.setOperationType(ImageScope.OperationType.Color);
- }
+ isSettingColor = false;
RadioButton selected = (RadioButton) colorGroup.getSelectedToggle();
if (getMessage("Brightness").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Brightness;
+ colorOperationType = OperationType.Brightness;
colorSlider.setMax(100);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -170,7 +169,7 @@ private void checkColorOperationType() {
filterButton.setDisable(true);
invertButton.setDisable(true);
} else if (getMessage("Saturation").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Sauration;
+ colorOperationType = OperationType.Sauration;
colorSlider.setMax(100);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -181,7 +180,7 @@ private void checkColorOperationType() {
filterButton.setDisable(true);
invertButton.setDisable(true);
} else if (getMessage("Hue").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Hue;
+ colorOperationType = OperationType.Hue;
colorSlider.setMax(359);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -192,7 +191,7 @@ private void checkColorOperationType() {
filterButton.setDisable(true);
invertButton.setDisable(true);
} else if (getMessage("Red").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Red;
+ colorOperationType = OperationType.Red;
colorSlider.setMax(255);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -201,7 +200,7 @@ private void checkColorOperationType() {
colorInput.setText("50");
}
} else if (getMessage("Green").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Green;
+ colorOperationType = OperationType.Green;
colorSlider.setMax(255);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -210,7 +209,7 @@ private void checkColorOperationType() {
colorInput.setText("50");
}
} else if (getMessage("Blue").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Blue;
+ colorOperationType = OperationType.Blue;
colorSlider.setMax(255);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -219,7 +218,7 @@ private void checkColorOperationType() {
colorInput.setText("50");
}
} else if (getMessage("Yellow").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Yellow;
+ colorOperationType = OperationType.Yellow;
colorSlider.setMax(255);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -228,7 +227,7 @@ private void checkColorOperationType() {
colorInput.setText("50");
}
} else if (getMessage("Cyan").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Cyan;
+ colorOperationType = OperationType.Cyan;
colorSlider.setMax(255);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -237,7 +236,7 @@ private void checkColorOperationType() {
colorInput.setText("50");
}
} else if (getMessage("Magenta").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Magenta;
+ colorOperationType = OperationType.Magenta;
colorSlider.setMax(255);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -246,7 +245,7 @@ private void checkColorOperationType() {
colorInput.setText("50");
}
} else if (getMessage("RGB").equals(selected.getText())) {
- colorOperationType = ColorObjectType.RGB;
+ colorOperationType = OperationType.RGB;
colorSlider.setMax(255);
colorSlider.setMin(1);
colorSlider.setBlockIncrement(1);
@@ -257,7 +256,7 @@ private void checkColorOperationType() {
filterButton.setDisable(true);
setButton.setDisable(true);
} else if (getMessage("Opacity").equals(selected.getText())) {
- colorOperationType = ColorObjectType.Opacity;
+ colorOperationType = OperationType.Opacity;
colorSlider.setMax(100);
colorSlider.setMin(0);
colorSlider.setBlockIncrement(1);
@@ -268,16 +267,14 @@ private void checkColorOperationType() {
filterButton.setDisable(true);
invertButton.setDisable(true);
} else if (getMessage("Color").equals(selected.getText())) {
- if (scope != null) {
- scope.setOperationType(ImageScope.OperationType.ReplaceColor);
- }
- colorOperationType = ColorObjectType.Color;
+ colorOperationType = OperationType.Color;
decreaseButton.setDisable(true);
increaseButton.setDisable(true);
filterButton.setDisable(true);
invertButton.setDisable(true);
colorHBox.setDisable(false);
sliderHBox.setDisable(true);
+ isSettingColor = true;
}
if (scope != null) {
showLabels();
@@ -331,23 +328,29 @@ public void invertAction() {
@Override
protected void keyEventsHandler(KeyEvent event) {
super.keyEventsHandler(event);
- String key = event.getText();
- if (key == null || key.isEmpty()) {
- return;
- }
if (event.isControlDown()) {
+ String key = event.getText();
+ if (key == null || key.isEmpty()) {
+ return;
+ }
switch (key) {
- case "a":
- case "A":
- increaseAction();
- break;
case "q":
case "Q":
- decreaseAction();
+ if (setButton != null && !setButton.isDisabled()) {
+ setAction();
+ }
break;
case "w":
case "W":
- setAction();
+ if (increaseButton != null && !increaseButton.isDisabled()) {
+ increaseAction();
+ }
+ break;
+ case "e":
+ case "E":
+ if (decreaseButton != null && !decreaseButton.isDisabled()) {
+ decreaseAction();
+ }
break;
}
}
@@ -360,12 +363,15 @@ private void applyChange() {
task = new Task() {
@Override
protected Void call() throws Exception {
- double change = colorValue;
+ PixelsOperation pixelsOperation = new PixelsOperation(values.getCurrentImage(), scope,
+ colorOperationType, colorActionType);
switch (colorOperationType) {
+ case Hue:
+ pixelsOperation.setFloatPara1(colorValue / 360.0f);
+ break;
case Brightness:
case Sauration:
- case Opacity:
- change = change / 100.0f;
+ pixelsOperation.setFloatPara1(colorValue / 100.0f);
break;
case Red:
case Green:
@@ -374,11 +380,16 @@ protected Void call() throws Exception {
case Cyan:
case Magenta:
case RGB:
- change = change / 255.0;
+ pixelsOperation.setIntPara1(colorValue);
+ break;
+ case Opacity:
+ pixelsOperation.setIntPara1(colorValue * 255 / 100);
+ break;
+ case Color:
+ pixelsOperation.setColorPara1(ImageColor.converColor(colorPicker.getValue()));
break;
}
- final Image newImage = FxmlAdjustColorTools.ajustColor(values.getCurrentImage(),
- colorOperationType, colorActionType, change, colorPicker.getValue(), scope);
+ final Image newImage = pixelsOperation.operateFxImage();
if (task.isCancelled()) {
return null;
}
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureController.java
index 9f7e0adf4..f47356981 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureController.java
@@ -29,14 +29,10 @@
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
-import javafx.scene.control.RadioButton;
import javafx.scene.control.ScrollPane;
-import javafx.scene.control.SplitPane;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
-import javafx.scene.control.Toggle;
-import javafx.scene.control.ToggleGroup;
import javafx.scene.control.ToolBar;
import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
@@ -47,6 +43,7 @@
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
+import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
@@ -55,27 +52,29 @@
import javafx.stage.Modality;
import javafx.util.Callback;
import javax.imageio.ImageIO;
-import static mara.mybox.objects.AppVaribles.logger;
import mara.mybox.db.TableImageHistory;
import mara.mybox.db.TableImageInit;
-import mara.mybox.imagefile.ImageFileReaders;
-import mara.mybox.imagefile.ImageFileWriters;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.ImageHistory;
-import mara.mybox.objects.ImageManufactureValues;
-import mara.mybox.objects.ImageScope;
+import mara.mybox.image.file.ImageFileReaders;
+import mara.mybox.image.file.ImageFileWriters;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.value.CommonValues;
+import mara.mybox.data.ImageHistory;
+import mara.mybox.data.ImageManufactureValues;
+import mara.mybox.image.ImageScope;
import mara.mybox.tools.DateTools;
import mara.mybox.tools.FileTools;
import mara.mybox.fxml.FxmlTools;
-import mara.mybox.fxml.FxmlImageTools;
-import mara.mybox.fxml.FxmlScopeTools;
+import mara.mybox.fxml.image.ImageTools;
+import mara.mybox.fxml.image.FxmlScopeTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.objects.ImageScope.ColorScopeType;
-import mara.mybox.objects.ImageScope.OperationType;
-import mara.mybox.objects.ImageScope.ScopeType;
-import mara.mybox.objects.IntRectangle;
+import mara.mybox.fxml.image.PixelsOperation;
+import mara.mybox.image.ImageColor;
+import mara.mybox.image.ImageScope.ColorScopeType;
+import mara.mybox.image.ImageScope.ScopeType;
+import mara.mybox.image.PixelsOperation.OperationType;
+import mara.mybox.data.IntRectangle;
+import static mara.mybox.value.AppVaribles.logger;
/**
* @Author Mara
@@ -89,15 +88,12 @@ public abstract class ImageManufactureController extends ImageViewerController {
protected ImageView refView, scopeView;
protected Label refLabel;
protected VBox refBox, scopeBox;
-
protected ImageManufactureValues values;
- protected boolean isSettingValues, isSwitchingTab;
-
+ protected boolean isSwitchingTab, isSettingColor;
protected String initTab;
protected int stageWidth, stageHeight;
protected String imageHistoriesPath;
protected List imageHistories;
-
protected ImageScope scope;
protected TextField scopeLeftXInput, scopeLeftYInput, scopeRightXInput, scopeRightYInput;
@@ -134,31 +130,27 @@ protected class ImageManufactureParameters {
protected ToolBar fileBar, hotBar;
@FXML
protected Tab fileTab, viewTab, colorTab, textTab, coverTab, cropTab,
- arcTab, shadowTab, effectsTab, convolutionTab, sizeTab, refTab,
+ arcTab, shadowTab, effectsTab, sizeTab, refTab,
browseTab, transformTab, marginsTab;
@FXML
- protected Label tipsLabel, promptLabel, imageLabel;
+ protected Label promptLabel, imageLabel;
@FXML
- protected Button selectRefButton, saveButton, recoverButton, undoButton, redoButton;
+ protected Button selectRefButton, recoverButton, undoButton, redoButton, popButton, refButton;
@FXML
protected CheckBox showRefCheck, showScopeCheck, saveCheck;
@FXML
- protected SplitPane splitPane;
- @FXML
protected TabPane tabPane;
@FXML
protected HBox hotBox, imageLabelBox;
@FXML
protected VBox imageBox;
@FXML
- protected ComboBox hisBox;
- @FXML
- protected ToggleGroup scopeGroup;
+ protected ComboBox hisBox, scopeListBox;
@FXML
protected ColorPicker colorPicker;
public ImageManufactureController() {
- sourcePathKey = "ImageSourcePathKey";
+ TipsLabelKey = "ImageManufactureTips";
}
@@ -166,12 +158,12 @@ protected void initCommon() {
try {
values = new ImageManufactureValues();
values.setRefSync(true);
+ isSettingColor = false;
browseTab.setDisable(true);
viewTab.setDisable(true);
colorTab.setDisable(true);
effectsTab.setDisable(true);
- convolutionTab.setDisable(true);
sizeTab.setDisable(true);
refTab.setDisable(true);
transformTab.setDisable(true);
@@ -196,11 +188,7 @@ public void changed(ObservableValue extends Tab> observable,
}
});
- Tooltip tips = new Tooltip(getMessage("ImageManufactureTips"));
- tips.setFont(new Font(16));
- FxmlTools.quickTooltip(tipsLabel, tips);
-
- tips = new Tooltip(getMessage("ImageRefTips"));
+ Tooltip tips = new Tooltip(getMessage("ImageRefTips"));
tips.setFont(new Font(16));
FxmlTools.setComments(showRefCheck, tips);
showRefCheck.selectedProperty().addListener(new ChangeListener() {
@@ -221,7 +209,7 @@ public void changed(ObservableValue ov, Number oldValue, Number newValue) {
return;
}
if (getMessage("SettingsDot").equals(hisBox.getItems().get(index))) {
- BaseController c = openStage(CommonValues.SettingsFxml, true);
+ BaseController c = openStage(CommonValues.SettingsFxml, false);
c.setParentController(getMyController());
c.setParentFxml(getMyFxml());
return;
@@ -258,27 +246,19 @@ public void changed(ObservableValue ov, Number oldValue, Number newValue) {
tips.setFont(new Font(16));
FxmlTools.quickTooltip(undoButton, tips);
- tips = new Tooltip("CTRL+1");
- tips.setFont(new Font(16));
- FxmlTools.quickTooltip(oButton, tips);
-
- tips = new Tooltip("CTRL+2");
- tips.setFont(new Font(16));
- FxmlTools.quickTooltip(wButton, tips);
-
- tips = new Tooltip("CTRL+3");
+ tips = new Tooltip("CTRL+h");
tips.setFont(new Font(16));
- FxmlTools.quickTooltip(inButton, tips);
+ FxmlTools.quickTooltip(hisBox, tips);
- tips = new Tooltip("CTRL+4");
+ tips = new Tooltip("CTRL+f");
tips.setFont(new Font(16));
- FxmlTools.quickTooltip(outButton, tips);
+ FxmlTools.quickTooltip(refButton, tips);
- tips = new Tooltip("CTRL+h");
+ tips = new Tooltip("CTRL+p");
tips.setFont(new Font(16));
- FxmlTools.quickTooltip(hisBox, tips);
+ FxmlTools.quickTooltip(popButton, tips);
- if (showScopeCheck != null && scopeGroup != null) {
+ if (showScopeCheck != null && scopeListBox != null) {
tips = new Tooltip(getMessage("ShowScopeComments"));
tips.setFont(new Font(16));
FxmlTools.setComments(showScopeCheck, tips);
@@ -313,7 +293,6 @@ protected void initInterface() {
cropTab.setDisable(false);
colorTab.setDisable(false);
- convolutionTab.setDisable(false);
effectsTab.setDisable(false);
arcTab.setDisable(false);
shadowTab.setDisable(false);
@@ -374,6 +353,8 @@ public void changed(ObservableValue extends Number> observableValue,
isSettingValues = false;
+ imageData = values.getImageData();
+
} catch (Exception e) {
logger.debug(e.toString());
}
@@ -383,13 +364,17 @@ public void changed(ObservableValue extends Number> observableValue,
protected void initScopeBar() {
try {
- scopeGroup.selectedToggleProperty().addListener(new ChangeListener() {
+ List scopeList = Arrays.asList(getMessage("All"),
+ getMessage("Rectangle"), getMessage("Circle"), getMessage("Matting"), getMessage("ColorMatching"),
+ getMessage("RectangleColor"), getMessage("CircleColor"));
+ scopeListBox.getItems().addAll(scopeList);
+ scopeListBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener() {
@Override
- public void changed(ObservableValue extends Toggle> ov,
- Toggle old_toggle, Toggle new_toggle) {
+ public void changed(ObservableValue ov, Number oldValue, Number newValue) {
checkScopeType();
}
});
+ scopeListBox.getSelectionModel().select(0);
} catch (Exception e) {
logger.error(e.toString());
@@ -406,30 +391,30 @@ protected void checkScopeType() {
scope.clearColors();
scope.clearPoints();
- RadioButton selected = (RadioButton) scopeGroup.getSelectedToggle();
- if (AppVaribles.getMessage("All").equals(selected.getText())) {
+ String selected = scopeListBox.getSelectionModel().getSelectedItem();
+ if (AppVaribles.getMessage("All").equals(selected)) {
scope.setScopeType(ImageScope.ScopeType.All);
showScopeCheck.setDisable(true);
hideScopePane();
} else {
- if (AppVaribles.getMessage("Matting").equals(selected.getText())) {
+ if (AppVaribles.getMessage("Matting").equals(selected)) {
scope.setScopeType(ImageScope.ScopeType.Matting);
- } else if (getMessage("Rectangle").equals(selected.getText())) {
+ } else if (getMessage("Rectangle").equals(selected)) {
scope.setScopeType(ImageScope.ScopeType.Rectangle);
- } else if (getMessage("Circle").equals(selected.getText())) {
+ } else if (getMessage("Circle").equals(selected)) {
scope.setScopeType(ImageScope.ScopeType.Circle);
- } else if (getMessage("ColorMatching").equals(selected.getText())) {
+ } else if (getMessage("ColorMatching").equals(selected)) {
scope.setScopeType(ImageScope.ScopeType.Color);
- } else if (getMessage("RectangleColor").equals(selected.getText())) {
+ } else if (getMessage("RectangleColor").equals(selected)) {
scope.setScopeType(ImageScope.ScopeType.RectangleColor);
- } else if (getMessage("CircleColor").equals(selected.getText())) {
+ } else if (getMessage("CircleColor").equals(selected)) {
scope.setScopeType(ImageScope.ScopeType.CircleColor);
}
@@ -499,7 +484,7 @@ protected boolean checkDistanceValue() {
case Hue:
if (distance >= 0 && distance <= 360) {
scopeDistanceInput.setStyle(null);
- scope.setHueDistance(distance);
+ scope.setHsbDistance(distance / 360.0f);
} else {
scopeDistanceInput.setStyle(badStyle);
valid = false;
@@ -509,7 +494,7 @@ protected boolean checkDistanceValue() {
case Saturation:
if (distance >= 0 && distance <= 100) {
scopeDistanceInput.setStyle(null);
- scope.setColorDistance(distance / 100.0);
+ scope.setHsbDistance(distance / 100.0f);
} else {
scopeDistanceInput.setStyle(badStyle);
valid = false;
@@ -518,7 +503,7 @@ protected boolean checkDistanceValue() {
default:
if (distance >= 0 && distance <= 255) {
scopeDistanceInput.setStyle(null);
- scope.setColorDistance(distance / 255.0);
+ scope.setColorDistance(distance);
} else {
scopeDistanceInput.setStyle(badStyle);
valid = false;
@@ -710,7 +695,8 @@ protected Void call() throws Exception {
if (task.isCancelled()) {
return null;
}
- Image scopedImage = FxmlScopeTools.scopeImage(values.getCurrentImage(), scope);
+ PixelsOperation pixelsOperation = new PixelsOperation(values.getCurrentImage(), scope, OperationType.Scope);
+ final Image scopedImage = pixelsOperation.operateFxImage();
if (task.isCancelled()) {
return null;
}
@@ -759,7 +745,8 @@ protected Void call() throws Exception {
if (task.isCancelled()) {
return null;
}
- Image scopedImage = FxmlScopeTools.scopeImage(values.getCurrentImage(), scope);
+ PixelsOperation pixelsOperation = new PixelsOperation(values.getCurrentImage(), scope, OperationType.Scope);
+ final Image scopedImage = pixelsOperation.operateFxImage();
if (task.isCancelled()) {
return null;
}
@@ -798,7 +785,8 @@ protected void indicateMatting() {
@Override
protected Void call() throws Exception {
try {
- final Image scopeImage = FxmlScopeTools.scopeMatting(values.getCurrentImage(), scope);
+ PixelsOperation pixelsOperation = new PixelsOperation(values.getCurrentImage(), scope, OperationType.Scope);
+ final Image scopeImage = pixelsOperation.operateFxImage();
if (task.isCancelled()) {
return null;
}
@@ -831,7 +819,8 @@ protected void indicateColor() {
@Override
protected Void call() throws Exception {
try {
- final Image scopeImage = FxmlScopeTools.scopeImage(values.getCurrentImage(), scope);
+ PixelsOperation pixelsOperation = new PixelsOperation(values.getCurrentImage(), scope, OperationType.Scope);
+ final Image scopeImage = pixelsOperation.operateFxImage();
if (task.isCancelled()) {
return null;
}
@@ -856,6 +845,81 @@ public void run() {
thread.start();
}
+ @FXML
+ @Override
+ protected void selectSourceFile(ActionEvent event) {
+ if (values == null || values.getCurrentImage() != null && values.isImageChanged()) {
+ if (!checkSavingBeforeExit()) {
+ return;
+ }
+ }
+ super.selectSourceFile(event);
+ }
+
+ @Override
+ public void afterImageLoaded() {
+ try {
+ super.afterImageLoaded();
+
+ if (imageInformation != null && imageInformation.isIsSampled()) {
+ hotBar.setDisable(false);
+ showRefCheck.setDisable(true);
+ hisBox.setDisable(true);
+ undoButton.setDisable(true);
+ redoButton.setDisable(true);
+ recoverButton.setDisable(true);
+ saveButton.setDisable(true);
+
+ browseTab.setDisable(true);
+ viewTab.setDisable(true);
+ colorTab.setDisable(true);
+ effectsTab.setDisable(true);
+ sizeTab.setDisable(true);
+ refTab.setDisable(true);
+ transformTab.setDisable(true);
+ textTab.setDisable(true);
+ coverTab.setDisable(true);
+ arcTab.setDisable(true);
+ shadowTab.setDisable(true);
+ marginsTab.setDisable(true);
+ cropTab.setDisable(true);
+
+ }
+
+ isSettingValues = true;
+ values.setSourceFile(sourceFile);
+ values.setImage(image);
+ values.setImageInfo(imageInformation);
+ values.setCurrentImage(image);
+ isSettingValues = false;
+
+ if (image == null
+ || (imageInformation != null && imageInformation.isIsSampled())) {
+ return;
+ }
+
+ isSettingValues = true;
+ values.setRefImage(image);
+ values.setRefInfo(imageInformation);
+ setImageChanged(false);
+ values.setScope(new ImageScope(image));
+ scope = values.getScope();
+
+ recordImageHistory(ImageOperationType.Load, image);
+
+ imageData = values.getImageData();
+ if (initTab != null) {
+ switchTab(initTab);
+ } else {
+ initInterface();
+ }
+ isSettingValues = false;
+
+ } catch (Exception e) {
+ logger.debug(e.toString());
+ }
+ }
+
public void setImage(final File file) {
task = new Task() {
@Override
@@ -986,12 +1050,12 @@ protected void loadReferenceImage() {
values.setRefImage(image);
values.setRefInfo(values.getImageInfo());
refView.setImage(image);
- if (scrollPane.getHeight() < values.getImageInfo().getWidth()) {
+ if (scrollPane.getHeight() < (int) values.getImage().getWidth()) {
refView.setFitWidth(scrollPane.getWidth() - 1);
refView.setFitHeight(scrollPane.getHeight() - 5); // use attributes of scrollPane but not refPane
} else {
- refView.setFitWidth(values.getImageInfo().getWidth());
- refView.setFitHeight(values.getImageInfo().getHeight());
+ refView.setFitWidth((int) values.getImage().getWidth());
+ refView.setFitHeight((int) values.getImage().getHeight());
}
return;
}
@@ -1040,6 +1104,8 @@ protected void setImageChanged(boolean imageChanged) {
undoButton.setDisable(false);
redoButton.setDisable(true);
+ loadData();
+
} else {
saveButton.setDisable(true);
recoverButton.setDisable(true);
@@ -1140,7 +1206,7 @@ protected void recordImageHistory(final int updateType, final Image newImage) {
@Override
protected Void call() throws Exception {
try {
- final BufferedImage bufferedImage = FxmlImageTools.getBufferedImage(newImage);
+ final BufferedImage bufferedImage = ImageTools.getBufferedImage(newImage);
String filename = imageHistoriesPath + File.separator
+ FileTools.getFilePrefix(values.getSourceFile().getName())
+ "_" + (new Date().getTime()) + "_" + updateType
@@ -1197,42 +1263,11 @@ protected boolean loadImageHistory(final int index) {
protected void switchTab(Tab newTab) {
- String tabName = null;
- if (fileTab.equals(newTab)) {
- tabName = "file";
- } else if (sizeTab.equals(newTab)) {
- tabName = "size";
- } else if (cropTab.equals(newTab)) {
- tabName = "crop";
- } else if (convolutionTab.equals(newTab)) {
- tabName = "convolution";
- } else if (effectsTab.equals(newTab)) {
- tabName = "effects";
- } else if (colorTab.equals(newTab)) {
- tabName = "color";
- } else if (textTab.equals(newTab)) {
- tabName = "text";
- } else if (coverTab.equals(newTab)) {
- tabName = "cover";
- } else if (arcTab.equals(newTab)) {
- tabName = "arc";
- } else if (shadowTab.equals(newTab)) {
- tabName = "shadow";
- } else if (transformTab.equals(newTab)) {
- tabName = "transform";
- } else if (marginsTab.equals(newTab)) {
- tabName = "margins";
- } else if (viewTab.equals(newTab)) {
- tabName = "view";
- } else if (refTab.equals(newTab)) {
- tabName = "ref";
- } else if (browseTab.equals(newTab)) {
- tabName = "browse";
- }
+ String tabName = findTabName(newTab);
switchTab(tabName);
}
- protected void switchTab(String tabName) {
+ public void switchTab(String tabName) {
try {
isSwitchingTab = true;
String fxml = null;
@@ -1249,9 +1284,6 @@ protected void switchTab(String tabName) {
case "color":
fxml = CommonValues.ImageManufactureColorFxml;
break;
- case "convolution":
- fxml = CommonValues.ImageManufactureConvolutionFxml;
- break;
case "effects":
fxml = CommonValues.ImageManufactureEffectsFxml;
break;
@@ -1285,10 +1317,12 @@ protected void switchTab(String tabName) {
}
if (fxml != null) {
+// values.setCurrentImage(imageView.getImage());
values.setStageWidth(stageWidth);
values.setStageHeight(stageHeight);
values.setImageViewWidth((int) imageView.getFitWidth());
values.setImageViewHeight((int) imageView.getFitHeight());
+ values.setImageData(imageData);
ImageManufactureController controller
= (ImageManufactureController) reloadStage(fxml, AppVaribles.getMessage("ImageManufacture"));
controller.setValues(values);
@@ -1296,86 +1330,113 @@ protected void switchTab(String tabName) {
controller.xZoomStep = xZoomStep;
controller.yZoomStep = yZoomStep;
controller.initInterface();
+ controller.loadData(imageData);
}
+ isSwitchingTab = false;
} catch (Exception e) {
logger.error(e.toString());
}
}
- public void setTab(String tab) {
+ public void setTab(String tabName) {
try {
+ Tab tab = findTab(tabName);
if (tab == null) {
return;
}
isSettingValues = true;
- switch (tab) {
- case "file":
- tabPane.getSelectionModel().select(fileTab);
- break;
- case "size":
- tabPane.getSelectionModel().select(sizeTab);
- break;
- case "crop":
- tabPane.getSelectionModel().select(cropTab);
- break;
- case "color":
- tabPane.getSelectionModel().select(colorTab);
- break;
- case "convolution":
- tabPane.getSelectionModel().select(convolutionTab);
- break;
- case "effects":
- tabPane.getSelectionModel().select(effectsTab);
- break;
- case "text":
- tabPane.getSelectionModel().select(textTab);
- break;
- case "cover":
- tabPane.getSelectionModel().select(coverTab);
- break;
- case "arc":
- tabPane.getSelectionModel().select(arcTab);
- break;
- case "shadow":
- tabPane.getSelectionModel().select(shadowTab);
- break;
- case "transform":
- tabPane.getSelectionModel().select(transformTab);
- break;
- case "margins":
- tabPane.getSelectionModel().select(marginsTab);
- break;
- case "view":
- tabPane.getSelectionModel().select(viewTab);
- break;
- case "ref":
- tabPane.getSelectionModel().select(refTab);
- break;
- case "browse":
- tabPane.getSelectionModel().select(browseTab);
- break;
- }
+ tabPane.getSelectionModel().select(tab);
isSettingValues = false;
} catch (Exception e) {
logger.debug(e.toString());
}
}
+ protected String findTabName(Tab tab) {
+ String tabName = null;
+ if (fileTab.equals(tab)) {
+ tabName = "file";
+ } else if (sizeTab.equals(tab)) {
+ tabName = "size";
+ } else if (cropTab.equals(tab)) {
+ tabName = "crop";
+ } else if (effectsTab.equals(tab)) {
+ tabName = "effects";
+ } else if (colorTab.equals(tab)) {
+ tabName = "color";
+ } else if (textTab.equals(tab)) {
+ tabName = "text";
+ } else if (coverTab.equals(tab)) {
+ tabName = "cover";
+ } else if (arcTab.equals(tab)) {
+ tabName = "arc";
+ } else if (shadowTab.equals(tab)) {
+ tabName = "shadow";
+ } else if (transformTab.equals(tab)) {
+ tabName = "transform";
+ } else if (marginsTab.equals(tab)) {
+ tabName = "margins";
+ } else if (viewTab.equals(tab)) {
+ tabName = "view";
+ } else if (refTab.equals(tab)) {
+ tabName = "ref";
+ } else if (browseTab.equals(tab)) {
+ tabName = "browse";
+ }
+ return tabName;
+ }
+
+ public Tab findTab(String tabName) {
+ switch (tabName) {
+ case "file":
+ return fileTab;
+ case "size":
+ return sizeTab;
+ case "crop":
+ return cropTab;
+ case "color":
+ return colorTab;
+ case "effects":
+ return effectsTab;
+ case "text":
+ return textTab;
+ case "cover":
+ return coverTab;
+ case "arc":
+ return arcTab;
+ case "shadow":
+ return shadowTab;
+ case "transform":
+ return transformTab;
+ case "margins":
+ return marginsTab;
+ case "view":
+ return viewTab;
+ case "ref":
+ return refTab;
+ case "browse":
+ return browseTab;
+ }
+ return null;
+ }
+
// Hotbar Methods
@FXML
- public void save() {
+ @Override
+ public void saveAction() {
if (saveButton.isDisabled()) {
return;
}
if (values.getSourceFile() == null) {
- saveAs();
+ saveAsAction();
return;
}
if (values.isIsConfirmBeforeSave()) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(getMyStage().getTitle());
alert.setContentText(AppVaribles.getMessage("SureOverrideFile"));
+ alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
ButtonType buttonSave = new ButtonType(AppVaribles.getMessage("Save"));
ButtonType buttonSaveAs = new ButtonType(AppVaribles.getMessage("SaveAs"));
ButtonType buttonCancel = new ButtonType(AppVaribles.getMessage("Cancel"));
@@ -1385,7 +1446,7 @@ public void save() {
if (result.get() == buttonCancel) {
return;
} else if (result.get() == buttonSaveAs) {
- saveAs();
+ saveAsAction();
return;
}
@@ -1394,8 +1455,11 @@ public void save() {
task = new Task() {
@Override
protected Void call() throws Exception {
- String format = values.getImageInfo().getImageFormat();
- final BufferedImage bufferedImage = FxmlImageTools.getBufferedImage(values.getCurrentImage());
+ String format = "png";
+ if (values.getImageInfo() != null) {
+ format = values.getImageInfo().getImageFormat();
+ }
+ final BufferedImage bufferedImage = ImageTools.getBufferedImage(values.getCurrentImage());
if (task.isCancelled()) {
return null;
}
@@ -1425,12 +1489,13 @@ public void run() {
}
@FXML
- @Override
- public void saveAs() {
+ public void saveAsAction() {
try {
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(targetPathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(targetPathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
final File file = fileChooser.showSaveDialog(getMyStage());
if (file == null) {
@@ -1442,7 +1507,7 @@ public void saveAs() {
@Override
protected Void call() throws Exception {
String format = FileTools.getFileSuffix(file.getName());
- final BufferedImage bufferedImage = FxmlImageTools.getBufferedImage(values.getCurrentImage());
+ final BufferedImage bufferedImage = ImageTools.getBufferedImage(values.getCurrentImage());
if (task.isCancelled()) {
return null;
}
@@ -1549,7 +1614,7 @@ public void setBottomLabel() {
str = AppVaribles.getMessage("CurrentPixels") + ":" + (int) values.getCurrentImage().getWidth() + "x" + (int) values.getCurrentImage().getHeight();
} else {
str = AppVaribles.getMessage("Format") + ":" + values.getImageInfo().getImageFormat() + " "
- + AppVaribles.getMessage("Pixels") + ":" + values.getImageInfo().getWidth() + "x" + values.getImageInfo().getHeight() + " "
+ + AppVaribles.getMessage("Pixels") + ":" + (int) values.getImage().getWidth() + "x" + (int) values.getImage().getHeight() + " "
+ AppVaribles.getMessage("Size") + ":" + FileTools.showFileSize(values.getSourceFile().length()) + " "
+ AppVaribles.getMessage("ModifyTime") + ":" + DateTools.datetimeToString(values.getSourceFile().lastModified()) + " "
+ AppVaribles.getMessage("CurrentPixels") + ":" + (int) values.getCurrentImage().getWidth() + "x" + (int) values.getCurrentImage().getHeight();
@@ -1573,17 +1638,17 @@ public void clickImage(MouseEvent event) {
switch (scope.getScopeType()) {
case All:
- if (scope.getOperationType() == OperationType.ReplaceColor) {
+ if (isSettingColor) {
colorPicker.setValue(color);
}
break;
case Color:
- if (scope.getOperationType() == OperationType.ReplaceColor
+ if (isSettingColor
&& event.getButton() == MouseButton.SECONDARY) {
colorPicker.setValue(color);
} else {
- scope.addColor(color);
+ scope.addColor(ImageColor.converColor(color));
scopeColorsBox.getItems().add(color);
scopeColorsBox.getSelectionModel().select(scopeColorsBox.getItems().size() - 1);
scopeColorsBox.setVisibleRowCount(15);
@@ -1592,7 +1657,7 @@ public void clickImage(MouseEvent event) {
break;
case Matting:
- if (scope.getOperationType() == OperationType.ReplaceColor
+ if (isSettingColor
&& event.getButton() == MouseButton.SECONDARY) {
colorPicker.setValue(color);
} else {
@@ -1605,7 +1670,7 @@ public void clickImage(MouseEvent event) {
break;
case Rectangle:
- if (scope.getOperationType() == OperationType.ReplaceColor) {
+ if (isSettingColor) {
colorPicker.setValue(color);
} else {
if (event.getButton() == MouseButton.PRIMARY) {
@@ -1625,7 +1690,7 @@ public void clickImage(MouseEvent event) {
break;
case Circle:
- if (scope.getOperationType() == OperationType.ReplaceColor) {
+ if (isSettingColor) {
colorPicker.setValue(color);
} else {
if (event.getButton() == MouseButton.PRIMARY) {
@@ -1648,11 +1713,11 @@ public void clickImage(MouseEvent event) {
break;
case RectangleColor:
- if (scope.getOperationType() == OperationType.ReplaceColor
+ if (isSettingColor
&& event.getButton() == MouseButton.SECONDARY) {
colorPicker.setValue(color);
} else {
- scope.addColor(color);
+ scope.addColor(ImageColor.converColor(color));
scopeColorsBox.getItems().add(color);
scopeColorsBox.getSelectionModel().select(scopeColorsBox.getItems().size() - 1);
scopeColorsBox.setVisibleRowCount(15);
@@ -1662,11 +1727,11 @@ public void clickImage(MouseEvent event) {
break;
case CircleColor:
- if (scope.getOperationType() == OperationType.ReplaceColor
+ if (isSettingColor
&& event.getButton() == MouseButton.SECONDARY) {
colorPicker.setValue(color);
} else {
- scope.addColor(color);
+ scope.addColor(ImageColor.converColor(color));
scopeColorsBox.getItems().add(color);
scopeColorsBox.getSelectionModel().select(scopeColorsBox.getItems().size() - 1);
scopeColorsBox.setVisibleRowCount(15);
@@ -1696,7 +1761,7 @@ public void scopeViewClicked(MouseEvent event) {
switch (scope.getScopeType()) {
case Color:
- scope.addColor(color);
+ scope.addColor(ImageColor.converColor(color));
scopeColorsBox.getItems().add(color);
scopeColorsBox.getSelectionModel().select(scopeColorsBox.getItems().size() - 1);
scopeColorsBox.setVisibleRowCount(15);
@@ -1795,7 +1860,7 @@ public void recovery() {
setImageChanged(false);
undoButton.setDisable(false);
redoButton.setDisable(true);
-
+ loadData();
}
@FXML
@@ -1824,6 +1889,24 @@ public void redoAction() {
redoButton.setDisable(true);
}
+ @FXML
+ public void refAction() {
+ values.setRefImage(imageView.getImage());
+ values.setRefInfo(null);
+ if (!showRefCheck.isSelected()) {
+ showRefCheck.setSelected(true);
+ } else if (refView != null) {
+ refView.setImage(imageView.getImage());
+ }
+ }
+
+ @FXML
+ public void popAction() {
+ ImageViewerController controller
+ = (ImageViewerController) openStage(CommonValues.ImageViewerFxml, false);
+ controller.loadImage(sourceFile, imageView.getImage(), imageInformation, imageData);
+ }
+
@FXML
public void clearScope() {
scope.clearColors();
@@ -1859,18 +1942,12 @@ public void clearScope() {
@Override
protected void keyEventsHandler(KeyEvent event) {
super.keyEventsHandler(event);
- String key = event.getText();
- if (key == null || key.isEmpty()) {
- return;
- }
if (event.isControlDown()) {
+ String key = event.getText();
+ if (key == null || key.isEmpty()) {
+ return;
+ }
switch (key) {
- case "s":
- case "S":
- if (!saveButton.isDisabled()) {
- save();
- }
- break;
case "r":
case "R":
if (!recoverButton.isDisabled()) {
@@ -1895,29 +1972,19 @@ protected void keyEventsHandler(KeyEvent event) {
hisBox.show();
}
break;
- case "1":
- if (!wButton.isDisabled()) {
- paneSize();
- }
- break;
- case "2":
- if (!oButton.isDisabled()) {
- imageSize();
+ case "x":
+ if (!scopeClearButton.isDisabled()) {
+ clearScope();
}
break;
- case "3":
- if (!inButton.isDisabled()) {
- zoomIn();
+ case "f":
+ if (!refButton.isDisabled()) {
+ refAction();
}
break;
- case "4":
- if (!outButton.isDisabled()) {
- zoomOut();
- }
- break;
- case "x":
- if (!scopeClearButton.isDisabled()) {
- clearScope();
+ case "p":
+ if (!popButton.isDisabled()) {
+ popAction();
}
break;
default:
@@ -2481,7 +2548,7 @@ public void handle(ActionEvent event) {
protected void showLabels() {
try {
- if (values == null || scope == null || scope.getOperationType() == null) {
+ if (values == null || scope == null) {
return;
}
@@ -2490,7 +2557,7 @@ protected void showLabels() {
switch (scope.getScopeType()) {
case All:
- if (scope.getOperationType() == OperationType.ReplaceColor) {
+ if (isSettingColor) {
imageLabel.setText(getMessage("ClickCurrentForNewColor"));
} else {
imageLabelBox.setAlignment(Pos.CENTER);
@@ -2500,7 +2567,7 @@ protected void showLabels() {
promptLabel.setText("");
break;
case Matting:
- if (scope.getOperationType() == OperationType.ReplaceColor) {
+ if (isSettingColor) {
promptLabel.setText(getMessage("MattingComments2"));
imageLabel.setText(getMessage("ClickCurrentForColors"));
} else {
@@ -2510,7 +2577,7 @@ protected void showLabels() {
break;
case Rectangle:
- if (scope.getOperationType() == OperationType.ReplaceColor) {
+ if (isSettingColor) {
promptLabel.setText(getMessage("RectangleLabel"));
imageLabel.setText(getMessage("ClickCurrentForNewColor"));
} else {
@@ -2520,7 +2587,7 @@ protected void showLabels() {
break;
case Circle:
- if (scope.getOperationType() == OperationType.ReplaceColor) {
+ if (isSettingColor) {
promptLabel.setText(getMessage("CircleLabel"));
imageLabel.setText(getMessage("ClickCurrentForNewColor"));
} else {
@@ -2530,7 +2597,7 @@ protected void showLabels() {
break;
case Color:
- if (scope.getOperationType() == OperationType.ReplaceColor) {
+ if (isSettingColor) {
promptLabel.setText(getMessage("ClickScopeForColorMatch"));
imageLabel.setText(getMessage("ClickCurrentForColors"));
} else {
@@ -2540,7 +2607,7 @@ protected void showLabels() {
break;
case RectangleColor:
- if (scope.getOperationType() == OperationType.ReplaceColor) {
+ if (isSettingColor) {
promptLabel.setText("");
imageLabel.setText(getMessage("ClickScopeForRectangle"));
scopePromptLabel.setText(getMessage("ClickCurrentForColors"));
@@ -2552,7 +2619,7 @@ protected void showLabels() {
break;
case CircleColor:
- if (scope.getOperationType() == OperationType.ReplaceColor) {
+ if (isSettingColor) {
promptLabel.setText("");
imageLabel.setText(getMessage("ClickScopeForCircle"));
scopePromptLabel.setText(getMessage("ClickCurrentForColors"));
@@ -2588,25 +2655,6 @@ protected void hideScopePane() {
}
}
- protected void adjustSplitPane() {
- switch (splitPane.getItems().size()) {
- case 3:
- splitPane.getDividers().get(0).setPosition(0.33333);
- splitPane.getDividers().get(1).setPosition(0.66666);
-// splitPane.setDividerPositions(0.33, 0.33, 0.33); // This way not work!
- break;
- case 2:
- splitPane.getDividers().get(0).setPosition(0.5);
-// splitPane.setDividerPositions(0.5, 0.5); // This way not work!
- break;
- default:
- splitPane.setDividerPositions(1);
- break;
- }
- splitPane.layout();
- fitSize();
- }
-
@Override
public boolean stageReloading() {
if (isSwitchingTab) {
@@ -2628,6 +2676,7 @@ public boolean checkSavingBeforeExit() {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(getMyStage().getTitle());
alert.setContentText(AppVaribles.getMessage("ImageChanged"));
+ alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
ButtonType buttonSave = new ButtonType(AppVaribles.getMessage("Save"));
ButtonType buttonSaveAs = new ButtonType(AppVaribles.getMessage("SaveAs"));
ButtonType buttonNotSave = new ButtonType(AppVaribles.getMessage("NotSave"));
@@ -2636,12 +2685,12 @@ public boolean checkSavingBeforeExit() {
Optional result = alert.showAndWait();
if (result.get() == buttonSave) {
- save();
+ saveAction();
return true;
} else if (result.get() == buttonNotSave) {
return true;
} else if (result.get() == buttonSaveAs) {
- saveAs();
+ saveAsAction();
return true;
} else {
return false;
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureConvolutionController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureConvolutionController.java
deleted file mode 100644
index 7c5c3bc60..000000000
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureConvolutionController.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package mara.mybox.controller;
-
-import java.util.ArrayList;
-import java.util.List;
-import javafx.application.Platform;
-import javafx.beans.value.ChangeListener;
-import javafx.beans.value.ObservableValue;
-import javafx.concurrent.Task;
-import javafx.event.ActionEvent;
-import javafx.fxml.FXML;
-import javafx.scene.control.ComboBox;
-import javafx.scene.control.Label;
-import javafx.scene.control.Tooltip;
-import javafx.scene.image.Image;
-import javafx.scene.input.KeyEvent;
-import javafx.scene.text.Font;
-import javafx.stage.Modality;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.db.TableConvolutionKernel;
-import mara.mybox.fxml.FxmlEffectTools;
-import mara.mybox.fxml.FxmlTools;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.ConvolutionKernel;
-import mara.mybox.objects.ImageScope;
-
-/**
- * FXML Controller class
- *
- * @author mara
- */
-public class ImageManufactureConvolutionController extends ImageManufactureController {
-
- private List kernels;
- private ConvolutionKernel currentKernel;
-
- @FXML
- private Label kernelLabel;
- @FXML
- private ComboBox kernelBox;
-
- @Override
- protected void initializeNext2() {
- try {
- initCommon();
- initConvolutionTab();
- } catch (Exception e) {
- logger.error(e.toString());
- }
- }
-
- protected void initConvolutionTab() {
- try {
-
- Tooltip tips = new Tooltip(getMessage("CTRL+k"));
- tips.setFont(new Font(16));
- FxmlTools.quickTooltip(kernelBox, tips);
-
- kernelBox.setVisibleRowCount(15);
- kernels = TableConvolutionKernel.read();
- loadList(kernels);
- kernelBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener() {
- @Override
- public void changed(ObservableValue ov, Number oldValue, Number newValue) {
- if (isSettingValues) {
- return;
- }
- int index = newValue.intValue();
- if (index < 0 || index >= kernels.size()) {
- return;
- }
- currentKernel = kernels.get(index);
- applyKernel();
- }
- });
-
- } catch (Exception e) {
- logger.error(e.toString());
- }
- }
-
- @Override
- protected void initInterface() {
- try {
- if (values == null || values.getImage() == null) {
- return;
- }
- super.initInterface();
- values.getScope().setOperationType(ImageScope.OperationType.Convolution);
-
- isSettingValues = true;
-
- isSettingValues = false;
- } catch (Exception e) {
- logger.debug(e.toString());
- }
-
- }
-
- public void loadList(List records) {
- isSettingValues = true;
- kernels = records;
- kernelBox.getItems().clear();
- if (records == null) {
- return;
- }
- List names = new ArrayList<>();
- for (ConvolutionKernel k : kernels) {
- names.add(k.getName());
- }
- kernelBox.getItems().addAll(names);
- isSettingValues = false;
- }
-
- public void selectKernel(ConvolutionKernel kernel) {
- if (kernelBox.getItems().contains(kernel.getName())) {
- kernelBox.getSelectionModel().select(kernel.getName());
- } else {
- applyKernel(kernel);
- }
- }
-
- @FXML
- private void manageKernels(ActionEvent event) {
- BaseController c = openStage(CommonValues.ConvolutionKernelManagerFxml, true);
- c.setParentController(getMyController());
- c.setParentFxml(getMyFxml());
- }
-
- @Override
- protected void keyEventsHandler(KeyEvent event) {
- super.keyEventsHandler(event);
- String key = event.getText();
- if (key == null || key.isEmpty()) {
- return;
- }
- if (event.isControlDown()) {
- switch (key) {
- case "k":
- case "K":
- kernelBox.show();
- break;
- }
- }
- }
-
- public void applyKernel(ConvolutionKernel inKernel) {
- currentKernel = inKernel;
- applyKernel();
- }
-
- private void applyKernel() {
- if (isSettingValues || currentKernel == null) {
- return;
- }
- task = new Task() {
- @Override
- protected Void call() throws Exception {
- try {
- final Image newImage;
- if (scope == null || scope.getScopeType() == ImageScope.ScopeType.All) {
- newImage = FxmlEffectTools.applyConvolution(values.getCurrentImage(), currentKernel);
- } else if (scope.getScopeType() == ImageScope.ScopeType.Matting) {
- newImage = FxmlEffectTools.applyConvolutionByMatting(values.getCurrentImage(), currentKernel, scope);
- } else {
- newImage = FxmlEffectTools.applyConvolutionByScope(values.getCurrentImage(), currentKernel, scope);
- }
- if (task.isCancelled()) {
- return null;
- }
-
- recordImageHistory(ImageOperationType.Convolution, newImage);
- Platform.runLater(new Runnable() {
- @Override
- public void run() {
- values.setUndoImage(values.getCurrentImage());
- values.setCurrentImage(newImage);
- imageView.setImage(newImage);
- setImageChanged(true);
- }
- });
- } catch (Exception e) {
- logger.debug(e.toString());
- }
- return null;
- }
- };
- openHandlingStage(task, Modality.WINDOW_MODAL);
- Thread thread = new Thread(task);
- thread.setDaemon(true);
- thread.start();
- }
-
-}
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureCoverController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureCoverController.java
index db8e231fb..ab0e7087e 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureCoverController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureCoverController.java
@@ -34,11 +34,10 @@
import javafx.stage.Modality;
import javafx.util.Callback;
import javax.imageio.ImageIO;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.fxml.FxmlCoverTools;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.fxml.image.FxmlCoverTools;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
import static mara.mybox.fxml.FxmlTools.badStyle;
/**
@@ -394,7 +393,7 @@ private void checkShape() {
}
if (leftY >= rightY) {
- leftYInput.setStyle(badStyle);
+ rightYInput.setStyle(badStyle);
}
}
@@ -481,8 +480,10 @@ public void clickImage(MouseEvent event) {
private void selectPicture(ActionEvent event) {
try {
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(sourcePathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(sourcePathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
final File file = fileChooser.showOpenDialog(getMyStage());
if (file == null) {
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureCropController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureCropController.java
index a7c901354..975cec3d5 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureCropController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureCropController.java
@@ -7,23 +7,19 @@
import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.scene.Cursor;
-import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.control.ToolBar;
-import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
-import javafx.scene.text.Font;
import javafx.stage.Modality;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.fxml.FxmlImageTools;
-import mara.mybox.fxml.FxmlScopeTools;
-import mara.mybox.fxml.FxmlTools;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.fxml.image.ImageTools;
+import mara.mybox.fxml.image.FxmlScopeTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.IntRectangle;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.data.IntRectangle;
/**
* @Author Mara
@@ -35,8 +31,7 @@ public class ImageManufactureCropController extends ImageManufactureController {
@FXML
protected TextField cropLeftXInput, cropLeftYInput, cropRightXInput, cropRightYInput;
- @FXML
- protected Button cropOkButton;
+
@FXML
protected ToolBar cropBar;
@@ -62,10 +57,10 @@ protected void initInterface() {
super.initInterface();
isSettingValues = true;
- cropRightXInput.setText(values.getImageInfo().getWidth() * 3 / 4 + "");
- cropRightYInput.setText(values.getImageInfo().getHeight() * 3 / 4 + "");
- cropLeftXInput.setText(values.getImageInfo().getWidth() / 4 + "");
- cropLeftYInput.setText(values.getImageInfo().getHeight() / 4 + "");
+ cropRightXInput.setText((int) values.getImage().getWidth() * 3 / 4 + "");
+ cropRightYInput.setText((int) values.getImage().getHeight() * 3 / 4 + "");
+ cropLeftXInput.setText((int) values.getImage().getWidth() / 4 + "");
+ cropLeftYInput.setText((int) values.getImage().getHeight() / 4 + "");
isSettingValues = false;
checkCropValues();
@@ -78,9 +73,6 @@ protected void initInterface() {
protected void initCropTab() {
try {
- Tooltip tips = new Tooltip(getMessage("CropComments"));
- tips.setFont(new Font(16));
- FxmlTools.setComments(cropBar, tips);
cropLeftXInput.textProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends String> observable,
@@ -110,7 +102,7 @@ public void changed(ObservableValue extends String> observable,
}
});
- cropOkButton.disableProperty().bind(
+ okButton.disableProperty().bind(
cropLeftXInput.styleProperty().isEqualTo(badStyle)
.or(cropLeftYInput.styleProperty().isEqualTo(badStyle))
.or(cropRightXInput.styleProperty().isEqualTo(badStyle))
@@ -133,7 +125,7 @@ protected void checkCropValues() {
boolean areaValid = true;
try {
cropLeftX = Integer.valueOf(cropLeftXInput.getText());
- if (cropLeftX >= 0 && cropLeftX <= values.getCurrentImage().getWidth()) {
+ if (cropLeftX >= 0 && cropLeftX < values.getCurrentImage().getWidth()) {
cropLeftXInput.setStyle(null);
} else {
cropLeftXInput.setStyle(badStyle);
@@ -146,7 +138,7 @@ protected void checkCropValues() {
try {
cropLeftY = Integer.valueOf(cropLeftYInput.getText());
- if (cropLeftY >= 0 && cropLeftY <= values.getCurrentImage().getHeight()) {
+ if (cropLeftY >= 0 && cropLeftY < values.getCurrentImage().getHeight()) {
cropLeftYInput.setStyle(null);
} else {
cropLeftYInput.setStyle(badStyle);
@@ -159,7 +151,7 @@ protected void checkCropValues() {
try {
cropRightX = Integer.valueOf(cropRightXInput.getText());
- if (cropRightX >= 0 && cropRightX <= values.getCurrentImage().getWidth()) {
+ if (cropRightX >= 0 && cropRightX < values.getCurrentImage().getWidth()) {
cropRightXInput.setStyle(null);
} else {
cropRightXInput.setStyle(badStyle);
@@ -172,7 +164,7 @@ protected void checkCropValues() {
try {
cropRightY = Integer.valueOf(cropRightYInput.getText());
- if (cropRightY >= 0 && cropRightY <= values.getCurrentImage().getHeight()) {
+ if (cropRightY >= 0 && cropRightY < values.getCurrentImage().getHeight()) {
cropRightYInput.setStyle(null);
} else {
cropRightYInput.setStyle(badStyle);
@@ -220,7 +212,7 @@ protected Void call() throws Exception {
@Override
public void run() {
imageView.setImage(newImage);
-// popInformation(AppVaribles.getMessage("CropComments"));
+// infoAction(AppVaribles.getMessage("CropComments"));
}
});
} catch (Exception e) {
@@ -237,8 +229,20 @@ public void run() {
@FXML
@Override
- public void copySelectionAction() {
- copySelectionAction(values.getCurrentImage());
+ public void selectAllAction() {
+ isSettingValues = true;
+ cropLeftXInput.setText("0");
+ cropLeftYInput.setText("0");
+ cropRightXInput.setText((int) (values.getCurrentImage().getWidth() - 1) + "");
+ cropRightYInput.setText((int) (values.getCurrentImage().getHeight() - 1) + "");
+ isSettingValues = false;
+ checkCropValues();
+ }
+
+ @FXML
+ @Override
+ public void copyAction() {
+ copyAction(values.getCurrentImage());
}
@FXML
@@ -274,13 +278,14 @@ public void clickImage(MouseEvent event) {
}
@FXML
- public void cropAction() {
+ @Override
+ public void okAction() {
imageView.setCursor(Cursor.OPEN_HAND);
task = new Task() {
@Override
protected Void call() throws Exception {
try {
- final Image newImage = FxmlImageTools.cropImage(values.getCurrentImage(),
+ final Image newImage = ImageTools.cropImage(values.getCurrentImage(),
cropLeftX, cropLeftY, cropRightX, cropRightY);
if (task.isCancelled()) {
return null;
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureEffectsController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureEffectsController.java
index ab88da4c9..e1d5412e9 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureEffectsController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureEffectsController.java
@@ -1,10 +1,14 @@
package mara.mybox.controller;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Task;
+import javafx.event.ActionEvent;
+import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
@@ -18,18 +22,24 @@
import javafx.scene.image.Image;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.HBox;
-import javafx.scene.text.Font;
import javafx.stage.Modality;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.fxml.FxmlEffectTools;
-import mara.mybox.fxml.FxmlEffectTools.EffectsOperationType;
-import mara.mybox.image.ImageConvertTools.Direction;
-import static mara.mybox.objects.AppVaribles.getMessage;
+import mara.mybox.db.TableConvolutionKernel;
import mara.mybox.fxml.FxmlTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.image.ImageGrayTools;
-import mara.mybox.objects.ConvolutionKernel;
-import mara.mybox.objects.ImageScope;
+import static mara.mybox.value.AppVaribles.logger;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.fxml.image.ImageConvolution;
+import mara.mybox.fxml.image.PixelsOperation;
+import mara.mybox.fxml.image.ImageBinary;
+import mara.mybox.fxml.image.ImageContrast;
+import mara.mybox.fxml.image.ImageGray;
+import mara.mybox.fxml.image.ImageQuantization;
+import mara.mybox.image.ImageContrast.ContrastAlgorithm;
+import mara.mybox.image.ImageConvert.Direction;
+import mara.mybox.image.ImageQuantization.QuantizationAlgorithm;
+import mara.mybox.data.ConvolutionKernel;
+import mara.mybox.image.PixelsOperation.OperationType;
+import mara.mybox.value.CommonValues;
/**
* @Author Mara
@@ -39,26 +49,27 @@
*/
public class ImageManufactureEffectsController extends ImageManufactureController {
- private EffectsOperationType effectType;
- protected int intValue, direction;
- protected int threadholding, threadholdingSmall, threadholdingBig;
+ private OperationType effectType;
+ protected int intPara1, intPara2, intPara3;
+ private List kernels;
+ private ConvolutionKernel kernel;
+ private ComboBox intBox, stringBox;
+ private Label intLabel, intLabel2, intLabel3, intLabel4, stringLabel;
+ private CheckBox valueCheck;
+ private TextField intInput, intInput2, intInput3, intInput4;
+ private RadioButton radio1, radio2, radio3, radio4;
+ private ToggleGroup radioGroup;
+ private Button setButton;
+ private QuantizationAlgorithm quantizationAlgorithm;
+ private ContrastAlgorithm contrastAlgorithm;
@FXML
protected ToggleGroup effectsGroup;
@FXML
- protected ComboBox intBox, stringBox;
+ protected HBox setBox;
@FXML
- protected TextField thresholdingInput, thresholdingMinInput, thresholdingMaxInput;
- @FXML
- protected RadioButton thresholdingRadio;
- @FXML
- protected Button okButton, calculateButton;
- @FXML
- protected HBox thresholdingBox1, thresholdingBox2;
- @FXML
- protected Label intLabel, stringLabel, smallLabel, bigLabel, thresholdLabel;
- @FXML
- protected CheckBox grayCheck;
+ protected RadioButton thresholdingRadio, posterizingRadio, bwRadio,
+ convolutionRadio, contrastRadio;
public ImageManufactureEffectsController() {
}
@@ -84,45 +95,162 @@ public void changed(ObservableValue extends Toggle> ov,
});
checkEffetcsOperationType();
+ FxmlTools.setComments(thresholdingRadio, new Tooltip(getMessage("ThresholdingComments")));
+ FxmlTools.setComments(posterizingRadio, new Tooltip(getMessage("QuantizationComments")));
+ FxmlTools.setComments(bwRadio, new Tooltip(getMessage("BWThresholdComments")));
+
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
+ }
+
+ @Override
+ protected void initInterface() {
+ try {
+ if (values == null || values.getImage() == null) {
+ return;
+ }
+ super.initInterface();
+
+ isSettingValues = true;
+
+ isSettingValues = false;
+ } catch (Exception e) {
+ logger.debug(e.toString());
+ }
+
+ }
+
+ private void removeTmpControls() {
+ intBox = null;
+ valueCheck = null;
+ intInput = intInput2 = intInput3 = intInput4 = null;
+ intLabel = intLabel2 = intLabel3 = intLabel4 = stringLabel = null;
+ radio1 = radio2 = radio3 = radio4 = null;
+ setButton = null;
+ scopeListBox.setDisable(false);
+ }
+
+ private void checkEffetcsOperationType() {
+ try {
+ setBox.getChildren().clear();
+ okButton.disableProperty().unbind();
+ removeTmpControls();
+ stringBox = null;
+ radioGroup = null;
+
+ RadioButton selected = (RadioButton) effectsGroup.getSelectedToggle();
+ String selectedString = selected.getText();
+ if (getMessage("Blur").equals(selectedString)) {
+ effectType = OperationType.Blur;
+ makeBlurBox();
+
+ } else if (getMessage("Sharpen").equals(selectedString)) {
+ effectType = OperationType.Sharpen;
+
+ } else if (getMessage("Clarity").equals(selectedString)) {
+ effectType = OperationType.Clarity;
+
+ } else if (getMessage("EdgeDetection").equals(selectedString)) {
+ effectType = OperationType.EdgeDetect;
+
+ } else if (getMessage("Emboss").equals(selectedString)) {
+ effectType = OperationType.Emboss;
+ makeEmbossBox();
+
+ } else if (getMessage("Posterizing").equals(selectedString)) {
+ effectType = OperationType.Quantization;
+ makePosterizingBox();
+
+ } else if (getMessage("Thresholding").equals(selectedString)) {
+ effectType = OperationType.Thresholding;
+ makeThresholdingBox();
+
+ } else if (getMessage("Gray").equals(selectedString)) {
+ effectType = OperationType.Gray;
+
+ } else if (getMessage("BlackOrWhite").equals(selectedString)) {
+ effectType = OperationType.BlackOrWhite;
+ makeBlackWhiteBox();
+
+ } else if (getMessage("Sepia").equals(selectedString)) {
+ effectType = OperationType.Sepia;
+ makeSepiaBox();
+
+ } else if (getMessage("Contrast").equals(selectedString)) {
+ effectType = OperationType.Contrast;
+ makeContrastBox();
+
+ } else if (getMessage("Convolution").equals(selectedString)) {
+ effectType = OperationType.Convolution;
+ makeConvolutionBox();
+
+ }
+
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
+ }
+
+ private void makeBlurBox() {
+ try {
+ intPara1 = 10;
+ intLabel = new Label(getMessage("Radius"));
+ intBox = new ComboBox();
+ intBox.setEditable(true);
+ intBox.setPrefWidth(80);
intBox.valueProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue ov, String oldValue, String newValue) {
- int defaultValue = 0;
- if (null != effectType) {
- switch (effectType) {
- case Blur:
- defaultValue = 1;
- break;
- case Posterizing:
- defaultValue = 32;
- break;
- case Emboss:
- defaultValue = 3;
- break;
- default:
- break;
- }
- }
try {
- String v = newValue;
- int pos = v.indexOf(" ");
- if (pos > 0) {
- v = v.substring(0, pos);
- }
- intValue = Integer.valueOf(v);
- if (intValue > 0) {
+ int v = Integer.valueOf(newValue);
+ if (v > 0) {
+ intPara1 = v;
intBox.getEditor().setStyle(null);
} else {
- intValue = defaultValue;
intBox.getEditor().setStyle(badStyle);
}
} catch (Exception e) {
- intValue = defaultValue;
intBox.getEditor().setStyle(badStyle);
}
}
});
+ intBox.getItems().addAll(Arrays.asList("10", "5", "3", "2", "1", "8", "15", "20", "30"));
+ intBox.getSelectionModel().select(0);
+ stringLabel = new Label(getMessage("Algorithm"));
+ stringBox = new ComboBox();
+ stringBox.valueProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue ov, String oldValue, String newValue) {
+ try {
+ if (getMessage("AverageBlur").equals(newValue)) {
+ kernel = ConvolutionKernel.makeAverageBlur(intPara1);
+ } else {
+ kernel = ConvolutionKernel.makeGaussKernel(intPara1);
+ }
+ stringBox.getEditor().setStyle(null);
+ } catch (Exception e) {
+ stringBox.getEditor().setStyle(badStyle);
+ }
+ }
+ });
+ stringBox.getItems().addAll(Arrays.asList(getMessage("AverageBlur"), getMessage("GaussianBlur")));
+ stringBox.getSelectionModel().select(getMessage("AverageBlur"));
+ setBox.getChildren().addAll(stringLabel, stringBox, intLabel, intBox);
+ okButton.disableProperty().bind(
+ intBox.getEditor().styleProperty().isEqualTo(badStyle)
+ .or(stringBox.getEditor().styleProperty().isEqualTo(badStyle))
+ );
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
+ }
+ private void makeEmbossBox() {
+ try {
+ intPara1 = Direction.Top;
+ stringLabel = new Label(getMessage("Direction"));
+ stringBox = new ComboBox();
stringBox.valueProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue ov, String oldValue, String newValue) {
@@ -130,342 +258,655 @@ public void changed(ObservableValue ov, String oldValue, String newValue) {
return;
}
if (getMessage("Top").equals(newValue)) {
- direction = Direction.Top;
+ intPara1 = Direction.Top;
} else if (getMessage("Bottom").equals(newValue)) {
- direction = Direction.Bottom;
+ intPara1 = Direction.Bottom;
} else if (getMessage("Left").equals(newValue)) {
- direction = Direction.Top;
+ intPara1 = Direction.Top;
} else if (getMessage("Right").equals(newValue)) {
- direction = Direction.Right;
+ intPara1 = Direction.Right;
} else if (getMessage("LeftTop").equals(newValue)) {
- direction = Direction.LeftTop;
+ intPara1 = Direction.LeftTop;
} else if (getMessage("RightBottom").equals(newValue)) {
- direction = Direction.RightBottom;
+ intPara1 = Direction.RightBottom;
} else if (getMessage("LeftBottom").equals(newValue)) {
- direction = Direction.LeftBottom;
+ intPara1 = Direction.LeftBottom;
} else if (getMessage("RightTop").equals(newValue)) {
- direction = Direction.RightTop;
+ intPara1 = Direction.RightTop;
} else {
- direction = Direction.Top;
+ intPara1 = Direction.Top;
}
}
});
+ stringBox.getItems().addAll(Arrays.asList(getMessage("Top"), getMessage("Bottom"),
+ getMessage("Left"), getMessage("Right"),
+ getMessage("LeftTop"), getMessage("RightBottom"),
+ getMessage("LeftBottom"), getMessage("RightTop")));
+ stringBox.getSelectionModel().select(getMessage("Top"));
+ intPara2 = 3;
+ intLabel = new Label(getMessage("Radius"));
+ intBox = new ComboBox();
+ intBox.setEditable(false);
+ intBox.setPrefWidth(80);
+ intBox.valueProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue ov, String oldValue, String newValue) {
+ try {
+ int v = Integer.valueOf(newValue);
+ if (v > 0) {
+ intPara2 = v;
+ intBox.getEditor().setStyle(null);
+ } else {
+ intBox.getEditor().setStyle(badStyle);
+ }
+ } catch (Exception e) {
+ intBox.getEditor().setStyle(badStyle);
+ }
+ }
+ });
+ intBox.getItems().addAll(Arrays.asList("3", "5"));
+ intBox.getSelectionModel().select(0);
+ valueCheck = new CheckBox(getMessage("Gray"));
+ valueCheck.setSelected(true);
+ setBox.getChildren().addAll(stringLabel, stringBox, intLabel, intBox, valueCheck);
+ okButton.disableProperty().bind(
+ intBox.getEditor().styleProperty().isEqualTo(badStyle)
+ .or(stringBox.getEditor().styleProperty().isEqualTo(badStyle))
+ );
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
+ }
- Tooltip tips = new Tooltip("0~255");
- tips.setFont(new Font(16));
- FxmlTools.quickTooltip(thresholdingMinInput, tips);
- FxmlTools.quickTooltip(thresholdingMaxInput, tips);
-
- tips = new Tooltip(getMessage("CTRL+a"));
- tips.setFont(new Font(16));
- FxmlTools.quickTooltip(okButton, tips);
+ private void makePosterizingBox() {
+ try {
+ quantizationAlgorithm = QuantizationAlgorithm.RGB_Uniform;
+ stringLabel = new Label(getMessage("Algorithm"));
+ stringBox = new ComboBox();
+ stringBox.valueProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue ov, String oldValue, String newValue) {
+ if (getMessage("RGBUniformQuantization").equals(newValue)) {
+ quantizationAlgorithm = QuantizationAlgorithm.RGB_Uniform;
+ } else if (getMessage("HSBUniformQuantization").equals(newValue)) {
+ quantizationAlgorithm = QuantizationAlgorithm.HSB_Uniform;
+ }
+ }
+ });
+ stringBox.getItems().addAll(Arrays.asList(getMessage("RGBUniformQuantization"),
+ getMessage("HSBUniformQuantization")));
+ stringBox.getSelectionModel().select(getMessage("RGBUniformQuantization"));
+ intPara1 = 64;
+ intLabel = new Label(getMessage("ColorsNumber"));
+ intBox = new ComboBox();
+ intBox.setEditable(false);
+ intBox.setPrefWidth(120);
+ intBox.valueProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue ov, String oldValue, String newValue) {
+ try {
+ int v = Integer.valueOf(newValue);
+ if (v > 0) {
+ intPara1 = v;
+ intBox.getEditor().setStyle(null);
+ } else {
+ intBox.getEditor().setStyle(badStyle);
+ }
+ } catch (Exception e) {
+ intBox.getEditor().setStyle(badStyle);
+ }
+ }
+ });
+ intBox.getItems().addAll(Arrays.asList(
+ "64", "512", "8", "4096", "216", "343", "27", "125", "1000", "729", "1728", "8000"));
+ intBox.getSelectionModel().select(0);
+ valueCheck = new CheckBox(getMessage("Dithering"));
+ valueCheck.setSelected(true);
+ FxmlTools.setComments(valueCheck, new Tooltip(getMessage("DitherComments")));
+ setBox.getChildren().addAll(stringLabel, stringBox, intLabel, intBox, valueCheck);
+ okButton.disableProperty().bind(
+ intBox.getEditor().styleProperty().isEqualTo(badStyle)
+ .or(stringBox.getEditor().styleProperty().isEqualTo(badStyle))
+ );
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
- tips = new Tooltip(getMessage("ThresholdingComments"));
- tips.setFont(new Font(16));
- FxmlTools.setComments(thresholdingRadio, tips);
+ }
- thresholdingInput.textProperty().addListener(new ChangeListener() {
+ private void makeThresholdingBox() {
+ try {
+ intPara1 = 128;
+ intLabel = new Label(getMessage("Threshold"));
+ intInput = new TextField();
+ intInput.textProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends String> observable,
String oldValue, String newValue) {
- if (null != effectType) {
- switch (effectType) {
- case Thresholding:
- checkThresholding();
- break;
- case BlackOrWhite:
- checkThresholdForBW();
- break;
- case Sepia:
- checkDensityForSepia();
- break;
- default:
- break;
+ try {
+ int v = Integer.valueOf(newValue);
+ if (v >= 0 && v <= 255) {
+ intPara1 = v;
+ intInput.setStyle(null);
+ } else {
+ popError("0~255");
+ intInput.setStyle(badStyle);
}
+ } catch (Exception e) {
+ popError("0~255");
+ intInput.setStyle(badStyle);
}
}
});
- thresholdingInput.setText("128");
+ intInput.setPrefWidth(100);
+ intInput.setText("128");
+ FxmlTools.quickTooltip(intInput, new Tooltip("0~255"));
- thresholdingMinInput.textProperty().addListener(new ChangeListener() {
+ intPara2 = 0;
+ intLabel2 = new Label(getMessage("SmallValue"));
+ intInput2 = new TextField();
+ intInput2.textProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends String> observable,
String oldValue, String newValue) {
- checkThresholding();
+ try {
+ int v = Integer.valueOf(newValue);
+ if (v >= 0 && v <= 255) {
+ intPara2 = v;
+ intInput2.setStyle(null);
+ } else {
+ popError("0~255");
+ intInput2.setStyle(badStyle);
+ }
+ } catch (Exception e) {
+ popError("0~255");
+ intInput2.setStyle(badStyle);
+ }
}
});
- thresholdingMinInput.setText("0");
+ intInput2.setPrefWidth(100);
+ intInput2.setText("0");
+ FxmlTools.quickTooltip(intInput2, new Tooltip("0~255"));
- thresholdingMaxInput.textProperty().addListener(new ChangeListener() {
+ intPara3 = 255;
+ intLabel3 = new Label(getMessage("BigValue"));
+ intInput3 = new TextField();
+ intInput3.textProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends String> observable,
String oldValue, String newValue) {
- checkThresholding();
+ try {
+ int v = Integer.valueOf(newValue);
+ if (v >= 0 && v <= 255) {
+ intPara3 = v;
+ intInput3.setStyle(null);
+ } else {
+ popError("0~255");
+ intInput3.setStyle(badStyle);
+ }
+ } catch (Exception e) {
+ popError("0~255");
+ intInput3.setStyle(badStyle);
+ }
}
});
- thresholdingMaxInput.setText("255");
+ intInput3.setPrefWidth(100);
+ intInput3.setText("255");
+ FxmlTools.quickTooltip(intInput3, new Tooltip("0~255"));
+ setBox.getChildren().addAll(intLabel, intInput,
+ intLabel2, intInput2,
+ intLabel3, intInput3);
okButton.disableProperty().bind(
- thresholdingInput.styleProperty().isEqualTo(badStyle)
- .or(thresholdingMinInput.styleProperty().isEqualTo(badStyle))
- .or(thresholdingMaxInput.styleProperty().isEqualTo(badStyle))
+ intInput.styleProperty().isEqualTo(badStyle)
+ .or(intInput3.styleProperty().isEqualTo(badStyle))
+ .or(intInput2.styleProperty().isEqualTo(badStyle))
);
-
} catch (Exception e) {
logger.error(e.toString());
}
+
}
- @Override
- protected void initInterface() {
+ private void makeBlackWhiteBox() {
try {
- if (values == null || values.getImage() == null) {
- return;
- }
- super.initInterface();
- values.getScope().setOperationType(ImageScope.OperationType.Effects);
+ intPara2 = 128;
+ intInput = new TextField();
+ intInput.textProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue extends String> observable,
+ String oldValue, String newValue) {
+ try {
+ int v = Integer.valueOf(intInput.getText());
+ if (v >= 0 && v <= 255) {
+ intPara2 = v;
+ intInput.setStyle(null);
+ } else {
+ intInput.setStyle(badStyle);
+ }
+ } catch (Exception e) {
+ intInput.setStyle(badStyle);
+ }
+ }
+ });
+ intInput.setPrefWidth(100);
+ intInput.setText("128");
+ FxmlTools.quickTooltip(intInput, new Tooltip("0~255"));
- isSettingValues = true;
+ setButton = new Button(getMessage("Calculate"));
+ setButton.setOnAction(new EventHandler() {
+ @Override
+ public void handle(ActionEvent event) {
+ int scaleValue = ImageBinary.calculateThreshold(imageView.getImage());
+ intInput.setText(scaleValue + "");
+ }
+ });
- isSettingValues = false;
- } catch (Exception e) {
- logger.debug(e.toString());
- }
+ intPara1 = 1;
+ radioGroup = new ToggleGroup();
+ radio1 = new RadioButton(getMessage("OTSU"));
+ radio1.setToggleGroup(radioGroup);
+ radio1.setUserData(1);
+ radio2 = new RadioButton(getMessage("Default"));
+ radio2.setToggleGroup(radioGroup);
+ radio2.setUserData(2);
+ radio3 = new RadioButton(getMessage("Threshold"));
+ radio3.setToggleGroup(radioGroup);
+ radio3.setUserData(3);
+ radioGroup.selectedToggleProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue extends Toggle> ov,
+ Toggle old_toggle, Toggle new_toggle) {
+ if (radioGroup.getSelectedToggle() == null) {
+ return;
+ }
+ intPara1 = (int) ((RadioButton) new_toggle).getUserData();
+ intInput.setDisable(intPara1 != 3);
+ setButton.setDisable(intPara1 != 3);
+ }
+ });
+ radio1.setSelected(true);
- }
+ valueCheck = new CheckBox(getMessage("Dithering"));
+ valueCheck.setSelected(true);
+ FxmlTools.setComments(valueCheck, new Tooltip(getMessage("DitherComments")));
- private void checkEffetcsOperationType() {
- intLabel.setText("");
- stringLabel.setText("");
- smallLabel.setText("");
- bigLabel.setText("");
- thresholdLabel.setText("");
- intBox.setDisable(true);
- stringBox.setDisable(true);
- thresholdingBox1.setDisable(true);
- thresholdingBox2.setDisable(true);
- thresholdingInput.setStyle(null);
- thresholdingMinInput.setStyle(null);
- thresholdingMaxInput.setStyle(null);
- grayCheck.setDisable(true);
- calculateButton.setDisable(true);
- RadioButton selected = (RadioButton) effectsGroup.getSelectedToggle();
- if (getMessage("Blur").equals(selected.getText())) {
- effectType = EffectsOperationType.Blur;
- intLabel.setText(getMessage("Radius"));
- intBox.setDisable(false);
- intBox.getItems().clear();
- intBox.getItems().addAll(Arrays.asList("10", "5", "3", "2", "1", "8", "15", "20", "30"));
- intBox.setEditable(true);
- intValue = 10;
- intBox.getSelectionModel().select("10");
- } else if (getMessage("Sharpen").equals(selected.getText())) {
- effectType = EffectsOperationType.Sharpen;
- } else if (getMessage("Clarity").equals(selected.getText())) {
- effectType = EffectsOperationType.Clarity;
- } else if (getMessage("EdgeDetection").equals(selected.getText())) {
- effectType = EffectsOperationType.EdgeDetect;
- } else if (getMessage("Emboss").equals(selected.getText())) {
- effectType = EffectsOperationType.Emboss;
- intLabel.setText(getMessage("Radius"));
- intBox.setDisable(false);
- intBox.getItems().clear();
- intBox.getItems().addAll(Arrays.asList("3", "5"));
- intBox.setEditable(false);
- intValue = 3;
- intBox.getSelectionModel().select("3");
- stringLabel.setText(getMessage("Direction"));
- stringBox.setDisable(false);
- stringBox.getItems().clear();
- stringBox.getItems().addAll(Arrays.asList(getMessage("Top"), getMessage("Bottom"),
- getMessage("Left"), getMessage("Right"),
- getMessage("LeftTop"), getMessage("RightBottom"),
- getMessage("LeftBottom"), getMessage("RightTop")));
- direction = Direction.Top;
- stringBox.getSelectionModel().select(getMessage("Top"));
- grayCheck.setDisable(false);
- } else if (getMessage("Posterizing").equals(selected.getText())) {
- effectType = EffectsOperationType.Posterizing;
- intLabel.setText(getMessage("Size"));
- intBox.setDisable(false);
- intBox.getItems().clear();
- intBox.getItems().addAll(Arrays.asList("64", "32", "128", "16"));
- intBox.setEditable(false);
- intBox.getSelectionModel().select("64");
- } else if (getMessage("Thresholding").equals(selected.getText())) {
- effectType = EffectsOperationType.Thresholding;
- thresholdLabel.setText(getMessage("Threshold"));
- smallLabel.setText(getMessage("SmallValue"));
- bigLabel.setText(getMessage("BigValue"));
- thresholdingBox1.setDisable(false);
- thresholdingBox2.setDisable(false);
- checkThresholding();
- Tooltip tips = new Tooltip("0~255");
- tips.setFont(new Font(16));
- FxmlTools.quickTooltip(thresholdingInput, tips);
- } else if (getMessage("Gray").equals(selected.getText())) {
- effectType = EffectsOperationType.Gray;
-
- } else if (getMessage("BlackOrWhite").equals(selected.getText())) {
- effectType = EffectsOperationType.BlackOrWhite;
- thresholdingBox1.setDisable(false);
- thresholdLabel.setText(getMessage("Threshold"));
- thresholdingInput.setText("50");
- smallLabel.setText("%");
- calculateButton.setDisable(false);
- checkThresholdForBW();
- Tooltip tips = new Tooltip("0~100");
- tips.setFont(new Font(16));
- FxmlTools.quickTooltip(thresholdingInput, tips);
-
- } else if (getMessage("Sepia").equals(selected.getText())) {
- effectType = EffectsOperationType.Sepia;
- thresholdingBox1.setDisable(false);
- thresholdLabel.setText(getMessage("Intensity"));
- thresholdingInput.setText("80");
- checkDensityForSepia();
- Tooltip tips = new Tooltip("0~255");
- tips.setFont(new Font(16));
- FxmlTools.quickTooltip(thresholdingInput, tips);
+ setBox.getChildren().addAll(radio1, radio2, radio3,
+ intInput, setButton, valueCheck);
+ okButton.disableProperty().bind(
+ intInput.styleProperty().isEqualTo(badStyle)
+ );
+ } catch (Exception e) {
+ logger.error(e.toString());
}
+
}
- private void checkThresholding() {
- try {
- threadholding = Integer.valueOf(thresholdingInput.getText());
- if (threadholding >= 0 && threadholding <= 255) {
- thresholdingInput.setStyle(null);
- } else {
- popError("0~100");
- thresholdingInput.setStyle(badStyle);
- }
- } catch (Exception e) {
- popError("0~100");
- thresholdingInput.setStyle(badStyle);
- }
+ private void makeSepiaBox() {
try {
- threadholdingSmall = Integer.valueOf(thresholdingMinInput.getText());
- if (threadholdingSmall >= 0 && threadholdingSmall <= 255) {
- thresholdingMinInput.setStyle(null);
- } else {
- thresholdingMinInput.setStyle(badStyle);
- }
- } catch (Exception e) {
- thresholdingMinInput.setStyle(badStyle);
- }
- try {
- threadholdingBig = Integer.valueOf(thresholdingMaxInput.getText());
- if (threadholdingBig >= 0 && threadholdingBig <= 255) {
- thresholdingMaxInput.setStyle(null);
- } else {
- thresholdingMaxInput.setStyle(badStyle);
- }
+ intPara1 = 80;
+ intLabel = new Label(getMessage("Intensity"));
+ intInput = new TextField();
+ intInput.textProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue extends String> observable,
+ String oldValue, String newValue) {
+ try {
+ int v = Integer.valueOf(intInput.getText());
+ if (v >= 0 && v <= 255) {
+ intPara1 = v;
+ intInput.setStyle(null);
+ } else {
+ intInput.setStyle(badStyle);
+ popError("0~255");
+ }
+ } catch (Exception e) {
+ popError("0~255");
+ intInput.setStyle(badStyle);
+ }
+ }
+ });
+ intInput.setPrefWidth(100);
+ intInput.setText("80");
+ FxmlTools.quickTooltip(intInput, new Tooltip("0~255"));
+
+ setBox.getChildren().addAll(intLabel, intInput);
+ okButton.disableProperty().bind(
+ intInput.styleProperty().isEqualTo(badStyle)
+ );
} catch (Exception e) {
- thresholdingMaxInput.setStyle(badStyle);
+ logger.error(e.toString());
}
+
}
- private void checkThresholdForBW() {
+ private void makeConvolutionBox() {
try {
- threadholding = Integer.valueOf(thresholdingInput.getText());
- if (threadholding >= 0 && threadholding <= 100) {
- thresholdingInput.setStyle(null);
- } else {
- thresholdingInput.setStyle(badStyle);
- popError("0~100");
+ stringLabel = new Label(getMessage("ConvolutionKernel"));
+ stringBox = new ComboBox();
+ kernel = null;
+ if (kernels == null) {
+ kernels = TableConvolutionKernel.read();
}
+ loadKernelsList(kernels);
+ stringBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue ov, Number oldValue, Number newValue) {
+ int index = newValue.intValue();
+ if (index < 0 || index >= kernels.size()) {
+ kernel = null;
+ stringBox.getEditor().setStyle(badStyle);
+ return;
+ }
+ kernel = kernels.get(index);
+ stringBox.getEditor().setStyle(null);
+ }
+ });
+ FxmlTools.quickTooltip(stringBox, new Tooltip(getMessage("CTRL+k")));
+ setButton = new Button(getMessage("ManageDot"));
+ setButton.setOnAction(new EventHandler() {
+ @Override
+ public void handle(ActionEvent event) {
+ BaseController c = openStage(CommonValues.ConvolutionKernelManagerFxml, false);
+ c.setParentController(getMyController());
+ c.setParentFxml(getMyFxml());
+ }
+ });
+ setBox.getChildren().addAll(stringLabel, stringBox, setButton);
+ okButton.disableProperty().bind(
+ stringBox.getEditor().styleProperty().isEqualTo(badStyle)
+ );
} catch (Exception e) {
- popError("0~100");
- thresholdingInput.setStyle(badStyle);
+ logger.error(e.toString());
}
+
}
- private void checkDensityForSepia() {
+ private void makeContrastBox() {
try {
- threadholding = Integer.valueOf(thresholdingInput.getText());
- if (threadholding >= 0 && threadholding <= 255) {
- thresholdingInput.setStyle(null);
- } else {
- popError("0~255");
- thresholdingInput.setStyle(badStyle);
- }
+ contrastAlgorithm = ContrastAlgorithm.Gray_Histogram_Equalization;
+ stringLabel = new Label(getMessage("Algorithm"));
+ stringBox = new ComboBox();
+ stringBox.getItems().addAll(Arrays.asList(
+ getMessage("HSBHistogramEqualization"),
+ getMessage("GrayHistogramEqualization"),
+ getMessage("GrayHistogramStretching"),
+ getMessage("GrayHistogramShifting")
+ // getMessage("LumaHistogramEqualization"),
+ // getMessage("AdaptiveHistogramEqualization")
+ ));
+ stringBox.getSelectionModel().select(0);
+ stringBox.valueProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue ov, String oldValue, String newValue) {
+ if (setBox.getChildren() != null) {
+ if (setBox.getChildren().contains(intInput)) {
+ setBox.getChildren().removeAll(intLabel, intInput);
+ }
+ if (setBox.getChildren().contains(intInput2)) {
+ setBox.getChildren().removeAll(intLabel2, intInput2);
+ }
+ }
+ okButton.disableProperty().unbind();
+ if (getMessage("GrayHistogramEqualization").equals(newValue)) {
+ contrastAlgorithm = ContrastAlgorithm.Gray_Histogram_Equalization;
+ } else if (getMessage("GrayHistogramStretching").equals(newValue)) {
+ contrastAlgorithm = ContrastAlgorithm.Gray_Histogram_Stretching;
+ intPara1 = 100;
+ intLabel = new Label(getMessage("LeftThreshold"));
+ intInput = new TextField();
+ intInput.textProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue extends String> observable,
+ String oldValue, String newValue) {
+ try {
+ int v = Integer.valueOf(intInput.getText());
+ if (v >= 0) {
+ intPara1 = v;
+ intInput.setStyle(null);
+ } else {
+ intInput.setStyle(badStyle);
+ }
+ } catch (Exception e) {
+ intInput.setStyle(badStyle);
+ }
+ }
+ });
+ intInput.setPrefWidth(100);
+ intInput.setText("100");
+
+ intPara2 = 100;
+ intLabel2 = new Label(getMessage("RightThreshold"));
+ intInput2 = new TextField();
+ intInput2.textProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue extends String> observable,
+ String oldValue, String newValue) {
+ try {
+ int v = Integer.valueOf(intInput2.getText());
+ if (v >= 0) {
+ intPara2 = v;
+ intInput2.setStyle(null);
+ } else {
+ intInput2.setStyle(badStyle);
+ }
+ } catch (Exception e) {
+ intInput2.setStyle(badStyle);
+ }
+ }
+ });
+ intInput2.setPrefWidth(100);
+ intInput2.setText("100");
+
+ setBox.getChildren().addAll(intLabel, intInput, intLabel2, intInput2);
+ okButton.disableProperty().bind(
+ intInput.styleProperty().isEqualTo(badStyle)
+ .or(intInput2.styleProperty().isEqualTo(badStyle))
+ .or(stringBox.getEditor().styleProperty().isEqualTo(badStyle))
+ );
+ } else if (getMessage("GrayHistogramShifting").equals(newValue)) {
+ contrastAlgorithm = ContrastAlgorithm.Gray_Histogram_Shifting;
+ intPara1 = 80;
+ intLabel = new Label(getMessage("Offset"));
+ intInput = new TextField();
+ intInput.textProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue extends String> observable,
+ String oldValue, String newValue) {
+ try {
+ int v = Integer.valueOf(intInput.getText());
+ if (v >= -255 && v <= 255) {
+ intPara1 = v;
+ intInput.setStyle(null);
+ } else {
+ intInput.setStyle(badStyle);
+ popError("-255 ~ 255");
+ }
+ } catch (Exception e) {
+ popError("-255 ~ 255");
+ }
+ }
+ });
+ intInput.setPrefWidth(100);
+ intInput.setText("10");
+ FxmlTools.quickTooltip(intInput, new Tooltip("-255 ~ 255"));
+ setBox.getChildren().addAll(intLabel, intInput);
+ okButton.disableProperty().bind(
+ intInput.styleProperty().isEqualTo(badStyle)
+ .or(stringBox.getEditor().styleProperty().isEqualTo(badStyle))
+ );
+ } else if (getMessage("LumaHistogramEqualization").equals(newValue)) {
+ contrastAlgorithm = ContrastAlgorithm.Luma_Histogram_Equalization;
+ } else if (getMessage("HSBHistogramEqualization").equals(newValue)) {
+ contrastAlgorithm = ContrastAlgorithm.HSB_Histogram_Equalization;
+ } else if (getMessage("AdaptiveHistogramEqualization").equals(newValue)) {
+ contrastAlgorithm = ContrastAlgorithm.Adaptive_Histogram_Equalization;
+ }
+ }
+ });
+
+ setBox.getChildren().addAll(stringLabel, stringBox);
} catch (Exception e) {
- popError("0~255");
- thresholdingInput.setStyle(badStyle);
+ logger.error(e.toString());
}
}
- @FXML
- private void calculateAction() {
- int scaleValue = ImageGrayTools.calculateThreshold(values.getSourceFile());
- scaleValue = scaleValue * 100 / 256;
- thresholdingInput.setText(scaleValue + "");
- }
-
@Override
protected void keyEventsHandler(KeyEvent event) {
super.keyEventsHandler(event);
- String key = event.getText();
- if (key == null || key.isEmpty()) {
- return;
- }
if (event.isControlDown()) {
+ String key = event.getText();
+ if (key == null || key.isEmpty()) {
+ return;
+ }
switch (key) {
- case "a":
- case "A":
- effectsAction();
+ case "k":
+ case "K":
+ if (stringBox != null) {
+ stringBox.show();
+ }
break;
}
}
}
+ public void applyKernel(ConvolutionKernel kernel) {
+ if (effectType != OperationType.Convolution || stringBox == null) {
+ return;
+ }
+ convolutionRadio.fire();
+ if (stringBox.getItems().contains(kernel.getName())) {
+ stringBox.getSelectionModel().select(kernel.getName());
+ } else {
+ stringBox.getSelectionModel().select(-1);
+ }
+ this.kernel = kernel;
+ okAction();
+ }
+
+ public void loadKernelsList(List records) {
+ if (effectType != OperationType.Convolution || stringBox == null) {
+ return;
+ }
+ kernels = records;
+ stringBox.getItems().clear();
+ if (kernels != null && !kernels.isEmpty()) {
+ List names = new ArrayList<>();
+ for (ConvolutionKernel k : kernels) {
+ names.add(k.getName());
+ }
+ stringBox.getItems().addAll(names);
+ stringBox.getSelectionModel().select(0);
+ stringBox.getEditor().setStyle(null);
+ } else {
+ stringBox.getEditor().setStyle(badStyle);
+ }
+ }
+
@FXML
- public void effectsAction() {
+ @Override
+ public void okAction() {
if (null == effectType) {
return;
}
task = new Task() {
+ private Image newImage;
+
@Override
protected Void call() throws Exception {
- final Image newImage;
- ConvolutionKernel convolutionKernel;
+ PixelsOperation pixelsOperation;
+ ImageConvolution imageConvolution;
switch (effectType) {
+ case Contrast:
+ ImageContrast imageContrast = new ImageContrast(values.getCurrentImage(), contrastAlgorithm);
+ imageContrast.setIntPara1(intPara1);
+ imageContrast.setIntPara2(intPara2);
+ newImage = imageContrast.operateFxImage();
+ break;
+ case Convolution:
+ if (kernel == null) {
+ int index = stringBox.getSelectionModel().getSelectedIndex();
+ if (kernels == null || kernels.isEmpty() || index < 0) {
+ return null;
+ }
+ kernel = kernels.get(index);
+ }
+ imageConvolution = new ImageConvolution(values.getCurrentImage(), scope, kernel);
+ newImage = imageConvolution.operateFxImage();
+ break;
case Blur:
- convolutionKernel = ConvolutionKernel.makeAverageBlur(intValue);
- newImage = FxmlEffectTools.applyConvolution(values.getCurrentImage(), convolutionKernel, scope);
+ if (kernel == null) {
+ return null;
+ }
+ imageConvolution = new ImageConvolution(values.getCurrentImage(), scope, kernel);
+ newImage = imageConvolution.operateFxImage();
break;
case Sharpen:
- convolutionKernel = ConvolutionKernel.makeSharpen3b();
- newImage = FxmlEffectTools.applyConvolution(values.getCurrentImage(), convolutionKernel, scope);
+ kernel = ConvolutionKernel.makeSharpen3b();
+ imageConvolution = new ImageConvolution(values.getCurrentImage(), scope, kernel);
+ newImage = imageConvolution.operateFxImage();
break;
case Clarity:
- convolutionKernel = ConvolutionKernel.makeUnsharpMasking5();
- newImage = FxmlEffectTools.applyConvolution(values.getCurrentImage(), convolutionKernel, scope);
+ kernel = ConvolutionKernel.makeUnsharpMasking5();
+ imageConvolution = new ImageConvolution(values.getCurrentImage(), scope, kernel);
+ newImage = imageConvolution.operateFxImage();
break;
case EdgeDetect:
- convolutionKernel = ConvolutionKernel.makeEdgeDetection3b();
- newImage = FxmlEffectTools.applyConvolution(values.getCurrentImage(), convolutionKernel, scope);
+ kernel = ConvolutionKernel.makeEdgeDetection3b();
+ imageConvolution = new ImageConvolution(values.getCurrentImage(), scope, kernel);
+ newImage = imageConvolution.operateFxImage();
break;
case Emboss:
- convolutionKernel = ConvolutionKernel.makeEmbossKernel(direction, intValue, grayCheck.isSelected());
- newImage = FxmlEffectTools.applyConvolution(values.getCurrentImage(), convolutionKernel, scope);
+ kernel = ConvolutionKernel.makeEmbossKernel(intPara1, intPara2, valueCheck.isSelected());
+ imageConvolution = new ImageConvolution(values.getCurrentImage(), scope, kernel);
+ newImage = imageConvolution.operateFxImage();
+ break;
+ case Quantization:
+ int channelSize = (int) Math.round(Math.pow(intPara1, 1.0 / 3.0));
+ ImageQuantization quantization = new ImageQuantization(values.getCurrentImage());
+ quantization.setScope(scope);
+ quantization.set(quantizationAlgorithm, channelSize);
+ quantization.setIsDithering(valueCheck.isSelected());
+ newImage = quantization.operateFxImage();
break;
case Thresholding:
- newImage = FxmlEffectTools.thresholdingImage(values.getCurrentImage(),
- threadholding, threadholdingSmall, threadholdingBig, scope);
+ pixelsOperation = new PixelsOperation(values.getCurrentImage(), scope, effectType);
+ pixelsOperation.setIntPara1(intPara1);
+ pixelsOperation.setIntPara2(intPara2);
+ pixelsOperation.setIntPara3(intPara3);
+ pixelsOperation.setIsDithering(false);
+ newImage = pixelsOperation.operateFxImage();
break;
- case Posterizing:
- newImage = FxmlEffectTools.posterizingImage(values.getCurrentImage(), intValue, scope);
+ case BlackOrWhite:
+ ImageBinary imageBinary;
+ switch (intPara1) {
+ case 2:
+ imageBinary = new ImageBinary(values.getCurrentImage(), scope, -1);
+ break;
+ case 3:
+ imageBinary = new ImageBinary(values.getCurrentImage(), scope, intPara2);
+ break;
+ default:
+ int t = ImageBinary.calculateThreshold(values.getCurrentImage());
+ imageBinary = new ImageBinary(values.getCurrentImage(), scope, t);
+ break;
+ }
+ imageBinary.setIsDithering(valueCheck.isSelected());
+ newImage = imageBinary.operateFxImage();
break;
case Gray:
- case BlackOrWhite:
+ ImageGray imageGray = new ImageGray(values.getCurrentImage(), scope);
+ newImage = imageGray.operateFxImage();
+ break;
case Sepia:
- newImage = FxmlEffectTools.makeColor(values.getCurrentImage(), effectType, threadholding, scope);
+ pixelsOperation = new PixelsOperation(values.getCurrentImage(), scope, effectType);
+ pixelsOperation.setIntPara1(intPara1);
+ newImage = pixelsOperation.operateFxImage();
break;
default:
return null;
}
- if (task.isCancelled()) {
+ if (task.isCancelled() || newImage == null) {
return null;
}
recordImageHistory(ImageOperationType.Effects, newImage);
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureFileController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureFileController.java
index 297677848..989fd2db2 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureFileController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureFileController.java
@@ -2,15 +2,14 @@
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
-import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.ToolBar;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.AppVaribles;
-import mara.mybox.objects.ImageScope;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.value.AppVaribles;
+import mara.mybox.image.ImageScope;
/**
* @Author Mara
@@ -94,75 +93,6 @@ public void changed(ObservableValue extends Boolean> ov, Boolean old_val, Bool
}
}
- @Override
- protected void afterInfoLoaded() {
- super.afterInfoLoaded();
- fileBar.setDisable(false);
- saveCheck.setDisable(true);
- }
-
- @Override
- public void afterImageLoaded() {
- try {
- super.afterImageLoaded();
-
- if (imageInformation.isIsSampled()) {
- hotBar.setDisable(false);
- showRefCheck.setDisable(true);
- hisBox.setDisable(true);
- undoButton.setDisable(true);
- redoButton.setDisable(true);
- recoverButton.setDisable(true);
- saveButton.setDisable(true);
-
- browseTab.setDisable(true);
- viewTab.setDisable(true);
- colorTab.setDisable(true);
- effectsTab.setDisable(true);
- convolutionTab.setDisable(true);
- sizeTab.setDisable(true);
- refTab.setDisable(true);
- transformTab.setDisable(true);
- textTab.setDisable(true);
- coverTab.setDisable(true);
- arcTab.setDisable(true);
- shadowTab.setDisable(true);
- marginsTab.setDisable(true);
- cropTab.setDisable(true);
-
- }
- isSettingValues = true;
- values.setSourceFile(sourceFile);
- values.setImage(image);
- values.setImageInfo(imageInformation);
- values.setCurrentImage(image);
- isSettingValues = false;
-
- if (image == null || imageInformation.isIsSampled()) {
- return;
- }
-
- isSettingValues = true;
- values.setRefImage(image);
- values.setRefInfo(imageInformation);
- setImageChanged(false);
- values.setScope(new ImageScope(image));
- scope = values.getScope();
-
- recordImageHistory(ImageOperationType.Load, image);
- saveCheck.setDisable(false);
- if (initTab != null) {
- switchTab(initTab);
- } else {
- initInterface();
- }
- isSettingValues = false;
-
- } catch (Exception e) {
- logger.debug(e.toString());
- }
- }
-
private void checkSaveAsType() {
try {
RadioButton selected = (RadioButton) saveAsGroup.getSelectedToggle();
@@ -183,17 +113,6 @@ private void checkSaveAsType() {
}
}
- @FXML
- @Override
- protected void selectSourceFile(ActionEvent event) {
- if (values == null || values.getCurrentImage() != null && values.isImageChanged()) {
- if (!checkSavingBeforeExit()) {
- return;
- }
- }
- super.selectSourceFile(event);
- }
-
@Override
protected void initInterface() {
try {
@@ -205,6 +124,8 @@ protected void initInterface() {
isSettingValues = true;
fileBar.setDisable(false);
saveAsBar.setDisable(false);
+ infoButton.setDisable(imageInformation == null);
+ metaButton.setDisable(imageInformation == null);
isSettingValues = false;
} catch (Exception e) {
logger.debug(e.toString());
@@ -212,4 +133,22 @@ protected void initInterface() {
}
+ @Override
+ protected void afterInfoLoaded() {
+ super.afterInfoLoaded();
+ fileBar.setDisable(false);
+ saveCheck.setDisable(true);
+ }
+
+ @Override
+ public void afterImageLoaded() {
+ try {
+ super.afterImageLoaded();
+ saveCheck.setDisable(false);
+
+ } catch (Exception e) {
+ logger.debug(e.toString());
+ }
+ }
+
}
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureMarginsController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureMarginsController.java
index d687aca8b..592d92e2c 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureMarginsController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureMarginsController.java
@@ -11,7 +11,6 @@
import javafx.scene.control.CheckBox;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.ComboBox;
-import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.Toggle;
@@ -22,11 +21,11 @@
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Modality;
-import static mara.mybox.objects.AppVaribles.logger;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.fxml.FxmlMarginsTools;
-import mara.mybox.objects.AppVaribles;
+import static mara.mybox.value.AppVaribles.logger;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.value.CommonValues;
+import mara.mybox.fxml.image.FxmlMarginsTools;
+import mara.mybox.value.AppVaribles;
import static mara.mybox.fxml.FxmlTools.badStyle;
/**
@@ -47,14 +46,12 @@ public class ImageManufactureMarginsController extends ImageManufactureControlle
@FXML
protected ColorPicker marginsColorPicker;
@FXML
- protected Button marginsWhiteButton, marginsBlackButton, marginsOkButton, marginsTrButton;
+ protected Button marginsWhiteButton, marginsBlackButton, marginsTrButton;
@FXML
protected CheckBox marginsTopCheck, marginsBottomCheck, marginsLeftCheck, marginsRightCheck;
@FXML
private HBox colorBox, distanceBox, widthBox;
@FXML
- private Label promptLabel;
- @FXML
private TextField distanceInput;
public ImageManufactureMarginsController() {
@@ -85,7 +82,8 @@ protected void initInterface() {
super.initInterface();
isSettingValues = true;
- if (CommonValues.NoAlphaImages.contains(values.getImageInfo().getImageFormat())) {
+ if (values.getImageInfo() != null
+ && CommonValues.NoAlphaImages.contains(values.getImageInfo().getImageFormat())) {
marginsTrButton.setDisable(true);
} else {
marginsTrButton.setDisable(false);
@@ -127,7 +125,7 @@ public void changed(ObservableValue ov, String oldValue, String newValue) {
});
marginWidthBox.getSelectionModel().select(0);
- marginsOkButton.disableProperty().bind(
+ okButton.disableProperty().bind(
marginWidthBox.getEditor().styleProperty().isEqualTo(badStyle)
.or(distanceInput.styleProperty().isEqualTo(badStyle))
);
@@ -234,7 +232,8 @@ public void clickImage(MouseEvent event) {
}
@FXML
- public void marginsAction() {
+ @Override
+ public void okAction() {
if (!marginsTopCheck.isSelected()
&& !marginsBottomCheck.isSelected()
&& !marginsLeftCheck.isSelected()
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureRefController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureRefController.java
index 28142484a..c5ecb5036 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureRefController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureRefController.java
@@ -7,9 +7,9 @@
import javafx.scene.control.CheckBox;
import javafx.scene.control.ToolBar;
import javafx.stage.FileChooser;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.AppVaribles;
-import mara.mybox.objects.CommonValues;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.value.AppVaribles;
+import mara.mybox.value.CommonValues;
/**
* @Author Mara
@@ -85,8 +85,8 @@ protected void checkReferenceImage() {
public void selectReference() {
try {
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(sourcePathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(sourcePathKey);
+ if ( path.exists() ) fileChooser.setInitialDirectory(path);
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
File file = fileChooser.showOpenDialog(getMyStage());
if (file == null) {
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureShadowController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureShadowController.java
index df57ffa85..029846978 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureShadowController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureShadowController.java
@@ -12,10 +12,10 @@
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.stage.Modality;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.AppVaribles;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.fxml.FxmlImageTools;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.value.AppVaribles;
+import mara.mybox.value.CommonValues;
+import mara.mybox.fxml.image.ImageTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
/**
@@ -60,17 +60,18 @@ protected void initInterface() {
isSettingValues = true;
- if (CommonValues.NoAlphaImages.contains(values.getImageInfo().getImageFormat())) {
+ if (values.getImageInfo() != null
+ && CommonValues.NoAlphaImages.contains(values.getImageInfo().getImageFormat())) {
transShadowButton.setDisable(true);
} else {
transShadowButton.setDisable(false);
}
shadowBox.getItems().clear();
- shadowBox.getItems().addAll(Arrays.asList(values.getImageInfo().getWidth() / 100 + "",
- values.getImageInfo().getWidth() / 50 + "",
- values.getImageInfo().getWidth() / 200 + "",
- values.getImageInfo().getWidth() / 30 + "",
+ shadowBox.getItems().addAll(Arrays.asList((int) values.getImage().getWidth() / 100 + "",
+ (int) values.getImage().getWidth() / 50 + "",
+ (int) values.getImage().getWidth() / 200 + "",
+ (int) values.getImage().getWidth() / 30 + "",
"0", "4", "5", "3", "2", "1", "6"));
shadowBox.getSelectionModel().select(0);
@@ -131,7 +132,7 @@ public void shadowAction() {
return;
}
try {
- Image newImage = FxmlImageTools.addShadowFx(values.getCurrentImage(), shadow, shadowColorPicker.getValue());
+ Image newImage = ImageTools.addShadowFx(values.getCurrentImage(), shadow, shadowColorPicker.getValue());
if (newImage != null) {
recordImageHistory(ImageOperationType.Shadow, newImage);
values.setUndoImage(values.getCurrentImage());
@@ -145,7 +146,7 @@ public void shadowAction() {
}
- Image newImage = FxmlImageTools.addShadowBigFx(values.getCurrentImage(), shadow, shadowColorPicker.getValue());
+ Image newImage = ImageTools.addShadowBigFx(values.getCurrentImage(), shadow, shadowColorPicker.getValue());
if (newImage != null) {
recordImageHistory(ImageOperationType.Shadow, newImage);
values.setUndoImage(values.getCurrentImage());
@@ -159,7 +160,7 @@ public void shadowAction() {
task = new Task() {
@Override
protected Void call() throws Exception {
- final Image newImage = FxmlImageTools.addShadow(values.getCurrentImage(), shadow, shadowColorPicker.getValue());
+ final Image newImage = ImageTools.addShadow(values.getCurrentImage(), shadow, shadowColorPicker.getValue());
if (task.isCancelled()) {
return null;
}
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureSizeController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureSizeController.java
index 816e3016e..1f7970d67 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureSizeController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureSizeController.java
@@ -9,7 +9,6 @@
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
-import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.ComboBox;
@@ -23,14 +22,14 @@
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.image.ImageConvertTools;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.ImageAttributes;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.image.ImageConvert;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.value.CommonValues;
+import mara.mybox.data.ImageAttributes;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.fxml.FxmlImageTools;
+import mara.mybox.fxml.image.ImageTools;
/**
* @Author Mara
@@ -49,8 +48,6 @@ public class ImageManufactureSizeController extends ImageManufactureController {
@FXML
protected ToggleGroup pixelsGroup;
@FXML
- protected Button pixelsOkButton;
- @FXML
protected CheckBox keepRatioCheck;
@FXML
protected TextField widthInput, heightInput;
@@ -79,14 +76,11 @@ protected void initInterface() {
return;
}
super.initInterface();
-
isSettingValues = true;
-
- widthInput.setText(values.getImageInfo().getWidth() + "");
- heightInput.setText(values.getImageInfo().getHeight() + "");
- attributes.setSourceWidth(values.getImageInfo().getWidth());
- attributes.setSourceHeight(values.getImageInfo().getHeight());
-
+ widthInput.setText((int) values.getImage().getWidth() + "");
+ heightInput.setText((int) values.getImage().getHeight() + "");
+ attributes.setSourceWidth((int) values.getImage().getWidth());
+ attributes.setSourceHeight((int) values.getImage().getHeight());
isSettingValues = false;
} catch (Exception e) {
logger.debug(e.toString());
@@ -124,7 +118,7 @@ public void changed(ObservableValue extends Boolean> ov, Boolean oldValue, Boo
});
checkRatio();
- pixelsOkButton.disableProperty().bind(
+ okButton.disableProperty().bind(
widthInput.styleProperty().isEqualTo(badStyle)
.or(heightInput.styleProperty().isEqualTo(badStyle))
.or(scaleBox.getEditor().styleProperty().isEqualTo(badStyle))
@@ -236,15 +230,15 @@ private void checkPixelsHeight() {
protected void checkRatioAdjustion(String s) {
try {
if (getMessage("BaseOnWidth").equals(s)) {
- attributes.setRatioAdjustion(ImageConvertTools.KeepRatioType.BaseOnWidth);
+ attributes.setRatioAdjustion(ImageConvert.KeepRatioType.BaseOnWidth);
} else if (getMessage("BaseOnHeight").equals(s)) {
- attributes.setRatioAdjustion(ImageConvertTools.KeepRatioType.BaseOnHeight);
+ attributes.setRatioAdjustion(ImageConvert.KeepRatioType.BaseOnHeight);
} else if (getMessage("BaseOnLarger").equals(s)) {
- attributes.setRatioAdjustion(ImageConvertTools.KeepRatioType.BaseOnLarger);
+ attributes.setRatioAdjustion(ImageConvert.KeepRatioType.BaseOnLarger);
} else if (getMessage("BaseOnSmaller").equals(s)) {
- attributes.setRatioAdjustion(ImageConvertTools.KeepRatioType.BaseOnSmaller);
+ attributes.setRatioAdjustion(ImageConvert.KeepRatioType.BaseOnSmaller);
} else {
- attributes.setRatioAdjustion(ImageConvertTools.KeepRatioType.None);
+ attributes.setRatioAdjustion(ImageConvert.KeepRatioType.None);
}
} catch (Exception e) {
logger.error(e.toString());
@@ -260,8 +254,8 @@ protected void checkRatio() {
height = Integer.valueOf(heightInput.getText());
attributes.setTargetWidth(width);
attributes.setTargetHeight(height);
- int sourceX = values.getImageInfo().getWidth();
- int sourceY = values.getImageInfo().getHeight();
+ int sourceX = (int) values.getImage().getWidth();
+ int sourceY = (int) values.getImage().getHeight();
if (noRatio || !keepRatioCheck.isSelected() || sourceX <= 0 || sourceY <= 0) {
return;
}
@@ -271,20 +265,20 @@ protected void checkRatio() {
return;
}
switch (attributes.getRatioAdjustion()) {
- case ImageConvertTools.KeepRatioType.BaseOnWidth:
+ case ImageConvert.KeepRatioType.BaseOnWidth:
heightInput.setText(Math.round(width * sourceY / sourceX) + "");
break;
- case ImageConvertTools.KeepRatioType.BaseOnHeight:
+ case ImageConvert.KeepRatioType.BaseOnHeight:
widthInput.setText(Math.round(height * sourceX / sourceY) + "");
break;
- case ImageConvertTools.KeepRatioType.BaseOnLarger:
+ case ImageConvert.KeepRatioType.BaseOnLarger:
if (ratioX > ratioY) {
heightInput.setText(Math.round(width * sourceY / sourceX) + "");
} else {
widthInput.setText(Math.round(height * sourceX / sourceY) + "");
}
break;
- case ImageConvertTools.KeepRatioType.BaseOnSmaller:
+ case ImageConvert.KeepRatioType.BaseOnSmaller:
if (ratioX > ratioY) {
widthInput.setText(Math.round(height * sourceX / sourceY) + "");
} else {
@@ -304,11 +298,11 @@ protected void checkRatio() {
@FXML
protected void setOriginalSize() {
noRatio = true;
- if (values.getImageInfo().getWidth() > 0) {
- widthInput.setText(values.getImageInfo().getWidth() + "");
+ if (values.getImage().getWidth() > 0) {
+ widthInput.setText((int) values.getImage().getWidth() + "");
}
- if (values.getImageInfo().getHeight() > 0) {
- heightInput.setText(values.getImageInfo().getHeight() + "");
+ if (values.getImage().getHeight() > 0) {
+ heightInput.setText((int) values.getImage().getHeight() + "");
}
noRatio = false;
}
@@ -348,7 +342,8 @@ public void handle(WindowEvent event) {
}
@FXML
- protected void pixelsAction() {
+ @Override
+ public void okAction() {
if (isScale) {
setScale();
} else {
@@ -363,7 +358,7 @@ protected void setScale() {
task = new Task() {
@Override
protected Void call() throws Exception {
- final Image newImage = FxmlImageTools.scaleImage(values.getCurrentImage(), values.getImageInfo().getImageFormat(), scale);
+ final Image newImage = ImageTools.scaleImage(values.getCurrentImage(), scale);
if (task.isCancelled()) {
return null;
}
@@ -376,6 +371,7 @@ public void run() {
imageView.setImage(newImage);
setImageChanged(true);
setBottomLabel();
+ popInformation(AppVaribles.getMessage("Successful"), 1500);
}
});
return null;
@@ -394,7 +390,7 @@ protected void setPixels() {
task = new Task() {
@Override
protected Void call() throws Exception {
- final Image newImage = FxmlImageTools.scaleImage(values.getCurrentImage(), values.getImageInfo().getImageFormat(), width, height);
+ final Image newImage = ImageTools.scaleImage(values.getCurrentImage(), width, height);
if (task.isCancelled()) {
return null;
}
@@ -407,6 +403,7 @@ public void run() {
imageView.setImage(newImage);
setImageChanged(true);
setBottomLabel();
+ popInformation(AppVaribles.getMessage("Successful"), 1500);
}
});
return null;
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureTextController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureTextController.java
index 062ab038c..838c289ec 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureTextController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureTextController.java
@@ -21,11 +21,11 @@
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Modality;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.fxml.FxmlImageTools;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.value.CommonValues;
+import mara.mybox.fxml.image.ImageTools;
import mara.mybox.fxml.FxmlTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
@@ -80,7 +80,8 @@ protected void initInterface() {
super.initInterface();
isSettingValues = true;
- if (CommonValues.NoAlphaImages.contains(values.getImageInfo().getImageFormat())) {
+ if (values.getImageInfo() != null
+ && CommonValues.NoAlphaImages.contains(values.getImageInfo().getImageFormat())) {
waterTransparentBox.setDisable(true);
waterTransparentBox.getSelectionModel().select("1.0");
} else {
@@ -323,7 +324,7 @@ protected Void call() throws Exception {
} else {
font = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, waterSize);
}
- final Image newImage = FxmlImageTools.addText(values.getCurrentImage(), waterInput.getText(),
+ final Image newImage = ImageTools.addText(values.getCurrentImage(), waterInput.getText(),
font, waterColorPicker.getValue(), waterX, waterY,
waterTransparent, waterShadow, waterAngle, outlineCheck.isSelected());
if (task.isCancelled()) {
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureTransformController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureTransformController.java
index 478543647..2e9344784 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureTransformController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureTransformController.java
@@ -16,11 +16,11 @@
import javafx.scene.layout.HBox;
import javafx.scene.text.Font;
import javafx.stage.Modality;
-import static mara.mybox.objects.AppVaribles.logger;
-import static mara.mybox.objects.AppVaribles.getMessage;
+import static mara.mybox.value.AppVaribles.logger;
+import static mara.mybox.value.AppVaribles.getMessage;
import mara.mybox.fxml.FxmlTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.fxml.FxmlTransformTools;
+import mara.mybox.fxml.image.FxmlTransformTools;
/**
* @Author Mara
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureViewController.java b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureViewController.java
index 1aa3a2f67..f83f193a2 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageManufactureViewController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageManufactureViewController.java
@@ -5,7 +5,7 @@
import javafx.fxml.FXML;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
-import static mara.mybox.objects.AppVaribles.logger;
+import static mara.mybox.value.AppVaribles.logger;
import mara.mybox.fxml.FxmlTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageMetaDataController.java b/MyBox/src/main/java/mara/mybox/controller/ImageMetaDataController.java
index 53580071a..47838e698 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageMetaDataController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageMetaDataController.java
@@ -9,8 +9,8 @@
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.ImageInformation;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.data.ImageInformation;
/**
* @Author Mara
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageSampleController.java b/MyBox/src/main/java/mara/mybox/controller/ImageSampleController.java
index c5c476e48..b82c4d6de 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageSampleController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageSampleController.java
@@ -10,10 +10,8 @@
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Task;
-import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Cursor;
-import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
@@ -26,15 +24,15 @@
import javafx.scene.paint.Color;
import javafx.stage.FileChooser;
import javafx.stage.Modality;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.fxml.FxmlScopeTools;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.fxml.image.FxmlScopeTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.imagefile.ImageFileReaders;
-import mara.mybox.imagefile.ImageFileWriters;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.IntRectangle;
+import mara.mybox.image.file.ImageFileReaders;
+import mara.mybox.image.file.ImageFileWriters;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.value.CommonValues;
+import mara.mybox.data.IntRectangle;
import mara.mybox.tools.FileTools;
/**
@@ -47,15 +45,12 @@ public class ImageSampleController extends ImageViewerController {
private double scale;
private int sampleWidth, sampleHeight;
- private boolean isSettingValues;
@FXML
private ToolBar opBar;
@FXML
private HBox cropBox, sampleBox, showBox;
@FXML
- private Button saveButton;
- @FXML
private CheckBox viewCheck;
@FXML
private ComboBox widthBox, heightBox;
@@ -177,8 +172,8 @@ private void checkSample() {
getMessage("ImageSize") + ": "
+ imageInformation.getWidth() + "x" + imageInformation.getHeight()
+ " " + getMessage("SampledSize") + ": "
- + (int) ((cropRightX - cropLeftX) / sampleWidth)
- + "x" + (int) ((cropRightY - cropLeftY) / sampleHeight));
+ + (int) ((cropRightX - cropLeftX + 1) / sampleWidth)
+ + "x" + (int) ((cropRightY - cropLeftY + 1) / sampleHeight));
}
}
@@ -215,7 +210,7 @@ private void checkCropValues() {
try {
cropRightX = Integer.valueOf(cropRightXInput.getText());
- if (cropRightX >= 0 && cropRightX <= imageInformation.getWidth()) {
+ if (cropRightX >= 0 && cropRightX < imageInformation.getWidth()) {
cropRightXInput.setStyle(null);
} else {
cropRightXInput.setStyle(badStyle);
@@ -263,14 +258,18 @@ private void indicateCropScope() {
@Override
protected Void call() throws Exception {
try {
- int lineWidth = 1;
- if (image.getWidth() >= 200) {
- lineWidth = (int) image.getWidth() / 200;
+ final Image newImage;
+ if (isWholeImage(image)) {
+ newImage = image;
+ } else {
+ int lineWidth = 1;
+ if (image.getWidth() >= 200) {
+ lineWidth = (int) image.getWidth() / 200;
+ }
+ newImage = FxmlScopeTools.indicateRectangle(image, Color.RED, lineWidth,
+ new IntRectangle((int) (cropLeftX / scale), (int) (cropLeftY / scale),
+ (int) (cropRightX / scale), (int) (cropRightY / scale)));
}
- final Image newImage = FxmlScopeTools.indicateRectangle(image,
- Color.RED, lineWidth,
- new IntRectangle((int) (cropLeftX / scale), (int) (cropLeftY / scale),
- (int) (cropRightX / scale), (int) (cropRightY / scale)));
if (task.isCancelled()) {
return null;
}
@@ -278,7 +277,7 @@ protected Void call() throws Exception {
@Override
public void run() {
imageView.setImage(newImage);
-// popInformation(AppVaribles.getMessage("CropComments"));
+// infoAction(AppVaribles.getMessage("CropComments"));
}
});
} catch (Exception e) {
@@ -388,24 +387,28 @@ public void clickImage(MouseEvent event) {
}
@FXML
- private void allAction(ActionEvent event) {
+ @Override
+ public void selectAllAction() {
isSettingValues = true;
cropLeftXInput.setText("0");
cropLeftYInput.setText("0");
- cropRightXInput.setText(imageInformation.getWidth() + "");
- cropRightYInput.setText(imageInformation.getHeight() + "");
+ cropRightXInput.setText((imageInformation.getWidth() - 1) + "");
+ cropRightYInput.setText((imageInformation.getHeight() - 1) + "");
isSettingValues = false;
checkCropValues();
}
@FXML
- public void saveAction(ActionEvent event) {
+ @Override
+ public void saveAction() {
if (image == null || sampleWidth < 1 || sampleHeight < 1) {
return;
}
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(targetPathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(targetPathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
final File file = fileChooser.showSaveDialog(getMyStage());
if (file == null) {
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageSourcesController.java b/MyBox/src/main/java/mara/mybox/controller/ImageSourcesController.java
index 7b7a366b8..ee490e0c3 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageSourcesController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageSourcesController.java
@@ -38,13 +38,13 @@
import javafx.stage.FileChooser;
import javafx.stage.Modality;
import javafx.util.Callback;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.imagefile.ImageFileReaders;
-import mara.mybox.objects.AppVaribles;
-import mara.mybox.objects.CommonValues;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.ImageFileInformation;
-import mara.mybox.objects.ImageInformation;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.image.file.ImageFileReaders;
+import mara.mybox.value.AppVaribles;
+import mara.mybox.value.CommonValues;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.data.ImageFileInformation;
+import mara.mybox.data.ImageInformation;
import mara.mybox.tools.ValueTools;
/**
@@ -56,13 +56,13 @@
public class ImageSourcesController extends ImageViewerController {
protected File targetFile;
- protected boolean isSettingValues, isOpenning;
+ protected boolean isOpenning;
protected SimpleBooleanProperty changed, hasSampled;
protected ObservableList sourceImages = FXCollections.observableArrayList();
@FXML
- protected Button saveButton, deleteButton, saveAsButton, insertButton, viewButton, clearButton;
+ protected Button saveAsButton, insertButton, viewButton, clearButton;
@FXML
protected TableView sourceTable;
@FXML
@@ -229,8 +229,10 @@ protected void createAction(ActionEvent event) {
}
sourceImages.clear();
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(sourcePathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(sourcePathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
final File file = fileChooser.showSaveDialog(getMyStage());
if (file == null) {
@@ -255,8 +257,10 @@ protected void openAction(ActionEvent event) {
return;
}
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(sourcePathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(sourcePathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
final File file = fileChooser.showOpenDialog(getMyStage());
if (file == null) {
@@ -299,6 +303,7 @@ protected boolean checkSaving() {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(getMyStage().getTitle());
alert.setContentText(AppVaribles.getMessage("ImageChanged"));
+ alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
ButtonType buttonSave = new ButtonType(AppVaribles.getMessage("Save"));
ButtonType buttonNotSave = new ButtonType(AppVaribles.getMessage("NotSave"));
ButtonType buttonCancel = new ButtonType(AppVaribles.getMessage("Cancel"));
@@ -350,11 +355,14 @@ protected boolean hasSampled() {
}
@FXML
- protected void saveAction() {
+ @Override
+ public void saveAction() {
if (targetFile == null) {
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(targetPathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(targetPathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
final File file = fileChooser.showSaveDialog(getMyStage());
if (file == null) {
@@ -373,8 +381,10 @@ protected void saveAsAction() {
return;
}
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(targetPathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(targetPathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
final File file = fileChooser.showSaveDialog(getMyStage());
if (file == null) {
@@ -432,8 +442,10 @@ protected void insertAction(ActionEvent event) {
protected void addAction(int index) {
try {
final FileChooser fileChooser = new FileChooser();
- File defaultPath = new File(AppVaribles.getUserConfigPath(sourcePathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(defaultPath);
+ File defaultPath = AppVaribles.getUserConfigPath(sourcePathKey);
+ if (defaultPath.exists()) {
+ fileChooser.setInitialDirectory(defaultPath);
+ }
fileChooser.getExtensionFilters().addAll(CommonValues.ImageExtensionFilter);
List files = fileChooser.showOpenMultipleDialog(getMyStage());
@@ -547,7 +559,8 @@ protected void loadFile(final File file, List infos) {
}
@FXML
- protected void deleteAction(ActionEvent event) {
+ @Override
+ public void deleteAction() {
List selected = new ArrayList<>();
selected.addAll(sourceTable.getSelectionModel().getSelectedIndices());
if (selected.isEmpty()) {
@@ -618,7 +631,8 @@ protected void downAction(ActionEvent event) {
}
@FXML
- protected void showInfo() {
+ @Override
+ public void infoAction() {
showImageInformation(sourceTable.getSelectionModel().getSelectedItem());
}
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageSplitController.java b/MyBox/src/main/java/mara/mybox/controller/ImageSplitController.java
index 038334c1a..4e3337cc5 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageSplitController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageSplitController.java
@@ -39,19 +39,19 @@
import javafx.scene.text.Font;
import javafx.stage.FileChooser;
import javafx.stage.Modality;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.image.ImageConvertTools;
-import mara.mybox.imagefile.ImageFileWriters;
-import mara.mybox.objects.AppVaribles;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.image.ImageConvert;
+import mara.mybox.image.file.ImageFileWriters;
+import mara.mybox.value.AppVaribles;
import mara.mybox.fxml.FxmlTools;
-import mara.mybox.fxml.FxmlImageTools;
+import mara.mybox.fxml.image.ImageTools;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.image.ImageValueTools;
-import mara.mybox.imagefile.ImageFileReaders;
-import mara.mybox.imagefile.ImageTiffFile;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.ImageAttributes;
+import mara.mybox.image.ImageValue;
+import mara.mybox.image.file.ImageFileReaders;
+import mara.mybox.image.file.ImageTiffFile;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.value.CommonValues;
+import mara.mybox.data.ImageAttributes;
import mara.mybox.tools.FileTools;
import mara.mybox.tools.PdfTools;
import mara.mybox.tools.PdfTools.PdfImageFormat;
@@ -69,7 +69,7 @@ public class ImageSplitController extends ImageViewerController {
private List rows, cols;
private int rowsNumber, colsNumber, width, height,
marginSize, pageWidth, pageHeight, jpegQuality, threshold;
- private boolean isImageSize, isSettingValues;
+ private boolean isImageSize;
private double scale;
private PdfImageFormat pdfFormat;
protected SimpleBooleanProperty splitValid;
@@ -86,12 +86,12 @@ public static enum SplitMethod {
@FXML
private ToggleGroup splitGroup, sizeGroup, formatGroup, colorGroup, compressionGroup, binaryGroup;
@FXML
- private Button imagesButton, tiffButton, pdfButton, okButton;
+ private Button imagesButton, tiffButton, pdfButton;
@FXML
private TextField rowsInput, colsInput, customizedRowsInput, customizedColsInput,
customWidthInput, customHeightInput, authorInput, pdfThresholdInput, headerInput, tiffThresholdInput;
@FXML
- private CheckBox displaySizeCheck, pageNumberCheck;
+ private CheckBox displaySizeCheck, pageNumberCheck, pdfDitherCheck, tiffDitherCheck;
@FXML
private ComboBox lineWidthBox;
@FXML
@@ -434,6 +434,8 @@ public void changed(ObservableValue extends String> observable,
}
});
+ FxmlTools.setComments(tiffDitherCheck, new Tooltip(getMessage("DitherComments")));
+
} catch (Exception e) {
logger.error(e.toString());
}
@@ -468,7 +470,7 @@ protected void setCompressionTypes() {
compressionBox.getChildren().clear();
compressionGroup = new ToggleGroup();
String[] compressionTypes
- = ImageValueTools.getCompressionTypes("tif", attributes.getColorSpace());
+ = ImageValue.getCompressionTypes("tif", attributes.getColorSpace());
for (String ctype : compressionTypes) {
if (ctype.equals("ZLib")) { // This type looks not work for mutiple frames tiff file
continue;
@@ -527,7 +529,7 @@ protected void checkTiffThreshold() {
return;
}
int inputValue = Integer.parseInt(tiffThresholdInput.getText());
- if (inputValue >= 0 && inputValue <= 100) {
+ if (inputValue >= 0 && inputValue <= 255) {
attributes.setThreshold(inputValue);
tiffThresholdInput.setStyle(null);
} else {
@@ -646,6 +648,8 @@ public void changed(ObservableValue extends String> observable, String oldValu
});
checkPdfThreshold();
+ FxmlTools.setComments(pdfDitherCheck, new Tooltip(getMessage("DitherComments")));
+
MarginsBox.getItems().addAll(Arrays.asList("20", "10", "15", "5", "25", "30"));
MarginsBox.valueProperty().addListener(new ChangeListener() {
@Override
@@ -877,7 +881,7 @@ private void checkPdfThreshold() {
return;
}
threshold = Integer.valueOf(pdfThresholdInput.getText());
- if (threshold >= 0 && threshold <= 100) {
+ if (threshold >= 0 && threshold <= 255) {
pdfThresholdInput.setStyle(null);
} else {
threshold = -1;
@@ -949,7 +953,8 @@ protected void handleSampledImage() {
}
@FXML
- private void okAction(ActionEvent event) {
+ @Override
+ public void okAction() {
if (splitMethod == SplitMethod.ByNumber) {
divideImageByNumber();
} else if (splitMethod == SplitMethod.BySize) {
@@ -1127,7 +1132,7 @@ private void indicateSplit() {
protected Void call() throws Exception {
ValueTools.sortList(rows);
ValueTools.sortList(cols);
- final Image newImage = FxmlImageTools.indicateSplit(image, rows, cols,
+ final Image newImage = ImageTools.indicateSplit(image, rows, cols,
lineColorPicker.getValue(), lineWidthBox.getValue(),
displaySizeCheck.isSelected(), scale);
if (task.isCancelled()) {
@@ -1171,6 +1176,7 @@ private File validationBeforeSave(List ext, String
alert.setTitle(getMyStage().getTitle());
alert.setContentText(AppVaribles.getMessage("SureSampled"));
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
+ alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
ButtonType buttonSure = new ButtonType(AppVaribles.getMessage("Sure"));
ButtonType buttonCancel = new ButtonType(AppVaribles.getMessage("Cancel"));
alert.getButtonTypes().setAll(buttonSure, buttonCancel);
@@ -1181,8 +1187,10 @@ private File validationBeforeSave(List ext, String
}
}
final FileChooser fileChooser = new FileChooser();
- File path = new File(AppVaribles.getUserConfigPath(targetPathKey, CommonValues.UserFilePath));
- fileChooser.setInitialDirectory(path);
+ File path = AppVaribles.getUserConfigPath(targetPathKey);
+ if (path.exists()) {
+ fileChooser.setInitialDirectory(path);
+ }
fileChooser.getExtensionFilters().addAll(ext);
if (diagTitle != null) {
fileChooser.setTitle(diagTitle);
@@ -1214,7 +1222,7 @@ protected Void call() throws Exception {
final String filename = sourceFile.getAbsolutePath();
BufferedImage wholeSource = null;
if (!imageInformation.isIsSampled()) {
- wholeSource = FxmlImageTools.getBufferedImage(image);
+ wholeSource = ImageTools.getBufferedImage(image);
}
for (int i = 0; i < rows.size() - 1; i++) {
if (task.isCancelled()) {
@@ -1232,7 +1240,7 @@ protected Void call() throws Exception {
if (imageInformation.isIsSampled()) {
target = ImageFileReaders.readRectangle(sourceFormat, filename, x1, y1, x2, y2);
} else {
- target = ImageConvertTools.cropImage(wholeSource, x1, y1, x2, y2);
+ target = ImageConvert.cropImage(wholeSource, x1, y1, x2, y2);
}
String fileName = filePrefix + "_"
+ (rows.size() - 1) + "x" + (cols.size() - 1) + "_"
@@ -1271,6 +1279,7 @@ private void saveAsPdfAction() {
protected Void call() throws Exception {
final String sourceFormat = imageInformation.getImageFormat();
final String sourcefile = sourceFile.getAbsolutePath();
+ attributes.setIsDithering(pdfDitherCheck.isSelected());
ok = PdfTools.writeSplitImages(sourceFormat, sourcefile, imageInformation,
rows, cols, attributes, targetFile,
pdfFormat, fontBox.getSelectionModel().getSelectedItem(), authorInput.getText(),
@@ -1316,6 +1325,7 @@ private void saveAsTiffAction(ActionEvent event) {
protected Void call() throws Exception {
final String sourceFormat = imageInformation.getImageFormat();
final String filename = sourceFile.getAbsolutePath();
+ attributes.setIsDithering(tiffDitherCheck.isSelected());
ok = ImageTiffFile.writeSplitImages(sourceFormat, filename,
imageInformation, rows, cols, attributes, targetFile);
if (task.isCancelled()) {
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageStatisticController.java b/MyBox/src/main/java/mara/mybox/controller/ImageStatisticController.java
new file mode 100644
index 000000000..52855f3d0
--- /dev/null
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageStatisticController.java
@@ -0,0 +1,420 @@
+package mara.mybox.controller;
+
+import java.util.Arrays;
+import java.util.List;
+import javafx.application.Platform;
+import javafx.beans.binding.Bindings;
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import javafx.concurrent.Task;
+import javafx.fxml.FXML;
+import javafx.scene.chart.BarChart;
+import javafx.scene.chart.NumberAxis;
+import javafx.scene.chart.PieChart;
+import javafx.scene.control.CheckBox;
+import javafx.scene.control.ComboBox;
+import javafx.scene.control.ContentDisplay;
+import javafx.scene.control.Tab;
+import javafx.scene.control.TabPane;
+import javafx.scene.control.TableCell;
+import javafx.scene.control.TableColumn;
+import javafx.scene.control.TableView;
+import javafx.scene.control.ToolBar;
+import javafx.scene.control.Tooltip;
+import javafx.scene.control.cell.PropertyValueFactory;
+import javafx.scene.paint.Color;
+import javafx.scene.shape.Rectangle;
+import javafx.scene.text.Font;
+import javafx.scene.text.Text;
+import javafx.stage.Modality;
+import javafx.util.Callback;
+import mara.mybox.fxml.FxmlTools;
+import mara.mybox.fxml.image.ImageQuantization;
+import mara.mybox.image.ImageColor;
+import mara.mybox.image.ImageQuantization.QuantizationAlgorithm;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import static mara.mybox.value.AppVaribles.logger;
+import mara.mybox.data.IntStatistic;
+
+/**
+ * @Author Mara
+ * @CreateDate 2018-10-12
+ * @Description
+ * @License Apache License Version 2.0
+ */
+public class ImageStatisticController extends ImageViewerController {
+
+ final private String ImageStatisticHueStages, ImageStatisticSaturationStages,
+ ImageStatisticBrightnessStages, ImageStatisticDataNumber;
+ private int paletteSize;
+
+ protected ObservableList colorList = FXCollections.observableArrayList();
+ protected ObservableList colorSummaryList = FXCollections.observableArrayList();
+ protected ObservableList greyList = FXCollections.observableArrayList();
+ protected ObservableList redList = FXCollections.observableArrayList();
+ protected ObservableList blueList = FXCollections.observableArrayList();
+ protected ObservableList greenList = FXCollections.observableArrayList();
+ protected ObservableList hueList = FXCollections.observableArrayList();
+ protected ObservableList saturationList = FXCollections.observableArrayList();
+ protected ObservableList brightnessList = FXCollections.observableArrayList();
+ protected ObservableList opacityList = FXCollections.observableArrayList();
+
+ @FXML
+ protected TabPane tabPane;
+ @FXML
+ protected Tab imageTab, histogramTab;
+ @FXML
+ protected BarChart greyHistogram, redHistogram, blueHistogram, greenHistogram,
+ opacityHistogram, hueHistogram, saturationHistogram, brightnessHistogram;
+ @FXML
+ protected PieChart colorPie;
+ @FXML
+ protected ComboBox paletteBox, algorithmBox;
+ @FXML
+ protected NumberAxis grayY;
+ @FXML
+ private TableView colorTable, colorSummaryTable, greyTable, redTable, blueTable, greenTable,
+ hueTable, saturationTable, brightnessTable, opacityTable;
+ @FXML
+ private TableColumn colorSummaryNameColumn,
+ greyNameColumn,
+ redValueColumn, redNameColumn,
+ blueValueColumn, blueNameColumn, greenValueColumn, greenNameColumn, hueValueColumn, hueNameColumn,
+ saturationValueColumn, saturationNameColumn, brightnessValueColumn, brightnessNameColumn,
+ opacityValueColumn, opacityNameColumn;
+ @FXML
+ private TableColumn colorSequenceColumn, colorValueColumn, colorNumberColumn, colorShowcaseColumn,
+ colorSummaryValueColumn, colorSummaryShowcaseColumn, colorSummaryNumberColumn,
+ greyValueColumn, greyNumberColumn, greyShowcaseColumn,
+ redNumberColumn, blueNumberColumn, greenNumberColumn,
+ hueNumberColumn, saturationNumberColumn, brightnessNumberColumn, opacityNumberColumn;
+ @FXML
+ private TableColumn colorPercentageColumn, colorSummaryPercentageColumn,
+ greyPercentageColumn;
+ @FXML
+ private CheckBox ditheringCheck;
+ @FXML
+ private ToolBar colorBar;
+
+ public ImageStatisticController() {
+ ImageStatisticHueStages = "ImageStatisticHueStages";
+ ImageStatisticSaturationStages = "ImageStatisticSaturationStages";
+ ImageStatisticBrightnessStages = "ImageStatisticBrightnessStages";
+ ImageStatisticDataNumber = "ImageStatisticDataNumber";
+ }
+
+ @Override
+ protected void initializeNext2() {
+ try {
+ tabPane.disableProperty().bind(
+ Bindings.isNull(imageView.imageProperty())
+ );
+ imageView.requestFocus();
+
+ initColorTab();
+ initGreyTab();
+
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
+ }
+
+ private void initColorTab() {
+
+ Tooltip tips = new Tooltip(getMessage("QuantizationComments"));
+ tips.setFont(new Font(16));
+ FxmlTools.setComments(colorBar, tips);
+
+ FxmlTools.setComments(ditheringCheck, new Tooltip(getMessage("DitherComments")));
+
+ colorTable.setItems(colorList);
+ colorValueColumn.setCellValueFactory(new PropertyValueFactory("value"));
+// colorValueColumn.setCellFactory(new Callback, TableCell>() {
+// @Override
+// public TableCell call(TableColumn param) {
+// String name = (String) param.getColumns().get(0);
+// return new ValueCell();
+// }
+// });
+ colorShowcaseColumn.setCellValueFactory(new PropertyValueFactory("value"));
+ colorShowcaseColumn.setCellFactory(new Callback, TableCell>() {
+ @Override
+ public TableCell call(TableColumn param) {
+ return new ShowcaseCell();
+ }
+ });
+ colorNumberColumn.setCellValueFactory(new PropertyValueFactory("number"));
+ colorSequenceColumn.setCellValueFactory(new PropertyValueFactory("value2"));
+ colorPercentageColumn.setCellValueFactory(new PropertyValueFactory("percentage"));
+
+ colorSummaryTable.setItems(colorSummaryList);
+ colorSummaryValueColumn.setCellValueFactory(new PropertyValueFactory("value"));
+ colorSummaryValueColumn.setCellFactory(new Callback, TableCell>() {
+ @Override
+ public TableCell call(TableColumn param) {
+ return new ValueCell();
+ }
+ });
+ colorSummaryShowcaseColumn.setCellValueFactory(new PropertyValueFactory("value"));
+ colorSummaryShowcaseColumn.setCellFactory(new Callback, TableCell>() {
+ @Override
+ public TableCell call(TableColumn param) {
+ return new ShowcaseCell();
+ }
+ });
+ colorSummaryNameColumn.setCellValueFactory(new PropertyValueFactory("name"));
+ colorSummaryNameColumn.setCellFactory(new Callback, TableCell>() {
+ @Override
+ public TableCell call(TableColumn param) {
+ return new NameCell();
+ }
+ });
+ colorSummaryNumberColumn.setCellValueFactory(new PropertyValueFactory("number"));
+ colorSummaryPercentageColumn.setCellValueFactory(new PropertyValueFactory("percentage"));
+
+ List aList = Arrays.asList(
+ getMessage("RGBUniformQuantization"), getMessage("HSBUniformQuantization"));
+ algorithmBox.getItems().addAll(aList);
+ algorithmBox.getSelectionModel().select(getMessage("RGBUniformQuantization"));
+
+ List paletteList = Arrays.asList(
+ "512", "64", "8", "4096", "216", "343", "27", "125", "1000", "729", "1728", "8000");
+ paletteBox.getItems().addAll(paletteList);
+ paletteBox.valueProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue ov, String oldValue, String newValue) {
+ try {
+ paletteSize = Integer.valueOf(newValue);
+ } catch (Exception e) {
+ }
+ }
+ });
+ paletteBox.getSelectionModel().select("512");
+
+ }
+
+ private void initGreyTab() {
+ greyTable.setItems(greyList);
+ greyValueColumn.setCellValueFactory(new PropertyValueFactory("value"));
+ greyValueColumn.setCellFactory(new Callback, TableCell>() {
+ @Override
+ public TableCell call(TableColumn param) {
+ return new ValueCell();
+ }
+ });
+ greyShowcaseColumn.setCellValueFactory(new PropertyValueFactory("value"));
+ greyShowcaseColumn.setCellFactory(new Callback, TableCell>() {
+ @Override
+ public TableCell call(TableColumn param) {
+ return new ShowcaseCell();
+ }
+ });
+ greyNameColumn.setCellValueFactory(new PropertyValueFactory("name"));
+ greyNameColumn.setCellFactory(new Callback, TableCell>() {
+ @Override
+ public TableCell call(TableColumn param) {
+ return new NameCell();
+ }
+ });
+ greyNumberColumn.setCellValueFactory(new PropertyValueFactory("number"));
+ greyPercentageColumn.setCellValueFactory(new PropertyValueFactory("percentage"));
+
+ }
+
+ private class ValueCell extends TableCell {
+
+ @Override
+ protected void updateItem(final Integer item, boolean empty) {
+ super.updateItem(item, empty);
+ if (item == null || item < 0 || empty) {
+ setText("");
+ } else {
+ if (item > 255) {
+ setText(ImageColor.pixel2hex(item));
+ } else {
+ setText(item + "");
+ }
+ }
+ }
+ }
+
+ private class ShowcaseCell extends TableCell {
+
+ private final Rectangle rectangle;
+
+ {
+ setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
+ rectangle = new Rectangle(30, 20);
+ }
+
+ @Override
+ protected void updateItem(final Integer item, boolean empty) {
+ super.updateItem(item, empty);
+ if (item == null || item < 0 || empty) {
+ setGraphic(null);
+ } else {
+ if (item > 255) {
+ rectangle.setFill(ImageColor.converColor(new java.awt.Color(item)));
+ setGraphic(rectangle);
+ } else {
+ double grey = item / 255.0;
+ rectangle.setFill(new Color(grey, grey, grey, 1.0));
+ setGraphic(rectangle);
+ }
+
+ }
+ }
+
+ }
+
+ private class NameCell extends TableCell {
+
+ final Text text = new Text();
+
+ @Override
+ protected void updateItem(final String item, boolean empty) {
+ super.updateItem(item, empty);
+ if (item != null && !empty) {
+ text.setText(AppVaribles.getMessage(item));
+ setGraphic(text);
+ }
+ }
+ }
+
+ @Override
+ public void afterImageLoaded() {
+ try {
+ super.afterImageLoaded();
+ if (image == null) {
+ return;
+ }
+ makeStatistic();
+ } catch (Exception e) {
+ logger.error(e.toString());
+ imageView.setImage(null);
+ alertInformation(AppVaribles.getMessage("NotSupported"));
+ }
+ }
+
+ @FXML
+ public void colorAction() {
+ makeStatistic();
+ }
+
+ // https://stackoverflow.com/questions/15219334/javafx-change-piechart-color
+ private void makeStatistic() {
+ QuantizationAlgorithm algorithm;
+ switch (algorithmBox.getSelectionModel().getSelectedIndex()) {
+ case 0:
+ algorithm = QuantizationAlgorithm.RGB_Uniform;
+ break;
+ case 1:
+ algorithm = QuantizationAlgorithm.HSB_Uniform;
+ break;
+ case 4:
+ algorithm = QuantizationAlgorithm.Statistic;
+ break;
+ case 5:
+ algorithm = QuantizationAlgorithm.kMeansClustering;
+ break;
+ case 6:
+ algorithm = QuantizationAlgorithm.ANN;
+ break;
+ default:
+ return;
+ }
+ int channelSize = (int) Math.round(Math.pow(paletteSize, 1.0 / 3.0));
+ final ImageQuantization quantization = new ImageQuantization(image);
+ quantization.set(algorithm, channelSize);
+ quantization.setIsDithering(ditheringCheck.isSelected());
+
+ colorList.clear();
+ colorSummaryList.clear();
+ greyList.clear();
+ redList.clear();
+ blueList.clear();
+ opacityList.clear();
+ greenList.clear();
+ hueList.clear();
+ saturationList.clear();
+ brightnessList.clear();
+
+ colorPie.getData().clear();
+ greyHistogram.getData().clear();
+ redHistogram.getData().clear();
+ blueHistogram.getData().clear();
+ opacityHistogram.getData().clear();
+ greenHistogram.getData().clear();
+ hueHistogram.getData().clear();
+ saturationHistogram.getData().clear();
+ brightnessHistogram.getData().clear();
+
+ task = new Task() {
+ @Override
+ protected Void call() throws Exception {
+ try {
+// ImageStatistic statistic = new ImageStatistic(SwingFXUtils.fromFXImage(image, null), quantization);
+// final Map statisticMap = statistic.statistic();
+// if (task.isCancelled() || statisticMap == null) {
+// return null;
+// }
+ Platform.runLater(new Runnable() {
+ @Override
+ public void run() {
+// Map statistic = (Map) statisticMap.get("colorQuantization");
+// colorList.addAll((List) statistic.get("data"));
+// ObservableList pieChartData = FXCollections.observableArrayList();
+// for (int i = 0; i < colorList.size(); i++) {
+// IntStatistic s = colorList.get(i);
+// if (s.getPercentage() < 1) {
+// break;
+// }
+// pieChartData.add(new PieChart.Data(s.getPercentage() + "% "
+// + ImageColor.pixel2hex(colorList.get(i).getValue()), s.getNumber()));
+// }
+// colorPie.getData().addAll(pieChartData);
+// for (int i = 0; i < pieChartData.size(); i++) {
+// PieChart.Data d = pieChartData.get(i);
+// d.getNode().setStyle("-fx-pie-color: " + ImageColor.pixel2hex(colorList.get(i).getValue()) + ";"
+// );
+// } // Must set colors after chart generated
+// colorSummaryList.add((IntStatistic) statistic.get("size"));
+// colorSummaryList.add((IntStatistic) statistic.get("sum"));
+// colorSummaryList.add((IntStatistic) statistic.get("mode"));
+// colorSummaryList.add((IntStatistic) statistic.get("median"));
+// colorSummaryList.add((IntStatistic) statistic.get("mean"));
+// colorSummaryList.add((IntStatistic) statistic.get("variance"));
+//
+// statistic = (Map) statisticMap.get("grey");
+// greyList.addAll((List) statistic.get("data"));
+// XYChart.Series series = new XYChart.Series();
+// for (int i = 0; i < greyList.size(); i++) {
+// IntStatistic s = greyList.get(i);
+// series.getData().add(new XYChart.Data(s.getValue() + "", s.getNumber()));
+// }
+// greyHistogram.getData().addAll(series);
+// IntStatistic.setDesc(greyList); // Must sort after historgram generated
+
+// greyList.add(0, (IntStatistic) statistic.get("maximum"));
+// greyList.add(0, (IntStatistic) statistic.get("minimum"));
+// greyList.add(0, (IntStatistic) statistic.get("median"));
+// greyList.add(0, (IntStatistic) statistic.get("average"));
+// greyList.add(0, (IntStatistic) statistic.get("sum"));
+ }
+ });
+ } catch (Exception e) {
+ logger.debug(e.toString());
+ }
+ return null;
+ }
+ };
+ openHandlingStage(task, Modality.WINDOW_MODAL);
+ Thread thread = new Thread(task);
+ thread.setDaemon(true);
+ thread.start();
+ }
+
+}
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageTiffEditerController.java b/MyBox/src/main/java/mara/mybox/controller/ImageTiffEditerController.java
index 5c1f5e1c5..c515a3bcb 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageTiffEditerController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageTiffEditerController.java
@@ -13,14 +13,14 @@
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.HBox;
import javafx.stage.Modality;
-import static mara.mybox.objects.AppVaribles.logger;
+import static mara.mybox.value.AppVaribles.logger;
import static mara.mybox.fxml.FxmlTools.badStyle;
-import mara.mybox.image.ImageValueTools;
-import mara.mybox.imagefile.ImageTiffFile;
-import mara.mybox.objects.AppVaribles;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import mara.mybox.objects.CommonValues;
-import mara.mybox.objects.ImageAttributes;
+import mara.mybox.image.ImageValue;
+import mara.mybox.image.file.ImageTiffFile;
+import mara.mybox.value.AppVaribles;
+import static mara.mybox.value.AppVaribles.getMessage;
+import mara.mybox.value.CommonValues;
+import mara.mybox.data.ImageAttributes;
import org.apache.pdfbox.rendering.ImageType;
/**
@@ -126,7 +126,7 @@ protected void setCompressionTypes() {
compressionBox.getChildren().clear();
compressionGroup = new ToggleGroup();
String[] compressionTypes
- = ImageValueTools.getCompressionTypes("tif", attributes.getColorSpace());
+ = ImageValue.getCompressionTypes("tif", attributes.getColorSpace());
for (String ctype : compressionTypes) {
if (ctype.equals("ZLib")) { // This type looks not work for mutiple frames tiff file
continue;
@@ -185,7 +185,7 @@ protected void checkThreshold() {
return;
}
int inputValue = Integer.parseInt(thresholdInput.getText());
- if (inputValue >= 0 && inputValue <= 100) {
+ if (inputValue >= 0 && inputValue <= 255) {
attributes.setThreshold(inputValue);
thresholdInput.setStyle(null);
} else {
diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageViewerController.java b/MyBox/src/main/java/mara/mybox/controller/ImageViewerController.java
index ce5bdb6b9..62ac839a4 100644
--- a/MyBox/src/main/java/mara/mybox/controller/ImageViewerController.java
+++ b/MyBox/src/main/java/mara/mybox/controller/ImageViewerController.java
@@ -1,53 +1,74 @@
package mara.mybox.controller;
+import com.sun.javafx.charts.Legend;
+import mara.mybox.fxml.FxmlStage;
import java.awt.image.BufferedImage;
import java.io.File;
import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
import javafx.concurrent.Task;
+import javafx.embed.swing.SwingFXUtils;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.Cursor;
+import javafx.scene.Node;
+import javafx.scene.chart.BarChart;
+import javafx.scene.chart.XYChart;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
+import javafx.scene.control.CheckBox;
+import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
+import javafx.scene.control.SplitPane;
+import javafx.scene.control.TableCell;
+import javafx.scene.control.TableColumn;
+import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.ToolBar;
-import javafx.scene.control.Tooltip;
+import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.Image;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
-import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
-import javafx.scene.text.Font;
+import javafx.scene.shape.Rectangle;
+import javafx.scene.text.Text;
import javafx.stage.FileChooser;
import javafx.stage.Modality;
-import mara.mybox.fxml.FxmlImageTools;
-import mara.mybox.fxml.FxmlScopeTools;
-import mara.mybox.objects.AppVaribles;
-import mara.mybox.objects.CommonValues;
+import javafx.util.Callback;
+import mara.mybox.fxml.image.ImageTools;
+import mara.mybox.fxml.image.FxmlScopeTools;
+import mara.mybox.value.AppVaribles;
+import mara.mybox.value.CommonValues;
import mara.mybox.tools.FileTools;
import mara.mybox.fxml.FxmlTools;
-import mara.mybox.imagefile.ImageFileWriters;
-import static mara.mybox.objects.AppVaribles.getMessage;
-import static mara.mybox.objects.AppVaribles.logger;
-import mara.mybox.objects.IntRectangle;
+import mara.mybox.image.file.ImageFileWriters;
+import mara.mybox.data.ImageFileInformation;
+import mara.mybox.data.IntRectangle;
+import mara.mybox.data.IntStatistic;
+import mara.mybox.fxml.FxmlColor;
+import mara.mybox.image.ImageStatistic;
+import static mara.mybox.value.AppVaribles.getMessage;
+import static mara.mybox.value.AppVaribles.logger;
/**
* @Author Mara
@@ -57,89 +78,181 @@
*/
public class ImageViewerController extends ImageBaseController {
+ final protected String ConfirmDeleteKey, OpenAfterSaveKey, SelectKey;
+
protected double mouseX, mouseY;
protected int xZoomStep = 50, yZoomStep = 50;
protected int currentAngle = 0, rotateAngle = 90;
protected File nextFile, previousFile;
protected int cropLeftX, cropLeftY, cropRightX, cropRightY;
+ protected ObservableList statisticList = FXCollections.observableArrayList();
+ protected Map colorTable;
+
@FXML
protected TextField imageFile;
@FXML
- protected HBox sourceBox, opeBox;
+ protected HBox operation1Box, operation2Box, operation3Box, navBox;
@FXML
protected VBox contentBox;
@FXML
- protected Button iButton, mButton, gButton, pButton, inButton, outButton, lButton, rButton,
- previousButton, nextButton, wButton, oButton,
- tButton, sButton, mrButton, mlButton, upButton, downButton, infoButton, metaButton,
- cropButton, selectAllButton, copySelectionButton;
- @FXML
- protected ToolBar toolbar, navBar, infoBar, selectionBar, cropBar;
+ protected Button upButton, downButton, renameButton, metaButton, manufactureButton, statisticButton;
@FXML
protected ToggleGroup sortGroup;
+ @FXML
+ protected CheckBox cropCheck, deleteConfirmCheck, openSaveCheck;
+ @FXML
+ protected SplitPane splitPane;
+ @FXML
+ protected CheckBox dataCheck, greyHistCheck, redHistCheck, greenHistCheck, blueHistCheck, alphaHistCheck,
+ hueHistCheck, saturationHistCheck, brightnessHistCheck;
+ @FXML
+ protected SplitPane dataPane;
+ @FXML
+ protected TableView dataTable;
+ @FXML
+ protected TableColumn colorColumn;
+ @FXML
+ protected TableColumn meanColumn, varianceColumn,
+ skewnessColumn, maximumColumn, minimumColumn, modeColumn;
+ @FXML
+ protected BarChart histogramChart;
+ @FXML
+ protected ToolBar manuBar;
public ImageViewerController() {
-
+ ConfirmDeleteKey = "ImageConfirmDeleteKey";
+ OpenAfterSaveKey = "ImageOpenAfterSaveKey";
+ SelectKey = "ImageSelectKey";
+ TipsLabelKey = "ImageViewerTips";
}
@Override
protected void initializeNext() {
try {
- if (imageView != null) {
- if (toolbar != null) {
- toolbar.disableProperty().bind(
- Bindings.isNull(imageView.imageProperty())
- );
- }
+ initOperation1Box();
+ initOperation2Box();
+ initOperation3Box();
+ initImageView();
+ initDataPane();
+ initializeNext2();
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
+ }
- if (opeBox != null) {
- opeBox.disableProperty().bind(
- Bindings.isNull(imageView.imageProperty())
- );
+ protected void initOperation1Box() {
+ if (operation1Box != null) {
+ operation1Box.disableProperty().bind(
+ Bindings.isNull(imageView.imageProperty())
+ );
+ }
+
+ if (openSaveCheck != null) {
+ openSaveCheck.selectedProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue ov, Boolean oldValue, Boolean newValue) {
+ AppVaribles.setUserConfigValue(OpenAfterSaveKey, openSaveCheck.isSelected());
+ }
+ });
+ openSaveCheck.setSelected(AppVaribles.getUserConfigBoolean(OpenAfterSaveKey, false));
+ }
+ if (deleteConfirmCheck != null) {
+ deleteConfirmCheck.selectedProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue ov, Boolean oldValue, Boolean newValue) {
+ AppVaribles.setUserConfigValue(ConfirmDeleteKey, deleteConfirmCheck.isSelected());
}
+ });
+ deleteConfirmCheck.setSelected(AppVaribles.getUserConfigBoolean(ConfirmDeleteKey, true));
+ }
- if (scrollPane != null) {
- imageView.fitHeightProperty().addListener(new ChangeListener() {
- @Override
- public void changed(ObservableValue extends Number> ov, Number old_val, Number new_val) {
- moveCenter();
- }
- });
- scrollPane.heightProperty().addListener(new ChangeListener() {
- @Override
- public void changed(ObservableValue extends Number> ov, Number old_val, Number new_val) {
- if (Math.abs(imageView.getFitHeight() - old_val.doubleValue()) < 20) {
- paneSize();
- }
- moveCenter();
- }
- });
- scrollPane.widthProperty().addListener(new ChangeListener() {
- @Override
- public void changed(ObservableValue extends Number> ov, Number old_val, Number new_val) {
- moveCenter();
- }
- });
+ }
+
+ protected void initOperation2Box() {
+
+ if (operation2Box != null) {
+ operation2Box.disableProperty().bind(
+ Bindings.isNull(imageView.imageProperty())
+ );
+ }
+
+ if (cropCheck != null) {
+ cropCheck.selectedProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue ov, Boolean oldValue, Boolean newValue) {
+ AppVaribles.setUserConfigValue(SelectKey, cropCheck.isSelected());
+ checkSelect();
}
- }
+ });
+ cropCheck.setSelected(AppVaribles.getUserConfigBoolean(SelectKey, true));
+ checkSelect();
+ }
+
+ }
+
+ protected void initOperation3Box() {
+
+ if (navBox != null) {
+ navBox.setDisable(true);
+ }
+
+ if (manufactureButton != null) {
+ manufactureButton.setDisable(true);
+ }
+
+ if (manuBar != null) {
+ manuBar.disableProperty().bind(
+ Bindings.isNull(imageView.imageProperty())
+ );
+ }
- if (copySelectionButton != null) {
- Tooltip tips = new Tooltip("CTRL+c");
- tips.setFont(new Font(16));
- FxmlTools.quickTooltip(copySelectionButton, tips);
+ }
+
+ protected void initImageView() {
+ if (imageView == null || scrollPane == null) {
+ return;
+ }
+
+ imageView.fitHeightProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue extends Number> ov, Number old_val, Number new_val) {
+ moveCenter();
}
- if (cropButton != null) {
- Tooltip tips = new Tooltip(getMessage("CropLabel"));
- tips.setFont(new Font(16));
- FxmlTools.quickTooltip(cropButton, tips);
+ });
+ scrollPane.heightProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue extends Number> ov, Number old_val, Number new_val) {
+ if (Math.abs(imageView.getFitHeight() - old_val.doubleValue()) < 20) {
+ paneSize();
+ }
+ moveCenter();
}
+ });
+ scrollPane.widthProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue extends Number> ov, Number old_val, Number new_val) {
+ moveCenter();
+ }
+ });
- initializeNext2();
+ }
- } catch (Exception e) {
- logger.error(e.toString());
+ protected void checkSelect() {
+ if (image == null || cropCheck == null) {
+ return;
+ }
+ if (!cropCheck.isSelected()) {
+ imageView.setImage(image);
+ FxmlTools.removeTooltip(imageView);
+ bottomLabel.setText("");
+ } else {
+ selectAllAction();
+
+ bottomLabel.setText(getMessage("CropLabel"));
}
+ selectAllButton.setDisable(!cropCheck.isSelected());
+
}
public void moveCenter() {
@@ -154,6 +267,381 @@ public void moveCenter() {
}
}
+ protected void initDataPane() {
+ try {
+ if (dataCheck == null || dataPane == null) {
+ return;
+ }
+ splitPane.disableProperty().bind(
+ Bindings.isNull(imageView.imageProperty())
+ );
+
+ dataCheck.selectedProperty().addListener(new ChangeListener() {
+ @Override
+ public void changed(ObservableValue extends Boolean> ov, Boolean old_val, Boolean new_val) {
+ if (isSettingValues) {
+ return;
+ }
+ loadDataBox();
+ AppVaribles.setUserConfigValue("ImageDataShow", new_val);
+ }
+ });
+ isSettingValues = true;
+ dataCheck.setSelected(AppVaribles.getUserConfigBoolean("ImageDataShow", true));
+ isSettingValues = false;
+ loadDataBox();
+
+ dataTable.setItems(statisticList);
+ colorColumn.setCellValueFactory(new PropertyValueFactory("name"));
+ colorColumn.setCellFactory(new Callback, TableCell>() {
+ @Override
+ public TableCell call(TableColumn param) {
+ return new NameCell();
+ }
+ });
+ meanColumn.setCellValueFactory(new PropertyValueFactory("mean"));
+ meanColumn.setCellFactory(new Callback, TableCell>() {
+ @Override
+ public TableCell call(TableColumn param) {
+ return new ColorCell();
+ }
+ });
+ varianceColumn.setCellValueFactory(new PropertyValueFactory("variance"));
+ skewnessColumn.setCellValueFactory(new PropertyValueFactory("skewness"));
+ maximumColumn.setCellValueFactory(new PropertyValueFactory("maximum"));
+ maximumColumn.setCellFactory(new Callback, TableCell>() {
+ @Override
+ public TableCell call(TableColumn param) {
+ return new ColorCell();
+ }
+ });
+ minimumColumn.setCellValueFactory(new PropertyValueFactory("minimum"));
+ minimumColumn.setCellFactory(new Callback, TableCell>() {
+ @Override
+ public TableCell call(TableColumn