This repository was archived by the owner on May 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChangePictureController.java
More file actions
133 lines (116 loc) · 3.96 KB
/
ChangePictureController.java
File metadata and controls
133 lines (116 loc) · 3.96 KB
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
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.MenuBar;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.stage.PopupWindow;
import javafx.stage.Stage;
import javafx.fxml.Initializable;
/**
* This class handles events when certain parts of the scene is interacted and outputs image data for user to pick.
* @author Kevin Pan 969449
* @version 1
*/
public class ChangePictureController implements Initializable {
ObservableList<String> pictures = FXCollections.observableArrayList("Picture 1", "Picture 2", "Picture 3", "Picture 4", "Picture 5", "Picture 6");
public String selected;
@FXML
private Button save;
@FXML
private Button drawPicture;
@FXML
private ChoiceBox<String> pic;
@FXML
private Label username;
@FXML
private ImageView picture;
@FXML
private Image image;
@FXML
private String imageURL;
@FXML
/**
* Displays different images depending on which choice is selected.
* @param event The event is when the button is clicked.
* @throws IOException Exception to combat failed or interrupted inputs.
*/
public void handlePicturePushed(ActionEvent event) throws IOException {
selected = pic.getSelectionModel().getSelectedItem();
if (selected == "Picture 1") {
imageURL = "templates/TAWE-Lib User.png";
image = new Image(imageURL);
picture.setImage(image);
} else if (selected == "Picture 2") {
imageURL = "templates/TAWE-Lib Triangle.png";
image = new Image(imageURL);
picture.setImage(image);
} else if (selected == "Picture 3") {
imageURL = "templates/TAWE-Lib Star.png";
image = new Image(imageURL);
picture.setImage(image);
} else if (selected == "Picture 4") {
imageURL = "templates/TAWE-Lib Lines.png";
image = new Image(imageURL);
picture.setImage(image);
} else if (selected == "Picture 5") {
imageURL = "templates/TAWE-Lib Hex.png";
image = new Image(imageURL);
picture.setImage(image);
} else if (selected == "Picture 6") {
imageURL = "templates/TAWE-Lib Circle.png";
image = new Image(imageURL);
picture.setImage(image);
}
}
@FXML
/**
* Switches to the drawing scene.
* @param event The event is when the button is clicked.
* @throws IOException Exception to combat failed or interrupted inputs.
*/
public void handleDrawPicture(ActionEvent event) throws IOException {
Stage window = (Stage)((Node)event.getSource()).getScene().getWindow();
Drawing newTemplate = new Drawing();
newTemplate.start(window);
}
@FXML
/**
* Saves the selected avatar and closes the window.
* @param event The event is when the button is clicked.
* @throws IOException Exception to combat failed or interrupted inputs.
*/
public void handleSave(ActionEvent event) {
Controller currentLogin = Library.getCurrentLogin();
System.out.println("yee: " + imageURL);
currentLogin.setPicture(imageURL);
Stage stage = (Stage) save.getScene().getWindow();
stage.close();
}
@Override
/**
* Method that is immediately run when the scene is loaded to output the inital picture.
* @param url The location used to resolve relative paths for the root object or null if the location is unknown.
* @param resources The resources used to localise the root object or null if the root object is not localised.
*/
public void initialize(URL url, ResourceBundle resources) {
System.out.println("Working...");
pic.setValue("Picture 1");
imageURL = "templates/TAWE-Lib User.png";
pic.setItems(pictures);
}
}