diff --git a/src/Logica/Meses.java b/src/Logica/Meses.java index fd520f1..7eea92c 100644 --- a/src/Logica/Meses.java +++ b/src/Logica/Meses.java @@ -11,6 +11,25 @@ private ArrayList meses; this.meses = new ArrayList(); } + public void aniadirGestion(String nombre, int anio, Month mes) { + try { + for(Mes mesSelect:this.meses) { + if(mesSelect.getMes().equals(mes) && mesSelect.getAnio() == anio){ + mesSelect.getGestiones().add(new Gestion(nombre)); + return; + } + } + }catch (NullPointerException e) { + ArrayList gestiones=new ArrayList(); + gestiones.add(new Gestion(nombre)); + this.meses.add(new Mes(gestiones,anio,mes)); + return; + } + ArrayList gestiones=new ArrayList(); + gestiones.add(new Gestion(nombre)); + this.meses.add(new Mes(gestiones,anio,mes)); + } + public void aniadirTransaccion(Transaccion transaccion, String nombre) { for(Mes mes:this.meses) { if(transaccion.getDia().getMonth().equals(mes.getMes()) && @@ -19,7 +38,8 @@ private ArrayList meses; return; } } - this.meses.add(new Mes(new ArrayList())); + this.meses.add(new Mes(new ArrayList(),transaccion.getDia().getYear(), + transaccion.getDia().getMonth())); this.meses.get(this.meses.size()-1).aniadirTransaccion(transaccion, nombre); } @@ -42,8 +62,10 @@ class Mes{ private Month mes; int total; ArrayList gestiones; - Mes(ArrayList gestiones){ + Mes(ArrayList gestiones, int anio, Month mes){ this.gestiones = gestiones; + this.anio=anio; + this.mes=mes; } void aniadirTransaccion(Transaccion transaccion, String nombre) { diff --git a/src/VistaControlador/CheckBoxList.java b/src/VistaControlador/CheckBoxList.java deleted file mode 100644 index b666d2a..0000000 --- a/src/VistaControlador/CheckBoxList.java +++ /dev/null @@ -1,28 +0,0 @@ -package VistaControlador; - -import java.awt.Component; -import java.awt.List; - -import javax.swing.JCheckBox; -import javax.swing.JList; -import javax.swing.ListCellRenderer; - -class CheckBoxList extends JCheckBox implements ListCellRenderer { - - private static final long serialVersionUID = 3734536442230283966L; - - @Override - public Component getListCellRendererComponent(JList list, E value, int index, boolean isSelected, boolean cellHasFocus) { - setComponentOrientation(list.getComponentOrientation()); - - setFont(list.getFont()); - setText(String.valueOf(value)); - - setBackground(list.getBackground()); - setForeground(list.getForeground()); - - setSelected(isSelected); - setEnabled(list.isEnabled()); - return this; - } -} diff --git a/src/VistaControlador/Menu.java b/src/VistaControlador/Menu.java index d40be6a..4f5f941 100644 --- a/src/VistaControlador/Menu.java +++ b/src/VistaControlador/Menu.java @@ -3,6 +3,7 @@ package VistaControlador; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; +import java.time.LocalDate; import javax.swing.JButton; import javax.swing.JFrame; @@ -13,6 +14,7 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import Logica.Gestion; +import Logica.Meses; public class Menu extends JFrame{ protected JPanel panelCentral; @@ -20,17 +22,21 @@ public class Menu extends JFrame{ protected VistaAniadirVisualizar ingresos; protected VistaAniadirVisualizar gastos; protected VistaPanelLateral panel; + Meses meses; 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.setLayout(new GridBagLayout()); GridBagConstraints constrain = new GridBagConstraints(); this.panel = new VistaPanelLateral(constrain); - this.ingresos = new VistaAniadirVisualizar(this,datosIngresos,true); - this.gastos = new VistaAniadirVisualizar(this,datosGastos,false); + 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; @@ -48,12 +54,12 @@ public class Menu extends JFrame{ ControladorAniadirVisualizar controlador = new ControladorAniadirVisualizar(this.ingresos); ControladorAniadirVisualizar controlador2 = new ControladorAniadirVisualizar(this.gastos); ControladorPanelLateral controlador3 = new ControladorPanelLateral(this.panel); - this.panel.actualizarDatos(datosIngresos); + //this.panel.actualizarDatos(datosIngresos); this.pestania.addChangeListener((ChangeListener)->{ if(this.pestania.getSelectedIndex() == 0) { - this.panel.actualizarDatos(datosIngresos); + this.panel.actualizarDatos(meses.getGestionesActuales().get(0)); }else { - this.panel.actualizarDatos(datosGastos); + this.panel.actualizarDatos(meses.getGestionesActuales().get(1)); } }); this.add(this.panel);