Skip to content

Commit

Permalink
v2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
Mararsh committed Aug 11, 2018
1 parent 49ae808 commit 7caf8ca
Show file tree
Hide file tree
Showing 37 changed files with 1,938 additions and 352 deletions.
2 changes: 1 addition & 1 deletion MyBox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>mara</groupId>
<artifactId>MyBox</artifactId>
<version>2.9</version>
<version>2.10</version>
<packaging>jar</packaging>

<name>MyBox</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class AboutController extends BaseController {

@Override
protected void initializeNext() {
version.setText(CommonValues.AppVersion + "");
version.setText(CommonValues.AppVersion);
date.setText(CommonValues.AppVersionDate);

task = new Task<Void>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,18 @@ protected void edit(AlarmClock alarm) {
saveButton.setText(getMessage("Save"));
}

@Override
public boolean stageClosing() {
// logger.debug("stageClosing");
if (player != null) {
player.stop();
player.drain();
player.close();
player = null;
}
return super.stageClosing();
}

public boolean isIsEdit() {
return isEdit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void handle(MouseEvent event) {
@FXML
private void clearAction(ActionEvent event) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(AppVaribles.getMessage("AppTitle"));
alert.setTitle(getBaseTitle());
alert.setContentText(AppVaribles.getMessage("SureClearAlarmClocks"));
Optional<ButtonType> result = alert.showAndWait();
if (result.get() != ButtonType.OK) {
Expand Down
27 changes: 25 additions & 2 deletions MyBox/src/main/java/mara/mybox/controller/BaseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ public void reloadStage(String newFxml, String title) {
// return;
// }
// }
// logger.debug("reloadStage:" + getClass());
if (!stageReloading()) {
return;
}
Expand Down Expand Up @@ -484,7 +485,7 @@ public boolean stageClosing() {

if (task != null && task.isRunning()) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(AppVaribles.getMessage("AppTitle"));
alert.setTitle(getMyStage().getTitle());
alert.setContentText(AppVaribles.getMessage("TaskRunning"));
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK && task != null) {
Expand Down Expand Up @@ -543,7 +544,7 @@ public boolean stageClosing() {
public void popInformation(String information) {
try {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle(AppVaribles.getMessage("AppTitle"));
alert.setTitle(getMyStage().getTitle());
alert.setHeaderText(null);
alert.setContentText(information);
alert.showAndWait();
Expand Down Expand Up @@ -609,6 +610,28 @@ public void showImageManufacture(String filename) {
}
}

public Stage openHandlingStage(Modality block) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.LoadingFxml), AppVaribles.CurrentBundle);
Pane pane = fxmlLoader.load();
LoadingController controller = fxmlLoader.getController();

final Stage loadingStage = new Stage();
loadingStage.initModality(block);
// loadingStage.initStyle(StageStyle.UNDECORATED);
loadingStage.initStyle(StageStyle.TRANSPARENT);
loadingStage.initOwner(getMyStage());
loadingStage.setScene(new Scene(pane));
loadingStage.show();

return loadingStage;

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

public void openHandlingStage(final Task<?> task, Modality block) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.LoadingFxml), AppVaribles.CurrentBundle);
Expand Down
77 changes: 54 additions & 23 deletions MyBox/src/main/java/mara/mybox/controller/HtmlEditorController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
Expand All @@ -15,7 +16,6 @@
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.InputEvent;
import javafx.scene.web.HTMLEditor;
import javafx.scene.web.WebView;
Expand All @@ -29,10 +29,12 @@
* @Description
* @License Apache License Version 2.0
*/
public class HtmlEditorController extends BaseController {
public class HtmlEditorController extends TextEditorController {

private final String HtmlFilePathKey;
private int cols, rows;
protected int lastHtmlLen;
private boolean isSettingValues;

@FXML
private Button saveButton, openButton, createButton;
Expand All @@ -43,8 +45,6 @@ public class HtmlEditorController extends BaseController {
@FXML
private TextArea textArea;
@FXML
protected TextField bottomText;
@FXML
private TabPane tabPane;
@FXML
protected Tab editorTab, codesTab;
Expand All @@ -62,32 +62,62 @@ public HtmlEditorController() {
}

@Override

protected void initializeNext() {
try {
htmlEdior.addEventHandler(InputEvent.ANY, new EventHandler<InputEvent>() {
@Override
public void handle(InputEvent event) {
bottomText.setText(AppVaribles.getMessage("Total") + ": " + htmlEdior.getHtmlText().length());
int len = htmlEdior.getHtmlText().length();
if (!isSettingValues && len != lastHtmlLen) {
fileChanged.set(true);
}
lastHtmlLen = len;
bottomText.setText(AppVaribles.getMessage("Total") + ": " + len);
}
});

textArea.addEventHandler(InputEvent.ANY, new EventHandler<InputEvent>() {
@Override
public void handle(InputEvent event) {
bottomText.setText(AppVaribles.getMessage("Total") + ": " + textArea.getText().length());
int len = textArea.getText().length();
if (!isSettingValues && len != lastTextLen) {
fileChanged.set(true);
}
lastTextLen = len;
bottomText.setText(AppVaribles.getMessage("Total") + ": " + len);
}
});

tabPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Tab>() {
@Override
public void changed(ObservableValue<? extends Tab> observable,
Tab oldValue, Tab newValue) {
isSettingValues = true;
if (AppVaribles.getMessage("Editor").equals(newValue.getText())) {
htmlEdior.setHtmlText(textArea.getText());
} else {
textArea.setText(htmlEdior.getHtmlText());
}
isSettingValues = false;
}
});

fileChanged = new SimpleBooleanProperty(false);
fileChanged.addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> ov, Boolean old_val, Boolean new_val) {
if (isSettingValues) {
return;
}
String t = getBaseTitle();
if (sourceFile != null) {
t += " " + sourceFile.getAbsolutePath();
}
if (fileChanged.getValue()) {
getMyStage().setTitle(t + "*");
} else {
getMyStage().setTitle(t);
}
}
});

Expand All @@ -100,6 +130,7 @@ public void changed(ObservableValue<? extends Tab> observable,
@FXML
private void openAction(ActionEvent event) {
try {
isSettingValues = true;
// sourceFile = null;
// htmlEdior.setHtmlText("");
final FileChooser fileChooser = new FileChooser();
Expand Down Expand Up @@ -132,7 +163,9 @@ private void openAction(ActionEvent event) {
} else {
textArea.setText(contents.toString());
}
getMyStage().setTitle(AppVaribles.getMessage("AppTitle") + " " + sourceFile.getAbsolutePath());
fileChanged.set(false);
getMyStage().setTitle(getBaseTitle() + " " + sourceFile.getAbsolutePath());
isSettingValues = false;

} catch (Exception e) {
logger.error(e.toString());
Expand All @@ -141,8 +174,9 @@ private void openAction(ActionEvent event) {
}

@FXML
private void saveAction(ActionEvent event) {
private void saveAction() {
try {
isSettingValues = true;
if (sourceFile == null) {
final FileChooser fileChooser = new FileChooser();
File path = new File(AppVaribles.getConfigValue(HtmlFilePathKey, System.getProperty("user.home")));
Expand All @@ -166,7 +200,9 @@ private void saveAction(ActionEvent event) {
out.write(contents);
out.flush();
}
getMyStage().setTitle(AppVaribles.getMessage("AppTitle") + " " + sourceFile.getAbsolutePath());
fileChanged.set(false);
getMyStage().setTitle(getBaseTitle() + " " + sourceFile.getAbsolutePath());
isSettingValues = false;
} catch (Exception e) {
logger.error(e.toString());
}
Expand All @@ -176,6 +212,7 @@ private void saveAction(ActionEvent event) {
@FXML
private void saveAsAction(ActionEvent event) {
try {
isSettingValues = true;
final FileChooser fileChooser = new FileChooser();
File path = new File(AppVaribles.getConfigValue(HtmlFilePathKey, System.getProperty("user.home")));
fileChooser.setInitialDirectory(path);
Expand All @@ -197,7 +234,9 @@ private void saveAsAction(ActionEvent event) {
out.write(contents);
out.flush();
}
getMyStage().setTitle(AppVaribles.getMessage("AppTitle") + " " + sourceFile.getAbsolutePath());
fileChanged.set(false);
getMyStage().setTitle(getBaseTitle() + " " + sourceFile.getAbsolutePath());
isSettingValues = false;
} catch (Exception e) {
logger.error(e.toString());
}
Expand All @@ -207,20 +246,12 @@ private void saveAsAction(ActionEvent event) {
@FXML
private void createAction(ActionEvent event) {
try {
isSettingValues = true;
sourceFile = null;
htmlEdior.setHtmlText("");
final FileChooser fileChooser = new FileChooser();
File path = new File(AppVaribles.getConfigValue(HtmlFilePathKey, System.getProperty("user.home")));
fileChooser.setInitialDirectory(path);
fileChooser.getExtensionFilters().addAll(fileExtensionFilter);
final File file = fileChooser.showSaveDialog(getMyStage());
if (file == null) {
return;
}
AppVaribles.setConfigValue("LastPath", file.getParent());
AppVaribles.setConfigValue(HtmlFilePathKey, file.getParent());
sourceFile = file;
getMyStage().setTitle(AppVaribles.getMessage("AppTitle") + " " + sourceFile.getAbsolutePath());
fileChanged.set(false);
getMyStage().setTitle(getBaseTitle());
isSettingValues = false;
} catch (Exception e) {
logger.error(e.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected void doCurrentProcess() {
public void loadImage(final File file, final boolean onlyInformation) {
sourceFile = file;
final String fileName = file.getPath();
task = new Task<Void>() {
Task loadTask = new Task<Void>() {
@Override
protected Void call() throws Exception {
imageInformation = ImageFileReaders.readImageMetaData(fileName);
Expand All @@ -135,8 +135,8 @@ public void run() {
return null;
}
};
openHandlingStage(task, Modality.WINDOW_MODAL);
Thread thread = new Thread(task);
openHandlingStage(loadTask, Modality.WINDOW_MODAL);
Thread thread = new Thread(loadTask);
thread.setDaemon(true);
thread.start();
}
Expand Down
Loading

0 comments on commit 7caf8ca

Please sign in to comment.