123 lines
3.5 KiB
Java
123 lines
3.5 KiB
Java
package VistaControlador;
|
|
|
|
import java.awt.Dimension;
|
|
import java.util.LinkedList;
|
|
|
|
import javax.swing.JButton;
|
|
import javax.swing.JCheckBox;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JScrollPane;
|
|
|
|
import Logica.*;
|
|
|
|
public class VistaAniadirVisualizar extends JPanel{
|
|
private int x,y;
|
|
private static final int altoCheck=28;
|
|
protected Gestion gestiones;
|
|
protected JButton boton;
|
|
protected LinkedList<JCheckBox> transacciones;
|
|
JPanel cuadro;
|
|
JScrollPane panel;
|
|
Menu menu;
|
|
private ControladorAniadirVisualizar controlador;
|
|
private static VistaPanelLateral panelLateral;
|
|
|
|
/*
|
|
* Constructor de la ventana que contendra las pestanias
|
|
*
|
|
* @param menu menu donde se guardaran
|
|
* @param gestion gestion de la pestania
|
|
*/
|
|
public VistaAniadirVisualizar(Menu menu, Gestion gestion) {
|
|
this.gestiones = gestion;
|
|
this.transacciones = new LinkedList<JCheckBox>();
|
|
this.menu = menu;
|
|
this.x = 100;
|
|
this.boton = new JButton("aniadir");
|
|
this.add(boton);
|
|
this.cuadro = new JPanel();
|
|
this.panel = new JScrollPane(cuadro);
|
|
this.panel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
|
this.panel.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
|
cuadro.setPreferredSize(new Dimension(x, y));
|
|
panel.setPreferredSize(new Dimension(100,200));
|
|
panel.setVisible(true);
|
|
this.add(panel);
|
|
}
|
|
|
|
/*
|
|
* Establece cual es el panel lateral
|
|
*
|
|
* @param panel panel lateral que gestionara este panel
|
|
*/
|
|
public static void setPanelLateral(VistaPanelLateral panel) {
|
|
VistaAniadirVisualizar.panelLateral = panel;
|
|
}
|
|
|
|
public String getName() {
|
|
return this.gestiones.getNombre();
|
|
}
|
|
|
|
/*
|
|
* Inicia la gestion
|
|
*/
|
|
void iniciarGestion() {
|
|
for(Transaccion transaccion:this.gestiones.getElementos()) {
|
|
this.aniadirElemento(transaccion);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Aniade una nueva transaccion introduciendo sus datos
|
|
*
|
|
* @param nombre nombre de la transaccion
|
|
* @param dinero dinero de la transaccion
|
|
* @para controlador controlador de la casilla que de aniadira
|
|
*/
|
|
public void aniadirElemento(String nombre, float dinero, ControladorAniadirVisualizar controlador) {
|
|
Transaccion transaccion = new Transaccion(nombre, dinero,panelLateral.getDate(),this.gestiones);
|
|
this.gestiones.aniadirGasto(transaccion);
|
|
JCheckBox check = new JCheckBox(transaccion.toString());
|
|
check.setSelected(true);
|
|
check.setSize(new Dimension(x,VistaAniadirVisualizar.altoCheck));
|
|
check.addActionListener(controlador);
|
|
this.transacciones.add(check);
|
|
this.cuadro.add(check);
|
|
this.y += VistaAniadirVisualizar.altoCheck;
|
|
cuadro.setPreferredSize(new Dimension(x, y));
|
|
this.revalidate();
|
|
this.repaint();
|
|
}
|
|
|
|
/*
|
|
* Elimina las casillas deseleccionadas
|
|
*/
|
|
void eliminarDeseleccionados(){
|
|
for(JCheckBox check:this.transacciones) {
|
|
if(!check.isSelected()) {
|
|
this.cuadro.remove(check);
|
|
this.gestiones.eliminarTransaccion(check.getText());
|
|
this.cuadro.revalidate();
|
|
this.cuadro.repaint();
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
* aniade una nueva transaccion
|
|
*/
|
|
private void aniadirElemento(Transaccion transaccion) {
|
|
JCheckBox check = new JCheckBox(transaccion.toString());
|
|
check.setSelected(true);
|
|
check.setSize(new Dimension(x,VistaAniadirVisualizar.altoCheck));
|
|
check.addActionListener(this.boton.getActionListeners()[0]);
|
|
this.transacciones.add(check);
|
|
this.cuadro.add(check);
|
|
this.y += VistaAniadirVisualizar.altoCheck;
|
|
cuadro.setPreferredSize(new Dimension(x, y));
|
|
this.revalidate();
|
|
this.repaint();
|
|
}
|
|
}
|