GameCardController.java (1334B) download
1package nl.isygameclient.controllers.game_selector;
2
3import javafx.fxml.FXML;
4import javafx.scene.control.Label;
5import javafx.scene.image.Image;
6import javafx.scene.image.ImageView;
7import javafx.scene.input.MouseEvent;
8import nl.isygameclient.Application;
9import nl.isygameclient.models.settings.GameCard;
10
11public class GameCardController {
12
13 private GameCard gameCard;
14
15 @FXML
16 private ImageView gameImage;
17
18 @FXML
19 private Label gameTitle;
20
21 public void initializeCard(GameCard gameCard) {
22 this.gameCard = gameCard;
23 // Set Title
24 gameTitle.setText(gameCard.getName());
25 loadImage();
26 }
27
28 public void loadImage() {
29 // Load Image
30 if (gameCard.getImgSrc() != null) {
31 var imageSrc = Application.class.getResource(gameCard.getImgSrc());
32 if (imageSrc != null) {
33 gameImage.setImage(new Image(imageSrc.toExternalForm()));
34 } else {
35 System.err.printf("Image for: %s at %s, doen not exist\n", gameCard.getName(), gameCard.getImgSrc());
36 }
37 } else {
38 System.err.printf("ImgSrc for: %s, not provided\n", gameCard.getName());
39 }
40 }
41
42 @FXML
43 protected void onCardMouseClick(MouseEvent event) {
44 GameSelectorController.onGameClick(event, gameCard);
45 }
46}