update e621 (site changed + move to not deprecated BasicSupport
[fanfix.git] / src / jexer / TKeypress.java
CommitLineData
daa4106c 1/*
df8de03f
KL
2 * Jexer - Java Text User Interface
3 *
e16dda65 4 * The MIT License (MIT)
df8de03f 5 *
a69ed767 6 * Copyright (C) 2019 Kevin Lamonte
df8de03f 7 *
e16dda65
KL
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
df8de03f 14 *
e16dda65
KL
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
df8de03f 17 *
e16dda65
KL
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
7b5261bc
KL
25 *
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
27 * @version 1
df8de03f
KL
28 */
29package jexer;
30
31/**
32 * This class represents keystrokes.
33 */
051e2913 34public class TKeypress {
df8de03f 35
d36057df
KL
36 // ------------------------------------------------------------------------
37 // Constants --------------------------------------------------------------
38 // ------------------------------------------------------------------------
39
df8de03f
KL
40 // Various special keystrokes
41
42 /**
7b5261bc 43 * "No key".
df8de03f 44 */
7b5261bc 45 public static final int NONE = 255;
df8de03f
KL
46
47 /**
7b5261bc 48 * Function key F1.
df8de03f 49 */
7b5261bc 50 public static final int F1 = 1;
df8de03f
KL
51
52 /**
7b5261bc 53 * Function key F2.
df8de03f 54 */
7b5261bc 55 public static final int F2 = 2;
df8de03f
KL
56
57 /**
7b5261bc 58 * Function key F3.
df8de03f 59 */
7b5261bc 60 public static final int F3 = 3;
df8de03f
KL
61
62 /**
7b5261bc 63 * Function key F4.
df8de03f 64 */
7b5261bc 65 public static final int F4 = 4;
df8de03f
KL
66
67 /**
7b5261bc 68 * Function key F5.
df8de03f 69 */
7b5261bc 70 public static final int F5 = 5;
df8de03f
KL
71
72 /**
7b5261bc 73 * Function key F6.
df8de03f 74 */
7b5261bc 75 public static final int F6 = 6;
df8de03f
KL
76
77 /**
7b5261bc 78 * Function key F7.
df8de03f 79 */
7b5261bc 80 public static final int F7 = 7;
df8de03f
KL
81
82 /**
7b5261bc 83 * Function key F8.
df8de03f 84 */
7b5261bc 85 public static final int F8 = 8;
df8de03f
KL
86
87 /**
7b5261bc 88 * Function key F9.
df8de03f 89 */
7b5261bc 90 public static final int F9 = 9;
df8de03f
KL
91
92 /**
7b5261bc 93 * Function key F10.
df8de03f 94 */
7b5261bc 95 public static final int F10 = 10;
df8de03f
KL
96
97 /**
7b5261bc 98 * Function key F11.
df8de03f 99 */
7b5261bc 100 public static final int F11 = 11;
df8de03f
KL
101
102 /**
7b5261bc 103 * Function key F12.
df8de03f 104 */
7b5261bc 105 public static final int F12 = 12;
df8de03f
KL
106
107 /**
7b5261bc 108 * Home.
df8de03f 109 */
7b5261bc 110 public static final int HOME = 20;
df8de03f
KL
111
112 /**
7b5261bc 113 * End.
df8de03f 114 */
7b5261bc 115 public static final int END = 21;
df8de03f
KL
116
117 /**
7b5261bc 118 * Page up.
df8de03f 119 */
7b5261bc 120 public static final int PGUP = 22;
df8de03f
KL
121
122 /**
7b5261bc 123 * Page down.
df8de03f 124 */
7b5261bc 125 public static final int PGDN = 23;
df8de03f
KL
126
127 /**
7b5261bc 128 * Insert.
df8de03f 129 */
7b5261bc 130 public static final int INS = 24;
df8de03f
KL
131
132 /**
7b5261bc 133 * Delete.
df8de03f 134 */
7b5261bc 135 public static final int DEL = 25;
df8de03f
KL
136
137 /**
7b5261bc 138 * Right arrow.
df8de03f 139 */
7b5261bc 140 public static final int RIGHT = 30;
df8de03f
KL
141
142 /**
7b5261bc 143 * Left arrow.
df8de03f 144 */
7b5261bc 145 public static final int LEFT = 31;
df8de03f
KL
146
147 /**
7b5261bc 148 * Up arrow.
df8de03f 149 */
7b5261bc 150 public static final int UP = 32;
df8de03f
KL
151
152 /**
7b5261bc 153 * Down arrow.
df8de03f 154 */
7b5261bc 155 public static final int DOWN = 33;
df8de03f
KL
156
157 /**
7b5261bc 158 * Tab.
df8de03f 159 */
7b5261bc 160 public static final int TAB = 40;
df8de03f
KL
161
162 /**
7b5261bc 163 * Back-tab (shift-tab).
df8de03f 164 */
7b5261bc 165 public static final int BTAB = 41;
df8de03f
KL
166
167 /**
7b5261bc 168 * Enter.
df8de03f 169 */
7b5261bc 170 public static final int ENTER = 42;
df8de03f
KL
171
172 /**
7b5261bc 173 * Escape.
df8de03f 174 */
7b5261bc 175 public static final int ESC = 43;
df8de03f 176
d36057df
KL
177 // Special "no-key" keypress, used to ignore undefined keystrokes
178 public static final TKeypress kbNoKey = new TKeypress(true,
179 TKeypress.NONE, ' ', false, false, false);
df8de03f
KL
180
181 // Normal keys
7b5261bc 182 public static final TKeypress kbF1 = new TKeypress(true,
7c870d89 183 TKeypress.F1, ' ', false, false, false);
7b5261bc 184 public static final TKeypress kbF2 = new TKeypress(true,
7c870d89 185 TKeypress.F2, ' ', false, false, false);
7b5261bc 186 public static final TKeypress kbF3 = new TKeypress(true,
7c870d89 187 TKeypress.F3, ' ', false, false, false);
7b5261bc 188 public static final TKeypress kbF4 = new TKeypress(true,
7c870d89 189 TKeypress.F4, ' ', false, false, false);
7b5261bc 190 public static final TKeypress kbF5 = new TKeypress(true,
7c870d89 191 TKeypress.F5, ' ', false, false, false);
7b5261bc 192 public static final TKeypress kbF6 = new TKeypress(true,
7c870d89 193 TKeypress.F6, ' ', false, false, false);
7b5261bc 194 public static final TKeypress kbF7 = new TKeypress(true,
7c870d89 195 TKeypress.F7, ' ', false, false, false);
7b5261bc 196 public static final TKeypress kbF8 = new TKeypress(true,
7c870d89 197 TKeypress.F8, ' ', false, false, false);
7b5261bc 198 public static final TKeypress kbF9 = new TKeypress(true,
7c870d89 199 TKeypress.F9, ' ', false, false, false);
7b5261bc 200 public static final TKeypress kbF10 = new TKeypress(true,
7c870d89 201 TKeypress.F10, ' ', false, false, false);
7b5261bc 202 public static final TKeypress kbF11 = new TKeypress(true,
7c870d89 203 TKeypress.F11, ' ', false, false, false);
7b5261bc 204 public static final TKeypress kbF12 = new TKeypress(true,
7c870d89 205 TKeypress.F12, ' ', false, false, false);
7b5261bc 206 public static final TKeypress kbAltF1 = new TKeypress(true,
7c870d89 207 TKeypress.F1, ' ', true, false, false);
7b5261bc 208 public static final TKeypress kbAltF2 = new TKeypress(true,
7c870d89 209 TKeypress.F2, ' ', true, false, false);
7b5261bc 210 public static final TKeypress kbAltF3 = new TKeypress(true,
7c870d89 211 TKeypress.F3, ' ', true, false, false);
7b5261bc 212 public static final TKeypress kbAltF4 = new TKeypress(true,
7c870d89 213 TKeypress.F4, ' ', true, false, false);
7b5261bc 214 public static final TKeypress kbAltF5 = new TKeypress(true,
7c870d89 215 TKeypress.F5, ' ', true, false, false);
7b5261bc 216 public static final TKeypress kbAltF6 = new TKeypress(true,
7c870d89 217 TKeypress.F6, ' ', true, false, false);
7b5261bc 218 public static final TKeypress kbAltF7 = new TKeypress(true,
7c870d89 219 TKeypress.F7, ' ', true, false, false);
7b5261bc 220 public static final TKeypress kbAltF8 = new TKeypress(true,
7c870d89 221 TKeypress.F8, ' ', true, false, false);
7b5261bc 222 public static final TKeypress kbAltF9 = new TKeypress(true,
7c870d89 223 TKeypress.F9, ' ', true, false, false);
7b5261bc 224 public static final TKeypress kbAltF10 = new TKeypress(true,
7c870d89 225 TKeypress.F10, ' ', true, false, false);
7b5261bc 226 public static final TKeypress kbAltF11 = new TKeypress(true,
7c870d89 227 TKeypress.F11, ' ', true, false, false);
7b5261bc 228 public static final TKeypress kbAltF12 = new TKeypress(true,
7c870d89 229 TKeypress.F12, ' ', true, false, false);
7b5261bc 230 public static final TKeypress kbCtrlF1 = new TKeypress(true,
7c870d89 231 TKeypress.F1, ' ', false, true, false);
7b5261bc 232 public static final TKeypress kbCtrlF2 = new TKeypress(true,
7c870d89 233 TKeypress.F2, ' ', false, true, false);
7b5261bc 234 public static final TKeypress kbCtrlF3 = new TKeypress(true,
7c870d89 235 TKeypress.F3, ' ', false, true, false);
7b5261bc 236 public static final TKeypress kbCtrlF4 = new TKeypress(true,
7c870d89 237 TKeypress.F4, ' ', false, true, false);
7b5261bc 238 public static final TKeypress kbCtrlF5 = new TKeypress(true,
7c870d89 239 TKeypress.F5, ' ', false, true, false);
7b5261bc 240 public static final TKeypress kbCtrlF6 = new TKeypress(true,
7c870d89 241 TKeypress.F6, ' ', false, true, false);
7b5261bc 242 public static final TKeypress kbCtrlF7 = new TKeypress(true,
7c870d89 243 TKeypress.F7, ' ', false, true, false);
7b5261bc 244 public static final TKeypress kbCtrlF8 = new TKeypress(true,
7c870d89 245 TKeypress.F8, ' ', false, true, false);
7b5261bc 246 public static final TKeypress kbCtrlF9 = new TKeypress(true,
7c870d89 247 TKeypress.F9, ' ', false, true, false);
7b5261bc 248 public static final TKeypress kbCtrlF10 = new TKeypress(true,
7c870d89 249 TKeypress.F10, ' ', false, true, false);
7b5261bc 250 public static final TKeypress kbCtrlF11 = new TKeypress(true,
7c870d89 251 TKeypress.F11, ' ', false, true, false);
7b5261bc 252 public static final TKeypress kbCtrlF12 = new TKeypress(true,
7c870d89 253 TKeypress.F12, ' ', false, true, false);
7b5261bc 254 public static final TKeypress kbShiftF1 = new TKeypress(true,
7c870d89 255 TKeypress.F1, ' ', false, false, true);
7b5261bc 256 public static final TKeypress kbShiftF2 = new TKeypress(true,
7c870d89 257 TKeypress.F2, ' ', false, false, true);
7b5261bc 258 public static final TKeypress kbShiftF3 = new TKeypress(true,
7c870d89 259 TKeypress.F3, ' ', false, false, true);
7b5261bc 260 public static final TKeypress kbShiftF4 = new TKeypress(true,
7c870d89 261 TKeypress.F4, ' ', false, false, true);
7b5261bc 262 public static final TKeypress kbShiftF5 = new TKeypress(true,
7c870d89 263 TKeypress.F5, ' ', false, false, true);
7b5261bc 264 public static final TKeypress kbShiftF6 = new TKeypress(true,
7c870d89 265 TKeypress.F6, ' ', false, false, true);
7b5261bc 266 public static final TKeypress kbShiftF7 = new TKeypress(true,
7c870d89 267 TKeypress.F7, ' ', false, false, true);
7b5261bc 268 public static final TKeypress kbShiftF8 = new TKeypress(true,
7c870d89 269 TKeypress.F8, ' ', false, false, true);
7b5261bc 270 public static final TKeypress kbShiftF9 = new TKeypress(true,
7c870d89 271 TKeypress.F9, ' ', false, false, true);
7b5261bc 272 public static final TKeypress kbShiftF10 = new TKeypress(true,
7c870d89 273 TKeypress.F10, ' ', false, false, true);
7b5261bc 274 public static final TKeypress kbShiftF11 = new TKeypress(true,
7c870d89 275 TKeypress.F11, ' ', false, false, true);
7b5261bc 276 public static final TKeypress kbShiftF12 = new TKeypress(true,
7c870d89 277 TKeypress.F12, ' ', false, false, true);
7b5261bc 278 public static final TKeypress kbEnter = new TKeypress(true,
7c870d89 279 TKeypress.ENTER, ' ', false, false, false);
7b5261bc 280 public static final TKeypress kbTab = new TKeypress(true,
7c870d89 281 TKeypress.TAB, ' ', false, false, false);
7b5261bc 282 public static final TKeypress kbEsc = new TKeypress(true,
7c870d89 283 TKeypress.ESC, ' ', false, false, false);
7b5261bc 284 public static final TKeypress kbHome = new TKeypress(true,
7c870d89 285 TKeypress.HOME, ' ', false, false, false);
7b5261bc 286 public static final TKeypress kbEnd = new TKeypress(true,
7c870d89 287 TKeypress.END, ' ', false, false, false);
7b5261bc 288 public static final TKeypress kbPgUp = new TKeypress(true,
7c870d89 289 TKeypress.PGUP, ' ', false, false, false);
7b5261bc 290 public static final TKeypress kbPgDn = new TKeypress(true,
7c870d89 291 TKeypress.PGDN, ' ', false, false, false);
7b5261bc 292 public static final TKeypress kbIns = new TKeypress(true,
7c870d89 293 TKeypress.INS, ' ', false, false, false);
7b5261bc 294 public static final TKeypress kbDel = new TKeypress(true,
7c870d89 295 TKeypress.DEL, ' ', false, false, false);
7b5261bc 296 public static final TKeypress kbUp = new TKeypress(true,
7c870d89 297 TKeypress.UP, ' ', false, false, false);
7b5261bc 298 public static final TKeypress kbDown = new TKeypress(true,
7c870d89 299 TKeypress.DOWN, ' ', false, false, false);
7b5261bc 300 public static final TKeypress kbLeft = new TKeypress(true,
7c870d89 301 TKeypress.LEFT, ' ', false, false, false);
7b5261bc 302 public static final TKeypress kbRight = new TKeypress(true,
7c870d89 303 TKeypress.RIGHT, ' ', false, false, false);
7b5261bc 304 public static final TKeypress kbAltEnter = new TKeypress(true,
7c870d89 305 TKeypress.ENTER, ' ', true, false, false);
7b5261bc 306 public static final TKeypress kbAltTab = new TKeypress(true,
7c870d89 307 TKeypress.TAB, ' ', true, false, false);
7b5261bc 308 public static final TKeypress kbAltEsc = new TKeypress(true,
7c870d89 309 TKeypress.ESC, ' ', true, false, false);
7b5261bc 310 public static final TKeypress kbAltHome = new TKeypress(true,
7c870d89 311 TKeypress.HOME, ' ', true, false, false);
7b5261bc 312 public static final TKeypress kbAltEnd = new TKeypress(true,
7c870d89 313 TKeypress.END, ' ', true, false, false);
7b5261bc 314 public static final TKeypress kbAltPgUp = new TKeypress(true,
7c870d89 315 TKeypress.PGUP, ' ', true, false, false);
7b5261bc 316 public static final TKeypress kbAltPgDn = new TKeypress(true,
7c870d89 317 TKeypress.PGDN, ' ', true, false, false);
7b5261bc 318 public static final TKeypress kbAltIns = new TKeypress(true,
7c870d89 319 TKeypress.INS, ' ', true, false, false);
7b5261bc 320 public static final TKeypress kbAltDel = new TKeypress(true,
7c870d89 321 TKeypress.DEL, ' ', true, false, false);
7b5261bc 322 public static final TKeypress kbAltUp = new TKeypress(true,
7c870d89 323 TKeypress.UP, ' ', true, false, false);
7b5261bc 324 public static final TKeypress kbAltDown = new TKeypress(true,
7c870d89 325 TKeypress.DOWN, ' ', true, false, false);
7b5261bc 326 public static final TKeypress kbAltLeft = new TKeypress(true,
7c870d89 327 TKeypress.LEFT, ' ', true, false, false);
7b5261bc 328 public static final TKeypress kbAltRight = new TKeypress(true,
7c870d89 329 TKeypress.RIGHT, ' ', true, false, false);
7b5261bc 330 public static final TKeypress kbCtrlEnter = new TKeypress(true,
7c870d89 331 TKeypress.ENTER, ' ', false, true, false);
7b5261bc 332 public static final TKeypress kbCtrlTab = new TKeypress(true,
7c870d89 333 TKeypress.TAB, ' ', false, true, false);
7b5261bc 334 public static final TKeypress kbCtrlEsc = new TKeypress(true,
7c870d89 335 TKeypress.ESC, ' ', false, true, false);
7b5261bc 336 public static final TKeypress kbCtrlHome = new TKeypress(true,
7c870d89 337 TKeypress.HOME, ' ', false, true, false);
7b5261bc 338 public static final TKeypress kbCtrlEnd = new TKeypress(true,
7c870d89 339 TKeypress.END, ' ', false, true, false);
7b5261bc 340 public static final TKeypress kbCtrlPgUp = new TKeypress(true,
7c870d89 341 TKeypress.PGUP, ' ', false, true, false);
7b5261bc 342 public static final TKeypress kbCtrlPgDn = new TKeypress(true,
7c870d89 343 TKeypress.PGDN, ' ', false, true, false);
7b5261bc 344 public static final TKeypress kbCtrlIns = new TKeypress(true,
7c870d89 345 TKeypress.INS, ' ', false, true, false);
7b5261bc 346 public static final TKeypress kbCtrlDel = new TKeypress(true,
7c870d89 347 TKeypress.DEL, ' ', false, true, false);
7b5261bc 348 public static final TKeypress kbCtrlUp = new TKeypress(true,
7c870d89 349 TKeypress.UP, ' ', false, true, false);
7b5261bc 350 public static final TKeypress kbCtrlDown = new TKeypress(true,
7c870d89 351 TKeypress.DOWN, ' ', false, true, false);
7b5261bc 352 public static final TKeypress kbCtrlLeft = new TKeypress(true,
7c870d89 353 TKeypress.LEFT, ' ', false, true, false);
7b5261bc 354 public static final TKeypress kbCtrlRight = new TKeypress(true,
7c870d89 355 TKeypress.RIGHT, ' ', false, true, false);
7b5261bc 356 public static final TKeypress kbShiftEnter = new TKeypress(true,
7c870d89 357 TKeypress.ENTER, ' ', false, false, true);
7b5261bc 358 public static final TKeypress kbShiftTab = new TKeypress(true,
7c870d89 359 TKeypress.TAB, ' ', false, false, true);
7b5261bc 360 public static final TKeypress kbBackTab = new TKeypress(true,
7c870d89 361 TKeypress.BTAB, ' ', false, false, false);
7b5261bc 362 public static final TKeypress kbShiftEsc = new TKeypress(true,
7c870d89 363 TKeypress.ESC, ' ', false, false, true);
7b5261bc 364 public static final TKeypress kbShiftHome = new TKeypress(true,
7c870d89 365 TKeypress.HOME, ' ', false, false, true);
7b5261bc 366 public static final TKeypress kbShiftEnd = new TKeypress(true,
7c870d89 367 TKeypress.END, ' ', false, false, true);
7b5261bc 368 public static final TKeypress kbShiftPgUp = new TKeypress(true,
7c870d89 369 TKeypress.PGUP, ' ', false, false, true);
7b5261bc 370 public static final TKeypress kbShiftPgDn = new TKeypress(true,
7c870d89 371 TKeypress.PGDN, ' ', false, false, true);
7b5261bc 372 public static final TKeypress kbShiftIns = new TKeypress(true,
7c870d89 373 TKeypress.INS, ' ', false, false, true);
7b5261bc 374 public static final TKeypress kbShiftDel = new TKeypress(true,
7c870d89 375 TKeypress.DEL, ' ', false, false, true);
7b5261bc 376 public static final TKeypress kbShiftUp = new TKeypress(true,
7c870d89 377 TKeypress.UP, ' ', false, false, true);
7b5261bc 378 public static final TKeypress kbShiftDown = new TKeypress(true,
7c870d89 379 TKeypress.DOWN, ' ', false, false, true);
7b5261bc 380 public static final TKeypress kbShiftLeft = new TKeypress(true,
7c870d89 381 TKeypress.LEFT, ' ', false, false, true);
7b5261bc 382 public static final TKeypress kbShiftRight = new TKeypress(true,
7c870d89 383 TKeypress.RIGHT, ' ', false, false, true);
7b5261bc 384 public static final TKeypress kbA = new TKeypress(false,
7c870d89 385 0, 'a', false, false, false);
7b5261bc 386 public static final TKeypress kbB = new TKeypress(false,
7c870d89 387 0, 'b', false, false, false);
7b5261bc 388 public static final TKeypress kbC = new TKeypress(false,
7c870d89 389 0, 'c', false, false, false);
7b5261bc 390 public static final TKeypress kbD = new TKeypress(false,
7c870d89 391 0, 'd', false, false, false);
7b5261bc 392 public static final TKeypress kbE = new TKeypress(false,
7c870d89 393 0, 'e', false, false, false);
7b5261bc 394 public static final TKeypress kbF = new TKeypress(false,
7c870d89 395 0, 'f', false, false, false);
7b5261bc 396 public static final TKeypress kbG = new TKeypress(false,
7c870d89 397 0, 'g', false, false, false);
7b5261bc 398 public static final TKeypress kbH = new TKeypress(false,
7c870d89 399 0, 'h', false, false, false);
7b5261bc 400 public static final TKeypress kbI = new TKeypress(false,
7c870d89 401 0, 'i', false, false, false);
7b5261bc 402 public static final TKeypress kbJ = new TKeypress(false,
7c870d89 403 0, 'j', false, false, false);
7b5261bc 404 public static final TKeypress kbK = new TKeypress(false,
7c870d89 405 0, 'k', false, false, false);
7b5261bc 406 public static final TKeypress kbL = new TKeypress(false,
7c870d89 407 0, 'l', false, false, false);
7b5261bc 408 public static final TKeypress kbM = new TKeypress(false,
7c870d89 409 0, 'm', false, false, false);
7b5261bc 410 public static final TKeypress kbN = new TKeypress(false,
7c870d89 411 0, 'n', false, false, false);
7b5261bc 412 public static final TKeypress kbO = new TKeypress(false,
7c870d89 413 0, 'o', false, false, false);
7b5261bc 414 public static final TKeypress kbP = new TKeypress(false,
7c870d89 415 0, 'p', false, false, false);
7b5261bc 416 public static final TKeypress kbQ = new TKeypress(false,
7c870d89 417 0, 'q', false, false, false);
7b5261bc 418 public static final TKeypress kbR = new TKeypress(false,
7c870d89 419 0, 'r', false, false, false);
7b5261bc 420 public static final TKeypress kbS = new TKeypress(false,
7c870d89 421 0, 's', false, false, false);
7b5261bc 422 public static final TKeypress kbT = new TKeypress(false,
7c870d89 423 0, 't', false, false, false);
7b5261bc 424 public static final TKeypress kbU = new TKeypress(false,
7c870d89 425 0, 'u', false, false, false);
7b5261bc 426 public static final TKeypress kbV = new TKeypress(false,
7c870d89 427 0, 'v', false, false, false);
7b5261bc 428 public static final TKeypress kbW = new TKeypress(false,
7c870d89 429 0, 'w', false, false, false);
7b5261bc 430 public static final TKeypress kbX = new TKeypress(false,
7c870d89 431 0, 'x', false, false, false);
7b5261bc 432 public static final TKeypress kbY = new TKeypress(false,
7c870d89 433 0, 'y', false, false, false);
7b5261bc 434 public static final TKeypress kbZ = new TKeypress(false,
7c870d89 435 0, 'z', false, false, false);
7b5261bc 436 public static final TKeypress kbSpace = new TKeypress(false,
7c870d89 437 0, ' ', false, false, false);
7b5261bc 438 public static final TKeypress kbAltA = new TKeypress(false,
7c870d89 439 0, 'a', true, false, false);
7b5261bc 440 public static final TKeypress kbAltB = new TKeypress(false,
7c870d89 441 0, 'b', true, false, false);
7b5261bc 442 public static final TKeypress kbAltC = new TKeypress(false,
7c870d89 443 0, 'c', true, false, false);
7b5261bc 444 public static final TKeypress kbAltD = new TKeypress(false,
7c870d89 445 0, 'd', true, false, false);
7b5261bc 446 public static final TKeypress kbAltE = new TKeypress(false,
7c870d89 447 0, 'e', true, false, false);
7b5261bc 448 public static final TKeypress kbAltF = new TKeypress(false,
7c870d89 449 0, 'f', true, false, false);
7b5261bc 450 public static final TKeypress kbAltG = new TKeypress(false,
7c870d89 451 0, 'g', true, false, false);
7b5261bc 452 public static final TKeypress kbAltH = new TKeypress(false,
7c870d89 453 0, 'h', true, false, false);
7b5261bc 454 public static final TKeypress kbAltI = new TKeypress(false,
7c870d89 455 0, 'i', true, false, false);
7b5261bc 456 public static final TKeypress kbAltJ = new TKeypress(false,
7c870d89 457 0, 'j', true, false, false);
7b5261bc 458 public static final TKeypress kbAltK = new TKeypress(false,
7c870d89 459 0, 'k', true, false, false);
7b5261bc 460 public static final TKeypress kbAltL = new TKeypress(false,
7c870d89 461 0, 'l', true, false, false);
7b5261bc 462 public static final TKeypress kbAltM = new TKeypress(false,
7c870d89 463 0, 'm', true, false, false);
7b5261bc 464 public static final TKeypress kbAltN = new TKeypress(false,
7c870d89 465 0, 'n', true, false, false);
7b5261bc 466 public static final TKeypress kbAltO = new TKeypress(false,
7c870d89 467 0, 'o', true, false, false);
7b5261bc 468 public static final TKeypress kbAltP = new TKeypress(false,
7c870d89 469 0, 'p', true, false, false);
7b5261bc 470 public static final TKeypress kbAltQ = new TKeypress(false,
7c870d89 471 0, 'q', true, false, false);
7b5261bc 472 public static final TKeypress kbAltR = new TKeypress(false,
7c870d89 473 0, 'r', true, false, false);
7b5261bc 474 public static final TKeypress kbAltS = new TKeypress(false,
7c870d89 475 0, 's', true, false, false);
7b5261bc 476 public static final TKeypress kbAltT = new TKeypress(false,
7c870d89 477 0, 't', true, false, false);
7b5261bc 478 public static final TKeypress kbAltU = new TKeypress(false,
7c870d89 479 0, 'u', true, false, false);
7b5261bc 480 public static final TKeypress kbAltV = new TKeypress(false,
7c870d89 481 0, 'v', true, false, false);
7b5261bc 482 public static final TKeypress kbAltW = new TKeypress(false,
7c870d89 483 0, 'w', true, false, false);
7b5261bc 484 public static final TKeypress kbAltX = new TKeypress(false,
7c870d89 485 0, 'x', true, false, false);
7b5261bc 486 public static final TKeypress kbAltY = new TKeypress(false,
7c870d89 487 0, 'y', true, false, false);
7b5261bc 488 public static final TKeypress kbAltZ = new TKeypress(false,
7c870d89 489 0, 'z', true, false, false);
9696a8f6
KL
490 public static final TKeypress kbAlt0 = new TKeypress(false,
491 0, '0', true, false, false);
492 public static final TKeypress kbAlt1 = new TKeypress(false,
493 0, '1', true, false, false);
494 public static final TKeypress kbAlt2 = new TKeypress(false,
495 0, '2', true, false, false);
496 public static final TKeypress kbAlt3 = new TKeypress(false,
497 0, '3', true, false, false);
498 public static final TKeypress kbAlt4 = new TKeypress(false,
499 0, '4', true, false, false);
500 public static final TKeypress kbAlt5 = new TKeypress(false,
501 0, '5', true, false, false);
502 public static final TKeypress kbAlt6 = new TKeypress(false,
503 0, '6', true, false, false);
504 public static final TKeypress kbAlt7 = new TKeypress(false,
505 0, '7', true, false, false);
506 public static final TKeypress kbAlt8 = new TKeypress(false,
507 0, '8', true, false, false);
508 public static final TKeypress kbAlt9 = new TKeypress(false,
509 0, '9', true, false, false);
7b5261bc 510 public static final TKeypress kbCtrlA = new TKeypress(false,
7c870d89 511 0, 'A', false, true, false);
7b5261bc 512 public static final TKeypress kbCtrlB = new TKeypress(false,
7c870d89 513 0, 'B', false, true, false);
7b5261bc 514 public static final TKeypress kbCtrlC = new TKeypress(false,
7c870d89 515 0, 'C', false, true, false);
7b5261bc 516 public static final TKeypress kbCtrlD = new TKeypress(false,
7c870d89 517 0, 'D', false, true, false);
7b5261bc 518 public static final TKeypress kbCtrlE = new TKeypress(false,
7c870d89 519 0, 'E', false, true, false);
7b5261bc 520 public static final TKeypress kbCtrlF = new TKeypress(false,
7c870d89 521 0, 'F', false, true, false);
7b5261bc 522 public static final TKeypress kbCtrlG = new TKeypress(false,
7c870d89 523 0, 'G', false, true, false);
7b5261bc 524 public static final TKeypress kbCtrlH = new TKeypress(false,
7c870d89 525 0, 'H', false, true, false);
7b5261bc 526 public static final TKeypress kbCtrlI = new TKeypress(false,
7c870d89 527 0, 'I', false, true, false);
7b5261bc 528 public static final TKeypress kbCtrlJ = new TKeypress(false,
7c870d89 529 0, 'J', false, true, false);
7b5261bc 530 public static final TKeypress kbCtrlK = new TKeypress(false,
7c870d89 531 0, 'K', false, true, false);
7b5261bc 532 public static final TKeypress kbCtrlL = new TKeypress(false,
7c870d89 533 0, 'L', false, true, false);
7b5261bc 534 public static final TKeypress kbCtrlM = new TKeypress(false,
7c870d89 535 0, 'M', false, true, false);
7b5261bc 536 public static final TKeypress kbCtrlN = new TKeypress(false,
7c870d89 537 0, 'N', false, true, false);
7b5261bc 538 public static final TKeypress kbCtrlO = new TKeypress(false,
7c870d89 539 0, 'O', false, true, false);
7b5261bc 540 public static final TKeypress kbCtrlP = new TKeypress(false,
7c870d89 541 0, 'P', false, true, false);
7b5261bc 542 public static final TKeypress kbCtrlQ = new TKeypress(false,
7c870d89 543 0, 'Q', false, true, false);
7b5261bc 544 public static final TKeypress kbCtrlR = new TKeypress(false,
7c870d89 545 0, 'R', false, true, false);
7b5261bc 546 public static final TKeypress kbCtrlS = new TKeypress(false,
7c870d89 547 0, 'S', false, true, false);
7b5261bc 548 public static final TKeypress kbCtrlT = new TKeypress(false,
7c870d89 549 0, 'T', false, true, false);
7b5261bc 550 public static final TKeypress kbCtrlU = new TKeypress(false,
7c870d89 551 0, 'U', false, true, false);
7b5261bc 552 public static final TKeypress kbCtrlV = new TKeypress(false,
7c870d89 553 0, 'V', false, true, false);
7b5261bc 554 public static final TKeypress kbCtrlW = new TKeypress(false,
7c870d89 555 0, 'W', false, true, false);
7b5261bc 556 public static final TKeypress kbCtrlX = new TKeypress(false,
7c870d89 557 0, 'X', false, true, false);
7b5261bc 558 public static final TKeypress kbCtrlY = new TKeypress(false,
7c870d89 559 0, 'Y', false, true, false);
7b5261bc 560 public static final TKeypress kbCtrlZ = new TKeypress(false,
7c870d89 561 0, 'Z', false, true, false);
7b5261bc 562 public static final TKeypress kbAltShiftA = new TKeypress(false,
7c870d89 563 0, 'A', true, false, true);
7b5261bc 564 public static final TKeypress kbAltShiftB = new TKeypress(false,
7c870d89 565 0, 'B', true, false, true);
7b5261bc 566 public static final TKeypress kbAltShiftC = new TKeypress(false,
7c870d89 567 0, 'C', true, false, true);
7b5261bc 568 public static final TKeypress kbAltShiftD = new TKeypress(false,
7c870d89 569 0, 'D', true, false, true);
7b5261bc 570 public static final TKeypress kbAltShiftE = new TKeypress(false,
7c870d89 571 0, 'E', true, false, true);
7b5261bc 572 public static final TKeypress kbAltShiftF = new TKeypress(false,
7c870d89 573 0, 'F', true, false, true);
7b5261bc 574 public static final TKeypress kbAltShiftG = new TKeypress(false,
7c870d89 575 0, 'G', true, false, true);
7b5261bc 576 public static final TKeypress kbAltShiftH = new TKeypress(false,
7c870d89 577 0, 'H', true, false, true);
7b5261bc 578 public static final TKeypress kbAltShiftI = new TKeypress(false,
7c870d89 579 0, 'I', true, false, true);
7b5261bc 580 public static final TKeypress kbAltShiftJ = new TKeypress(false,
7c870d89 581 0, 'J', true, false, true);
7b5261bc 582 public static final TKeypress kbAltShiftK = new TKeypress(false,
7c870d89 583 0, 'K', true, false, true);
7b5261bc 584 public static final TKeypress kbAltShiftL = new TKeypress(false,
7c870d89 585 0, 'L', true, false, true);
7b5261bc 586 public static final TKeypress kbAltShiftM = new TKeypress(false,
7c870d89 587 0, 'M', true, false, true);
7b5261bc 588 public static final TKeypress kbAltShiftN = new TKeypress(false,
7c870d89 589 0, 'N', true, false, true);
7b5261bc 590 public static final TKeypress kbAltShiftO = new TKeypress(false,
7c870d89 591 0, 'O', true, false, true);
7b5261bc 592 public static final TKeypress kbAltShiftP = new TKeypress(false,
7c870d89 593 0, 'P', true, false, true);
7b5261bc 594 public static final TKeypress kbAltShiftQ = new TKeypress(false,
7c870d89 595 0, 'Q', true, false, true);
7b5261bc 596 public static final TKeypress kbAltShiftR = new TKeypress(false,
7c870d89 597 0, 'R', true, false, true);
7b5261bc 598 public static final TKeypress kbAltShiftS = new TKeypress(false,
7c870d89 599 0, 'S', true, false, true);
7b5261bc 600 public static final TKeypress kbAltShiftT = new TKeypress(false,
7c870d89 601 0, 'T', true, false, true);
7b5261bc 602 public static final TKeypress kbAltShiftU = new TKeypress(false,
7c870d89 603 0, 'U', true, false, true);
7b5261bc 604 public static final TKeypress kbAltShiftV = new TKeypress(false,
7c870d89 605 0, 'V', true, false, true);
7b5261bc 606 public static final TKeypress kbAltShiftW = new TKeypress(false,
7c870d89 607 0, 'W', true, false, true);
7b5261bc 608 public static final TKeypress kbAltShiftX = new TKeypress(false,
7c870d89 609 0, 'X', true, false, true);
7b5261bc 610 public static final TKeypress kbAltShiftY = new TKeypress(false,
7c870d89 611 0, 'Y', true, false, true);
7b5261bc 612 public static final TKeypress kbAltShiftZ = new TKeypress(false,
7c870d89 613 0, 'Z', true, false, true);
7b5261bc 614
43ee96da
KL
615 public static final TKeypress kbAltShiftHome = new TKeypress(true,
616 TKeypress.HOME, ' ', true, false, true);
617 public static final TKeypress kbAltShiftEnd = new TKeypress(true,
618 TKeypress.END, ' ', true, false, true);
619 public static final TKeypress kbAltShiftPgUp = new TKeypress(true,
620 TKeypress.PGUP, ' ', true, false, true);
621 public static final TKeypress kbAltShiftPgDn = new TKeypress(true,
622 TKeypress.PGDN, ' ', true, false, true);
623 public static final TKeypress kbAltShiftUp = new TKeypress(true,
624 TKeypress.UP, ' ', true, false, true);
625 public static final TKeypress kbAltShiftDown = new TKeypress(true,
626 TKeypress.DOWN, ' ', true, false, true);
627 public static final TKeypress kbAltShiftLeft = new TKeypress(true,
628 TKeypress.LEFT, ' ', true, false, true);
629 public static final TKeypress kbAltShiftRight = new TKeypress(true,
630 TKeypress.RIGHT, ' ', true, false, true);
631
632 public static final TKeypress kbCtrlShiftHome = new TKeypress(true,
633 TKeypress.HOME, ' ', false, true, true);
634 public static final TKeypress kbCtrlShiftEnd = new TKeypress(true,
635 TKeypress.END, ' ', false, true, true);
636 public static final TKeypress kbCtrlShiftPgUp = new TKeypress(true,
637 TKeypress.PGUP, ' ', false, true, true);
638 public static final TKeypress kbCtrlShiftPgDn = new TKeypress(true,
639 TKeypress.PGDN, ' ', false, true, true);
640 public static final TKeypress kbCtrlShiftUp = new TKeypress(true,
641 TKeypress.UP, ' ', false, true, true);
642 public static final TKeypress kbCtrlShiftDown = new TKeypress(true,
643 TKeypress.DOWN, ' ', false, true, true);
644 public static final TKeypress kbCtrlShiftLeft = new TKeypress(true,
645 TKeypress.LEFT, ' ', false, true, true);
646 public static final TKeypress kbCtrlShiftRight = new TKeypress(true,
647 TKeypress.RIGHT, ' ', false, true, true);
648
649
7b5261bc
KL
650 /**
651 * Backspace as ^H.
652 */
653 public static final TKeypress kbBackspace = new TKeypress(false,
7c870d89 654 0, 'H', false, true, false);
7b5261bc
KL
655
656 /**
657 * Backspace as ^?.
658 */
659 public static final TKeypress kbBackspaceDel = new TKeypress(false,
afdec5e9 660 0, (char) 0x7F, false, false, false);
df8de03f 661
d36057df
KL
662 // ------------------------------------------------------------------------
663 // Variables --------------------------------------------------------------
664 // ------------------------------------------------------------------------
665
666 /**
667 * If true, ch is meaningless, use keyCode instead.
668 */
669 private boolean isFunctionKey;
670
671 /**
672 * Will be set to F1, F2, HOME, END, etc. if isKey is true.
673 */
674 private int keyCode;
675
676 /**
677 * Keystroke modifier ALT.
678 */
679 private boolean alt;
680
681 /**
682 * Keystroke modifier CTRL.
683 */
684 private boolean ctrl;
685
686 /**
687 * Keystroke modifier SHIFT.
688 */
689 private boolean shift;
690
691 /**
692 * The character received.
693 */
afdec5e9 694 private int ch;
d36057df
KL
695
696 // ------------------------------------------------------------------------
697 // Constructors -----------------------------------------------------------
698 // ------------------------------------------------------------------------
699
700 /**
701 * Public constructor makes an immutable instance.
702 *
703 * @param isKey is true, this is a function key
704 * @param fnKey the function key code (only valid if isKey is true)
705 * @param ch the character (only valid if fnKey is false)
706 * @param alt if true, ALT was pressed with this keystroke
707 * @param ctrl if true, CTRL was pressed with this keystroke
708 * @param shift if true, SHIFT was pressed with this keystroke
709 */
afdec5e9 710 public TKeypress(final boolean isKey, final int fnKey, final int ch,
d36057df
KL
711 final boolean alt, final boolean ctrl, final boolean shift) {
712
713 this.isFunctionKey = isKey;
714 this.keyCode = fnKey;
715 this.ch = ch;
716 this.alt = alt;
717 this.ctrl = ctrl;
718 this.shift = shift;
719 }
720
721 // ------------------------------------------------------------------------
722 // TKeypress --------------------------------------------------------------
723 // ------------------------------------------------------------------------
724
725 /**
726 * Getter for isFunctionKey.
727 *
728 * @return if true, ch is meaningless, use keyCode instead
729 */
730 public boolean isFnKey() {
731 return isFunctionKey;
732 }
733
734 /**
735 * Getter for function key code.
736 *
737 * @return function key code int value (only valid is isKey is true)
738 */
739 public int getKeyCode() {
740 return keyCode;
741 }
742
743 /**
744 * Getter for ALT.
745 *
746 * @return alt value
747 */
748 public boolean isAlt() {
749 return alt;
750 }
751
752 /**
753 * Getter for CTRL.
754 *
755 * @return ctrl value
756 */
757 public boolean isCtrl() {
758 return ctrl;
759 }
760
761 /**
762 * Getter for SHIFT.
763 *
764 * @return shift value
765 */
766 public boolean isShift() {
767 return shift;
768 }
769
770 /**
771 * Getter for character.
772 *
773 * @return the character (only valid if isKey is false)
774 */
afdec5e9 775 public int getChar() {
d36057df
KL
776 return ch;
777 }
778
779 /**
780 * Create a duplicate instance.
781 *
782 * @return duplicate intance
783 */
784 public TKeypress dup() {
785 TKeypress keypress = new TKeypress(isFunctionKey, keyCode, ch,
786 alt, ctrl, shift);
787 return keypress;
788 }
789
790 /**
791 * Comparison check. All fields must match to return true.
792 *
793 * @param rhs another TKeypress instance
794 * @return true if all fields are equal
795 */
796 @Override
797 public boolean equals(final Object rhs) {
798 if (!(rhs instanceof TKeypress)) {
799 return false;
800 }
801
802 TKeypress that = (TKeypress) rhs;
803 return ((isFunctionKey == that.isFunctionKey)
804 && (keyCode == that.keyCode)
805 && (ch == that.ch)
806 && (alt == that.alt)
807 && (ctrl == that.ctrl)
808 && (shift == that.shift));
809 }
810
811 /**
812 * Comparison check, omitting the ctrl/alt/shift flags.
813 *
814 * @param rhs another TKeypress instance
815 * @return true if all fields (except for ctrl/alt/shift) are equal
816 */
817 public boolean equalsWithoutModifiers(final Object rhs) {
818 if (!(rhs instanceof TKeypress)) {
819 return false;
820 }
821
822 TKeypress that = (TKeypress) rhs;
823 return ((isFunctionKey == that.isFunctionKey)
824 && (keyCode == that.keyCode)
825 && (ch == that.ch));
826 }
827
828 /**
829 * Hashcode uses all fields in equals().
830 *
831 * @return the hash
832 */
833 @Override
834 public int hashCode() {
835 int A = 13;
836 int B = 23;
837 int hash = A;
838 hash = (B * hash) + (isFunctionKey ? 1 : 0);
839 hash = (B * hash) + keyCode;
840 hash = (B * hash) + ch;
841 hash = (B * hash) + (alt ? 1 : 0);
842 hash = (B * hash) + (ctrl ? 1 : 0);
843 hash = (B * hash) + (shift ? 1 : 0);
844 return hash;
845 }
846
847 /**
848 * Make human-readable description of this TKeypress.
849 *
850 * @return displayable String
851 */
852 @Override
853 public String toString() {
a69ed767
KL
854 // Special case: Enter is "<arrow> <line> <angle>"
855 if (equals(kbEnter)) {
856 return "\u25C0\u2500\u2518";
857 }
858
3c5921e6
KL
859 // Special case: Space is "Space"
860 if (equals(kbSpace)) {
861 return "Space";
862 }
863
1dac6b8d
KL
864 if (equals(kbShiftLeft)) {
865 return "Shift+\u2190";
866 }
867 if (equals(kbShiftRight)) {
868 return "Shift+\u2192";
869 }
870
d36057df
KL
871 if (isFunctionKey) {
872 switch (keyCode) {
873 case F1:
874 return String.format("%s%s%sF1",
875 ctrl ? "Ctrl+" : "",
876 alt ? "Alt+" : "",
877 shift ? "Shift+" : "");
878 case F2:
879 return String.format("%s%s%sF2",
880 ctrl ? "Ctrl+" : "",
881 alt ? "Alt+" : "",
882 shift ? "Shift+" : "");
883 case F3:
884 return String.format("%s%s%sF3",
885 ctrl ? "Ctrl+" : "",
886 alt ? "Alt+" : "",
887 shift ? "Shift+" : "");
888 case F4:
889 return String.format("%s%s%sF4",
890 ctrl ? "Ctrl+" : "",
891 alt ? "Alt+" : "",
892 shift ? "Shift+" : "");
893 case F5:
894 return String.format("%s%s%sF5",
895 ctrl ? "Ctrl+" : "",
896 alt ? "Alt+" : "",
897 shift ? "Shift+" : "");
898 case F6:
899 return String.format("%s%s%sF6",
900 ctrl ? "Ctrl+" : "",
901 alt ? "Alt+" : "",
902 shift ? "Shift+" : "");
903 case F7:
904 return String.format("%s%s%sF7",
905 ctrl ? "Ctrl+" : "",
906 alt ? "Alt+" : "",
907 shift ? "Shift+" : "");
908 case F8:
909 return String.format("%s%s%sF8",
910 ctrl ? "Ctrl+" : "",
911 alt ? "Alt+" : "",
912 shift ? "Shift+" : "");
913 case F9:
914 return String.format("%s%s%sF9",
915 ctrl ? "Ctrl+" : "",
916 alt ? "Alt+" : "",
917 shift ? "Shift+" : "");
918 case F10:
919 return String.format("%s%s%sF10",
920 ctrl ? "Ctrl+" : "",
921 alt ? "Alt+" : "",
922 shift ? "Shift+" : "");
923 case F11:
924 return String.format("%s%s%sF11",
925 ctrl ? "Ctrl+" : "",
926 alt ? "Alt+" : "",
927 shift ? "Shift+" : "");
928 case F12:
929 return String.format("%s%s%sF12",
930 ctrl ? "Ctrl+" : "",
931 alt ? "Alt+" : "",
932 shift ? "Shift+" : "");
933 case HOME:
934 return String.format("%s%s%sHOME",
935 ctrl ? "Ctrl+" : "",
936 alt ? "Alt+" : "",
937 shift ? "Shift+" : "");
938 case END:
939 return String.format("%s%s%sEND",
940 ctrl ? "Ctrl+" : "",
941 alt ? "Alt+" : "",
942 shift ? "Shift+" : "");
943 case PGUP:
944 return String.format("%s%s%sPGUP",
945 ctrl ? "Ctrl+" : "",
946 alt ? "Alt+" : "",
947 shift ? "Shift+" : "");
948 case PGDN:
949 return String.format("%s%s%sPGDN",
950 ctrl ? "Ctrl+" : "",
951 alt ? "Alt+" : "",
952 shift ? "Shift+" : "");
953 case INS:
954 return String.format("%s%s%sINS",
955 ctrl ? "Ctrl+" : "",
956 alt ? "Alt+" : "",
957 shift ? "Shift+" : "");
958 case DEL:
959 return String.format("%s%s%sDEL",
960 ctrl ? "Ctrl+" : "",
961 alt ? "Alt+" : "",
962 shift ? "Shift+" : "");
963 case RIGHT:
964 return String.format("%s%s%sRIGHT",
965 ctrl ? "Ctrl+" : "",
966 alt ? "Alt+" : "",
967 shift ? "Shift+" : "");
968 case LEFT:
969 return String.format("%s%s%sLEFT",
970 ctrl ? "Ctrl+" : "",
971 alt ? "Alt+" : "",
972 shift ? "Shift+" : "");
973 case UP:
974 return String.format("%s%s%sUP",
975 ctrl ? "Ctrl+" : "",
976 alt ? "Alt+" : "",
977 shift ? "Shift+" : "");
978 case DOWN:
979 return String.format("%s%s%sDOWN",
980 ctrl ? "Ctrl+" : "",
981 alt ? "Alt+" : "",
982 shift ? "Shift+" : "");
983 case TAB:
984 return String.format("%s%s%sTAB",
985 ctrl ? "Ctrl+" : "",
986 alt ? "Alt+" : "",
987 shift ? "Shift+" : "");
988 case BTAB:
989 return String.format("%s%s%sBTAB",
990 ctrl ? "Ctrl+" : "",
991 alt ? "Alt+" : "",
992 shift ? "Shift+" : "");
993 case ENTER:
994 return String.format("%s%s%sENTER",
995 ctrl ? "Ctrl+" : "",
996 alt ? "Alt+" : "",
997 shift ? "Shift+" : "");
998 case ESC:
999 return String.format("%s%s%sESC",
1000 ctrl ? "Ctrl+" : "",
1001 alt ? "Alt+" : "",
1002 shift ? "Shift+" : "");
1003 default:
1004 return String.format("--UNKNOWN--");
1005 }
1006 } else {
1007 if (alt && !shift && !ctrl) {
1008 // Alt-X
1009 return String.format("Alt+%c", Character.toUpperCase(ch));
1010 } else if (!alt && shift && !ctrl) {
1011 // Shift-X
1012 return String.format("%c", ch);
1013 } else if (!alt && !shift && ctrl) {
1014 // Ctrl-X
1015 return String.format("Ctrl+%c", ch);
1016 } else if (alt && shift && !ctrl) {
1017 // Alt-Shift-X
1018 return String.format("Alt+Shift+%c", ch);
1019 } else if (!alt && shift && ctrl) {
1020 // Ctrl-Shift-X
1021 return String.format("Ctrl+Shift+%c", ch);
1022 } else if (alt && !shift && ctrl) {
1023 // Ctrl-Alt-X
1024 return String.format("Ctrl+Alt+%c", Character.toUpperCase(ch));
1025 } else if (alt && shift && ctrl) {
1026 // Ctrl-Alt-Shift-X
1027 return String.format("Ctrl+Alt+Shift+%c",
1028 Character.toUpperCase(ch));
1029 } else {
1030 // X
1031 return String.format("%c", ch);
1032 }
1033 }
1034 }
1035
1036 /**
1037 * Convert a keypress to lowercase. Function keys and alt/ctrl keys are
1038 * not converted.
1039 *
1040 * @return a new instance with the key converted
1041 */
1042 public TKeypress toLowerCase() {
1043 TKeypress newKey = new TKeypress(isFunctionKey, keyCode, ch, alt, ctrl,
1044 shift);
1045 if (!isFunctionKey && (ch >= 'A') && (ch <= 'Z') && !ctrl && !alt) {
1046 newKey.shift = false;
1047 newKey.ch += 32;
1048 }
1049 return newKey;
1050 }
1051
1052 /**
1053 * Convert a keypress to uppercase. Function keys and alt/ctrl keys are
1054 * not converted.
1055 *
1056 * @return a new instance with the key converted
1057 */
1058 public TKeypress toUpperCase() {
1059 TKeypress newKey = new TKeypress(isFunctionKey, keyCode, ch, alt, ctrl,
1060 shift);
1061 if (!isFunctionKey && (ch >= 'a') && (ch <= 'z') && !ctrl && !alt) {
1062 newKey.shift = true;
1063 newKey.ch -= 32;
1064 }
1065 return newKey;
1066 }
1067
df8de03f 1068}