/*
 * Copyright
 *   2007 axYus - www.axyus.com
 *   2008 L.Meckert - laurent.meckert.com
 *
 * This file is part of XEMELIOS.
 *
 * XEMELIOS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * XEMELIOS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with XEMELIOS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package fr.gouv.finances.cp.xemelios.plugin.signerfichier;

import javax.swing.JFrame;
import java.io.File;
import java.net.URLClassLoader;
import java.net.URL;

/**
 *
 * @author laurent.meckert
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        Runnable mainTask = new Runnable() {

            public void run() {
                try {
                    File jardirectory = new File("C:\\devel\\lib");
                    File file = new File(jardirectory, "APXSFileSigner.jar");
                    URL url = file.toURL();
                    String url1 = url.toString();

                    //  file = new File(jardirectory, "xmlsec-1.4.1.jar");
                    file = new File(jardirectory, "xmlsec-1.4.2.jar");
                    url = file.toURL();
                    String url2 = url.toString();
                    file = new File(jardirectory, "xalan.jar");
                    url = file.toURL();
                    String url3 = url.toString();

                    file = new File(jardirectory, "bc-jce-jdk13-129.jar");
                    url = file.toURL();
                    String url4 = url.toString();

                    ClassLoader prevCl = Thread.currentThread().getContextClassLoader();

                    ClassLoader loader = URLClassLoader.newInstance(new URL[]{
                                new URL(url1),
                                new URL(url2),
                                new URL(url3),
                                new URL(url4)
                            }, prevCl);
                    Thread.currentThread().setContextClassLoader(loader);



                    Thread.currentThread().setContextClassLoader(loader);

                } catch (Exception e) {
                    e.printStackTrace();
                    return;
                }




                JFrame frame = new JFrame("test");
                frame.setTitle("Signature d'un fichier PES");
                // DlgSignerfichier dialog = new DlgSignerfichier(frame, true);
                WizardSignerFichier dialog = new WizardSignerFichier(frame, true);
                dialog.dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });

                dialog.run();
                System.exit(0);
            }
        };

        Thread t = new Thread(mainTask);
        t.setPriority(Thread.NORM_PRIORITY);


        java.awt.EventQueue.invokeLater(t);

    }
}
