From 0d6d20001f20d4c9a141652c9c2291a64f41542b Mon Sep 17 00:00:00 2001
From: Guillermo <groche97@gmail.com>
Date: Fri, 15 Nov 2019 01:10:55 +0100
Subject: [PATCH] Corregir bugs y aniadir la opcion de eliminar transacciones

---
 bin/Logica/Gestion.class                      | Bin 1900 -> 2301 bytes
 src/Logica/Gestion.java                       |  28 ++++++++++++------
 src/Logica/Meses.java                         |  15 ++++++++--
 .../ControladorPanelLateral.java              |  19 ++++--------
 src/VistaControlador/Menu.java                |   3 +-
 .../VistaAniadirVisualizar.java               |  12 +++++++-
 src/VistaControlador/VistaPanelLateral.java   |  11 +++++--
 7 files changed, 57 insertions(+), 31 deletions(-)

diff --git a/bin/Logica/Gestion.class b/bin/Logica/Gestion.class
index 445f77a037de885ed2ed1013bb6f5c79b4a561a2..e72e9f55d8409d43209533585d2f8bdb0d0db6ed 100644
GIT binary patch
literal 2301
zcmZ`)T~i!I6g|Bx?6M4jgoOYJUm?V0`B)_+L6=|@0uq75Ko-HT^ez+VxI3e>vy|nV
zKfyQAm%Q<28Tm-5RhG~G1%HZF#?v#iFp{-WnZDh(``&xbJ$L!@pI?6mFbNeyMBv<#
zy{!r|vtX88Wm_>s1zMlVU70CLYddp4|I{qF0*%|g-z*DUSn~W8R~0ikdTl4m3#)3|
zl5WK@1yZkEm|hCftU1yu%R+&vvNL=ZEmulXK+Fr&yS6Kf0(B*w<h&olRV6dCY+LS*
zzAP<ev%HXN!<0IELX{ubW#y_}`o*R|gJqZUx|X0=56r6TC~KS78>W?|+!=w6pwzH?
zb2!ITv-XymKpi>_B+<pHQp33zE>+11flr_tosAIaHBgTRZS@;yL_%9v3^e)HRRb5$
zrq8Y!XvKMfmL+AGE0t2-bk=0P=oM=hWHBclrT4*M)ZI}eq_s+6&?&-TQ{0sRXEHVH
z(-MXvV30DorJMy>c1g{}R5ePt5yLr+;dKLVV1h{H)|Nnfm>FLM+2PFub#pU@8=6;N
zH=#HNZehx=YL3Vp<|AwDY?FK1b%A895(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~n!li~
zL9Cr#o+F6<L`nAS-JEw<S1oWKACZ)Aod=#G;k2`7<-B=8T7i%8(B~|sbsYpg)N-az
zu>J~*C-~$!KKEpOV>Kjjnk>)kc~bA6Ti2q$!1e`b`={+XkLKUHd=9PlMhlm`XL6ec
zyTjJqrAHR9&Uag41Ha_|t*@x=0bBMRoAv{n_9L716ZO-U^;>&*+S)^uu|-jIYvYLi
PgHmcS$@w<t5j_46&b)8E

diff --git a/src/Logica/Gestion.java b/src/Logica/Gestion.java
index 1d13074..9b683fd 100644
--- a/src/Logica/Gestion.java
+++ b/src/Logica/Gestion.java
@@ -6,7 +6,7 @@ import java.util.Vector;
 public class Gestion{
 	private Vector<Transaccion> gestiones;
 	private float suma;
-	private static float total = 0;
+	private  float total;
 	private Month mes;
 	private Year anio;
 	private boolean isPositivo;
@@ -15,6 +15,7 @@ public class Gestion{
 	public Gestion(String nombre, boolean isPositivo) {
 		this.gestiones = new Vector<Transaccion>();
 		this.suma = 0;
+		this.total = 0;
 		this.nombre = nombre;
 		this.isPositivo = isPositivo;
 	}
@@ -27,9 +28,9 @@ public class Gestion{
 		this.gestiones.add(transaccion);
 		this.suma += transaccion.getDinero();
 		if(this.isPositivo) {
-			Gestion.total += transaccion.getDinero();
+			this.total += transaccion.getDinero();
 		}else {
-			Gestion.total -= transaccion.getDinero();
+			this.total -= transaccion.getDinero();
 		}
 	}
 	
@@ -37,28 +38,37 @@ public class Gestion{
 		return this.suma;
 	}
 	
-	public static float getTotal() {
-		return Gestion.total;
+	public float getTotal() {
+		return this.total;
 	}
 	
 	public Vector<Transaccion> getElementos(){
 		return this.gestiones;
 	}
 	
+	public void eliminarTransaccion(String transaccion) {
+		for(Transaccion elemento:this.gestiones) {
+			if(elemento.toString().equals(transaccion)) {
+				this.gestiones.remove(elemento);
+				return;
+			}
+		}
+	}
+	
 	public void alterarVisibilidad(int elemento) {
 		if(this.gestiones.get(elemento).alterarVisivilidad()) {
 			this.suma += this.gestiones.get(elemento).getDinero();
 			if(this.isPositivo) {
-				Gestion.total += this.gestiones.get(elemento).getDinero();
+				this.total += this.gestiones.get(elemento).getDinero();
 			}else {
-				Gestion.total -= this.gestiones.get(elemento).getDinero();
+				this.total -= this.gestiones.get(elemento).getDinero();
 			}
 		}else {
 			this.suma -= this.gestiones.get(elemento).getDinero();
 			if(this.isPositivo) {
-				Gestion.total -= this.gestiones.get(elemento).getDinero();
+				this.total -= this.gestiones.get(elemento).getDinero();
 			}else {
-				Gestion.total += this.gestiones.get(elemento).getDinero();
+				this.total += this.gestiones.get(elemento).getDinero();
 			}
 		}
 	}
diff --git a/src/Logica/Meses.java b/src/Logica/Meses.java
index 29bf9cc..58285a9 100644
--- a/src/Logica/Meses.java
+++ b/src/Logica/Meses.java
@@ -6,7 +6,6 @@ import java.util.ArrayList;
 public class Meses {
 private ArrayList<Mes> meses;
 	private int mesActual=0;
-	
 	public Meses() {
 		this.meses = new ArrayList<Mes>();
 	}
@@ -57,19 +56,21 @@ private ArrayList<Mes> meses;
 		}
 		this.meses.add(new Mes(new ArrayList<Gestion>(), anio, mes));
 		this.mesActual = this.meses.size()-1;
-		System.out.println(this.meses.size()-1);
 	}
 	
 	public ArrayList<Gestion> getGestionesActuales(){
 		return this.meses.get(this.mesActual).getGestiones();
 	}
 	
+	public float getTotal() {
+		return this.meses.get(this.mesActual).getTotal();
+	}
+	
 }
 
 class Mes{
 	private int anio;
 	private Month mes;
-	int total;
 	ArrayList<Gestion> gestiones;
 	Mes(ArrayList<Gestion> gestiones, int anio, Month mes){
 		this.gestiones = gestiones;
@@ -101,4 +102,12 @@ class Mes{
 		return this.gestiones;
 	}
 	
+	float getTotal() {
+		float ret = 0;
+		for(Gestion gestion:this.gestiones) {
+			ret += gestion.getTotal();
+		}
+		return ret;
+	}
+	
 }
diff --git a/src/VistaControlador/ControladorPanelLateral.java b/src/VistaControlador/ControladorPanelLateral.java
index 9a86990..ffa5cfa 100644
--- a/src/VistaControlador/ControladorPanelLateral.java
+++ b/src/VistaControlador/ControladorPanelLateral.java
@@ -74,21 +74,12 @@ public class ControladorPanelLateral implements ActionListener, DateChangeListen
 				}
 				break;
 			}
+			
+			case "Eliminar Transacciones":{
+				this.menu.pestanias.get(this.menu.pestania.getSelectedIndex()).eliminarDeseleccionados();
+			}
 		}
 		
-		/*if(e.getActionCommand().equals(this.vista.mostrarEstadisticas.getActionCommand())) {
-			
-			XYSeries serie = new XYSeries("Mes");
-			serie.add(10,1);
-			serie.add(4,2);
-			serie.add(90,10);
-			XYSeriesCollection dataset = new XYSeriesCollection(serie);
-			JFreeChart chart = ChartFactory.createXYLineChart("Mes", "Dias", "Gastos", dataset);
-			ChartFrame frame = new ChartFrame("Estadisricas", chart);
-			frame.setVisible(true);
-			frame.setSize(700,500);
-		}
-		*/
 	}
 	
 	private void aniadirElementos() {
@@ -101,6 +92,8 @@ public class ControladorPanelLateral implements ActionListener, DateChangeListen
 			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) {
diff --git a/src/VistaControlador/Menu.java b/src/VistaControlador/Menu.java
index b380974..cf9c71e 100644
--- a/src/VistaControlador/Menu.java
+++ b/src/VistaControlador/Menu.java
@@ -35,7 +35,7 @@ public class Menu extends JFrame{
 		this.cargarPestanias();
 		this.setLayout(new GridBagLayout());
 		GridBagConstraints constrain = new GridBagConstraints();
-		this.panel = new VistaPanelLateral(constrain);
+		this.panel = new VistaPanelLateral(constrain, this.meses);
 		this.panelCentral = new JPanel();
 		
 		constrain.fill = GridBagConstraints.VERTICAL;
@@ -77,7 +77,6 @@ public class Menu extends JFrame{
 		this.meses.elegirMes(anio, mes);
 		if(this.meses.getGestionesActuales().size() == 0) {
 			this.iniciarMes(anio, mes);
-			System.out.println("entra");
 		}else {
 			this.cargarMes();
 		}
diff --git a/src/VistaControlador/VistaAniadirVisualizar.java b/src/VistaControlador/VistaAniadirVisualizar.java
index a771c8a..3f9deea 100644
--- a/src/VistaControlador/VistaAniadirVisualizar.java
+++ b/src/VistaControlador/VistaAniadirVisualizar.java
@@ -21,7 +21,7 @@ public class VistaAniadirVisualizar extends JPanel{
 	JScrollPane panel;
 	Menu menu;
 	private ControladorAniadirVisualizar controlador;
-	static VistaPanelLateral panelLateral;
+	private static VistaPanelLateral panelLateral;
 	public VistaAniadirVisualizar(Menu menu, Gestion gestion) {
 		this.gestiones = gestion;
 		this.transacciones = new LinkedList<JCheckBox>();
@@ -68,6 +68,16 @@ public class VistaAniadirVisualizar extends JPanel{
 		this.repaint();
 	}
 	
+	void eliminarDeseleccionados(){
+		for(JCheckBox check:this.transacciones) {
+			if(!check.isSelected()) {
+				this.cuadro.remove(check);
+				this.gestiones.eliminarTransaccion(check.getText());
+				this.cuadro.revalidate();
+				this.cuadro.repaint();
+			}
+		}
+	}
 	
 	private void aniadirElemento(Transaccion transaccion) {
 		JCheckBox check = new JCheckBox(transaccion.toString());
diff --git a/src/VistaControlador/VistaPanelLateral.java b/src/VistaControlador/VistaPanelLateral.java
index 57153d0..d1591fd 100644
--- a/src/VistaControlador/VistaPanelLateral.java
+++ b/src/VistaControlador/VistaPanelLateral.java
@@ -12,16 +12,19 @@ import javax.swing.JTextArea;
 import com.github.lgooddatepicker.components.DatePicker;
 
 import Logica.Gestion;
+import Logica.Meses;
 
 public class VistaPanelLateral extends JPanel{
 	protected JTextArea total;
 	protected JTextArea gastoEnvio;
-	//protected JButton elegirMes;
 	protected static DatePicker elegirMes = inicializarCalendario();
 	protected JButton mostrarEstadisticas;
 	JButton aniadirGestion;
-	VistaPanelLateral(GridBagConstraints constrain){
+	JButton eliminarTransaccion;
+	Meses meses;
+	VistaPanelLateral(GridBagConstraints constrain, Meses meses){
 		this.setPreferredSize(new Dimension(200,200));
+		this.meses=meses;
 		this.total = new JTextArea();
 		this.gastoEnvio = new JTextArea();
 		this.mostrarEstadisticas = new JButton("Mostrar grafico del mes");
@@ -40,10 +43,12 @@ public class VistaPanelLateral extends JPanel{
 		constrain.weightx = 2;
 		this.add(this.gastoEnvio);
 		this.add(this.aniadirGestion);
+		this.eliminarTransaccion = new JButton("Eliminar Deseleccionados");
+		this.add(this.eliminarTransaccion);
 	}
 	
 	void actualizarDatos(Gestion gestion) {
-		this.total.setText("Total: " + String.valueOf(Gestion.getTotal()) + "€");
+		this.total.setText("Total: " + String.valueOf(this.meses.getTotal()) + "€");
 		this.gastoEnvio.setText("Suma: " + String.valueOf(gestion.getSuma()) + "€");
 	}