From c759f93fea0b4669c790a959f585d2fae7f8bc6c Mon Sep 17 00:00:00 2001 From: Guillermo Date: Thu, 21 Nov 2019 23:47:41 +0100 Subject: [PATCH] Aniadido soporte cambio de nombre --- bin/.gitignore | 6 +- bin/Logica/Gestion.class | Bin 2732 -> 3126 bytes bin/Logica/Transaccion.class | Bin 1836 -> 1922 bytes src/Logica/Gestion.java | 13 +++ src/Logica/Transaccion.java | 4 + src/VistaControlador/BarraOpciones.java | 9 ++ .../ControladorAniadirVisualizar.java | 12 +-- src/VistaControlador/ControladorBarra.java | 12 +++ ...eral.java => ControladorPanelGestion.java} | 23 +---- .../ControladorPanelModificar.java | 41 ++++++++ src/VistaControlador/Menu.java | 90 +++++++++++++++--- src/VistaControlador/MostrarTodo.java | 1 + .../VistaAniadirVisualizar.java | 32 +++++-- src/VistaControlador/VistaPanel.java | 7 ++ ...nelLateral.java => VistaPanelGestion.java} | 27 ++---- src/VistaControlador/VistaPanelModificar.java | 57 +++++++++++ 16 files changed, 267 insertions(+), 67 deletions(-) rename src/VistaControlador/{ControladorPanelLateral.java => ControladorPanelGestion.java} (78%) create mode 100644 src/VistaControlador/ControladorPanelModificar.java create mode 100644 src/VistaControlador/VistaPanel.java rename src/VistaControlador/{VistaPanelLateral.java => VistaPanelGestion.java} (73%) create mode 100644 src/VistaControlador/VistaPanelModificar.java diff --git a/bin/.gitignore b/bin/.gitignore index 86d6556..b9067c1 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,3 +1,5 @@ -/Logica/ -/VistaControlador/ +/Fichero/ /Ficheros/ +/Logica/ +/Main.class +/VistaControlador/ diff --git a/bin/Logica/Gestion.class b/bin/Logica/Gestion.class index b87231c154489904b81a6e4dc91f4320a290b24c..c8df8496abf6de9b9a1ba04f24176f83fa4129fa 100644 GIT binary patch delta 1555 zcmZvc-BTM?7{;HI>}E+=C`2Fyh7zzX5J*!=T4+;iwbF`0TKfT|el$zEU=R|!1WH>a z{j%Ej^4wUx@k(wwV-Xs^W*l$4>5Lb0>v-p#<6q#6_1Rs%>M%RAIq!SUd(Q8D&a-(~ zTiPCY^6w8n0Z8E9V&I8r^-r6HRDNpIG6ibe2PTYJBQ|N|#$%@oRyH@D>==?OBI?_# z;{|j})e{aUuwTPIf#5)XJex6MXDlN(ZDcapd`?FXdS##Imp}m9aa6~v=#yRE-NobR z*YFx^oc(7C*~wUc!L*D*-qP_p-Vji7=3GIbroCem!->%eGgC+gNIR$_g@`~|A@7m} za1y69yeUxie`p=2(JkOJFU=T}(?n^&Ssg=8&N8R+vt~Jtz#avN|U4 zzU)=PWeH5_$Ppl|GzKmSK*O{^NLH#Ls&^7II%aWMex>XSTDYPkh^_!ET+{I(K9YYc z$!$de5w>$T?A%S+qqdY;xNQd?%e30!wJ<1es~3bW|5R7{4#UF-@I^Wwqh*mJ4|ee# zaI!n0GTP0!&RvBzv@_y*RG}I?3sLNmU;9GkvEj(bGMYL|h|Ax6&rQTfAES8zRd%-7 z&W|kqPu^)T5c??b1iwNx$MK=yo#EnCf>xU+BfO7&#Rx0pBb&e0wTPba) zI3yowwcZyQ-DlKiM-_+h60!YU?ZFYbqP2>YoiDzOE>_ks|0QP>{w5;JXe{BC)B;+g z-{Y9T&qxe*l`uf^6Aw^f&oewTyvXTcfzO}*zR^nqA z_H2J#tKtDq6z3F0emJ+VrA5=g|JKiMHtArV)aHR$8?U8QyA|!jCz)5l52v8ZO(&IJ7($ z7di5$6G6XU{IP9k+l}TWlcb{h{J&y}PPmi+X$K z4c+#mf_#_R`W)rDLeE~sFP{>$t(^Gu*@%xP@ly-I=@5VTgtj}PWDhTE&-z*ardkpSS{QIR$Q!yhvORs6 zw`|^2Bq!af+g>Sqe*0iKUvkUElEWZJ^jsvJ>te{^C>ce(TpTHvyy=Mq$2e~Dj-oz1 z>ATYt?JFsV6LctI`I(CA&zk#AI-CkarTkQ}ny=+BV-D|<)4xYj`ip2LcGlrTT>WD- zJ>124hjDU($@LAC(x^Av@4E*oo2y} z(IH8Hf&w!RC1&+ZP2cK@R7;!K$0qiPzE`uUuE1sEe5zQ#^R&KSvp!N_NXKJmRYDhH zzv$2H`r5X!Ozsw`Y(S^JX|J8^Joh~t7pXVVjV5|Q{3TH)!Zukq2v%ri6&aeyl46%w zZSw7AA02F$Y!jBOee7VT?8e$lFN#;hj$*YrV($|bH^jH9UVSaz80i!5jCco(SNAIW zrNS!t+u}9-b$qirV&e0!(=R6*Bz{9OQQ3Pkw|FVw!0;lQ+wO8mai6ZEy8_-8Qj45z@>mIL)mYosufP_3!#En WWW7o!bGqJXUVSx`P%#(&HU9_11?*=4 diff --git a/bin/Logica/Transaccion.class b/bin/Logica/Transaccion.class index a546cc519111c448efa6adc7261092c51695ed47..5a3811a76e844526514e5e7806763722e16f3181 100644 GIT binary patch delta 120 zcmZ3(*Tm0t>ff$?3=9k=4B;EOo-wnt7pIo^CFV|k%bdo@wK;_4GE<-#10#b3P>CG_ z6A&^muxV*;WsunjWHB+Q0ZA^fXd(kELlT2JkS_*N#h}5U3FHCQGw?9*0?lA#2nF(( G7{UN8N)j#r delta 36 scmZqTU&F_B>ff$?3=9k=3}G9&o-t4U#hlE@xjByIG7~EU0~13i0PSB32LJ#7 diff --git a/src/Logica/Gestion.java b/src/Logica/Gestion.java index 7583430..20f0f5b 100644 --- a/src/Logica/Gestion.java +++ b/src/Logica/Gestion.java @@ -32,6 +32,10 @@ public class Gestion implements Serializable{ return this.nombre; } + public void setNombre(String nombre) { + this.nombre = nombre; + } + /** * Aniade una transaccion a la gestion * @@ -88,6 +92,15 @@ public class Gestion implements Serializable{ } } + public void editarTransaccion(String nombreViejo, String nombreNuevo) { + for(Transaccion elemento:this.gestiones) { + if(elemento.getNombre().equals(nombreViejo)) { + elemento.setName(nombreNuevo); + return; + } + } + } + /** * Devuelve verdadero si es un ingerso y falso si es un gasto * diff --git a/src/Logica/Transaccion.java b/src/Logica/Transaccion.java index fd69dea..7c4e483 100644 --- a/src/Logica/Transaccion.java +++ b/src/Logica/Transaccion.java @@ -92,4 +92,8 @@ public class Transaccion implements Serializable{ public String getNombre() { return this.nombre; } + + public void setName(String nombre) { + this.nombre = nombre; + } } diff --git a/src/VistaControlador/BarraOpciones.java b/src/VistaControlador/BarraOpciones.java index 9dad4bd..c0ecc76 100644 --- a/src/VistaControlador/BarraOpciones.java +++ b/src/VistaControlador/BarraOpciones.java @@ -18,6 +18,9 @@ public class BarraOpciones extends JMenuBar{ JMenuItem modoClaro; JMenu mostrar; JMenuItem mostrarTodo; + JMenu vistas; + JMenuItem gestion; + JMenuItem modificacion; /** * Inicializa labarra con los datos por defecto @@ -45,5 +48,11 @@ public class BarraOpciones extends JMenuBar{ this.mostrarTodo = new JMenuItem("Mostrar todo"); this.mostrar.add(this.mostrarTodo); this.add(this.mostrar); + this.vistas = new JMenu("Vista"); + this.add(this.vistas); + this.gestion = new JMenuItem("Gestion"); + this.vistas.add(this.gestion); + this.modificacion = new JMenuItem("Modificacion"); + this.vistas.add(this.modificacion); } } diff --git a/src/VistaControlador/ControladorAniadirVisualizar.java b/src/VistaControlador/ControladorAniadirVisualizar.java index 7a3a7ea..f1035a0 100644 --- a/src/VistaControlador/ControladorAniadirVisualizar.java +++ b/src/VistaControlador/ControladorAniadirVisualizar.java @@ -35,9 +35,9 @@ public class ControladorAniadirVisualizar implements ActionListener{ try { this.vista.aniadirElemento(nombre, Float.parseFloat(dinero),this); - this.vista.menu.panel.actualizarDatos(this.vista.gestiones); - this.vista.menu.panel.revalidate(); - this.vista.menu.panel.repaint(); + this.vista.menu.panelGestion.actualizarDatos(this.vista.gestiones); + this.vista.menu.panelGestion.revalidate(); + this.vista.menu.panelGestion.repaint(); }catch (NumberFormatException ex) { JOptionPane.showMessageDialog(null, "Debe introducir un numero", "error", JOptionPane.WARNING_MESSAGE); } @@ -48,9 +48,9 @@ public class ControladorAniadirVisualizar implements ActionListener{ for(int i = 0; i < vista.gestiones.getElementos().size();i++) { if(vista.gestiones.getElementos().get(i).toString().equals(pulsado.getText())) { vista.gestiones.alterarVisibilidad(i); - this.vista.menu.panel.actualizarDatos(this.vista.gestiones); - this.vista.menu.panel.revalidate(); - this.vista.menu.panel.repaint(); + this.vista.menu.panelGestion.actualizarDatos(this.vista.gestiones); + this.vista.menu.panelGestion.revalidate(); + this.vista.menu.panelGestion.repaint(); } } } diff --git a/src/VistaControlador/ControladorBarra.java b/src/VistaControlador/ControladorBarra.java index c085346..5d3061f 100644 --- a/src/VistaControlador/ControladorBarra.java +++ b/src/VistaControlador/ControladorBarra.java @@ -81,6 +81,14 @@ public class ControladorBarra implements ActionListener{ this.menu.cargarPestanias(); break; } + case "Cambiar Gestion":{ + this.menu.cambiarVista(this.menu.VISTA_GESTION); + break; + } + case "Cambiar Modificar":{ + this.menu.cambiarVista(this.menu.VISTA_MODIFICAR); + } + } } @@ -105,6 +113,10 @@ public class ControladorBarra implements ActionListener{ this.barra.modoOscuro.setActionCommand("Modo oscuro"); this.barra.mostrarTodo.addActionListener(this); this.barra.mostrarTodo.setActionCommand("Mostrar todo"); + this.barra.gestion.addActionListener(this); + this.barra.gestion.setActionCommand("Cambiar Gestion"); + this.barra.modificacion.addActionListener(this); + this.barra.modificacion.setActionCommand("Cambiar Modificar"); } } diff --git a/src/VistaControlador/ControladorPanelLateral.java b/src/VistaControlador/ControladorPanelGestion.java similarity index 78% rename from src/VistaControlador/ControladorPanelLateral.java rename to src/VistaControlador/ControladorPanelGestion.java index 0be7ca9..23ca39f 100644 --- a/src/VistaControlador/ControladorPanelLateral.java +++ b/src/VistaControlador/ControladorPanelGestion.java @@ -23,10 +23,8 @@ import com.github.lgooddatepicker.zinternaltools.DemoPanel; import Logica.Gestion; import Logica.Transaccion; -public class ControladorPanelLateral implements ActionListener, DateChangeListener{ - private VistaPanelLateral vista; - private java.time.Month mes; - private int anio; +public class ControladorPanelGestion implements ActionListener{ + private VistaPanelGestion vista; private Menu menu; /** @@ -35,7 +33,7 @@ public class ControladorPanelLateral implements ActionListener, DateChangeListen * @param vista Vista que usa el controlador * @param menu Menu que contiene la vista que usa este controlador */ - public ControladorPanelLateral(VistaPanelLateral vista, Menu menu) { + public ControladorPanelGestion(VistaPanelGestion vista, Menu menu) { this.vista = vista; this.menu = menu; this.aniadirElementos(); @@ -102,23 +100,8 @@ public class ControladorPanelLateral implements ActionListener, DateChangeListen this.vista.mostrarEstadisticas.setActionCommand("Mostrar estadisticas"); this.vista.aniadirGestion.addActionListener(this); this.vista.aniadirGestion.setActionCommand("Aniadir una nueva gestion"); - if(VistaPanelLateral.elegirMes.getDateChangeListeners().size() == 0) { - VistaPanelLateral.elegirMes.addDateChangeListener(this); - this.mes=VistaPanelLateral.elegirMes.getDate().getMonth(); - this.anio=VistaPanelLateral.elegirMes.getDate().getYear(); - } this.vista.eliminarTransaccion.addActionListener(this); this.vista.eliminarTransaccion.setActionCommand("Eliminar Transacciones"); } - public void dateChanged(DateChangeEvent arg0) { - if(this.mes!=VistaPanelLateral.elegirMes.getDate().getMonth() || - this.anio!=VistaPanelLateral.elegirMes.getDate().getYear()) { - this.menu.cargarGestiones(VistaPanelLateral.elegirMes.getDate().getYear(), VistaPanelLateral.elegirMes.getDate().getMonth()); - this.mes=VistaPanelLateral.elegirMes.getDate().getMonth(); - this.anio=VistaPanelLateral.elegirMes.getDate().getYear(); - } - - } - } diff --git a/src/VistaControlador/ControladorPanelModificar.java b/src/VistaControlador/ControladorPanelModificar.java new file mode 100644 index 0000000..d7af8c3 --- /dev/null +++ b/src/VistaControlador/ControladorPanelModificar.java @@ -0,0 +1,41 @@ +package VistaControlador; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import Logica.Gestion; + +public class ControladorPanelModificar implements ActionListener{ + VistaPanelModificar vista; + Menu menu; + + ControladorPanelModificar(VistaPanelModificar vista, Menu menu) { + this.menu = menu; + this.vista = vista; + this.aniadirListeners(); + } + + private void aniadirListeners() { + this.vista.editarGestion.addActionListener(this); + this.vista.editarGestion.setActionCommand("Editar gestion"); + this.vista.editarTransaccion.addActionListener(this); + this.vista.editarTransaccion.setActionCommand("Editar transaccion"); + } + + @Override + public void actionPerformed(ActionEvent arg0) { + switch(arg0.getActionCommand()) { + case "Editar gestion":{ + this.menu.pestanias.get(this.menu.pestania.getSelectedIndex()).gestiones.setNombre(this.vista.nuevoEditar.getText()); + this.menu.cargarPestanias(); + break; + } + case "Editar transaccion":{ + this.menu.pestanias.get(this.menu.pestania.getSelectedIndex()).editarTransaccion(this.vista.viejoEditar.getText(), this.vista.nuevoEditar.getText()); + break; + } + } + + } + +} diff --git a/src/VistaControlador/Menu.java b/src/VistaControlador/Menu.java index c84081a..50a6910 100644 --- a/src/VistaControlador/Menu.java +++ b/src/VistaControlador/Menu.java @@ -19,25 +19,36 @@ import javax.swing.JTextArea; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import com.github.lgooddatepicker.components.DatePicker; +import com.github.lgooddatepicker.optionalusertools.DateChangeListener; + import Ficheros.Configuracion; import Logica.Gestion; import Logica.Meses; import Logica.Transaccion; public class Menu extends JFrame{ - protected JPanel panelCentral; - protected JTabbedPane pestania; - protected VistaAniadirVisualizar ingresos; - protected VistaAniadirVisualizar gastos; - protected VistaPanelLateral panel; + static final int VISTA_MODIFICAR = 0; + static final int VISTA_GESTION = 1; + + JPanel panelCentral; + JTabbedPane pestania; + VistaAniadirVisualizar ingresos; + VistaAniadirVisualizar gastos; + VistaPanelGestion panelGestion; + VistaPanelModificar panelModificar; + VistaPanel panel; String rutaGuardado; int tema; Meses meses; ArrayList pestanias; ArrayList controladores; BarraOpciones barra; - protected Gestion datosGastos; - protected Gestion datosIngresos; + Gestion datosGastos; + Gestion datosIngresos; + DatePicker elegirMes; + int anio; + Month mes; /** * Constructor que carga los datos del menu @@ -62,7 +73,9 @@ public class Menu extends JFrame{ this.cargarPestanias(); this.panelCentral = new JPanel(); this.panelCentral.setLayout(new GridBagLayout()); - this.panel = new VistaPanelLateral(this.meses); + this.panelGestion = new VistaPanelGestion(this.meses); + this.panelModificar = new VistaPanelModificar(); + this.panel = this.panelGestion; constrain.fill = GridBagConstraints.HORIZONTAL; constrain.gridx = 0; @@ -70,21 +83,41 @@ public class Menu extends JFrame{ constrain.gridy = 0; constrain.weightx = 0; this.panelCentral.add(this.barra,constrain); + constrain.fill = GridBagConstraints.HORIZONTAL; constrain.gridwidth = 1; constrain.gridx = 0; constrain.gridy = 1; + constrain.gridheight = 2; constrain.weightx = 0.25; this.panelCentral.add(pestania,constrain); setTitle("Titulo"); setSize(new Dimension(420,320)); setDefaultCloseOperation(3); setLocationRelativeTo(null); - ControladorPanelLateral controlador3 = new ControladorPanelLateral(this.panel, this); + ControladorPanelGestion controlador3 = new ControladorPanelGestion(this.panelGestion, this); + ControladorPanelModificar controlador4 = new ControladorPanelModificar(this.panelModificar, this); this.listenerPestania(); + + this.elegirMes = new DatePicker(); + this.elegirMes.setDate(LocalDate.now()); + this.elegirMes.addDateChangeListener((DateChangeListener)->{ + if(!this.elegirMes.getDate().getMonth().equals(this.mes) || !(this.elegirMes.getDate().getYear() == this.anio) ) { + this.mes = this.elegirMes.getDate().getMonth(); + this.anio = this.elegirMes.getDate().getYear(); + this.cargarGestiones(this.anio, this.mes); + } + }); constrain.fill = GridBagConstraints.HORIZONTAL; constrain.gridx = 1; constrain.gridy = 1; + constrain.gridheight = 1; + constrain.weightx = 0.25; + this.panelCentral.add(this.elegirMes, constrain); + + constrain.fill = GridBagConstraints.HORIZONTAL; + constrain.gridx = 1; + constrain.gridy = 2; constrain.weightx = 0.25; this.panelCentral.add(this.panel,constrain); this.add(this.panelCentral); @@ -204,7 +237,7 @@ public class Menu extends JFrame{ * @param sumaOResta tipo de gestion */ void aniadirGestion(String nombre, boolean sumaOResta) { - Gestion gestion=this.meses.aniadirGestion(nombre, VistaPanelLateral.getDate().getYear(), VistaPanelLateral.getDate().getMonth(), sumaOResta); + Gestion gestion=this.meses.aniadirGestion(nombre, this.anio, this.mes, sumaOResta); VistaAniadirVisualizar vista = new VistaAniadirVisualizar(this, gestion); this.pestanias.add(vista); this.controladores.add(new ControladorAniadirVisualizar(vista)); @@ -219,7 +252,7 @@ public class Menu extends JFrame{ this.pestania.addChangeListener((ChangeListener)->{ if(this.pestania.getTabCount()>0) { try { - this.panel.actualizarDatos(meses.getGestionesActuales().get(this.pestania.getSelectedIndex())); + this.panelGestion.actualizarDatos(meses.getGestionesActuales().get(this.pestania.getSelectedIndex())); }catch (Exception e) { // TODO: handle exception } @@ -272,7 +305,8 @@ public class Menu extends JFrame{ this.panelCentral.setBackground(Color.WHITE); this.panelCentral.repaint(); this.panelCentral.revalidate(); - this.panel.setBackground(Color.WHITE); + this.panelGestion.setBackground(Color.WHITE); + this.panelModificar.setBackground(Color.WHITE); this.panel.repaint(); this.panel.revalidate(); break; @@ -287,7 +321,8 @@ public class Menu extends JFrame{ this.panelCentral.setBackground(Color.PINK); this.panelCentral.repaint(); this.panelCentral.revalidate(); - this.panel.setBackground(Color.PINK); + this.panelGestion.setBackground(Color.PINK); + this.panelModificar.setBackground(Color.PINK); this.panel.repaint(); this.panel.revalidate(); break; @@ -302,7 +337,8 @@ public class Menu extends JFrame{ this.panelCentral.setBackground(Color.BLACK); this.panelCentral.repaint(); this.panelCentral.revalidate(); - this.panel.setBackground(Color.BLACK); + this.panelGestion.setBackground(Color.BLACK); + this.panelModificar.setBackground(Color.BLACK); this.panel.repaint(); this.panel.revalidate(); break; @@ -311,4 +347,30 @@ public class Menu extends JFrame{ } } + void cambiarVista(int vista) { + GridBagConstraints constrain = new GridBagConstraints(); + this.panelCentral.remove(this.panel); + constrain = new GridBagConstraints(); + constrain.fill = GridBagConstraints.HORIZONTAL; + constrain.gridx = 1; + constrain.gridy = 2; + constrain.weightx = 0.25; + switch(vista) { + case Menu.VISTA_GESTION:{ + this.panel = this.panelGestion; + break; + } + case Menu.VISTA_MODIFICAR:{ + this.panel = this.panelModificar; + break; + } + } + this.panelCentral.add(this.panel,constrain); + this.panel.repaint(); + this.panel.revalidate(); + this.panelCentral.repaint(); + this.panelCentral.revalidate(); + + } + } diff --git a/src/VistaControlador/MostrarTodo.java b/src/VistaControlador/MostrarTodo.java index b7fb62f..c114ae7 100644 --- a/src/VistaControlador/MostrarTodo.java +++ b/src/VistaControlador/MostrarTodo.java @@ -20,6 +20,7 @@ public class MostrarTodo extends JFrame{ public MostrarTodo(Meses meses) { super(); this.elementos=new JList(meses.salidaTodo()); + this.setSize(400, 400); this.add(elementos); } } diff --git a/src/VistaControlador/VistaAniadirVisualizar.java b/src/VistaControlador/VistaAniadirVisualizar.java index a2cec7d..ffff2f1 100644 --- a/src/VistaControlador/VistaAniadirVisualizar.java +++ b/src/VistaControlador/VistaAniadirVisualizar.java @@ -20,8 +20,8 @@ public class VistaAniadirVisualizar extends JPanel{ JPanel cuadro; JScrollPane panel; Menu menu; - private ControladorAniadirVisualizar controlador; - private static VistaPanelLateral panelLateral; + //private ControladorAniadirVisualizar controlador; + //private static VistaPanelGestion panelLateral; /** * Constructor de la ventana que contendra las pestanias @@ -51,9 +51,9 @@ public class VistaAniadirVisualizar extends JPanel{ * * @param panel panel lateral que gestionara este panel */ - public static void setPanelLateral(VistaPanelLateral panel) { + /*public static void setPanelLateral(VistaPanelGestion panel) { VistaAniadirVisualizar.panelLateral = panel; - } + }*/ public String getName() { return this.gestiones.getNombre(); @@ -76,7 +76,7 @@ public class VistaAniadirVisualizar extends JPanel{ * @param controlador controlador de la casilla que de aniadira */ public void aniadirElemento(String nombre, float dinero, ControladorAniadirVisualizar controlador) { - Transaccion transaccion = new Transaccion(nombre, dinero,panelLateral.getDate(),this.gestiones); + Transaccion transaccion = new Transaccion(nombre, dinero,this.menu.elegirMes.getDate(),this.gestiones); this.gestiones.aniadirGasto(transaccion); JCheckBox check = new JCheckBox(transaccion.toString()); check.setSelected(true); @@ -99,13 +99,33 @@ public class VistaAniadirVisualizar extends JPanel{ if(!check.isSelected()) { this.cuadro.remove(check); this.gestiones.eliminarTransaccion(check.getText()); - this.menu.panel.actualizarDatos(this.gestiones); + this.menu.panelGestion.actualizarDatos(this.gestiones); this.cuadro.revalidate(); this.cuadro.repaint(); } } } + void editarTransaccion(String nombreViejo, String nombreNuevo){ + for(Transaccion transaccion:this.gestiones.getElementos()) { + if(transaccion.getNombre().equals(nombreViejo)) { + for(JCheckBox check:this.transacciones) { + if(check.getText().equals(transaccion.toString())) { + transaccion.setName(nombreNuevo); + check.setText(transaccion.toString()); + check.revalidate(); + check.repaint(); + //this.gestiones.editarTransaccion(nombreViejo, nombreNuevo); + this.menu.panelGestion.actualizarDatos(this.gestiones); + this.cuadro.revalidate(); + this.cuadro.repaint(); + } + } + } + } + + } + /** * aniade una nueva transaccion */ diff --git a/src/VistaControlador/VistaPanel.java b/src/VistaControlador/VistaPanel.java new file mode 100644 index 0000000..f439d4c --- /dev/null +++ b/src/VistaControlador/VistaPanel.java @@ -0,0 +1,7 @@ +package VistaControlador; + +import javax.swing.JPanel; + +public class VistaPanel extends JPanel{ + +} diff --git a/src/VistaControlador/VistaPanelLateral.java b/src/VistaControlador/VistaPanelGestion.java similarity index 73% rename from src/VistaControlador/VistaPanelLateral.java rename to src/VistaControlador/VistaPanelGestion.java index 4000fb2..8423c5f 100644 --- a/src/VistaControlador/VistaPanelLateral.java +++ b/src/VistaControlador/VistaPanelGestion.java @@ -1,12 +1,10 @@ package VistaControlador; import java.awt.Dimension; -import java.awt.GridBagConstraints; import java.time.LocalDate; import java.util.Date; import javax.swing.JButton; -import javax.swing.JPanel; import javax.swing.JTextArea; import com.github.lgooddatepicker.components.DatePicker; @@ -14,10 +12,10 @@ import com.github.lgooddatepicker.components.DatePicker; import Logica.Gestion; import Logica.Meses; -public class VistaPanelLateral extends JPanel{ +public class VistaPanelGestion extends VistaPanel{ protected JTextArea total; protected JTextArea gastoEnvio; - protected static DatePicker elegirMes = inicializarCalendario(); + //protected static DatePicker elegirMes = inicializarCalendario(); protected JButton mostrarEstadisticas; JButton aniadirGestion; JButton eliminarTransaccion; @@ -27,7 +25,8 @@ public class VistaPanelLateral extends JPanel{ * * @param meses datos a gestionar */ - VistaPanelLateral(Meses meses){ + VistaPanelGestion(Meses meses){ + super(); this.setPreferredSize(new Dimension(200,200)); this.meses=meses; this.total = new JTextArea(String.valueOf(meses.getTotal())); @@ -35,7 +34,7 @@ public class VistaPanelLateral extends JPanel{ this.mostrarEstadisticas = new JButton("Mostrar grafico del mes"); this.aniadirGestion = new JButton("Aniadir nueva gestión"); this.add(this.mostrarEstadisticas); - this.add(VistaPanelLateral.elegirMes); + //this.add(VistaPanelGestion.elegirMes); this.add(this.total); this.add(this.gastoEnvio); this.add(this.aniadirGestion); @@ -56,19 +55,9 @@ public class VistaPanelLateral extends JPanel{ * * @return fecha en la que se encuentra */ - static LocalDate getDate() { - return elegirMes.getDate(); - } + /*static LocalDate getDate() { + //return elegirMes.getDate(); + }*/ - /** - * Inicializa el calendario - * - * @return calendario que inicializa - */ - static DatePicker inicializarCalendario() { - DatePicker ret = new DatePicker(); - ret.setDate(LocalDate.now()); - return ret; - } } diff --git a/src/VistaControlador/VistaPanelModificar.java b/src/VistaControlador/VistaPanelModificar.java new file mode 100644 index 0000000..4ff39a0 --- /dev/null +++ b/src/VistaControlador/VistaPanelModificar.java @@ -0,0 +1,57 @@ +package VistaControlador; + +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; + +import javax.swing.JButton; +import javax.swing.JTextField; + +public class VistaPanelModificar extends VistaPanel{ + JTextField viejoNombre; + JTextField nuevoNombre; + JTextField viejoEditar; + JTextField nuevoEditar; + JButton editarTransaccion; + JButton editarGestion; + VistaPanelModificar() { + GridBagConstraints constrain = new GridBagConstraints(); + this.setLayout(new GridBagLayout()); + + //this.add(VistaPanelGestion.elegirMes); + + this.viejoNombre = new JTextField("Nombre"); + this.viejoNombre.setEditable(false); + constrain.gridx = 0; + constrain.gridy = 0; + this.add(this.viejoNombre, constrain); + + this.nuevoNombre = new JTextField("Nombre nuevo"); + this.nuevoNombre.setEditable(false); + constrain.gridx = 0; + constrain.gridy = 1; + this.add(this.nuevoNombre, constrain); + + this.viejoEditar = new JTextField(); + this.viejoEditar.setPreferredSize(new Dimension(80, 17)); + constrain.gridx = 1; + constrain.gridy = 0; + this.add(this.viejoEditar, constrain); + + this.nuevoEditar = new JTextField(); + this.nuevoEditar.setPreferredSize(new Dimension(80, 17)); + constrain.gridx = 1; + constrain.gridy = 1; + this.add(this.nuevoEditar, constrain); + + this.editarGestion = new JButton("Gestion"); + constrain.gridx = 0; + constrain.gridy = 2; + this.add(this.editarGestion, constrain); + + this.editarTransaccion = new JButton("Transaccion"); + constrain.gridx = 1; + constrain.gridy = 2; + this.add(this.editarTransaccion, constrain); + } +}