Finalizado soporte de persistencia
This commit is contained in:
@@ -3,12 +3,14 @@ package VistaControlador;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.JTextArea;
|
||||
@@ -17,6 +19,7 @@ import javax.swing.event.ChangeListener;
|
||||
|
||||
import Logica.Gestion;
|
||||
import Logica.Meses;
|
||||
import Logica.Transaccion;
|
||||
|
||||
public class Menu extends JFrame{
|
||||
protected JPanel panelCentral;
|
||||
@@ -24,20 +27,30 @@ public class Menu extends JFrame{
|
||||
protected VistaAniadirVisualizar ingresos;
|
||||
protected VistaAniadirVisualizar gastos;
|
||||
protected VistaPanelLateral panel;
|
||||
String nombreDatos;
|
||||
Meses meses;
|
||||
ArrayList<VistaAniadirVisualizar> pestanias;
|
||||
ArrayList<ControladorAniadirVisualizar> controladores;
|
||||
protected Gestion datosGastos;
|
||||
protected Gestion datosIngresos;
|
||||
public Menu() {
|
||||
this.nombreDatos = ".mes";
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||
|
||||
addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
public void windowClosing(java.awt.event.WindowEvent evt) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
this.pestania = new JTabbedPane();
|
||||
GridBagConstraints constrain = new GridBagConstraints();
|
||||
|
||||
this.cargarGestiones(LocalDate.now().getYear(), LocalDate.now().getMonth());
|
||||
this.cargarPestanias();
|
||||
this.setLayout(new GridBagLayout());
|
||||
GridBagConstraints constrain = new GridBagConstraints();
|
||||
this.panel = new VistaPanelLateral(constrain, this.meses);
|
||||
this.panelCentral = new JPanel();
|
||||
|
||||
|
||||
constrain.fill = GridBagConstraints.VERTICAL;
|
||||
constrain.gridx = 0;
|
||||
constrain.gridy = 0;
|
||||
@@ -49,16 +62,26 @@ public class Menu extends JFrame{
|
||||
setDefaultCloseOperation(3);
|
||||
setLocationRelativeTo(null);
|
||||
ControladorPanelLateral controlador3 = new ControladorPanelLateral(this.panel, this);
|
||||
this.pestania.addChangeListener((ChangeListener)->{
|
||||
if(this.pestania.getTabCount()<0) {
|
||||
this.panel.actualizarDatos(meses.getGestionesActuales().get(this.pestania.getSelectedIndex()));
|
||||
}
|
||||
});
|
||||
this.listenerPestania();
|
||||
this.add(this.panel);
|
||||
}
|
||||
|
||||
private void close(){
|
||||
if (JOptionPane.showConfirmDialog(rootPane, "¿Desea guardar el estado?",
|
||||
"Salir del sistema", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
try {
|
||||
this.meses.guardarMeses(this.nombreDatos);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
private void iniciarMes(int anio, Month mes) {
|
||||
this.pestania.removeAll();
|
||||
this.listenerPestania();
|
||||
meses.aniadirGestion("Ingresos", anio, mes, true);
|
||||
meses.aniadirGestion("Gastos", anio, mes, false);
|
||||
this.pestanias=new ArrayList<VistaAniadirVisualizar>();
|
||||
@@ -73,6 +96,15 @@ public class Menu extends JFrame{
|
||||
void cargarGestiones(int anio, Month mes) {
|
||||
if(this.meses==null) {
|
||||
this.meses=new Meses();
|
||||
try {
|
||||
meses.cargarMeses(this.nombreDatos);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
this.meses.elegirMes(anio, mes);
|
||||
if(this.meses.getGestionesActuales().size() == 0) {
|
||||
@@ -84,8 +116,17 @@ public class Menu extends JFrame{
|
||||
|
||||
private void cargarMes() {
|
||||
this.pestania.removeAll();
|
||||
this.pestanias.clear();
|
||||
this.controladores.clear();
|
||||
this.listenerPestania();
|
||||
if(this.pestanias == null) {
|
||||
this.pestanias = new ArrayList<VistaAniadirVisualizar>();
|
||||
}else {
|
||||
this.pestanias.clear();
|
||||
}
|
||||
if(this.controladores == null) {
|
||||
this.controladores = new ArrayList<ControladorAniadirVisualizar>();
|
||||
}else {
|
||||
this.controladores.clear();
|
||||
}
|
||||
for(Gestion gestion:this.meses.getGestionesActuales()) {
|
||||
VistaAniadirVisualizar vista = new VistaAniadirVisualizar(this, gestion);
|
||||
ControladorAniadirVisualizar controlador = new ControladorAniadirVisualizar(vista);
|
||||
@@ -98,9 +139,11 @@ public class Menu extends JFrame{
|
||||
|
||||
void cargarPestanias() {
|
||||
this.pestania.removeAll();
|
||||
this.listenerPestania();
|
||||
for(VistaAniadirVisualizar vista:this.pestanias) {
|
||||
this.pestania.addTab(vista.getName(),vista);
|
||||
}
|
||||
this.pestania.setSelectedIndex(0);
|
||||
}
|
||||
|
||||
void aniadirGestion(String nombre, boolean sumaOResta) {
|
||||
@@ -111,4 +154,19 @@ public class Menu extends JFrame{
|
||||
this.pestania.addTab(vista.getName(),vista);
|
||||
}
|
||||
|
||||
void listenerPestania(){
|
||||
if(this.pestania.getChangeListeners().length == 1) {
|
||||
this.pestania.addChangeListener((ChangeListener)->{
|
||||
if(this.pestania.getTabCount()>0) {
|
||||
try {
|
||||
this.panel.actualizarDatos(meses.getGestionesActuales().get(this.pestania.getSelectedIndex()));
|
||||
}catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user