Code refactoring
This commit is contained in:
parent
2af689b666
commit
2735c8bfa7
4 changed files with 30 additions and 46 deletions
|
@ -6,8 +6,8 @@ import javafx.fxml.FXML;
|
|||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.TextFormatter;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import mplayer4anime.ServiceWindow;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
|
@ -21,7 +21,7 @@ public class ControllerListsSelector implements Initializable {
|
|||
private ObservableList<String> observableList;
|
||||
private ResourceBundle resourceBundle;
|
||||
|
||||
private boolean listOfExtensions; // Handle validation of the format importing items
|
||||
private boolean isListOfExtensions;
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle rb) {
|
||||
|
@ -32,9 +32,25 @@ public class ControllerListsSelector implements Initializable {
|
|||
* Set list content
|
||||
*/
|
||||
void setList(String[] listFromStorage, boolean isListOfExtensions){
|
||||
this.isListOfExtensions = isListOfExtensions;
|
||||
observableList = FXCollections.observableArrayList(listFromStorage);
|
||||
listView.setItems(observableList);
|
||||
this.listOfExtensions = isListOfExtensions;
|
||||
if (isListOfExtensions) {
|
||||
newRecordText.setText("*.");
|
||||
newRecordText.setTextFormatter(new TextFormatter<Object>(change -> {
|
||||
if (change.getControlNewText().matches("(^\\*\\.[A-Za-z0-9]$)|(^\\*\\.[A-Za-z0-9][A-Za-z0-9\\.]+?$)|(^\\*\\.$)"))
|
||||
return change;
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
else {
|
||||
newRecordText.setTextFormatter(new TextFormatter<Object>(change -> {
|
||||
if (change.getControlNewText().matches("(^[A-Za-z0-9\\-]+?$)|(^$)"))
|
||||
return change;
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Return list content
|
||||
|
@ -71,40 +87,14 @@ public class ControllerListsSelector implements Initializable {
|
|||
private void removeRecord(){ observableList.remove(listView.getSelectionModel().getSelectedItem()); }
|
||||
@FXML
|
||||
private void addNewRecord(){
|
||||
String addingItem = newRecordText.getText().trim().toLowerCase();
|
||||
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 {
|
||||
validateAndAdd(addingItem);
|
||||
}
|
||||
}
|
||||
else if (addingItem.contains("*")) {
|
||||
ServiceWindow.getErrorNotification(resourceBundle.getString("Error"), resourceBundle.getString("settings_fieldContainUnacceptedChars"));
|
||||
}
|
||||
else if (addingItem.startsWith(".")) {
|
||||
validateAndAdd("*" + addingItem);
|
||||
}
|
||||
else {
|
||||
validateAndAdd("*." + addingItem);
|
||||
}
|
||||
}
|
||||
else {
|
||||
validateAndAdd(addingItem);
|
||||
}
|
||||
}
|
||||
else{
|
||||
ServiceWindow.getErrorNotification(resourceBundle.getString("Error"), resourceBundle.getString("settings_fieldContainUnacceptedChars"));
|
||||
}
|
||||
newRecordText.clear();
|
||||
}
|
||||
private void validateAndAdd(String addingItem){
|
||||
if (!observableList.contains(addingItem)) {
|
||||
String addingItem = newRecordText.getText().toLowerCase();
|
||||
if (!addingItem.isEmpty()) { // If this field is non-empty
|
||||
if (!observableList.contains(addingItem))
|
||||
observableList.add(addingItem);
|
||||
}
|
||||
if (isListOfExtensions)
|
||||
newRecordText.setText("*.");
|
||||
else
|
||||
newRecordText.clear();
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.shape.SVGPath?>
|
||||
|
||||
<VBox prefHeight="200.0" prefWidth="100.0" spacing="5.0" VBox.vgrow="ALWAYS" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mplayer4anime.Settings.ControllerListsSelector">
|
||||
<VBox prefHeight="200.0" prefWidth="100.0" spacing="5.0" VBox.vgrow="ALWAYS" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mplayer4anime.Settings.ControllerListsSelector">
|
||||
<children>
|
||||
<HBox alignment="CENTER_LEFT" spacing="5.0" VBox.vgrow="ALWAYS">
|
||||
<children>
|
||||
|
|
|
@ -13,7 +13,7 @@ settings_PathToMplayerLbl=Path to mplayer executable:
|
|||
OkBtn=OK
|
||||
settings_SettingsName=Settings
|
||||
main_tab_subtitles=Subtitles
|
||||
settings_SubtitlesTabFirst=Show 'Subutitles' tab first after application starts:
|
||||
settings_SubtitlesTabFirst=Show 'Subutitles' tab first after application starts
|
||||
ErrorUnableToStartMplayer=Unable to execute 'mplayer'.\n\
|
||||
1. Make sure it's installed.\n\
|
||||
2. Check application settings.
|
||||
|
@ -22,9 +22,6 @@ Please don't change it if not sure.
|
|||
SelectDirectoryTitle=Select directory
|
||||
settings_subsExtensionList=Avaliable subtitles extensions:
|
||||
settings_subsCodepageList=Avaliable codepages for subtitles:
|
||||
settings_fieldContainUnacceptedChars=Spaces and tab symbols are not allowed.\n\
|
||||
'*' symbol could be only in the starting position.\n\
|
||||
Example: *.mp3
|
||||
subsShow_option=Don't show subtitles.
|
||||
menu_File=File
|
||||
menu_Tools=Tools
|
||||
|
|
|
@ -14,7 +14,7 @@ settings_PathToMplayerLbl=\u0420\u0430\u0441\u043F\u043E\u043B\u043E\u0436\u0435
|
|||
OkBtn=\u041E\u041A
|
||||
settings_SettingsName=\u041D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0438
|
||||
main_tab_subtitles=\u0421\u0443\u0431\u0442\u0438\u0442\u0440\u044B
|
||||
settings_SubtitlesTabFirst=\u041F\u0440\u0438 \u0437\u0430\u043F\u0443\u0441\u043A\u0435 \u0441\u043F\u0435\u0440\u0432\u0430 \u043F\u043E\u043A\u0430\u0437\u044B\u0432\u0430\u0442\u044C \u0432\u043A\u043B\u0430\u0434\u043A\u0443 "\u0421\u0443\u0431\u0442\u0438\u0442\u0440\u044B":
|
||||
settings_SubtitlesTabFirst=\u041F\u0440\u0438 \u0437\u0430\u043F\u0443\u0441\u043A\u0435 \u0441\u043F\u0435\u0440\u0432\u0430 \u043F\u043E\u043A\u0430\u0437\u044B\u0432\u0430\u0442\u044C \u0432\u043A\u043B\u0430\u0434\u043A\u0443 \u00AB\u0421\u0443\u0431\u0442\u0438\u0442\u0440\u044B\u00BB
|
||||
ErrorUnableToStartMplayer=\u041D\u0435\u0432\u043E\u0437\u043C\u043E\u0436\u043D\u043E \u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u044C mplayer.\n\
|
||||
1. \u0423\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044C, \u0447\u0442\u043E \u043E\u043D \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D.\n\
|
||||
2. \u041F\u0440\u043E\u0432\u0435\u0440\u044C\u0442\u0435 \u043F\u0440\u0430\u0432\u0438\u043B\u044C\u043D\u043E\u0441\u0442\u044C \u043D\u0430\u0441\u0442\u0440\u043E\u0435\u043A.
|
||||
|
@ -23,9 +23,6 @@ settings_unixOsInformation=Unix-\u043F\u043E\u0434\u043E\u0431\u043D\u044B\u0435
|
|||
SelectDirectoryTitle=\u0412\u044B\u0431\u043E\u0440 \u0434\u0438\u0440\u0435\u043A\u0442\u043E\u0440\u0438\u0438
|
||||
settings_subsExtensionList=\u0414\u043E\u0441\u0442\u0443\u043F\u043D\u044B\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043D\u0438\u044F \u0434\u043B\u044F \u0441\u0443\u0431\u0442\u0438\u0442\u0440\u043E\u0432:
|
||||
settings_subsCodepageList=\u0414\u043E\u0441\u0442\u0443\u043F\u043D\u044B\u0435 \u043A\u043E\u0434\u0438\u0440\u043E\u0432\u043A\u0438 \u0434\u043B\u044F \u0441\u0443\u0431\u0442\u0438\u0442\u0440\u043E\u0432:
|
||||
settings_fieldContainUnacceptedChars=\u041F\u0440\u043E\u0431\u0435\u043B\u044B \u0438 \u0441\u0438\u043C\u0432\u043E\u043B\u044B \u0442\u0430\u0431\u0443\u043B\u044F\u0446\u0438\u0438 \u043D\u0435\u0434\u043E\u043F\u0443\u0441\u0442\u0438\u043C\u044B.\n\
|
||||
\u0421\u0438\u043C\u0432\u043E\u043B "*" \u043C\u043E\u0436\u0435\u0442 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C\u0441\u044F \u0442\u043E\u043B\u044C\u043A\u043E \u0432 \u043D\u0430\u0447\u0430\u043B\u0435.\n\
|
||||
\u041F\u0440\u0438\u043C\u0435\u0440: *.mp3
|
||||
subsShow_option=\u041D\u0435 \u043E\u0442\u043E\u0431\u0440\u0430\u0436\u0430\u0442\u044C \u0441\u0443\u0431\u0442\u0438\u0442\u0440\u044B.
|
||||
menu_File=\u0424\u0430\u0439\u043B
|
||||
menu_Tools=\u0418\u043D\u0441\u0442\u0440\u0443\u043C\u0435\u043D\u0442\u044B
|
||||
|
|
Loading…
Reference in a new issue