Terminado backend de gestionde varios meses con varias gestiones

This commit is contained in:
roche 2019-11-14 12:57:01 +01:00
parent 667182d76e
commit cde3dec2f5
3 changed files with 35 additions and 35 deletions

View File

@ -11,6 +11,25 @@ private ArrayList<Mes> meses;
this.meses = new ArrayList<Mes>(); this.meses = new ArrayList<Mes>();
} }
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<Gestion> gestiones=new ArrayList<Gestion>();
gestiones.add(new Gestion(nombre));
this.meses.add(new Mes(gestiones,anio,mes));
return;
}
ArrayList<Gestion> gestiones=new ArrayList<Gestion>();
gestiones.add(new Gestion(nombre));
this.meses.add(new Mes(gestiones,anio,mes));
}
public void aniadirTransaccion(Transaccion transaccion, String nombre) { public void aniadirTransaccion(Transaccion transaccion, String nombre) {
for(Mes mes:this.meses) { for(Mes mes:this.meses) {
if(transaccion.getDia().getMonth().equals(mes.getMes()) && if(transaccion.getDia().getMonth().equals(mes.getMes()) &&
@ -19,7 +38,8 @@ private ArrayList<Mes> meses;
return; return;
} }
} }
this.meses.add(new Mes(new ArrayList<Gestion>())); this.meses.add(new Mes(new ArrayList<Gestion>(),transaccion.getDia().getYear(),
transaccion.getDia().getMonth()));
this.meses.get(this.meses.size()-1).aniadirTransaccion(transaccion, nombre); this.meses.get(this.meses.size()-1).aniadirTransaccion(transaccion, nombre);
} }
@ -42,8 +62,10 @@ class Mes{
private Month mes; private Month mes;
int total; int total;
ArrayList<Gestion> gestiones; ArrayList<Gestion> gestiones;
Mes(ArrayList<Gestion> gestiones){ Mes(ArrayList<Gestion> gestiones, int anio, Month mes){
this.gestiones = gestiones; this.gestiones = gestiones;
this.anio=anio;
this.mes=mes;
} }
void aniadirTransaccion(Transaccion transaccion, String nombre) { void aniadirTransaccion(Transaccion transaccion, String nombre) {

View File

@ -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<E> extends JCheckBox implements ListCellRenderer<E> {
private static final long serialVersionUID = 3734536442230283966L;
@Override
public Component getListCellRendererComponent(JList<? extends E> 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;
}
}

View File

@ -3,6 +3,7 @@ package VistaControlador;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
import java.time.LocalDate;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JFrame; import javax.swing.JFrame;
@ -13,6 +14,7 @@ import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import Logica.Gestion; import Logica.Gestion;
import Logica.Meses;
public class Menu extends JFrame{ public class Menu extends JFrame{
protected JPanel panelCentral; protected JPanel panelCentral;
@ -20,17 +22,21 @@ public class Menu extends JFrame{
protected VistaAniadirVisualizar ingresos; protected VistaAniadirVisualizar ingresos;
protected VistaAniadirVisualizar gastos; protected VistaAniadirVisualizar gastos;
protected VistaPanelLateral panel; protected VistaPanelLateral panel;
Meses meses;
protected Gestion datosGastos; protected Gestion datosGastos;
protected Gestion datosIngresos; protected Gestion datosIngresos;
public Menu() { 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); VistaAniadirVisualizar.setPanelLateral(panel);
this.datosGastos = new Gestion(); this.datosGastos = new Gestion();
this.datosIngresos = new Gestion(); this.datosIngresos = new Gestion();
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.ingresos = new VistaAniadirVisualizar(this,datosIngresos,true); this.ingresos = new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(0),true);
this.gastos = new VistaAniadirVisualizar(this,datosGastos,false); this.gastos = new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(1),false);
this.panelCentral = new JPanel(); this.panelCentral = new JPanel();
this.pestania = new JTabbedPane(); this.pestania = new JTabbedPane();
constrain.fill = GridBagConstraints.VERTICAL; constrain.fill = GridBagConstraints.VERTICAL;
@ -48,12 +54,12 @@ public class Menu extends JFrame{
ControladorAniadirVisualizar controlador = new ControladorAniadirVisualizar(this.ingresos); ControladorAniadirVisualizar controlador = new ControladorAniadirVisualizar(this.ingresos);
ControladorAniadirVisualizar controlador2 = new ControladorAniadirVisualizar(this.gastos); ControladorAniadirVisualizar controlador2 = new ControladorAniadirVisualizar(this.gastos);
ControladorPanelLateral controlador3 = new ControladorPanelLateral(this.panel); ControladorPanelLateral controlador3 = new ControladorPanelLateral(this.panel);
this.panel.actualizarDatos(datosIngresos); //this.panel.actualizarDatos(datosIngresos);
this.pestania.addChangeListener((ChangeListener)->{ this.pestania.addChangeListener((ChangeListener)->{
if(this.pestania.getSelectedIndex() == 0) { if(this.pestania.getSelectedIndex() == 0) {
this.panel.actualizarDatos(datosIngresos); this.panel.actualizarDatos(meses.getGestionesActuales().get(0));
}else { }else {
this.panel.actualizarDatos(datosGastos); this.panel.actualizarDatos(meses.getGestionesActuales().get(1));
} }
}); });
this.add(this.panel); this.add(this.panel);