diff --git a/bin/.gitignore b/bin/.gitignore index a1bbed7..dfe691c 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1 +1,2 @@ /VistaControlador/ +/Logica/ diff --git a/bin/Logica/Gestion.class b/bin/Logica/Gestion.class index b2e2050..84ca809 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 03febd1..9081292 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 bc1e88f..2183cfb 100644 --- a/src/Logica/Gestion.java +++ b/src/Logica/Gestion.java @@ -3,8 +3,8 @@ import java.util.Vector; public class Gestion{ private Vector gestiones; - private int suma; - private static int total; + private float suma; + private static float total; public Gestion() { this.gestiones=new Vector(); @@ -15,14 +15,18 @@ public class Gestion{ public void aniadirGasto(Transaccion transaccion) { this.gestiones.add(transaccion); this.suma+=transaccion.getDinero(); - Gestion.total+=transaccion.getDinero(); + if(transaccion.isPositivo()) { + Gestion.total+=transaccion.getDinero(); + }else { + Gestion.total-=transaccion.getDinero(); + } } - public int getSuma() { + public float getSuma() { return this.suma; } - public static int getTotal() { + public static float getTotal() { return Gestion.total; } @@ -33,10 +37,18 @@ public class Gestion{ public void alterarVisibilidad(int elemento) { if(this.gestiones.get(elemento).alterarVisivilidad()) { this.suma+=this.gestiones.get(elemento).getDinero(); - Gestion.total+=this.gestiones.get(elemento).getDinero(); + if(this.gestiones.get(elemento).isPositivo()) { + Gestion.total+=this.gestiones.get(elemento).getDinero(); + }else { + Gestion.total-=this.gestiones.get(elemento).getDinero(); + } }else { this.suma-=this.gestiones.get(elemento).getDinero(); - Gestion.total-=this.gestiones.get(elemento).getDinero(); + if(this.gestiones.get(elemento).isPositivo()) { + Gestion.total-=this.gestiones.get(elemento).getDinero(); + }else { + Gestion.total+=this.gestiones.get(elemento).getDinero(); + } } } diff --git a/src/Logica/Transaccion.java b/src/Logica/Transaccion.java index 59469e0..a40c8f8 100644 --- a/src/Logica/Transaccion.java +++ b/src/Logica/Transaccion.java @@ -2,13 +2,25 @@ package Logica; public class Transaccion { private String nombre; - private int dinero; + private float dinero; private boolean visible; + private int dia; + private boolean positivo; - public Transaccion(String nombre, int dinero){ + public Transaccion(String nombre, float dinero){ this.nombre=nombre; this.dinero=dinero; this.visible=true; + this.dia=1; + this.positivo=true; + } + + public Transaccion(String nombre, float dinero, int dia, boolean positivo){ + this.nombre=nombre; + this.dinero=dinero; + this.visible=true; + this.positivo=positivo; + this.dia=dia; } public String toString() { @@ -24,7 +36,16 @@ public class Transaccion { return this.visible; } - public int getDinero() { + public float getDinero() { + /*if(positivo) { + return this.dinero; + }else { + return -this.dinero; + }*/ return this.dinero; } + + public boolean isPositivo() { + return this.positivo; + } } diff --git a/src/VistaControlador/ControladorAniadirVisualizar.java b/src/VistaControlador/ControladorAniadirVisualizar.java index 42c3afb..325b857 100644 --- a/src/VistaControlador/ControladorAniadirVisualizar.java +++ b/src/VistaControlador/ControladorAniadirVisualizar.java @@ -33,7 +33,7 @@ public class ControladorAniadirVisualizar implements ActionListener,ChangeListen } try { - this.vista.aniadirElemento(nombre, Integer.parseInt(dinero),this); + this.vista.aniadirElemento(nombre, Float.parseFloat(dinero),this); this.vista.menu.panel.actualizarDatos(this.vista.gestiones); this.vista.menu.panel.revalidate(); this.vista.menu.panel.repaint(); diff --git a/src/VistaControlador/ControladorPanelLateral.java b/src/VistaControlador/ControladorPanelLateral.java index 03de1e6..e55d6f6 100644 --- a/src/VistaControlador/ControladorPanelLateral.java +++ b/src/VistaControlador/ControladorPanelLateral.java @@ -2,21 +2,33 @@ package VistaControlador; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; - +import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.chart.JFreeChart; -import org.jfree.chart.plot.Plot; -import org.jfree.chart.plot.XYPlot; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; public class ControladorPanelLateral implements ActionListener{ private VistaPanelLateral vista; + + public ControladorPanelLateral(VistaPanelLateral vista) { + this.vista=vista; + this.aniadirElementos(); + } + public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals(this.vista.mostrarEstadisticas.getActionCommand())) { - XYPlot plot=new XYPlot(); - - JFreeChart chart=new JFreeChart(plot); + 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); + }else if(e.getActionCommand().equals(this.vista.elegirMes.getActionCommand())){ + } } @@ -24,6 +36,8 @@ public class ControladorPanelLateral implements ActionListener{ private void aniadirElementos() { this.vista.mostrarEstadisticas.addActionListener(this); this.vista.mostrarEstadisticas.setActionCommand("Mostrar estadisticas"); + this.vista.elegirMes.addActionListener(this); + this.vista.elegirMes.setActionCommand("Elegir mes"); } } diff --git a/src/VistaControlador/Menu.java b/src/VistaControlador/Menu.java index 90b17cd..a20baeb 100644 --- a/src/VistaControlador/Menu.java +++ b/src/VistaControlador/Menu.java @@ -28,8 +28,8 @@ public class Menu extends JFrame{ this.setLayout(new GridBagLayout()); GridBagConstraints constrain=new GridBagConstraints(); this.panel=new VistaPanelLateral(constrain); - this.ingresos=new VistaAniadirVisualizar(this,datosIngresos); - this.gastos=new VistaAniadirVisualizar(this,datosGastos); + this.ingresos=new VistaAniadirVisualizar(this,datosIngresos,true); + this.gastos=new VistaAniadirVisualizar(this,datosGastos,false); this.panelCentral=new JPanel(); this.pestania=new JTabbedPane(); constrain.fill=GridBagConstraints.VERTICAL; @@ -41,11 +41,12 @@ public class Menu extends JFrame{ this.pestania.addTab("Gastos", gastos); getContentPane().add(pestania); setTitle("Titulo"); - setSize(new Dimension(230,320)); + setSize(new Dimension(420,320)); setDefaultCloseOperation(3); setLocationRelativeTo(null); ControladorAniadirVisualizar controlador=new ControladorAniadirVisualizar(this.ingresos); ControladorAniadirVisualizar controlador2=new ControladorAniadirVisualizar(this.gastos); + ControladorPanelLateral controlador3=new ControladorPanelLateral(this.panel); /*constrain.fill=GridBagConstraints.HORIZONTAL; constrain.gridx=1; constrain.gridy=0; diff --git a/src/VistaControlador/VistaAniadirVisualizar.java b/src/VistaControlador/VistaAniadirVisualizar.java index b3b54c3..5ab4343 100644 --- a/src/VistaControlador/VistaAniadirVisualizar.java +++ b/src/VistaControlador/VistaAniadirVisualizar.java @@ -20,8 +20,10 @@ public class VistaAniadirVisualizar extends JPanel{ JPanel cuadro; JScrollPane panel; Menu menu; + boolean positivo; - public VistaAniadirVisualizar(Menu menu, Gestion gestion) { + public VistaAniadirVisualizar(Menu menu, Gestion gestion,boolean positivo) { + this.positivo=positivo; this.gestiones=gestion; this.transacciones=new LinkedList(); this.menu=menu; @@ -39,8 +41,8 @@ public class VistaAniadirVisualizar extends JPanel{ this.add(panel); } - public void aniadirElemento(String nombre, int dinero, ControladorAniadirVisualizar controlador) { - Transaccion transaccion=new Transaccion(nombre, dinero); + public void aniadirElemento(String nombre, float dinero, ControladorAniadirVisualizar controlador) { + Transaccion transaccion=new Transaccion(nombre, dinero,1,this.positivo); this.gestiones.aniadirGasto(transaccion); JCheckBox check=new JCheckBox(transaccion.toString()); check.setSelected(true); diff --git a/src/VistaControlador/VistaPanelLateral.java b/src/VistaControlador/VistaPanelLateral.java index da35911..4fcf7b4 100644 --- a/src/VistaControlador/VistaPanelLateral.java +++ b/src/VistaControlador/VistaPanelLateral.java @@ -1,5 +1,6 @@ package VistaControlador; +import java.awt.Dimension; import java.awt.GridBagConstraints; import javax.swing.JButton; @@ -15,6 +16,7 @@ public class VistaPanelLateral extends JPanel{ protected JButton mostrarEstadisticas; VistaPanelLateral(GridBagConstraints constrain){ + this.setPreferredSize(new Dimension(200,200)); this.total=new JTextArea(); this.gastoEnvio=new JTextArea(); this.elegirMes=new JButton("Elegir mes");