/* Copyright (c) 2017 Christopher Cromer * Copyright (c) 2017 Carlos Faúndez * * This file is part of mt. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution. * This file may not be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file. */ package cl.cromer.mt; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.Scene; import javafx.scene.control.TableView; import javafx.scene.control.TextField; import javafx.scene.layout.VBox; import javafx.stage.Stage; /** * Controlar las acciones de reconocimiento por lote */ public class LoteController extends VBox { /** * La tabla de resultados por lote */ private final ObservableList tablaData = FXCollections.observableArrayList(); /** * El contenido de la ventana */ @FXML private VBox contenido; /** * La cadena que el usuario ingresa */ @FXML private TextField cadena; /** * Boton de run MT */ @FXML protected void runLote() { Scene scene = contenido.getScene(); EstadosFinales estadosFinales = (EstadosFinales) scene.getUserData(); Maquina maquina = estadosFinales.getMaquina(); for (TablaData fila : tablaData) { boolean exito = maquina.comprobarCadena(new StringBuilder(fila.getPrimera()), estadosFinales.getEstadosElegidos().stream().mapToInt(i -> i).toArray()); if (exito) { fila.setSegunda("Aceptada"); } else { fila.setSegunda("Rechazada"); } maquina.reset(); } } /** * Boton de agregar cadena */ @FXML protected void agregarCadena() { StringBuilder temp = new StringBuilder(cadena.getText()); if (temp.charAt(0) != '#') { temp.insert(0, "#"); } if (temp.charAt(temp.length() - 1) != '#') { temp.insert(temp.length(), "#"); } tablaData.add(new TablaData(temp.toString(), "")); Scene scene = contenido.getScene(); @SuppressWarnings("unchecked") TableView tableView = (TableView) scene.lookup("#tableView"); tableView.setEditable(true); tableView.setItems(tablaData); cadena.setText(""); } /** * Boton de cerrar */ @FXML protected void cerrar() { Scene scene = contenido.getScene(); Stage stage = (Stage) scene.getWindow(); stage.close(); } }