diff --git a/bin/Logica/Gestion.class b/bin/Logica/Gestion.class index 3ad3087..c278cff 100644 Binary files a/bin/Logica/Gestion.class and b/bin/Logica/Gestion.class differ diff --git a/bin/Logica/Transaccion.class b/bin/Logica/Transaccion.class index 30dd48f..dd3367c 100644 Binary files a/bin/Logica/Transaccion.class and b/bin/Logica/Transaccion.class differ diff --git a/src/Logica/Gestion.java b/src/Logica/Gestion.java index 9ce8a73..b322286 100644 --- a/src/Logica/Gestion.java +++ b/src/Logica/Gestion.java @@ -9,20 +9,15 @@ public class Gestion{ private static float total; private Month mes; private Year anio; - //private boolean isPositivo; + private boolean isPositivo; private String nombre; - public Gestion() { - this.gestiones=new Vector(); - this.suma = 0; - Gestion.total = 0; - } - - public Gestion(String nombre) { + public Gestion(String nombre, boolean isPositivo) { this.gestiones = new Vector(); this.suma = 0; Gestion.total = 0; this.nombre = nombre; + this.isPositivo = isPositivo; } public String getNombre() { @@ -32,7 +27,7 @@ public class Gestion{ public void aniadirGasto(Transaccion transaccion) { this.gestiones.add(transaccion); this.suma += transaccion.getDinero(); - if(transaccion.isPositivo()) { + if(this.isPositivo) { Gestion.total += transaccion.getDinero(); }else { Gestion.total -= transaccion.getDinero(); @@ -54,14 +49,14 @@ public class Gestion{ public void alterarVisibilidad(int elemento) { if(this.gestiones.get(elemento).alterarVisivilidad()) { this.suma += this.gestiones.get(elemento).getDinero(); - if(this.gestiones.get(elemento).isPositivo()) { + if(this.isPositivo) { Gestion.total += this.gestiones.get(elemento).getDinero(); }else { Gestion.total -= this.gestiones.get(elemento).getDinero(); } }else { this.suma -= this.gestiones.get(elemento).getDinero(); - if(this.gestiones.get(elemento).isPositivo()) { + if(this.isPositivo) { Gestion.total -= this.gestiones.get(elemento).getDinero(); }else { Gestion.total += this.gestiones.get(elemento).getDinero(); diff --git a/src/Logica/Meses.java b/src/Logica/Meses.java index c2a994d..dae1dd7 100644 --- a/src/Logica/Meses.java +++ b/src/Logica/Meses.java @@ -11,41 +11,41 @@ private ArrayList meses; this.meses = new ArrayList(); } - public Gestion aniadirGestion(String nombre, int anio, Month mes) { + public Gestion aniadirGestion(String nombre, int anio, Month mes, boolean isPositivo) { Gestion ret; try { for(Mes mesSelect:this.meses) { if(mesSelect.getMes().equals(mes) && mesSelect.getAnio() == anio){ - ret = new Gestion(nombre); + ret = new Gestion(nombre, isPositivo); mesSelect.getGestiones().add(ret); return ret; } } }catch (NullPointerException e) { ArrayList gestiones=new ArrayList(); - ret = new Gestion(nombre); + ret = new Gestion(nombre, isPositivo); gestiones.add(ret); this.meses.add(new Mes(gestiones,anio,mes)); return ret; } ArrayList gestiones=new ArrayList(); - ret = new Gestion(nombre); + ret = new Gestion(nombre, isPositivo); gestiones.add(ret); this.meses.add(new Mes(gestiones,anio,mes)); return ret; } - public void aniadirTransaccion(Transaccion transaccion, String nombre) { + public void aniadirTransaccion(Transaccion transaccion, String nombre, boolean isPositivo) { for(Mes mes:this.meses) { if(transaccion.getDia().getMonth().equals(mes.getMes()) && transaccion.getDia().getYear() == mes.getAnio()){ - mes.aniadirTransaccion(transaccion, nombre); + mes.aniadirTransaccion(transaccion, nombre, isPositivo); return; } } this.meses.add(new Mes(new ArrayList(),transaccion.getDia().getYear(), transaccion.getDia().getMonth())); - this.meses.get(this.meses.size()-1).aniadirTransaccion(transaccion, nombre); + this.meses.get(this.meses.size()-1).aniadirTransaccion(transaccion, nombre, isPositivo); } public void elegirMes(int anio, Month mes) { @@ -75,14 +75,14 @@ class Mes{ this.mes=mes; } - void aniadirTransaccion(Transaccion transaccion, String nombre) { + void aniadirTransaccion(Transaccion transaccion, String nombre, boolean isPositivo) { for(Gestion gestion:this.gestiones) { if(gestion.getNombre().equals(nombre)) { gestion.aniadirGasto(transaccion); return; } } - gestiones.add(new Gestion(nombre)); + gestiones.add(new Gestion(nombre, isPositivo)); gestiones.get(this.gestiones.size()-1).aniadirGasto(transaccion); return; } diff --git a/src/Logica/Transaccion.java b/src/Logica/Transaccion.java index 1d4e94e..2dc7689 100644 --- a/src/Logica/Transaccion.java +++ b/src/Logica/Transaccion.java @@ -7,21 +7,18 @@ public class Transaccion { private float dinero; private boolean visible; private LocalDate dia; - private boolean positivo; public Transaccion(String nombre, float dinero){ this.nombre = nombre; this.dinero = dinero; this.visible = true; this.dia = LocalDate.now(); - this.positivo = true; } - public Transaccion(String nombre, float dinero, LocalDate dia, boolean positivo){ + public Transaccion(String nombre, float dinero, LocalDate dia){ this.nombre = nombre; this.dinero = dinero; this.visible = true; - this.positivo = positivo; this.dia = dia; } @@ -42,10 +39,6 @@ public class Transaccion { return this.dinero; } - public boolean isPositivo() { - return this.positivo; - } - public LocalDate getDia() { return this.dia; } diff --git a/src/VistaControlador/Menu.java b/src/VistaControlador/Menu.java index 30963ec..06530b3 100644 --- a/src/VistaControlador/Menu.java +++ b/src/VistaControlador/Menu.java @@ -60,11 +60,11 @@ public class Menu extends JFrame{ } private void iniciarMes(int anio, Month mes) { - meses.aniadirGestion("Ingresos", anio, mes); - meses.aniadirGestion("Gastos", anio, mes); + meses.aniadirGestion("Ingresos", anio, mes, true); + meses.aniadirGestion("Gastos", anio, mes, false); this.pestanias=new ArrayList(); - this.pestanias.add(new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(0),true)); - this.pestanias.add(new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(1),false)); + this.pestanias.add(new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(0))); + this.pestanias.add(new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(1))); this.controladores=new ArrayList(); this.controladores.add(new ControladorAniadirVisualizar(this.pestanias.get(0))); this.controladores.add(new ControladorAniadirVisualizar(this.pestanias.get(1))); @@ -86,7 +86,7 @@ public class Menu extends JFrame{ this.pestanias=new ArrayList(); this.controladores=new ArrayList(); for(Gestion gestion:this.meses.getGestionesActuales()) { - VistaAniadirVisualizar vista = new VistaAniadirVisualizar(this, gestion, true); + VistaAniadirVisualizar vista = new VistaAniadirVisualizar(this, gestion); this.pestania.add(vista); this.controladores.add(new ControladorAniadirVisualizar(vista)); } @@ -100,8 +100,8 @@ public class Menu extends JFrame{ } void aniadirGestion(String nombre, boolean sumaOResta) { - Gestion gestion=this.meses.aniadirGestion(nombre, VistaPanelLateral.getDate().getYear(), VistaPanelLateral.getDate().getMonth()); - VistaAniadirVisualizar vista = new VistaAniadirVisualizar(this, gestion, sumaOResta); + Gestion gestion=this.meses.aniadirGestion(nombre, VistaPanelLateral.getDate().getYear(), VistaPanelLateral.getDate().getMonth(), sumaOResta); + VistaAniadirVisualizar vista = new VistaAniadirVisualizar(this, gestion); this.pestanias.add(vista); this.controladores.add(new ControladorAniadirVisualizar(vista)); this.pestania.addTab(vista.getName(),vista); diff --git a/src/VistaControlador/VistaAniadirVisualizar.java b/src/VistaControlador/VistaAniadirVisualizar.java index d094401..5ae8a3a 100644 --- a/src/VistaControlador/VistaAniadirVisualizar.java +++ b/src/VistaControlador/VistaAniadirVisualizar.java @@ -20,10 +20,8 @@ public class VistaAniadirVisualizar extends JPanel{ JPanel cuadro; JScrollPane panel; Menu menu; - boolean positivo; static VistaPanelLateral panelLateral; - public VistaAniadirVisualizar(Menu menu, Gestion gestion,boolean positivo) { - this.positivo = positivo; + public VistaAniadirVisualizar(Menu menu, Gestion gestion) { this.gestiones = gestion; this.transacciones = new LinkedList(); this.menu = menu; @@ -49,7 +47,7 @@ public class VistaAniadirVisualizar extends JPanel{ } public void aniadirElemento(String nombre, float dinero, ControladorAniadirVisualizar controlador) { - Transaccion transaccion = new Transaccion(nombre, dinero,panelLateral.getDate(),this.positivo); + Transaccion transaccion = new Transaccion(nombre, dinero,panelLateral.getDate()); this.gestiones.aniadirGasto(transaccion); JCheckBox check = new JCheckBox(transaccion.toString()); check.setSelected(true);