From b1fb35a1ef9a1aedcb3572f93efd3b4bba67c24a Mon Sep 17 00:00:00 2001 From: Robson Date: Wed, 29 Nov 2023 01:59:49 -0300 Subject: [PATCH 1/9] Cadastrando evento com imagem --- .../controller/CadastrarEventoController.java | 40 +++++++++++++++++++ .../sgec/view/cadastrarEvento.fxml | 18 ++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/casaculturaqxd/sgec/controller/CadastrarEventoController.java b/src/main/java/com/casaculturaqxd/sgec/controller/CadastrarEventoController.java index 70731cfb..9f981d66 100644 --- a/src/main/java/com/casaculturaqxd/sgec/controller/CadastrarEventoController.java +++ b/src/main/java/com/casaculturaqxd/sgec/controller/CadastrarEventoController.java @@ -1,7 +1,10 @@ package com.casaculturaqxd.sgec.controller; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.sql.Date; import java.sql.SQLException; import java.sql.Time; @@ -48,6 +51,8 @@ import javafx.scene.control.ButtonBar; import javafx.scene.control.ButtonType; import javafx.scene.control.ButtonBar.ButtonData; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; import javafx.scene.control.CheckBox; import javafx.scene.control.ChoiceBox; import javafx.scene.control.DateCell; @@ -61,6 +66,7 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.FileChooser; +import javafx.stage.FileChooser.ExtensionFilter; import javafx.stage.Stage; import javafx.util.converter.LocalTimeStringConverter; @@ -108,8 +114,11 @@ public class CadastrarEventoController implements ControllerServiceFile, Control ObservableMap colaboradorObservableMap = FXCollections.observableHashMap(); @FXML Button botaoNovaLocalizacao; + @FXML + ImageView capaEvento; ObservableMap participantes = FXCollections.observableHashMap(); private Alert mensagem = new Alert(AlertType.NONE); + File file = null; public void initialize() throws IOException { eventoDAO = new EventoDAO(db.getConnection()); @@ -259,6 +268,20 @@ private Evento getTargetEvento() throws SQLException { builderEvento.setListaArquivos(listaArquivos); builderEvento.setLocalizacoes(locais); builderEvento.setListaMetas(getMetasSelecionadas()); + if(file != null){ + ServiceFile serviceFileTemp = new ServiceFile(file); + try { + if(serviceFileDAO.getArquivo(serviceFileTemp.getFileKey()).isEmpty()){ + serviceFileDAO.inserirArquivo(serviceFileTemp); + serviceFileTemp = serviceFileDAO.getArquivo(serviceFileTemp.getFileKey()).get(); + } else { + serviceFileTemp = serviceFileDAO.getArquivo(serviceFileTemp.getFileKey()).get(); + } + } catch (SQLException e) { + e.printStackTrace(); + } + builderEvento.setImagemCapa(serviceFileTemp); + } return builderEvento.getEvento(); } @@ -752,4 +775,21 @@ public void removerLocalizacao(Localizacao localizacao) { botaoNovaLocalizacao.setDisable(false); } + + public void loadImagem(){ + InputStream fileAsStream; + FileChooser fileChooser = new FileChooser(); + fileChooser.setTitle("Alterar foto da instituição"); + ExtensionFilter filterImagens = new ExtensionFilter("imagem", "*.jpeg", "*.jpg", "*.png", "*.bmp"); + fileChooser.getExtensionFilters().add(filterImagens); + try { + file = fileChooser.showOpenDialog(stage); + fileAsStream = new FileInputStream(file); + capaEvento.setImage(new Image(fileAsStream)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (NullPointerException e) { + e.printStackTrace(); + } + } } diff --git a/src/main/resources/com/casaculturaqxd/sgec/view/cadastrarEvento.fxml b/src/main/resources/com/casaculturaqxd/sgec/view/cadastrarEvento.fxml index 00c2ba61..f3baf579 100644 --- a/src/main/resources/com/casaculturaqxd/sgec/view/cadastrarEvento.fxml +++ b/src/main/resources/com/casaculturaqxd/sgec/view/cadastrarEvento.fxml @@ -10,13 +10,14 @@ + - + @@ -24,13 +25,26 @@ - + + + + + + + + +