/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package feuille.drawing.dialog;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.SpinnerNumberModel;
import feuille.drawing.glyph.GlyphObject;
import feuille.drawing.renderer.FontPreviewRenderer;
import feuille.drawing.renderer.GlyphRenderer;
import feuille.lib.Language;
/**
*
* @author The Wingate 2940
*/
public class OpenGlyphDialog extends javax.swing.JDialog {
private ButtonPressed bp = ButtonPressed.NONE;
private DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
private DefaultListModel dlm = new DefaultListModel();
private SpinnerNumberModel snm;
private Language localeLanguage = feuille.MainFrame.getLanguage();
public enum ButtonPressed{
NONE, OK_BUTTON, CANCEL_BUTTON;
}
/**
* Creates new form OpenGlyphDialog
*/
public OpenGlyphDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Font[] flist = ge.getAllFonts();
dcbm = new DefaultComboBoxModel(flist);
cbFonts.setModel(dcbm);
cbFonts.setRenderer(new FontPreviewRenderer());
lstChars.setModel(dlm);
lstChars.setCellRenderer(new GlyphRenderer());
String[] charTable = new String[] {"A","B","C","D","E","F","G","H","I",
"J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q",
"r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7",
"8","9"};
for(String s : charTable){
Font f = ((Font)dcbm.getElementAt(0)).deriveFont(50.0f);
dlm.addElement(new GlyphObject(s, f));
}
snm = new SpinnerNumberModel(100, 10, 1000, 1);
spiSize.setModel(snm);
if(localeLanguage.getValueOf("titleGlyph")!=null){setTitle(localeLanguage.getValueOf("titleGlyph"));}
if(localeLanguage.getValueOf("buttonOk")!=null){OK_Button.setText(localeLanguage.getValueOf("buttonOk"));}
if(localeLanguage.getValueOf("buttonCancel")!=null){Cancel_Button.setText(localeLanguage.getValueOf("buttonCancel"));}
}
/**
* 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
cbFonts = new javax.swing.JComboBox();
spChars = new javax.swing.JScrollPane();
lstChars = new javax.swing.JList();
OK_Button = new javax.swing.JButton();
Cancel_Button = new javax.swing.JButton();
spiSize = new javax.swing.JSpinner();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
cbFonts.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
cbFonts.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
cbFontsItemStateChanged(evt);
}
});
spChars.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
lstChars.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
spChars.setViewportView(lstChars);
OK_Button.setText("OK");
OK_Button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
OK_ButtonActionPerformed(evt);
}
});
Cancel_Button.setText("Annuler");
Cancel_Button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Cancel_ButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cbFonts, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(spChars)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(spiSize, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 158, Short.MAX_VALUE)
.addComponent(Cancel_Button, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(OK_Button, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(cbFonts, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spChars, javax.swing.GroupLayout.PREFERRED_SIZE, 329, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(OK_Button)
.addComponent(Cancel_Button)
.addComponent(spiSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void OK_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OK_ButtonActionPerformed
bp = ButtonPressed.OK_BUTTON;
dispose();
}//GEN-LAST:event_OK_ButtonActionPerformed
private void Cancel_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Cancel_ButtonActionPerformed
bp = ButtonPressed.CANCEL_BUTTON;
dispose();
}//GEN-LAST:event_Cancel_ButtonActionPerformed
private void cbFontsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbFontsItemStateChanged
Font font = (Font)dcbm.getSelectedItem();
for(Object o : dlm.toArray()){
if(o instanceof GlyphObject){
GlyphObject go = (GlyphObject)o;
go.setFont(font.getFontName());
}
}
}//GEN-LAST:event_cbFontsItemStateChanged
public boolean showDialog(){
setVisible(true);
if(bp.equals(ButtonPressed.OK_BUTTON)){
return true;
}else{
return false;
}
}
public String getGlyph(){
GlyphObject go = (GlyphObject)dlm.getElementAt(lstChars.getSelectedIndex());
return go.getGlyph();
}
public Font getGlyphFont(){
return (Font)dcbm.getSelectedItem();
}
public int getGlyphSize(){
return snm.getNumber().intValue();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(OpenGlyphDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(OpenGlyphDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(OpenGlyphDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(OpenGlyphDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
OpenGlyphDialog dialog = new OpenGlyphDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton Cancel_Button;
private javax.swing.JButton OK_Button;
private javax.swing.JComboBox cbFonts;
private javax.swing.JList lstChars;
private javax.swing.JScrollPane spChars;
private javax.swing.JSpinner spiSize;
// End of variables declaration//GEN-END:variables
}