Preferences and Setting refactoring

This commit is contained in:
Dmitry Isaenko 2019-05-22 04:41:35 +03:00
parent bc2764b123
commit 01d5ebd634
5 changed files with 100 additions and 325 deletions

View file

@ -16,61 +16,10 @@ public class AppPreferences {
public void setAll(
String xciHeaderKey,
String headerKey,
String applicationKey0,
String applicationKey1,
String applicationKey2,
String applicationKey3,
String applicationKey4,
String applicationKey5,
String applicationKey6,
String applicationKey7,
String oceanKey0,
String oceanKey1,
String oceanKey2,
String oceanKey3,
String oceanKey4,
String oceanKey5,
String oceanKey6,
String oceanKey7,
String systemKey0,
String systemKey1,
String systemKey2,
String systemKey3,
String systemKey4,
String systemKey5,
String systemKey6,
String systemKey7
String headerKey
) {
setXciHeaderKey(xciHeaderKey);
setHeaderKey(headerKey);
setApplicationKey(0, applicationKey0);
setApplicationKey(1, applicationKey1);
setApplicationKey(2, applicationKey2);
setApplicationKey(3, applicationKey3);
setApplicationKey(4, applicationKey4);
setApplicationKey(5, applicationKey5);
setApplicationKey(6, applicationKey6);
setApplicationKey(7, applicationKey7);
setOceanKey(0, oceanKey0);
setOceanKey(1, oceanKey1);
setOceanKey(2, oceanKey2);
setOceanKey(3, oceanKey3);
setOceanKey(4, oceanKey4);
setOceanKey(5, oceanKey5);
setOceanKey(6, oceanKey6);
setOceanKey(7, oceanKey7);
setSystemKey(0, systemKey0);
setSystemKey(1, systemKey1);
setSystemKey(2, systemKey2);
setSystemKey(3, systemKey3);
setSystemKey(4, systemKey4);
setSystemKey(5, systemKey5);
setSystemKey(6, systemKey6);
setSystemKey(7, systemKey7);
}
public String getRecentPath(){return preferences.get("recent_path", System.getProperty("user.home"));}

View file

@ -13,6 +13,7 @@ import konogonka.ServiceWindow;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.ResourceBundle;
public class ListSelectorController implements Initializable {
@ -61,7 +62,7 @@ public class ListSelectorController implements Initializable {
* Must be run on start
* Set list content
*/
void setList(HashMap<String, String> stringPairsArray){
void setList(LinkedHashMap<String, String> stringPairsArray){
if (stringPairsArray != null && ! stringPairsArray.isEmpty())
for (String name: stringPairsArray.keySet())
validateAndAdd(name+" = "+stringPairsArray.get(name));

View file

@ -13,6 +13,7 @@ import konogonka.AppPreferences;
import java.io.*;
import java.net.URL;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.ResourceBundle;
public class SettingsController implements Initializable {
@ -20,42 +21,51 @@ public class SettingsController implements Initializable {
private Button okBtn, cancelBtn, importKeysBtn, importTitleKeysBtn;
@FXML
ListSelectorController ListSelectorTitleKeysController;
ListSelectorController
ListSelectorKAEKAppController,
ListSelectorKAEKOceanController,
ListSelectorKAEKSysController,
ListSelectorTitleKeysController;
@FXML
private TextField
xciHdrKeyTF,
hdrKeyTF,
keyApp0TF,
keyApp1TF,
keyApp2TF,
keyApp3TF,
keyApp4TF,
keyApp5TF,
keyApp6TF,
keyApp7TF,
keyOcean0TF,
keyOcean1TF,
keyOcean2TF,
keyOcean3TF,
keyOcean4TF,
keyOcean5TF,
keyOcean6TF,
keyOcean7TF,
keySys0TF,
keySys1TF,
keySys2TF,
keySys3TF,
keySys4TF,
keySys5TF,
keySys6TF,
keySys7TF;
hdrKeyTF;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
ListSelectorKAEKAppController.initSelector(32, "key_area_key_application_");
ListSelectorKAEKOceanController.initSelector(32, "key_area_key_ocean_");
ListSelectorKAEKSysController.initSelector(32, "key_area_key_sys_");
ListSelectorTitleKeysController.initSelector(32, null); // 32 required
HashMap<String, String> preparedPairsMapInit = new HashMap<>();
LinkedHashMap<String, String> preparedPairsMapInit = new LinkedHashMap<>();
String kaekApp;
int cnt = 0;
while (!(kaekApp = AppPreferences.getInstance().getApplicationKey(cnt)).isEmpty()){
preparedPairsMapInit.put("key_area_key_application_"+String.format("%02d", cnt), kaekApp);
cnt++;
}
ListSelectorKAEKAppController.setList(preparedPairsMapInit);
preparedPairsMapInit.clear();
cnt = 0;
while (!(kaekApp = AppPreferences.getInstance().getOceanKey(cnt)).isEmpty()){
preparedPairsMapInit.put("key_area_key_ocean_"+String.format("%02d", cnt), kaekApp);
cnt++;
}
ListSelectorKAEKOceanController.setList(preparedPairsMapInit);
preparedPairsMapInit.clear();
cnt = 0;
while (!(kaekApp = AppPreferences.getInstance().getSystemKey(cnt)).isEmpty()){
preparedPairsMapInit.put("key_area_key_sys_"+String.format("%02d", cnt), kaekApp);
cnt++;
}
ListSelectorKAEKSysController.setList(preparedPairsMapInit);
preparedPairsMapInit.clear();
for (int i = 0; i < AppPreferences.getInstance().getTitleKeysCount(); i++){
preparedPairsMapInit.put(
AppPreferences.getInstance().getTitleKeyPair(i)[0],
@ -66,57 +76,9 @@ public class SettingsController implements Initializable {
xciHdrKeyTF.setText(AppPreferences.getInstance().getXciHeaderKey());
hdrKeyTF.setText(AppPreferences.getInstance().getHeaderKey());
keyApp0TF.setText(AppPreferences.getInstance().getApplicationKey(0));
keyApp1TF.setText(AppPreferences.getInstance().getApplicationKey(1));
keyApp2TF.setText(AppPreferences.getInstance().getApplicationKey(2));
keyApp3TF.setText(AppPreferences.getInstance().getApplicationKey(3));
keyApp4TF.setText(AppPreferences.getInstance().getApplicationKey(4));
keyApp5TF.setText(AppPreferences.getInstance().getApplicationKey(5));
keyApp6TF.setText(AppPreferences.getInstance().getApplicationKey(6));
keyApp7TF.setText(AppPreferences.getInstance().getApplicationKey(7));
keyOcean0TF.setText(AppPreferences.getInstance().getOceanKey(0));
keyOcean1TF.setText(AppPreferences.getInstance().getOceanKey(1));
keyOcean2TF.setText(AppPreferences.getInstance().getOceanKey(2));
keyOcean3TF.setText(AppPreferences.getInstance().getOceanKey(3));
keyOcean4TF.setText(AppPreferences.getInstance().getOceanKey(4));
keyOcean5TF.setText(AppPreferences.getInstance().getOceanKey(5));
keyOcean6TF.setText(AppPreferences.getInstance().getOceanKey(6));
keyOcean7TF.setText(AppPreferences.getInstance().getOceanKey(7));
keySys0TF.setText(AppPreferences.getInstance().getSystemKey(0));
keySys1TF.setText(AppPreferences.getInstance().getSystemKey(1));
keySys2TF.setText(AppPreferences.getInstance().getSystemKey(2));
keySys3TF.setText(AppPreferences.getInstance().getSystemKey(3));
keySys4TF.setText(AppPreferences.getInstance().getSystemKey(4));
keySys5TF.setText(AppPreferences.getInstance().getSystemKey(5));
keySys6TF.setText(AppPreferences.getInstance().getSystemKey(6));
keySys7TF.setText(AppPreferences.getInstance().getSystemKey(7));
setTextValidation(xciHdrKeyTF);
setTextValidation(hdrKeyTF);
setTextValidation(keyApp0TF);
setTextValidation(keyApp1TF);
setTextValidation(keyApp2TF);
setTextValidation(keyApp3TF);
setTextValidation(keyApp4TF);
setTextValidation(keyApp5TF);
setTextValidation(keyApp6TF);
setTextValidation(keyApp7TF);
setTextValidation(keyOcean0TF);
setTextValidation(keyOcean1TF);
setTextValidation(keyOcean2TF);
setTextValidation(keyOcean3TF);
setTextValidation(keyOcean4TF);
setTextValidation(keyOcean5TF);
setTextValidation(keyOcean6TF);
setTextValidation(keyOcean7TF);
setTextValidation(keySys0TF);
setTextValidation(keySys1TF);
setTextValidation(keySys2TF);
setTextValidation(keySys3TF);
setTextValidation(keySys4TF);
setTextValidation(keySys5TF);
setTextValidation(keySys6TF);
setTextValidation(keySys7TF);
importKeysBtn.setOnAction(e->{
FileChooser fileChooser = new FileChooser();
@ -141,30 +103,32 @@ public class SettingsController implements Initializable {
fileMap.put(keyValue[0], keyValue[1]);
}
hdrKeyTF.setText(fileMap.get("header_key"));
keyApp0TF.setText(fileMap.get("key_area_key_application_00"));
keyApp1TF.setText(fileMap.get("key_area_key_application_01"));
keyApp2TF.setText(fileMap.get("key_area_key_application_02"));
keyApp3TF.setText(fileMap.get("key_area_key_application_03"));
keyApp4TF.setText(fileMap.get("key_area_key_application_04"));
keyApp5TF.setText(fileMap.get("key_area_key_application_05"));
keyApp6TF.setText(fileMap.get("key_area_key_application_06"));
keyApp7TF.setText(fileMap.get("key_area_key_application_07"));
keyOcean0TF.setText(fileMap.get("key_area_key_ocean_00"));
keyOcean1TF.setText(fileMap.get("key_area_key_ocean_01"));
keyOcean2TF.setText(fileMap.get("key_area_key_ocean_02"));
keyOcean3TF.setText(fileMap.get("key_area_key_ocean_03"));
keyOcean4TF.setText(fileMap.get("key_area_key_ocean_04"));
keyOcean5TF.setText(fileMap.get("key_area_key_ocean_05"));
keyOcean6TF.setText(fileMap.get("key_area_key_ocean_06"));
keyOcean7TF.setText(fileMap.get("key_area_key_ocean_07"));
keySys0TF.setText(fileMap.get("key_area_key_system_00"));
keySys1TF.setText(fileMap.get("key_area_key_system_01"));
keySys2TF.setText(fileMap.get("key_area_key_system_02"));
keySys3TF.setText(fileMap.get("key_area_key_system_03"));
keySys4TF.setText(fileMap.get("key_area_key_system_04"));
keySys5TF.setText(fileMap.get("key_area_key_system_05"));
keySys6TF.setText(fileMap.get("key_area_key_system_06"));
keySys7TF.setText(fileMap.get("key_area_key_system_07"));
LinkedHashMap<String, String> kaekSingle = new LinkedHashMap<>();
String keyParsed;
int counter = 0;
while ((keyParsed = fileMap.get("key_area_key_application_"+String.format("%02d", counter))) != null){
kaekSingle.put("key_area_key_application_"+String.format("%02d", counter), keyParsed);
counter++;
}
ListSelectorKAEKAppController.setList(kaekSingle);
kaekSingle.clear();
counter = 0;
while ((keyParsed = fileMap.get("key_area_key_ocean_"+String.format("%02d", counter))) != null){
kaekSingle.put("key_area_key_ocean_"+String.format("%02d", counter), keyParsed);
counter++;
}
ListSelectorKAEKOceanController.setList(kaekSingle);
kaekSingle.clear();
counter = 0;
while ((keyParsed = fileMap.get("key_area_key_system_"+String.format("%02d", counter))) != null){
kaekSingle.put("key_area_key_system_"+String.format("%02d", counter), keyParsed);
counter++;
}
ListSelectorKAEKSysController.setList(kaekSingle);
}
catch (IOException ioe){
ioe.printStackTrace();
@ -188,7 +152,7 @@ public class SettingsController implements Initializable {
String fileLine;
String[] keyValue;
HashMap<String, String> preparedPairsMap = new HashMap<>();
LinkedHashMap<String, String> preparedPairsMap = new LinkedHashMap<>();
while ((fileLine = br.readLine()) != null){
keyValue = fileLine.trim().split("\\s+?=\\s+?", 2);
if (keyValue.length == 2 && keyValue[0].length() == 32 && keyValue[1].length() == 32){
@ -210,34 +174,30 @@ public class SettingsController implements Initializable {
okBtn.setOnAction(e->{
Stage thisStage = (Stage)cancelBtn.getScene().getWindow();
// Saving all keys we have
AppPreferences.getInstance().setAll(
xciHdrKeyTF.getText(),
hdrKeyTF.getText(),
keyApp0TF.getText(),
keyApp1TF.getText(),
keyApp2TF.getText(),
keyApp3TF.getText(),
keyApp4TF.getText(),
keyApp5TF.getText(),
keyApp6TF.getText(),
keyApp7TF.getText(),
keyOcean0TF.getText(),
keyOcean1TF.getText(),
keyOcean2TF.getText(),
keyOcean3TF.getText(),
keyOcean4TF.getText(),
keyOcean5TF.getText(),
keyOcean6TF.getText(),
keyOcean7TF.getText(),
keySys0TF.getText(),
keySys1TF.getText(),
keySys2TF.getText(),
keySys3TF.getText(),
keySys4TF.getText(),
keySys5TF.getText(),
keySys6TF.getText(),
keySys7TF.getText()
hdrKeyTF.getText()
);
String[] kaekAppKeySet = ListSelectorKAEKAppController.getList();
if (kaekAppKeySet != null){
for (int i = 0; i < kaekAppKeySet.length; i++)
AppPreferences.getInstance().setApplicationKey(i, kaekAppKeySet[i].split("\\s=\\s", 2)[1]);
}
String[] kaekOceanKeySet = ListSelectorKAEKOceanController.getList();
if (kaekOceanKeySet != null){
for (int i = 0; i < kaekOceanKeySet.length; i++)
AppPreferences.getInstance().setOceanKey(i, kaekOceanKeySet[i].split("\\s=\\s", 2)[1]);
}
String[] kaekSysKeySet = ListSelectorKAEKSysController.getList();
if (kaekSysKeySet != null){
for (int i = 0; i < kaekSysKeySet.length; i++)
AppPreferences.getInstance().setOceanKey(i, kaekSysKeySet[i].split("\\s=\\s", 2)[1]);
}
String[] titleKeysSet = ListSelectorTitleKeysController.getList();
if (titleKeysSet != null){
AppPreferences.getInstance().setTitleKeysCount(titleKeysSet.length);

View file

@ -8,11 +8,11 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.SVGPath?>
<VBox spacing="5.0" VBox.vgrow="ALWAYS" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="konogonka.Settings.ListSelectorController">
<VBox minHeight="250.0" spacing="5.0" VBox.vgrow="ALWAYS" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="konogonka.Settings.ListSelectorController">
<children>
<HBox alignment="CENTER_LEFT" spacing="5.0" VBox.vgrow="ALWAYS">
<children>
<ListView fx:id="listView" onKeyPressed="#listKeyPressed" prefWidth="200.0" HBox.hgrow="ALWAYS" />
<ListView fx:id="listView" onKeyPressed="#listKeyPressed" HBox.hgrow="ALWAYS" />
<VBox spacing="5.0">
<children>
<Button mnemonicParsing="false" onAction="#removeRecord">

View file

@ -14,7 +14,7 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.SVGPath?>
<VBox minHeight="600.0" minWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="konogonka.Settings.SettingsController">
<VBox xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="konogonka.Settings.SettingsController">
<children>
<TabPane side="LEFT" tabClosingPolicy="UNAVAILABLE" tabMaxHeight="100.0" tabMaxWidth="80.0" tabMinHeight="80.0" tabMinWidth="50.0" VBox.vgrow="ALWAYS">
<tabs>
@ -47,150 +47,15 @@
</HBox>
<Label disable="true" text="Length should be 64 symbols" wrapText="true" />
<Pane VBox.vgrow="ALWAYS" />
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_00" />
<TextField fx:id="keyApp0TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_01" />
<TextField fx:id="keyApp1TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_02" />
<TextField fx:id="keyApp2TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_03" />
<TextField fx:id="keyApp3TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_04" />
<TextField fx:id="keyApp4TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_05" />
<TextField fx:id="keyApp5TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_06" />
<TextField fx:id="keyApp6TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_07" />
<TextField fx:id="keyApp7TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_00" />
<TextField fx:id="keyOcean0TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_01" />
<TextField fx:id="keyOcean1TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_02" />
<TextField fx:id="keyOcean2TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_03" />
<TextField fx:id="keyOcean3TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_04" />
<TextField fx:id="keyOcean4TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_05" />
<TextField fx:id="keyOcean5TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_06" />
<TextField fx:id="keyOcean6TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_07" />
<TextField fx:id="keyOcean7TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_00" />
<TextField fx:id="keySys0TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_01" />
<TextField fx:id="keySys1TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_02" />
<TextField fx:id="keySys2TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_03" />
<TextField fx:id="keySys3TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_04" />
<TextField fx:id="keySys4TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_05" />
<TextField fx:id="keySys5TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_06" />
<TextField fx:id="keySys6TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_07" />
<TextField fx:id="keySys7TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<Separator prefWidth="200.0" />
<Label text="Label" />
<fx:include fx:id="ListSelectorKAEKApp" source="ListSelectorLayout.fxml" VBox.vgrow="ALWAYS" />
<Separator prefWidth="200.0" />
<Label text="Label" />
<fx:include fx:id="ListSelectorKAEKOcean" source="ListSelectorLayout.fxml" VBox.vgrow="ALWAYS" />
<Separator prefWidth="200.0" />
<Label text="Label" />
<fx:include fx:id="ListSelectorKAEKSys" source="ListSelectorLayout.fxml" VBox.vgrow="ALWAYS" />
<Separator prefWidth="200.0" />
</children>
<padding>