From c14fba7f857f3957db5595c4127807e05137bbf3 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Mon, 3 Jul 2017 16:03:43 -0400 Subject: [PATCH] Terminar por lote --- doc/mt/ListaCargada.html | 2 +- doc/mt/class-use/ListaCargada.html | 6 +- src/mt/LoteController.java | 66 +++++++++++++++++--- src/mt/MenuController.java | 57 +++++++++++------ src/mt/{ListaCargada.java => TablaData.java} | 6 +- src/mt/lote.fxml | 35 ++++++++--- src/mt/{transiciones.fxml => tabla.fxml} | 4 +- 7 files changed, 133 insertions(+), 43 deletions(-) rename src/mt/{ListaCargada.java => TablaData.java} (81%) rename src/mt/{transiciones.fxml => tabla.fxml} (86%) diff --git a/doc/mt/ListaCargada.html b/doc/mt/ListaCargada.html index af67341..dbca5e4 100644 --- a/doc/mt/ListaCargada.html +++ b/doc/mt/ListaCargada.html @@ -109,7 +109,7 @@
  • java.lang.Object
  • diff --git a/doc/mt/class-use/ListaCargada.html b/doc/mt/class-use/ListaCargada.html index 54dffb2..e94db5a 100644 --- a/doc/mt/class-use/ListaCargada.html +++ b/doc/mt/class-use/ListaCargada.html @@ -3,7 +3,7 @@ - Uses of Class mt.ListaCargada + Uses of Class mt.TablaData @@ -70,9 +70,9 @@
    -

    Uses of Class
    mt.ListaCargada

    +

    Uses of Class
    mt.TablaData

    -
    No usage of mt.ListaCargada
    +
    No usage of mt.TablaData
    diff --git a/src/mt/LoteController.java b/src/mt/LoteController.java index 89ac8da..70b865a 100644 --- a/src/mt/LoteController.java +++ b/src/mt/LoteController.java @@ -1,25 +1,77 @@ +/* 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 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; -public class LoteController { +/** + * Controlar las acciones de reconocimiento por lote + */ +public class LoteController extends VBox { @FXML private VBox vboxLote; + @FXML + private TextField cadena; + + private ObservableList tablaData = FXCollections.observableArrayList(); + /** - * Boton Run MT de lote + * Boton de run MT + * @throws Exception La excepción */ @FXML protected void runLote() throws Exception { Scene scene = vboxLote.getScene(); Maquina maquina = (Maquina) scene.getUserData(); - if (maquina.comprobarCadena(new StringBuilder("000111###"), 5)) { - MT.mostrarMensaje("Resultado", "Reconce"); - } - else { - MT.mostrarMensaje("Resultado", " No reconce"); + for (TablaData fila : tablaData) { + boolean exito = maquina.comprobarCadena(new StringBuilder(fila.getPrimer()), 5); + if (exito) { + fila.setSegundo("Aceptado"); + } + else { + fila.setSegundo("Rechazada"); + } } } + + /** + * Boton de agregar cadena + */ + @FXML + protected void agregarCadena() { + if (!cadena.getText().trim().equals("")) { + tablaData.add(new TablaData(cadena.getText(), "")); + Scene scene = vboxLote.getScene(); + @SuppressWarnings("unchecked") + TableView tableView = (TableView) scene.lookup("#tableView"); + tableView.setEditable(true); + tableView.setItems(tablaData); + } + else { + MT.mostrarMensaje("Error", "Ingresa una cadena por favor!"); + } + } + + /** + * Boton de cerrar + */ + @FXML + protected void cerrar() { + Scene scene = vboxLote.getScene(); + Stage stage = (Stage) scene.getWindow(); + stage.close(); + } } diff --git a/src/mt/MenuController.java b/src/mt/MenuController.java index fef4f2c..e711acf 100644 --- a/src/mt/MenuController.java +++ b/src/mt/MenuController.java @@ -12,11 +12,12 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; -import javafx.fxml.Initializable; import javafx.scene.Scene; import javafx.scene.control.MenuBar; import javafx.scene.control.MenuItem; +import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; +import javafx.scene.control.cell.TextFieldTableCell; import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; @@ -28,16 +29,14 @@ import javafx.stage.Stage; import org.w3c.dom.Document; import java.io.File; -import java.net.URL; -import java.util.ResourceBundle; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Controlar las acciones cuando una opción es elegido en el menu. */ -public class MenuController extends VBox implements Initializable { - Maquina maquina = null; +public class MenuController { + private Maquina maquina = null; @FXML private MenuBar menuBar; @@ -48,17 +47,6 @@ public class MenuController extends VBox implements Initializable { @FXML private MenuItem menuLote; - /** - * Inicialicar el menu con el idioma. - * - * @param location Tiene URL de FXML en uso. - * @param resourceBundle Tiene recursos qu se pasa al controller. - */ - @Override - public void initialize(URL location, ResourceBundle resourceBundle) { - // No es necesario poner algo aqui porque el programa mt no se usa los resourceBundles - } - /** * Menu opción cargar transiciones * @@ -90,7 +78,7 @@ public class MenuController extends VBox implements Initializable { menuIndiv.setDisable(false); menuLote.setDisable(false); } - TableView tableView = FXMLLoader.load(getClass().getResource("transiciones.fxml")); + TableView tableView = FXMLLoader.load(getClass().getResource("tabla.fxml")); VBox.setVgrow(tableView, Priority.ALWAYS); tableView.skinProperty().addListener((source, oldWidth, newWidth) -> { final TableHeaderRow header = (TableHeaderRow) tableView.lookup("TableHeaderRow"); @@ -98,17 +86,20 @@ public class MenuController extends VBox implements Initializable { }); tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); - ObservableList listaCargadas = FXCollections.observableArrayList(); + ObservableList tablaData = FXCollections.observableArrayList(); Pattern pattern = Pattern.compile("(\\(.*\\)) = (\\(.*\\))"); for (int i = 0; i < maquina.getMaquina().getEstados().size(); i++) { Matcher matcher = pattern.matcher(maquina.getMaquina().getEstados().get(i).toString()); while (matcher.find()) { - listaCargadas.add(new ListaCargada(matcher.group(1), matcher.group(2))); + tablaData.add(new TablaData(matcher.group(1), matcher.group(2))); } } tableView.setEditable(true); - tableView.setItems(listaCargadas); + tableView.setItems(tablaData); + + tableView.getColumns().get(0).setText("(qi,si)"); + tableView.getColumns().get(1).setText("(qj,sj,movimiento)"); contenido.getChildren().add(tableView); @@ -133,6 +124,7 @@ public class MenuController extends VBox implements Initializable { * Menu opción reconocimiento lote */ @FXML + @SuppressWarnings("unchecked") protected void reconoceLote() throws Exception { Scene parentScene = menuBar.getScene(); Stage parentStage = (Stage) parentScene.getWindow(); @@ -141,11 +133,36 @@ public class MenuController extends VBox implements Initializable { fxmlLoader.setLocation(getClass().getResource("lote.fxml")); Scene scene = new Scene(fxmlLoader.load(), 640, 480); scene.setUserData(maquina); + scene.getStylesheets().add("/mt/mt.css"); Stage stage = new Stage(); stage.initModality(Modality.WINDOW_MODAL); stage.initOwner(parentStage); stage.setTitle("Reconocimiento por lotes"); + stage.setMinHeight(480); + stage.setMinWidth(640); stage.setScene(scene); stage.show(); + + TableView tableView = FXMLLoader.load(getClass().getResource("tabla.fxml")); + VBox.setVgrow(tableView, Priority.ALWAYS); + tableView.skinProperty().addListener((source, oldWidth, newWidth) -> { + final TableHeaderRow header = (TableHeaderRow) tableView.lookup("TableHeaderRow"); + header.reorderingProperty().addListener((observable, oldValue, newValue) -> header.setReordering(false)); + }); + tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); + + TableColumn columna1 = (TableColumn) tableView.getColumns().get(0); + columna1.setCellFactory(TextFieldTableCell.forTableColumn()); + columna1.setOnEditCommit( + columna -> columna.getTableView().getItems().get(columna.getTablePosition().getRow()).setPrimer(columna.getNewValue()) + ); + + tableView.getColumns().get(0).setText("Cadena"); + tableView.getColumns().get(0).setEditable(true); + tableView.getColumns().get(1).setText("Aceptada/Rechazada"); + tableView.getColumns().get(1).setEditable(false); + + VBox contenido = (VBox) scene.lookup("#contenidoLote"); + contenido.getChildren().add(tableView); } } \ No newline at end of file diff --git a/src/mt/ListaCargada.java b/src/mt/TablaData.java similarity index 81% rename from src/mt/ListaCargada.java rename to src/mt/TablaData.java index f3e8377..c27cfa9 100644 --- a/src/mt/ListaCargada.java +++ b/src/mt/TablaData.java @@ -2,17 +2,17 @@ package mt; import javafx.beans.property.SimpleStringProperty; -public class ListaCargada { +public class TablaData { private final SimpleStringProperty primer; private final SimpleStringProperty segundo; - public ListaCargada(SimpleStringProperty primer, SimpleStringProperty segundo) { + public TablaData(SimpleStringProperty primer, SimpleStringProperty segundo) { this.primer = primer; this.segundo = segundo; } - public ListaCargada(String primer, String segundo) { + public TablaData(String primer, String segundo) { this.primer = new SimpleStringProperty(primer); this.segundo = new SimpleStringProperty(segundo); } diff --git a/src/mt/lote.fxml b/src/mt/lote.fxml index d31091c..28ffd66 100644 --- a/src/mt/lote.fxml +++ b/src/mt/lote.fxml @@ -1,4 +1,5 @@ + - - - - + + + + + - + + + + + + + + Cadena: + +