Terminado soporte aniadir gestion nueva
This commit is contained in:
		
							parent
							
								
									cbace53701
								
							
						
					
					
						commit
						0d7df06ad6
					
				
							
								
								
									
										2
									
								
								bin/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								bin/.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1,3 +1,3 @@ | |||||||
|  | /IniciarSesion/ | ||||||
| /VistaControlador/ | /VistaControlador/ | ||||||
| /Logica/ | /Logica/ | ||||||
| /IniciarSesion/ |  | ||||||
|  | |||||||
										
											Binary file not shown.
										
									
								
							| @ -7,9 +7,10 @@ public class Gestion{ | |||||||
| 	private Vector<Transaccion> gestiones; | 	private Vector<Transaccion> gestiones; | ||||||
| 	private float suma; | 	private float suma; | ||||||
| 	private static float total; | 	private static float total; | ||||||
| 	private static Month mes; | 	private Month mes; | ||||||
| 	private static Year anio; | 	private Year anio; | ||||||
| 	private static String nombre; | 	//private boolean isPositivo; | ||||||
|  | 	private String nombre; | ||||||
| 	 | 	 | ||||||
| 	public Gestion() { | 	public Gestion() { | ||||||
| 		this.gestiones=new Vector<Transaccion>(); | 		this.gestiones=new Vector<Transaccion>(); | ||||||
|  | |||||||
| @ -11,23 +11,28 @@ private ArrayList<Mes> meses; | |||||||
| 		this.meses = new ArrayList<Mes>(); | 		this.meses = new ArrayList<Mes>(); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public void aniadirGestion(String nombre, int anio, Month mes) { | 	public Gestion aniadirGestion(String nombre, int anio, Month mes) { | ||||||
|  | 		Gestion ret; | ||||||
| 		try { | 		try { | ||||||
| 			for(Mes mesSelect:this.meses) { | 			for(Mes mesSelect:this.meses) { | ||||||
| 				if(mesSelect.getMes().equals(mes) && mesSelect.getAnio() == anio){ | 				if(mesSelect.getMes().equals(mes) && mesSelect.getAnio() == anio){ | ||||||
| 					mesSelect.getGestiones().add(new Gestion(nombre)); | 					ret = new Gestion(nombre); | ||||||
| 					return; | 					mesSelect.getGestiones().add(ret); | ||||||
|  | 					return ret; | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		}catch (NullPointerException e) { | 		}catch (NullPointerException e) { | ||||||
| 			ArrayList<Gestion> gestiones=new ArrayList<Gestion>(); | 			ArrayList<Gestion> gestiones=new ArrayList<Gestion>(); | ||||||
| 			gestiones.add(new Gestion(nombre)); | 			ret = new Gestion(nombre); | ||||||
|  | 			gestiones.add(ret); | ||||||
| 			this.meses.add(new Mes(gestiones,anio,mes)); | 			this.meses.add(new Mes(gestiones,anio,mes)); | ||||||
| 			return; | 			return ret; | ||||||
| 		} | 		} | ||||||
| 		ArrayList<Gestion> gestiones=new ArrayList<Gestion>(); | 		ArrayList<Gestion> gestiones=new ArrayList<Gestion>(); | ||||||
| 		gestiones.add(new Gestion(nombre)); | 		ret = new Gestion(nombre); | ||||||
|  | 		gestiones.add(ret); | ||||||
| 		this.meses.add(new Mes(gestiones,anio,mes)); | 		this.meses.add(new Mes(gestiones,anio,mes)); | ||||||
|  | 		return ret; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public void aniadirTransaccion(Transaccion transaccion, String nombre) { | 	public void aniadirTransaccion(Transaccion transaccion, String nombre) { | ||||||
|  | |||||||
| @ -7,6 +7,7 @@ import java.awt.event.ActionListener; | |||||||
| import java.time.Year; | import java.time.Year; | ||||||
| 
 | 
 | ||||||
| import javax.swing.JFrame; | import javax.swing.JFrame; | ||||||
|  | import javax.swing.JOptionPane; | ||||||
| 
 | 
 | ||||||
| import org.jfree.chart.ChartFactory; | import org.jfree.chart.ChartFactory; | ||||||
| import org.jfree.chart.ChartFrame; | 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.optionalusertools.DateChangeListener; | ||||||
| import com.github.lgooddatepicker.zinternaltools.DateChangeEvent; | import com.github.lgooddatepicker.zinternaltools.DateChangeEvent; | ||||||
| import com.github.lgooddatepicker.zinternaltools.DemoPanel; | import com.github.lgooddatepicker.zinternaltools.DemoPanel; | ||||||
|  | 
 | ||||||
|  | import Logica.Gestion; | ||||||
| public class ControladorPanelLateral implements ActionListener, DateChangeListener{ | public class ControladorPanelLateral implements ActionListener, DateChangeListener{ | ||||||
| 	private VistaPanelLateral vista; | 	private VistaPanelLateral vista; | ||||||
| 	private java.time.Month mes; | 	private java.time.Month mes; | ||||||
| 	private int anio; | 	private int anio; | ||||||
|  | 	private Menu menu; | ||||||
| 	 | 	 | ||||||
| 	 | 	public ControladorPanelLateral(VistaPanelLateral vista, Menu menu) { | ||||||
| 	public ControladorPanelLateral(VistaPanelLateral vista) { |  | ||||||
| 		this.vista = vista; | 		this.vista = vista; | ||||||
|  | 		this.menu = menu; | ||||||
| 		this.aniadirElementos(); | 		this.aniadirElementos(); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public void actionPerformed(ActionEvent e) { | 	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"); | 			XYSeries serie = new XYSeries("Mes"); | ||||||
| 			serie.add(10,1); | 			serie.add(10,1); | ||||||
| @ -43,12 +88,14 @@ public class ControladorPanelLateral implements ActionListener, DateChangeListen | |||||||
| 			frame.setVisible(true); | 			frame.setVisible(true); | ||||||
| 			frame.setSize(700,500); | 			frame.setSize(700,500); | ||||||
| 		} | 		} | ||||||
| 		 | 		*/ | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	private void aniadirElementos() { | 	private void aniadirElementos() { | ||||||
| 		this.vista.mostrarEstadisticas.addActionListener(this); | 		this.vista.mostrarEstadisticas.addActionListener(this); | ||||||
| 		this.vista.mostrarEstadisticas.setActionCommand("Mostrar estadisticas"); | 		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) { | 		if(VistaPanelLateral.elegirMes.getDateChangeListeners().size() == 0) { | ||||||
| 			VistaPanelLateral.elegirMes.addDateChangeListener(this); | 			VistaPanelLateral.elegirMes.addDateChangeListener(this); | ||||||
| 			this.mes=VistaPanelLateral.elegirMes.getDate().getMonth(); | 			this.mes=VistaPanelLateral.elegirMes.getDate().getMonth(); | ||||||
|  | |||||||
| @ -26,38 +26,29 @@ public class Menu extends JFrame{ | |||||||
| 	protected VistaPanelLateral panel; | 	protected VistaPanelLateral panel; | ||||||
| 	Meses meses; | 	Meses meses; | ||||||
| 	ArrayList<VistaAniadirVisualizar> pestanias; | 	ArrayList<VistaAniadirVisualizar> pestanias; | ||||||
|  | 	ArrayList<ControladorAniadirVisualizar> controladores; | ||||||
| 	protected Gestion datosGastos; | 	protected Gestion datosGastos; | ||||||
| 	protected Gestion datosIngresos; | 	protected Gestion datosIngresos; | ||||||
| 	public Menu() { | 	public Menu() { | ||||||
| 		this.meses=new Meses(); | 		this.pestania = new JTabbedPane(); | ||||||
| 		meses.aniadirGestion("Ingresos", LocalDate.now().getYear(), LocalDate.now().getMonth()); | 		this.cargarGestiones(LocalDate.now().getYear(), LocalDate.now().getMonth()); | ||||||
| 		meses.aniadirGestion("Gastos", LocalDate.now().getYear(), LocalDate.now().getMonth()); | 		this.cargarPestanias(); | ||||||
| 		VistaAniadirVisualizar.setPanelLateral(panel); |  | ||||||
| 		//this.datosGastos = 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,meses.getGestionesActuales().get(0),true); |  | ||||||
| 		this.gastos = new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(1),false); |  | ||||||
| 		this.panelCentral = new JPanel(); | 		this.panelCentral = new JPanel(); | ||||||
| 		this.pestania = new JTabbedPane(); | 		 | ||||||
| 		constrain.fill = GridBagConstraints.VERTICAL; | 		constrain.fill = GridBagConstraints.VERTICAL; | ||||||
| 		constrain.gridx = 0; | 		constrain.gridx = 0; | ||||||
| 		constrain.gridy = 0; | 		constrain.gridy = 0; | ||||||
| 		constrain.weightx = 2; | 		constrain.weightx = 2; | ||||||
| 		this.panelCentral.add(pestania,constrain); | 		this.panelCentral.add(pestania,constrain); | ||||||
| 		this.pestania.addTab("Ingresos", ingresos); |  | ||||||
| 		this.pestania.addTab("Gastos", gastos); |  | ||||||
| 		getContentPane().add(pestania); | 		getContentPane().add(pestania); | ||||||
| 		setTitle("Titulo"); | 		setTitle("Titulo"); | ||||||
| 		setSize(new Dimension(420,320)); | 		setSize(new Dimension(420,320)); | ||||||
| 		setDefaultCloseOperation(3); | 		setDefaultCloseOperation(3); | ||||||
| 		setLocationRelativeTo(null); | 		setLocationRelativeTo(null); | ||||||
| 		ControladorAniadirVisualizar controlador = new ControladorAniadirVisualizar(this.ingresos); | 		ControladorPanelLateral controlador3 = new ControladorPanelLateral(this.panel, this); | ||||||
| 		ControladorAniadirVisualizar controlador2 = new ControladorAniadirVisualizar(this.gastos); |  | ||||||
| 		ControladorPanelLateral controlador3 = new ControladorPanelLateral(this.panel); |  | ||||||
| 		//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(meses.getGestionesActuales().get(0)); | 				this.panel.actualizarDatos(meses.getGestionesActuales().get(0)); | ||||||
| @ -68,28 +59,52 @@ public class Menu extends JFrame{ | |||||||
| 		this.add(this.panel); | 		this.add(this.panel); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	 |  | ||||||
| 	 |  | ||||||
| 	private void iniciarMes(int anio, Month mes) { | 	private void iniciarMes(int anio, Month mes) { | ||||||
| 		this.meses=new Meses(); |  | ||||||
| 		meses.aniadirGestion("Ingresos", anio, mes); | 		meses.aniadirGestion("Ingresos", anio, mes); | ||||||
| 		meses.aniadirGestion("Gastos", anio, mes); | 		meses.aniadirGestion("Gastos", anio, mes); | ||||||
|  | 		this.pestanias=new ArrayList<VistaAniadirVisualizar>(); | ||||||
| 		this.pestanias.add(new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(0),true)); | 		this.pestanias.add(new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(0),true)); | ||||||
| 		this.pestanias.add(new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(1),false)); | 		this.pestanias.add(new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(1),false)); | ||||||
|  | 		this.controladores=new ArrayList<ControladorAniadirVisualizar>(); | ||||||
|  | 		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) { | 	private void cargarGestiones(int anio, Month mes) { | ||||||
|  | 		if(this.meses==null) { | ||||||
|  | 			this.meses=new Meses(); | ||||||
|  | 		} | ||||||
| 		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); | ||||||
|  | 		}else { | ||||||
|  | 			this.cargarMes(); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	private void cargarPestanias() { | 	private void cargarMes() { | ||||||
|  | 		this.pestanias=new ArrayList<VistaAniadirVisualizar>(); | ||||||
|  | 		this.controladores=new ArrayList<ControladorAniadirVisualizar>(); | ||||||
|  | 		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(); | 		this.pestania.removeAll(); | ||||||
| 		for(VistaAniadirVisualizar vista:this.pestanias) { | 		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); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
| } | } | ||||||
|  | |||||||
| @ -44,6 +44,10 @@ public class VistaAniadirVisualizar extends JPanel{ | |||||||
| 		VistaAniadirVisualizar.panelLateral = panel; | 		VistaAniadirVisualizar.panelLateral = panel; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
|  | 	public String getName() { | ||||||
|  | 		return this.gestiones.getNombre(); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
| 	public void aniadirElemento(String nombre, float dinero, ControladorAniadirVisualizar controlador) { | 	public void aniadirElemento(String nombre, float dinero, ControladorAniadirVisualizar controlador) { | ||||||
| 		Transaccion transaccion = new Transaccion(nombre, dinero,panelLateral.getDate(),this.positivo); | 		Transaccion transaccion = new Transaccion(nombre, dinero,panelLateral.getDate(),this.positivo); | ||||||
| 		this.gestiones.aniadirGasto(transaccion); | 		this.gestiones.aniadirGasto(transaccion); | ||||||
|  | |||||||
| @ -39,6 +39,7 @@ public class VistaPanelLateral extends JPanel{ | |||||||
| 		constrain.gridy = 2; | 		constrain.gridy = 2; | ||||||
| 		constrain.weightx = 2; | 		constrain.weightx = 2; | ||||||
| 		this.add(this.gastoEnvio); | 		this.add(this.gastoEnvio); | ||||||
|  | 		this.add(this.aniadirGestion); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	void actualizarDatos(Gestion gestion) { | 	void actualizarDatos(Gestion gestion) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user