1 /*****************************************************/
\r
2 /* This java file is a part of the */
\r
4 /* - Plouf's Java IRC Client - */
\r
6 /* Copyright (C) 2002 - 2004 Philippe Detournay */
\r
8 /* All contacts : theplouf@yahoo.com */
\r
10 /* PJIRC is free software; you can redistribute */
\r
11 /* it and/or modify it under the terms of the GNU */
\r
12 /* General Public License as published by the */
\r
13 /* Free Software Foundation; version 2 or later of */
\r
16 /* PJIRC is distributed in the hope that it will */
\r
17 /* be useful, but WITHOUT ANY WARRANTY; without */
\r
18 /* even the implied warranty of MERCHANTABILITY or */
\r
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
\r
20 /* General Public License for more details. */
\r
22 /* You should have received a copy of the GNU */
\r
23 /* General Public License along with PJIRC; if */
\r
24 /* not, write to the Free Software Foundation, */
\r
25 /* Inc., 59 Temple Place, Suite 330, Boston, */
\r
26 /* MA 02111-1307 USA */
\r
28 /*****************************************************/
\r
30 package irc.gui.pixx;
\r
32 import irc.EventDispatcher;
\r
34 import java.awt.Button;
\r
35 import java.awt.Choice;
\r
36 import java.awt.FlowLayout;
\r
37 import java.awt.Font;
\r
38 import java.awt.Frame;
\r
39 import java.awt.Panel;
\r
40 import java.awt.TextField;
\r
41 import java.awt.event.ActionEvent;
\r
42 import java.awt.event.ActionListener;
\r
43 import java.awt.event.WindowEvent;
\r
44 import java.awt.event.WindowListener;
\r
47 * The font selector window.
\r
49 public class FontSelector implements WindowListener, ActionListener, Runnable {
\r
50 private Choice _name;
\r
51 private TextField _size;
\r
54 private FontSelectorListener _lis;
\r
57 * Create a new font selector.
\r
60 * the irc configuration.
\r
62 public FontSelector(PixxConfiguration config) {
\r
64 _f.setTitle(config.getText(PixxTextProvider.GUI_FONT_WINDOW));
\r
65 _name = new Choice();
\r
66 _name.add("Monospaced");
\r
68 _name.add("SansSerif");
\r
69 _name.add("Dialog");
\r
70 _name.add("DialogInput");
\r
71 _size = new TextField("12");
\r
72 _ok = new Button(config.getText(PixxTextProvider.GUI_FONT_WINDOW_OK));
\r
73 _ok.addActionListener(this);
\r
74 Panel p = new Panel();
\r
76 p.setLayout(new FlowLayout(FlowLayout.CENTER));
\r
81 // _f.setResizable(false);
\r
82 _f.setSize(200, 80);
\r
83 _f.addWindowListener(this);
\r
94 * Release this object.
\r
96 public void release() {
\r
97 _ok.removeActionListener(this);
\r
98 _f.removeWindowListener(this);
\r
100 Thread t = new Thread(this, "Frame disposal thread");
\r
108 * Ask for a font to be selected, calling back the given listener once choice
\r
112 * listener to be called once font is selected.
\r
114 public void selectFont(FontSelectorListener lis) {
\r
120 public void windowActivated(WindowEvent e) {
\r
124 public void windowClosed(WindowEvent e) {
\r
128 public void windowClosing(WindowEvent e) {
\r
133 public void windowDeactivated(WindowEvent e) {
\r
137 public void windowDeiconified(WindowEvent e) {
\r
141 public void windowIconified(WindowEvent e) {
\r
145 public void windowOpened(WindowEvent e) {
\r
148 private Font getResult() {
\r
149 String name = _name.getSelectedItem();
\r
152 size = (new Integer(_size.getText())).intValue();
\r
153 } catch (Exception ex) {
\r
155 return new Font(name, Font.PLAIN, size);
\r
159 public void actionPerformed(ActionEvent e) {
\r
161 Font f = getResult();
\r
163 EventDispatcher.dispatchEventAsync(_lis, "fontSelected", new Object[] { f });
\r