forked from evantd/twidor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwidorMenu.java
216 lines (194 loc) · 5.8 KB
/
TwidorMenu.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
Twidor: the twiddler typing tutor.
Copyright (C) 2005 James Fusia
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA.
*/
/**
* CCG: Twidor- The Twiddler Tutor!
* <pre>
* This class is here to automate the Menu switching and flipping
* and flopping and other fish-like features.
*
* Revisions:
* 0.5 17 July 2003
* Completed Tutor
* 0.1 17 June 2003
* Created class TwidorMenu
* </pre>
* @author <a href="mailto:[email protected]">James Fusia</a>
* @version Version 0.5; 17 July 2003
*/
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class TwidorMenu extends JMenuBar implements TwidorConstants {
/**
* internal variables
*/
EventHandler myEventHandler;
Twidor myTutor;
Vector Tutor, Twiddler;
ButtonGroup Lesson;
Vector lessonButtons;
/**
* default constructor
*/
private TwidorMenu () {
if (bDEBUG) System.out.println("TwidorMenu: New MenuBar Created");
}// end TwidorMenu ()
/**
* default constructor
*/
public TwidorMenu (Twidor tutor, EventHandler events, int lessonCount) {
this();
JMenu menu;
JMenuItem jmItem;
JCheckBoxMenuItem cbItem;
JRadioButtonMenuItem rbItem;
Tutor(tutor);
Events(events);
menu = new JMenu("Twidor");
jmItem = jmenuItem(QUIT_TEXT);
menu.add(jmItem);
add(menu);
Tutor = new Vector();
menu = new JMenu("Tutor");
jmItem = jcheckItem(HIGHLIGHT_HINT_TEXT, HIGHLIGHT_HINT);
Tutor.add(jmItem);
menu.add(jmItem);
jmItem = jcheckItem(HIGHLIGHT_KEYPRESS_TEXT, HIGHLIGHT_KEYPRESS);
Tutor.add(jmItem);
menu.add(jmItem);
jmItem = jcheckItem(HIGHLIGHT_ERRORS_TEXT, HIGHLIGHT_ERRORS);
Tutor.add(jmItem);
menu.add(jmItem);
add(menu);
Twiddler = new Vector();
menu = new JMenu("Twiddler");
jmItem = jcheckItem(TWIDDLER_SHOW_TEXT, TWIDDLER_SHOW);
Twiddler.add(jmItem);
menu.add(jmItem);
jmItem = jcheckItem(TWIDDLER_MIRROR_TEXT, TWIDDLER_MIRROR);
Twiddler.add(jmItem);
menu.add(jmItem);
jmItem = jcheckItem(TWIDDLER_SHOW_LETTERS_TEXT, TWIDDLER_SHOW_LETTERS);
Twiddler.add(jmItem);
menu.add(jmItem);
add(menu);
Lesson = new ButtonGroup();
lessonButtons = new Vector();
menu = new JMenu("Lesson");
rbItem = jradioItem("Lesson 1", true);
Lesson.add(rbItem);
lessonButtons.add(rbItem);
menu.add(rbItem);
for (int i = 2; i <= lessonCount; i++) {
rbItem = jradioItem("Lesson " + i, false);
Lesson.add(rbItem);
lessonButtons.add(rbItem);
menu.add(rbItem);
}
add(menu);
if (bDEBUG) System.out.println("TwidorMenu: Finished Creating");
}// end TwidorMenu (Twidor, EventHandler)
/**
* helper function for creating menu items.
* @param String the text of the item
* @return JMenuItem the completed item.
*/
private JMenuItem jmenuItem (String text) {
JMenuItem toReturn = new JMenuItem(text);
toReturn.addActionListener(Events());
return toReturn;
}// end jmenuItem (String)
/**
* helper function for creating menu items.
* @param String the text of the item
* @param boolean the default value of the item
* @return JCheckBoxMenuItem the completed item
*/
private JCheckBoxMenuItem jcheckItem (String text, boolean status) {
JCheckBoxMenuItem toReturn = new JCheckBoxMenuItem(text, status);
toReturn.addItemListener(Events());
return toReturn;
}// end jcheckItem (String, boolean)
/**
* helper function for creating radio menu items
* @param String the text of the item
* @param boolean the default value of the item
* @return JRadioButtonMenuItem the completed item
*/
private JRadioButtonMenuItem jradioItem (String text, boolean status) {
JRadioButtonMenuItem toReturn = new JRadioButtonMenuItem(text, status);
toReturn.setActionCommand(text);
toReturn.setSelected(status);
toReturn.addActionListener(Events());
return toReturn;
}// end jradioItem (String, boolean)
/**
* Used for ensuring certain elements of the menu can't overlap each other.
* @param String the element that just got fiddled with
* @param boolean the state it got changed to
*/
public void itemSelected (String item, boolean state) {
if (bDEBUG) System.out.println("TwidorMenu: " + item + " selected " + state);
if (item.equals(TWIDDLER_SHOW_TEXT)) {
if (state) {
((JMenuItem)Twiddler.elementAt(1)).setEnabled(true);
((JMenuItem)Twiddler.elementAt(2)).setEnabled(true);
} else {
((JMenuItem)Twiddler.elementAt(1)).setEnabled(false);
((JMenuItem)Twiddler.elementAt(2)).setEnabled(false);
}
}
}// end itemSelected (String, boolean)
public void makeSelectedLesson (String lesson) {
JRadioButtonMenuItem temp;
for (int i = 0; i < lessonButtons.size(); i++) {
temp = (JRadioButtonMenuItem)lessonButtons.elementAt(i);
if (temp.getActionCommand().equals(lesson)) {
temp.doClick();
return;
}
}
}
/**
* Modifier
* @param Twidor
*/
private void Tutor (Twidor tutor) {
myTutor = tutor;
}// end Tutor (Twidor)
/**
* Accessor
* @return Twidor
*/
public Twidor Tutor () {
return myTutor;
}// end Tutor ()
/**
* Modifier
* @param EventHandler
*/
private void Events (EventHandler events) {
myEventHandler = events;
}// end Events (EventHandler)
/**
* Accessor
* @return EventHandler
*/
public EventHandler Events () {
return myEventHandler;
}// end Events ()
}// end class TwidorMenu