From 291f183f5ea24321a5ecdc52b19351f89a1a03ce Mon Sep 17 00:00:00 2001 From: Seil0 Date: Sat, 12 Jan 2019 23:07:25 +0100 Subject: [PATCH] removed more mwc dependencies & code clean up --- .../application/MainWindowController.java | 64 ++++++------------- .../HomeFlix/controller/DBController.java | 2 +- .../controller/SourcesController.java | 8 +-- .../HomeFlix/controller/XMLController.java | 16 ++--- .../kellerkinder/HomeFlix/player/Player.java | 9 +-- .../HomeFlix/player/PlayerController.java | 14 ++-- src/main/resources/fxml/MainWindow.fxml | 10 ++- 7 files changed, 54 insertions(+), 69 deletions(-) diff --git a/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java b/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java index 9e291bc..4965855 100644 --- a/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java +++ b/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java @@ -132,17 +132,19 @@ public class MainWindowController { @FXML private TableColumn sourceColumn; @FXML private TableColumn modeColumn; + @FXML private TreeTableColumn columnStreamUrl; + @FXML private TreeTableColumn columnTitle; + @FXML private TreeTableColumn columnFavorite; + @FXML private TreeTableColumn columnSeason; + @FXML private TreeTableColumn columnEpisode; + // table-mode @FXML private AnchorPane tableModeAnchorPane; @FXML private JFXTextField searchTextField; @FXML private TreeTableView filmsTreeTable; @FXML private TreeItem filmRoot = new TreeItem<>(new FilmTabelDataType("", "", "", "", false, false, null)); - @FXML private TreeTableColumn columnStreamUrl = new TreeTableColumn<>("File Name"); - @FXML private TreeTableColumn columnTitle = new TreeTableColumn<>("Title"); - @FXML private TreeTableColumn columnSeason = new TreeTableColumn<>("Season"); - @FXML private TreeTableColumn columnEpisode = new TreeTableColumn<>("Episode"); - @FXML private TreeTableColumn columnFavorite = new TreeTableColumn<>("Favorite"); + @FXML private ScrollPane textScrollPane; @FXML private TextFlow textFlow; @@ -156,9 +158,8 @@ public class MainWindowController { // poster-mode // @FXML private AnchorPane posterModeAnchorPane; - private MainWindowController mainWindowController; + private static DBController dbController; // the player needs the initialized dbController private UpdateController updateController; - private DBController dbController; private XMLController xmlController; private Stage primaryStage; private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName()); @@ -182,7 +183,7 @@ public class MainWindowController { private ObservableList branches = FXCollections.observableArrayList("stable", "beta"); private ObservableList filterData = FXCollections.observableArrayList(); private ObservableList filmsList = FXCollections.observableArrayList(); - private ObservableList sourcesList = FXCollections.observableArrayList(); + private static ObservableList sourcesList = FXCollections.observableArrayList(); private MenuItem like = new MenuItem("like"); private MenuItem dislike = new MenuItem("dislike"); // TODO one option (like or dislike) private ContextMenu menu = new ContextMenu(like, dislike); @@ -193,7 +194,6 @@ public class MainWindowController { @FXML public void initialize() { - mainWindowController = this; xmlController = new XMLController(); dbController = new DBController(this); } @@ -211,6 +211,9 @@ public class MainWindowController { initActions(); dbController.init(); + // load sources list in gui + addSourceToTable(); + // posterModeStartup(); // TODO testing DO NOT USE THIS!! } @@ -243,24 +246,6 @@ public class MainWindowController { private void initTabel() { // film Table - columnStreamUrl.setMaxWidth(0); - columnTitle.setMaxWidth(182); - columnFavorite.setMaxWidth(80); - columnSeason.setMaxWidth(70); - columnEpisode.setMaxWidth(70); - - columnTitle.setMinWidth(182); - columnFavorite.setMinWidth(80); - columnSeason.setMinWidth(70); - columnEpisode.setMinWidth(70); - - columnTitle.setResizable(false); - columnFavorite.setResizable(false); - columnSeason.setResizable(false); - columnEpisode.setResizable(false); - - columnFavorite.setStyle("-fx-alignment: CENTER;"); - filmsTreeTable.setRoot(filmRoot); filmsTreeTable.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY); filmsTreeTable.setShowRoot(false); @@ -272,14 +257,6 @@ public class MainWindowController { columnEpisode.setCellValueFactory(cellData -> cellData.getValue().getValue().episodeProperty()); columnFavorite.setCellValueFactory(cellData -> cellData.getValue().getValue().imageProperty()); - // add columns to treeTableViewfilm - filmsTreeTable.getColumns().add(columnStreamUrl); - filmsTreeTable.getColumns().add(columnTitle); - filmsTreeTable.getColumns().add(columnFavorite); - filmsTreeTable.getColumns().add(columnSeason); - filmsTreeTable.getColumns().add(columnEpisode); - filmsTreeTable.getColumns().get(0).setVisible(false); // hide columnStreamUrl (important) - // context menu for treeTableViewfilm filmsTreeTable.setContextMenu(menu); @@ -467,7 +444,7 @@ public class MainWindowController { } if (isSupportedFormat(currentTableFilm)) { - new Player(mainWindowController); + new Player(getCurrentTableFilm()); } else { LOGGER.error("using fallback player!"); if (System.getProperty("os.name").contains("Linux")) { @@ -641,10 +618,11 @@ public class MainWindowController { } } - // add a source to the sources table on the settings pane - public void addSourceToTable(String path, String mode) { - sourcesList.add(new SourceDataType(path, mode)); - sourceRoot.getChildren().add(new TreeItem(sourcesList.get(sourcesList.size() - 1))); // adds data to root-node + // add a all elements of sourcesList to the sources table on the settings pane + public void addSourceToTable() { + for (SourceDataType source: sourcesList) { + sourceRoot.getChildren().add(new TreeItem(source)); // add data to root-node + } } /** @@ -785,9 +763,9 @@ public class MainWindowController { branchLbl.setText(XMLController.getLocalBundle().getString("branchLbl")); columnStreamUrl.setText(XMLController.getLocalBundle().getString("columnStreamUrl")); columnTitle.setText(XMLController.getLocalBundle().getString("columnName")); + columnFavorite.setText(XMLController.getLocalBundle().getString("columnFavorite")); columnSeason.setText(XMLController.getLocalBundle().getString("columnSeason")); columnEpisode.setText(XMLController.getLocalBundle().getString("columnEpisode")); - columnFavorite.setText(XMLController.getLocalBundle().getString("columnFavorite")); } // if AutoUpdate, then check for updates @@ -841,7 +819,7 @@ public class MainWindowController { } // getter and setter - public DBController getDbController() { + public static DBController getDbController() { return dbController; } @@ -869,7 +847,7 @@ public class MainWindowController { return filmsList; } - public ObservableList getSourcesList() { + public static ObservableList getSourcesList() { return sourcesList; } diff --git a/src/main/java/kellerkinder/HomeFlix/controller/DBController.java b/src/main/java/kellerkinder/HomeFlix/controller/DBController.java index b07d195..78a347c 100644 --- a/src/main/java/kellerkinder/HomeFlix/controller/DBController.java +++ b/src/main/java/kellerkinder/HomeFlix/controller/DBController.java @@ -143,7 +143,7 @@ public class DBController { * load all sources */ private void loadSources() { - SourcesController sourcesController = new SourcesController(mainWindowController); + SourcesController sourcesController = new SourcesController(); sourceStreams = sourcesController.loadSources(); } diff --git a/src/main/java/kellerkinder/HomeFlix/controller/SourcesController.java b/src/main/java/kellerkinder/HomeFlix/controller/SourcesController.java index 942f171..a55d6f8 100644 --- a/src/main/java/kellerkinder/HomeFlix/controller/SourcesController.java +++ b/src/main/java/kellerkinder/HomeFlix/controller/SourcesController.java @@ -39,15 +39,15 @@ import com.eclipsesource.json.JsonValue; import kellerkinder.HomeFlix.application.MainWindowController; import kellerkinder.HomeFlix.datatypes.DatabaseDataType; +import kellerkinder.HomeFlix.datatypes.SourceDataType; public class SourcesController { - private MainWindowController mainWindowController; private List sourceStreams = new ArrayList(); private static final Logger LOGGER = LogManager.getLogger(SourcesController.class.getName()); - public SourcesController(MainWindowController mainWindowController) { - this.mainWindowController = mainWindowController; + public SourcesController() { + // Auto-generated constructor stub } /** @@ -61,7 +61,7 @@ public class SourcesController { for (JsonValue source : sources) { String path = source.asObject().getString("path", ""); String mode = source.asObject().getString("mode", ""); - mainWindowController.addSourceToTable(path, mode); // add loaded source to source-table TODO this should be done in mwc + MainWindowController.getSourcesList().add(new SourceDataType(path, mode)); if (mode.equals("local")) addLocalSource(path); diff --git a/src/main/java/kellerkinder/HomeFlix/controller/XMLController.java b/src/main/java/kellerkinder/HomeFlix/controller/XMLController.java index 8d36204..02670e6 100644 --- a/src/main/java/kellerkinder/HomeFlix/controller/XMLController.java +++ b/src/main/java/kellerkinder/HomeFlix/controller/XMLController.java @@ -42,14 +42,14 @@ import com.eclipsesource.json.JsonObject; public class XMLController { - private static String userHome = System.getProperty("user.home"); - private static String userName = System.getProperty("user.name"); - private static String osName = System.getProperty("os.name"); - private static String osArch = System.getProperty("os.arch"); - private static String osVers = System.getProperty("os.version"); - private static String javaVers = System.getProperty("java.version"); - private static String javaVend = System.getProperty("java.vendor"); - private static String sysLocal = System.getProperty("user.language") + "_" + System.getProperty("user.country"); + private static final String userHome = System.getProperty("user.home"); + private static final String userName = System.getProperty("user.name"); + private static final String osName = System.getProperty("os.name"); + private static final String osArch = System.getProperty("os.arch"); + private static final String osVers = System.getProperty("os.version"); + private static final String javaVers = System.getProperty("java.version"); + private static final String javaVend = System.getProperty("java.vendor"); + private static final String sysLocal = System.getProperty("user.language") + "_" + System.getProperty("user.country"); private static String dirHomeFlixPath; private static File dirHomeFlix; private static File configFile; diff --git a/src/main/java/kellerkinder/HomeFlix/player/Player.java b/src/main/java/kellerkinder/HomeFlix/player/Player.java index f6d5cc8..209185b 100644 --- a/src/main/java/kellerkinder/HomeFlix/player/Player.java +++ b/src/main/java/kellerkinder/HomeFlix/player/Player.java @@ -31,6 +31,7 @@ import javafx.stage.Stage; import javafx.stage.WindowEvent; import kellerkinder.HomeFlix.application.Main; import kellerkinder.HomeFlix.application.MainWindowController; +import kellerkinder.HomeFlix.datatypes.FilmTabelDataType; public class Player { @@ -41,10 +42,10 @@ public class Player { /** * generate a new PlayerWindow - * @param mainWindowController the MainWindowController + * @param currentTableFilm the currently selected film */ - public Player(MainWindowController mainWindowController) { - playerController = new PlayerController(mainWindowController, this, mainWindowController.getCurrentTableFilm()); + public Player(FilmTabelDataType currentTableFilm) { + playerController = new PlayerController(this, currentTableFilm); try { FXMLLoader fxmlLoader = new FXMLLoader(); @@ -58,7 +59,7 @@ public class Player { stage.getIcons().add(new Image(Main.class.getResourceAsStream("/icons/Homeflix_Icon_64x64.png"))); stage.setOnCloseRequest(new EventHandler() { public void handle(WindowEvent we) { - mainWindowController.getDbController().setCurrentTime(mainWindowController.getCurrentStreamUrl(), + MainWindowController.getDbController().setCurrentTime(currentTableFilm.getStreamUrl(), playerController.getCurrentTime()); playerController.getMediaPlayer().stop(); stage.close(); diff --git a/src/main/java/kellerkinder/HomeFlix/player/PlayerController.java b/src/main/java/kellerkinder/HomeFlix/player/PlayerController.java index f94e7e9..9750932 100644 --- a/src/main/java/kellerkinder/HomeFlix/player/PlayerController.java +++ b/src/main/java/kellerkinder/HomeFlix/player/PlayerController.java @@ -67,7 +67,6 @@ public class PlayerController { @FXML private JFXButton nextEpBtn; private Player player; - private MainWindowController mainWCon; private Media media; private MediaPlayer mediaPlayer; @@ -95,8 +94,7 @@ public class PlayerController { * @param player the player object (needed for closing action) * @param film the film object */ - public PlayerController(MainWindowController mainWCon, Player player, FilmTabelDataType film) { - this.mainWCon = mainWCon; + public PlayerController(Player player, FilmTabelDataType film) { this.player = player; this.film = film; } @@ -124,7 +122,7 @@ public class PlayerController { width.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width")); height.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height")); - startTime = mainWCon.getDbController().getCurrentTime(film.getStreamUrl()); + startTime = MainWindowController.getDbController().getCurrentTime(film.getStreamUrl()); autoplay = XMLController.isAutoplay(); season = !film.getSeason().isEmpty() ? Integer.parseInt(film.getSeason()) : 0; episode = !film.getEpisode().isEmpty() ? Integer.parseInt(film.getEpisode()) : 0; @@ -177,7 +175,7 @@ public class PlayerController { } else if (timeToEnd < 120) { // if we are 120ms to the end stop the media mediaPlayer.stop(); - mainWCon.getDbController().setCurrentTime(film.getStreamUrl(), 0); // reset old video start time + MainWindowController.getDbController().setCurrentTime(film.getStreamUrl(), 0); // reset old video start time playBtn.setGraphic(play_arrow_black); } else { if (nextEpBtn.isVisible()) @@ -255,7 +253,7 @@ public class PlayerController { @FXML void stopBtnAction(ActionEvent event) { - mainWCon.getDbController().setCurrentTime(film.getStreamUrl(), currentTime); + MainWindowController.getDbController().setCurrentTime(film.getStreamUrl(), currentTime); mediaPlayer.stop(); player.getStage().close(); } @@ -289,8 +287,8 @@ public class PlayerController { private void autoPlayNewFilm() { autoplay = false; - mainWCon.getDbController().setCurrentTime(film.getStreamUrl(), 0); // reset old video start time - FilmTabelDataType nextFilm = mainWCon.getDbController().getNextEpisode(film.getTitle(), episode, season); + MainWindowController.getDbController().setCurrentTime(film.getStreamUrl(), 0); // reset old video start time + FilmTabelDataType nextFilm = MainWindowController.getDbController().getNextEpisode(film.getTitle(), episode, season); if (nextFilm != null) { mediaPlayer.stop(); film = nextFilm; diff --git a/src/main/resources/fxml/MainWindow.fxml b/src/main/resources/fxml/MainWindow.fxml index e0aa81f..b850b67 100644 --- a/src/main/resources/fxml/MainWindow.fxml +++ b/src/main/resources/fxml/MainWindow.fxml @@ -13,6 +13,7 @@ + @@ -31,7 +32,14 @@ - + + + + + + + +