Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. package vistas;
  2.  
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileNotFoundException;
  6. import java.io.IOException;
  7. import java.lang.reflect.Array;
  8. import java.util.ResourceBundle;
  9.  
  10. import javax.print.DocFlavor.URL;
  11.  
  12. import javafx.event.ActionEvent;
  13. import javafx.fxml.FXML;
  14. import javafx.scene.Node;
  15. import javafx.scene.control.Button;
  16. import javafx.scene.control.Label;
  17. import javafx.scene.control.TextField;
  18. import javafx.scene.image.Image;
  19. import javafx.scene.image.ImageView;
  20. import javafx.scene.layout.AnchorPane;
  21. import javafx.scene.layout.ColumnConstraints;
  22. import javafx.scene.layout.GridPane;
  23. import javafx.scene.layout.RowConstraints;
  24. import javafx.stage.FileChooser;
  25.  
  26. import principal.main;
  27.  
  28. public class AreaProjectoController {
  29.  
  30. @FXML
  31. private Button meuBotaoImagem, meuBotaoGrelha, btnLimpaGrelha, btnArea;
  32.  
  33. @FXML
  34. private ImageView minhaImagem;
  35.  
  36. @FXML
  37. private TextField txtGrelhaLeft, txtGrelhaRight;
  38.  
  39. @FXML
  40. private AnchorPane painelGrelha, painelArea;
  41.  
  42. @FXML
  43. private GridPane painelCriaGrelha;
  44.  
  45. public void initialize(URL location, ResourceBundle resources) {
  46. }
  47.  
  48. public void mostraImagem(ActionEvent evento) throws FileNotFoundException {
  49.  
  50. FileChooser imagemEscolhida = new FileChooser();
  51.  
  52. // Define a extensão do ficheiro
  53. FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("JPEG/PNG", "*.jpeg", "*.png");
  54. imagemEscolhida.getExtensionFilters().add(extFilter);
  55.  
  56. // abre a janela para procurar uma imagem
  57. File ficheiro = imagemEscolhida.showOpenDialog(main.getPrimaryStage());
  58.  
  59. // O if trata quando se cancela o carregamento de uma imagem
  60. if(ficheiro != null) {
  61. Image imagem = new Image(new FileInputStream(ficheiro));
  62. minhaImagem.setImage(imagem);
  63. painelGrelha.setVisible(true);
  64. txtGrelhaLeft.setText("0");
  65. txtGrelhaRight.setText("0");
  66. }
  67.  
  68. }
  69.  
  70. public void criaGrelha(ActionEvent evento) throws FileNotFoundException, IOException {
  71.  
  72. int txtLeft = 0, txtRight = 0, i = 1, ii = 1, l = 0, j = 0;
  73.  
  74. ColumnConstraints colunas = null;
  75. RowConstraints linhas = null;
  76.  
  77. txtLeft = Integer.parseInt(txtGrelhaLeft.getText());
  78. txtRight = Integer.parseInt(txtGrelhaRight.getText());
  79.  
  80. //Este for cria a grelha após receber os valores
  81. for(i = 1; i <= txtLeft; i++) {
  82. colunas = new ColumnConstraints();
  83. colunas.setPercentWidth(25);
  84. painelCriaGrelha.getColumnConstraints().add(colunas);
  85. }
  86.  
  87. for(ii = 1; ii <= txtRight; ii++) {
  88. linhas = new RowConstraints();
  89. linhas.setPercentHeight(25);
  90. painelCriaGrelha.getRowConstraints().add(linhas);
  91. }
  92.  
  93. //Label fillLabel[][] = new Label[txtLeft][txtRight];
  94. TextField fillLabel[][] = new TextField[txtLeft][txtRight];
  95.  
  96. for (l = 0; l < txtLeft; l++) {
  97. for (j = 0; j < txtRight; j++) {
  98. fillLabel[l][j] = new TextField();
  99. //fillLabel[l][j] = new Label();
  100. fillLabel[l][j].setText(String.valueOf(0));
  101. fillLabel[l][j].setBackground(null);
  102. painelCriaGrelha.add(fillLabel[l][j], l, j);
  103.  
  104.  
  105. }
  106. }
  107.  
  108. /*for (l = 0; l < fillLabel.length; l++) {
  109. for (j = 0; j < fillLabel.length; j++) {
  110. System.out.println(fillLabel[l][j].getText());
  111. }
  112. System.out.println(" ");
  113. }*/
  114.  
  115. painelCriaGrelha.setGridLinesVisible(true); //isto faz aparecer as linhas da grelha a preto
  116. painelArea.setVisible(true);
  117.  
  118.  
  119.  
  120. //for(l = 1; l <= fillLabel.length; l++) {
  121.  
  122. //System.out.println(l);
  123. // }
  124.  
  125. //Func.salvaInfoGrelha(listaElementosArea);
  126.  
  127. }
  128.  
  129. public void limpaGrelha(ActionEvent evento) {
  130.  
  131. painelCriaGrelha.getColumnConstraints().clear();
  132. painelCriaGrelha.getRowConstraints().clear();
  133. txtGrelhaLeft.setText("0");
  134. txtGrelhaRight.setText("0");
  135.  
  136. }
  137.  
  138. public void defineArea(ActionEvent evento) {
  139.  
  140. int txtLeft = 0, txtRight = 0;
  141. int l = 0, j = 0;
  142.  
  143. txtLeft = Integer.parseInt(txtGrelhaLeft.getText());
  144. txtRight = Integer.parseInt(txtGrelhaRight.getText());
  145.  
  146.  
  147. TextField fillLabel[][] = new TextField[txtLeft][txtRight];// = new S[txtLeft][txtRight];
  148. //GridPane painel = new GridPane();
  149.  
  150. System.out.println(txtLeft);
  151. System.out.println(txtRight);
  152.  
  153. //TextField texto = fillLabel[1][1];
  154.  
  155. painelCriaGrelha.getChildren().get(fillLabel[1][1].getText());
  156. System.out.println(painelCriaGrelha.getChildren().get(fillLabel[1][1]).getText());
  157.  
  158. /*for (l = 0; l < txtLeft; l++) {
  159. for (j = 0; j < txtRight; j++) {
  160. System.out.println(painelCriaGrelha.getChildren().get(fillLabel[1][1]));
  161. }
  162. }*/
  163.  
  164. //System.out.println(texto);
  165.  
  166. }
  167.  
  168. }
  169.  
  170. painelCriaGrelha.getChildren().get(fillLabel[1][1]);
  171.  
  172. if(node instanceof TextField)
  173.  
  174. ((TextField)painelCriaGrelha.getChildren().get(fillLabel[1][1])).getText();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement