Package com.GestDB.general

Source Code of com.GestDB.general.addLibrary

/*
* addLibrary.java
*
* Created on 25 de septiembre de 2006, 9:18
*/

package com.GestDB.general;

import java.net.*;
import java.io.*;
import com.GestDB.Gestor;
import com.GestDB.swing.Alerta;
import com.GestDB.swing.EnterSingleData;
import com.GestDB.swing.Configuracion;


/**
*
* @author  65191363
*/
public class addLibrary extends javax.swing.JDialog
{
   
    /** Creates new form addLibrary */
    public addLibrary(java.awt.Frame parent, boolean modal, Configuracion conf)
    {
        super(parent, modal);
       
        this.conf = conf;
       
        initComponents();
       
        PonLiterales();
       
        // cargamos la lista de librerias cargadas
        CargaLista();
    }
   
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents()
    {
        jScrollPane1 = new javax.swing.JScrollPane();
        jtaLibrarys = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jtInfo = new javax.swing.JTextField();
        jlInfo2 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jbAddSkin = new javax.swing.JButton();
        jbAdd = new javax.swing.JButton();
        jbCerrar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("A\u00f1adir librerias");
        setResizable(false);
        jtaLibrarys.setColumns(20);
        jtaLibrarys.setEditable(false);
        jtaLibrarys.setFont(new java.awt.Font("Tahoma", 0, 11));
        jtaLibrarys.setRows(5);
        jScrollPane1.setViewportView(jtaLibrarys);

        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jPanel1.setLayout(new java.awt.BorderLayout());

        jPanel2.setLayout(new java.awt.GridLayout(1, 0));

        jtInfo.setEditable(false);
        jtInfo.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        jtInfo.setText("Pulse en el bot\u00f3n 'A\u00f1adir' para agregar librerias o drivers JDBC a la aplicaci\u00f3n.");
        jtInfo.setBorder(null);
        jtInfo.setMargin(new java.awt.Insets(1, 1, 2, 1));
        jtInfo.setOpaque(false);
        jtInfo.setPreferredSize(new java.awt.Dimension(372, 40));
        jPanel2.add(jtInfo);

        jPanel1.add(jPanel2, java.awt.BorderLayout.CENTER);

        jlInfo2.setText("Drivers JDBC/Librerias cargadas");
        jPanel1.add(jlInfo2, java.awt.BorderLayout.SOUTH);

        getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);

        jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        jbAddSkin.setText("A\u00f1adir Skin");
        jbAddSkin.setPreferredSize(new java.awt.Dimension(110, 23));
        jbAddSkin.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jbAddSkinActionPerformed(evt);
            }
        });

        jPanel3.add(jbAddSkin);

        jbAdd.setText("A\u00f1adir Driver JDBC");
        jbAdd.setPreferredSize(new java.awt.Dimension(150, 23));
        jbAdd.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jbAddActionPerformed(evt);
            }
        });

        jPanel3.add(jbAdd);

        jbCerrar.setText("Cerrar");
        jbCerrar.setPreferredSize(new java.awt.Dimension(100, 23));
        jbCerrar.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jbCerrarActionPerformed(evt);
            }
        });

        jPanel3.add(jbCerrar);

        getContentPane().add(jPanel3, java.awt.BorderLayout.SOUTH);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-446)/2, (screenSize.height-335)/2, 446, 335);
    }// </editor-fold>//GEN-END:initComponents

    private void jbAddSkinActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jbAddSkinActionPerformed
    {//GEN-HEADEREND:event_jbAddSkinActionPerformed
        add(false);
    }//GEN-LAST:event_jbAddSkinActionPerformed

    private void jbCerrarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jbCerrarActionPerformed
    {//GEN-HEADEREND:event_jbCerrarActionPerformed
        setVisible(false);
        dispose();
    }//GEN-LAST:event_jbCerrarActionPerformed

    private void jbAddActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jbAddActionPerformed
    {//GEN-HEADEREND:event_jbAddActionPerformed
        add(true);
    }//GEN-LAST:event_jbAddActionPerformed

    private void add(boolean esDriver)
    {
        javax.swing.JFileChooser jfc = new javax.swing.JFileChooser();
        jfc.setFileSelectionMode(jfc.FILES_ONLY);
        jfc.setDialogType(javax.swing.JFileChooser.OPEN_DIALOG);
        if(Gestor.propiedades.containsKey("conexion.exportar.ultimo_dir_html"))
            jfc.setCurrentDirectory(new File((String)Gestor.propiedades.get("conexion.exportar.ultimo_dir_html")));
        if(jfc.showOpenDialog(this) == javax.swing.JFileChooser.APPROVE_OPTION)
        {
            Gestor.propiedades.put("conexion.exportar.ultimo_dir_html", jfc.getCurrentDirectory().getAbsolutePath());
            // el archivo lo tenemos en jfc.getSelectedFile(), lo tenemos que copiar la a ruta de las librerias.
            File libdir = new File(Gestor.getRutaBaseSkin());
            if(esDriver)
                libdir = new File(Gestor.getRutaBaseLib());
            File archivo = jfc.getSelectedFile();
            if(archivo.exists() && archivo.canRead())
            {
                // si el directorio de librerias no existe se crea.
                if(!libdir.exists())
                    libdir.mkdirs();
               
                File archivoDestino = new File(libdir,archivo.getName());
                FileInputStream fin = null;
                FileOutputStream fout = null;
                byte buffer[] = new byte[10000];
                int leido = 0;
                try
                {
                    fin = new FileInputStream(archivo);
                    fout = new FileOutputStream(archivoDestino);
                    while((leido=fin.read(buffer)) != -1)
                    {
                        fout.write(buffer,0,leido);
                    }
                    fin.close();
                    fout.close();
                   
                    // todo va bien, tenemos que recargar la lista y las librerias.
                    try {
                        Gestor.CargarLibrerias(this.getClass());
                        CargaLista();
                       
                        // si es un skin tenemos que pedirle el nombre de la clase principal y actualizarlo en la lista de skins
                        EnterSingleData edata = new EnterSingleData(new javax.swing.JFrame(),true,
                            Gestor.GetLiteral("addlibrary.enter_class","Introduzca la clase java principal, esta le viene indicada en la documentaci�n de la libreria"),
                            Gestor.GetLiteral("addlibrary.class","Clase"));
                        edata.setVisible(true);
                       
                        if(edata.getReturnStatus() == edata.RET_OK)
                        {
                            String clase = edata.jTextField1.getText();
                           
                            edata = new EnterSingleData(new javax.swing.JFrame(),true,
                                Gestor.GetLiteral("addlibrary.enter_skinname","Introduzca el nombre de la piel"),
                                Gestor.GetLiteral("dlgconfig.skin","Piel"));
                            edata.setVisible(true);
                            if(edata.getReturnStatus() == edata.RET_OK)
                            {
                                Gestor.skins.saveSkin(edata.jTextField1.getText(),clase);
                                // tenemos que actualizar la ventana de configuraci�n
                                conf.CargaSkins();
                            }
                        }

                    }catch(Exception e)
                    {
                        Alerta al = new Alerta(this,Gestor.GetLiteral("gestor.alert","Aviso"),true,
                            Gestor.GetLiteral("gestor.error_1","Error") + ": " + e.getMessage(),Alerta.OK);
                        al.setVisible(true);
                        al = null;
                    }
                } catch (Exception ex)
                {
                    if(fin != null)
                    {
                        try {
                            fin.close();
                        }catch(Exception ee){
                            ;
                        }
                    }
                    if(fout != null)
                    {
                        try {
                            fout.close();
                        }catch(Exception ee){
                            ;
                        }
                    }
                    // se tiene que borrar el archivo de destino
                    if(archivoDestino.exists())
                        archivoDestino.delete();
                   
                   
                    Alerta al = new Alerta(this,Gestor.GetLiteral("gestor.alert","Aviso"),true,
                        Gestor.GetLiteral("gestor.error_1","Error") + ": " + ex.getMessage(),Alerta.OK);
                    al.setVisible(true);
                    al = null;
                }
               
            }
            else
            {
                // Espa�ol: no se puee leer el archivo origen.
                // English: Reading error with source file
                Alerta al = new Alerta(this,Gestor.GetLiteral("gestor.alert","Aviso"),true,
                    Gestor.GetLiteral("gestor.error_1","Error") + ": " +
                    Gestor.GetLiteral("addlibrary.error_reading","El archivo no se puede leer") +
                    ". " + archivo.getAbsolutePath(),Alerta.OK);
                al.setVisible(true);
                al = null;
            }
        }       
    }

    private void CargaLista()
    {
        jtaLibrarys.setText("");
        URLClassLoader Cargador = (URLClassLoader)ClassLoader.getSystemClassLoader();
        URL[] cjto = Cargador.getURLs();
        File fl1 = null;
        for (int i=0; i < cjto.length; i++)
        {
            fl1 = new File(cjto[i].getFile());
            jtaLibrarys.append(fl1.getAbsolutePath() + "\n");
        }
    }

    public void PonLiterales()
    {
        jtInfo.setText(Gestor.GetLiteral("addlibrary.info1","Pulse en el bot�n 'A\u00f1adir' para agregar librerias o drivers JDBC a la aplicaci\u00F3n."));
        jlInfo2.setText(Gestor.GetLiteral("addlibrary.info2","Drivers JDBC/Librerias cargadas."));
        setTitle(Gestor.GetLiteral("addlibrary.title","A\u00f1adir librerias"));
        jbAdd.setText(Gestor.GetLiteral("setfiltroquerydlg.add","A\u00f1adir") + " Driver JDBC");
        jbAddSkin.setText(Gestor.GetLiteral("setfiltroquerydlg.add","A\u00f1adir") + " Skin");
        jbCerrar.setText(Gestor.GetLiteral("wizarexportardatos.finish","Finalizar"));
    }   
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbAdd;
    private javax.swing.JButton jbAddSkin;
    private javax.swing.JButton jbCerrar;
    private javax.swing.JLabel jlInfo2;
    private javax.swing.JTextField jtInfo;
    private javax.swing.JTextArea jtaLibrarys;
    // End of variables declaration//GEN-END:variables
   
    private Configuracion conf = null;
}
TOP

Related Classes of com.GestDB.general.addLibrary

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.