package seng302.visualiser.controllers; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; import java.util.List; import java.util.ResourceBundle; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.input.MouseEvent; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.GridPane; import javafx.scene.layout.Pane; import seng302.model.ClientYacht; import seng302.utilities.Sounds; public class FinishScreenViewController implements Initializable { @FXML private GridPane finishScreenGridPane; @FXML private TableView finishOrderTable; @FXML private TableColumn posCol; @FXML private TableColumn boatNameCol; @FXML private TableColumn shortNameCol; @FXML private TableColumn countryCol; ObservableList data = FXCollections.observableArrayList(); @Override public void initialize(URL location, ResourceBundle resources) { finishScreenGridPane.getStylesheets() .add(getClass().getResource("/css/Master.css").toString()); finishOrderTable.getStylesheets().add(getClass().getResource("/css/Master.css").toString()); // set up data for table finishOrderTable.setItems(data); // setting table col data posCol.setCellValueFactory( new PropertyValueFactory<>("position") ); boatNameCol.setCellValueFactory( new PropertyValueFactory<>("boatName") ); shortNameCol.setCellValueFactory( new PropertyValueFactory<>("shortName") ); countryCol.setCellValueFactory( new PropertyValueFactory<>("country") ); finishOrderTable.refresh(); } public void setFinishers(Collection participants) { List sorted = new ArrayList<>(participants); sorted.sort(Comparator.comparingInt(ClientYacht::getPlacing)); finishOrderTable.getItems().setAll(sorted); } private void setContentPane(String jfxUrl) { try { // get the main controller anchor pane (FinishView -> MainView) AnchorPane contentPane = (AnchorPane) finishScreenGridPane.getParent(); contentPane.getChildren().removeAll(); contentPane.getChildren().clear(); contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString()); contentPane.getChildren() .addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl))); } catch (javafx.fxml.LoadException e) { System.out.println("[Controller] FXML load exception"); } catch (IOException e) { System.out.println("[Controller] IO exception"); } } public void switchToStartScreenView() { Sounds.playButtonClick(); //TODO merge fix setContentPane("/views/StartScreenView.fxml"); } public void playButtonHoverSound(MouseEvent mouseEvent) { Sounds.playHoverSound(); } }