Aniadido soporte cambio de nombre

This commit is contained in:
2019-11-21 23:47:41 +01:00
parent a379ac104e
commit c759f93fea
16 changed files with 267 additions and 67 deletions

View File

@@ -19,25 +19,36 @@ import javax.swing.JTextArea;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.github.lgooddatepicker.components.DatePicker;
import com.github.lgooddatepicker.optionalusertools.DateChangeListener;
import Ficheros.Configuracion;
import Logica.Gestion;
import Logica.Meses;
import Logica.Transaccion;
public class Menu extends JFrame{
protected JPanel panelCentral;
protected JTabbedPane pestania;
protected VistaAniadirVisualizar ingresos;
protected VistaAniadirVisualizar gastos;
protected VistaPanelLateral panel;
static final int VISTA_MODIFICAR = 0;
static final int VISTA_GESTION = 1;
JPanel panelCentral;
JTabbedPane pestania;
VistaAniadirVisualizar ingresos;
VistaAniadirVisualizar gastos;
VistaPanelGestion panelGestion;
VistaPanelModificar panelModificar;
VistaPanel panel;
String rutaGuardado;
int tema;
Meses meses;
ArrayList<VistaAniadirVisualizar> pestanias;
ArrayList<ControladorAniadirVisualizar> controladores;
BarraOpciones barra;
protected Gestion datosGastos;
protected Gestion datosIngresos;
Gestion datosGastos;
Gestion datosIngresos;
DatePicker elegirMes;
int anio;
Month mes;
/**
* Constructor que carga los datos del menu
@@ -62,7 +73,9 @@ public class Menu extends JFrame{
this.cargarPestanias();
this.panelCentral = new JPanel();
this.panelCentral.setLayout(new GridBagLayout());
this.panel = new VistaPanelLateral(this.meses);
this.panelGestion = new VistaPanelGestion(this.meses);
this.panelModificar = new VistaPanelModificar();
this.panel = this.panelGestion;
constrain.fill = GridBagConstraints.HORIZONTAL;
constrain.gridx = 0;
@@ -70,21 +83,41 @@ public class Menu extends JFrame{
constrain.gridy = 0;
constrain.weightx = 0;
this.panelCentral.add(this.barra,constrain);
constrain.fill = GridBagConstraints.HORIZONTAL;
constrain.gridwidth = 1;
constrain.gridx = 0;
constrain.gridy = 1;
constrain.gridheight = 2;
constrain.weightx = 0.25;
this.panelCentral.add(pestania,constrain);
setTitle("Titulo");
setSize(new Dimension(420,320));
setDefaultCloseOperation(3);
setLocationRelativeTo(null);
ControladorPanelLateral controlador3 = new ControladorPanelLateral(this.panel, this);
ControladorPanelGestion controlador3 = new ControladorPanelGestion(this.panelGestion, this);
ControladorPanelModificar controlador4 = new ControladorPanelModificar(this.panelModificar, this);
this.listenerPestania();
this.elegirMes = new DatePicker();
this.elegirMes.setDate(LocalDate.now());
this.elegirMes.addDateChangeListener((DateChangeListener)->{
if(!this.elegirMes.getDate().getMonth().equals(this.mes) || !(this.elegirMes.getDate().getYear() == this.anio) ) {
this.mes = this.elegirMes.getDate().getMonth();
this.anio = this.elegirMes.getDate().getYear();
this.cargarGestiones(this.anio, this.mes);
}
});
constrain.fill = GridBagConstraints.HORIZONTAL;
constrain.gridx = 1;
constrain.gridy = 1;
constrain.gridheight = 1;
constrain.weightx = 0.25;
this.panelCentral.add(this.elegirMes, constrain);
constrain.fill = GridBagConstraints.HORIZONTAL;
constrain.gridx = 1;
constrain.gridy = 2;
constrain.weightx = 0.25;
this.panelCentral.add(this.panel,constrain);
this.add(this.panelCentral);
@@ -204,7 +237,7 @@ public class Menu extends JFrame{
* @param sumaOResta tipo de gestion
*/
void aniadirGestion(String nombre, boolean sumaOResta) {
Gestion gestion=this.meses.aniadirGestion(nombre, VistaPanelLateral.getDate().getYear(), VistaPanelLateral.getDate().getMonth(), sumaOResta);
Gestion gestion=this.meses.aniadirGestion(nombre, this.anio, this.mes, sumaOResta);
VistaAniadirVisualizar vista = new VistaAniadirVisualizar(this, gestion);
this.pestanias.add(vista);
this.controladores.add(new ControladorAniadirVisualizar(vista));
@@ -219,7 +252,7 @@ public class Menu extends JFrame{
this.pestania.addChangeListener((ChangeListener)->{
if(this.pestania.getTabCount()>0) {
try {
this.panel.actualizarDatos(meses.getGestionesActuales().get(this.pestania.getSelectedIndex()));
this.panelGestion.actualizarDatos(meses.getGestionesActuales().get(this.pestania.getSelectedIndex()));
}catch (Exception e) {
// TODO: handle exception
}
@@ -272,7 +305,8 @@ public class Menu extends JFrame{
this.panelCentral.setBackground(Color.WHITE);
this.panelCentral.repaint();
this.panelCentral.revalidate();
this.panel.setBackground(Color.WHITE);
this.panelGestion.setBackground(Color.WHITE);
this.panelModificar.setBackground(Color.WHITE);
this.panel.repaint();
this.panel.revalidate();
break;
@@ -287,7 +321,8 @@ public class Menu extends JFrame{
this.panelCentral.setBackground(Color.PINK);
this.panelCentral.repaint();
this.panelCentral.revalidate();
this.panel.setBackground(Color.PINK);
this.panelGestion.setBackground(Color.PINK);
this.panelModificar.setBackground(Color.PINK);
this.panel.repaint();
this.panel.revalidate();
break;
@@ -302,7 +337,8 @@ public class Menu extends JFrame{
this.panelCentral.setBackground(Color.BLACK);
this.panelCentral.repaint();
this.panelCentral.revalidate();
this.panel.setBackground(Color.BLACK);
this.panelGestion.setBackground(Color.BLACK);
this.panelModificar.setBackground(Color.BLACK);
this.panel.repaint();
this.panel.revalidate();
break;
@@ -311,4 +347,30 @@ public class Menu extends JFrame{
}
}
void cambiarVista(int vista) {
GridBagConstraints constrain = new GridBagConstraints();
this.panelCentral.remove(this.panel);
constrain = new GridBagConstraints();
constrain.fill = GridBagConstraints.HORIZONTAL;
constrain.gridx = 1;
constrain.gridy = 2;
constrain.weightx = 0.25;
switch(vista) {
case Menu.VISTA_GESTION:{
this.panel = this.panelGestion;
break;
}
case Menu.VISTA_MODIFICAR:{
this.panel = this.panelModificar;
break;
}
}
this.panelCentral.add(this.panel,constrain);
this.panel.repaint();
this.panel.revalidate();
this.panelCentral.repaint();
this.panelCentral.revalidate();
}
}