diff --git a/bin/Logica/Gestion.class b/bin/Logica/Gestion.class index 445f77a..e72e9f5 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 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 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(); 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 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 meses; private int mesActual=0; - public Meses() { this.meses = new ArrayList(); } @@ -57,19 +56,21 @@ 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(){ 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 gestiones; Mes(ArrayList 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(); @@ -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()) + "€"); }