Package com.GestDB.swing.table

Source Code of com.GestDB.swing.table.FontEditor

/*
* FontEditor.java
*
* Created on 27 de septiembre de 2006, 15:30
* Created by Arsenio Molinero
* Copyright (C) 2004, 2005, 2006 Arsenio Molinero
*
* GestDB - a Java multi database client
*
* This file is part of GestDB.
*
* GestDB is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GestDB 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GestDB; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package com.GestDB.swing.table;

import com.GestDB.Gestor;
import java.awt.GraphicsEnvironment;
import javax.swing.DefaultComboBoxModel;
import java.awt.Font;

/**
*
* @author  seni
*/
public class FontEditor extends javax.swing.JInternalFrame
{
   
    /** Creates new form FontEditor */
    public FontEditor(CellEditor cellEditor)
    {
        this.cellEditor = cellEditor;
       
        initComponents();
        PonLiterales();
       
        // tenemos que cargar las fuentes del sistema
        GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
        jcbFont.setModel(new DefaultComboBoxModel(gEnv.getAvailableFontFamilyNames()));
    }
   
    /** 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();
        jlFont = new javax.swing.JLabel();
        jcbFont = new javax.swing.JComboBox();
        jlStyle = new javax.swing.JLabel();
        jcbStyle = new javax.swing.JComboBox();
        jlSize = new javax.swing.JLabel();
        jtSize = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jbAceptar = new javax.swing.JButton();
        jbCancelar = new javax.swing.JButton();

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

        setTitle("Selector de fuente");
        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jPanel1.setPreferredSize(new java.awt.Dimension(410, 60));
        jlFont.setText("Fuente:");
        jPanel1.add(jlFont);

        jcbFont.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1" }));
        jcbFont.setPreferredSize(new java.awt.Dimension(355, 22));
        jcbFont.addItemListener(new java.awt.event.ItemListener()
        {
            public void itemStateChanged(java.awt.event.ItemEvent evt)
            {
                jcbFontItemStateChanged(evt);
            }
        });

        jPanel1.add(jcbFont);

        jlStyle.setText("Estilo:");
        jlStyle.setPreferredSize(new java.awt.Dimension(38, 14));
        jPanel1.add(jlStyle);

        jcbStyle.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "PLAIN", "BOLD", "ITALIC", "BOLD ITALIC" }));
        jcbStyle.setPreferredSize(new java.awt.Dimension(155, 22));
        jcbStyle.addItemListener(new java.awt.event.ItemListener()
        {
            public void itemStateChanged(java.awt.event.ItemEvent evt)
            {
                jcbStyleItemStateChanged(evt);
            }
        });

        jPanel1.add(jcbStyle);

        jlSize.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jlSize.setText("Tama\u00f1o:");
        jlSize.setPreferredSize(new java.awt.Dimension(62, 14));
        jPanel1.add(jlSize);

        jtSize.setText("12");
        jtSize.setPreferredSize(new java.awt.Dimension(40, 19));
        jtSize.addFocusListener(new java.awt.event.FocusAdapter()
        {
            public void focusLost(java.awt.event.FocusEvent evt)
            {
                jtSizeFocusLost(evt);
            }
        });

        jPanel1.add(jtSize);

        getContentPane().add(jPanel1);

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

        jPanel2.setPreferredSize(new java.awt.Dimension(405, 65));
        jLabel1.setText("aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ");
        jLabel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Previsualizaci\u00f3n"));
        jPanel2.add(jLabel1);

        getContentPane().add(jPanel2);

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

        jPanel3.setPreferredSize(new java.awt.Dimension(410, 33));
        jbAceptar.setText("Aceptar");
        jbAceptar.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jbAceptarActionPerformed(evt);
            }
        });

        jPanel3.add(jbAceptar);

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

        jPanel3.add(jbCancelar);

        getContentPane().add(jPanel3);

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

    private void jtSizeFocusLost(java.awt.event.FocusEvent evt)//GEN-FIRST:event_jtSizeFocusLost
    {//GEN-HEADEREND:event_jtSizeFocusLost
        if(fuente != null)
        {
            try {
                int tamanio = Integer.parseInt(jtSize.getText());
                fuente = new Font(fuente.getFamily(),fuente.getStyle(),tamanio);
                jLabel1.setFont(fuente);
            }catch(Exception e)
            {
                ;
            }
        }
    }//GEN-LAST:event_jtSizeFocusLost

    private void jcbStyleItemStateChanged(java.awt.event.ItemEvent evt)//GEN-FIRST:event_jcbStyleItemStateChanged
    {//GEN-HEADEREND:event_jcbStyleItemStateChanged
        if(fuente != null && jcbStyle.getSelectedIndex() != -1)
        {
            fuente = new Font(fuente.getFamily(),jcbStyle.getSelectedIndex(),fuente.getSize());
            jLabel1.setFont(fuente);
        }

    }//GEN-LAST:event_jcbStyleItemStateChanged

    private void jcbFontItemStateChanged(java.awt.event.ItemEvent evt)//GEN-FIRST:event_jcbFontItemStateChanged
    {//GEN-HEADEREND:event_jcbFontItemStateChanged
        if(fuente != null && jcbFont.getSelectedIndex() != -1)
        {
            fuente = new Font(jcbFont.getSelectedItem().toString(),fuente.getStyle(),fuente.getSize());
            jLabel1.setFont(fuente);
        }

    }//GEN-LAST:event_jcbFontItemStateChanged

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

    private void jbAceptarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jbAceptarActionPerformed
    {//GEN-HEADEREND:event_jbAceptarActionPerformed
        ok = true;
        cellEditor.setFuente(fuente);
        this.setVisible(false);
    }//GEN-LAST:event_jbAceptarActionPerformed
   
    public void setFuente(Font font)
    {
        this.fuente = font;
        // tenemos que actualizar los combos.
        jtSize.setText(String.valueOf(fuente.getSize()));
        jcbStyle.setSelectedIndex(fuente.getStyle());
        jcbFont.setSelectedItem(fuente.getFamily());
        jLabel1.setFont(fuente);
        // System.out.println("fuente.getFamily(): " + fuente.getFamily());
    }
   
    public Font getFuente()
    {
        return fuente;
    }
   
    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.setTitle(Gestor.GetLiteral("fonteditor.title","Selector de fuente"));
        jlFont.setText(Gestor.GetLiteral("editskin.font","Fuente") + ":");
        jlStyle.setText(Gestor.GetLiteral("fonteditor.style","Estilo") + ":");
        jlSize.setText(Gestor.GetLiteral("fonteditor.size","Tama\u00F1o") + ":");
        jLabel1.setBorder(javax.swing.BorderFactory.createTitledBorder(Gestor.GetLiteral("fonteditor.preview","Previsualizaci\u00f3n")));
    }

    public boolean isOK()
    {
        return ok;
    }
   
    // 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.JButton jbAceptar;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JComboBox jcbFont;
    private javax.swing.JComboBox jcbStyle;
    private javax.swing.JLabel jlFont;
    private javax.swing.JLabel jlSize;
    private javax.swing.JLabel jlStyle;
    private javax.swing.JTextField jtSize;
    // End of variables declaration//GEN-END:variables

    private Font fuente = null;
    private boolean ok = false;
    private CellEditor cellEditor = null;
}
TOP

Related Classes of com.GestDB.swing.table.FontEditor

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.