-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from c-eg/settings-page
Settings page
- Loading branch information
Showing
8 changed files
with
466 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/uk/co/conoregan/showrenamer/controller/NavigationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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<String, Scene> 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/main/java/uk/co/conoregan/showrenamer/controller/SettingsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.