Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework fxweaver #3

Merged
merged 2 commits into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added screenshots/file_commander_screenshot-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 1 addition & 5 deletions src/main/java/com/commander/PrimaryStageInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,20 @@
public class PrimaryStageInitializer implements ApplicationListener<com.commander.StageReadyEvent> {

private final FxWeaver fxWeaver;
private final int height;
private final int width;

@Value("${application.ui.title}")
private String title;

@Autowired
public PrimaryStageInitializer(FxWeaver fxWeaver) {
this.fxWeaver = fxWeaver;
this.height = 600;
this.width = 900;
}

@Override
public void onApplicationEvent(com.commander.StageReadyEvent event) {
Stage stage = event.stage;
stage.setTitle(title);
Scene scene = new Scene(fxWeaver.loadView(RootController.class), width, height);
Scene scene = new Scene(fxWeaver.loadView(RootController.class));
stage.setScene(scene);
stage.setResizable(false);
stage.show();
Expand Down
44 changes: 14 additions & 30 deletions src/main/java/com/commander/controller/DragDropController.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,11 @@ public class DragDropController {
private FileService fileService;
private ConvertService convertService;
private User user;
private ObservableList<Label> observableList;
private ListView<Label> listView;
private final ObservableList<Label> observableList;
private final ListView<Label> listView;

StringProperty obsSrcDirectory = new SimpleStringProperty();
StringProperty obsTrgtDirectory = new SimpleStringProperty();
StringProperty obsTextDocPref = new SimpleStringProperty();
StringProperty obsExcelDocPref = new SimpleStringProperty();
StringProperty obsImgTypePref = new SimpleStringProperty();

@FXML
private ScrollPane scrollPane;
Expand All @@ -81,12 +78,6 @@ public class DragDropController {
private BorderPane rootPane2;
@FXML
private Button runConvertButton;
@FXML
private Label wordPrefLabel;
@FXML
private Label imagePrefLabel;
@FXML
private Label excelPrefLabel;

private HostServices hostServices;

Expand Down Expand Up @@ -185,27 +176,27 @@ private void handleSelectedItemConvert(ActionEvent event) {

@FXML
public void initialize() {
HashMap<String, Object> resourceBundle = new HashMap<>();
resourceBundle.put("delete.policy", user.getSourceFilePolicy());
resourceBundle.put("default.bg.color", user.getReplaceBgColor());

if (Objects.nonNull(user)) {
//Bind reactive preference values
wordPrefLabel.textProperty().bind(obsTextDocPref);
excelPrefLabel.textProperty().bind(obsExcelDocPref);
imagePrefLabel.textProperty().bind(obsImgTypePref);

superDirectoryLabel.textProperty().bind(obsSrcDirectory);
outputDirPathLbl.textProperty().bind(obsTrgtDirectory);

Converter.setResources(resourceBundle);


setPreferencesViewer();
setLabels();
initListView();
updateSrcFileAndBgColorPreference();
}
}

protected void updateSrcFileAndBgColorPreference() {
HashMap<String, Object> resourceBundle = new HashMap<>();
resourceBundle.put("delete.policy", user.getSourceFilePolicy());
resourceBundle.put("default.bg.color", user.getReplaceBgColor());

Converter.setResources(resourceBundle);

}

/**
* {@code initListView()} handles updating and populating the ListView with files
* from the users source file directory. It also, configures the Drag and Drop
Expand Down Expand Up @@ -288,13 +279,6 @@ private void loadFilesList() {
}, null);
}

void setPreferencesViewer() {

obsTextDocPref.set(user.getDocPreference().getDocOperation());
obsExcelDocPref.set(user.getExcelPreference().getExtension());
obsImgTypePref.set(user.getImgPreference().getExtension());
}

/**
* {@code setLabels()} Initializes the clickable Labels and event listeners for the
* source directory and output directory.
Expand Down Expand Up @@ -354,7 +338,7 @@ private void setHostServices(@SuppressWarnings("SpringJavaInjectionPointsAutowir

protected void handleUpdatePreferences() {
loadFilesList();
setPreferencesViewer();
setLabels();
}

}
50 changes: 33 additions & 17 deletions src/main/java/com/commander/controller/RootController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.commander.service.FileService;
import com.commander.utils.Constants;
import com.commander.utils.DialogHelper;
import com.jfoenix.controls.JFXSnackbar;
import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.event.ActionEvent;
Expand Down Expand Up @@ -83,8 +82,6 @@ public class RootController {
@FXML
private TextField outputPathTextField;
@FXML
private Button saveButton;
@FXML
private ComboBox<String> prefsComboBox;
@FXML
private ComboBox<String> textDocPrefsComboBox;
Expand Down Expand Up @@ -152,7 +149,9 @@ private void configComboBoxes() {
private void handleSrcFilePrefChanged(ActionEvent event) {
String pref = prefsComboBox.getSelectionModel().getSelectedItem();
user.setSourceFilePolicy(pref);

updatePreferenceValues("Source file handling policy changed to " + user.getSourceFilePolicy() + " the file " +
"after conversion.");
dragDropController.getController().updateSrcFileAndBgColorPreference();
}

/**
Expand All @@ -172,22 +171,23 @@ private void handleTextDocPrefChanged(ActionEvent actionEvent) {
user.setDocPreference(DocOperation.DOCX_TO_PDF);

}
updatePreferenceValues("Text document file type preference changed to " + user.getDocPreference().getDocOperation());

}

/**
* {@code handleSaveButton()}
* {@code updatePreferenceValues(String message)}
*
* @param event User pressed Save button
* @param message to display on updating preferences
*/
@FXML
private void handleSaveButton(ActionEvent event) {
try {
user.setPreferences();
private void updatePreferenceValues(String message) {

Boolean success = user.setPreferences();
if (success) {
dragDropController.getController().handleUpdatePreferences();
DialogHelper.snackbarToast(rootPane, "Your preferences have been saved");
} catch (Exception e3) {
DialogHelper.snackbarToast(rootPane, message);
} else {
DialogHelper.showErrorAlert("Something went wrong,\nWe're not able to save your preferences.");
e3.printStackTrace();
}

}
Expand Down Expand Up @@ -218,7 +218,8 @@ private void handleAssignDirectory(ActionEvent event) {
String strPath = result.getAbsolutePath();
user.setDirectoryPath(strPath);
directoryPathTextField.setText(strPath);
dragDropController.getController().setLabels();

updatePreferenceValues("Source folder updated.");

}
}
Expand All @@ -235,24 +236,27 @@ private void handleAssignOutputDirectory(ActionEvent actionEvent) {
File result = directoryChooser.showDialog(new Stage());
if (result == null && user.getWriteDirectoryPath() == null) {
DialogHelper.showErrorAlert(
"Please assign an output directory to write new files into, before moving on.");
"Please assign an output directory to write new files into, before running conversions.");

} else if (result != null) {
String writePath = result.getAbsolutePath();
user.setWriteDirectoryPath(writePath);
outputPathTextField.setText(writePath);

updatePreferenceValues("Output folder updated.");

}
}

@FXML
private void handleExitPressed(ActionEvent event) {
fileService.onClose();
updatePreferenceValues("Saving user preferences before exiting...");
Platform.exit();
}

/**
* Configures GUI labels and textfield saved values.
* Configures GUI labels and text field saved values.
*/
private void setProjectLabels() {

Expand All @@ -267,8 +271,11 @@ private void setProjectLabels() {
private void handleColorChanged(ActionEvent actionEvent) {
Color colorChoice = bgColorPicker.getValue();
user.setReplaceBgColor(colorChoice);
updatePreferenceValues("Background color to use when image does not support transparency updated.");
dragDropController.getController().updateSrcFileAndBgColorPreference();
}


/**
* Triggers Welcome message Pop-Up if User.nuUser evaluates to true
*/
Expand Down Expand Up @@ -333,6 +340,11 @@ private void configRadioButtonGroups() {
} else {
throw new UnsupportedOperationException("Something unexpected happened while setting the Excel preference radio buttons");
}
if (oldValue != newValue) {
updatePreferenceValues("Excel file type preference changed to " + user.getExcelPreference().getExtension());

}

});

jpgRadioButton.setToggleGroup(imgGroup);
Expand All @@ -348,14 +360,18 @@ private void configRadioButtonGroups() {
user.setImgPreference(DocType.JPG);
} else if (imgChoice.getText().equalsIgnoreCase(DocType.BMP.getExtension())) {
user.setImgPreference(DocType.BMP);

} else if (imgChoice.getText().equalsIgnoreCase(DocType.GIF.getExtension())) {
user.setImgPreference(DocType.GIF);
} else if (imgChoice.getText().equalsIgnoreCase(DocType.PNG.getExtension())) {
user.setImgPreference(DocType.PNG);
} else {
throw new UnsupportedOperationException("We were unable to process your image preference selection.");
}
if (oldValue != newValue) {
updatePreferenceValues("Image file type preference changed to " + user.getImgPreference().getExtension().toUpperCase());


}

});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,6 @@ static boolean handleTransBg(BufferedImage srcImage, String imgFormat, File out)
return res;
}

// /**
// * Handle trans support boolean.
// *
// * @param srcImage the src image
// * @param imgFormat the img format
// * @param out the out
// * @return the boolean
// * @throws IOException the io exception
// * @throws IllegalArgumentException the illegal argument exception
// */
// static boolean handleTransSupport(BufferedImage srcImage, String imgFormat, File out) throws IOException, IllegalArgumentException {
// log.info("Attempting manual conversion with alpha channel (transparent background)");
// java.awt.Color transparency = new java.awt.Color(0,0,0,0);
//
// graphic.dispose();
//
// return res;
// }

/**
* Handle simple img convert boolean.
*
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/commander/utils/DialogHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,17 @@ public static void snackbarToast(Pane pane, String message) {
VBox vbox = new VBox();
Label label = new Label(message);
label.setFont(Font.font("SansSerif", FontWeight.BOLD, 16.0));
label.setTextFill(Color.MIDNIGHTBLUE);
label.setTextFill(Color.DARKSLATEBLUE);
label.setTextAlignment(TextAlignment.CENTER);
label.setAlignment(Pos.CENTER);
label.setWrapText(true);
label.setPrefSize(500, 100);
vbox.autosize();
label.setBackground(new Background(new BackgroundFill(new Color(0.2, 0.1, 0.3, 0.1),
new CornerRadii(3.5),
Insets.EMPTY)));
new Insets(3.5))));
vbox.getChildren().add(label);
final JFXSnackbar.SnackbarEvent snackbarEvent = new JFXSnackbar.SnackbarEvent(vbox, Duration.seconds(3.33), null);
final JFXSnackbar.SnackbarEvent snackbarEvent = new JFXSnackbar.SnackbarEvent(vbox, Duration.seconds(1.33),
null);
snackbar.enqueue(snackbarEvent);

}
Expand Down
Loading