performance improvements

* call refreshUIData() only if there is enough space for another column
This commit is contained in:
Seil0 2017-09-15 19:23:44 +02:00
parent 3853f70895
commit 109bcf6e03
14 changed files with 74 additions and 45 deletions

Binary file not shown.

View File

@ -16,7 +16,7 @@
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.TextFlow?>
<AnchorPane fx:id="mainAnchorPane" prefHeight="600.0" prefWidth="892.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainWindowController">
<AnchorPane fx:id="mainAnchorPane" prefHeight="600.0" prefWidth="904.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainWindowController">
<children>
<ScrollPane fx:id="scrollPaneMain" fitToWidth="true" layoutY="38.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="38.0">
<content>
@ -61,7 +61,7 @@
</children>
</VBox>
<!-- space between settings sections 35px, between sections elements (label + element) 20px, between label and element 3px(or more) -->
<AnchorPane fx:id="settingsAnchorPane" layoutX="38.0" layoutY="27.0" prefHeight="573.0" style="-fx-background-color: white;" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="175.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="38.0">
<AnchorPane fx:id="settingsAnchorPane" layoutX="38.0" layoutY="27.0" style="-fx-background-color: white;" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="175.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="38.0">
<children>
<Label layoutX="22.0" layoutY="59.0" text="Cemu Directory" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="59.0" />
<JFXTextField fx:id="cemuTextField" layoutX="18.0" layoutY="83.0" maxWidth="305.0" minWidth="305.0" onAction="#cemuTextFieldAction" prefHeight="32.0" prefWidth="305.0" promptText="cemu directory" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="79.0" />

View File

