Mas documentacion y cambiados la mayoria de los action listeners por keybindings

This commit is contained in:
Daniel Cortes
2019-01-03 00:25:54 -03:00
parent 070a12b54e
commit c5da56117c
9 changed files with 588 additions and 356 deletions

View File

@@ -24,6 +24,7 @@
package danielcortes.xyz.controllers;
import danielcortes.xyz.controllers.actions.NextAction;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.documentos.Documentos;
import danielcortes.xyz.models.documentos.DocumentosDAO;
@@ -35,6 +36,7 @@ import danielcortes.xyz.views.ArqueoView;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
/**
* Controlador destinado a la vista ArqueoView
@@ -191,19 +193,58 @@ public class ArqueoController {
}
/**
* Setea los eventos de los botones de guardar
* Setea los eventos de los fields de la vista
*/
private void setUpViewEvents() {
this.view.getGuardarEfectivoButton().addActionListener(e -> {
this.normalizeEfectivoInput();
this.hiddeEfectivoErrorMessages();
this.guardarEfectivo();
});
this.view.getGuardarDocumentosButton().addActionListener(e -> {
this.normalizeDocumentosInput();
this.hiddeDocumentosErrorMessages();
this.guardarDocumentos();
});
this.view.getVeinteMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getDiezMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getCincoMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getDosMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getQuinientosField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getCienField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getCincuentaField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getDiezField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"save");
this.view.getVeinteMilField().getActionMap().put("nextField", new NextAction(this.view.getDiezMilField()));
this.view.getDiezMilField().getActionMap().put("nextField", new NextAction(this.view.getCincoMilField()));
this.view.getCincoMilField().getActionMap().put("nextField", new NextAction(this.view.getDosMilField()));
this.view.getDosMilField().getActionMap().put("nextField", new NextAction(this.view.getMilField()));
this.view.getMilField().getActionMap().put("nextField", new NextAction(this.view.getQuinientosField()));
this.view.getQuinientosField().getActionMap().put("nextField", new NextAction(this.view.getCienField()));
this.view.getCienField().getActionMap().put("nextField", new NextAction(this.view.getCincuentaField()));
this.view.getCincuentaField().getActionMap().put("nextField", new NextAction(this.view.getDiezField()));
this.view.getDiezField().getActionMap().put("save", new GuardarEfectivoAction(this));
this.view.getChequesField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getTarjetasField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"save");
this.view.getChequesField().getActionMap().put("nextField", new NextAction(this.view.getTarjetasField()));
this.view.getTarjetasField().getActionMap().put("save", new GuardarDocumentosAction(this));
this.view.getGuardarEfectivoButton().addActionListener(e -> guardarEfectivoActionListener());
this.view.getGuardarDocumentosButton().addActionListener(e -> guardarDocumentosActionListener());
}
/**
* Llama a los metodos necesarios para guardar los campos de efectivo
* Primero llama a normalizar el input, luego a esconder los mensajes de error, para finalmente llamar a guardar el efectivo
*/
private void guardarEfectivoActionListener(){
this.normalizeEfectivoInput();
this.hiddeEfectivoErrorMessages();
this.guardarEfectivo();
}
/**
* Llama a los metodos necesarios para guardar los documentos
* Primero llama a normalizar el input, luego a esconder los mensajes de error y finalmente a guardar los documentos
*/
private void guardarDocumentosActionListener(){
this.normalizeDocumentosInput();
this.hiddeDocumentosErrorMessages();
this.guardarDocumentos();
}
/**
@@ -408,4 +449,28 @@ public class ArqueoController {
this.view.getTarjetasField().setText(this.view.getTarjetasField().getText().trim());
}
private class GuardarEfectivoAction extends AbstractAction{
ArqueoController controller;
GuardarEfectivoAction(ArqueoController controller){
this.controller = controller;
}
@Override
public void actionPerformed(ActionEvent e) {
this.controller.guardarEfectivoActionListener();
}
}
private class GuardarDocumentosAction extends AbstractAction{
ArqueoController controller;
GuardarDocumentosAction(ArqueoController controller){
this.controller = controller;
}
@Override
public void actionPerformed(ActionEvent e) {
this.controller.guardarDocumentosActionListener();
}
}
}