import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class FontSec implements ActionListener,ListSelectionListener
{
private String FontFamily;
private int FontStyle;
private int FontSize;
JDialog font;
JList fontlist;
JList stillist;
JList sizelist;
JTextArea onizle,gelentext;
String[] fontlar;
String[] sizelar;
String[] stiller;
Font gelen;
Component degisecek;
public FontSec(Component f)
{
degisecek = f;
gelen = f.getFont();
fontlar = GraphicsEnvironment.getLocalGraphicsEnvironment(). getAvailableFontFamilyNames();
stiller = new String[] {"Normal","Kalýn","Ýtalik","Kalýn Ýtalic"};
sizelar = new String[] {"8","9","10","12","14","18","20","22","24","28"," 30","32","34","36"};
font = new JDialog();
font.setTitle("Yazý Tipi Seç");
font.setModal(true);
font.setResizable(false);
font.setAlwaysOnTop(true);

fontlist = new JList(fontlar);
stillist = new JList(stiller);
sizelist = new JList(sizelar);

JLabel fontlabel = new JLabel("Yazý Tipi");
JLabel stillabel = new JLabel("Stil");
JLabel sizelabel = new JLabel("Boyut");

onizle = new JTextArea();

JButton btnOk = new JButton("Tamam");
JButton btnCancel = new JButton("Vazgeç");


font.setBounds((f.getX()+f.getWidth()/2-300),(f.getY()+f.getHeight()/2-100),475,220);
font.setAlwaysOnTop(true);
////////////////////////////////////////////////////
onizle.setBounds(5, 100, 460, 85);
onizle.setEditable(false);
onizle.setWrapStyleWord(true);
onizle.setLineWrap(true);
///////////////////////////////////////////////////
fontlabel.setBounds(5, 5, 70, 15);
stillabel.setBounds(210, 5, 70, 15);
sizelabel.setBounds(315, 5, 70, 15);
fontlist.setBounds(5, 25, 200, 72);
fontlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
fontlist.addListSelectionListener(this);
JScrollPane scrFont = new JScrollPane(fontlist);
scrFont.setBounds(fontlist.getBounds());
stillist.setBounds(210, 25, 100, 72);
stillist.setAutoscrolls(true);
JScrollPane scrStil = new JScrollPane(stillist);
scrStil.setBounds(stillist.getBounds());
stillist.addListSelectionListener(this);
sizelist.setBounds(315, 25, 60, 72);
JScrollPane scrSize = new JScrollPane(sizelist);
scrSize.setBounds(sizelist.getBounds());
sizelist.addListSelectionListener(this);
///////////////////////////////////////////////////
btnOk.setBounds(380,25,85,25);
btnCancel.setBounds(380,52,85,25);
btnOk.addActionListener(this);
btnCancel.addActionListener(this);
///////////////////////////////////////////////////
font.add(fontlabel);
font.add(stillabel);
font.add(sizelabel);
font.add(scrFont);
font.add(scrStil);
font.add(scrSize);
font.add(scrStil);
font.add(scrSize);
font.add(onizle);
font.add(btnOk);
font.add(btnCancel);
font.setLayout(null);
listeayarla();
onizle.setFont(gelen);
onizle.setText("ABCDEFGÐHIÝJKLMNOÖPRSÞTUÜVYZQXW123 4567890*-" +
"abcdefgðhýijklmnoöprsþtuüvyzqwx"+
"!’^+%&/()=?-#$½¾{[]}\\;:<>|");
font.setVisible(true);
}

public String getFontFamily() { return FontFamily; }
public int getFontStyle() { return FontStyle; }
public int getFontSize()
{
return Integer.parseInt(sizelar[FontSize]);
}

public void actionPerformed(ActionEvent ae)
{
String dugme = ae.getActionCommand();
if(dugme == "Tamam")
{
FontFamily = fontlar[fontlist.getSelectedIndex()];
FontStyle = stillist.getSelectedIndex();
FontSize = Integer.parseInt(sizelar[sizelist.getSelectedIndex()]);
degisecek.setFont(new Font(FontFamily,FontStyle,FontSize));
}
else if(dugme == "Vazgeç")
{
FontFamily = null;
FontStyle = -1;
FontSize = -1;
}
font.setVisible(false);
}

private void listeayarla()
{
for(int i=0;i<fontlar.length;i++)
{
if(fontlar[i].equals(gelen.getFamily().toString()))
{
fontlist.setSelectedIndex(i);
break;
}
}

stillist.setSelectedIndex(gelen.getStyle());

for(int i=0;i<sizelar.length;i++)
{
if(Integer.parseInt(sizelar[i])== gelen.getSize())
{
sizelist.setSelectedIndex(i);
break;
}
}

}
private void TextAyarla()
{

try
{
onizle.setFont(new Font(getFontFamily(),getFontStyle(),getFontSize()) );
onizle.setText("ABCDEFGÐHIÝJKLMNOÖPRSÞTUÜVYZQXW123 4567890*-" +
"abcdefgðhýijklmnoöprsþtuüvyzqwx"+
"!’^+%&/()=?-#$½¾{[]}\\;:<>|");
}
catch(Exception ex)
{
System.out.print(ex.getMessage());
}

}

public void valueChanged(ListSelectionEvent se)
{
try
{
FontFamily = fontlar[fontlist.getSelectedIndex()];
FontStyle = stillist.getSelectedIndex();
FontSize = Integer.parseInt(sizelar[sizelist.getSelectedIndex()]);
TextAyarla();
}catch(Exception ex) {}
}
} 