-
Notifications
You must be signed in to change notification settings - Fork 5
/
ThumbPanel.java
219 lines (197 loc) · 6.47 KB
/
ThumbPanel.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
217
218
219
/*
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>
* ThumbPanel.java, a class for making the management of the thumb buttons
* that much easier. See also FingerPanel.
*
* Revisions:
* 0.5 17 July 2003
* Completed Tutor
* 0.2 06 June 2003
* Should be almost finished. We'll see when I get GUI going.
* 0.1 29 May 2003
* Created class FingerPanel
* </pre>
* @author <a href="mailto:visyz@cc.gatech.edu">James Fusia</a>
* @version Version 0.5; 17 July 2003
*/
import java.awt.*;
import javax.swing.*;
import java.util.Vector;
public class ThumbPanel extends JPanel implements TwiddlerSubPanel, TwidorConstants {
/**
* internal variables
*/
private Vector myButtons;
/**
* default constructor
*/
private ThumbPanel () {
}// end ThumbPanel ()
/**
* default constructor
* @param boolean the orientation
* @param KeyMap the keymap to implement
*/
public ThumbPanel (boolean orient, KeyMap keys, boolean visibleKeys) {
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
JPanel panel;
setPreferredSize(new Dimension(twiddlerX, (int)(windowY / 5)));
initButtons();
if (orient) {
setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
}
else {
setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
}
if (bDEBUG) System.out.println("ThumbPanel: creating panel");
setLayout(gridbag);
setBackground(twiddlerBackground);
constraints.weighty = 1;
/* Line 1 - Filler; Label; Label; Filler */
constraints.weightx = 1;
constraints.gridwidth = 1;
filler(gridbag, constraints);
constraints.weightx = 1;
if (visibleKeys) {
label("ALT", gridbag, constraints);
label("CTRL", gridbag, constraints);
}
else {
label("", gridbag, constraints);
label("", gridbag, constraints);
}
constraints.weightx = 1;
constraints.gridwidth = GridBagConstraints.REMAINDER;
filler(gridbag, constraints);
/* Line 2 - Label; Button; Button; Label */
constraints.gridwidth = 1;
constraints.weightx = 2;
if (visibleKeys) {
label("NUM", gridbag, constraints);
}
else {
label("", gridbag, constraints);
}
constraints.weightx = 1;
button(1, gridbag, constraints);
button(2, gridbag, constraints);
constraints.weightx = 2;
constraints.gridwidth = GridBagConstraints.REMAINDER;
if (visibleKeys) {
label("SHIFT", gridbag, constraints);
}
else {
label("", gridbag, constraints);
}
/* Line 3 - Filler; Button; Filler; Filler; Button; Filler */
constraints.weightx = 1;
constraints.gridwidth = 1;
button(0, gridbag, constraints);
constraints.gridwidth = 2;
filler(gridbag, constraints);
constraints.weightx = 1;
button(3, gridbag, constraints);
constraints.gridwidth = GridBagConstraints.REMAINDER;
if (bDEBUG) System.out.println("ThumbPanel: panel created");
}// end ThumbPanel (boolean)
/**
* Quick function to make it easier to use the myButtons variable
*/
private void initButtons () {
myButtons = new Vector(4, 0);
for (int i = 0; i < 4; i++) {
myButtons.add(null);
}
}// end initButtons ()
/**
* Quick function to return the button vector
* @return Vector the buttons this panel holds
*/
public Vector getButtons () {
return myButtons;
}// end getButtons ()
/**
* quick helper function to add filler boxes
* @param GridBagLayout the layout we're using
* @param GridBagConstraints the constraints we have to use
*/
private void filler (GridBagLayout gridbag, GridBagConstraints constraints) {
JPanel panel = new JPanel();
panel.setBackground(twiddlerBackground);
gridbag.setConstraints(panel, constraints);
add(panel);
}// end filler (GridBagLayout, GridBagConstraints)
/**
* quick helper function to add labels
* @param String the label to add
* @param GridBagLayout the layout we use
* @param GridBagConstraints the constraints we're under
*/
private void label (String label, GridBagLayout gridbag, GridBagConstraints constraints) {
JPanel panel = new JPanel();
JLabel thelabel = new JLabel(label, JLabel.CENTER);
thelabel.setFont(new Font("Monospaced", Font.PLAIN, 10));
thelabel.setForeground(Color.WHITE);
panel.setBackground(twiddlerBackground);
panel.add(thelabel);
gridbag.setConstraints(panel, constraints);
add(panel);
}// end label (String, GridBagLayout, GridBagConstraints)
/**
* quick helper function to add buttons
* @param int the button number
* @param GridBagLayout the layout we're using
* @param GridBagConstraints the constraints we use
*/
private void button (int number, GridBagLayout gridbag, GridBagConstraints constraints) {
JPanel panel = new JPanel();
panel.setBackground(buttonBackground);
panel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
gridbag.setConstraints(panel, constraints);
getButtons().setElementAt(panel, number);
add(panel);
}// end button (int, GridBagLayout, GridBagConstraints)
/* --==<( TwiddlerSubPanel Requirement )>==-- */
/**
* highlighting method, for highlighting a key
* @param int which key to highlight
* @param Color what color to use
*/
public void highlight (int which, Color color) {
if (bDEBUG) System.out.println("ThumbPanel: highlighting button " + which);
try {
((JPanel)getButtons().elementAt(which)).setBackground(color);
}
catch (ArrayIndexOutOfBoundsException e) {
if (bDEBUG) System.out.println("ThumbPanel: array oob");
}
}// end highlight (int, Color)
/* --==<( TwiddlerSubPanel Requirement )>==-- */
/**
* clearing method, for restoring the button to it's default color
*/
public void clear () {
if (bDEBUG) System.out.println("ThumbPanel: clearing buttons");
for (int i = 0; i < getButtons().size(); i++) {
((JPanel)getButtons().elementAt(i)).setBackground(buttonBackground);
}
}// end clear ()
}// end class THumbPanel