diff --git a/bin/.gitignore b/bin/.gitignore index 1871611..9bbe4d5 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,3 +1,3 @@ +/IniciarSesion/ /VistaControlador/ /Logica/ -/IniciarSesion/ diff --git a/bin/Logica/Gestion.class b/bin/Logica/Gestion.class index 0c3a5da..3ad3087 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 d24f556..9ce8a73 100644 --- a/src/Logica/Gestion.java +++ b/src/Logica/Gestion.java @@ -7,9 +7,10 @@ public class Gestion{ private Vector gestiones; private float suma; private static float total; - private static Month mes; - private static Year anio; - private static String nombre; + private Month mes; + private Year anio; + //private boolean isPositivo; + private String nombre; public Gestion() { this.gestiones=new Vector(); diff --git a/src/Logica/Meses.java b/src/Logica/Meses.java index d8e2d80..c2a994d 100644 --- a/src/Logica/Meses.java +++ b/src/Logica/Meses.java @@ -11,23 +11,28 @@ private ArrayList meses; this.meses = new ArrayList(); } - public void aniadirGestion(String nombre, int anio, Month mes) { + public Gestion aniadirGestion(String nombre, int anio, Month mes) { + Gestion ret; try { for(Mes mesSelect:this.meses) { if(mesSelect.getMes().equals(mes) && mesSelect.getAnio() == anio){ - mesSelect.getGestiones().add(new Gestion(nombre)); - return; + ret = new Gestion(nombre); + mesSelect.getGestiones().add(ret); + return ret; } } }catch (NullPointerException e) { ArrayList gestiones=new ArrayList(); - gestiones.add(new Gestion(nombre)); + ret = new Gestion(nombre); + gestiones.add(ret); this.meses.add(new Mes(gestiones,anio,mes)); - return; + return ret; } ArrayList gestiones=new ArrayList(); - gestiones.add(new Gestion(nombre)); + ret = new Gestion(nombre); + gestiones.add(ret); this.meses.add(new Mes(gestiones,anio,mes)); + return ret; } public void aniadirTransaccion(Transaccion transaccion, String nombre) { diff --git a/src/VistaControlador/ControladorPanelLateral.java b/src/VistaControlador/ControladorPanelLateral.java index 9f873f1..88bf28a 100644 --- a/src/VistaControlador/ControladorPanelLateral.java +++ b/src/VistaControlador/ControladorPanelLateral.java @@ -7,6 +7,7 @@ import java.awt.event.ActionListener; import java.time.Year; import javax.swing.JFrame; +import javax.swing.JOptionPane; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; @@ -19,19 +20,63 @@ import com.github.lgooddatepicker.components.DatePicker; import com.github.lgooddatepicker.optionalusertools.DateChangeListener; import com.github.lgooddatepicker.zinternaltools.DateChangeEvent; import com.github.lgooddatepicker.zinternaltools.DemoPanel; + +import Logica.Gestion; public class ControladorPanelLateral implements ActionListener, DateChangeListener{ private VistaPanelLateral vista; private java.time.Month mes; private int anio; + private Menu menu; - - public ControladorPanelLateral(VistaPanelLateral vista) { + public ControladorPanelLateral(VistaPanelLateral vista, Menu menu) { this.vista = vista; + this.menu = menu; this.aniadirElementos(); } public void actionPerformed(ActionEvent e) { - if(e.getActionCommand().equals(this.vista.mostrarEstadisticas.getActionCommand())) { + switch(e.getActionCommand()) { + case "Mostrar estadisticas":{ + 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); + break; + } + + case "Aniadir una nueva gestion":{ + String nombre = JOptionPane.showInputDialog("Introduce un nuevo gasto o ingreso"); + if(nombre == null) return; + if(nombre.equals("")) { + JOptionPane.showMessageDialog(null, "Debe introducir algo", "error", JOptionPane.WARNING_MESSAGE); + return; + } + String sumaOResta = JOptionPane.showInputDialog("Son gastos?"); + if(sumaOResta == null) return; + if(sumaOResta.equals("")) { + JOptionPane.showMessageDialog(null, "Debe introducir algo", "error", JOptionPane.WARNING_MESSAGE); + return; + } + VistaAniadirVisualizar vistaA; + if(sumaOResta.equalsIgnoreCase("si")) { + this.menu.aniadirGestion(nombre, false); + + }else if(sumaOResta.equalsIgnoreCase("no")) { + this.menu.aniadirGestion(nombre, true); + }else { + JOptionPane.showMessageDialog(null, "Debe introducir si o no", "error", JOptionPane.WARNING_MESSAGE); + return; + } + break; + } + } + + /*if(e.getActionCommand().equals(this.vista.mostrarEstadisticas.getActionCommand())) { XYSeries serie = new XYSeries("Mes"); serie.add(10,1); @@ -43,12 +88,14 @@ public class ControladorPanelLateral implements ActionListener, DateChangeListen frame.setVisible(true); frame.setSize(700,500); } - + */ } private void aniadirElementos() { this.vista.mostrarEstadisticas.addActionListener(this); this.vista.mostrarEstadisticas.setActionCommand("Mostrar estadisticas"); + this.vista.aniadirGestion.addActionListener(this); + this.vista.aniadirGestion.setActionCommand("Aniadir una nueva gestion"); if(VistaPanelLateral.elegirMes.getDateChangeListeners().size() == 0) { VistaPanelLateral.elegirMes.addDateChangeListener(this); this.mes=VistaPanelLateral.elegirMes.getDate().getMonth(); diff --git a/src/VistaControlador/Menu.java b/src/VistaControlador/Menu.java index 315705c..30963ec 100644 --- a/src/VistaControlador/Menu.java +++ b/src/VistaControlador/Menu.java @@ -26,38 +26,29 @@ public class Menu extends JFrame{ protected VistaPanelLateral panel; Meses meses; ArrayList pestanias; + ArrayList controladores; protected Gestion datosGastos; protected Gestion datosIngresos; public Menu() { - this.meses=new Meses(); - meses.aniadirGestion("Ingresos", LocalDate.now().getYear(), LocalDate.now().getMonth()); - meses.aniadirGestion("Gastos", LocalDate.now().getYear(), LocalDate.now().getMonth()); - VistaAniadirVisualizar.setPanelLateral(panel); - //this.datosGastos = new Gestion(); - //this.datosIngresos = new Gestion(); + this.pestania = new JTabbedPane(); + this.cargarGestiones(LocalDate.now().getYear(), LocalDate.now().getMonth()); + this.cargarPestanias(); this.setLayout(new GridBagLayout()); GridBagConstraints constrain = new GridBagConstraints(); this.panel = new VistaPanelLateral(constrain); - this.ingresos = new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(0),true); - this.gastos = new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(1),false); this.panelCentral = new JPanel(); - this.pestania = new JTabbedPane(); + constrain.fill = GridBagConstraints.VERTICAL; constrain.gridx = 0; constrain.gridy = 0; constrain.weightx = 2; this.panelCentral.add(pestania,constrain); - this.pestania.addTab("Ingresos", ingresos); - this.pestania.addTab("Gastos", gastos); getContentPane().add(pestania); setTitle("Titulo"); 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); - //this.panel.actualizarDatos(datosIngresos); + ControladorPanelLateral controlador3 = new ControladorPanelLateral(this.panel, this); this.pestania.addChangeListener((ChangeListener)->{ if(this.pestania.getSelectedIndex() == 0) { this.panel.actualizarDatos(meses.getGestionesActuales().get(0)); @@ -68,28 +59,52 @@ public class Menu extends JFrame{ this.add(this.panel); } - - private void iniciarMes(int anio, Month mes) { - this.meses=new Meses(); meses.aniadirGestion("Ingresos", anio, mes); meses.aniadirGestion("Gastos", anio, mes); + 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.controladores=new ArrayList(); + this.controladores.add(new ControladorAniadirVisualizar(this.pestanias.get(0))); + this.controladores.add(new ControladorAniadirVisualizar(this.pestanias.get(1))); } private void cargarGestiones(int anio, Month mes) { + if(this.meses==null) { + this.meses=new Meses(); + } this.meses.elegirMes(anio, mes); if(this.meses.getGestionesActuales().size() == 0) { this.iniciarMes(anio, mes); + }else { + this.cargarMes(); } } - private void cargarPestanias() { + private void cargarMes() { + this.pestanias=new ArrayList(); + this.controladores=new ArrayList(); + for(Gestion gestion:this.meses.getGestionesActuales()) { + VistaAniadirVisualizar vista = new VistaAniadirVisualizar(this, gestion, true); + this.pestania.add(vista); + this.controladores.add(new ControladorAniadirVisualizar(vista)); + } + } + + void cargarPestanias() { this.pestania.removeAll(); for(VistaAniadirVisualizar vista:this.pestanias) { - this.pestania.add(vista); + this.pestania.addTab(vista.getName(),vista); } } + 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); + 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 0b678c9..d094401 100644 --- a/src/VistaControlador/VistaAniadirVisualizar.java +++ b/src/VistaControlador/VistaAniadirVisualizar.java @@ -44,6 +44,10 @@ public class VistaAniadirVisualizar extends JPanel{ VistaAniadirVisualizar.panelLateral = panel; } + public String getName() { + return this.gestiones.getNombre(); + } + public void aniadirElemento(String nombre, float dinero, ControladorAniadirVisualizar controlador) { Transaccion transaccion = new Transaccion(nombre, dinero,panelLateral.getDate(),this.positivo); this.gestiones.aniadirGasto(transaccion); diff --git a/src/VistaControlador/VistaPanelLateral.java b/src/VistaControlador/VistaPanelLateral.java index a908ff4..57153d0 100644 --- a/src/VistaControlador/VistaPanelLateral.java +++ b/src/VistaControlador/VistaPanelLateral.java @@ -39,6 +39,7 @@ public class VistaPanelLateral extends JPanel{ constrain.gridy = 2; constrain.weightx = 2; this.add(this.gastoEnvio); + this.add(this.aniadirGestion); } void actualizarDatos(Gestion gestion) {