Corregir bugs y aniadir la opcion de eliminar transacciones

This commit is contained in:
Guillermo Roche 2019-11-15 01:10:55 +01:00
parent 86c642dba9
commit 0d6d20001f
7 changed files with 57 additions and 31 deletions

Binary file not shown.

View File

@ -6,7 +6,7 @@ import java.util.Vector;
public class Gestion{ public class Gestion{
private Vector<Transaccion> gestiones; private Vector<Transaccion> gestiones;
private float suma; private float suma;
private static float total = 0; private float total;
private Month mes; private Month mes;
private Year anio; private Year anio;
private boolean isPositivo; private boolean isPositivo;
@ -15,6 +15,7 @@ public class Gestion{
public Gestion(String nombre, boolean isPositivo) { public Gestion(String nombre, boolean isPositivo) {
this.gestiones = new Vector<Transaccion>(); this.gestiones = new Vector<Transaccion>();
this.suma = 0; this.suma = 0;
this.total = 0;
this.nombre = nombre; this.nombre = nombre;
this.isPositivo = isPositivo; this.isPositivo = isPositivo;
} }
@ -27,9 +28,9 @@ public class Gestion{
this.gestiones.add(transaccion); this.gestiones.add(transaccion);
this.suma += transaccion.getDinero(); this.suma += transaccion.getDinero();
if(this.isPositivo) { if(this.isPositivo) {
Gestion.total += transaccion.getDinero(); this.total += transaccion.getDinero();
}else { }else {
Gestion.total -= transaccion.getDinero(); this.total -= transaccion.getDinero();
} }
} }
@ -37,28 +38,37 @@ public class Gestion{
return this.suma; return this.suma;
} }
public static float getTotal() { public float getTotal() {
return Gestion.total; return this.total;
} }
public Vector<Transaccion> getElementos(){ public Vector<Transaccion> getElementos(){
return this.gestiones; 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) { public void alterarVisibilidad(int elemento) {
if(this.gestiones.get(elemento).alterarVisivilidad()) { if(this.gestiones.get(elemento).alterarVisivilidad()) {
this.suma += this.gestiones.get(elemento).getDinero(); this.suma += this.gestiones.get(elemento).getDinero();
if(this.isPositivo) { if(this.isPositivo) {
Gestion.total += this.gestiones.get(elemento).getDinero(); this.total += this.gestiones.get(elemento).getDinero();
}else { }else {
Gestion.total -= this.gestiones.get(elemento).getDinero(); this.total -= this.gestiones.get(elemento).getDinero();
} }
}else { }else {
this.suma -= this.gestiones.get(elemento).getDinero(); this.suma -= this.gestiones.get(elemento).getDinero();
if(this.isPositivo) { if(this.isPositivo) {
Gestion.total -= this.gestiones.get(elemento).getDinero(); this.total -= this.gestiones.get(elemento).getDinero();
}else { }else {
Gestion.total += this.gestiones.get(elemento).getDinero(); this.total += this.gestiones.get(elemento).getDinero();
} }
} }
} }

View File

@ -6,7 +6,6 @@ import java.util.ArrayList;
public class Meses { public class Meses {
private ArrayList<Mes> meses; private ArrayList<Mes> meses;
private int mesActual=0; private int mesActual=0;
public Meses() { public Meses() {
this.meses = new ArrayList<Mes>(); this.meses = new ArrayList<Mes>();
} }
@ -57,19 +56,21 @@ private ArrayList<Mes> meses;
} }
this.meses.add(new Mes(new ArrayList<Gestion>(), anio, mes)); this.meses.add(new Mes(new ArrayList<Gestion>(), anio, mes));
this.mesActual = this.meses.size()-1; this.mesActual = this.meses.size()-1;
System.out.println(this.meses.size()-1);
} }
public ArrayList<Gestion> getGestionesActuales(){ public ArrayList<Gestion> getGestionesActuales(){
return this.meses.get(this.mesActual).getGestiones(); return this.meses.get(this.mesActual).getGestiones();
} }
public float getTotal() {
return this.meses.get(this.mesActual).getTotal();
}
} }
class Mes{ class Mes{
private int anio; private int anio;
private Month mes; private Month mes;
int total;
ArrayList<Gestion> gestiones; ArrayList<Gestion> gestiones;
Mes(ArrayList<Gestion> gestiones, int anio, Month mes){ Mes(ArrayList<Gestion> gestiones, int anio, Month mes){
this.gestiones = gestiones; this.gestiones = gestiones;
@ -101,4 +102,12 @@ class Mes{
return this.gestiones; return this.gestiones;
} }
float getTotal() {
float ret = 0;
for(Gestion gestion:this.gestiones) {
ret += gestion.getTotal();
}
return ret;
}
} }

View File

@ -74,21 +74,12 @@ public class ControladorPanelLateral implements ActionListener, DateChangeListen
} }
break; 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() { private void aniadirElementos() {
@ -101,6 +92,8 @@ public class ControladorPanelLateral implements ActionListener, DateChangeListen
this.mes=VistaPanelLateral.elegirMes.getDate().getMonth(); this.mes=VistaPanelLateral.elegirMes.getDate().getMonth();
this.anio=VistaPanelLateral.elegirMes.getDate().getYear(); this.anio=VistaPanelLateral.elegirMes.getDate().getYear();
} }
this.vista.eliminarTransaccion.addActionListener(this);
this.vista.eliminarTransaccion.setActionCommand("Eliminar Transacciones");
} }
public void dateChanged(DateChangeEvent arg0) { public void dateChanged(DateChangeEvent arg0) {

View File

@ -35,7 +35,7 @@ public class Menu extends JFrame{
this.cargarPestanias(); this.cargarPestanias();
this.setLayout(new GridBagLayout()); this.setLayout(new GridBagLayout());
GridBagConstraints constrain = new GridBagConstraints(); GridBagConstraints constrain = new GridBagConstraints();
this.panel = new VistaPanelLateral(constrain); this.panel = new VistaPanelLateral(constrain, this.meses);
this.panelCentral = new JPanel(); this.panelCentral = new JPanel();
constrain.fill = GridBagConstraints.VERTICAL; constrain.fill = GridBagConstraints.VERTICAL;
@ -77,7 +77,6 @@ public class Menu extends JFrame{
this.meses.elegirMes(anio, mes); this.meses.elegirMes(anio, mes);
if(this.meses.getGestionesActuales().size() == 0) { if(this.meses.getGestionesActuales().size() == 0) {
this.iniciarMes(anio, mes); this.iniciarMes(anio, mes);
System.out.println("entra");
}else { }else {
this.cargarMes(); this.cargarMes();
} }

View File

@ -21,7 +21,7 @@ public class VistaAniadirVisualizar extends JPanel{
JScrollPane panel; JScrollPane panel;
Menu menu; Menu menu;
private ControladorAniadirVisualizar controlador; private ControladorAniadirVisualizar controlador;
static VistaPanelLateral panelLateral; private static VistaPanelLateral panelLateral;
public VistaAniadirVisualizar(Menu menu, Gestion gestion) { public VistaAniadirVisualizar(Menu menu, Gestion gestion) {
this.gestiones = gestion; this.gestiones = gestion;
this.transacciones = new LinkedList<JCheckBox>(); this.transacciones = new LinkedList<JCheckBox>();
@ -68,6 +68,16 @@ public class VistaAniadirVisualizar extends JPanel{
this.repaint(); 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) { private void aniadirElemento(Transaccion transaccion) {
JCheckBox check = new JCheckBox(transaccion.toString()); JCheckBox check = new JCheckBox(transaccion.toString());

View File

@ -12,16 +12,19 @@ import javax.swing.JTextArea;
import com.github.lgooddatepicker.components.DatePicker; import com.github.lgooddatepicker.components.DatePicker;
import Logica.Gestion; import Logica.Gestion;
import Logica.Meses;
public class VistaPanelLateral extends JPanel{ public class VistaPanelLateral extends JPanel{
protected JTextArea total; protected JTextArea total;
protected JTextArea gastoEnvio; protected JTextArea gastoEnvio;
//protected JButton elegirMes;
protected static DatePicker elegirMes = inicializarCalendario(); protected static DatePicker elegirMes = inicializarCalendario();
protected JButton mostrarEstadisticas; protected JButton mostrarEstadisticas;
JButton aniadirGestion; JButton aniadirGestion;
VistaPanelLateral(GridBagConstraints constrain){ JButton eliminarTransaccion;
Meses meses;
VistaPanelLateral(GridBagConstraints constrain, Meses meses){
this.setPreferredSize(new Dimension(200,200)); this.setPreferredSize(new Dimension(200,200));
this.meses=meses;
this.total = new JTextArea(); this.total = new JTextArea();
this.gastoEnvio = new JTextArea(); this.gastoEnvio = new JTextArea();
this.mostrarEstadisticas = new JButton("Mostrar grafico del mes"); this.mostrarEstadisticas = new JButton("Mostrar grafico del mes");
@ -40,10 +43,12 @@ public class VistaPanelLateral extends JPanel{
constrain.weightx = 2; constrain.weightx = 2;
this.add(this.gastoEnvio); this.add(this.gastoEnvio);
this.add(this.aniadirGestion); this.add(this.aniadirGestion);
this.eliminarTransaccion = new JButton("Eliminar Deseleccionados");
this.add(this.eliminarTransaccion);
} }
void actualizarDatos(Gestion gestion) { 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()) + ""); this.gastoEnvio.setText("Suma: " + String.valueOf(gestion.getSuma()) + "");
} }