From 667182d76e952cc7473b1bbcbd3dad2bd99bbc49 Mon Sep 17 00:00:00 2001 From: roche <roche@localhost> Date: Thu, 14 Nov 2019 12:05:58 +0100 Subject: [PATCH] Mejoras de estilo y otros --- bin/.gitignore | 1 + bin/Logica/Transaccion.class | Bin 1663 -> 1663 bytes src/IniciarSesion/Usuario.java | 27 ++++++++++++ src/IniciarSesion/Validacion.java | 8 ++++ src/Logica/Gestion.java | 30 +++++++------- src/Logica/Meses.java | 13 +++--- src/Logica/Transaccion.java | 29 ++++++------- src/VistaControlador/CheckBoxList.java | 2 +- .../ControladorAniadirVisualizar.java | 14 +++---- .../ControladorPanelLateral.java | 15 +++---- src/VistaControlador/Menu.java | 39 +++++++----------- .../VistaAniadirVisualizar.java | 25 ++++++----- src/VistaControlador/VistaPanelLateral.java | 32 +++++++------- 13 files changed, 126 insertions(+), 109 deletions(-) create mode 100644 src/IniciarSesion/Usuario.java create mode 100644 src/IniciarSesion/Validacion.java diff --git a/bin/.gitignore b/bin/.gitignore index dfe691c..1871611 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,2 +1,3 @@ /VistaControlador/ /Logica/ +/IniciarSesion/ diff --git a/bin/Logica/Transaccion.class b/bin/Logica/Transaccion.class index e330ed93f65df4493689b78fcac169b9889c2dc2..30dd48f581dbb4ca5d4d489aaab012a673ec898e 100644 GIT binary patch delta 41 rcmey*^PgwK3sy$0$&Rd|lmD@*GwOj^)@<sGMj#fuCj$cm6N48384C(u delta 41 rcmey*^PgwK3sy$`$&Rd|lmD@*Ga7?g)@<sG<{%ckCj$cm6N4838e|G? diff --git a/src/IniciarSesion/Usuario.java b/src/IniciarSesion/Usuario.java new file mode 100644 index 0000000..ee59957 --- /dev/null +++ b/src/IniciarSesion/Usuario.java @@ -0,0 +1,27 @@ +package IniciarSesion; + +import java.io.Serializable; + +public class Usuario implements Serializable{ + String nombre; + String contrasenia; + boolean admin; + + public Usuario(String nombre, String contrasenia, boolean admin) { + this.admin = admin; + this.nombre = nombre; + this.contrasenia = contrasenia; + } + + public boolean comprobar(String contrasenia) { + if(this.contrasenia.equals(contrasenia)) { + return true; + } + return false; + } + + public String getUsuario() { + return this.nombre; + } + +} diff --git a/src/IniciarSesion/Validacion.java b/src/IniciarSesion/Validacion.java new file mode 100644 index 0000000..f9ad8dd --- /dev/null +++ b/src/IniciarSesion/Validacion.java @@ -0,0 +1,8 @@ +package IniciarSesion; + +import java.io.File; + +public class Validacion { + File fichero; + +} diff --git a/src/Logica/Gestion.java b/src/Logica/Gestion.java index 38414fa..d24f556 100644 --- a/src/Logica/Gestion.java +++ b/src/Logica/Gestion.java @@ -13,15 +13,15 @@ public class Gestion{ public Gestion() { this.gestiones=new Vector<Transaccion>(); - this.suma=0; - Gestion.total=0; + this.suma = 0; + Gestion.total = 0; } public Gestion(String nombre) { - this.gestiones=new Vector<Transaccion>(); - this.suma=0; - Gestion.total=0; - this.nombre=nombre; + this.gestiones = new Vector<Transaccion>(); + this.suma = 0; + Gestion.total = 0; + this.nombre = nombre; } public String getNombre() { @@ -30,11 +30,11 @@ public class Gestion{ public void aniadirGasto(Transaccion transaccion) { this.gestiones.add(transaccion); - this.suma+=transaccion.getDinero(); + this.suma += transaccion.getDinero(); if(transaccion.isPositivo()) { - Gestion.total+=transaccion.getDinero(); + Gestion.total += transaccion.getDinero(); }else { - Gestion.total-=transaccion.getDinero(); + Gestion.total -= transaccion.getDinero(); } } @@ -52,18 +52,18 @@ public class Gestion{ public void alterarVisibilidad(int elemento) { if(this.gestiones.get(elemento).alterarVisivilidad()) { - this.suma+=this.gestiones.get(elemento).getDinero(); + this.suma += this.gestiones.get(elemento).getDinero(); if(this.gestiones.get(elemento).isPositivo()) { - Gestion.total+=this.gestiones.get(elemento).getDinero(); + Gestion.total += this.gestiones.get(elemento).getDinero(); }else { - Gestion.total-=this.gestiones.get(elemento).getDinero(); + Gestion.total -= this.gestiones.get(elemento).getDinero(); } }else { - this.suma-=this.gestiones.get(elemento).getDinero(); + this.suma -= this.gestiones.get(elemento).getDinero(); if(this.gestiones.get(elemento).isPositivo()) { - Gestion.total-=this.gestiones.get(elemento).getDinero(); + Gestion.total -= this.gestiones.get(elemento).getDinero(); }else { - Gestion.total+=this.gestiones.get(elemento).getDinero(); + Gestion.total += this.gestiones.get(elemento).getDinero(); } } } diff --git a/src/Logica/Meses.java b/src/Logica/Meses.java index e9883fb..fd520f1 100644 --- a/src/Logica/Meses.java +++ b/src/Logica/Meses.java @@ -8,13 +8,13 @@ private ArrayList<Mes> meses; private int mesActual=0; public Meses() { - this.meses=new ArrayList<Mes>(); + this.meses = new ArrayList<Mes>(); } public void aniadirTransaccion(Transaccion transaccion, String nombre) { for(Mes mes:this.meses) { if(transaccion.getDia().getMonth().equals(mes.getMes()) && - transaccion.getDia().getYear()==mes.getAnio()){ + transaccion.getDia().getYear() == mes.getAnio()){ mes.aniadirTransaccion(transaccion, nombre); return; } @@ -24,9 +24,9 @@ private ArrayList<Mes> meses; } public void elegirMes(int anio, Month mes) { - for(int i=0;i<this.meses.size();i++) { + for(int i = 0; i < this.meses.size(); i++) { if(this.meses.get(i).getAnio()==anio && this.meses.get(i).getMes().equals(mes)) { - this.mesActual=0; + this.mesActual = 0; } } } @@ -35,9 +35,6 @@ private ArrayList<Mes> meses; return this.meses.get(this.mesActual).getGestiones(); } - - - } class Mes{ @@ -46,7 +43,7 @@ class Mes{ int total; ArrayList<Gestion> gestiones; Mes(ArrayList<Gestion> gestiones){ - this.gestiones=gestiones; + this.gestiones = gestiones; } void aniadirTransaccion(Transaccion transaccion, String nombre) { diff --git a/src/Logica/Transaccion.java b/src/Logica/Transaccion.java index e5700fd..1d4e94e 100644 --- a/src/Logica/Transaccion.java +++ b/src/Logica/Transaccion.java @@ -10,23 +10,23 @@ public class Transaccion { private boolean positivo; public Transaccion(String nombre, float dinero){ - this.nombre=nombre; - this.dinero=dinero; - this.visible=true; - this.dia=LocalDate.now(); - this.positivo=true; + this.nombre = nombre; + this.dinero = dinero; + this.visible = true; + this.dia = LocalDate.now(); + this.positivo = true; } public Transaccion(String nombre, float dinero, LocalDate dia, boolean positivo){ - this.nombre=nombre; - this.dinero=dinero; - this.visible=true; - this.positivo=positivo; - this.dia=dia; + this.nombre = nombre; + this.dinero = dinero; + this.visible = true; + this.positivo = positivo; + this.dia = dia; } public String toString() { - return this.nombre+" "+this.dinero; + return this.nombre + " " + this.dinero; } public boolean getVisivilidad() { @@ -34,16 +34,11 @@ public class Transaccion { } public boolean alterarVisivilidad() { - this.visible=!this.visible; + this.visible =! this.visible; return this.visible; } public float getDinero() { - /*if(positivo) { - return this.dinero; - }else { - return -this.dinero; - }*/ return this.dinero; } diff --git a/src/VistaControlador/CheckBoxList.java b/src/VistaControlador/CheckBoxList.java index 5de3ef2..b666d2a 100644 --- a/src/VistaControlador/CheckBoxList.java +++ b/src/VistaControlador/CheckBoxList.java @@ -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()); diff --git a/src/VistaControlador/ControladorAniadirVisualizar.java b/src/VistaControlador/ControladorAniadirVisualizar.java index 325b857..bf0cfff 100644 --- a/src/VistaControlador/ControladorAniadirVisualizar.java +++ b/src/VistaControlador/ControladorAniadirVisualizar.java @@ -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); diff --git a/src/VistaControlador/ControladorPanelLateral.java b/src/VistaControlador/ControladorPanelLateral.java index d569405..9f873f1 100644 --- a/src/VistaControlador/ControladorPanelLateral.java +++ b/src/VistaControlador/ControladorPanelLateral.java @@ -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(); diff --git a/src/VistaControlador/Menu.java b/src/VistaControlador/Menu.java index e80c6b5..d40be6a 100644 --- a/src/VistaControlador/Menu.java +++ b/src/VistaControlador/Menu.java @@ -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); } - - } diff --git a/src/VistaControlador/VistaAniadirVisualizar.java b/src/VistaControlador/VistaAniadirVisualizar.java index e001dec..0b678c9 100644 --- a/src/VistaControlador/VistaAniadirVisualizar.java +++ b/src/VistaControlador/VistaAniadirVisualizar.java @@ -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(); diff --git a/src/VistaControlador/VistaPanelLateral.java b/src/VistaControlador/VistaPanelLateral.java index 8999f45..2120abf 100644 --- a/src/VistaControlador/VistaPanelLateral.java +++ b/src/VistaControlador/VistaPanelLateral.java @@ -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; }