Mejoras de estilo y otros

This commit is contained in:
roche
2019-11-14 12:05:58 +01:00
parent 0ade46bde2
commit 667182d76e
13 changed files with 126 additions and 109 deletions

View File

@@ -12,7 +12,7 @@ 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) {
public Component getListCellRendererComponent(JList<? extends E> list, E value, int index, boolean isSelected, boolean cellHasFocus) {
setComponentOrientation(list.getComponentOrientation());
setFont(list.getFont());

View File

@@ -13,20 +13,20 @@ public class ControladorAniadirVisualizar implements ActionListener,ChangeListen
private VistaAniadirVisualizar vista;
public ControladorAniadirVisualizar(VistaAniadirVisualizar vista) {
this.vista=vista;
this.vista = vista;
this.aniadirListeners();
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals(this.vista.boton.getActionCommand())) {
String nombre=JOptionPane.showInputDialog("Introduce un nuevo gasto o ingreso");
if(nombre==null) return;
if(nombre == null) return;
if(nombre.equals("")) {
JOptionPane.showMessageDialog(null, "Debe introducir algo", "error", JOptionPane.WARNING_MESSAGE);
return;
}
String dinero=JOptionPane.showInputDialog("Introduce a cuanto asciende");
if(dinero==null) return;
String dinero = JOptionPane.showInputDialog("Introduce a cuanto asciende");
if(dinero == null) return;
if(dinero.equals("")) {
JOptionPane.showMessageDialog(null, "Debe introducir algo", "error", JOptionPane.WARNING_MESSAGE);
return;
@@ -41,8 +41,8 @@ public class ControladorAniadirVisualizar implements ActionListener,ChangeListen
JOptionPane.showMessageDialog(null, "Debe introducir un numero", "error", JOptionPane.WARNING_MESSAGE);
}
}else {
JCheckBox pulsado=(JCheckBox)e.getSource();
for(int i=0;i<vista.gestiones.getElementos().size();i++) {
JCheckBox pulsado = (JCheckBox)e.getSource();
for(int i = 0; i < vista.gestiones.getElementos().size();i++) {
if(vista.gestiones.getElementos().get(i).toString().equals(pulsado.getText())) {
vista.gestiones.alterarVisibilidad(i);
this.vista.menu.panel.actualizarDatos(this.vista.gestiones);
@@ -56,7 +56,7 @@ public class ControladorAniadirVisualizar implements ActionListener,ChangeListen
private void aniadirListeners() {
vista.boton.addActionListener(this);
vista.boton.setActionCommand("Aniadir");
int contador=0;
int contador = 0;
for(JCheckBox check:this.vista.transacciones) {
check.addActionListener(this);
check.setActionCommand("pulsar "+contador);

View File

@@ -26,33 +26,30 @@ public class ControladorPanelLateral implements ActionListener, DateChangeListen
public ControladorPanelLateral(VistaPanelLateral vista) {
this.vista=vista;
this.vista = vista;
this.aniadirElementos();
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals(this.vista.mostrarEstadisticas.getActionCommand())) {
XYSeries serie=new XYSeries("Mes");
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);
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);
}
//}else if(e.getActionCommand().equals(this.vista.elegirMes.getActionCommand())){
//}
}
private void aniadirElementos() {
this.vista.mostrarEstadisticas.addActionListener(this);
this.vista.mostrarEstadisticas.setActionCommand("Mostrar estadisticas");
if(VistaPanelLateral.elegirMes.getDateChangeListeners().size()==0) {
if(VistaPanelLateral.elegirMes.getDateChangeListeners().size() == 0) {
VistaPanelLateral.elegirMes.addDateChangeListener(this);
this.mes=VistaPanelLateral.elegirMes.getDate().getMonth();
this.anio=VistaPanelLateral.elegirMes.getDate().getYear();

View File

@@ -24,19 +24,19 @@ public class Menu extends JFrame{
protected Gestion datosIngresos;
public Menu() {
VistaAniadirVisualizar.setPanelLateral(panel);
this.datosGastos=new Gestion();
this.datosIngresos=new Gestion();
this.datosGastos = new Gestion();
this.datosIngresos = new Gestion();
this.setLayout(new GridBagLayout());
GridBagConstraints constrain=new GridBagConstraints();
this.panel=new VistaPanelLateral(constrain);
this.ingresos=new VistaAniadirVisualizar(this,datosIngresos,true);
this.gastos=new VistaAniadirVisualizar(this,datosGastos,false);
this.panelCentral=new JPanel();
this.pestania=new JTabbedPane();
constrain.fill=GridBagConstraints.VERTICAL;
constrain.gridx=0;
constrain.gridy=0;
constrain.weightx=2;
GridBagConstraints constrain = new GridBagConstraints();
this.panel = new VistaPanelLateral(constrain);
this.ingresos = new VistaAniadirVisualizar(this,datosIngresos,true);
this.gastos = new VistaAniadirVisualizar(this,datosGastos,false);
this.panelCentral = new JPanel();
this.pestania = new JTabbedPane();
constrain.fill = GridBagConstraints.VERTICAL;
constrain.gridx = 0;
constrain.gridy = 0;
constrain.weightx = 2;
this.panelCentral.add(pestania,constrain);
this.pestania.addTab("Ingresos", ingresos);
this.pestania.addTab("Gastos", gastos);
@@ -45,17 +45,12 @@ public class Menu extends JFrame{
setSize(new Dimension(420,320));
setDefaultCloseOperation(3);
setLocationRelativeTo(null);
ControladorAniadirVisualizar controlador=new ControladorAniadirVisualizar(this.ingresos);
ControladorAniadirVisualizar controlador2=new ControladorAniadirVisualizar(this.gastos);
ControladorPanelLateral controlador3=new ControladorPanelLateral(this.panel);
/*constrain.fill=GridBagConstraints.HORIZONTAL;
constrain.gridx=1;
constrain.gridy=0;
constrain.weightx=1;
constrain.weighty=2;*/
ControladorAniadirVisualizar controlador = new ControladorAniadirVisualizar(this.ingresos);
ControladorAniadirVisualizar controlador2 = new ControladorAniadirVisualizar(this.gastos);
ControladorPanelLateral controlador3 = new ControladorPanelLateral(this.panel);
this.panel.actualizarDatos(datosIngresos);
this.pestania.addChangeListener((ChangeListener)->{
if(this.pestania.getSelectedIndex()==0) {
if(this.pestania.getSelectedIndex() == 0) {
this.panel.actualizarDatos(datosIngresos);
}else {
this.panel.actualizarDatos(datosGastos);
@@ -64,6 +59,4 @@ public class Menu extends JFrame{
this.add(this.panel);
}
}

View File

@@ -23,16 +23,15 @@ public class VistaAniadirVisualizar extends JPanel{
boolean positivo;
static VistaPanelLateral panelLateral;
public VistaAniadirVisualizar(Menu menu, Gestion gestion,boolean positivo) {
this.positivo=positivo;
this.gestiones=gestion;
this.transacciones=new LinkedList<JCheckBox>();
this.menu=menu;
this.x=100;
this.boton=new JButton("aniadir");
//this.gestiones=new Gestion();
this.positivo = positivo;
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.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));
@@ -42,19 +41,19 @@ public class VistaAniadirVisualizar extends JPanel{
}
public static void setPanelLateral(VistaPanelLateral panel) {
VistaAniadirVisualizar.panelLateral=panel;
VistaAniadirVisualizar.panelLateral = panel;
}
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);
JCheckBox check=new JCheckBox(transaccion.toString());
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;
this.y += VistaAniadirVisualizar.altoCheck;
cuadro.setPreferredSize(new Dimension(x, y));
this.revalidate();
this.repaint();

View File

@@ -17,32 +17,32 @@ public class VistaPanelLateral extends JPanel{
protected JTextArea total;
protected JTextArea gastoEnvio;
//protected JButton elegirMes;
protected static DatePicker elegirMes=inicializarCalendario();
protected static DatePicker elegirMes = inicializarCalendario();
protected JButton mostrarEstadisticas;
VistaPanelLateral(GridBagConstraints constrain){
this.setPreferredSize(new Dimension(200,200));
this.total=new JTextArea();
this.gastoEnvio=new JTextArea();
this.mostrarEstadisticas=new JButton("Mostrar grafico del mes");
this.total = new JTextArea();
this.gastoEnvio = new JTextArea();
this.mostrarEstadisticas = new JButton("Mostrar grafico del mes");
this.add(this.mostrarEstadisticas);
constrain.gridx=1;
constrain.gridy=0;
constrain.weightx=2;
constrain.gridx = 1;
constrain.gridy = 0;
constrain.weightx = 2;
this.add(VistaPanelLateral.elegirMes);
constrain.gridx=1;
constrain.gridy=1;
constrain.weightx=2;
constrain.gridx = 1;
constrain.gridy = 1;
constrain.weightx = 2;
this.add(this.total);
constrain.gridx=1;
constrain.gridy=2;
constrain.weightx=2;
constrain.gridx = 1;
constrain.gridy = 2;
constrain.weightx = 2;
this.add(this.gastoEnvio);
}
void actualizarDatos(Gestion gestion) {
this.total.setText("Total: "+String.valueOf(Gestion.getTotal())+"");
this.gastoEnvio.setText("Suma: "+String.valueOf(gestion.getSuma())+"");
this.total.setText("Total: " + String.valueOf(Gestion.getTotal()) + "");
this.gastoEnvio.setText("Suma: " + String.valueOf(gestion.getSuma()) + "");
}
static LocalDate getDate() {
@@ -50,7 +50,7 @@ public class VistaPanelLateral extends JPanel{
}
static DatePicker inicializarCalendario() {
DatePicker ret=new DatePicker();
DatePicker ret = new DatePicker();
ret.setDate(LocalDate.now());
return ret;
}