diff --git a/About/AboutController.java b/About/AboutController.java
index 38a47ad..5ca5170 100644
--- a/About/AboutController.java
+++ b/About/AboutController.java
@@ -40,7 +40,7 @@ public class AboutController implements Initializable {
@FXML
private void bloggerUrl(){
try {
- hostServices.showDocument("https://developersu.blogspot.com/");
+ hostServices.showDocument("https://developersu.blogspot.com/search/label/mplayer4anime");
} catch (Exception e){
e.printStackTrace();
}
@@ -53,6 +53,16 @@ public class AboutController implements Initializable {
e.printStackTrace();
}
}
+ @FXML
+ private void iconsMaterial(){
+ try {
+ hostServices.showDocument("https://materialdesignicons.com/");
+ } catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ //TODO note icons meaterial design
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
diff --git a/About/AboutLayout.fxml b/About/AboutLayout.fxml
index 55da844..d594d60 100644
--- a/About/AboutLayout.fxml
+++ b/About/AboutLayout.fxml
@@ -52,6 +52,7 @@
+
diff --git a/About/AboutWindow.java b/About/AboutWindow.java
index ffb9dbd..61ee68d 100644
--- a/About/AboutWindow.java
+++ b/About/AboutWindow.java
@@ -18,7 +18,7 @@ public class AboutWindow {
Stage stageAbout = new Stage();
stageAbout.setMinWidth(500);
- stageAbout.setMinHeight(450);
+ stageAbout.setMinHeight(500);
FXMLLoader loaderAbout = new FXMLLoader(getClass().getResource("AboutLayout.fxml"));
ResourceBundle resourceBundle;
@@ -42,7 +42,7 @@ public class AboutWindow {
new Image(Main.class.getResourceAsStream("/mplayer4anime/res/app_icon64x64.png")),
new Image(Main.class.getResourceAsStream("/mplayer4anime/res/app_icon128x128.png"))
); // TODO: change to something reliable
- stageAbout.setScene(new Scene(parentAbout, 500, 450));
+ stageAbout.setScene(new Scene(parentAbout, 500, 500));
stageAbout.show();
diff --git a/AppPreferences.java b/AppPreferences.java
index 898bd15..f7c7bd5 100644
--- a/AppPreferences.java
+++ b/AppPreferences.java
@@ -32,15 +32,6 @@ public class AppPreferences {
preferences.putBoolean("SUBS_TAB_FIRST", set);
}
- // Set option, that tells that we have to save/restore lists on startup
- public void setLoadListsOnStart(boolean set){
- preferences.putBoolean("LOAD_LISTS_ON_START", set);
- }
- // Returns settings for the save/restore lists option
- public boolean getLoadListsOnStart(){
- return preferences.getBoolean("LOAD_LISTS_ON_START", false); // Don't populate lists by-default
- }
-
/** Convert strings array to singls string.
* Used in:
* setSubsExtensionsList
@@ -50,23 +41,25 @@ public class AppPreferences {
StringBuilder collect = new StringBuilder();
for (String e : strArr) {
collect.append(e);
- collect.append("@@@"); // If there is some idiot who will use @@@ in file extension I'll find him.
+ collect.append(" ");
}
String strToStore = collect.toString();
preferences.put(whichList, strToStore);
}
+ /** Handle lists of the video files extensions */
+ public void setVideoExtensionsList(String[] videoExtensionsList){ storeSingleStringList("VIDEO_EXTENSIONS_LIST", videoExtensionsList); }
+ public String[] getVideoExtensionsList(){ return preferences.get("VIDEO_EXTENSIONS_LIST", "*.mkv *.avi *.mp4").split(" "); }
+ /** Handle lists of the audio files extensions */
+ public void setAudioExtensionsList(String[] audioExtensionsList){ storeSingleStringList("AUDIO_EXTENSIONS_LIST", audioExtensionsList); }
+ public String[] getAudioExtensionsList(){ return preferences.get("AUDIO_EXTENSIONS_LIST", "*.mka *.ac3").split(" "); }
/** Handle lists of the subtitles extensions selector */
public void setSubsExtensionsList(String[] subsList){ storeSingleStringList("SUBS_EXTENSIONS_LIST", subsList); }
- public String[] getSubsExtensionsList(){ return preferences.get("SUBS_EXTENSIONS_LIST", ".ass@@@.crt@@@").split("@@@"); }
+ public String[] getSubsExtensionsList(){ return preferences.get("SUBS_EXTENSIONS_LIST", "*.ass *.crt ").split(" "); }
/** Handle lists of the subtitles encodings selector */
public void setSubsEncodingList(String[] subsEncodingList){ storeSingleStringList("SUBS_ENCODINGS_LIST", subsEncodingList); }
- public String[] getSubsEncodingList(){ return preferences.get("SUBS_ENCODINGS_LIST", "default@@@utf8@@@cp1251@@@koi8-r").split("@@@"); }
-
- /** Save & recover selected by user Subtitles format */
- public void setLastTimeUsedSusExt(String selected){ preferences.put("SUBS_EXT_LAST_TIME_SELECTED", selected); }
- public String getLastTimeUsedSubsExt(){ return preferences.get("SUBS_EXT_LAST_TIME_SELECTED", ""); }
+ public String[] getSubsEncodingList(){ return preferences.get("SUBS_ENCODINGS_LIST", "default utf8 cp1251 koi8-r").split(" "); }
/** Save & recover selected by user Subtitles encoding */
public void setLastTimeUsedSubsEncoding(String selected){ preferences.put("SUBS_ENCODING_LAST_TIME_SELECTED", selected); }
@@ -100,7 +93,7 @@ public class AppPreferences {
preferences.put("RECENT_PLS_" + i, recentPlaylists[i]);
else
preferences.put("RECENT_PLS_" + i, "");
- for (;i<10;i++) // Not needed. Logic may handle recieved String to be less or greater then String[10], but it never happened.
+ for (;i<10;i++) // Not needed. Logic may handle received String to be less or greater then String[10], but it never happened.
preferences.put("RECENT_PLS_" + i, "");
}
}
diff --git a/Controller.java b/Controller.java
index 70b0056..004afe5 100644
--- a/Controller.java
+++ b/Controller.java
@@ -13,8 +13,7 @@ import mplayer4anime.About.AboutWindow;
import mplayer4anime.Playlists.JsonStorage;
import mplayer4anime.Playlists.Playlists;
import mplayer4anime.Settings.SettingsWindow;
-import mplayer4anime.appPanes.ControllerMKA;
-import mplayer4anime.appPanes.ControllerMKV;
+import mplayer4anime.appPanes.ControllerPane;
import mplayer4anime.appPanes.ControllerSUB;
import java.io.*;
@@ -24,12 +23,12 @@ import java.util.ResourceBundle;
public class Controller implements Initializable {
@FXML
- private ControllerMKV mkvPaneController;
+ private ControllerPane mkvPaneController;
+ @FXML
+ private ControllerPane mkaPaneController;
@FXML
private ControllerSUB subPaneController;
@FXML
- private ControllerMKA mkaPaneController;
- @FXML
private Label statusLbl;
@FXML
private Menu recentlyOpenedMenu;
@@ -53,14 +52,14 @@ public class Controller implements Initializable {
private String currentPlaylistLocation = null; //TODO: move to the constructor?
@Override
public void initialize(URL url, ResourceBundle rb) {
+ mkvPaneController.setPaneType("Video");
+ mkaPaneController.setPaneType("Audio");
+ subPaneController.setPaneType("Subtitles");
// Register this controller in mediator
MediatorControl.getInstance().registerMainController(this);
resourceBundle = rb;
- // Set default extension of the subtitles files:
- subPaneController.setSubtExt(appPreferences.getSubsExtensionsList(), appPreferences.getLastTimeUsedSubsExt());// Receive list from storage & set selected value
-
// Set default list of encodings of the subtitles files:
subPaneController.setEncoding(appPreferences.getSubsEncodingList(), appPreferences.getLastTimeUsedSubsEncoding());
@@ -217,7 +216,6 @@ public class Controller implements Initializable {
// Will be used to store lists previously opened.
// Linkage established by ohHidden in Main.java class
void shutdown(){
- appPreferences.setLastTimeUsedSusExt(subPaneController.getSelectedExt());
appPreferences.setLastTimeUsedSubsEncoding(subPaneController.getSelectedEncoding());
appPreferences.setFullScreenSelected(fullScreen.isSelected());
appPreferences.setSubtitlesHideSelected(subsHide.isSelected());
@@ -240,12 +238,6 @@ 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(){
- /* update list of extensions */
- // Clear and update list
- subPaneController.setSubtExt(appPreferences.getSubsExtensionsList(), null);
- // In case of application failure should be better to save this immediately
- appPreferences.setLastTimeUsedSusExt(subPaneController.getSelectedEncoding());
-
/* update list of encoding */
subPaneController.setEncoding(appPreferences.getSubsEncodingList(), null);
// In case of application failure should be better to save this immediately
@@ -255,14 +247,20 @@ public class Controller implements Initializable {
@FXML
private void openBtn() {
JsonStorage jsonStorage = Playlists.Read(resourceBundle);
+ setAllLists(jsonStorage);
+ }
+ private void setAllLists(JsonStorage jsonStorage){
if (jsonStorage != null) {
+ mkvPaneController.cleanList();
+ mkaPaneController.cleanList();
+ subPaneController.cleanList();
mkvPaneController.setFilesFromList(jsonStorage.getVideo());
mkaPaneController.setFilesFromList(jsonStorage.getAudio());
subPaneController.setFilesFromList(jsonStorage.getSubs());
subPaneController.selectEncodingValue(jsonStorage.getSubEncoding(), appPreferences);
- this.currentPlaylistLocation = Playlists.getPlaylistLocation(); // TODO: Implement listener? mmm...
- this.statusLbl.setText(currentPlaylistLocation);
+ currentPlaylistLocation = Playlists.getPlaylistLocation(); // TODO: Implement listener? mmm...
+ statusLbl.setText(currentPlaylistLocation);
addRecentlyOpened(currentPlaylistLocation);
}
}
@@ -326,16 +324,7 @@ public class Controller implements Initializable {
@Override
public void handle(ActionEvent actionEvent) {
JsonStorage jsonStorage = Playlists.ReadByPath(resourceBundle, new File(playlistPath));
- if (jsonStorage != null) {
- mkvPaneController.setFilesFromList(jsonStorage.getVideo());
- mkaPaneController.setFilesFromList(jsonStorage.getAudio());
- subPaneController.setFilesFromList(jsonStorage.getSubs());
- subPaneController.selectEncodingValue(jsonStorage.getSubEncoding(), appPreferences);
-
- currentPlaylistLocation = Playlists.getPlaylistLocation(); // TODO: Implement listener? mmm...
- statusLbl.setText(currentPlaylistLocation);
- addRecentlyOpened(currentPlaylistLocation);
- }
+ setAllLists(jsonStorage);
}
});
// Limit list to 13 elements (2 in the end are separator and clear button)
diff --git a/Main.java b/Main.java
index 3132c93..ab76f68 100644
--- a/Main.java
+++ b/Main.java
@@ -3,8 +3,9 @@ package mplayer4anime;
Name: mplayer4anime
@author Dmitry Isaenko
License: GNU GPL v.3
-@version 0.10
-@see https://developersu.blogspot.com/
+@version 0.11
+@see https://developersu.blogspot.com/search/label/mplayer4anime
+@see https://github.com/developersu/mplayer4anime
2018, Russia
*/
diff --git a/Readme.md b/Readme.md
index 018e755..decac43 100644
--- a/Readme.md
+++ b/Readme.md
@@ -6,6 +6,14 @@ mplayer4anime is mplayer launcher to play mkv file with mka audio and subtitles
Source code spreads under the GNU General Public License v.3. You can find it in LICENSE file or just visit www.gnu.org (it should be there for sure).
+Note: Since 0.10 application supports playlists management and implements own json-based format that (somehow) could be used in third-party application,
+it would be nice to leave it as is. At least, I would prefer to have .alpr file extension used for this. As for the format of playlist format, please
+refer to WFTPL license.
+
+## Used libraries
+GSON: https://github.com/google/gson
+Pay attention, that this lib uses Apache-2.0 license
+
## Requirements
JRE and JavaFX should be installed on your PC.
@@ -18,9 +26,6 @@ Just start it as usual Java application:
$ java -jar mplayer4anime.jar
```
-## Used libraries
-GSON: https://github.com/google/gson
-
## Run on windows
Step 1.
Download and install JRE (8 or later):
diff --git a/ServiceWindow.java b/ServiceWindow.java
index 2339d54..91340cc 100644
--- a/ServiceWindow.java
+++ b/ServiceWindow.java
@@ -1,6 +1,7 @@
package mplayer4anime;
import javafx.scene.control.Alert;
+import javafx.scene.layout.Region;
public class ServiceWindow {
/**
@@ -11,6 +12,7 @@ public class ServiceWindow {
alertBox.setTitle(title);
alertBox.setHeaderText(null);
alertBox.setContentText(body);
+ alertBox.getDialogPane().setMinHeight(Region.USE_PREF_SIZE); // Java bug workaround for linux
alertBox.show();
}
}
diff --git a/Settings/ControllerListsSelector.java b/Settings/ControllerListsSelector.java
new file mode 100644
index 0000000..427d8e6
--- /dev/null
+++ b/Settings/ControllerListsSelector.java
@@ -0,0 +1,101 @@
+package mplayer4anime.Settings;
+
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import javafx.fxml.FXML;
+import javafx.fxml.Initializable;
+import javafx.scene.control.ListView;
+import javafx.scene.control.TextField;
+import javafx.scene.input.KeyEvent;
+import mplayer4anime.ServiceWindow;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.ResourceBundle;
+
+public class ControllerListsSelector implements Initializable {
+ @FXML
+ private ListView listView;
+ @FXML
+ private TextField newRecordText;
+ private ObservableList observableList;
+ private ResourceBundle resourceBundle;
+
+ private boolean listOfExtensions; // Handle validation of the format importing items
+
+ @Override
+ public void initialize(URL url, ResourceBundle rb) {
+ resourceBundle = rb;
+ }
+ /**
+ * Must be run on start
+ * Set list content
+ */
+ void setList(String[] listFromStorage, boolean isListOfExtensions){
+ observableList = FXCollections.observableArrayList(listFromStorage);
+ listView.setItems(observableList);
+ this.listOfExtensions = isListOfExtensions;
+ }
+ /**
+ * Return list content
+ * */
+ String[] getList(){
+ return Arrays.copyOf(observableList.toArray(), observableList.toArray().length, String[].class);
+ }
+ @FXML
+ private void listKeyPressed(KeyEvent event){
+ if (event.getCode().toString().equals("DELETE"))
+ removeRecord();
+ }
+ @FXML
+ private void upRecord(){
+ int index;
+ index = listView.getSelectionModel().getSelectedIndex();
+ if (index >0){
+ observableList.add(index-1, listView.getSelectionModel().getSelectedItem());
+ observableList.remove(index+1);
+ listView.getSelectionModel().select(index-1);
+ }
+ }
+ @FXML
+ private void downRecord(){
+ int index;
+ index = listView.getSelectionModel().getSelectedIndex();
+ if (index+1 < observableList.size() ){
+ observableList.add(index+2, listView.getSelectionModel().getSelectedItem());
+ observableList.remove(index);
+ listView.getSelectionModel().select(index+1);
+ }
+ }
+ @FXML
+ private void removeRecord(){ observableList.remove(listView.getSelectionModel().getSelectedItem()); }
+ @FXML
+ private void addNewRecord(){
+ String addingItem = newRecordText.getText().trim();
+ if (!addingItem.isEmpty()) // If this field is non-empty
+ if (!addingItem.contains(" ") && !addingItem.contains("\t")) {
+ if (this.listOfExtensions) {
+ if (addingItem.startsWith("*."))
+ if (addingItem.substring(2).contains("*")) {
+ ServiceWindow.getErrorNotification(resourceBundle.getString("Error"), resourceBundle.getString("settings_fieldContainUnacceptedChars"));
+ } else {
+ observableList.add(addingItem);
+ }
+ else if (addingItem.contains("*")) {
+ ServiceWindow.getErrorNotification(resourceBundle.getString("Error"), resourceBundle.getString("settings_fieldContainUnacceptedChars"));
+ } else if (addingItem.startsWith(".")) {
+ observableList.add("*" + addingItem);
+ } else {
+ observableList.add("*." + addingItem);
+ }
+ }
+ else {
+ observableList.add(addingItem);
+ }
+ }
+ else{
+ ServiceWindow.getErrorNotification(resourceBundle.getString("Error"), resourceBundle.getString("settings_fieldContainUnacceptedChars"));
+ }
+ newRecordText.clear();
+ }
+}
diff --git a/Settings/ListSelector.fxml b/Settings/ListSelector.fxml
new file mode 100644
index 0000000..5a1327e
--- /dev/null
+++ b/Settings/ListSelector.fxml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Settings/SettingsController.java b/Settings/SettingsController.java
index ad4219f..205cf6a 100644
--- a/Settings/SettingsController.java
+++ b/Settings/SettingsController.java
@@ -1,154 +1,46 @@
package mplayer4anime.Settings;
-import javafx.collections.FXCollections;
-import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
-import javafx.scene.input.KeyEvent;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import mplayer4anime.AppPreferences;
import java.io.File;
import java.net.URL;
-import java.util.Arrays;
import java.util.ResourceBundle;
import mplayer4anime.MediatorControl;
public class SettingsController implements Initializable {
- private ResourceBundle resourceBundle;
- // Class of settings used
private AppPreferences appPreferences;
-
@FXML
- private Label pathToMplayerLbl,
- unixOsInfoLbl;
-
+ private ControllerListsSelector subExtensionListController;
@FXML
- private CheckBox subtitlesFirstCheckBox,
- listsLoadOnStartCheckBox;
-
- // subs extensions and codepages error handle
- private void showFormattingError(){
- Alert alertBox = new Alert(Alert.AlertType.ERROR);
- alertBox.setTitle(resourceBundle.getString("Error"));
- alertBox.setHeaderText(null);
- alertBox.setContentText(resourceBundle.getString("settings_fieldContainSpacesTabs"));
- alertBox.show();
- }
- // subs extensions
+ private ControllerListsSelector subEncodingListController;
@FXML
- private ListView subsExtListView;
- private ObservableList subsExtObservableList;
+ private ControllerListsSelector videoExtensionListController;
@FXML
- private TextField subsExtNewRecordText;
+ private ControllerListsSelector audioExtensionListController;
@FXML
- private void subsExtAddNewRecord(){
- String add = subsExtNewRecordText.getText().trim();
- if (!add.isEmpty()) // If this field is non-empty
- if (!add.contains(" ") && !add.contains("\t"))
- subsExtObservableList.add(subsExtNewRecordText.getText().trim());
- else{
- showFormattingError();
- }
- subsExtNewRecordText.clear();
- }
+ private Label pathToMplayerLbl;
@FXML
- private void subsExtListKeyPressed(KeyEvent event){
- if (event.getCode().toString().equals("DELETE"))
- subsExtRemoveRecord();
- }
- @FXML
- private void subsExtRemoveRecord(){ subsExtObservableList.remove(subsExtListView.getSelectionModel().getSelectedItem()); }
- @FXML
- private void subsExtUpRecord(){
- int index;
- index = subsExtListView.getSelectionModel().getSelectedIndex();
- if (index >0){
- subsExtObservableList.add(index-1, subsExtListView.getSelectionModel().getSelectedItem());
- subsExtObservableList.remove(index+1);
- subsExtListView.getSelectionModel().select(index-1);
- }
- }
- @FXML
- private void subsExtDownRecord(){
- int index;
- index = subsExtListView.getSelectionModel().getSelectedIndex();
- if (index+1 < subsExtObservableList.size() ){
- subsExtObservableList.add(index+2, subsExtListView.getSelectionModel().getSelectedItem());
- subsExtObservableList.remove(index);
- subsExtListView.getSelectionModel().select(index+1);
- }
- }
-
- // subs codepage
- @FXML
- private ListView subsCodepageListView;
- private ObservableList subsCodepageObservableList;
- @FXML
- private TextField subsCodepageNewRecordText;
- @FXML
- private void subsCodepageAddNewRecord(){
- String add = subsCodepageNewRecordText.getText().trim();
- if (!add.isEmpty()) // If this field is non-empty
- if (!add.contains(" ") && !add.contains("\t"))
- subsCodepageObservableList.add(subsCodepageNewRecordText.getText().trim());
- else{
- showFormattingError();
- }
- subsCodepageNewRecordText.clear();
- }
- @FXML
- private void subsCodepageListKeyPressed(KeyEvent event){
- if (event.getCode().toString().equals("DELETE"))
- subsCodepageRemoveRecord();
- }
- @FXML
- private void subsCodepageRemoveRecord(){ subsCodepageObservableList.remove(subsCodepageListView.getSelectionModel().getSelectedItem()); }
- @FXML
- private void subsCodepageUpRecord(){
- int index;
- index = subsCodepageListView.getSelectionModel().getSelectedIndex();
- if (index >0){
- subsCodepageObservableList.add(index-1, subsCodepageListView.getSelectionModel().getSelectedItem());
- subsCodepageObservableList.remove(index+1);
- subsCodepageListView.getSelectionModel().select(index-1);
- }
- }
- @FXML
- private void subsCodepageDownRecord(){
- int index;
- index = subsCodepageListView.getSelectionModel().getSelectedIndex();
- if (index+1 < subsCodepageObservableList.size() ){
- subsCodepageObservableList.add(index+2, subsCodepageListView.getSelectionModel().getSelectedItem());
- subsCodepageObservableList.remove(index);
- subsCodepageListView.getSelectionModel().select(index+1);
- }
- }
+ private CheckBox subtitlesFirstCheckBox;
@Override
public void initialize(URL url, ResourceBundle resBundle) {
- resourceBundle = resBundle;
appPreferences = new AppPreferences();
pathToMplayerLbl.setText(appPreferences.getPath());
- // unixOsInfoLbl.setVisible(false);
-
// Subtitles should be shown first? If TRUE, then set checkbox.
subtitlesFirstCheckBox.setSelected(appPreferences.getSubtilesFirst());
- // Should application restore lists after startup?
- listsLoadOnStartCheckBox.setSelected(appPreferences.getLoadListsOnStart());
- //---------------------------------------------------------
- // Populate list of avaliable subtitles extensions
- subsExtObservableList = FXCollections.observableArrayList(appPreferences.getSubsExtensionsList());
- subsExtListView.setItems(subsExtObservableList);
- //---------------------------------------------------------
- // Populate list of avaliable codepages
- subsCodepageObservableList = FXCollections.observableArrayList(appPreferences.getSubsEncodingList());
- subsCodepageListView.setItems(subsCodepageObservableList);
+ // Fill lists of extensions and encodings
+ subExtensionListController.setList(appPreferences.getSubsExtensionsList(), true);
+ subEncodingListController.setList(appPreferences.getSubsEncodingList(), false);
+ videoExtensionListController.setList(appPreferences.getVideoExtensionsList(), true);
+ audioExtensionListController.setList(appPreferences.getAudioExtensionsList(), true);
}
@FXML
@@ -189,9 +81,10 @@ public class SettingsController implements Initializable {
Stage thisStage = (Stage) pathToMplayerLbl.getScene().getWindow(); // TODO: consider refactoring. Non-urgent.
appPreferences.setPath(pathToMplayerLbl.getText());
appPreferences.setSubtilesFirst(subtitlesFirstCheckBox.isSelected());
- appPreferences.setLoadListsOnStart(listsLoadOnStartCheckBox.isSelected());
- appPreferences.setSubsExtensionsList(Arrays.copyOf(subsExtObservableList.toArray(), subsExtObservableList.toArray().length, String[].class));
- appPreferences.setSubsEncodingList(Arrays.copyOf(subsCodepageObservableList.toArray(), subsCodepageObservableList.toArray().length, String[].class));
+ appPreferences.setSubsExtensionsList(subExtensionListController.getList());
+ appPreferences.setSubsEncodingList(subEncodingListController.getList());
+ appPreferences.setVideoExtensionsList(videoExtensionListController.getList());
+ appPreferences.setAudioExtensionsList(audioExtensionListController.getList());
MediatorControl.getInstance().sentUpdates(); // TODO: implement list to track what should be updated
diff --git a/Settings/SettingsLayout.fxml b/Settings/SettingsLayout.fxml
index cc97e1c..769404f 100644
--- a/Settings/SettingsLayout.fxml
+++ b/Settings/SettingsLayout.fxml
@@ -4,142 +4,140 @@
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
diff --git a/appPanes/ControllerMKA.java b/appPanes/ControllerMKA.java
deleted file mode 100644
index 1a3ab21..0000000
--- a/appPanes/ControllerMKA.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package mplayer4anime.appPanes;
-
-public class ControllerMKA extends ControllerPane {
-
- @Override
- protected void openAction() { openFileChooser(".mka"); }
-}
diff --git a/appPanes/ControllerMKV.java b/appPanes/ControllerMKV.java
deleted file mode 100644
index b15167b..0000000
--- a/appPanes/ControllerMKV.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package mplayer4anime.appPanes;
-
-public class ControllerMKV extends ControllerPane {
-
- @Override
- protected void openAction() { openFileChooser(".mkv"); }
-}
diff --git a/appPanes/ControllerPane.java b/appPanes/ControllerPane.java
index bdf630b..3c2dfa7 100644
--- a/appPanes/ControllerPane.java
+++ b/appPanes/ControllerPane.java
@@ -4,32 +4,62 @@ import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
+import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.input.KeyEvent;
import javafx.stage.DirectoryChooser;
+import javafx.stage.FileChooser;
import javafx.util.Callback;
+import mplayer4anime.AppPreferences;
import java.io.File;
import java.io.FilenameFilter;
import java.net.URL;
import java.util.Arrays;
+import java.util.List;
import java.util.ResourceBundle;
-public abstract class ControllerPane implements Initializable {
+public class ControllerPane implements Initializable {
private ResourceBundle resourceBundle;
// use folderToOpen same variable in all panes
private static String folderToOpen;
+ private AppPreferences appPreferences;
+
@FXML
private ListView paneListView;
private ObservableList paneFileList = FXCollections.observableArrayList();
+ @FXML
+ private Label paneLbl;
+ private String paneType;
+
+
@Override
public void initialize(URL url, ResourceBundle resBundle) {
SetCellFactory(paneListView);
resourceBundle = resBundle;
+ appPreferences = new AppPreferences();
+ }
+ public void setPaneType(String paneType){
+ this.paneType = paneType;
+
+ switch (paneType) {
+ case "Video":
+ paneLbl.setText(resourceBundle.getString("lbl_VideoPane"));
+ break;
+ case "Audio":
+ paneLbl.setText(resourceBundle.getString("lbl_AudioPane"));
+ break;
+ case "Subtitles":
+ paneLbl.setText(resourceBundle.getString("lbl_SubsPane"));
+ break;
+ default:
+ paneLbl.setText(resourceBundle.getString("?"));
+ break;
+ }
}
/** Get index of the selected in pane element */
@@ -94,7 +124,24 @@ public abstract class ControllerPane implements Initializable {
/**
* Open file selector (Open folder button in UI).
* */
- void openFileChooser (String key){
+ @FXML
+ void openDirChooser(){
+ String[] filesExtension;
+ switch (paneType) {
+ case "Video":
+ filesExtension = appPreferences.getVideoExtensionsList();
+ break;
+ case "Audio":
+ filesExtension = appPreferences.getAudioExtensionsList();
+ break;
+ case "Subtitles":
+ filesExtension = appPreferences.getSubsExtensionsList();
+ break;
+ default:
+ filesExtension = new String[]{"*"};
+ break;
+ }
+
File directoryReceived; // Store files (folder) received from selector
DirectoryChooser dirSelect;
@@ -109,30 +156,68 @@ public abstract class ControllerPane implements Initializable {
// GET LIST OF FILES from directory
if (directoryReceived != null) {
- setFilesFromFolder(directoryReceived, key);
+ File[] files; // Store files mkv/mka
+
+ files = directoryReceived.listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(File file, String Name) {
+ if (Name.lastIndexOf('.') > 0) {
+ int lastindex = Name.lastIndexOf('.');
+ String ext = Name.substring(lastindex);
+ for (String key : filesExtension){
+ if (ext.equals(key.substring(1)))
+ return true;
+ }
+ } else
+ return false;
+ return false;
+ }
+ });
+
+ displayFiles(files);
} else {
- System.out.println("\tNo folder selected");
+ System.out.println("No folder selected");
}
}
+ /**
+ * Open file selector (Open files button in UI).
+ * */
+ @FXML
+ void openFilesChooser(){
+ String[] filesExtension;
+ switch (paneType) {
+ case "Video":
+ filesExtension = appPreferences.getVideoExtensionsList();
+ break;
+ case "Audio":
+ filesExtension = appPreferences.getAudioExtensionsList();
+ break;
+ case "Subtitles":
+ filesExtension = appPreferences.getSubsExtensionsList();
+ break;
+ default:
+ filesExtension = new String[]{"*"};
+ break;
+ }
- private void setFilesFromFolder(File directoryReceived, String key) {
- File[] files; // Store files mkv/mka
+ List filesRecievedList;
- files = directoryReceived.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File file, String Name) {
- if (Name.lastIndexOf('.') > 0) {
- int lastindex = Name.lastIndexOf('.');
- String ext = Name.substring(lastindex);
- if (ext.equals(key))
- return true;
- } else
- return false;
- return false;
- }
- });
+ FileChooser fc = new FileChooser();
+ fc.setTitle(resourceBundle.getString("SelectFile"));
+ if (folderToOpen == null)
+ fc.setInitialDirectory(new File(System.getProperty("user.home")));
+ else
+ fc.setInitialDirectory(new File(folderToOpen));
+ fc.getExtensionFilters().addAll(new FileChooser.ExtensionFilter(paneType, filesExtension));
- displayFiles(files);
+ filesRecievedList = fc.showOpenMultipleDialog(paneListView.getScene().getWindow());
+ if (filesRecievedList != null){
+ File[] filesRecieved = new File[filesRecievedList.size()];
+ filesRecievedList.toArray(filesRecieved);
+ displayFiles(filesRecieved);
+ } else {
+ System.out.println("No files selected");
+ }
}
/**
* Set files using lists. Used if playlist loaded
@@ -151,16 +236,10 @@ public abstract class ControllerPane implements Initializable {
// spiced java magic
Arrays.sort(files);
- /* DEBUG START
- for (File eachFile : files)
- System.out.println(eachFile.getAbsoluteFile());
- DEBUG END */
-
// Remember the folder used for MKV and reuse it when user opens MKA/subs folder (as new default path instead of user.home)
folderToOpen = files[0].getParent();
//System.out.println(folderToOpen);
- paneListView.getItems().clear(); // wipe elements from ListView
paneFileList.addAll(files);
paneListView.setItems(paneFileList);
paneListView.getSelectionModel().select(0);
@@ -169,6 +248,11 @@ public abstract class ControllerPane implements Initializable {
System.out.println("\tNo files in this folder");
}
}
+ @FXML
+ public void cleanList(){
+ paneListView.getItems().clear(); // wipe elements from ListView
+ }
+
@FXML
private void Up(){
int index;
@@ -197,7 +281,4 @@ public abstract class ControllerPane implements Initializable {
if (event.getCode().toString().equals("DELETE"))
Del();
}
- // TO IMPLEMENT IN REAL CLASS
- @FXML
- protected abstract void openAction();
}
\ No newline at end of file
diff --git a/appPanes/ControllerSUB.java b/appPanes/ControllerSUB.java
index a94d0c4..cbf12e9 100644
--- a/appPanes/ControllerSUB.java
+++ b/appPanes/ControllerSUB.java
@@ -11,64 +11,39 @@ import java.util.Arrays;
import java.util.ResourceBundle;
public class ControllerSUB extends ControllerPane {
- // TODO: Move file extension filtering options to the OS-selector and remove drop-down with file ext. filtering options
- @FXML
- private ChoiceBox subtExt;
- // Observable list of the content subtExt
- private ObservableList subtExtList;
-
@FXML
private ChoiceBox subtEncoding;
- // Observable list of the content subtEncoding
private ObservableList subEncodingList;
public void initialize(URL url, ResourceBundle rb) {
super.initialize(url, rb);
- this.subtExtList = FXCollections.observableArrayList();
this.subEncodingList = FXCollections.observableArrayList();
}
- @Override
- protected void openAction() { openFileChooser(subtExt.getValue());} // TODO: check if non-empty and show error if needed
- /** Return selected file extension */
- // Walking on the thin ice..
- public String getSelectedExt(){
- return subtExt.getSelectionModel().getSelectedItem();
- }
/** Return selected file encoding */
public String getSelectedEncoding(){
return subtEncoding.getSelectionModel().getSelectedItem();
}
- /**
- * Set Files extensions list and select element
- * */
- public void setSubtExt(String[] list, String selection){
- setMenuElements(subtExt, subtExtList, list, selection);
- }
/**
* Set encoding list and select element
* */
public void setEncoding(String[] list, String selection){
- setMenuElements(subtEncoding, subEncodingList, list, selection);
- }
- /* Encoding and Extension common setter */
- private void setMenuElements(ChoiceBox menu, ObservableList obsList, String[] list, String selection){
- String currentlySelectedValue = menu.getValue();
+ String currentlySelectedValue = subtEncoding.getValue();
- obsList.clear();
- obsList.setAll(list);
- menu.setItems(obsList);
+ subEncodingList.clear();
+ subEncodingList.setAll(list);
+ subtEncoding.setItems(subEncodingList);
if (selection == null || selection.isEmpty())
// Try to restore previously selected value if it existed before and exists in the new list
- if (currentlySelectedValue !=null && !currentlySelectedValue.isEmpty() && obsList.contains(currentlySelectedValue))
- menu.getSelectionModel().select(currentlySelectedValue);
+ if (currentlySelectedValue !=null && !currentlySelectedValue.isEmpty() && subEncodingList.contains(currentlySelectedValue))
+ subtEncoding.getSelectionModel().select(currentlySelectedValue);
else
- menu.setValue(obsList.get(0));
+ subtEncoding.setValue(subEncodingList.get(0));
else {
- if (obsList.contains(selection))
- menu.getSelectionModel().select(selection);
+ if (subEncodingList.contains(selection))
+ subtEncoding.getSelectionModel().select(selection);
else
- menu.setValue(obsList.get(0));
+ subtEncoding.setValue(subEncodingList.get(0));
}
}
/**
@@ -76,14 +51,16 @@ public class ControllerSUB extends ControllerPane {
* Updates stored lists/selection of encoding
* */
public void selectEncodingValue(String encodingValue, AppPreferences preferences){
- if (encodingValue != null && !encodingValue.isEmpty()) {
- if (!subEncodingList.contains(encodingValue)) {
- subEncodingList.add(encodingValue);
- preferences.setSubsEncodingList(Arrays.copyOf(subEncodingList.toArray(), subEncodingList.toArray().length, String[].class));
- }
- if (!subtEncoding.getValue().equals(encodingValue)) {
- subtEncoding.getSelectionModel().select(encodingValue);
- preferences.setLastTimeUsedSubsEncoding(encodingValue);
+ if (encodingValue != null && !(encodingValue = encodingValue.trim()).isEmpty()) {
+ if (!encodingValue.contains("\t") && !encodingValue.contains(" ")){ // If contains spaces or tabs, ignore.
+ if (!subEncodingList.contains(encodingValue)) {
+ subEncodingList.add(encodingValue);
+ preferences.setSubsEncodingList(Arrays.copyOf(subEncodingList.toArray(), subEncodingList.toArray().length, String[].class));
+ }
+ if (!subtEncoding.getValue().equals(encodingValue)) {
+ subtEncoding.getSelectionModel().select(encodingValue);
+ preferences.setLastTimeUsedSubsEncoding(encodingValue);
+ }
}
}
}
diff --git a/appPanes/mkvPane.fxml b/appPanes/genericPane.fxml
similarity index 51%
rename from appPanes/mkvPane.fxml
rename to appPanes/genericPane.fxml
index b7bba25..d8c2db1 100644
--- a/appPanes/mkvPane.fxml
+++ b/appPanes/genericPane.fxml
@@ -2,6 +2,7 @@
+
@@ -9,29 +10,41 @@
-
+
-
+
-