/*
* Main.java
*
* Created on 27 Декабрь 2007 г., 1:40
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package clips;
import beans.reportgen.ReportGeneratorRegister;
import ch.randelshofer.quaqua.jaguar.Quaqua13JaguarTabbedPaneUI;
import ch.randelshofer.quaqua.leopard.Quaqua15LeopardCrossPlatformLookAndFeel;
import cli_fmw.ContextParamsHolder;
import cli_fmw.MainAbstract;
import cli_fmw.delegate.directory.complex.DirectoryEnterpriseAbstract;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.delegate.directory.ro.DirectoryCollaboratorAbstract;
import cli_fmw.delegate.directory.simple.arm.DirectoryArmAbstract;
import cli_fmw.delegate.directory.simple.documentGivenPlace.DirectoryDocumentPlaceAbstract;
import cli_fmw.delegate.directory.simple.documentType.DirectoryDocumentTypeAbstract;
import cli_fmw.delegate.directory.simple.iwtype.DirectoryIWTypeAbstract;
import cli_fmw.delegate.directory.simple.name.DirectoryNameAbstract;
import cli_fmw.delegate.directory.simple.pathron.DirectoryPathronAbstract;
import cli_fmw.delegate.directory.simple.sex.DirectorySexAbstract;
import cli_fmw.delegate.directory.simple.surname.DirectorySurnameAbstract;
import cli_fmw.login.LoginDialogFrame;
import cli_fmw.main.ClipsException;
import cli_fmw.main.MainWindow;
import clips.dicom.dicombaseclass.DICOMException;
import clips.dicom.model.Agregator;
import cli_fmw.utils.MessageBox;
import clips.delegate.directory.complex.DirectoryEnterprise;
import clips.delegate.directory.ro.DirectoryCollaborator;
import clips.delegate.directory.simple.arm.DirectoryArm;
import clips.delegate.directory.simple.clientDocumentType.DirectoryDocumentType;
import clips.delegate.directory.simple.documentGivenPlace.DirectoryDocumentGivenPlace;
import clips.delegate.directory.simple.iwtype.DirectoryIWType;
import clips.delegate.directory.simple.name.DirectoryName;
import clips.delegate.directory.simple.pathron.DirectoryPathron;
import clips.delegate.directory.simple.sex.DirectorySex;
import clips.delegate.directory.simple.surname.DirectorySurname;
import clips.delegate.service.SerRenLocal;
import clips.login.DialogLogin;
import clips.main.AppMainWindow;
import clips.main.ClipsConfig;
import clips.main.DetectorBusy;
import clips.main.UserPanelsEnum;
import clips.report.ReporterFactoryProperties;
import com.jtattoo.plaf.luna.LunaLookAndFeel;
import java.util.Properties;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;
//import org.infotechservice.GostCrypto.GostSignatureProvider;
import org.infotechservice.OpenOfficeFarmework.OpenOfficeFactory;
import org.infotechservice.smartcard.service.SmartCardServer;
import org.infotechservice.smartcard.utils.Messages;
/**
*
* @author Axe Ilshat
*/
public class Main extends MainAbstract {
public static final boolean DEVELOPED_ON = true;
public static final boolean SCREEN_SHOT_MODE_ON = true;
private static boolean dicomStarted = false;
private final SmartCardServer smartCardService = new SmartCardServer();
private final static int ui_default = 0;
private final static int ui_win = 1;
private final static int ui_mac = 2;
private final static String param_ui = "-ui";
private final static String param_ui_default = "default";
private final static String param_ui_win = "win";
private final static String param_ui_mac = "mac";
private final static String param_orb_host = "-serverHost";
private final static String param_orb_port = "-serverPort";
/** Creates a new instance of Main */
public Main() {
}
@Override
public boolean isDebugModeOn() {
return DEVELOPED_ON;
}
@Override
public boolean isScreenShotModeOn() {
return SCREEN_SHOT_MODE_ON;
}
public SmartCardServer getSmartCardService() {
return smartCardService;
}
@Override
protected void beforeRun() {
try {
Agregator.start();
dicomStarted = true;
smartCardService.start();
DetectorBusy.start();
} catch (RuntimeException ex) {
MessageBox.showExceptionAndHalt(ex);
} catch (Exception ex) {
MessageBox.showException(ex);
}
}
@Override
protected LoginDialogFrame getLoginWindow() throws ClipsException {
return new DialogLogin(this);
}
@Override
protected MainWindow getMainWindow() throws ClipsException {
return new AppMainWindow(this);
}
@Override
protected void beforeAppExit() {
try {
smartCardService.stop();
DetectorBusy.stop();
if (dicomStarted) {
Agregator.stop();
dicomStarted = false;
}
} catch (DICOMException ex) {
MessageBox.showExceptionAndHalt(ex);
}
}
private void initLookAndFeel(int ui) throws UnsupportedLookAndFeelException {
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
LookAndFeelInfo[] installedLookAndFeels = UIManager.getInstalledLookAndFeels();
for (int i = 0; i < installedLookAndFeels.length; i++) {
LookAndFeelInfo lookAndFeelInfo = installedLookAndFeels[i];
System.out.println(lookAndFeelInfo);
}
Object fch = UIManager.get("FileChooserUI");
switch (ui) {
case (ui_default):
break;
case (ui_mac):
/*---------Включает Маковй ЛАФ----------*/
/*---------------BEGIN---------------*/
// try {
// Methods.invokeStatic(JFrame.class, "setDefaultLookAndFeelDecorated", Boolean.TYPE, Boolean.TRUE);
// Methods.invokeStatic(JDialog.class, "setDefaultLookAndFeelDecorated", Boolean.TYPE, Boolean.TRUE);
// } catch (Exception e) {
// e.printStackTrace();
// }
UIManager.setLookAndFeel(new Quaqua15LeopardCrossPlatformLookAndFeel());
// UIManager.getDefaults().put("FileChooserUI", fch);
UIManager.getDefaults().put("TabbedPaneUI", Quaqua13JaguarTabbedPaneUI.class.getCanonicalName());
/*--------------END-----------------*/
break;
case (ui_win):
/*---------Включает старый лаф----------*/
/*---------------BEGIN---------------*/
Properties props = new Properties();
props.put("logoString", "intel clinic");
props.put("licenseKey", "INSERT YOUR LICENSE KEY HERE");
LunaLookAndFeel.setCurrentTheme(props);
UIManager.setLookAndFeel(new LunaLookAndFeel());
/*--------------END-----------------*/
break;
}
}
@Override
protected void init(String[] args) throws Exception {
super.init(args);
ClipsConfig.init();
ReporterFactoryProperties.initReportSubsystem();
DirectoryLocator.setMap(DirectorySexAbstract.class, DirectorySex.class);
DirectoryLocator.setMap(DirectoryNameAbstract.class, DirectoryName.class);
DirectoryLocator.setMap(DirectorySurnameAbstract.class, DirectorySurname.class);
DirectoryLocator.setMap(DirectoryPathronAbstract.class, DirectoryPathron.class);
DirectoryLocator.setMap(DirectoryIWTypeAbstract.class, DirectoryIWType.class);
DirectoryLocator.setMap(DirectoryArmAbstract.class, DirectoryArm.class);
DirectoryLocator.setMap(DirectoryCollaboratorAbstract.class, DirectoryCollaborator.class);
DirectoryLocator.setMap(DirectoryEnterpriseAbstract.class, DirectoryEnterprise.class);
DirectoryLocator.setMap(DirectoryDocumentPlaceAbstract.class, DirectoryDocumentGivenPlace.class);
DirectoryLocator.setMap(DirectoryDocumentTypeAbstract.class, DirectoryDocumentType.class);
UserPanelsEnum.init();
ReportGeneratorRegister clinicReportSet = new ReportGeneratorRegister();
clinicReportSet.init();
int ui = ui_default;
for (int i = 0; i < args.length - 1; i++) {
String param = args[i];
if (param_ui.equalsIgnoreCase(param)){
if (i < args.length - 1){
String value = args[i+1];
if (param_ui_win.equalsIgnoreCase(value)){
ui = ui_win;
}else if (param_ui_mac.equalsIgnoreCase(value)){
ui = ui_mac;
}else if (param_ui_default.equalsIgnoreCase(value)){
ui = ui_default;
}else{
throw new IllegalArgumentException("illegal ui value, use 'default', 'win' or 'mac'");
}
break;
}else{
throw new IllegalArgumentException("value for '"+param_ui+"' parameter not set");
}
}
}
initLookAndFeel(ui);
Messages.init();
OpenOfficeFactory.init(Main.class.getClassLoader());
OpenOfficeFactory.setOOPath(ClipsConfig.getInstance().getOpenOfficePath());
// GostSignatureProvider.init(GostSignatureProvider.CONSTANTS_JCP);
//testOpenOffice();
}
/* private ROList<Pair<TestSorageClass, GenericEntity>> getReportData(){
ArrayList<Pair<TestSorageClass, GenericEntity>> list = new ArrayList<Pair<TestSorageClass, GenericEntity>>();
TestSorageClass ts = new TestSorageClass();
ts.value = 5;
GenericEntity mySyperEntity = new GenericEntity() {
@Override
public int getId() {
return 65536;
}
@Override
public void setId(int id) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public EntityDetails getDetails(RightChecker rightChecker) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String toString() {
return "mySyperEntity id - " + getId();
}
};
list.add(new Pair<TestSorageClass, GenericEntity>(ts, mySyperEntity));
return new ROList<Pair<TestSorageClass, GenericEntity>>(list);
}
private void testOpenOffice(){
OpenOfficeFactory factory;
try {
factory = new OpenOfficeFactory();
}
catch (IOException ex) {
MessageBox.showException(false, ex);
return;
}
try {
ReportExport ex = factory.create(ReportExport.class);
ex.exec(getReportData());// new ROList<Pair<TestSorageClass, GenericEntity>>(null);
}
catch (Throwable ex) {
MessageBox.showException(false, ex);
}
}*/
public static void main(String[] args) {
String host = null;
String port = null;
for (int i = 0; i < args.length - 1; i++) {
String param = args[i];
if (param_orb_host.equalsIgnoreCase(param)){
if (i < args.length - 1){
host = args[i+1];
}else{
throw new IllegalArgumentException("value for '"+param_orb_host+"' parameter not set");
}
}
if (param_orb_port.equalsIgnoreCase(param)){
if (i < args.length - 1){
port = args[i+1];
}else{
throw new IllegalArgumentException("value for '"+param_orb_port+"' parameter not set");
}
}
}
if (host == null && port != null){
throw new IllegalArgumentException("parameter '"+param_orb_host+"' not set");
}
if (host != null && port == null){
throw new IllegalArgumentException("parameter '"+param_orb_port+"' not set");
}
if (host != null && port != null){
System.out.println("Connect to " + host + ":" + port);
ContextParamsHolder.setContextParams(new ContextParamsHolder.ContextParams(host, port));
}else{
System.out.println("host and port not set");
}
new Main().start(args);
}
@Override
public void logout() {
super.logout();
//Очистка мапа после перелогивания
SerRenLocal.clearContractMap();
}
}