@ -57,7 +57,7 @@ public class Main extends Application {
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
cloudController = new CloudController(this);
initActions();
initActions(); //TODO this should be called after mainWindow(), but if we do so mainAnchorPane.getWidth() is 0
mainWindow();
}
@ -70,7 +70,7 @@ public class Main extends Application {
// primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/resources/Homeflix_Icon_64x64.png"))); //adds application icon
mainWindowController = loader.getController(); //Link of FXMLController and controller class
mainWindowController.setMain(this); //call setMain
mainWindowController.setMain(this); //call setMain
//get os and the right paths
if(System.getProperty("os.name").equals("Linux")){
@ -79,14 +79,12 @@ public class Main extends Application {
gamesDBFile = new File(dirLinux + "/games.db");
localDB = new File(dirLinux+"/localRoms.db");
pictureCache= new File(dirLinux+"/picture_cache");
pane.setPrefWidth(904); //this could be a kde plasma specific issue
}else{
directory = new File(dirWin);
configFile = new File(dirWin + "/config.xml");
gamesDBFile = new File(dirWin + "/games.db");
localDB = new File(dirWin+"/localRoms.db");
pictureCache= new File(dirWin+"/picture_cache");
pane.setPrefWidth(892); //FIXME this is not working under Windows anymore, need to test which size is correct. see issue #main.1
}
//startup checks
@ -190,29 +188,53 @@ public class Main extends Application {
}
private void initActions() {
final ChangeListener<Number> listener = new ChangeListener<Number>() {
final ChangeListener<Number> widthListener = new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, final Number newValue) {
int xPosHelperMax;
//TODO see issue #main.1
if(System.getProperty("os.name").equals("Linux")){
xPosHelperMax = (int) Math.floor((pane.getPrefWidth() - 36) / 217);
} else {
xPosHelperMax = (int) Math.floor((pane.getPrefWidth() - 24) / 217);
}
int xPosHelperMax = (int) Math.floor((mainWindowController.getMainAnchorPane().getWidth() - 36) / 217);
mainWindowController.refreshplayBtnPosition();
//call only if there is enough space for a new row TODO test this!
if (mainWindowController.getxPosHelper() != xPosHelperMax) {
//call only if there is enough space for a new row
if (mainWindowController.getOldXPosHelper() != xPosHelperMax) {
mainWindowController.refreshUIData();
}
// mainWindowController.refreshUIData();
//TODO saveSettings only on left mouseBtn release
mainWindowController.saveSettings();
}
};
final ChangeListener<Number> heightListener = new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, final Number newValue) {
mainWindowController.saveSettings();
}
};
final ChangeListener<Boolean> maximizeListener = new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
primaryStage.setMaximized(false);
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("edit");
alert.setHeaderText("cemu_UI");
alert.setContentText("maximized Window is not supporte!");
alert.initOwner(primaryStage);
alert.showAndWait();
LOGGER.warn("maximized Window is not supported");
}
};
//add listener to primaryStage
primaryStage.widthProperty().addListener(listener);
primaryStage.widthProperty().addListener(widthListener);
primaryStage.heightProperty().addListener(heightListener);
primaryStage.maximizedProperty().addListener(maximizeListener);
}
public static void main(String[] args) {

View File

@ -16,7 +16,7 @@
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.TextFlow?>
<AnchorPane fx:id="mainAnchorPane" prefHeight="600.0" prefWidth="892.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainWindowController">
<AnchorPane fx:id="mainAnchorPane" prefHeight="600.0" prefWidth="904.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainWindowController">
<children>
<ScrollPane fx:id="scrollPaneMain" fitToWidth="true" layoutY="38.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="38.0">
<content>
@ -61,7 +61,7 @@
</children>
</VBox>
<!-- space between settings sections 35px, between sections elements (label + element) 20px, between label and element 3px(or more) -->
<AnchorPane fx:id="settingsAnchorPane" layoutX="38.0" layoutY="27.0" prefHeight="573.0" style="-fx-background-color: white;" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="175.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="38.0">
<AnchorPane fx:id="settingsAnchorPane" layoutX="38.0" layoutY="27.0" style="-fx-background-color: white;" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="175.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="38.0">
<children>
<Label layoutX="22.0" layoutY="59.0" text="Cemu Directory" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="59.0" />
<JFXTextField fx:id="cemuTextField" layoutX="18.0" layoutY="83.0" maxWidth="305.0" minWidth="305.0" onAction="#cemuTextFieldAction" prefHeight="32.0" prefWidth="305.0" promptText="cemu directory" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="79.0" />

View File

@ -226,6 +226,7 @@ public class MainWindowController {
private int xPos = -200;
private int yPos = 17;
private int xPosHelper;
private int oldXPosHelper;
private int selectedUIDataIndex;
private int selected;
private double windowWidth;
@ -271,7 +272,6 @@ public class MainWindowController {
}
void initUI() {
System.out.println(getWindowWidth());
if (getWindowWidth() > 100 && getWindowHeight() > 100) {
mainAnchorPane.setPrefSize(getWindowWidth(), getWindowHeight());
}
@ -344,9 +344,9 @@ public class MainWindowController {
edit.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("edit "+selectedGameTitleID);
LOGGER.info("edit "+selectedGameTitleID);
if(selectedGameTitleID == null){
System.out.println("trying to edit null! null is not valid!");
LOGGER.warn("trying to edit null! null is not valid!");
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("edit");
alert.setHeaderText("cemu_UI");
@ -354,7 +354,7 @@ public class MainWindowController {
alert.initOwner(main.primaryStage);
alert.showAndWait();
}else{
System.out.println("show edit window TODO!"); //TODO show edit window
//TODO show edit window
}
}
});
@ -362,9 +362,9 @@ public class MainWindowController {
remove.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("remove "+selectedGameTitleID);
LOGGER.info("remove "+selectedGameTitleID);
if(selectedGameTitleID == null){
System.out.println("trying to remove null! null is not valid!");
LOGGER.warn("trying to remove null! null is not valid!");
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("remove");
alert.setHeaderText("cemu_UI");
@ -402,9 +402,9 @@ public class MainWindowController {
public void handle(ActionEvent event) {
String titleID = selectedGameTitleID;
String updatePath;
System.out.println("update: "+selectedGameTitleID);
LOGGER.info("update: "+selectedGameTitleID);
if(selectedGameTitleID == null){
LOGGER.error("trying to update null! null is not valid!");
LOGGER.warn("trying to update null! null is not valid!");
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("edit");
alert.setHeaderText("cemu_UI");
@ -461,7 +461,7 @@ public class MainWindowController {
LOGGER.info("add DLC: "+selectedGameTitleID);
if(selectedGameTitleID == null){
System.out.println("trying to add a dlc to null! null is not valid!");
LOGGER.warn("trying to add a dlc to null! null is not valid!");
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("add DLC");
alert.setHeaderText("cemu_UI");
@ -565,6 +565,7 @@ public class MainWindowController {
}
}
});
LOGGER.info("initializing Actions done!");
}
@ -678,8 +679,7 @@ public class MainWindowController {
Runtime.getRuntime().exec("java -jar cemu_UI.jar"); //start again
System.exit(0); //finishes itself
} catch (IOException e) {
System.out.println("es ist ein Fehler aufgetreten");
e.printStackTrace();
LOGGER.error("an error occurred", e);
}
}
}
@ -697,8 +697,7 @@ public class MainWindowController {
Runtime.getRuntime().exec("java -jar cemu_UI.jar"); //start again
System.exit(0); //finishes itself
} catch (IOException e) {
System.out.println("es ist ein Fehler aufgetreten");
e.printStackTrace();
LOGGER.error("an error occurred", e);
}
}
}
@ -1069,9 +1068,9 @@ public class MainWindowController {
}
void refreshplayBtnPosition() {
playBtn.setLayoutX((mainAnchorPane.getWidth()/2)-50);
totalPlaytimeBtn.setLayoutX((mainAnchorPane.getWidth()/2)-50-20.5-100);
lastTimePlayedBtn.setLayoutX((mainAnchorPane.getWidth()/2)+50+20.5);
playBtn.setLayoutX((main.pane.getWidth()/2)-50);
totalPlaytimeBtn.setLayoutX((main.pane.getWidth()/2)-50-20.5-100);
lastTimePlayedBtn.setLayoutX((main.pane.getWidth()/2)+50+20.5);
}
private void addCourseDescription(SmmdbApiDataType course) {
@ -1199,14 +1198,10 @@ public class MainWindowController {
* calculates how many games can be displayed in one row
*/
private void generatePosition() {
int xPosHelperMax;
//TODO see issue #main.1
if(System.getProperty("os.name").equals("Linux")){
xPosHelperMax = (int) Math.floor((mainAnchorPane.getWidth() - 36) / 217);
} else {
xPosHelperMax = (int) Math.floor((mainAnchorPane.getWidth() - 24) / 217);
}
int xPosHelperMax = (int) Math.floor((mainAnchorPane.getWidth() - 36) / 217);
if(xPosHelper == xPosHelperMax){
oldXPosHelper = xPosHelper;
xPos = 17;
yPos = yPos + 345;
xPosHelper = 1;
@ -1480,7 +1475,7 @@ public class MainWindowController {
* @return the main color in hexadecimal format
*/
private String hexToRgb() {
System.out.println(getColor());
LOGGER.info(getColor());
int hex = Integer.parseInt(getColor().substring(0, 5), 16);
int r = (hex & 0xFF0000) >> 16;
@ -1618,5 +1613,17 @@ public class MainWindowController {
public void setWindowHeight(double windowHeight) {
this.windowHeight = windowHeight;
}
public int getOldXPosHelper() {
return oldXPosHelper;
}
public void setOldXPosHelper(int oldXPosHelper) {
this.oldXPosHelper = oldXPosHelper;
}
public AnchorPane getMainAnchorPane() {
return mainAnchorPane;
}
}