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();
}
}
}

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.egreso.Egreso;
import danielcortes.xyz.models.egreso.EgresoDAO;
@@ -33,10 +34,7 @@ import danielcortes.xyz.views.EgresosView;
import danielcortes.xyz.views.components.EgresosTableModel;
import javax.swing.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.*;
/**
* Controlador el cual esta orientado a manejar la vista de EgresosView
@@ -123,21 +121,21 @@ public class EgresosController {
* - Cuando se selecciona una fila en la tabla se llama a updateButtonsEnabled
*/
private void setUpViewEvents() {
this.view.getNroField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getValorField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getDescripcionField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getTipoCombo().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "save");
this.view.getNroField().getActionMap().put("nextField", new NextAction(this.view.getDescripcionField()));
this.view.getDescripcionField().getActionMap().put("nextField", new NextAction(this.view.getValorField()));
this.view.getValorField().getActionMap().put("nextField", new NextAction(this.view.getTipoCombo()));
this.view.getTipoCombo().getActionMap().put("save", new GuardarAction(this));
this.view.getEgresosTable().getSelectionModel().addListSelectionListener(e -> updateButtonsEnabled());
this.view.getGuardarButton().addActionListener(e -> guardarActionListener());
this.view.getEliminarButton().addActionListener(e -> eliminarActionListener());
this.view.getEditarButton().addActionListener(e -> editarActionListener());
this.view.getDescripcionField().addActionListener(e -> guardarActionListener());
this.view.getNroField().addActionListener(e -> guardarActionListener());
this.view.getValorField().addActionListener(e -> guardarActionListener());
this.view.getTipoCombo().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
guardarActionListener();
}
}
});
this.view.getEgresosTable().addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent mouseEvent) {
JTable table = (JTable) mouseEvent.getSource();
@@ -430,4 +428,16 @@ public class EgresosController {
private void resetFocus() {
this.view.getNroField().requestFocus();
}
private class GuardarAction extends AbstractAction{
EgresosController controller;
GuardarAction(EgresosController controller){
this.controller = controller;
}
@Override
public void actionPerformed(ActionEvent e) {
this.controller.guardarActionListener();
}
}
}

View File

@@ -34,10 +34,7 @@ import danielcortes.xyz.views.components.IngresosTableModel;
import org.jetbrains.annotations.Contract;
import javax.swing.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.*;
/**
* Controlador el cual esta orientado a manejar la vista de IngresosView
@@ -123,23 +120,21 @@ public class IngresosController {
* - Cuando se presiona el boton de editar o se hace doble click sobre una fila de la tabla se llama a editarActionListener
*/
private void setupViewEvents() {
this.view.getValorField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getNroInicialField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getNroFinalField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getTipoCombo().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "save");
this.view.getValorField().getActionMap().put("nextField", new NextAction(this.view.getNroInicialField()));
this.view.getNroInicialField().getActionMap().put("nextField", new NextAction(this.view.getNroFinalField()));
this.view.getNroFinalField().getActionMap().put("nextField", new NextAction(this.view.getTipoCombo()));
this.view.getTipoCombo().getActionMap().put("save", new GuardarAction(this));
this.view.getIngresosTable().getSelectionModel().addListSelectionListener(e -> updateButtonsEnabled());
this.view.getGuardarButton().addActionListener(e -> guardarActionListener());
this.view.getValorField().addActionListener(e -> guardarActionListener());
this.view.getNroInicialField().addActionListener(e -> guardarActionListener());
this.view.getNroFinalField().addActionListener(e -> guardarActionListener());
this.view.getEliminarButton().addActionListener(e -> eliminarActionListener());
this.view.getEditarButton().addActionListener(e -> editarActionListener());
this.view.getTipoCombo().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_ENTER){
guardarActionListener();
}
}
});
this.view.getIngresosTable().addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent mouseEvent) {
JTable table = (JTable) mouseEvent.getSource();
@@ -431,6 +426,31 @@ public class IngresosController {
* Le pide focus al tipo combo
*/
private void resetFocus(){
this.view.getTipoCombo().requestFocus();
this.view.getValorField().requestFocus();
}
private class NextAction extends AbstractAction{
JComponent next;
NextAction(JComponent next){
this.next = next;
}
@Override
public void actionPerformed(ActionEvent e) {
this.next.requestFocus();
}
}
private class GuardarAction extends AbstractAction{
IngresosController controller;
GuardarAction(IngresosController controller){
this.controller = controller;
}
@Override
public void actionPerformed(ActionEvent e) {
this.controller.guardarActionListener();
}
}
}

View File

@@ -0,0 +1,41 @@
/*
* MIT License
*
* Copyright (c) 2018 Daniel Cortes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package danielcortes.xyz.controllers.actions;
import javax.swing.*;
import java.awt.event.ActionEvent;
public class NextAction extends AbstractAction {
private JComponent next;
public NextAction(JComponent next){
this.next = next;
}
@Override
public void actionPerformed(ActionEvent e) {
this.next.requestFocus();
}
}