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

@@ -99,6 +99,7 @@ public class Main {
JFrame frame = new JFrame("Caja");
frame.setContentPane(view.getContentPanel());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.setSize(780, 450);
frame.pack();
frame.setLocationRelativeTo(null);

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

View File

@@ -16,17 +16,17 @@
<border type="none"/>
<children/>
</grid>
<grid id="b2933" binding="controlsPanel" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="b2933" binding="controlsPanel" layout-manager="GridLayoutManager" row-count="1" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="a853b" class="javax.swing.JToggleButton" binding="egresosButton">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="200" height="-1"/>
</grid>
</constraints>
@@ -36,7 +36,7 @@
</component>
<component id="a494c" class="javax.swing.JToggleButton" binding="ingresosButton">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="200" height="-1"/>
</grid>
</constraints>
@@ -46,7 +46,7 @@
</component>
<component id="d23e2" class="javax.swing.JToggleButton" binding="arqueoButton">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<grid row="0" column="4" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="200" height="-1"/>
</grid>
</constraints>
@@ -60,6 +60,11 @@
</constraints>
<properties/>
</component>
<hspacer id="350b6">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
</children>

View File

@@ -27,6 +27,7 @@ package danielcortes.xyz.views;
import com.github.lgooddatepicker.components.DatePicker;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import javax.swing.*;
import java.awt.*;
@@ -85,25 +86,27 @@ public class ManagerView {
cardPanel.setLayout(new CardLayout(0, 0));
contentPanel.add(cardPanel, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
controlsPanel = new JPanel();
controlsPanel.setLayout(new GridLayoutManager(1, 4, new Insets(0, 0, 0, 0), -1, -1));
contentPanel.add(controlsPanel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
controlsPanel.setLayout(new GridLayoutManager(1, 5, new Insets(0, 0, 0, 0), -1, -1));
contentPanel.add(controlsPanel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_NORTH, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null, 0, false));
egresosButton = new JToggleButton();
egresosButton.setText("Egresos");
egresosButton.setMnemonic('E');
egresosButton.setDisplayedMnemonicIndex(0);
controlsPanel.add(egresosButton, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, new Dimension(200, -1), null, 0, false));
controlsPanel.add(egresosButton, new GridConstraints(0, 3, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, new Dimension(200, -1), null, 0, false));
ingresosButton = new JToggleButton();
ingresosButton.setText("Ingresos");
ingresosButton.setMnemonic('I');
ingresosButton.setDisplayedMnemonicIndex(0);
controlsPanel.add(ingresosButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, new Dimension(200, -1), null, 0, false));
controlsPanel.add(ingresosButton, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, new Dimension(200, -1), null, 0, false));
arqueoButton = new JToggleButton();
arqueoButton.setText("Arqueo");
arqueoButton.setMnemonic('A');
arqueoButton.setDisplayedMnemonicIndex(0);
controlsPanel.add(arqueoButton, new GridConstraints(0, 3, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, new Dimension(200, -1), null, 0, false));
controlsPanel.add(arqueoButton, new GridConstraints(0, 4, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, new Dimension(200, -1), null, 0, false));
datePicker = new DatePicker();
controlsPanel.add(datePicker, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
final Spacer spacer1 = new Spacer();
controlsPanel.add(spacer1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
ButtonGroup buttonGroup;
buttonGroup = new ButtonGroup();
buttonGroup.add(egresosButton);
@@ -117,4 +120,5 @@ public class ManagerView {
public JComponent $$$getRootComponent$$$() {
return contentPanel;
}
}