Creada ventana principal para mostrar el resto de ellas en un cardlayout!

This commit is contained in:
Daniel Cortes
2018-12-20 13:00:26 -03:00
parent a5cbe93151
commit dd52ef3975
9 changed files with 213 additions and 22 deletions

View File

@@ -24,12 +24,8 @@
package danielcortes.xyz; package danielcortes.xyz;
import danielcortes.xyz.controllers.CajaController; import danielcortes.xyz.controllers.ManagerController;
import danielcortes.xyz.models.EgresoDAO; import danielcortes.xyz.views.ManagerView;
import danielcortes.xyz.models.TipoEgresoDAO;
import danielcortes.xyz.models.mysql.MysqlEgresoDAO;
import danielcortes.xyz.models.mysql.MysqlTipoEgresoDAO;
import danielcortes.xyz.views.CajaView;
import javax.swing.*; import javax.swing.*;
@@ -43,18 +39,13 @@ public class Main {
} }
CajaView view = new CajaView(); ManagerView view = new ManagerView();
JFrame frame = new JFrame("Caja"); JFrame frame = new JFrame("Caja");
frame.setContentPane(view.getUI()); frame.setContentPane(view.getContentPanel());
frame.setContentPane(view.contentPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1300,700); frame.setSize(1300,700);
frame.setLocationRelativeTo(null); frame.setLocationRelativeTo(null);
ManagerController managerController = new ManagerController(view);
EgresoDAO egresoDAO = new MysqlEgresoDAO();
TipoEgresoDAO tipoEgresoDAO = new MysqlTipoEgresoDAO();
CajaController cajaController = new CajaController(view, egresoDAO, tipoEgresoDAO);
frame.setVisible(true); frame.setVisible(true);

View File

@@ -28,17 +28,16 @@ import danielcortes.xyz.models.Egreso;
import danielcortes.xyz.models.EgresoDAO; import danielcortes.xyz.models.EgresoDAO;
import danielcortes.xyz.models.TipoEgreso; import danielcortes.xyz.models.TipoEgreso;
import danielcortes.xyz.models.TipoEgresoDAO; import danielcortes.xyz.models.TipoEgresoDAO;
import danielcortes.xyz.views.CajaView; import danielcortes.xyz.views.EgresosView;
import javax.swing.*; import javax.swing.*;
public class CajaController { public class CajaController {
private CajaView view; private EgresosView view;
private EgresoDAO egresoDAO; private EgresoDAO egresoDAO;
private TipoEgresoDAO tipoEgresoDAO; private TipoEgresoDAO tipoEgresoDAO;
public CajaController(CajaView view, EgresoDAO egresoDAO, TipoEgresoDAO tipoEgresoDAO){ public CajaController(EgresosView view, EgresoDAO egresoDAO, TipoEgresoDAO tipoEgresoDAO){
this.view = view; this.view = view;
this.egresoDAO = egresoDAO; this.egresoDAO = egresoDAO;
this.tipoEgresoDAO = tipoEgresoDAO; this.tipoEgresoDAO = tipoEgresoDAO;

View File

@@ -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);
}
}

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="danielcortes.xyz.views.CajaView"> <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="danielcortes.xyz.views.EgresosView">
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="15" left="15" bottom="15" right="15"/> <margin top="15" left="15" bottom="15" right="15"/>
<constraints> <constraints>

View File

@@ -31,7 +31,7 @@ import javax.swing.*;
import javax.swing.plaf.basic.BasicComboBoxRenderer; import javax.swing.plaf.basic.BasicComboBoxRenderer;
import java.awt.*; import java.awt.*;
public class CajaView { public class EgresosView {
public JPanel contentPanel; public JPanel contentPanel;
private JPanel egresosPanel; private JPanel egresosPanel;
private JTable egresosTable; private JTable egresosTable;
@@ -54,7 +54,7 @@ public class CajaView {
egresosTable.setAutoCreateRowSorter(true); egresosTable.setAutoCreateRowSorter(true);
} }
public JPanel getUI() { public JPanel getContentPanel() {
return contentPanel; return contentPanel;
} }

View File

@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="danielcortes.xyz.views.ManagerView">
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="829" height="539"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="b2933" binding="controlsPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="10" vgap="10">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="2ed8e" class="javax.swing.JButton" binding="egresosButton">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="200" height="-1"/>
<preferred-size width="200" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Egresos"/>
</properties>
</component>
<component id="f54ab" class="javax.swing.JButton" binding="ingresosButton">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="200" height="-1"/>
<preferred-size width="200" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Ingresos"/>
</properties>
</component>
<component id="93758" class="javax.swing.JButton" binding="button3" default-binding="true">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="200" height="-1"/>
<preferred-size width="200" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Button"/>
</properties>
</component>
<component id="48887" class="javax.swing.JButton" binding="button4" default-binding="true">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="200" height="-1"/>
<preferred-size width="200" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Button"/>
</properties>
</component>
</children>
</grid>
<grid id="100a8" binding="cardPanel" layout-manager="CardLayout" hgap="10" vgap="10">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
</form>

View File

@@ -0,0 +1,53 @@
/*
* 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.views;
import javax.swing.*;
public class ManagerView {
private JButton egresosButton;
private JButton ingresosButton;
private JButton button3;
private JButton button4;
private JPanel contentPanel;
private JPanel cardPanel;
private JPanel controlsPanel;
public JButton getEgresosButton() {
return egresosButton;
}
public JButton getIngresosButton() {
return ingresosButton;
}
public JPanel getContentPanel() {
return contentPanel;
}
public JPanel getCardPanel() {
return cardPanel;
}
}

View File

@@ -29,6 +29,7 @@ import java.util.ArrayList;
public abstract class TableModel extends AbstractTableModel { public abstract class TableModel extends AbstractTableModel {
private ArrayList<String[]> rows = new ArrayList<>(); private ArrayList<String[]> rows = new ArrayList<>();
public int getRowCount() { public int getRowCount() {
return rows.size(); return rows.size();
} }