-
Notifications
You must be signed in to change notification settings - Fork 0
/
StageControl.java
201 lines (163 loc) · 8.37 KB
/
StageControl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Text;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class StageControl extends LyricsForSpotifyApplication{
/**
* Variables used that control the pane, scene, and Stage.
*/
private static VBox mainPane = new VBox(20);
private Scene mainScene = new Scene(mainPane,600,900);
private Stage mainStage;
protected LyricsForSpotifyApplication parent;
private Authorization authorization = Authorization.getInstance();
private MenuBar mainMenu;
double xOffset;
double yOffset;
public StageControl(LyricsForSpotifyApplication parent) {
mainStage = new Stage();
mainStage.initStyle(StageStyle.UNDECORATED);
mainStage.setScene(mainScene);
mainMenu = parent.getMenubar();
mainScene.setOnMousePressed(mouseClickEvent -> {
setXOffset(mainStage.getX() - mouseClickEvent.getScreenX());
setYOffset(yOffset = mainStage.getY() - mouseClickEvent.getScreenY());
});
mainScene.setOnMouseDragged(mouseDragEvent -> {
mainStage.setX(mouseDragEvent.getScreenX() + xOffset );
mainStage.setY(mouseDragEvent.getScreenY() + yOffset);
});
mainMenu.setOnMousePressed(menuMouseClickEvent -> {
setXOffset(mainStage.getX() - menuMouseClickEvent.getScreenX());
setYOffset(yOffset = mainStage.getY() - menuMouseClickEvent.getScreenY());
});
mainMenu.setOnMouseDragged(menuMouseDragEvent -> {
mainStage.setX(menuMouseDragEvent.getScreenX() + xOffset );
mainStage.setY(menuMouseDragEvent.getScreenY() + yOffset);
});
mainScene.setFill(Color.TRANSPARENT);
mainPane.getChildren().clear();
mainPane.setPrefSize(mainScene.getWidth(),mainScene.getHeight());
this.parent = parent;
}
public void setParent(LyricsForSpotifyApplication parent) {
this.parent = parent;
}
/**
* Sets the mainStage to the configurations for the home screen prior to authentication.
* @return mainStage with configurations applied.
*/
public void homeStage() {
parent.applyConfigurations();
Authorization.resetAuthentication();
mainPane.getChildren().clear();
mainPane.setAlignment(Pos.TOP_CENTER);
mainPane.setStyle("-fx-background-radius: 10; -fx-background-color: "+ textConfigurations.getBackgroundColor() +"; -fx-border-color: "+ textConfigurations.getBorderColor() + "; -fx-border-radius: 10; -fx-border-width: "+textConfigurations.getBorderSize()+";");
Label spotifyLyrics = new Label("Lyrics for");
spotifyLyrics.setTextFill(Paint.valueOf(Color.FLORALWHITE.toString()));
spotifyLyrics.setStyle("-fx-font-size: 72");
Button signIntoSpotify = new Button("Sign into Spotify");
signIntoSpotify.setTextFill(Paint.valueOf(Color.WHITE.toString()));
signIntoSpotify.setBackground(new Background(new BackgroundFill(Paint.valueOf(Color.TRANSPARENT.toString()),new CornerRadii(0),new Insets(0))));
signIntoSpotify.setOnAction(signIntoSpotifyAction ->{
authorizationStage();
});
signIntoSpotify.setPrefWidth(200);
signIntoSpotify.setStyle("-fx-font-size: 22;");
mainPane.getChildren().addAll(mainMenu, spotifyLyrics,new ImageView(new Image(this.getClass().getResourceAsStream("Spotify_Logo_RGB_White.png"),295.25,88.5,false,true)),new Label("\n\n\n\n"),signIntoSpotify);
}
/**
* Stage to display the webview to the user for Spotify authentication
* @return mainStage with the configurations applied
*/
public void authorizationStage() {
parent.applyConfigurations();
mainPane.getChildren().clear();
mainPane.setAlignment(Pos.CENTER_LEFT);
WebView webView= parent.connectToSpotify();
webView.setPrefHeight(mainPane.getHeight());
mainPane.getChildren().addAll(mainMenu, webView);
}
/**
* Sets the mainStage to the configuration to display artist, song, and lyrics.
* @return mainStage with the configurations applied
*/
public void lyricsStage(ScrollPane scrollPane) {
parent.applyConfigurations();
mainPane.getChildren().clear();
mainPane.setAlignment(Pos.TOP_LEFT);
mainPane.setStyle("-fx-background-radius: 10; -fx-background-color: "+ textConfigurations.getBackgroundColor() +"; -fx-border-color: "+ textConfigurations.getBorderColor() + "; -fx-border-radius: 10; -fx-border-width: "+textConfigurations.getBorderSize() +";");
scrollPane.setStyle("-fx-background-radius: 10; -fx-background: transparent; -fx-background-color: transparent; -fx-border-color: transparent; -fx-body-color: transparent;");
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
scrollPane.setVmin(0);
scrollPane.setVmax(100);
mainPane.getChildren().addAll(mainMenu,song,artist, scrollPane);
}
/**
* Sets the stage to display the provided error message and information for song controls if forLyrics is true.
* @param errorMessage Error message to display to the user
* @param forLyrics True if the error was thrown during the lyrics process, false otherwise.
* @return mainStage with the configurations applied
*/
public void errorStage(String errorMessage, Boolean forLyrics) {
mainPane.getChildren().clear();
parent.applyConfigurations();
if(forLyrics) {
mainPane.setAlignment(Pos.TOP_LEFT);
mainPane.setStyle("-fx-background-radius: 10; -fx-background-color: "+ textConfigurations.getBackgroundColor() +"; -fx-border-color: "+ textConfigurations.getBorderColor() + "; -fx-border-radius: 10; -fx-border-width: "+textConfigurations.getBorderSize() +";");
Text errorLabel = new Text(errorMessage);
errorLabel.setStrokeWidth(textConfigurations.getTextOutlineWidth());
errorLabel.setFill(Paint.valueOf(textConfigurations.getTextColor()));
errorLabel.setStroke(Paint.valueOf(textConfigurations.getTextOutLine()));
errorLabel.setStyle("-fx-font-size: "+ textConfigurations.getLyricTextSize() +"; -fx-text-fill: " + textConfigurations.getTextColor() +"; ");
Button skipSong = new Button("Next Song");
skipSong.setOnAction(skipSongAction ->{
skipSong.setDisable(true);
parent.nextSong();
skipSong.setDisable(false);
});
HBox songOptions = new HBox(30);
songOptions.setAlignment(Pos.CENTER);
mainPane.getChildren().clear();
scrollPane.setContent(errorLabel);
mainPane.getChildren().addAll(mainMenu,song == null? new Text("No song playing"): song,artist == null? new Text("No song playing"): artist, errorLabel);
parent.threadControl.startCurrentSongCheckThread();
// if (threadControl.currentSongCheckThread == null || threadControl.currentSongCheckThread.isInterrupted() || !threadControl.currentSongCheckThread.isAlive()){
// threadControl.startCurrentSongCheckThread();
// }
} else {
mainPane.setAlignment(Pos.CENTER);
Button retry = new Button("Retry");
retry.setPrefWidth(150);
retry.setOnAction(retryAction ->{
homeStage();
});
mainPane.getChildren().addAll(mainMenu,new Label(errorMessage),retry);
}
}
private void setXOffset(double newXOffset){
xOffset = newXOffset;
}
private void setYOffset(double newYOffset){
yOffset = newYOffset;
}
public Stage getMainStage() {
return mainStage;
}
public VBox getMainPane() {
return mainPane;
}
public double getStageHeight() {
return mainStage.getHeight();
}
}