/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package carcel.controllers;
import carcel.constant.CarcelConstants;
import carcel.constant.VistasCarceles;
import carcel.reportes.ImpresorReportes;
import carcel.views.PanelListener;
import carcel.views.PrincipalView;
import carcel.views.WindowsCreator;
import entidades.Usuario;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import net.sf.jasperreports.engine.JRException;
//import net.sf.jasperreports.engine.JRException;
/**
*
* @author Marcelo
*/
public class PrincipalController extends PrincipalView {
//Instanccia estatica para evitar se creen mas de una instancia del copntrolador de la ventana principal.
private static PrincipalController principalController;
private static Usuario usuario;
public static JFrame instanciaControllerPrincipal() {
return getInstance(usuario);
}
static Usuario getLogedUser() {
return usuario;
}
public PrincipalController(Usuario usuario) {
super();
//ControlAccesoController co = new ControlAccesoController();
VistasCarceles.inicializarVistas();
//agrego los controladores de los menus
addMenusHandlers();
principalController = this;
}
public static PrincipalController getInstance(Usuario usuario) {
//Si no esta instanciado creo una
/*if (principalController == null) {
principalController = new PrincipalController(usuario);
}*/
//si esta instanciado, devuelvo la primer instancia creada.
return principalController;
}
/**
* Este metoddo le da los handlers a los menus principales
*/
private void addMenusHandlers() {
//pabellones ----------------------------------------------------------
pabellonMnu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//Nuevo Pabellon desde el menu, por eso va null en pabellon
PabellonController pabellonController = new PabellonController(usuario, null);
final WindowsCreator wc = new WindowsCreator(principalController, pabellonController, true);
pabellonController.setPanelListener(new PanelListener() {
public void onPanelClose() {
wc.dispose();
}
});
}
});
gestionPabellonMnu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PabellonListPanelController pabellonListPanelController = new PabellonListPanelController(principalController);
final WindowsCreator wc = new WindowsCreator(principalController, pabellonListPanelController, true);
pabellonListPanelController.setPanelListener(new PanelListener() {
public void onPanelClose() {
wc.dispose();
}
});
}
});
//CELDAS................................................................
celdaMnu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
CeldaController celdaController = new CeldaController();
final WindowsCreator wc = new WindowsCreator(principalController, celdaController, true);
celdaController.setPanelListener(new PanelListener() {
public void onPanelClose() {
wc.dispose();
}
});
}
});
//Presos ---------------------------------------------------------------
presoMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PresoController presoController = new PresoController(usuario, null, CarcelConstants.OPERACION_ALTA);
final WindowsCreator wc = new WindowsCreator(principalController, presoController, true);
presoController.setPanelListener(new PanelListener() {
public void onPanelClose() {
wc.dispose();
}
});
}
});
gestionpreso.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PresoListPanelController presoListPanelController = new PresoListPanelController();
final WindowsCreator wc = new WindowsCreator(principalController, presoListPanelController, true);
presoListPanelController.setPanelListener(new PanelListener() {
public void onPanelClose() {
wc.dispose();
}
});
}
});
//Estados---------------------------------------------------------------
//motivos---------------------------------------------------------------
motivoMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MotivosDelPresoController motivosDelPresoController = new MotivosDelPresoController(null);
final WindowsCreator wc = new WindowsCreator(principalController, motivosDelPresoController, true);
motivosDelPresoController.setPanelListener(new PanelListener() {
public void onPanelClose() {
wc.dispose();
}
});
}
});
//condena---------------------------------------------------------------
asignarCondenaItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
CondenaController controller = new CondenaController(null, true);
final WindowsCreator wc = new WindowsCreator(principalController, controller, true);
controller.setPanelListener(new PanelListener() {
public void onPanelClose() {
wc.dispose();
}
});
}
});
gestionusuariomenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
UsuarioListPanelController usuariocontrolador = new UsuarioListPanelController();
final WindowsCreator wc = new WindowsCreator(principalController, usuariocontrolador, true);
usuariocontrolador.setPanelListener(new PanelListener() {
public void onPanelClose() {
wc.dispose();
}
});
}
});
//VISITA----------------------------------------------------------------
visitasMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
VisitasController visitasController = new VisitasController(null);
final WindowsCreator wc = new WindowsCreator(principalController, visitasController, true);
visitasController.setPanelListener(new PanelListener() {
public void onPanelClose() {
wc.dispose();
}
});
}
});
reasignacionPresoMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
AsignacionPresoController apc = new AsignacionPresoController(null, true);
final WindowsCreator creator = new WindowsCreator(PrincipalController.this, apc,false );
apc.setPanelListener(new PanelListener() {
public void onPanelClose() {
creator.dispose();
}
});
}
});
impMotivoMnu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ImportarMotivosController imc = new ImportarMotivosController();
final WindowsCreator creator = new WindowsCreator(principalController, imc, false);
imc.setListener(new PanelListener() {
public void onPanelClose() {
creator.dispose();
}
});
}
});
//policias--------------------------------------------------------------
gestionpoliciaMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PoliciaListPanelController policiaPanelController = new PoliciaListPanelController();
final WindowsCreator wc = new WindowsCreator(principalController, policiaPanelController, true);
policiaPanelController.setPanelListener(new PanelListener() {
public void onPanelClose() {
wc.dispose();
}
});
}
});
gestionRolMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
RolListPanelController panelcontroladorrol = new RolListPanelController();
final WindowsCreator wc = new WindowsCreator(principalController, panelcontroladorrol, true);
panelcontroladorrol.setPanelListener(new PanelListener() {
public void onPanelClose() {
wc.dispose();
}
});
}
});
policiaMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PoliciaController policiaController = new PoliciaController(null);
final WindowsCreator wc = new WindowsCreator(principalController, policiaController, true);
policiaController.setPanelListener(new PanelListener() {
public void onPanelClose() {
wc.dispose();
}
});
}
});
historicoPresoMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
HistoricoPresoListPanelController historicocontroller = new HistoricoPresoListPanelController();
final WindowsCreator wc = new WindowsCreator(principalController, historicocontroller, true);
historicocontroller.setPanelListener(new PanelListener() {
public void onPanelClose() {
wc.dispose();
}
});
}
});
gestionceldamenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
CeldaListPanelController celdacontroller = new CeldaListPanelController();
final WindowsCreator wc = new WindowsCreator(principalController, celdacontroller, true);
celdacontroller.setPanelListener(new PanelListener() {
public void onPanelClose() {
wc.dispose();
}
});
}
});
cerrarSesion.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// como cierro la pantalla
PrincipalController.this.dispose();
ControlAccesoController control = new ControlAccesoController();
}
});
salirPrograma.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PrincipalController.this.dispose();
}
});
asignarPabellonMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ResponsableController responsableController = new ResponsableController(null);
final WindowsCreator wc = new WindowsCreator(principalController, responsableController, true);
responsableController.setPanelListener(new PanelListener() {
public void onPanelClose() {
wc.dispose();
}
});
}
});
movimientoAComedorMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MovimientoAComedorController movimientoAComedorController = new MovimientoAComedorController();
final WindowsCreator wc = new WindowsCreator(principalController, movimientoAComedorController, true);
movimientoAComedorController.setPanelListener(new PanelListener() {
public void onPanelClose() {
wc.dispose();
}
});
}
});
// ------------------------------------------REPORTES-------------------------------------------------------
lgpreso.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
ImpresorReportes.ImprimirReportePresos();
} catch (JRException ex) {
Logger.getLogger(PrincipalController.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
historicoPresoMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ImpresorReportes.imprimirHistorico();
}
});
lgceldas.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
ImpresorReportes.ImprimirReporteCeldas();
} catch (JRException ex) {
Logger.getLogger(PrincipalController.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
lgmovpreso.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//ImpresorReportes.
}
});
lgpolicias.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
ImpresorReportes.ImprimirReportePolicia();
} catch (JRException ex) {
Logger.getLogger(PrincipalController.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
lpaliberar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
ImpresorReportes.ImprimirReportePresosALiberar();
} catch (JRException ex) {
Logger.getLogger(PrincipalController.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
lvpresos.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
ImpresorReportes.ImprimirReporteVisitasAPreso();
} catch (JRException ex) {
Logger.getLogger(PrincipalController.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
}