Package com.GestDB.swing.skins

Source Code of com.GestDB.swing.skins.EditSkin

/*
* EditSkin.java
*
* Created on 26 de septiembre de 2006, 19:14
*/

package com.GestDB.swing.skins;

import com.GestDB.Gestor;
import com.GestDB.swing.Configuracion;
import com.GestDB.swing.Alerta;
import com.GestDB.swing.tmodelTabla;
import com.GestDB.swing.table.CellRenderer;
import com.GestDB.swing.table.CellEditor;
import com.GestDB.swing.table.ImageData;
import java.awt.Color;
import java.awt.Font;
import java.io.File;
import java.util.Properties;
import java.util.Vector;


/**
*
* @author  seni
*/
public class EditSkin extends javax.swing.JInternalFrame
{
   
    /** Creates new form EditSkin */
    public EditSkin(String sskin, String stema, boolean esCrear, Gestor gestor, Configuracion conf)
    {
        this.sskin = sskin;
        this.stema = stema;
        this.esCrear = esCrear;
        this.gestor = gestor;
        this.conf = conf;
       
        initComponents();
        PonLiterales();
       
        // rellenamos el combo
        jcbPropiedades.setModel(new javax.swing.DefaultComboBoxModel(pro2));
       
        // creamos el modelode la tabla y lo aplicamos
        String columnas[] = { Gestor.GetLiteral("estructurabd.property","Propiedad"),
            Gestor.GetLiteral("estructurabd.type","Tipo"),
            Gestor.GetLiteral("estructurabd.value","Valor")};
        Class tiposColumnas[] = { java.lang.String.class, java.lang.String.class, java.lang.Object.class };
        boolean columnWriteTmp[] = { false, false, true };
       
        tmodel = new tmodelTabla();
        jTable1.setModel(tmodel);
        jTable1.setDefaultRenderer(java.beans.PropertyEditor.class, new CellRenderer());
        jTable1.setDefaultRenderer(Color.class, new CellRenderer());
        jTable1.setDefaultEditor(Color.class,new CellEditor(gestor));
        jTable1.setDefaultRenderer(String.class, new CellRenderer());
        jTable1.setDefaultEditor(String.class,new CellEditor(gestor));
        jTable1.setDefaultRenderer(Object.class, new CellRenderer());
        jTable1.setDefaultEditor(Object.class,new CellEditor(gestor));

        Vector vRows = new Vector();

        ImageData imageBlank = new ImageData();
       
        // cargamos los datos, en caso que sea una modicicaci�n, sino se carga vacio
        if(!esCrear)
        {
            Properties pro = Gestor.skins.getTheme(sskin, stema);
            Object claves[] = pro.keySet().toArray();
            Vector vtemp = null;
            String stemp = null;
            File ftemp = null;
            for(int i=0 ; i < claves.length ; i++)
            {
                vtemp = new Vector(3);
                vtemp.addElement(claves[i]); // propiedad
                stemp = claves[i].toString().substring(0,3); // coge los tres primeros caracteres del nombre de la propiedad
                if(stemp.equals("nam")) // string
                {
                    vtemp.addElement(Gestor.GetLiteral("editskin.string","Cadena")); // tipo cadena
                    vtemp.addElement(pro.getProperty(claves[i].toString())); // valor
                }
                else if(stemp.equals("pri") || stemp.equals("sec") || stemp.equals("bla") || stemp.equals("whi")) // color
                {
                    vtemp.addElement(Gestor.GetLiteral("editskin.color","Color")); // tipo color
                    vtemp.addElement(PropertiesMetal.parseAwtColor(pro.getProperty(claves[i].toString()))); // valor
                }
                else if(stemp.equals("fon")) // Fuente
                {
                    vtemp.addElement(Gestor.GetLiteral("editskin.font","Fuente")); // tipo fuente
                    vtemp.addElement(PropertiesMetal.parseAwtFont(pro.getProperty(claves[i].toString()))); // valor
                }
                else if(stemp.equals("Int")) // icono
                {
                    vtemp.addElement(Gestor.GetLiteral("editskin.image","Imagen")); // tipo imagen
                    // lo que recibimos es el nombre de la imagen.
                    // tenemos que generar la imagen
                    ftemp = new File(Gestor.getRutaBaseSkin() + "themes/" + stema + "/",pro.getProperty(claves[i].toString()));
                    if(ftemp.exists() || ftemp.canRead())
                        vtemp.addElement(new ImageData(ftemp.getAbsolutePath(),ftemp.getName())); // valor
                    else
                        vtemp.addElement(imageBlank);
                }
                else
                {
                    vtemp.addElement(Gestor.GetLiteral("editskin.string","Cadena")); // tipo cadena
                    vtemp.addElement(pro.getProperty(claves[i].toString())); // valor
                }
                vRows.addElement(vtemp); // a�ado la fila
            }
            vRows.trimToSize();
        }
        else
        {
                Vector vtemp = new Vector(3);
                vtemp.addElement("name");
                vtemp.addElement(Gestor.GetLiteral("editskin.string","Cadena"));
                vtemp.addElement(pro[0]);
                vRows.addElement(vtemp); // a�ado la fila
                vRows.trimToSize();
        }
       
        // carga las filas
        tmodel.CargaDatos(columnas,tiposColumnas,columnWriteTmp,vRows);
    }
   
