diff --git a/src/main/java/danielcortes/xyz/Main.java b/src/main/java/danielcortes/xyz/Main.java index 43d2e8e..cbd5520 100644 --- a/src/main/java/danielcortes/xyz/Main.java +++ b/src/main/java/danielcortes/xyz/Main.java @@ -24,12 +24,8 @@ package danielcortes.xyz; -import danielcortes.xyz.controllers.CajaController; -import danielcortes.xyz.models.EgresoDAO; -import danielcortes.xyz.models.TipoEgresoDAO; -import danielcortes.xyz.models.mysql.MysqlEgresoDAO; -import danielcortes.xyz.models.mysql.MysqlTipoEgresoDAO; -import danielcortes.xyz.views.CajaView; +import danielcortes.xyz.controllers.ManagerController; +import danielcortes.xyz.views.ManagerView; import javax.swing.*; @@ -43,18 +39,13 @@ public class Main { } - CajaView view = new CajaView(); + ManagerView view = new ManagerView(); JFrame frame = new JFrame("Caja"); - frame.setContentPane(view.getUI()); - frame.setContentPane(view.contentPanel); + frame.setContentPane(view.getContentPanel()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(1300,700); frame.setLocationRelativeTo(null); - - EgresoDAO egresoDAO = new MysqlEgresoDAO(); - TipoEgresoDAO tipoEgresoDAO = new MysqlTipoEgresoDAO(); - CajaController cajaController = new CajaController(view, egresoDAO, tipoEgresoDAO); - + ManagerController managerController = new ManagerController(view); frame.setVisible(true); diff --git a/src/main/java/danielcortes/xyz/controllers/CajaController.java b/src/main/java/danielcortes/xyz/controllers/CajaController.java index 60f5515..bb97fb2 100644 --- a/src/main/java/danielcortes/xyz/controllers/CajaController.java +++ b/src/main/java/danielcortes/xyz/controllers/CajaController.java @@ -28,17 +28,16 @@ import danielcortes.xyz.models.Egreso; import danielcortes.xyz.models.EgresoDAO; import danielcortes.xyz.models.TipoEgreso; import danielcortes.xyz.models.TipoEgresoDAO; -import danielcortes.xyz.views.CajaView; +import danielcortes.xyz.views.EgresosView; import javax.swing.*; - public class CajaController { - private CajaView view; + private EgresosView view; private EgresoDAO egresoDAO; private TipoEgresoDAO tipoEgresoDAO; - public CajaController(CajaView view, EgresoDAO egresoDAO, TipoEgresoDAO tipoEgresoDAO){ + public CajaController(EgresosView view, EgresoDAO egresoDAO, TipoEgresoDAO tipoEgresoDAO){ this.view = view; this.egresoDAO = egresoDAO; this.tipoEgresoDAO = tipoEgresoDAO; diff --git a/src/main/java/danielcortes/xyz/controllers/ManagerController.java b/src/main/java/danielcortes/xyz/controllers/ManagerController.java new file mode 100644 index 0000000..12f5f30 --- /dev/null +++ b/src/main/java/danielcortes/xyz/controllers/ManagerController.java @@ -0,0 +1,72 @@ +/* + * MIT License + * + * Copyright (c) 2018 Daniel Cortes + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package danielcortes.xyz.controllers; + +import danielcortes.xyz.models.EgresoDAO; +import danielcortes.xyz.models.TipoEgresoDAO; +import danielcortes.xyz.models.mysql.MysqlEgresoDAO; +import danielcortes.xyz.models.mysql.MysqlTipoEgresoDAO; +import danielcortes.xyz.views.EgresosView; +import danielcortes.xyz.views.ManagerView; + +import javax.swing.*; +import java.awt.*; + + +public class ManagerController { + private ManagerView view; + + public ManagerController(ManagerView view) { + this.view = view; + this.loadCardContents(); + this.setUpViewEvents(); + } + + private void setUpViewEvents(){ + this.view.getEgresosButton().addActionListener(e -> { + CardLayout layout = (CardLayout) this.view.getCardPanel().getLayout(); + layout.show(this.view.getCardPanel(),"EGRESOS"); + }); + this.view.getIngresosButton().addActionListener(e -> { + CardLayout layout = (CardLayout) this.view.getCardPanel().getLayout(); + layout.show(this.view.getCardPanel(),"NONE"); + }); + } + + private void loadCardContents(){ + this.view.getCardPanel().add(new JPanel(), "NONE"); + this.loadEgresosView(); + } + + private void loadEgresosView(){ + EgresosView egresosView = new EgresosView(); + EgresoDAO egresoDAO = new MysqlEgresoDAO(); + TipoEgresoDAO tipoEgresoDAO = new MysqlTipoEgresoDAO(); + + this.view.getCardPanel().add(egresosView.getContentPanel(), "EGRESOS"); + + CajaController cajaController = new CajaController(egresosView, egresoDAO, tipoEgresoDAO); + } +} diff --git a/src/main/java/danielcortes/xyz/views/CajaView.form b/src/main/java/danielcortes/xyz/views/EgresosView.form similarity index 99% rename from src/main/java/danielcortes/xyz/views/CajaView.form rename to src/main/java/danielcortes/xyz/views/EgresosView.form index 9f266a7..fbc64a3 100644 --- a/src/main/java/danielcortes/xyz/views/CajaView.form +++ b/src/main/java/danielcortes/xyz/views/EgresosView.form @@ -1,5 +1,5 @@ -