1
2
3
4
5 package nl.tudelft.simulation.introspection.mapping;
6
7 import java.awt.Dialog;
8 import java.awt.Font;
9 import java.awt.Frame;
10 import java.awt.event.ActionEvent;
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.Iterator;
14 import java.util.List;
15
16 import org.jfree.ui.FontChooserDialog;
17
18 /***
19 * (c) copyright 2002-2005 <a href="http://www.simulation.tudelft.nl">Delft
20 * University of Technology </a>, the Netherlands. <br>
21 * See for project information <a
22 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
23 * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser
24 * General Public License (LGPL) </a>, no warranty.
25 *
26 * @version 1.0 02.04.2003 <br>
27 * @author <a href="http://www.simulation.tudelft.nl/people/lang.html">Niels
28 * Lang </a>, <a href="http://www.peter-jacobs.com">Peter Jacobs </a>
29 */
30 public class MyFontChooserDialog extends FontChooserDialog
31 {
32 /*** the listeners */
33 private List<UserListenerInterface> listeners = Collections
34 .synchronizedList(new ArrayList<UserListenerInterface>(4));
35
36 /***
37 * @param arg0 the dialog
38 * @param arg1 the title
39 * @param arg2 the parent frame
40 * @param arg3 the font
41 */
42 public MyFontChooserDialog(final Dialog arg0, final String arg1,
43 final boolean arg2, final Font arg3)
44 {
45 super(arg0, arg1, arg2, arg3);
46 }
47
48 /***
49 * @param arg0 the dialog
50 * @param arg1 the title
51 * @param arg2 the parent frame
52 * @param arg3 the font
53 */
54 public MyFontChooserDialog(final Frame arg0, final String arg1,
55 final boolean arg2, final Font arg3)
56 {
57 super(arg0, arg1, arg2, arg3);
58 }
59
60 /***
61 * a userListener interface reacting on OK, cancel
62 */
63 public static interface UserListenerInterface
64 {
65 /***
66 * triggered when the OKAction is performed.
67 */
68 public void okActionPerformed();
69
70 /***
71 * triggered when the cancel action is performed.
72 */
73 public void cancelActionPerformed();
74 }
75
76 /***
77 * adds a user listener to the fontChooser Dialog
78 *
79 * @param l the listener
80 */
81 public void addUserListener(final UserListenerInterface l)
82 {
83 this.listeners.add(l);
84 }
85
86 /***
87 * removes a userListener in the fontChooser
88 *
89 * @param l the listener
90 */
91 public void removeUserListener(final UserListenerInterface l)
92 {
93 this.listeners.remove(l);
94 }
95
96 /***
97 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
98 */
99 @Override
100 public void actionPerformed(final ActionEvent evt)
101 {
102 if (evt.getActionCommand().equals("okButton"))
103 {
104 notifyOK();
105 }
106 if (evt.getActionCommand().equals("cancelButton"))
107 {
108 notifyCancel();
109 }
110 super.actionPerformed(evt);
111 }
112
113 /***
114 * notofies OK
115 */
116 private void notifyOK()
117 {
118 for (Iterator<UserListenerInterface> i = this.listeners.iterator(); i
119 .hasNext();)
120 {
121 i.next().okActionPerformed();
122 }
123 }
124
125 /***
126 * notifies cancels
127 */
128 private void notifyCancel()
129 {
130 for (Iterator<UserListenerInterface> i = this.listeners.iterator(); i
131 .hasNext();)
132 {
133 i.next().cancelActionPerformed();
134 }
135 }
136 }