    /** 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()
    {
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jcbPropiedades = new javax.swing.JComboBox();
        jbAdd = new javax.swing.JButton();
        jbDel = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jbAceptar = new javax.swing.JButton();
        jbCancelar = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jLabel1.setText("Propiedades disponibles:");
        jPanel1.add(jLabel1);

        jcbPropiedades.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbPropiedades.setPreferredSize(new java.awt.Dimension(225, 22));
        jPanel1.add(jcbPropiedades);

        jbAdd.setText("A\u00f1adir");
        jbAdd.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jbAddActionPerformed(evt);
            }
        });

        jPanel1.add(jbAdd);

        jbDel.setText("Quitar");
        jbDel.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jbDelActionPerformed(evt);
            }
        });

        jPanel1.add(jbDel);

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

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

        jbAceptar.setText("Aceptar");
        jbAceptar.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jbAceptarActionPerformed(evt);
            }
        });

        jPanel2.add(jbAceptar);

        jbCancelar.setText("Cancelar");
        jbCancelar.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jbCancelarActionPerformed(evt);
            }
        });

        jPanel2.add(jbCancelar);

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

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

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][]
            {
                {null, null, null, null}
            },
            new String []
            {
                "Propiedad", "Tipo", "Valor", ""
            }
        )
        {
            Class[] types = new Class []
            {
                java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean []
            {
                false, false, true, true
            };

            public Class getColumnClass(int columnIndex)
            {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex)
            {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jTable1);

        jPanel3.add(jScrollPane2);

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

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

    private void jbDelActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jbDelActionPerformed
    {//GEN-HEADEREND:event_jbDelActionPerformed
        if(this.jTable1.getSelectedRowCount() > 0)
        {
            int filas[] = jTable1.getSelectedRows();
            tmodel.removeRow(filas);
        }
    }//GEN-LAST:event_jbDelActionPerformed

    private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jbCancelarActionPerformed
    {//GEN-HEADEREND:event_jbCancelarActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_jbCancelarActionPerformed

    private void jbAceptarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jbAceptarActionPerformed
    {//GEN-HEADEREND:event_jbAceptarActionPerformed
        if(validarDatos())
        {
            // vamos con la creaci�n/modificaci�n del tema.
            // tenemos que crear un properties con todas las propiedades.
            Properties ptheme = new Properties();
            int filas = tmodel.getRowCount();
            String themeName = "mytheme";
            for(int i=0; i < filas ; i++)
            {
                if(tmodel.getValueAt(i,1).toString().equals(Gestor.GetLiteral("editskin.string","Cadena")))
                {
                    if(tmodel.getValueAt(i,0).toString().equals("name"))
                        themeName = tmodel.getValueAt(i,2).toString();
                       
                    ptheme.setProperty(tmodel.getValueAt(i,0).toString(),tmodel.getValueAt(i,2).toString());
                }
                else if(tmodel.getValueAt(i,1).toString().equals(Gestor.GetLiteral("editskin.color","Color")))
                {
                    ptheme.setProperty(tmodel.getValueAt(i,0).toString(),PropertiesMetal.parseColor((Color)tmodel.getValueAt(i,2)));
                }
                else if(tmodel.getValueAt(i,1).toString().equals(Gestor.GetLiteral("editskin.font","Fuente")))
                {
                    ptheme.setProperty(tmodel.getValueAt(i,0).toString(),PropertiesMetal.parseFont((Font)tmodel.getValueAt(i,2)));
                }
                else if(tmodel.getValueAt(i,1).toString().equals(Gestor.GetLiteral("editskin.image","Imagen")))
                {
                    // tenemos que sacar el nombre de la imagen
                    ImageData imgtmp = (ImageData)tmodel.getValueAt(i,2);
                    if(imgtmp.getNombre() != null && imgtmp.getNombre().trim().length() > 0)
                        ptheme.setProperty(tmodel.getValueAt(i,0).toString(),imgtmp.getNombre());
                }
            }
           
            // lo tenemos que crear o modificar.
            if(esCrear)
            {
                try {
                    if(!gestor.skins.createTheme(sskin,themeName,ptheme))
                    {
                        Alerta al = new Alerta(new javax.swing.JDialog(),Gestor.GetLiteral("gestor.alert","Aviso"),true,
                           Gestor.GetLiteral("editskin.error5","Error guardando el tema"),Alerta.OK);
                        al.setVisible(true);
                        al = null;
                    }
                    else
                    {
                        // tenemos que actualizar la ventana de configuraci�n
                        conf.CargaSkins();
                    }
                } catch(Exception e)
                {
                    Alerta al = new Alerta(new javax.swing.JDialog(),Gestor.GetLiteral("gestor.alert","Aviso"),true,
                        e.getMessage(),Alerta.OK);
                    al.setVisible(true);
                    al = null;
                }
            }
            else
            {
                try {
                    if(!gestor.skins.saveTheme(sskin,themeName,stema,ptheme))
                    {
                        Alerta al = new Alerta(new javax.swing.JDialog(),Gestor.GetLiteral("gestor.alert","Aviso"),true,
                           Gestor.GetLiteral("editskin.error5","Error guardando el tema"),Alerta.OK);
                        al.setVisible(true);
                        al = null;
                    }
                    else
                    {
                        // tenemos que actualizar la ventana de configuraci�n
                        conf.CargaSkins();
                    }
                } catch(Exception e)
                {
                    Alerta al = new Alerta(new javax.swing.JDialog(),Gestor.GetLiteral("gestor.alert","Aviso"),true,
                        e.getMessage(),Alerta.OK);
                    al.setVisible(true);
                    al = null;
                }
            }
           
            this.setVisible(false);
        }
    }//GEN-LAST:event_jbAceptarActionPerformed

    private void jbAddActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jbAddActionPerformed
    {//GEN-HEADEREND:event_jbAddActionPerformed
        if(jcbPropiedades.getSelectedIndex() != -1)
        {
            int i = jcbPropiedades.getSelectedIndex();
            Vector vtemp = new Vector(3);
            vtemp.addElement(pro2[i]); // propiedad
            String stemp = pro2[i].toString().substring(0,3); // coge los tres primeros caracteres del nombre de la propiedad
            if(stemp.equals("nam")) // string
            {
                vtemp.addElement(Gestor.GetLiteral("editskin.string","Cadena")); // tipo cadena
                vtemp.addElement(pro[i]); // valor
            }
            else if(stemp.equals("pri") || stemp.equals("sec") || stemp.equals("bla") || stemp.equals("whi")) // color
            {
                vtemp.addElement(Gestor.GetLiteral("editskin.color","Color")); // tipo color
                vtemp.addElement(PropertiesMetal.parseAwtColor(pro[i].toString())); // valor
            }
            else if(stemp.equals("fon")) // Fuente
            {
                vtemp.addElement(Gestor.GetLiteral("editskin.font","Fuente")); // tipo fuente
                vtemp.addElement(PropertiesMetal.parseAwtFont(pro[i].toString())); // valor
            }
            else if(stemp.equals("Int")) // icono
            {
                vtemp.addElement(Gestor.GetLiteral("editskin.image","Imagen")); // tipo imagen
                vtemp.addElement(new ImageData()); // valor
            }
            else
            {
                vtemp.addElement(Gestor.GetLiteral("editskin.string","Cadena")); // tipo cadena
                vtemp.addElement(pro[i]); // valor
            }
           
            tmodel.addRow(vtemp);
        }
    }//GEN-LAST:event_jbAddActionPerformed

    public void PonLiterales()
    {
        this.jbAceptar.setText(Gestor.GetLiteral("dlgmdfgrupos.accept","Aceptar"));
        this.jbAceptar.setToolTipText(Gestor.GetLiteral("dlgmdfgrupos.accept","Aceptar"));
        this.jbCancelar.setText(Gestor.GetLiteral("importardlg.cancel","Cancelar"));
        this.jbCancelar.setToolTipText(Gestor.GetLiteral("importardlg.cancel","Cancelar"));
        this.jbAdd.setText(Gestor.GetLiteral("setfiltroquerydlg.add","A\u00F1adir"));
        this.jbAdd.setToolTipText(Gestor.GetLiteral("setfiltroquerydlg.add","A\u00F1adir"));
        this.jbDel.setText(Gestor.GetLiteral("editskin.remove","Quitar"));
        this.jbDel.setToolTipText(Gestor.GetLiteral("editskin.remove","Quitar"));
        this.setTitle(Gestor.GetLiteral("editskin.title","Editor de temas"));
        jLabel1.setText(Gestor.GetLiteral("editskin.prop_available","Propiedades disponibles") + ":");
        // this.setVisible(false);
    }

    private boolean validarDatos()
    {
        // se recorre la tabla en busca de registros repetidos o sin valor
        int filas = tmodel.getRowCount();
        String mensaje = "";
        if(filas == 0)
            mensaje = Gestor.GetLiteral("editskin.error1","Tiene que poner alguna propiedad en el tema");
        else
        {
            Vector vtemp = new Vector(); // este vector es para buscar los repetidos
            boolean hayImagenes = false;
            for(int i=0; i < filas ; i++)
            {
                if(vtemp.contains(tmodel.getValueAt(i,0)))
                {
                    mensaje = Gestor.GetLiteral("editskin.error2","Tiene una propiedad repetida");
                    break;
                }
               
                vtemp.addElement(tmodel.getValueAt(i,0));
               
                if(tmodel.getValueAt(i,2).toString().trim().length() == 0)
                {
                    mensaje = Gestor.GetLiteral("editskin.error3","Tiene una propiedad sin valor");
                    break;
                }
               
                if(tmodel.getValueAt(i,1).toString().equals(Gestor.GetLiteral("editskin.string","Cadena")) &&
                        tmodel.getValueAt(i,0).toString().equals("name") &&
                        tmodel.getValueAt(i,2).toString().trim().indexOf(' ') != -1)
                {
                    mensaje = Gestor.GetLiteral("editskin.error6","El nombre no puede contener espacios");
                    break;
                }
            }
        }

        if(mensaje.length() == 0)
            return true;
       
        // tenemos que notificarselo al usuario.
        Alerta al = new Alerta(new javax.swing.JDialog(),Gestor.GetLiteral("gestor.alert","Aviso"),true,
            mensaje,Alerta.OK);
        al.setVisible(true);
        al = null;
       
       
        return false;
    }
   
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JButton jbAceptar;
    private javax.swing.JButton jbAdd;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JButton jbDel;
    private javax.swing.JComboBox jcbPropiedades;
    // End of variables declaration//GEN-END:variables

    private String sskin = null;
    private String stema = null;
    private boolean esCrear = true;
    private tmodelTabla tmodel = null;
    private Gestor gestor = null;
    private Configuracion conf;
    private Object pro[] = {"Theme","33,66,66","66,99,99","99,99,99",
        "0,0,0","51,51,51","102,102,102",
        "255,255,255","0,0,0",
        "Dialog,BOLD,11","Dialog,BOLD,11","Dialog,BOLD,11",
        "Dialog,BOLD,11","Dialog,BOLD,11","Dialog,BOLD,11",
        "close.jpg","maximize.jpg",
        "iconify.jpg","minimize.jpg"};
    private Object pro2[] = {"name","primary1","primary2","primary3",
        "secondary1","secondary2","secondary3",
        "black","white",
        "font.control","font.system","font.user",
        "font.menu","font.windowtitle","font.small",
        "InternalFrame.closeIcon","InternalFrame.maximizeIcon",
        "InternalFrame.iconifyIcon","InternalFrame.minimizeIcon"};
}
TOP

Related Classes of com.GestDB.swing.skins.EditSkin

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.