code clean up

This commit is contained in:
Jannik 2017-11-24 21:36:03 +01:00
parent 922b1443e1
commit fe6ddedab9
1 changed files with 416 additions and 453 deletions

View File

@ -40,7 +40,6 @@ import java.sql.SQLException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Optional;
import java.util.Properties;
import javax.imageio.ImageIO;
@ -80,9 +79,6 @@ import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Label;
@ -410,14 +406,14 @@ public class MainWindowController {
@Override
public void handle(ActionEvent event) {
try {
LOGGER.info("edit "+selectedGameTitleID);
LOGGER.info("edit " + selectedGameTitleID);
String[] gameInfo = dbController.getGameInfo(selectedGameTitleID);
//new edit dialog
// new edit dialog
String headingText = "edit a game";
String bodyText = "You can edit the tile and rom/cover path.";
JFXEditGameDialog editGameDialog = new JFXEditGameDialog(headingText, bodyText, dialogBtnStyle, 350, 300,
1, MWC, main.primaryStage, main.pane);
JFXEditGameDialog editGameDialog = new JFXEditGameDialog(headingText, bodyText, dialogBtnStyle, 450,
300, 1, MWC, main.primaryStage, main.pane);
editGameDialog.setTitle(gameInfo[0]);
editGameDialog.setCoverPath(gameInfo[1]);
editGameDialog.setRomPath(gameInfo[2]);
@ -426,63 +422,41 @@ public class MainWindowController {
} catch (Exception e) {
LOGGER.warn("trying to edit " + selectedGameTitleID + ",which is not a valid type!", e);
}
// if (selectedGameTitleID == null) {
// LOGGER.warn("trying to edit null! null is not valid!");
//
// String headingText = "edit game";
// String bodyText = "please select a game, \""+selectedGameTitleID+"\" is not a valid type!";
// JFXInfoDialog aboutDialog = new JFXInfoDialog(headingText, bodyText, dialogBtnStyle, 350, 170, main.pane);
// aboutDialog.show();
// } else {
// String[] gameInfo = dbController.getGameInfo(selectedGameTitleID);
//
// //new edit dialog
// String headingText = "edit a game";
// String bodyText = "You can edit the tile and rom/cover path.";
// JFXEditGameDialog editGameDialog = new JFXEditGameDialog(headingText, bodyText, dialogBtnStyle, 350, 300,
// 1, MWC, main.primaryStage, main.pane);
// editGameDialog.setTitle(gameInfo[0]);
// editGameDialog.setCoverPath(gameInfo[1]);
// editGameDialog.setRomPath(gameInfo[2]);
// editGameDialog.setTitleID(gameInfo[3]);
// editGameDialog.show();
// }
}
});
remove.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
LOGGER.info("remove "+selectedGameTitleID);
if(selectedGameTitleID == null){
LOGGER.warn("trying to remove null! null is not valid!");
String headingText = "remove game";
String bodyText = "please select a game, \""+selectedGameTitleID+"\" is not a valid type!";
JFXInfoDialog aboutDialog = new JFXInfoDialog(headingText, bodyText, dialogBtnStyle, 350, 170, main.pane);
aboutDialog.show();
}
else{
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("remove");
alert.setHeaderText("cemu_UI");
alert.setContentText("Are you sure you want to delete "+selectedGameTitle+" ?");
alert.initOwner(main.primaryStage);
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK){
try {
// remove game from database
games.remove(selectedUIDataIndex);
dbController.removeRom(selectedGameTitleID);
// refresh all games at gamesAnchorPane (UI)
refreshUIData();
LOGGER.info("remove " + selectedGameTitle + "(" + selectedGameTitleID + ")");
String headingText = "remove \"" + selectedGameTitle + "\"";
String bodyText = "Are you sure you want to delete " + selectedGameTitle + " ?";
EventHandler<ActionEvent> okayAction = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
games.remove(selectedUIDataIndex); // remove game form games-list
dbController.removeRom(selectedGameTitleID); // remove game from database
refreshUIData(); // refresh all games at gamesAnchorPane (UI)
} catch (Exception e) {
LOGGER.error("error!",e);
LOGGER.error("error while removing ROM from database!", e);
}
}
};
EventHandler<ActionEvent> cancelAction = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// do nothing
}
};
JFXOkayCancelDialog removeGameDialog = new JFXOkayCancelDialog(headingText, bodyText,
dialogBtnStyle, 350, 170, okayAction, cancelAction, main.pane);
removeGameDialog.show();
} catch (Exception e) {
LOGGER.error("error while removing " + selectedGameTitle + "(" + selectedGameTitleID + ")", e);
}
}
});
@ -490,31 +464,24 @@ public class MainWindowController {
addUpdate.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
LOGGER.info("update: "+selectedGameTitleID);
if (selectedGameTitleID == null) {
LOGGER.warn("trying to update null! null is not valid!");
String headingText = "update game";
String bodyText = "please select a game,\n"
+ "\""+selectedGameTitleID+"\" is not a valid type!";
JFXInfoDialog updateGameErrorDialog = new JFXInfoDialog(headingText, bodyText, dialogBtnStyle, 350, 170, main.pane);
updateGameErrorDialog.show();
} else {
try {
LOGGER.info("update: " + selectedGameTitleID);
String headingText = "update \"" + selectedGameTitle + "\"";
String bodyText = "pleas select the update root directory";
EventHandler<ActionEvent> okayAction = new EventHandler<ActionEvent>(){
EventHandler<ActionEvent> okayAction = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event){
public void handle(ActionEvent event) {
DirectoryChooser directoryChooser = new DirectoryChooser();
File selectedDirecroty = directoryChooser.showDialog(main.primaryStage);
String updatePath = selectedDirecroty.getAbsolutePath();
String[] parts = selectedGameTitleID.split("-"); // split string into 2 parts at "-"
File srcDir = new File(updatePath);
File destDir;
if (System.getProperty("os.name").equals("Linux")) {
destDir = new File(cemuPath+"/mlc01/usr/title/"+parts[0]+"/"+parts[1]);
destDir = new File(cemuPath + "/mlc01/usr/title/" + parts[0] + "/" + parts[1]);
} else {
destDir = new File(cemuPath+"\\mlc01\\usr\\title\\"+parts[0]+"\\"+parts[1]);
destDir = new File(cemuPath + "\\mlc01\\usr\\title\\" + parts[0] + "\\" + parts[1]);
}
// if directory doesn't exist create it
@ -539,13 +506,15 @@ public class MainWindowController {
EventHandler<ActionEvent> cancelAction = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// do nothing
}
};
JFXOkayCancelDialog updateGameDialog = new JFXOkayCancelDialog(headingText, bodyText,
dialogBtnStyle, 350, 170, okayAction, cancelAction, main.pane);
updateGameDialog.show();
} catch (Exception e) {
LOGGER.warn("trying to update " + selectedGameTitleID + ",which is not a valid type!", e);
}
}
});
@ -553,21 +522,13 @@ public class MainWindowController {
addDLC.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
LOGGER.info("add DLC: "+selectedGameTitleID);
if (selectedGameTitleID == null) {
LOGGER.warn("trying to add a dlc to null! null is not valid!");
String headingText = "add DLC";
String bodyText = "please select a game,\n"
+ "\"" + selectedGameTitleID + "\" is not a valid type!";
JFXInfoDialog addDLCErrorDialog = new JFXInfoDialog(headingText, bodyText, dialogBtnStyle, 350, 170, main.pane);
addDLCErrorDialog.show();
} else {
try {
LOGGER.info("add DLC: " + selectedGameTitleID);
String headingText = "add a DLC to \"" + selectedGameTitle + "\"";
String bodyText = "pleas select the DLC root directory";
EventHandler<ActionEvent> okayAction = new EventHandler<ActionEvent>(){
EventHandler<ActionEvent> okayAction = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event){
public void handle(ActionEvent event) {
DirectoryChooser directoryChooser = new DirectoryChooser();
File selectedDirecroty = directoryChooser.showDialog(main.primaryStage);
String dlcPath = selectedDirecroty.getAbsolutePath();
@ -575,9 +536,10 @@ public class MainWindowController {
File srcDir = new File(dlcPath);
File destDir;
if (System.getProperty("os.name").equals("Linux")) {
destDir = new File(cemuPath+"/mlc01/usr/title/"+parts[0]+"/"+parts[1]+"/aoc");
destDir = new File(cemuPath + "/mlc01/usr/title/" + parts[0] + "/" + parts[1] + "/aoc");
} else {
destDir = new File(cemuPath+"\\mlc01\\usr\\title\\"+parts[0]+"\\"+parts[1]+"\\aoc");
destDir = new File(
cemuPath + "\\mlc01\\usr\\title\\" + parts[0] + "\\" + parts[1] + "\\aoc");
}
// if directory doesn't exist create it
@ -602,13 +564,15 @@ public class MainWindowController {
EventHandler<ActionEvent> cancelAction = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// do nothing
}
};
JFXOkayCancelDialog addDLCDialog = new JFXOkayCancelDialog(headingText, bodyText,
dialogBtnStyle, 350, 170, okayAction, cancelAction, main.pane);
JFXOkayCancelDialog addDLCDialog = new JFXOkayCancelDialog(headingText, bodyText, dialogBtnStyle,
350, 170, okayAction, cancelAction, main.pane);
addDLCDialog.show();
} catch (Exception e) {
LOGGER.warn("trying to add a dlc to " + selectedGameTitleID + ",which is not a valid type!", e);
}
}
});
@ -634,10 +598,11 @@ public class MainWindowController {
// Change-listener for TreeTable
courseTreeTable.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Object>() {
@Override
public void changed(ObservableValue<?> observable, Object oldVal, Object newVal){
selected = courseTreeTable.getSelectionModel().getSelectedIndex(); //get selected item
public void changed(ObservableValue<?> observable, Object oldVal, Object newVal) {
selected = courseTreeTable.getSelectionModel().getSelectedIndex(); // get selected item
// FIXME if a item is selected and you change the sorting,you can't select a new item
// FIXME if a item is selected and you change the sorting,you can't select a new
// item
id = idColumn.getCellData(selected); // get name of selected item
for (int i = 0; i < courses.size(); i++) {
@ -659,7 +624,7 @@ public class MainWindowController {
helpLbl.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent) {
if(mouseEvent.getButton().equals(MouseButton.PRIMARY)){
if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
try {
Desktop.getDesktop().browse(new URI("https://github.com/Seil0/cemu_UI/issues/3"));
} catch (IOException | URISyntaxException e) {
@ -704,12 +669,12 @@ public class MainWindowController {
}
@FXML
void detailsSlideoutBtnAction(ActionEvent event){
void detailsSlideoutBtnAction(ActionEvent event) {
playBtnSlideOut();
}
@FXML
void aboutBtnAction(){
void aboutBtnAction() {
String headingText = "cemu_UI";
String bodyText = "cemu_UI by @Seil0 \nVersion: " + version + " (" + buildNumber + ") \"" + versionName + "\" \n"
+ "This Application is made with free Software\n"
@ -736,7 +701,7 @@ public class MainWindowController {
}
@FXML
void reloadRomsBtnAction() throws IOException{
void reloadRomsBtnAction() throws IOException {
reloadRomsBtn.setText("reloading...");
dbController.loadRomDirectory(getRomPath()); // TODO own thread
Runtime.getRuntime().exec("java -jar cemu_UI.jar"); // start again (preventing Bugs)
@ -758,9 +723,9 @@ public class MainWindowController {
courses.addAll(smmdbAPIController.startQuery());
// add query response to courseTreeTable
for(int i = 0; i < courses.size(); i++){
CourseTableDataType helpCourse = new CourseTableDataType(courses.get(i).getTitle(), courses.get(i).getId(),
courses.get(i).getTime(), courses.get(i).getStars());
for (int i = 0; i < courses.size(); i++) {
CourseTableDataType helpCourse = new CourseTableDataType(courses.get(i).getTitle(),
courses.get(i).getId(), courses.get(i).getTime(), courses.get(i).getStars());
root.getChildren().add(new TreeItem<CourseTableDataType>(helpCourse)); // add data to root-node
}
@ -768,35 +733,35 @@ public class MainWindowController {
}
@FXML
void playBtnAction(ActionEvent event) throws InterruptedException, IOException{
void playBtnAction(ActionEvent event) throws InterruptedException, IOException {
dbController.setLastPlayed(selectedGameTitleID);
playGame = new playGame(this,dbController);
playGame = new playGame(this, dbController);
playGame.start();
}
@FXML
void totalPlaytimeBtnAction(ActionEvent event){
void totalPlaytimeBtnAction(ActionEvent event) {
}
@FXML
void lastTimePlayedBtnAction(ActionEvent event){
void lastTimePlayedBtnAction(ActionEvent event) {
}
@FXML
void cemuTFBtnAction(ActionEvent event) {
File cemuDirectory = directoryChooser.showDialog(main.primaryStage);
if(cemuDirectory == null){
if (cemuDirectory == null) {
LOGGER.info("No Directory selected");
}else{
} else {
setCemuPath(cemuDirectory.getAbsolutePath());
saveSettings();
cemuTextField.setText(getCemuPath());
try {
Runtime.getRuntime().exec("java -jar cemu_UI.jar"); // start again
System.exit(0); //finishes itself
System.exit(0); // finishes itself
} catch (IOException e) {
LOGGER.error("an error occurred", e);
}
@ -806,9 +771,9 @@ public class MainWindowController {
@FXML
void romTFBtnAction(ActionEvent event) {
File romDirectory = directoryChooser.showDialog(main.primaryStage);
if(romDirectory == null){
if (romDirectory == null) {
LOGGER.info("No Directory selected");
}else{
} else {
setRomPath(romDirectory.getAbsolutePath());
saveSettings();
cemuTextField.setText(getCemuPath());
@ -831,15 +796,16 @@ public class MainWindowController {
@FXML
void autoUpdateToggleBtnAction(ActionEvent event) {
if(isAutoUpdate()){
if (isAutoUpdate()) {
setAutoUpdate(false);
}else{
} else {
setAutoUpdate(true);
}
saveSettings(); }
saveSettings();
}
@FXML
void smmdbDownloadBtnAction(ActionEvent event){
void smmdbDownloadBtnAction(ActionEvent event) {
String downloadUrl = "http://smmdb.ddns.net/api/downloadcourse?id=" + id + "&type=zip";
String downloadFileURL = getCemuPath() + "/" + id + ".zip"; // getCemuPath() + "/" + smmID + "/" + id + ".rar"
String outputFile = getCemuPath() + "/";
@ -904,29 +870,29 @@ public class MainWindowController {
}
@FXML
void cemuTextFieldAction(ActionEvent event){
void cemuTextFieldAction(ActionEvent event) {
setCemuPath(cemuTextField.getText());
saveSettings();
}
@FXML
void romTextFieldAction(ActionEvent event){
void romTextFieldAction(ActionEvent event) {
setRomPath(romTextField.getText());
saveSettings();
}
@FXML
void fullscreenToggleBtnAction(ActionEvent event){
if(fullscreen){
void fullscreenToggleBtnAction(ActionEvent event) {
if (fullscreen) {
fullscreen = false;
}else{
} else {
fullscreen = true;
}
saveSettings();
}
@FXML
void cloudSyncToggleBtnAction(ActionEvent event){
void cloudSyncToggleBtnAction(ActionEvent event) {
if(cloudSync) {
cloudSync = false;
} else {
@ -972,17 +938,17 @@ public class MainWindowController {
}
@FXML
void colorPickerAction(ActionEvent event){
void colorPickerAction(ActionEvent event) {
editColor(colorPicker.getValue().toString());
applyColor();
}
@FXML
void addBtnAction(ActionEvent event){
void addBtnAction(ActionEvent event) {
String headingText = "add a new game to cemu_UI";
String bodyText = "";
JFXEditGameDialog addGameDialog = new JFXEditGameDialog(headingText, bodyText, dialogBtnStyle, 450, 300,
0, this, main.primaryStage, main.pane);
JFXEditGameDialog addGameDialog = new JFXEditGameDialog(headingText, bodyText, dialogBtnStyle, 450, 300, 0,
this, main.primaryStage, main.pane);
addGameDialog.show();
}
@ -1156,9 +1122,9 @@ public class MainWindowController {
games.add(uiROMElement);
}
//add all games saved in games(ArrayList) to gamesAnchorPane
// add all games saved in games(ArrayList) to gamesAnchorPane
void addUIData() {
for(int i=0; i<games.size(); i++){
for (int i = 0; i < games.size(); i++) {
gamesAnchorPane.getChildren().add(games.get(i).getVBox());
}
}
@ -1190,14 +1156,14 @@ public class MainWindowController {
} else {
width = mainAnchorPane.getWidth();
}
playBtn.setLayoutX((width/2)-50);
totalPlaytimeBtn.setLayoutX((width/2)-50-20.5-100);
lastTimePlayedBtn.setLayoutX((width/2)+50+20.5);
playBtn.setLayoutX((width / 2) - 50);
totalPlaytimeBtn.setLayoutX((width / 2) - 50 - 20.5 - 100);
lastTimePlayedBtn.setLayoutX((width / 2) + 50 + 20.5);
}
void checkAutoUpdate() {
if(isAutoUpdate()){
if (isAutoUpdate()) {
try {
LOGGER.info("AutoUpdate: looking for updates on startup ...");
updateController = new UpdateController(this, buildNumber, useBeta);
@ -1319,14 +1285,14 @@ public class MainWindowController {
courseText.add(4, new Text(difficulty + "\n"));
courseText.add(5, new Text(autoscroll + "\n"));
courseText.add(6, new Text(course.getTime() + "\n"));
courseText.add(7, new Text(new java.util.Date((long)course.getLastmodified()*1000) + "\n"));
courseText.add(8, new Text(new java.util.Date((long)course.getUploaded()*1000) + "\n"));
courseText.add(7, new Text(new java.util.Date((long) course.getLastmodified() * 1000) + "\n"));
courseText.add(8, new Text(new java.util.Date((long) course.getUploaded() * 1000) + "\n"));
courseText.add(9, new Text(course.getNintendoid() + "\n"));
for(int i=0; i<nameText.size(); i++){
nameText.get(i).setFont(Font.font ("System", FontWeight.BOLD, 14));
courseText.get(i).setFont(Font.font ("System", 14));
smmdbTextFlow.getChildren().addAll(nameText.get(i),courseText.get(i));
for (int i = 0; i < nameText.size(); i++) {
nameText.get(i).setFont(Font.font("System", FontWeight.BOLD, 14));
courseText.get(i).setFont(Font.font("System", 14));
smmdbTextFlow.getChildren().addAll(nameText.get(i), courseText.get(i));
}
}
@ -1357,11 +1323,8 @@ public class MainWindowController {
xPosHelper++;
}
// TODO needs testing
System.out.println("Breit: " + main.pane.getWidth());
System.out.println("Breit2: " + mainAnchorPane.getWidth());
System.out.println("Breite3: " + main.scene.getWidth());
System.out.println("Breite4: " + main.primaryStage.getWidth());
// System.out.println("Breit: " + main.pane.getWidth());
// System.out.println("Breit2: " + mainAnchorPane.getWidth());
// System.out.println("xPosHelper: " + xPosHelper);
// System.out.println("yPos: " + yPos);
// System.out.println("xPos: " + xPos);
@ -1379,7 +1342,7 @@ public class MainWindowController {
cemuTextField.setFocusColor(Color.valueOf(getColor()));
romTextField.setFocusColor(Color.valueOf(getColor()));
if(icolor.compareTo(ccolor) == -1){
if (icolor.compareTo(ccolor) == -1) {
dialogBtnStyle = btnStyleWhite;
aboutBtn.setStyle("-fx-text-fill: WHITE;");
@ -1401,7 +1364,7 @@ public class MainWindowController {
smmdbBtn.setGraphic(smmdb_white);
menuHam.getStyleClass().add("jfx-hamburgerW");
}else{
} else {
dialogBtnStyle = btnStyleBlack;
aboutBtn.setStyle("-fx-text-fill: BLACK;");
@ -1425,7 +1388,7 @@ public class MainWindowController {
menuHam.getStyleClass().add("jfx-hamburgerB");
}
for(int i=0; i<games.size(); i++){
for (int i = 0; i < games.size(); i++) {
games.get(i).getButton().setRipplerFill(Paint.valueOf(getColor()));
}
}