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