]> git.somenet.org - irc/pjirc-ng.git/blob - src/main/java/irc/gui/pixx/FontSelector.java
Pjirc 2.2.1 as available on the net, reformatted and made it compile.
[irc/pjirc-ng.git] / src / main / java / irc / gui / pixx / FontSelector.java
1 /*****************************************************/\r
2 /*          This java file is a part of the          */\r
3 /*                                                   */\r
4 /*           -  Plouf's Java IRC Client  -           */\r
5 /*                                                   */\r
6 /*   Copyright (C)  2002 - 2004 Philippe Detournay   */\r
7 /*                                                   */\r
8 /*         All contacts : theplouf@yahoo.com         */\r
9 /*                                                   */\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
14 /*  the License.                                     */\r
15 /*                                                   */\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
21 /*                                                   */\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
27 /*                                                   */\r
28 /*****************************************************/\r
29 \r
30 package irc.gui.pixx;\r
31 \r
32 import irc.EventDispatcher;\r
33 \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
45 \r
46 /**\r
47  * The font selector window.\r
48  */\r
49 public class FontSelector implements WindowListener, ActionListener, Runnable {\r
50         private Choice _name;\r
51         private TextField _size;\r
52         private Button _ok;\r
53         private Frame _f;\r
54         private FontSelectorListener _lis;\r
55 \r
56         /**\r
57          * Create a new font selector.\r
58          * \r
59          * @param config\r
60          *          the irc configuration.\r
61          */\r
62         public FontSelector(PixxConfiguration config) {\r
63                 _f = new Frame();\r
64                 _f.setTitle(config.getText(PixxTextProvider.GUI_FONT_WINDOW));\r
65                 _name = new Choice();\r
66                 _name.add("Monospaced");\r
67                 _name.add("Serif");\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
75                 _f.add(p);\r
76                 p.setLayout(new FlowLayout(FlowLayout.CENTER));\r
77                 p.add(_name);\r
78                 p.add(_size);\r
79                 p.add(_ok);\r
80 \r
81                 // _f.setResizable(false);\r
82                 _f.setSize(200, 80);\r
83                 _f.addWindowListener(this);\r
84         }\r
85 \r
86         @Override\r
87         public void run() {\r
88                 if (_f != null)\r
89                         _f.dispose();\r
90                 _f = null;\r
91         }\r
92 \r
93         /**\r
94          * Release this object.\r
95          */\r
96         public void release() {\r
97                 _ok.removeActionListener(this);\r
98                 _f.removeWindowListener(this);\r
99                 _f.removeAll();\r
100                 Thread t = new Thread(this, "Frame disposal thread");\r
101                 t.start();\r
102                 // _f.dispose();\r
103                 // _f=null;\r
104                 _lis = null;\r
105         }\r
106 \r
107         /**\r
108          * Ask for a font to be selected, calling back the given listener once choice\r
109          * is performed.\r
110          * \r
111          * @param lis\r
112          *          listener to be called once font is selected.\r
113          */\r
114         public void selectFont(FontSelectorListener lis) {\r
115                 _lis = lis;\r
116                 _f.show();\r
117         }\r
118 \r
119         @Override\r
120         public void windowActivated(WindowEvent e) {\r
121         }\r
122 \r
123         @Override\r
124         public void windowClosed(WindowEvent e) {\r
125         }\r
126 \r
127         @Override\r
128         public void windowClosing(WindowEvent e) {\r
129                 _f.hide();\r
130         }\r
131 \r
132         @Override\r
133         public void windowDeactivated(WindowEvent e) {\r
134         }\r
135 \r
136         @Override\r
137         public void windowDeiconified(WindowEvent e) {\r
138         }\r
139 \r
140         @Override\r
141         public void windowIconified(WindowEvent e) {\r
142         }\r
143 \r
144         @Override\r
145         public void windowOpened(WindowEvent e) {\r
146         }\r
147 \r
148         private Font getResult() {\r
149                 String name = _name.getSelectedItem();\r
150                 int size = 12;\r
151                 try {\r
152                         size = (new Integer(_size.getText())).intValue();\r
153                 } catch (Exception ex) {\r
154                 }\r
155                 return new Font(name, Font.PLAIN, size);\r
156         }\r
157 \r
158         @Override\r
159         public void actionPerformed(ActionEvent e) {\r
160                 _f.hide();\r
161                 Font f = getResult();\r
162                 if (_lis != null)\r
163                         EventDispatcher.dispatchEventAsync(_lis, "fontSelected", new Object[] { f });\r
164         }\r
165 }\r