From 86c642dba909bc414e193c4cf7f61448030d6393 Mon Sep 17 00:00:00 2001 From: Guillermo Date: Thu, 14 Nov 2019 21:58:58 +0100 Subject: [PATCH] Aniadido soporte para cambiar de mes --- bin/Logica/Gestion.class | Bin 1846 -> 1900 bytes src/Logica/Gestion.java | 3 +-- src/Logica/Meses.java | 2 ++ .../ControladorPanelLateral.java | 1 + src/VistaControlador/Menu.java | 23 +++++++++++------- .../VistaAniadirVisualizar.java | 21 ++++++++++++++++ 6 files changed, 39 insertions(+), 11 deletions(-) diff --git a/bin/Logica/Gestion.class b/bin/Logica/Gestion.class index c278cff00072708531ef9d1082cd90fc19f2caac..445f77a037de885ed2ed1013bb6f5c79b4a561a2 100644 GIT binary patch literal 1900 zcmZ`(+fEx-6kW#{Y|MmP4NhV(35C>`CTE0sk0|k=ZW1>t~%hp*b^AA>~>9a3CMcIR9r_{O&*W0)?3O_?i#aYb5$Zg zv>WCi1TGsGLPB7qtSoc8+pd|;j;ysjAiFMGRp}@_4;BYj1DMI6=5U_9Ts46{WDKM+ z5yQ2fup!|Rm_bJ8ecM1k26QxUU=Rr%y<=b;Z|Nv!U=(Ad={{A|X0)ef&@@)W{`~_0jC6FUlhW8z`|5Cf1^C zhE)z^(V}b`_!OT}mJr%O4~;6&opCcDPP1;(y%oFb)Xfd0eP#qry`>)+uCx1ne6D<} z+8~_8IEx_8KiY(GLL1gwGjPcphcV)fw2U{>L>%M%CNV*TNzUdu>QDdB?@0a1Ac8CW z)d@i0tKJGYOJgdy@-2yIDl_?)n9l!+ncbJTevH}t&@txng=5^vPaPxs8tf|JKrT_5 zcZ6J$wDT2m$uQChuK94tqre$~wcR}eGurN?B=9b72I-3&HM#!$5pMj#Aj~-B0UG{+ z08ro-^d(*H_e>SxxXjD5g%iB@MSk}PbBq>hn*9;7&oTBJQr-$Bd4b_zwjT)8=LwYY z^iNZwDFRRPn?aV$3#?`dvmT8}KhJ~*C-~$!KKEpOV>Kjjnk>)kc~bA6Ti2q$!1e`b`={+XkLKUHd=9PlMhlm`XL6ec zyTjJqrAHR9&Uag41Ha_|t*@x=0bBMRoAv{n_9L716ZO-U^;>&*+S)^uu|-jIYvYLi PgHmcS$@w6B1cAvkkHuPxKr$1v>r#| z13!T;NPOros6-^hqe&$yAwKh$kPv5f*X}k6k+OSd?##LOoO{-P|NFq)0AYc-Zy+u*fCyVH^a;(t7?0@vfA{Ub!)O&k)AT^a5JGFD+)5&l`xzXX>cfdC*+yV<^oxw zR0J$aChN*8%C@F7li4mxbP&0U;qZ=ycX5kMWxXzNF{(`9g0vX-^4x8*k>?Ig*SeRB*j+6}y6F}&ZjTehQJ zYSJSe83%RAceRLY|E~kbWmDUp^eU>Ys;a5#lI#=Ntw5Ab3->_^aTYeBY(-TLWig_B zVqpuPQkDqXVHb@m(2@go*f<@!Ma!1mj#slEC^L8~9O|O^vM^7R#QBZ#12vA~D#=w0 z1N^727^jS@{5=a7{P!?M{5PHDzv(r;lf0Y8MLs9E`j)5$_iFwHCi5?GY3~ItA0v|= zI>zkK@0iao95czS>%aOSH~F0Li;o~d(~b~4O&d=UJj3V;p|d)yXquW)o;O_OO82b(L{th`k!*IAd;L7ld`{e>&mnmq5z%zW#vh*DLoW~0LHf>A< zrFy(p@gCl1BWuhh5L-wwUdNrVwJ5LIpLrz8>&7{}2Ju1f@->2(zXY2-eK+slHLL|T z@F8&nKiu^diI&ZrmUHo(vH~CB gestiones; private float suma; - private static float total; + private static float total = 0; private Month mes; private Year anio; private boolean isPositivo; @@ -15,7 +15,6 @@ public class Gestion{ public Gestion(String nombre, boolean isPositivo) { this.gestiones = new Vector(); this.suma = 0; - Gestion.total = 0; this.nombre = nombre; this.isPositivo = isPositivo; } diff --git a/src/Logica/Meses.java b/src/Logica/Meses.java index dae1dd7..29bf9cc 100644 --- a/src/Logica/Meses.java +++ b/src/Logica/Meses.java @@ -56,6 +56,8 @@ private ArrayList meses; } } this.meses.add(new Mes(new ArrayList(), anio, mes)); + this.mesActual = this.meses.size()-1; + System.out.println(this.meses.size()-1); } public ArrayList getGestionesActuales(){ diff --git a/src/VistaControlador/ControladorPanelLateral.java b/src/VistaControlador/ControladorPanelLateral.java index 88bf28a..9a86990 100644 --- a/src/VistaControlador/ControladorPanelLateral.java +++ b/src/VistaControlador/ControladorPanelLateral.java @@ -107,6 +107,7 @@ public class ControladorPanelLateral implements ActionListener, DateChangeListen if(this.mes!=VistaPanelLateral.elegirMes.getDate().getMonth() || this.anio!=VistaPanelLateral.elegirMes.getDate().getYear()) { System.out.println("Cambia mes"); + 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/Menu.java b/src/VistaControlador/Menu.java index 06530b3..b380974 100644 --- a/src/VistaControlador/Menu.java +++ b/src/VistaControlador/Menu.java @@ -50,16 +50,15 @@ public class Menu extends JFrame{ setLocationRelativeTo(null); ControladorPanelLateral controlador3 = new ControladorPanelLateral(this.panel, this); this.pestania.addChangeListener((ChangeListener)->{ - if(this.pestania.getSelectedIndex() == 0) { - this.panel.actualizarDatos(meses.getGestionesActuales().get(0)); - }else { - this.panel.actualizarDatos(meses.getGestionesActuales().get(1)); + if(this.pestania.getTabCount()<0) { + this.panel.actualizarDatos(meses.getGestionesActuales().get(this.pestania.getSelectedIndex())); } }); this.add(this.panel); } private void iniciarMes(int anio, Month mes) { + this.pestania.removeAll(); meses.aniadirGestion("Ingresos", anio, mes, true); meses.aniadirGestion("Gastos", anio, mes, false); this.pestanias=new ArrayList(); @@ -68,28 +67,34 @@ public class Menu extends JFrame{ this.controladores=new ArrayList(); this.controladores.add(new ControladorAniadirVisualizar(this.pestanias.get(0))); this.controladores.add(new ControladorAniadirVisualizar(this.pestanias.get(1))); + this.cargarPestanias(); } - private void cargarGestiones(int anio, Month mes) { + void cargarGestiones(int anio, Month mes) { if(this.meses==null) { this.meses=new Meses(); } this.meses.elegirMes(anio, mes); if(this.meses.getGestionesActuales().size() == 0) { this.iniciarMes(anio, mes); + System.out.println("entra"); }else { this.cargarMes(); } } private void cargarMes() { - this.pestanias=new ArrayList(); - this.controladores=new ArrayList(); + this.pestania.removeAll(); + this.pestanias.clear(); + this.controladores.clear(); for(Gestion gestion:this.meses.getGestionesActuales()) { VistaAniadirVisualizar vista = new VistaAniadirVisualizar(this, gestion); - this.pestania.add(vista); - this.controladores.add(new ControladorAniadirVisualizar(vista)); + ControladorAniadirVisualizar controlador = new ControladorAniadirVisualizar(vista); + vista.iniciarGestion(); + this.pestanias.add(vista); + this.controladores.add(controlador); } + this.cargarPestanias(); } void cargarPestanias() { diff --git a/src/VistaControlador/VistaAniadirVisualizar.java b/src/VistaControlador/VistaAniadirVisualizar.java index 5ae8a3a..a771c8a 100644 --- a/src/VistaControlador/VistaAniadirVisualizar.java +++ b/src/VistaControlador/VistaAniadirVisualizar.java @@ -20,6 +20,7 @@ public class VistaAniadirVisualizar extends JPanel{ JPanel cuadro; JScrollPane panel; Menu menu; + private ControladorAniadirVisualizar controlador; static VistaPanelLateral panelLateral; public VistaAniadirVisualizar(Menu menu, Gestion gestion) { this.gestiones = gestion; @@ -46,6 +47,12 @@ public class VistaAniadirVisualizar extends JPanel{ return this.gestiones.getNombre(); } + void iniciarGestion() { + for(Transaccion transaccion:this.gestiones.getElementos()) { + this.aniadirElemento(transaccion); + } + } + public void aniadirElemento(String nombre, float dinero, ControladorAniadirVisualizar controlador) { Transaccion transaccion = new Transaccion(nombre, dinero,panelLateral.getDate()); this.gestiones.aniadirGasto(transaccion); @@ -60,4 +67,18 @@ public class VistaAniadirVisualizar extends JPanel{ this.revalidate(); this.repaint(); } + + + private void aniadirElemento(Transaccion transaccion) { + JCheckBox check = new JCheckBox(transaccion.toString()); + check.setSelected(true); + check.setSize(new Dimension(x,VistaAniadirVisualizar.altoCheck)); + check.addActionListener(this.boton.getActionListeners()[0]); + this.transacciones.add(check); + this.cuadro.add(check); + this.y += VistaAniadirVisualizar.altoCheck; + cuadro.setPreferredSize(new Dimension(x, y)); + this.revalidate(); + this.repaint(); + } }