mt/src/cl/cromer/mt/LoteController.java

90 lines
2.3 KiB
Java
Raw Normal View History

2017-07-03 16:53:28 -04:00
/* 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.
*/
2017-07-03 20:46:11 -04:00
package cl.cromer.mt;
2017-07-03 13:22:01 -04:00
2017-07-03 16:53:28 -04:00
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
2017-07-03 13:22:01 -04:00
import javafx.fxml.FXML;
import javafx.scene.Scene;
2017-07-03 16:53:28 -04:00
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
2017-07-03 13:22:01 -04:00
import javafx.scene.layout.VBox;
2017-07-03 16:53:28 -04:00
import javafx.stage.Stage;
2017-07-03 13:22:01 -04:00
2017-07-03 16:53:28 -04:00
/**
* Controlar las acciones de reconocimiento por lote
*/
public class LoteController extends VBox {
2017-07-07 02:49:18 -04:00
/**
* La tabla de resultados por lote
*/
2017-07-04 23:34:45 -04:00
private final ObservableList<TablaData> tablaData = FXCollections.observableArrayList();
2017-07-07 02:49:18 -04:00
/**
* El contenido de la ventana
*/
2017-07-03 13:22:01 -04:00
@FXML
2017-07-04 23:34:45 -04:00
private VBox contenido;
2017-07-03 13:22:01 -04:00
2017-07-07 02:49:18 -04:00
/**
* La cadena que el usuario ingresa
*/
2017-07-03 16:53:28 -04:00
@FXML
private TextField cadena;
2017-07-03 13:22:01 -04:00
/**
2017-07-03 16:53:28 -04:00
* Boton de run MT
2017-07-03 13:22:01 -04:00
*/
@FXML
protected void runLote() {
2017-07-04 23:34:45 -04:00
Scene scene = contenido.getScene();
2017-07-04 16:32:21 -04:00
EstadosFinales estadosFinales = (EstadosFinales) scene.getUserData();
Maquina maquina = estadosFinales.getMaquina();
2017-07-03 16:53:28 -04:00
for (TablaData fila : tablaData) {
2017-07-04 23:34:45 -04:00
boolean exito = maquina.comprobarCadena(new StringBuilder(fila.getPrimera()), estadosFinales.getEstadosElegidos().stream().mapToInt(i -> i).toArray());
2017-07-03 16:53:28 -04:00
if (exito) {
2017-07-04 23:34:45 -04:00
fila.setSegunda("Aceptada");
2017-07-03 16:53:28 -04:00
}
else {
2017-07-04 23:34:45 -04:00
fila.setSegunda("Rechazada");
2017-07-03 16:53:28 -04:00
}
2017-07-03 20:46:11 -04:00
maquina.reset();
2017-07-03 16:53:28 -04:00
}
}
/**
* 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(), ""));
2017-07-04 23:34:45 -04:00
Scene scene = contenido.getScene();
2017-07-03 20:46:11 -04:00
@SuppressWarnings("unchecked")
TableView<TablaData> tableView = (TableView<TablaData>) scene.lookup("#tableView");
tableView.setEditable(true);
tableView.setItems(tablaData);
cadena.setText("");
2017-07-03 13:22:01 -04:00
}
2017-07-03 16:53:28 -04:00
/**
* Boton de cerrar
*/
@FXML
protected void cerrar() {
2017-07-04 23:34:45 -04:00
Scene scene = contenido.getScene();
2017-07-03 16:53:28 -04:00
Stage stage = (Stage) scene.getWindow();
stage.close();
}
}