From a8416c66d079f7f21c7fb2d4a572d61368ab27c1 Mon Sep 17 00:00:00 2001 From: Conor Egan <68134729+c-eg@users.noreply.github.com> Date: Fri, 5 May 2023 21:55:08 +0100 Subject: [PATCH 1/2] small refactor --- .../conoregan/showrenamer/ShowRenamerApplication.java | 10 +++++----- .../co/conoregan/showrenamer/ShowRenamerLauncher.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/uk/co/conoregan/showrenamer/ShowRenamerApplication.java b/src/main/java/uk/co/conoregan/showrenamer/ShowRenamerApplication.java index d3d8c1d..8688c2d 100644 --- a/src/main/java/uk/co/conoregan/showrenamer/ShowRenamerApplication.java +++ b/src/main/java/uk/co/conoregan/showrenamer/ShowRenamerApplication.java @@ -50,7 +50,7 @@ public class ShowRenamerApplication extends Application { * * @param args the ags. */ - public static void main(String[] args) { + public static void main(final String[] args) { launch(args); } @@ -58,13 +58,13 @@ public static void main(String[] args) { * @inheritDoc */ @Override - public void start(Stage primaryStage) throws Exception { - final Parent root = FXMLLoader.load(ShowRenamerApplication.class.getResource("/view/rename.fxml")); - final Scene scene = new Scene(root, WIDTH, HEIGHT); - + public void start(final Stage primaryStage) throws Exception { primaryStage.setMinWidth(WIDTH); primaryStage.setMinHeight(HEIGHT); primaryStage.setTitle("Show Renamer"); + + final Parent root = FXMLLoader.load(ShowRenamerApplication.class.getResource("/view/rename.fxml")); + final Scene scene = new Scene(root); primaryStage.setScene(scene); final Image appIcon = new Image(ShowRenamerApplication.class.getResourceAsStream("/images/show-renamer-icon.png")); diff --git a/src/main/java/uk/co/conoregan/showrenamer/ShowRenamerLauncher.java b/src/main/java/uk/co/conoregan/showrenamer/ShowRenamerLauncher.java index 138f88a..055d839 100644 --- a/src/main/java/uk/co/conoregan/showrenamer/ShowRenamerLauncher.java +++ b/src/main/java/uk/co/conoregan/showrenamer/ShowRenamerLauncher.java @@ -28,7 +28,7 @@ public class ShowRenamerLauncher { * * @param args the args. */ - public static void main(String[] args) { + public static void main(final String[] args) { ShowRenamerApplication.main(args); } } \ No newline at end of file From d011800c69e8b813931229a8e28c9d10b1777128 Mon Sep 17 00:00:00 2001 From: Conor Egan <68134729+c-eg@users.noreply.github.com> Date: Fri, 5 May 2023 21:56:11 +0100 Subject: [PATCH 2/2] settings page + navigation + small improvements --- .../controller/NavigationController.java | 68 +++++++ .../controller/RenameController.java | 40 ++-- .../controller/SettingsController.java | 101 ++++++++++ src/main/resources/style/style.css | 63 +++++- src/main/resources/view/rename.fxml | 20 +- src/main/resources/view/settings.fxml | 190 ++++++++++++++++++ 6 files changed, 460 insertions(+), 22 deletions(-) create mode 100644 src/main/java/uk/co/conoregan/showrenamer/controller/NavigationController.java create mode 100644 src/main/java/uk/co/conoregan/showrenamer/controller/SettingsController.java create mode 100644 src/main/resources/view/settings.fxml diff --git a/src/main/java/uk/co/conoregan/showrenamer/controller/NavigationController.java b/src/main/java/uk/co/conoregan/showrenamer/controller/NavigationController.java new file mode 100644 index 0000000..1a7bb31 --- /dev/null +++ b/src/main/java/uk/co/conoregan/showrenamer/controller/NavigationController.java @@ -0,0 +1,68 @@ +/* + * This file is part of ShowRenamer. + * + * ShowRenamer is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ShowRenamer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ShowRenamer. If not, see . + */ + +package uk.co.conoregan.showrenamer.controller; + +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +import javax.annotation.Nonnull; +import java.io.IOException; +import java.util.HashMap; + +/** + * The navigation controller, to be extended by JavaFX controllers to navigate to other scenes (pages). + */ +public class NavigationController { + /** + * The path to the .fxml files. + */ + private static final String VIEW_PATH = "/view/"; + + /** + * The scene mapping cache. + */ + private static final HashMap SCENE_MAP = new HashMap<>(); + + /** + * Changes the scene on the stage passed. + * + * @param fxml the fxml file to load, e.g. "rename". + * @param stage the stage to set the scene on. + * @throws IOException thrown if fxml file is not found. + */ + public static void changeScene(@Nonnull final String fxml, @Nonnull final Stage stage) throws IOException { + Scene scene = SCENE_MAP.get(fxml); + + // load if not in map + if (scene == null) { + final Parent root = FXMLLoader.load(NavigationController.class.getResource(VIEW_PATH + fxml + ".fxml")); + scene = new Scene(root); + SCENE_MAP.put(fxml, scene); + } + + // keep height and width from current scene. + final double currentHeight = stage.getHeight(); + final double currentWidth = stage.getWidth(); + + stage.setScene(scene); + stage.setHeight(currentHeight); + stage.setWidth(currentWidth); + } +} diff --git a/src/main/java/uk/co/conoregan/showrenamer/controller/RenameController.java b/src/main/java/uk/co/conoregan/showrenamer/controller/RenameController.java index 7839c51..fcc9614 100644 --- a/src/main/java/uk/co/conoregan/showrenamer/controller/RenameController.java +++ b/src/main/java/uk/co/conoregan/showrenamer/controller/RenameController.java @@ -21,8 +21,10 @@ import javafx.collections.FXCollections; import javafx.collections.MapChangeListener; import javafx.collections.ObservableMap; +import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; +import javafx.scene.Node; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.ListCell; @@ -32,6 +34,7 @@ import javafx.scene.input.TransferMode; import javafx.scene.layout.VBox; import javafx.stage.DirectoryChooser; +import javafx.stage.Stage; import javafx.stage.Window; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,7 +52,7 @@ /** * The JavaFX controller for the rename.fxml file. */ -public class RenameController implements Initializable { +public class RenameController extends NavigationController implements Initializable { /** * The logger. */ @@ -98,12 +101,6 @@ public class RenameController implements Initializable { @FXML private CheckBox checkboxIncludeSubFolder; - /** - * Checkbox to improve folder names. - */ - @FXML - private CheckBox checkboxImproveFolderNames; - /** * Button to get suggested file names. */ @@ -128,6 +125,18 @@ public class RenameController implements Initializable { @FXML private VBox vboxSuggestedTitles; + @FXML + private void navigateToRenamePage(final ActionEvent event) throws IOException { + final Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); + changeScene("rename", stage); + } + + @FXML + private void navigateToSettingsPage(final ActionEvent event) throws IOException { + final Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); + changeScene("settings", stage); + } + /** * Event to handle a files drag over event. * @@ -151,8 +160,7 @@ private void handleDragOverFileUpload(final DragEvent event) { */ @FXML private void handleDragDroppedFileUpload(final DragEvent event) { - final Dragboard dragboard = event.getDragboard(); - final List dragboardFiles = dragboard.getFiles(); + final List dragboardFiles = event.getDragboard().getFiles(); for (final File item : dragboardFiles) { addFile(item); @@ -163,8 +171,8 @@ private void handleDragDroppedFileUpload(final DragEvent event) { * Open file dialog to select files to be renamed. */ @FXML - private void openFileDialog() { - final Window window = checkboxIncludeSubFolder.getScene().getWindow(); + private void openFileDialog(final ActionEvent event) { + final Window window = ((Button) event.getSource()).getScene().getWindow(); final File dir = directoryChooser.showDialog(window); if (dir != null) { @@ -177,7 +185,7 @@ private void openFileDialog() { */ @FXML private void getSuggestions() { - for (Map.Entry entry : fileRenameMapping.entrySet()) { + for (final Map.Entry entry : fileRenameMapping.entrySet()) { final String fileNameWithoutExtension = getFileNameWithoutExtension(entry.getKey().getName()); /* @@ -211,7 +219,7 @@ private void clearAll() { */ @FXML public void saveAll() { - for (Map.Entry entry : fileRenameMapping.entrySet()) { + for (final Map.Entry entry : fileRenameMapping.entrySet()) { if (entry.getValue() == null) { LOGGER.info(String.format("Cannot rename: %s, no suggestion found.", entry.getKey().getName())); continue; @@ -235,12 +243,11 @@ public void saveAll() { * @inheritDoc */ @Override - public void initialize(URL url, ResourceBundle resourceBundle) { + public void initialize(final URL url, final ResourceBundle resourceBundle) { initializeConstructor(); // stops checkbox box resizing when clicking on and off other controls checkboxIncludeSubFolder.setFocusTraversable(false); - checkboxImproveFolderNames.setFocusTraversable(false); setListViewCellFactorySettings(listViewCurrentTitles); setListViewCellFactorySettings(listViewSuggestedTitles); @@ -251,7 +258,8 @@ public void initialize(URL url, ResourceBundle resourceBundle) { // update list views based on fileRenameMapping. fileRenameMapping.addListener((MapChangeListener) change -> { enableSectionCurrentTitles = !fileRenameMapping.keySet().isEmpty(); - enableSectionSuggestedTitles = !fileRenameMapping.values().isEmpty() && !fileRenameMapping.values().stream().allMatch(Objects::isNull); + enableSectionSuggestedTitles = !fileRenameMapping.values().isEmpty() && + !fileRenameMapping.values().stream().allMatch(Objects::isNull); vboxCurrentTitles.setDisable(!enableSectionCurrentTitles); vboxSuggestedTitles.setDisable(!enableSectionSuggestedTitles); diff --git a/src/main/java/uk/co/conoregan/showrenamer/controller/SettingsController.java b/src/main/java/uk/co/conoregan/showrenamer/controller/SettingsController.java new file mode 100644 index 0000000..739bbcd --- /dev/null +++ b/src/main/java/uk/co/conoregan/showrenamer/controller/SettingsController.java @@ -0,0 +1,101 @@ +/* + * This file is part of ShowRenamer. + * + * ShowRenamer is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ShowRenamer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ShowRenamer. If not, see . + */ + +package uk.co.conoregan.showrenamer.controller; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.scene.Node; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.URL; +import java.util.ResourceBundle; + +/** + * The JavaFX controller for the settings.fxml file. + */ +public class SettingsController extends NavigationController implements Initializable { + /** + * The logger. + */ + private static final Logger LOGGER = LoggerFactory.getLogger(SettingsController.class); + + private static final String SETTINGS_NAV_ACTIVE_CSS = "-fx-border-color: #3298e3;"; + + @FXML + private VBox vboxRenameFormat; + + @FXML + private VBox vboxAbout; + + @FXML + private Button buttonSettingsNavRenameFormat; + + @FXML + private Button buttonSettingsNavAbout; + + private Button buttonActiveSettingsNav; + + @FXML + private void navigateToRenamePage(final ActionEvent event) throws IOException { + final Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); + changeScene("rename", stage); + } + + @FXML + private void navigateToSettingsPage(final ActionEvent event) throws IOException { + final Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); + changeScene("settings", stage); + } + + /** + * @inheritDoc + */ + @Override + public void initialize(final URL location, final ResourceBundle resources) { + buttonSettingsNavRenameFormat.setStyle(SETTINGS_NAV_ACTIVE_CSS); + buttonActiveSettingsNav = buttonSettingsNavRenameFormat; + } + + @FXML + private void handleSettingsNavClick(final ActionEvent event) { + buttonActiveSettingsNav.setStyle(null); + + buttonActiveSettingsNav = (Button) event.getSource(); + buttonActiveSettingsNav.setStyle(SETTINGS_NAV_ACTIVE_CSS); + + if (buttonActiveSettingsNav.equals(buttonSettingsNavRenameFormat)) { + vboxRenameFormat.toFront(); + vboxRenameFormat.setVisible(true); + vboxAbout.setVisible(false); + } else if (buttonActiveSettingsNav.equals(buttonSettingsNavAbout)) { + vboxAbout.toFront(); + vboxAbout.setVisible(true); + vboxRenameFormat.setVisible(false); + } + } +} diff --git a/src/main/resources/style/style.css b/src/main/resources/style/style.css index 1f63902..98385ed 100644 --- a/src/main/resources/style/style.css +++ b/src/main/resources/style/style.css @@ -37,12 +37,22 @@ -fx-text-fill: #919191; } +.sub-heading { + -fx-font-weight: bold; + -fx-font-size: 18px; + -fx-text-fill: #919191; +} + .section-container { - -fx-padding: 40px 40px 40px 40px; + -fx-padding: 20px 40px 40px 40px; } .section-container-buttons { - -fx-padding: 40px 40px 20px 40px; + -fx-padding: 20px 40px 20px 40px; +} + +.section-nav { + -fx-padding: 40px 40px 0px 40px; } .section { @@ -98,6 +108,44 @@ -fx-background-color: #858383; } +.button-nav { + -fx-padding: 6px 40px; + -fx-background-radius: 20px; + -fx-background-color: #b8b8b8; + -fx-font-weight: bold; + -fx-font-size: 24px; + -fx-text-fill: #ffffff; +} + +.button-nav:hover { + -fx-background-color: #969696; + -fx-cursor: hand; +} + +.button-nav:pressed { + -fx-background-color: #858383; +} + +.button-nav-active { + -fx-background-color: #3298e3; +} + +.button-nav-active:hover { + -fx-background-color: #277ab8; + -fx-cursor: hand; +} + +.button-nav-active:pressed { + -fx-background-color: #146fb3; +} + +.text-field { + -fx-background-radius: 15px; + -fx-background-color: #f5f5f5; + -fx-border-radius: 15px; + -fx-border-color: #919191; +} + .check-box { -fx-text-fill: #727272; -fx-padding: 6px 0; @@ -164,3 +212,14 @@ #label-upload { -fx-font-size: 25px; } + +.button-settings-nav { + -fx-padding: 10px 40px 10px 20px; + -fx-border-color: rgba(255, 255, 255, 0); + -fx-border-width: 3px; + -fx-border-radius: 15px; +} + +.button-settings-nav:hover { + -fx-cursor: hand; +} diff --git a/src/main/resources/view/rename.fxml b/src/main/resources/view/rename.fxml index 13ebf99..4d88e5b 100644 --- a/src/main/resources/view/rename.fxml +++ b/src/main/resources/view/rename.fxml @@ -16,7 +16,20 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +