From d9ccb3a90aa4c5964c96dbe9297bb879245d8019 Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Wed, 15 Sep 2021 04:30:18 +0300 Subject: [PATCH] Refactoring. Quickly looked and remove some dumb things in IPC part. Align package/classes names to some appropriate naming convention, move PlayerToolbar to separate FXML+controller. --- src/META-INF/MANIFEST.MF | 3 - .../IPC/SingleInstanceHandler.java | 50 ------- src/main/java/mplayer4anime/MainFX.java | 30 ++-- .../java/mplayer4anime/MediatorControl.java | 39 +++-- .../{IPC => ipc}/ServerSocketProvider.java | 27 ++-- .../ipc/SingleInstanceHandler.java | 72 ++++++++++ .../mplayer4anime/mplayer/MplayerSlave.java | 2 +- .../java/mplayer4anime/mpv/MpvProcess.java | 2 +- .../{Playlists => playlists}/JsonStorage.java | 2 +- .../{Playlists => playlists}/Playlists.java | 4 +- .../mplayer4anime/{ => ui}/ServiceWindow.java | 2 +- .../{About => ui/about}/AboutController.java | 2 +- .../{About => ui/about}/AboutWindow.java | 2 +- .../landing/LandingController.java} | 136 ++++-------------- .../ui/landing/PlayerToolbarController.java | 133 +++++++++++++++++ .../landing/panes}/ControllerPane.java | 2 +- .../panes/ControllerPaneSubtitles.java} | 4 +- .../settings}/ControllerListsSelector.java | 2 +- .../settings}/SettingsController.java | 4 +- .../settings}/SettingsWindow.java | 2 +- src/main/resources/About/AboutLayout.fxml | 2 +- .../{landingPage.fxml => LandingPage.fxml} | 77 +--------- src/main/resources/PlayerToolbar.fxml | 83 +++++++++++ src/main/resources/Settings/ListSelector.fxml | 2 +- .../resources/Settings/SettingsLayout.fxml | 2 +- src/main/resources/appPanes/genericPane.fxml | 2 +- src/main/resources/appPanes/subPane.fxml | 2 +- 27 files changed, 390 insertions(+), 300 deletions(-) delete mode 100644 src/META-INF/MANIFEST.MF delete mode 100644 src/main/java/mplayer4anime/IPC/SingleInstanceHandler.java rename src/main/java/mplayer4anime/{IPC => ipc}/ServerSocketProvider.java (70%) create mode 100644 src/main/java/mplayer4anime/ipc/SingleInstanceHandler.java rename src/main/java/mplayer4anime/{Playlists => playlists}/JsonStorage.java (96%) rename src/main/java/mplayer4anime/{Playlists => playlists}/Playlists.java (98%) rename src/main/java/mplayer4anime/{ => ui}/ServiceWindow.java (98%) rename src/main/java/mplayer4anime/{About => ui/about}/AboutController.java (98%) rename src/main/java/mplayer4anime/{About => ui/about}/AboutWindow.java (98%) rename src/main/java/mplayer4anime/{Controller.java => ui/landing/LandingController.java} (71%) create mode 100644 src/main/java/mplayer4anime/ui/landing/PlayerToolbarController.java rename src/main/java/mplayer4anime/{appPanes => ui/landing/panes}/ControllerPane.java (99%) rename src/main/java/mplayer4anime/{appPanes/ControllerSUB.java => ui/landing/panes/ControllerPaneSubtitles.java} (96%) rename src/main/java/mplayer4anime/{Settings => ui/settings}/ControllerListsSelector.java (99%) rename src/main/java/mplayer4anime/{Settings => ui/settings}/SettingsController.java (96%) rename src/main/java/mplayer4anime/{Settings => ui/settings}/SettingsWindow.java (98%) rename src/main/resources/{landingPage.fxml => LandingPage.fxml} (53%) create mode 100644 src/main/resources/PlayerToolbar.fxml diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF deleted file mode 100644 index dcd19b4..0000000 --- a/src/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Main-Class: mplayer4anime.Main - diff --git a/src/main/java/mplayer4anime/IPC/SingleInstanceHandler.java b/src/main/java/mplayer4anime/IPC/SingleInstanceHandler.java deleted file mode 100644 index 17bcd30..0000000 --- a/src/main/java/mplayer4anime/IPC/SingleInstanceHandler.java +++ /dev/null @@ -1,50 +0,0 @@ -package mplayer4anime.IPC; - -import mplayer4anime.Controller; - -import java.io.*; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; - -// TODO: Rewrite and remove. Or just remove. -public class SingleInstanceHandler implements Runnable{ - - private ServerSocket servSock; - - public SingleInstanceHandler(Controller mainCntrl, String argument){ - int PORT = 65042; - // Creating client server socket; - try { - servSock = new ServerSocket(PORT, 10, InetAddress.getLocalHost()); - Thread ssp = new Thread(new ServerSocketProvider(mainCntrl, servSock)); - ssp.start(); - } catch (IOException e) { - if (argument != null){ - // Creating client socket; - try { - Socket clientSocket = new Socket(InetAddress.getLocalHost(), PORT); - OutputStream outStream = clientSocket.getOutputStream(); - OutputStreamWriter outStreamWriter = new OutputStreamWriter(outStream); - outStreamWriter.write(argument + "\n"); - outStreamWriter.flush(); - outStream.close(); - clientSocket.close(); - } catch (IOException ex){ - System.out.println("Internal issue: unable to create client socket."); - } - } - else - System.out.println("Application is already running."); - System.exit(0); - } - } - - @Override - public void run() { - while (! Thread.currentThread().isInterrupted()); - try { - servSock.close(); - } catch (IOException ignore) {} - } -} \ No newline at end of file diff --git a/src/main/java/mplayer4anime/MainFX.java b/src/main/java/mplayer4anime/MainFX.java index a386294..e3fa904 100644 --- a/src/main/java/mplayer4anime/MainFX.java +++ b/src/main/java/mplayer4anime/MainFX.java @@ -24,7 +24,8 @@ import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.stage.Stage; -import mplayer4anime.IPC.SingleInstanceHandler; +import mplayer4anime.ipc.SingleInstanceHandler; +import mplayer4anime.ui.landing.LandingController; import java.util.Locale; import java.util.ResourceBundle; @@ -39,7 +40,7 @@ public class MainFX extends Application { @Override public void start(Stage primaryStage) throws Exception{ - FXMLLoader loader = new FXMLLoader(getClass().getResource("/landingPage.fxml")); + FXMLLoader loader = new FXMLLoader(getClass().getResource("/LandingPage.fxml")); Locale userLocale = new Locale(Locale.getDefault().getISO3Language()); // NOTE: user locale based on ISO3 Language codes ResourceBundle rb = ResourceBundle.getBundle("locale", userLocale); @@ -47,21 +48,14 @@ public class MainFX extends Application { Parent root = loader.load(); - // tmp? - Controller controller = loader.getController(); - controller.setHostServices(getHostServices()); - SingleInstanceHandler sih; + LandingController landingController = loader.getController(); + landingController.setHostServices(getHostServices()); + SingleInstanceHandler singleInstanceHandler; - if (!getParameters().getUnnamed().isEmpty()) - sih = new SingleInstanceHandler(controller, getParameters().getUnnamed().get(0)); + if (getParameters().getUnnamed().isEmpty()) + singleInstanceHandler = new SingleInstanceHandler(landingController, null); else - sih = new SingleInstanceHandler(controller, null); - // end - Thread tsih = new Thread(sih); - tsih.start(); - - // TODO: refactor needed? - Runtime.getRuntime().addShutdownHook(new Thread(() -> tsih.interrupt())); + singleInstanceHandler = new SingleInstanceHandler(landingController, getParameters().getUnnamed().get(0)); primaryStage.getIcons().addAll( new Image(getClass().getResourceAsStream("/res/app_icon32x32.png")), @@ -80,10 +74,10 @@ public class MainFX extends Application { primaryStage.setOnHidden(e -> { AppPreferences.getINSTANCE().setSceneHeight(scene.getHeight()); AppPreferences.getINSTANCE().setSceneWidth(scene.getWidth()); - tsih.interrupt(); - controller.shutdown(); + singleInstanceHandler.finishWork(); + landingController.shutdown(); }); - + //Runtime.getRuntime().addShutdownHook(new Thread(sihThread::interrupt)); primaryStage.show(); } } diff --git a/src/main/java/mplayer4anime/MediatorControl.java b/src/main/java/mplayer4anime/MediatorControl.java index 783e397..3731c3d 100644 --- a/src/main/java/mplayer4anime/MediatorControl.java +++ b/src/main/java/mplayer4anime/MediatorControl.java @@ -1,14 +1,30 @@ +/* + Copyright 2018-2021 Dmitry Isaenko + + This file is part of mplayer4anime. + + mplayer4anime 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. + + mplayer4anime 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 mplayer4anime. If not, see . + */ package mplayer4anime; -public class MediatorControl{ - private Controller mainController; +import mplayer4anime.ui.landing.LandingController; - public void registerMainController(Controller mc) { - mainController = mc; - } +public class MediatorControl { + private LandingController mainLandingController; - public void sentUpdates() { - mainController.updateAfterSettingsChanged(); + private static class MediatorControlHold { + private static final MediatorControl INSTANCE = new MediatorControl(); } private MediatorControl() {} @@ -17,7 +33,12 @@ public class MediatorControl{ return MediatorControlHold.INSTANCE; } - private static class MediatorControlHold { - private static final MediatorControl INSTANCE = new MediatorControl(); + public void registerMainController(LandingController mainLandingController) { + this.mainLandingController = mainLandingController; } + + public void updateAfterSettingsChanged() { + mainLandingController.updateAfterSettingsChanged(); + } + } diff --git a/src/main/java/mplayer4anime/IPC/ServerSocketProvider.java b/src/main/java/mplayer4anime/ipc/ServerSocketProvider.java similarity index 70% rename from src/main/java/mplayer4anime/IPC/ServerSocketProvider.java rename to src/main/java/mplayer4anime/ipc/ServerSocketProvider.java index 73a389b..0e547d0 100644 --- a/src/main/java/mplayer4anime/IPC/ServerSocketProvider.java +++ b/src/main/java/mplayer4anime/ipc/ServerSocketProvider.java @@ -16,10 +16,10 @@ You should have received a copy of the GNU General Public License along with mplayer4anime. If not, see . */ -package mplayer4anime.IPC; +package mplayer4anime.ipc; import javafx.application.Platform; -import mplayer4anime.Controller; +import mplayer4anime.ui.landing.LandingController; import java.io.BufferedReader; import java.io.IOException; @@ -30,38 +30,29 @@ import java.net.Socket; class ServerSocketProvider implements Runnable{ private final ServerSocket serverSocket; - private final Controller controller; + private final LandingController landingController; - ServerSocketProvider(Controller mainCntrl, ServerSocket srvSock){ + ServerSocketProvider(LandingController mainLandingController, ServerSocket srvSock){ this.serverSocket = srvSock; - this.controller = mainCntrl; + this.landingController = mainLandingController; } @Override public void run() { - Socket servSockClient; try{ + Socket servSockClient; while (!serverSocket.isClosed()){ servSockClient = serverSocket.accept(); BufferedReader servInpRdr = new BufferedReader( - new InputStreamReader(servSockClient.getInputStream()) - ); + new InputStreamReader(servSockClient.getInputStream())); String line = servInpRdr.readLine(); // Avoid 'Not on FX application thread' error. - Platform.runLater(new Runnable() { - @Override - public void run() { - controller.setPlaylistAsArgument(line); - } - }); + Platform.runLater(() -> landingController.setPlaylistAsArgument(line)); servSockClient.close(); } } - catch (IOException ex){ - ex.printStackTrace(); - System.out.println("Socket has been closed."); - } + catch (IOException ignore){} } } \ No newline at end of file diff --git a/src/main/java/mplayer4anime/ipc/SingleInstanceHandler.java b/src/main/java/mplayer4anime/ipc/SingleInstanceHandler.java new file mode 100644 index 0000000..20ea35f --- /dev/null +++ b/src/main/java/mplayer4anime/ipc/SingleInstanceHandler.java @@ -0,0 +1,72 @@ +package mplayer4anime.ipc; + +import mplayer4anime.ui.landing.LandingController; + +import java.io.*; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; + +// TODO: Rewrite and remove. Or just remove. +public class SingleInstanceHandler{ + private ServerSocket servSocket; + private final LandingController mainLandingController; + private final String argument; + + private final int PORT = 65042; + + public SingleInstanceHandler(LandingController mainLandingController, String argument){ + this.mainLandingController = mainLandingController; + this.argument = argument; + + if (firstInstanceScenario()) + secondInstanceScenario(); + } + + /** + * Creating client server socket; + * @return true of failure + * */ + private boolean firstInstanceScenario(){ + try { + servSocket = new ServerSocket(PORT, 10, InetAddress.getLocalHost()); + Thread ssp = new Thread(new ServerSocketProvider(mainLandingController, servSocket)); + ssp.start(); + return false; + } + catch (IOException ignored){ + return true; + } + } + /** + * If socked occupied then send arguments to the running instance + * */ + private void secondInstanceScenario(){ + try { + if (argument != null){ + // Creating client socket; + Socket clientSocket = new Socket(InetAddress.getLocalHost(), PORT); + OutputStream outStream = clientSocket.getOutputStream(); + OutputStreamWriter outStreamWriter = new OutputStreamWriter(outStream); + outStreamWriter.write(argument + "\n"); + outStreamWriter.flush(); + outStream.close(); + clientSocket.close(); + } + else + System.out.println("Application is already running."); + } + catch (IOException ex){ + ex.printStackTrace(); + System.out.println("Internal issue: unable to create client socket."); + } + + System.exit(0); + } + + public void finishWork(){ + try { + servSocket.close(); + } catch (IOException ignore) {} + } +} \ No newline at end of file diff --git a/src/main/java/mplayer4anime/mplayer/MplayerSlave.java b/src/main/java/mplayer4anime/mplayer/MplayerSlave.java index 5a7c653..8dc7e1c 100644 --- a/src/main/java/mplayer4anime/mplayer/MplayerSlave.java +++ b/src/main/java/mplayer4anime/mplayer/MplayerSlave.java @@ -19,7 +19,7 @@ package mplayer4anime.mplayer; import mplayer4anime.ISlaveModeAppOrchestration; -import mplayer4anime.ServiceWindow; +import mplayer4anime.ui.ServiceWindow; import java.io.*; import java.util.ResourceBundle; diff --git a/src/main/java/mplayer4anime/mpv/MpvProcess.java b/src/main/java/mplayer4anime/mpv/MpvProcess.java index 2a43e6b..9b2bda7 100644 --- a/src/main/java/mplayer4anime/mpv/MpvProcess.java +++ b/src/main/java/mplayer4anime/mpv/MpvProcess.java @@ -19,7 +19,7 @@ package mplayer4anime.mpv; import com.sun.jna.ptr.IntByReference; -import mplayer4anime.ServiceWindow; +import mplayer4anime.ui.ServiceWindow; public class MpvProcess implements Runnable{ private String videoFilename; diff --git a/src/main/java/mplayer4anime/Playlists/JsonStorage.java b/src/main/java/mplayer4anime/playlists/JsonStorage.java similarity index 96% rename from src/main/java/mplayer4anime/Playlists/JsonStorage.java rename to src/main/java/mplayer4anime/playlists/JsonStorage.java index 1e79423..28b0e3e 100644 --- a/src/main/java/mplayer4anime/Playlists/JsonStorage.java +++ b/src/main/java/mplayer4anime/playlists/JsonStorage.java @@ -1,4 +1,4 @@ -package mplayer4anime.Playlists; +package mplayer4anime.playlists; public class JsonStorage { private final String Ver; diff --git a/src/main/java/mplayer4anime/Playlists/Playlists.java b/src/main/java/mplayer4anime/playlists/Playlists.java similarity index 98% rename from src/main/java/mplayer4anime/Playlists/Playlists.java rename to src/main/java/mplayer4anime/playlists/Playlists.java index 20f881b..3db69ab 100644 --- a/src/main/java/mplayer4anime/Playlists/Playlists.java +++ b/src/main/java/mplayer4anime/playlists/Playlists.java @@ -16,11 +16,11 @@ You should have received a copy of the GNU General Public License along with mplayer4anime. If not, see . */ -package mplayer4anime.Playlists; +package mplayer4anime.playlists; import com.google.gson.*; import javafx.stage.FileChooser; -import mplayer4anime.ServiceWindow; +import mplayer4anime.ui.ServiceWindow; import java.io.*; import java.nio.charset.StandardCharsets; diff --git a/src/main/java/mplayer4anime/ServiceWindow.java b/src/main/java/mplayer4anime/ui/ServiceWindow.java similarity index 98% rename from src/main/java/mplayer4anime/ServiceWindow.java rename to src/main/java/mplayer4anime/ui/ServiceWindow.java index 644f537..b481130 100644 --- a/src/main/java/mplayer4anime/ServiceWindow.java +++ b/src/main/java/mplayer4anime/ui/ServiceWindow.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with mplayer4anime. If not, see . */ -package mplayer4anime; +package mplayer4anime.ui; import javafx.scene.control.Alert; import javafx.scene.layout.Region; diff --git a/src/main/java/mplayer4anime/About/AboutController.java b/src/main/java/mplayer4anime/ui/about/AboutController.java similarity index 98% rename from src/main/java/mplayer4anime/About/AboutController.java rename to src/main/java/mplayer4anime/ui/about/AboutController.java index 53df491..9ca8f7e 100644 --- a/src/main/java/mplayer4anime/About/AboutController.java +++ b/src/main/java/mplayer4anime/ui/about/AboutController.java @@ -1,4 +1,4 @@ -package mplayer4anime.About; +package mplayer4anime.ui.about; import javafx.application.HostServices; import javafx.fxml.FXML; diff --git a/src/main/java/mplayer4anime/About/AboutWindow.java b/src/main/java/mplayer4anime/ui/about/AboutWindow.java similarity index 98% rename from src/main/java/mplayer4anime/About/AboutWindow.java rename to src/main/java/mplayer4anime/ui/about/AboutWindow.java index 4b4ae47..735a4bf 100644 --- a/src/main/java/mplayer4anime/About/AboutWindow.java +++ b/src/main/java/mplayer4anime/ui/about/AboutWindow.java @@ -1,4 +1,4 @@ -package mplayer4anime.About; +package mplayer4anime.ui.about; import javafx.application.HostServices; import javafx.fxml.FXMLLoader; diff --git a/src/main/java/mplayer4anime/Controller.java b/src/main/java/mplayer4anime/ui/landing/LandingController.java similarity index 71% rename from src/main/java/mplayer4anime/Controller.java rename to src/main/java/mplayer4anime/ui/landing/LandingController.java index bcc90af..271298b 100644 --- a/src/main/java/mplayer4anime/Controller.java +++ b/src/main/java/mplayer4anime/ui/landing/LandingController.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with mplayer4anime. If not, see . */ -package mplayer4anime; +package mplayer4anime.ui.landing; import javafx.application.HostServices; import javafx.application.Platform; @@ -26,12 +26,16 @@ import javafx.fxml.Initializable; import javafx.scene.control.*; import javafx.stage.Stage; -import mplayer4anime.About.AboutWindow; -import mplayer4anime.Playlists.JsonStorage; -import mplayer4anime.Playlists.Playlists; -import mplayer4anime.Settings.SettingsWindow; -import mplayer4anime.appPanes.ControllerPane; -import mplayer4anime.appPanes.ControllerSUB; +import mplayer4anime.ui.about.AboutWindow; +import mplayer4anime.AppPreferences; +import mplayer4anime.ISlaveModeAppOrchestration; +import mplayer4anime.MediatorControl; +import mplayer4anime.playlists.JsonStorage; +import mplayer4anime.playlists.Playlists; +import mplayer4anime.ui.ServiceWindow; +import mplayer4anime.ui.settings.SettingsWindow; +import mplayer4anime.ui.landing.panes.ControllerPane; +import mplayer4anime.ui.landing.panes.ControllerPaneSubtitles; import mplayer4anime.mplayer.MplayerSlave; import mplayer4anime.mpv.MpvSlave; @@ -39,21 +43,20 @@ import java.io.*; import java.net.URL; import java.util.ResourceBundle; -public class Controller implements Initializable { +public class LandingController implements Initializable { @FXML - private ControllerPane mkvPaneController, mkaPaneController; + ControllerPane mkvPaneController, mkaPaneController; @FXML - private ControllerSUB subPaneController; + ControllerPaneSubtitles subPaneController; + @FXML + private PlayerToolbarController playerToolbarController; @FXML private Label statusLbl; @FXML private Menu recentlyOpenedMenu; - @FXML - private CheckMenuItem fullScreen; + @FXML private TabPane tabPane; - @FXML - private CheckMenuItem subsHide; private final AppPreferences appPreferences = AppPreferences.getINSTANCE(); @@ -61,7 +64,8 @@ public class Controller implements Initializable { private HostServices hostServices; private String currentPlaylistLocation; private String backend; - private ISlaveModeAppOrchestration player; + + ISlaveModeAppOrchestration player; // If application started with playlist passed as an argument, then we'll try to load it (if it's valid). public void setPlaylistAsArgument(String playlist) { @@ -71,11 +75,12 @@ public class Controller implements Initializable { @Override public void initialize(URL url, ResourceBundle rb) { + // Register this controller in mediator + MediatorControl.getInstance().registerMainController(this); + mkvPaneController.setPaneType("Video"); mkaPaneController.setPaneType("Audio"); subPaneController.setPaneType("Subtitles"); - // Register this controller in mediator - MediatorControl.getInstance().registerMainController(this); resourceBundle = rb; @@ -87,9 +92,6 @@ public class Controller implements Initializable { tabPane.getSelectionModel().select(1); // 0 is mka 1 is subs } - fullScreen.setSelected(appPreferences.getFullScreenSelected()); - subsHide.setSelected(appPreferences.getSubtitlesHideSelected()); - String[] recentPlaylists = appPreferences.getRecentPlaylists(); for (int i = recentPlaylists.length-1; i >= 0; i--) { if (recentPlaylists[i].isEmpty()) @@ -104,9 +106,11 @@ public class Controller implements Initializable { backend = "mpv"; player = new MpvSlave(resourceBundle); } + + playerToolbarController.initializeMainUiController(this); } - void setHostServices(HostServices hostServices) { + public void setHostServices(HostServices hostServices) { this.hostServices = hostServices; } @@ -118,11 +122,10 @@ public class Controller implements Initializable { // Will be used to store lists previously opened. // Linkage established by ohHidden in MainFX.java class - void shutdown(){ + public void shutdown(){ appPreferences.setLastTimeUsedSubsEncoding(subPaneController.getSelectedEncoding()); - appPreferences.setFullScreenSelected(fullScreen.isSelected()); - appPreferences.setSubtitlesHideSelected(subsHide.isSelected()); - + playerToolbarController.shutdown(); + // TODO: remove from here; too sophisticated String[] storeRecentArr = new String[10]; for (int i =0; i < recentlyOpenedMenu.getItems().size() - 2 && !(i > 9); i++) { // Don't take separator and Clean button storeRecentArr[i] = (String) recentlyOpenedMenu.getItems().get(i).getUserData(); @@ -143,7 +146,7 @@ public class Controller implements Initializable { } // Get event that notify application in case some settings has been changed // This function called from MediatorControl after mediator receives request form SettingsController indicating that user updated some required fields. - void updateAfterSettingsChanged(){ + public void updateAfterSettingsChanged(){ /* update list of encoding */ subPaneController.setEncoding(appPreferences.getSubsEncodingList(), null); // In case of application failure should be better to save this immediately @@ -248,86 +251,5 @@ public class Controller implements Initializable { items.remove(9, recentlyOpenedMenu.getItems().size() - 2); items.add(0, menuItem); } - - /* PLAYER */ - @FXML - private void subsTriggerBtn(){ - player.subtitlesSwitch(); - } - @FXML - private void fullscreenBtn(){ - player.fullscreenSwitch(); - } - @FXML - private void muteBtn(){ - player.mute(); - } - @FXML - private void playPrevTrackBtn(){ - int index = mkvPaneController.getElementSelectedIndex(); - if (index <= 0) - return; - - mkvPaneController.setElementSelectedByIndex(index-1); - player.forcePlay(appPreferences.getPath(), - mkvPaneController.getElementSelected(), - mkaPaneController.getElementSelected(), - subPaneController.getElementSelected(), - subPaneController.getSelectedEncoding(), - subsHide.isSelected(), - fullScreen.isSelected() - ); - } - @FXML - private void playNextTrackBtn(){ - int index = mkvPaneController.getElementSelectedIndex(); - - if (index + 1 < mkvPaneController.getElementsCount()) { - mkvPaneController.setElementSelectedByIndex(index + 1); - } - index = mkaPaneController.getElementSelectedIndex(); - if (index + 1 < mkaPaneController.getElementsCount()) { - mkaPaneController.setElementSelectedByIndex(index + 1); - } - index = subPaneController.getElementSelectedIndex(); - if (index + 1 < subPaneController.getElementsCount()) { - subPaneController.setElementSelectedByIndex(index + 1); - } - - player.forcePlay(appPreferences.getPath(), - mkvPaneController.getElementSelected(), - mkaPaneController.getElementSelected(), - subPaneController.getElementSelected(), - subPaneController.getSelectedEncoding(), - subsHide.isSelected(), - fullScreen.isSelected() - ); - } - @FXML - private void playBtn(){ - if (mkvPaneController.getElementSelected() == null) - return; - - player.playPause(appPreferences.getPath(), - mkvPaneController.getElementSelected(), - mkaPaneController.getElementSelected(), - subPaneController.getElementSelected(), - subPaneController.getSelectedEncoding(), - subsHide.isSelected(), - fullScreen.isSelected() - ); - } - @FXML - private void stopBtn(){ - player.stop(); - } - @FXML - private void volumeUpBtn(){ - player.volumeUp(); - } - @FXML - private void volumeDownBtn(){ - player.volumeDown(); - } } diff --git a/src/main/java/mplayer4anime/ui/landing/PlayerToolbarController.java b/src/main/java/mplayer4anime/ui/landing/PlayerToolbarController.java new file mode 100644 index 0000000..704d2aa --- /dev/null +++ b/src/main/java/mplayer4anime/ui/landing/PlayerToolbarController.java @@ -0,0 +1,133 @@ +/* + Copyright 2018-2021 Dmitry Isaenko + + This file is part of mcontroller.player.anime. + + mcontroller.player.anime 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. + + mcontroller.player.anime 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 mcontroller.player.anime. If not, see . + */ +package mplayer4anime.ui.landing; + +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.CheckMenuItem; +import mplayer4anime.AppPreferences; + +import java.net.URL; +import java.util.ResourceBundle; + +public class PlayerToolbarController implements Initializable { + @FXML + private CheckMenuItem fullScreen; + @FXML + private CheckMenuItem subsHide; + + private AppPreferences appPreferences; + private LandingController landingController; + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + this.appPreferences = AppPreferences.getINSTANCE(); + + fullScreen.setSelected(appPreferences.getFullScreenSelected()); + subsHide.setSelected(appPreferences.getSubtitlesHideSelected()); + } + public void initializeMainUiController(LandingController landingController){ + this.landingController = landingController; + } + + @FXML + private void subsTriggerBtn(){ + landingController.player.subtitlesSwitch(); + } + @FXML + private void fullscreenBtn(){ + landingController.player.fullscreenSwitch(); + } + @FXML + private void muteBtn(){ + landingController.player.mute(); + } + @FXML + private void playPrevTrackBtn(){ + int index = landingController.mkvPaneController.getElementSelectedIndex(); + if (index <= 0) + return; + + landingController.mkvPaneController.setElementSelectedByIndex(index-1); + landingController.player.forcePlay(appPreferences.getPath(), + landingController.mkvPaneController.getElementSelected(), + landingController.mkaPaneController.getElementSelected(), + landingController.subPaneController.getElementSelected(), + landingController.subPaneController.getSelectedEncoding(), + subsHide.isSelected(), + fullScreen.isSelected() + ); + } + @FXML + private void playNextTrackBtn(){ + int index = landingController.mkvPaneController.getElementSelectedIndex(); + + if (index + 1 < landingController.mkvPaneController.getElementsCount()) { + landingController.mkvPaneController.setElementSelectedByIndex(index + 1); + } + index = landingController.mkaPaneController.getElementSelectedIndex(); + if (index + 1 < landingController.mkaPaneController.getElementsCount()) { + landingController.mkaPaneController.setElementSelectedByIndex(index + 1); + } + index = landingController.subPaneController.getElementSelectedIndex(); + if (index + 1 < landingController.subPaneController.getElementsCount()) { + landingController.subPaneController.setElementSelectedByIndex(index + 1); + } + + landingController.player.forcePlay(appPreferences.getPath(), + landingController.mkvPaneController.getElementSelected(), + landingController.mkaPaneController.getElementSelected(), + landingController.subPaneController.getElementSelected(), + landingController.subPaneController.getSelectedEncoding(), + subsHide.isSelected(), + fullScreen.isSelected() + ); + } + @FXML + private void playBtn(){ + if (landingController.mkvPaneController.getElementSelected() == null) + return; + + landingController.player.playPause(appPreferences.getPath(), + landingController.mkvPaneController.getElementSelected(), + landingController.mkaPaneController.getElementSelected(), + landingController.subPaneController.getElementSelected(), + landingController.subPaneController.getSelectedEncoding(), + subsHide.isSelected(), + fullScreen.isSelected() + ); + } + @FXML + private void stopBtn(){ + landingController.player.stop(); + } + @FXML + private void volumeUpBtn(){ + landingController.player.volumeUp(); + } + @FXML + private void volumeDownBtn(){ + landingController.player.volumeDown(); + } + + void shutdown(){ + appPreferences.setFullScreenSelected(fullScreen.isSelected()); + appPreferences.setSubtitlesHideSelected(subsHide.isSelected()); + } +} diff --git a/src/main/java/mplayer4anime/appPanes/ControllerPane.java b/src/main/java/mplayer4anime/ui/landing/panes/ControllerPane.java similarity index 99% rename from src/main/java/mplayer4anime/appPanes/ControllerPane.java rename to src/main/java/mplayer4anime/ui/landing/panes/ControllerPane.java index 2e1cc29..9a0fb1e 100644 --- a/src/main/java/mplayer4anime/appPanes/ControllerPane.java +++ b/src/main/java/mplayer4anime/ui/landing/panes/ControllerPane.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with mplayer4anime. If not, see . */ -package mplayer4anime.appPanes; +package mplayer4anime.ui.landing.panes; import javafx.collections.FXCollections; import javafx.collections.ObservableList; diff --git a/src/main/java/mplayer4anime/appPanes/ControllerSUB.java b/src/main/java/mplayer4anime/ui/landing/panes/ControllerPaneSubtitles.java similarity index 96% rename from src/main/java/mplayer4anime/appPanes/ControllerSUB.java rename to src/main/java/mplayer4anime/ui/landing/panes/ControllerPaneSubtitles.java index cbf12e9..790624e 100644 --- a/src/main/java/mplayer4anime/appPanes/ControllerSUB.java +++ b/src/main/java/mplayer4anime/ui/landing/panes/ControllerPaneSubtitles.java @@ -1,4 +1,4 @@ -package mplayer4anime.appPanes; +package mplayer4anime.ui.landing.panes; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -10,7 +10,7 @@ import java.net.URL; import java.util.Arrays; import java.util.ResourceBundle; -public class ControllerSUB extends ControllerPane { +public class ControllerPaneSubtitles extends ControllerPane { @FXML private ChoiceBox subtEncoding; private ObservableList subEncodingList; diff --git a/src/main/java/mplayer4anime/Settings/ControllerListsSelector.java b/src/main/java/mplayer4anime/ui/settings/ControllerListsSelector.java similarity index 99% rename from src/main/java/mplayer4anime/Settings/ControllerListsSelector.java rename to src/main/java/mplayer4anime/ui/settings/ControllerListsSelector.java index 75175bd..b3303b9 100644 --- a/src/main/java/mplayer4anime/Settings/ControllerListsSelector.java +++ b/src/main/java/mplayer4anime/ui/settings/ControllerListsSelector.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with mplayer4anime. If not, see . */ -package mplayer4anime.Settings; +package mplayer4anime.ui.settings; import javafx.collections.FXCollections; import javafx.collections.ObservableList; diff --git a/src/main/java/mplayer4anime/Settings/SettingsController.java b/src/main/java/mplayer4anime/ui/settings/SettingsController.java similarity index 96% rename from src/main/java/mplayer4anime/Settings/SettingsController.java rename to src/main/java/mplayer4anime/ui/settings/SettingsController.java index 404dca4..00cb851 100644 --- a/src/main/java/mplayer4anime/Settings/SettingsController.java +++ b/src/main/java/mplayer4anime/ui/settings/SettingsController.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with mplayer4anime. If not, see . */ -package mplayer4anime.Settings; +package mplayer4anime.ui.settings; import javafx.fxml.FXML; import javafx.fxml.Initializable; @@ -109,7 +109,7 @@ public class SettingsController implements Initializable { appPreferences.setAudioExtensionsList(audioExtensionListController.getList()); appPreferences.setBackendEngineIndexId(backEndEngineChoiceBox.getSelectionModel().getSelectedIndex()); - MediatorControl.getInstance().sentUpdates(); // TODO: implement list to track what should be updated + MediatorControl.getInstance().updateAfterSettingsChanged(); // TODO: implement list to track what should be updated } private void close(){ diff --git a/src/main/java/mplayer4anime/Settings/SettingsWindow.java b/src/main/java/mplayer4anime/ui/settings/SettingsWindow.java similarity index 98% rename from src/main/java/mplayer4anime/Settings/SettingsWindow.java rename to src/main/java/mplayer4anime/ui/settings/SettingsWindow.java index 98c7744..a1b0b99 100644 --- a/src/main/java/mplayer4anime/Settings/SettingsWindow.java +++ b/src/main/java/mplayer4anime/ui/settings/SettingsWindow.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with mplayer4anime. If not, see . */ -package mplayer4anime.Settings; +package mplayer4anime.ui.settings; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; diff --git a/src/main/resources/About/AboutLayout.fxml b/src/main/resources/About/AboutLayout.fxml index d594d60..1d68137 100644 --- a/src/main/resources/About/AboutLayout.fxml +++ b/src/main/resources/About/AboutLayout.fxml @@ -12,7 +12,7 @@ - + diff --git a/src/main/resources/landingPage.fxml b/src/main/resources/LandingPage.fxml similarity index 53% rename from src/main/resources/landingPage.fxml rename to src/main/resources/LandingPage.fxml index f30c4ed..6b6135c 100644 --- a/src/main/resources/landingPage.fxml +++ b/src/main/resources/LandingPage.fxml @@ -1,25 +1,20 @@ - - - - - - + @@ -90,75 +85,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +