From 21203e9524f96d8e693fc999b1863b407ebc8f7e Mon Sep 17 00:00:00 2001 From: Guillermo Date: Thu, 14 Nov 2019 20:31:28 +0100 Subject: [PATCH] Reorgnizando la diferenciacion entre lo que suma y resta al total del mes --- bin/Logica/Gestion.class | Bin 1931 -> 1846 bytes bin/Logica/Transaccion.class | Bin 1663 -> 1530 bytes src/Logica/Gestion.java | 17 ++++++----------- src/Logica/Meses.java | 18 +++++++++--------- src/Logica/Transaccion.java | 9 +-------- src/VistaControlador/Menu.java | 14 +++++++------- .../VistaAniadirVisualizar.java | 6 ++---- 7 files changed, 25 insertions(+), 39 deletions(-) diff --git a/bin/Logica/Gestion.class b/bin/Logica/Gestion.class index 3ad3087bd2382ed26a1a90b8974ca77878f2ffc9..c278cff00072708531ef9d1082cd90fc19f2caac 100644 GIT binary patch literal 1846 zcmZ`(Yi}Dx6g^`*apG+A!c9U`=h3I_Kn!gjg@jOOS`%>6B1cAvkkHuPxKr$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~CBkU@P=~it#-3&d)uxvRW2+43n*I@{riik++I zj^4NM0j^UBxx0IYJ#cz4_c)0g_%MN+TFhWJA~+Uq;dW5f1NQEbkD{*XoCOOd+!08s z*4J)J`D#D7d@L~NpV%%i-mN}?3uRx{zTcG3Le&y=+b^5x=;v-b7!HfuhYh=FJHAUv zj}?hHM_Kb7p(5e8j^LPV__im#ifXBFTLS?t@)$CQJC&mh=;ky2)Fh}cq_<8mrrpJz_1Wz&a^N+*F zeNvB}iCMT{)*%d=mGi>2pE;arKF4_~6HRcP%D=)y{x76=USaA0nf%}ZW(NPn?C&P^ z5}zp&f>3b|-Y}uY2{TEcIYzAj1ebAzCrxlQB-kTCjIr6b5#$R8m_K33uqj}IEGe?2 z$uh~`DO^OxFr@;tkcqhZGa#41d&q{IMRNvv^Di;~8{uNO#HUsZ1Uf0W_qgC3@?r9i zVZkLPX9|ZXe3RdKi5c#SRcgZZqvsg?1G6SVg{x1&9iuN`0D_@EBRp`>!06sZR)`sYx zIEy`-TQs@aCV^$#BW^HN_sxt%X)|Z#yw!zP;8T1S)GTi5J_vlI<(xjm%HOzgh_&bV z&d7QyY6LzNq14l?_f)J{HKIQ|7uWK?z_(p+_h{THjIOvr{^U7a&8G)6uyw(FRV5DH z9h!L87`8>j9?_^hs;8*m54ew?D8kQ_;TNpn4OSy|A069$gfH+Vh0=ESBmOTQrSFaN Kyuot}oBsnhH+UHU diff --git a/bin/Logica/Transaccion.class b/bin/Logica/Transaccion.class index 30dd48f581dbb4ca5d4d489aaab012a673ec898e..dd3367c4994491e173129be69f2caf118e72a8ac 100644 GIT binary patch literal 1530 zcmZuw*-jHt82-+*Fi-}lEv2+z0Y&H{)CE@%6|j0y;! zMiYxf6Cc2bQvY*0mVwUAobCUXf0^HZe*6Nkil;g>hFIBdh#D{MIovwrwVJRk9bty( zK0o5cCbt^Jo$9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GSliXL!Bz<|*Fhv3iQTr?~ekU*sT-85MZlX7@(OG`qrwxSz5%xeMzYDOP@- z0Iz4jb7Sy>G5BlSIiTVT`bRkVpHQ%)O3Ct8iOXjo)ezrVx;{dSs|+Qpv-%7F$QJ2mXwP(hJl2^7-(); - 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);