]> git.somenet.org - irc/pjirc-ng.git/blob - src/main/java/irc/gui/pixx/AWTStyleSelectorEx.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 / AWTStyleSelectorEx.java
1 /*****************************************************/
2 /*          This java file is a part of the          */
3 /*                                                   */
4 /*           -  Plouf's Java IRC Client  -           */
5 /*                                                   */
6 /*   Copyright (C)  2002 - 2004 Philippe Detournay   */
7 /*                                                   */
8 /*         All contacts : theplouf@yahoo.com         */
9 /*                                                   */
10 /*  PJIRC is free software; you can redistribute     */
11 /*  it and/or modify it under the terms of the GNU   */
12 /*  General Public License as published by the       */
13 /*  Free Software Foundation; version 2 or later of  */
14 /*  the License.                                     */
15 /*                                                   */
16 /*  PJIRC is distributed in the hope that it will    */
17 /*  be useful, but WITHOUT ANY WARRANTY; without     */
18 /*  even the implied warranty of MERCHANTABILITY or  */
19 /*  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   */
20 /*  General Public License for more details.         */
21 /*                                                   */
22 /*  You should have received a copy of the GNU       */
23 /*  General Public License along with PJIRC; if      */
24 /*  not, write to the Free Software Foundation,      */
25 /*  Inc., 59 Temple Place, Suite 330, Boston,        */
26 /*  MA  02111-1307  USA                              */
27 /*                                                   */
28 /*****************************************************/
29
30 package irc.gui.pixx;
31
32 import irc.EventDispatcher;
33 import irc.ListenerGroup;
34 import irc.StyleContext;
35
36 import java.awt.BorderLayout;
37 import java.awt.Button;
38 import java.awt.Font;
39 import java.awt.Panel;
40 import java.awt.event.ActionEvent;
41 import java.awt.event.ActionListener;
42
43 /**
44  * Extension for the style selector.
45  */
46 public class AWTStyleSelectorEx extends Panel implements ActionListener, FontSelectorListener {
47         private ListenerGroup _lis;
48         private AWTStyleSelector _selector;
49         private FontSelector _fs;
50         private Button _b;
51
52         /**
53          * Create a new AWTStyleSelectorEx.
54          * 
55          * @param config
56          *          global irc configuration.
57          */
58         public AWTStyleSelectorEx(PixxConfiguration config) {
59                 _fs = new FontSelector(config);
60                 _selector = new AWTStyleSelector(config);
61                 setLayout(new BorderLayout());
62                 add(_selector, BorderLayout.CENTER);
63                 _b = new NonFocusableButton(config.getText(PixxTextProvider.GUI_FONT));
64                 _b.setForeground(config.getColor(PixxColorModel.COLOR_WHITE));
65                 _b.setBackground(config.getColor(PixxColorModel.COLOR_FRONT));
66                 _b.addActionListener(this);
67                 if (config.getB("setfontonstyle"))
68                         add(_b, BorderLayout.EAST);
69                 _lis = new ListenerGroup();
70         }
71
72         /**
73          * Release this object.
74          */
75         public void release() {
76                 removeAll();
77                 _b.removeActionListener(this);
78                 _selector.release();
79                 _fs.release();
80                 _selector = null;
81                 _fs = null;
82         }
83
84         /**
85          * Set the style context.
86          * 
87          * @param ct
88          *          style context.
89          */
90         public void setStyleContext(StyleContext ct) {
91                 _selector.setStyleContext(ct);
92         }
93
94         /**
95          * Get prefix to use.
96          * 
97          * @return style prefix.
98          */
99         public String getPrefix() {
100                 return _selector.getPrefix();
101         }
102
103         /**
104          * Get the style selector.
105          * 
106          * @return the style selector.
107          */
108         public AWTStyleSelector getStyleSelector() {
109                 return _selector;
110         }
111
112         /**
113          * Add a listener.
114          * 
115          * @param lis
116          *          listener to add.
117          */
118         public void addAWTStyleSelectorExListener(AWTStyleSelectorExListener lis) {
119                 _lis.addListener(lis);
120         }
121
122         /**
123          * Remove a listener.
124          * 
125          * @param lis
126          *          listener to remove.
127          */
128         public void removeAWTStyleSelectorExListener(AWTStyleSelectorExListener lis) {
129                 _lis.removeListener(lis);
130         }
131
132         @Override
133         public void actionPerformed(ActionEvent e) {
134                 EventDispatcher.dispatchEventAsync(_fs, "selectFont", new Object[] { this });
135         }
136
137         @Override
138         public void fontSelected(Font f) {
139                 if (f != null)
140                         _lis.sendEvent("fontSelected", f);
141         }
142 }