code clean up

This commit is contained in:
Jannik 2018-06-12 16:24:12 +02:00
parent cc4e73c45d
commit 9b7a85cabe
3 changed files with 72 additions and 120 deletions

View File

@ -47,7 +47,6 @@ import javafx.scene.control.ButtonType;
import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
public class Main extends Application { public class Main extends Application {
private Stage primaryStage; private Stage primaryStage;
@ -63,13 +62,12 @@ public class Main extends Application {
private static String javaVers = System.getProperty("java.version"); private static String javaVers = System.getProperty("java.version");
private static String javaVend= System.getProperty("java.vendor"); private static String javaVend= System.getProperty("java.vendor");
private String gamesDBdownloadURL = "https://github.com/Seil0/cemu_UI/raw/master/downloadContent/games.db"; private String gamesDBdownloadURL = "https://github.com/Seil0/cemu_UI/raw/master/downloadContent/games.db";
public String dirWin = userHome + "/Documents/cemu_UI"; // Windows: C:/Users/"User"/Documents/cemu_UI private static String dirCemuUI;
public String dirLinux = userHome + "/cemu_UI"; // Linux: /home/"User"/cemu_UI private static File directory;
private File directory; private static File configFile;
private File configFile; private static File gamesDBFile;
private File gamesDBFile; private static File reference_gamesFile;
private File reference_gamesFile; private static File pictureCache;
private File pictureCache;
private static Logger LOGGER; private static Logger LOGGER;
@Override @Override
@ -78,7 +76,10 @@ public class Main extends Application {
LOGGER.info("OS: " + osName + " " + osVers + " " + osArch); LOGGER.info("OS: " + osName + " " + osVers + " " + osArch);
LOGGER.info("Java: " + javaVend + " " + javaVers); LOGGER.info("Java: " + javaVend + " " + javaVers);
LOGGER.info("User: " + userName + " " + userHome); LOGGER.info("User: " + userName + " " + userHome);
this.primaryStage = primaryStage; this.primaryStage = primaryStage;
mainWindowController = new MainWindowController(this);
mainWindow(); mainWindow();
initActions(); initActions();
} catch (Exception e) { } catch (Exception e) {
@ -91,28 +92,21 @@ public class Main extends Application {
try { try {
FXMLLoader loader = new FXMLLoader(); FXMLLoader loader = new FXMLLoader();
loader.setLocation(ClassLoader.getSystemResource("fxml/MainWindow.fxml")); loader.setLocation(ClassLoader.getSystemResource("fxml/MainWindow.fxml"));
loader.setController(mainWindowController);
pane = (AnchorPane) loader.load(); pane = (AnchorPane) loader.load();
primaryStage.setMinWidth(265.00);
primaryStage.setMinHeight(425.00);
primaryStage.setTitle("cemu_UI"); primaryStage.setTitle("cemu_UI");
// primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/resources/Homeflix_Icon_64x64.png"))); //adds application icon // primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream(""))); //adds application icon
primaryStage.setOnCloseRequest(event -> System.exit(1));
mainWindowController = loader.getController(); // Link of FXMLController and controller class
mainWindowController.setMain(this); // call setMain
cloudController = new CloudController(mainWindowController); // call cloudController constructor
// get OS and the specific paths // generate window
if (osName.equals("Linux")) { scene = new Scene(pane); // create new scene, append pane to scene
directory = new File(dirLinux); scene.getStylesheets().add(Main.class.getResource("/css/MainWindows.css").toExternalForm());
configFile = new File(dirLinux + "/config.xml"); primaryStage.setScene(scene); // append scene to stage
gamesDBFile = new File(dirLinux + "/games.db"); primaryStage.show(); // show stage
reference_gamesFile = new File(dirLinux + "/reference_games.db");
pictureCache= new File(dirLinux+"/picture_cache"); cloudController = new CloudController(mainWindowController); // call cloudController constructor
} else {
directory = new File(dirWin);
configFile = new File(dirWin + "/config.xml");
gamesDBFile = new File(dirWin + "/games.db");
reference_gamesFile = new File(dirWin + "/reference_games.db");
pictureCache= new File(dirWin+"/picture_cache");
}
// startup checks // startup checks
// check if client_secret.json is present // check if client_secret.json is present
@ -165,14 +159,6 @@ public class Main extends Application {
} }
} }
// generate window
scene = new Scene(pane); // create new scene, append pane to scene
scene.getStylesheets().add(Main.class.getResource("/css/MainWindows.css").toExternalForm());
primaryStage.setMinWidth(265.00);
primaryStage.setMinHeight(425.00);
primaryStage.setScene(scene); // append scene to stage
primaryStage.show(); // show stage
// init here as it loads the games to the mwc and the gui, therefore the window must exist // init here as it loads the games to the mwc and the gui, therefore the window must exist
mainWindowController.init(); mainWindowController.init();
mainWindowController.getDbController().init(); mainWindowController.getDbController().init();
@ -183,9 +169,31 @@ public class Main extends Application {
cloudController.sync(mainWindowController.getCloudService(), mainWindowController.getCemuPath(), directory.getPath()); cloudController.sync(mainWindowController.getCloudService(), mainWindowController.getCemuPath(), directory.getPath());
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
}
public static void main(String[] args) {
if (osName.contains("Windows")) {
dirCemuUI = userHome + "/Documents/cemu_UI";
} else {
dirCemuUI = userHome + "/cemu_UI";
}
directory = new File(dirCemuUI);
configFile = new File(dirCemuUI + "/config.xml");
gamesDBFile = new File(dirCemuUI + "/games.db");
reference_gamesFile = new File(dirCemuUI + "/reference_games.db");
pictureCache= new File(dirCemuUI+"/picture_cache");
// delete old log file and create new
System.setProperty("logFilename", dirCemuUI + "/app.log");
File logFile = new File(dirCemuUI + "/app.log");
logFile.delete();
LOGGER = LogManager.getLogger(Main.class.getName());
launch(args);
} }
private void firstStart() { private void firstStart() {
@ -291,26 +299,6 @@ public class Main extends Application {
primaryStage.heightProperty().addListener(heightListener); primaryStage.heightProperty().addListener(heightListener);
primaryStage.maximizedProperty().addListener(maximizeListener); primaryStage.maximizedProperty().addListener(maximizeListener);
} }
public static void main(String[] args) {
// delete old log file and create new
if (osName.equals("Linux")) {
System.setProperty("logFilename", userHome + "/cemu_UI/app.log");
File logFile = new File(userHome + "/cemu_UI/app.log");
logFile.delete();
} else {
System.setProperty("logFilename", userHome + "/Documents/cemu_UI/app.log");
File logFile = new File(userHome + "/Documents/cemu_UI/app.log");
logFile.delete();
}
LOGGER = LogManager.getLogger(Main.class.getName());
launch(args);
}
@Override
public void stop() {
System.exit(0);
}
public Stage getPrimaryStage() { public Stage getPrimaryStage() {
return primaryStage; return primaryStage;

View File

@ -111,37 +111,26 @@ public class MainWindowController {
@FXML @FXML
private JFXButton aboutBtn; private JFXButton aboutBtn;
@FXML @FXML
private JFXButton settingsBtn; private JFXButton settingsBtn;
@FXML @FXML
private JFXButton addBtn; private JFXButton addBtn;
@FXML @FXML
private JFXButton reloadRomsBtn; private JFXButton reloadRomsBtn;
@FXML @FXML
private JFXButton smmdbBtn; private JFXButton smmdbBtn;
@FXML @FXML
private JFXButton cemuTFBtn; private JFXButton cemuTFBtn;
@FXML @FXML
private JFXButton romTFBtn; private JFXButton romTFBtn;
@FXML @FXML
private JFXButton updateBtn; private JFXButton updateBtn;
@FXML @FXML
private JFXButton smmdbDownloadBtn; private JFXButton smmdbDownloadBtn;
@FXML @FXML
private JFXButton playBtn; private JFXButton playBtn;
@FXML @FXML
private JFXButton lastTimePlayedBtn; private JFXButton lastTimePlayedBtn;
@FXML @FXML
JFXButton totalPlaytimeBtn; JFXButton totalPlaytimeBtn;
@ -150,58 +139,46 @@ public class MainWindowController {
@FXML @FXML
private JFXTextField cemuTextField; private JFXTextField cemuTextField;
@FXML @FXML
private JFXTextField romTextField; private JFXTextField romTextField;
@FXML @FXML
private JFXTextField courseSearchTextFiled; private JFXTextField courseSearchTextFiled;
@FXML @FXML
private JFXTextField executeCommandTextFiled; private JFXTextField executeCommandTextFiled;
@FXML @FXML
private TextFlow smmdbTextFlow; private TextFlow smmdbTextFlow;
@FXML @FXML
private JFXColorPicker colorPicker; private JFXColorPicker colorPicker;
@FXML @FXML
private JFXToggleButton cloudSyncToggleBtn; private JFXToggleButton cloudSyncToggleBtn;
@FXML @FXML
private JFXToggleButton autoUpdateToggleBtn; private JFXToggleButton autoUpdateToggleBtn;
@FXML @FXML
private JFXToggleButton fullscreenToggleBtn; private JFXToggleButton fullscreenToggleBtn;
@FXML @FXML
private ChoiceBox<String> languageChoisBox; private ChoiceBox<String> languageChoisBox;
@FXML @FXML
private ChoiceBox<String> branchChoisBox; private ChoiceBox<String> branchChoisBox;
@FXML @FXML
private AnchorPane mainAnchorPane; private AnchorPane mainAnchorPane;
@FXML @FXML
private AnchorPane gamesAnchorPane; private AnchorPane gamesAnchorPane;
@FXML @FXML
private AnchorPane settingsAnchorPane; private AnchorPane settingsAnchorPane;
@FXML @FXML
private AnchorPane smmdbAnchorPane; private AnchorPane smmdbAnchorPane;
@FXML @FXML
private ScrollPane mainScrollPane; private ScrollPane mainScrollPane;
@FXML @FXML
private ScrollPane settingsScrollPane; private ScrollPane settingsScrollPane;
@FXML @FXML
private ScrollPane smmdbScrollPane; private ScrollPane smmdbScrollPane;
@FXML @FXML
private ScrollPane smmdbImageViewScrollPane; private ScrollPane smmdbImageViewScrollPane;
@ -210,7 +187,6 @@ public class MainWindowController {
@FXML @FXML
private HBox topHBox; private HBox topHBox;
@FXML @FXML
private HBox bottomHBox; private HBox bottomHBox;
@ -219,31 +195,22 @@ public class MainWindowController {
@FXML @FXML
private Label helpLbl; private Label helpLbl;
@FXML @FXML
private Label cemu_UISettingsLbl; private Label cemu_UISettingsLbl;
@FXML @FXML
private Label cemuDirectoryLbl; private Label cemuDirectoryLbl;
@FXML @FXML
private Label romDirectoryLbl; private Label romDirectoryLbl;
@FXML @FXML
private Label mainColorLbl; private Label mainColorLbl;
@FXML @FXML
private Label languageLbl; private Label languageLbl;
@FXML @FXML
private Label updateLbl; private Label updateLbl;
@FXML @FXML
private Label branchLbl; private Label branchLbl;
@FXML @FXML
private Label cemuSettingsLbl; private Label cemuSettingsLbl;
@FXML @FXML
private Label licensesLbl; private Label licensesLbl;
@ -251,17 +218,14 @@ public class MainWindowController {
private JFXTreeTableView<CourseTableDataType> courseTreeTable = new JFXTreeTableView<CourseTableDataType>(); private JFXTreeTableView<CourseTableDataType> courseTreeTable = new JFXTreeTableView<CourseTableDataType>();
@FXML @FXML
TreeItem<CourseTableDataType> root = new TreeItem<>(new CourseTableDataType("", "", 0, 0)); private TreeItem<CourseTableDataType> root = new TreeItem<>(new CourseTableDataType("", "", 0, 0));
@FXML @FXML
private JFXTreeTableColumn<CourseTableDataType, String> titleColumn = new JFXTreeTableColumn<>("title"); private JFXTreeTableColumn<CourseTableDataType, String> titleColumn = new JFXTreeTableColumn<>("title");
@FXML @FXML
private JFXTreeTableColumn<CourseTableDataType, String> idColumn = new JFXTreeTableColumn<>("id"); private JFXTreeTableColumn<CourseTableDataType, String> idColumn = new JFXTreeTableColumn<>("id");
@FXML @FXML
private JFXTreeTableColumn<CourseTableDataType, Integer> starsColumn = new JFXTreeTableColumn<>("stars"); private JFXTreeTableColumn<CourseTableDataType, Integer> starsColumn = new JFXTreeTableColumn<>("stars");
@FXML @FXML
private JFXTreeTableColumn<CourseTableDataType, Integer> timeColumn = new JFXTreeTableColumn<>("time"); private JFXTreeTableColumn<CourseTableDataType, Integer> timeColumn = new JFXTreeTableColumn<>("time");
@ -294,7 +258,7 @@ public class MainWindowController {
private String selectedGameTitle; private String selectedGameTitle;
private String id; private String id;
private String version = "0.3.0"; private String version = "0.3.0";
private String buildNumber = "077"; private String buildNumber = "079";
private String versionName = "Purple Comet"; private String versionName = "Purple Comet";
private int xPos = -200; private int xPos = -200;
private int yPos = 17; private int yPos = 17;
@ -372,8 +336,8 @@ public class MainWindowController {
private String smmdbDownloadBtnLoading; private String smmdbDownloadBtnLoading;
private String smmdbDownloadBtnDownload; private String smmdbDownloadBtnDownload;
public void setMain(Main m) { public MainWindowController(Main main) {
this.main = m; this.main = main;
dbController = new DBController(main, this); dbController = new DBController(main, this);
smmdbAPIController = new SmmdbAPIController(); smmdbAPIController = new SmmdbAPIController();
} }
@ -382,7 +346,7 @@ public class MainWindowController {
* initialize the MainWindowController * initialize the MainWindowController
* loadSettings, checkAutoUpdate, initUI and initActions * loadSettings, checkAutoUpdate, initUI and initActions
*/ */
void init() { public void init() {
loadSettings(); loadSettings();
checkAutoUpdate(); checkAutoUpdate();
initUI(); initUI();
@ -837,7 +801,7 @@ public class MainWindowController {
} }
@FXML @FXML
void detailsSlideoutBtnAction() { private void detailsSlideoutBtnAction() {
playBtnSlideOut(); playBtnSlideOut();
} }
@ -851,7 +815,7 @@ public class MainWindowController {
} }
@FXML @FXML
void settingsBtnAction() { private void settingsBtnAction() {
if (smmdbTrue) { if (smmdbTrue) {
smmdbAnchorPane.setVisible(false); smmdbAnchorPane.setVisible(false);
smmdbTrue = false; smmdbTrue = false;
@ -867,12 +831,12 @@ public class MainWindowController {
} }
@FXML @FXML
void reloadRomsBtnAction() throws IOException { private void reloadRomsBtnAction() throws IOException {
reloadRoms(); reloadRoms();
} }
@FXML @FXML
void smmdbBtnAction() { private void smmdbBtnAction() {
// show smmdbAnchorPane // show smmdbAnchorPane
if (smmdbTrue) { if (smmdbTrue) {
smmdbAnchorPane.setVisible(false); smmdbAnchorPane.setVisible(false);
@ -911,7 +875,7 @@ public class MainWindowController {
} }
@FXML @FXML
void playBtnAction() throws InterruptedException, IOException { private void playBtnAction() throws InterruptedException, IOException {
dbController.setLastPlayed(selectedGameTitleID); dbController.setLastPlayed(selectedGameTitleID);
playGame = new playGame(this, dbController); playGame = new playGame(this, dbController);
@ -919,17 +883,17 @@ public class MainWindowController {
} }
@FXML @FXML
void totalPlaytimeBtnAction() { private void totalPlaytimeBtnAction() {
} }
@FXML @FXML
void lastTimePlayedBtnAction() { private void lastTimePlayedBtnAction() {
} }
@FXML @FXML
void cemuTFBtnAction() { private void cemuTFBtnAction() {
File cemuDirectory = directoryChooser.showDialog(main.getPrimaryStage()); File cemuDirectory = directoryChooser.showDialog(main.getPrimaryStage());
if (cemuDirectory != null) { if (cemuDirectory != null) {
cemuTextField.setText(cemuDirectory.getAbsolutePath()); cemuTextField.setText(cemuDirectory.getAbsolutePath());
@ -937,7 +901,7 @@ public class MainWindowController {
} }
@FXML @FXML
void romTFBtnAction() { private void romTFBtnAction() {
File romDirectory = directoryChooser.showDialog(main.getPrimaryStage()); File romDirectory = directoryChooser.showDialog(main.getPrimaryStage());
if (romDirectory != null) { if (romDirectory != null) {
romTextField.setText(romDirectory.getAbsolutePath()); romTextField.setText(romDirectory.getAbsolutePath());
@ -945,7 +909,7 @@ public class MainWindowController {
} }
@FXML @FXML
void updateBtnAction() { private void updateBtnAction() {
updateController = new UpdateController(this, buildNumber, useBeta); updateController = new UpdateController(this, buildNumber, useBeta);
Thread updateThread = new Thread(updateController); Thread updateThread = new Thread(updateController);
updateThread.setName("Updater"); updateThread.setName("Updater");
@ -953,7 +917,7 @@ public class MainWindowController {
} }
@FXML @FXML
void autoUpdateToggleBtnAction() { private void autoUpdateToggleBtnAction() {
if (isAutoUpdate()) { if (isAutoUpdate()) {
setAutoUpdate(false); setAutoUpdate(false);
} else { } else {
@ -963,12 +927,12 @@ public class MainWindowController {
} }
@FXML @FXML
void courseSearchTextFiledAction() { private void courseSearchTextFiledAction() {
// not in use // not in use
} }
@FXML @FXML
void smmdbDownloadBtnAction() { private void smmdbDownloadBtnAction() {
String downloadUrl = "http://smmdb.ddns.net/api/downloadcourse?id=" + id + "&type=zip"; String downloadUrl = "http://smmdb.ddns.net/api/downloadcourse?id=" + id + "&type=zip";
String downloadFileURL = getCemuPath() + "/" + id + ".zip"; // getCemuPath() + "/" + smmID + "/" + id + ".rar" String downloadFileURL = getCemuPath() + "/" + id + ".zip"; // getCemuPath() + "/" + smmID + "/" + id + ".rar"
String outputFile = getCemuPath() + "/"; String outputFile = getCemuPath() + "/";
@ -1036,7 +1000,7 @@ public class MainWindowController {
} }
@FXML @FXML
void fullscreenToggleBtnAction() { private void fullscreenToggleBtnAction() {
if (fullscreen) { if (fullscreen) {
fullscreen = false; fullscreen = false;
} else { } else {
@ -1046,7 +1010,7 @@ public class MainWindowController {
} }
@FXML @FXML
void cloudSyncToggleBtnAction() { private void cloudSyncToggleBtnAction() {
if(cloudSync) { if(cloudSync) {
cloudSync = false; cloudSync = false;
} else { } else {
@ -1096,13 +1060,13 @@ public class MainWindowController {
} }
@FXML @FXML
void colorPickerAction() { private void colorPickerAction() {
editColor(colorPicker.getValue().toString()); editColor(colorPicker.getValue().toString());
applyColor(); applyColor();
} }
@FXML @FXML
void addBtnAction() { private void addBtnAction() {
String headingText = addGameBtnHeadingText; String headingText = addGameBtnHeadingText;
String bodyText = addGameBtnBodyText; String bodyText = addGameBtnBodyText;
JFXEditGameDialog addGameDialog = new JFXEditGameDialog(headingText, bodyText, dialogBtnStyle, 450, 300, 0, JFXEditGameDialog addGameDialog = new JFXEditGameDialog(headingText, bodyText, dialogBtnStyle, 450, 300, 0,

View File

@ -18,7 +18,7 @@
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import javafx.scene.text.TextFlow?> <?import javafx.scene.text.TextFlow?>
<AnchorPane fx:id="mainAnchorPane" minHeight="405.0" minWidth="260.0" prefHeight="600.0" prefWidth="904.0" xmlns="http://javafx.com/javafx/9" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.cemu_UI.application.MainWindowController"> <AnchorPane fx:id="mainAnchorPane" minHeight="405.0" minWidth="260.0" prefHeight="600.0" prefWidth="904.0" xmlns="http://javafx.com/javafx/9" xmlns:fx="http://javafx.com/fxml/1">
<children> <children>
<ScrollPane fx:id="mainScrollPane" fitToWidth="true" layoutY="38.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="38.0"> <ScrollPane fx:id="mainScrollPane" fitToWidth="true" layoutY="38.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="38.0">
<content> <content>