Ahora todos los fields de las vistas vistas se mueven de la misma manera

This commit is contained in:
Daniel Cortes
2019-02-16 14:49:40 -03:00
parent c2ff258cef
commit e65ac2bc10
7 changed files with 53 additions and 95 deletions

Binary file not shown.

View File

@@ -24,7 +24,6 @@
package danielcortes.xyz.controllers;
import danielcortes.xyz.controllers.actions.MoveToAction;
import danielcortes.xyz.data.DAOManager;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.documentos.Documentos;
@@ -41,7 +40,7 @@ import java.awt.event.ActionEvent;
* Controlador destinado a la vista ArqueoView
* Maneja su contenido y las acciones que esta realiza.
*/
public class ArqueoController {
public class ArqueoController extends BaseController{
private ArqueoView view;
private Caja caja;
private Efectivo efectivo;
@@ -164,45 +163,22 @@ public class ArqueoController {
* Setea los eventos de los fields de la vista
*/
private void setUpViewEvents() {
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 MoveToAction(this.view.getDiezMilField()));
this.view.getDiezMilField().getActionMap().put("nextField", new MoveToAction(this.view.getCincoMilField()));
this.view.getCincoMilField().getActionMap().put("nextField", new MoveToAction(this.view.getDosMilField()));
this.view.getDosMilField().getActionMap().put("nextField", new MoveToAction(this.view.getMilField()));
this.view.getMilField().getActionMap().put("nextField", new MoveToAction(this.view.getQuinientosField()));
this.view.getQuinientosField().getActionMap().put("nextField", new MoveToAction(this.view.getCienField()));
this.view.getCienField().getActionMap().put("nextField", new MoveToAction(this.view.getCincuentaField()));
this.view.getCincuentaField().getActionMap().put("nextField", new MoveToAction(this.view.getDiezField()));
this.view.getDiezField().getActionMap().put("save", new GuardarEfectivoAction());
this.view.getChequesField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getTarjetasField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getRetiroField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "save");
this.view.getChequesField().getActionMap().put("nextField", new MoveToAction(this.view.getTarjetasField()));
this.view.getTarjetasField().getActionMap().put("nextField", new MoveToAction(this.view.getRetiroField()));
this.view.getRetiroField().getActionMap().put("save", new GuardarDocumentosAction());
this.view.getGuardarEfectivoButton().addActionListener(e -> {
this.guardarEfectivoActionListener();
});
this.view.getGuardarDocumentosButton().addActionListener(e -> {
this.guardarEfectivoActionListener();
});
this.view.getCalcularFondoButton().addActionListener(e -> {
this.calcularFondoActionListener();
});
moveTo(this.view.getVeinteMilField(), this.view.getDiezMilField());
moveTo(this.view.getDiezMilField(), this.view.getCincoMilField());
moveTo(this.view.getCincoMilField(), this.view.getDosMilField());
moveTo(this.view.getDosMilField(), this.view.getMilField());
moveTo(this.view.getMilField(), this.view.getQuinientosField());
moveTo(this.view.getQuinientosField(), this.view.getCienField());
moveTo(this.view.getCienField(), this.view.getCincuentaField());
moveTo(this.view.getCincuentaField(), this.view.getDiezField());
doAction(this.view.getDiezField(), "save", KeyStroke.getKeyStroke("ENTER"), e -> this.guardarEfectivoActionListener());
moveTo(this.view.getChequesField(), this.view.getTarjetasField());
moveTo(this.view.getTarjetasField(), this.view.getRetiroField());
doAction(this.view.getRetiroField(), "save", KeyStroke.getKeyStroke("ENTER"), e -> this.guardarDocumentosActionListener());
this.view.getGuardarEfectivoButton().addActionListener(e -> this.guardarEfectivoActionListener());
this.view.getGuardarDocumentosButton().addActionListener(e -> this.guardarEfectivoActionListener());
this.view.getCalcularFondoButton().addActionListener(e -> this.calcularFondoActionListener());
}
/**

View File

@@ -0,0 +1,20 @@
package danielcortes.xyz.controllers;
import danielcortes.xyz.controllers.actions.BasicAction;
import javax.swing.*;
class BaseController {
static void moveTo(JComponent origin, JComponent destiny) {
KeyStroke next = KeyStroke.getKeyStroke("ENTER");
KeyStroke back = KeyStroke.getKeyStroke("ESCAPE");
origin.getInputMap(JComponent.WHEN_FOCUSED).put(next, "nextField");
destiny.getInputMap(JComponent.WHEN_FOCUSED).put(back, "previousField");
origin.getActionMap().put("nextField", (BasicAction) e -> destiny.requestFocus());
destiny.getActionMap().put("previousField", (BasicAction) e -> origin.requestFocus());
}
static void doAction(JComponent target, String name, KeyStroke keyStroke, BasicAction action){
target.getInputMap(JComponent.WHEN_FOCUSED).put(keyStroke, name);
target.getActionMap().put(name, action);
}
}

View File

@@ -1,6 +1,5 @@
package danielcortes.xyz.controllers;
import danielcortes.xyz.controllers.actions.MoveToAction;
import danielcortes.xyz.data.Configuration;
import danielcortes.xyz.data.DAOManager;
import danielcortes.xyz.models.caja.Caja;
@@ -13,7 +12,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class CalcularFondoController {
public class CalcularFondoController extends BaseController{
private JComponent parent;
private CalcularFondoView view;
private Caja caja;
@@ -52,20 +51,14 @@ public class CalcularFondoController {
}
private void setupViewEvents() {
this.view.getValorField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getDescripcionField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "save");
this.view.getFondoField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "updateResumen");
this.view.getValorField().getActionMap().put("nextField", new MoveToAction(this.view.getDescripcionField()));
this.view.getDescripcionField().getActionMap().put("save", new GuardarAction());
this.view.getFondoField().getActionMap().put("updateResumen", new UpdateResumenAction());
moveTo(this.view.getValorField(), this.view.getDescripcionField());
doAction(this.view.getDescripcionField(), "save", KeyStroke.getKeyStroke("ENTER"), e -> this.guardarActionListener());
doAction(this.view.getFondoField(), "updateResumen", KeyStroke.getKeyStroke("ENTER"), e -> this.updateResumen());
this.view.getTable().getSelectionModel().addListSelectionListener(e -> updateButtonsEnabled());
this.view.getGuardarButton().addActionListener(e -> guardarActionListener());
this.view.getEditarButton().addActionListener(e -> editarActionListener());
this.view.getEliminarButton().addActionListener(e -> eliminarActionListener());
this.view.getTable().addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent mouseEvent) {
JTable table = (JTable) mouseEvent.getSource();
@@ -174,13 +167,6 @@ public class CalcularFondoController {
this.view.getValorField().requestFocus();
}
private class GuardarAction extends AbstractAction {
@Override
public void actionPerformed(ActionEvent e) {
CalcularFondoController.this.guardarActionListener();
}
}
private class UpdateResumenAction extends AbstractAction {
@Override
public void actionPerformed(ActionEvent e) {

View File

@@ -24,7 +24,6 @@
package danielcortes.xyz.controllers;
import danielcortes.xyz.controllers.actions.MoveToAction;
import danielcortes.xyz.data.DAOManager;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.egreso.Egreso;
@@ -42,7 +41,7 @@ import java.awt.event.MouseEvent;
* Controlador el cual esta orientado a manejar la vista de EgresosView
* Maneja su contenido y las acciones que esta realiza
*/
public class EgresosController {
public class EgresosController extends BaseController{
private EgresosView view;
private Caja caja;
@@ -103,15 +102,10 @@ 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 MoveToAction(this.view.getDescripcionField()));
this.view.getDescripcionField().getActionMap().put("nextField", new MoveToAction(this.view.getValorField()));
this.view.getValorField().getActionMap().put("nextField", new MoveToAction(this.view.getTipoCombo()));
this.view.getTipoCombo().getActionMap().put("save", new GuardarAction(this));
moveTo(this.view.getNroField(), this.view.getDescripcionField());
moveTo(this.view.getDescripcionField(), this.view.getValorField());
moveTo(this.view.getValorField(), this.view.getTipoCombo());
doAction(this.view.getTipoCombo(), "save", KeyStroke.getKeyStroke("ENTER"), e -> this.guardarActionListener());
this.view.getEgresosTable().getSelectionModel().addListSelectionListener(e -> updateButtonsEnabled());
this.view.getGuardarButton().addActionListener(e -> guardarActionListener());

View File

@@ -1,6 +1,5 @@
package danielcortes.xyz.controllers;
import danielcortes.xyz.controllers.actions.BasicAction;
import danielcortes.xyz.data.DAOManager;
import danielcortes.xyz.models.estado_resultado.EstadoResultado;
import danielcortes.xyz.models.estado_resultado.EstadoResultadoDAO;
@@ -8,10 +7,9 @@ import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
import danielcortes.xyz.views.EstadoResultadoView;
import danielcortes.xyz.views.listeners.FocusLostListener;
import javax.swing.*;
import java.time.YearMonth;
public class EstadoResultadoController {
public class EstadoResultadoController extends BaseController{
private EstadoResultadoView view;
private EstadoResultado estadoResultado;
private YearMonth mes;
@@ -74,15 +72,6 @@ public class EstadoResultadoController {
moveTo(this.view.getResumenPPM(), this.view.getResumenIVAFavor());
}
private static void moveTo(JComponent origin, JComponent destiny) {
KeyStroke next = KeyStroke.getKeyStroke("ENTER");
KeyStroke back = KeyStroke.getKeyStroke("ESCAPE");
origin.getInputMap(JComponent.WHEN_FOCUSED).put(next, "nextField");
destiny.getInputMap(JComponent.WHEN_FOCUSED).put(back, "previousField");
origin.getActionMap().put("nextField", (BasicAction) e -> destiny.requestFocus());
destiny.getActionMap().put("previousField", (BasicAction) e -> origin.requestFocus());
}
private void guardarListener() {
EstadoResultadoDAO dao = DAOManager.getEstadoResultadoDAO();
dao.updateEstadoResultado(this.estadoResultado);

View File

@@ -41,7 +41,7 @@ import java.awt.event.MouseEvent;
* Controlador el cual esta orientado a manejar la vista de IngresosView
* Maneja su contenido y las acciones que esta realiza
*/
public class IngresosController {
public class IngresosController extends BaseController{
private IngresosView view;
private Caja caja;
@@ -103,19 +103,12 @@ 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.getNroZInicialField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getNroZFinalField().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.getNroZInicialField()));
this.view.getNroZInicialField().getActionMap().put("nextField", new NextAction(this.view.getNroZFinalField()));
this.view.getNroZFinalField().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));
moveTo(this.view.getValorField(), this.view.getNroZInicialField());
moveTo(this.view.getNroZInicialField(), this.view.getNroZFinalField());
moveTo(this.view.getNroZFinalField(), this.view.getNroInicialField());
moveTo(this.view.getNroInicialField(), this.view.getNroFinalField());
moveTo(this.view.getNroFinalField(), this.view.getTipoCombo());
doAction(this.view.getTipoCombo(), "save", KeyStroke.getKeyStroke("ENTER"), e ->this.guardarActionListener());
this.view.getIngresosTable().getSelectionModel().addListSelectionListener(e -> updateButtonsEnabled());
this.view.getGuardarButton().addActionListener(e -> guardarActionListener());