diff --git a/dist/local-release/Programa Caja.jar b/dist/local-release/Programa Caja.jar index 29efce8..a149cd3 100644 Binary files a/dist/local-release/Programa Caja.jar and b/dist/local-release/Programa Caja.jar differ diff --git a/src/danielcortes/xyz/controllers/ArqueoController.java b/src/danielcortes/xyz/controllers/ArqueoController.java index 880acd9..a28a1f9 100644 --- a/src/danielcortes/xyz/controllers/ArqueoController.java +++ b/src/danielcortes/xyz/controllers/ArqueoController.java @@ -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()); } /** diff --git a/src/danielcortes/xyz/controllers/BaseController.java b/src/danielcortes/xyz/controllers/BaseController.java new file mode 100644 index 0000000..b520e7d --- /dev/null +++ b/src/danielcortes/xyz/controllers/BaseController.java @@ -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); + } +} diff --git a/src/danielcortes/xyz/controllers/CalcularFondoController.java b/src/danielcortes/xyz/controllers/CalcularFondoController.java index c80b323..36e2e35 100644 --- a/src/danielcortes/xyz/controllers/CalcularFondoController.java +++ b/src/danielcortes/xyz/controllers/CalcularFondoController.java @@ -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) { diff --git a/src/danielcortes/xyz/controllers/EgresosController.java b/src/danielcortes/xyz/controllers/EgresosController.java index acbfe76..7a1757c 100644 --- a/src/danielcortes/xyz/controllers/EgresosController.java +++ b/src/danielcortes/xyz/controllers/EgresosController.java @@ -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()); diff --git a/src/danielcortes/xyz/controllers/EstadoResultadoController.java b/src/danielcortes/xyz/controllers/EstadoResultadoController.java index 8a0529f..d47f8cd 100644 --- a/src/danielcortes/xyz/controllers/EstadoResultadoController.java +++ b/src/danielcortes/xyz/controllers/EstadoResultadoController.java @@ -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); diff --git a/src/danielcortes/xyz/controllers/IngresosController.java b/src/danielcortes/xyz/controllers/IngresosController.java index 0a7b24e..9468741 100644 --- a/src/danielcortes/xyz/controllers/IngresosController.java +++ b/src/danielcortes/xyz/controllers/IngresosController.java @@ -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());