diff --git a/bin/Logica/Gestion.class b/bin/Logica/Gestion.class index c278cff..445f77a 100644 Binary files a/bin/Logica/Gestion.class and b/bin/Logica/Gestion.class differ diff --git a/src/Logica/Gestion.java b/src/Logica/Gestion.java index b322286..1d13074 100644 --- a/src/Logica/Gestion.java +++ b/src/Logica/Gestion.java @@ -6,7 +6,7 @@ import java.util.Vector; public class Gestion{ private Vector 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(); + } }