Commit | Line | Data |
---|---|---|
4d2c61b4 KL |
1 | /* |
2 | * Jexer - Java Text User Interface | |
3 | * | |
4 | * The MIT License (MIT) | |
5 | * | |
6 | * Copyright (C) 2019 Kevin Lamonte | |
7 | * | |
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: | |
14 | * | |
15 | * The above copyright notice and this permission notice shall be included in | |
16 | * all copies or substantial portions of the Software. | |
17 | * | |
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. | |
25 | * | |
26 | * @author Kevin Lamonte [kevin.lamonte@gmail.com] | |
27 | * @version 1 | |
28 | */ | |
29 | package jexer; | |
30 | ||
31 | import java.awt.Font; | |
32 | import java.awt.FontMetrics; | |
33 | import java.awt.Graphics2D; | |
34 | import java.awt.image.BufferedImage; | |
35 | ||
36 | import java.io.InputStream; | |
37 | import java.io.IOException; | |
38 | import java.lang.reflect.Field; | |
39 | import java.text.MessageFormat; | |
40 | import java.util.ArrayList; | |
41 | import java.util.HashMap; | |
42 | import java.util.List; | |
43 | import java.util.Map; | |
44 | import java.util.ResourceBundle; | |
45 | ||
46 | import jexer.backend.ECMA48Terminal; | |
47 | import jexer.backend.GlyphMaker; | |
48 | import jexer.backend.MultiScreen; | |
49 | import jexer.backend.SwingTerminal; | |
50 | import jexer.bits.Cell; | |
51 | import jexer.bits.CellAttributes; | |
63543c45 | 52 | import jexer.event.TCommandEvent; |
4d2c61b4 KL |
53 | import jexer.event.TKeypressEvent; |
54 | import jexer.event.TMenuEvent; | |
55 | import jexer.event.TMouseEvent; | |
56 | import jexer.event.TResizeEvent; | |
57 | import jexer.menu.TMenu; | |
58 | import jexer.tterminal.DisplayLine; | |
59 | import jexer.tterminal.DisplayListener; | |
60 | import jexer.tterminal.ECMA48; | |
63543c45 | 61 | import static jexer.TCommand.*; |
4d2c61b4 KL |
62 | import static jexer.TKeypress.*; |
63 | ||
64 | /** | |
2bc32111 | 65 | * TTerminalWidget exposes a ECMA-48 / ANSI X3.64 style terminal in a widget. |
4d2c61b4 KL |
66 | */ |
67 | public class TTerminalWidget extends TScrollableWidget | |
63543c45 | 68 | implements DisplayListener, EditMenuUser { |
4d2c61b4 KL |
69 | |
70 | /** | |
71 | * Translated strings. | |
72 | */ | |
73 | private static final ResourceBundle i18n = ResourceBundle.getBundle(TTerminalWidget.class.getName()); | |
74 | ||
75 | // ------------------------------------------------------------------------ | |
76 | // Variables -------------------------------------------------------------- | |
77 | // ------------------------------------------------------------------------ | |
78 | ||
79 | /** | |
80 | * The emulator. | |
81 | */ | |
82 | private ECMA48 emulator; | |
83 | ||
84 | /** | |
85 | * The Process created by the shell spawning constructor. | |
86 | */ | |
87 | private Process shell; | |
88 | ||
89 | /** | |
90 | * If true, we are using the ptypipe utility to support dynamic window | |
91 | * resizing. ptypipe is available at | |
92 | * https://gitlab.com/klamonte/ptypipe . | |
93 | */ | |
94 | private boolean ptypipe = false; | |
95 | ||
96 | /** | |
97 | * Double-height font. | |
98 | */ | |
99 | private GlyphMaker doubleFont; | |
100 | ||
101 | /** | |
102 | * Last text width value. | |
103 | */ | |
104 | private int lastTextWidth = -1; | |
105 | ||
106 | /** | |
107 | * Last text height value. | |
108 | */ | |
109 | private int lastTextHeight = -1; | |
110 | ||
111 | /** | |
112 | * The blink state, used only by ECMA48 backend and when double-width | |
113 | * chars must be drawn. | |
114 | */ | |
115 | private boolean blinkState = true; | |
116 | ||
117 | /** | |
118 | * Timer flag, used only by ECMA48 backend and when double-width chars | |
119 | * must be drawn. | |
120 | */ | |
121 | private boolean haveTimer = false; | |
122 | ||
123 | /** | |
9917c620 | 124 | * The last seen visible display. |
4d2c61b4 KL |
125 | */ |
126 | private List<DisplayLine> display; | |
127 | ||
128 | /** | |
129 | * If true, the display has changed and needs updating. | |
130 | */ | |
131 | private volatile boolean dirty = true; | |
132 | ||
133 | /** | |
134 | * Time that the display was last updated. | |
135 | */ | |
136 | private long lastUpdateTime = 0; | |
137 | ||
138 | /** | |
139 | * If true, hide the mouse after typing a keystroke. | |
140 | */ | |
141 | private boolean hideMouseWhenTyping = true; | |
142 | ||
143 | /** | |
144 | * If true, the mouse should not be displayed because a keystroke was | |
145 | * typed. | |
146 | */ | |
147 | private boolean typingHidMouse = false; | |
148 | ||
149 | /** | |
150 | * The return value from the emulator. | |
151 | */ | |
152 | private int exitValue = -1; | |
153 | ||
154 | /** | |
155 | * Title to expose to a window. | |
156 | */ | |
157 | private String title = ""; | |
158 | ||
2bc32111 KL |
159 | /** |
160 | * Action to perform when the terminal exits. | |
161 | */ | |
162 | private TAction closeAction = null; | |
163 | ||
4d2c61b4 KL |
164 | // ------------------------------------------------------------------------ |
165 | // Constructors ----------------------------------------------------------- | |
166 | // ------------------------------------------------------------------------ | |
167 | ||
168 | /** | |
169 | * Public constructor spawns a custom command line. | |
170 | * | |
171 | * @param parent parent widget | |
172 | * @param x column relative to parent | |
173 | * @param y row relative to parent | |
174 | * @param commandLine the command line to execute | |
175 | */ | |
2bc32111 KL |
176 | public TTerminalWidget(final TWidget parent, final int x, final int y, |
177 | final String commandLine) { | |
4d2c61b4 KL |
178 | |
179 | this(parent, x, y, commandLine.split("\\s+")); | |
180 | } | |
181 | ||
182 | /** | |
183 | * Public constructor spawns a custom command line. | |
184 | * | |
185 | * @param parent parent widget | |
186 | * @param x column relative to parent | |
187 | * @param y row relative to parent | |
188 | * @param command the command line to execute | |
189 | */ | |
2bc32111 KL |
190 | public TTerminalWidget(final TWidget parent, final int x, final int y, |
191 | final String [] command) { | |
192 | ||
193 | this(parent, x, y, command, null); | |
194 | } | |
195 | ||
196 | /** | |
197 | * Public constructor spawns a custom command line. | |
198 | * | |
199 | * @param parent parent widget | |
200 | * @param x column relative to parent | |
201 | * @param y row relative to parent | |
202 | * @param command the command line to execute | |
17b598e9 | 203 | * @param closeAction action to perform when the shell exits |
2bc32111 KL |
204 | */ |
205 | public TTerminalWidget(final TWidget parent, final int x, final int y, | |
206 | final String [] command, final TAction closeAction) { | |
207 | ||
208 | this(parent, x, y, 80, 24, command, closeAction); | |
209 | } | |
210 | ||
211 | /** | |
212 | * Public constructor spawns a custom command line. | |
213 | * | |
214 | * @param parent parent widget | |
215 | * @param x column relative to parent | |
216 | * @param y row relative to parent | |
217 | * @param width width of widget | |
218 | * @param height height of widget | |
219 | * @param command the command line to execute | |
17b598e9 | 220 | * @param closeAction action to perform when the shell exits |
2bc32111 KL |
221 | */ |
222 | public TTerminalWidget(final TWidget parent, final int x, final int y, | |
223 | final int width, final int height, final String [] command, | |
224 | final TAction closeAction) { | |
225 | ||
226 | super(parent, x, y, width, height); | |
4d2c61b4 | 227 | |
2bc32111 | 228 | this.closeAction = closeAction; |
4d2c61b4 KL |
229 | |
230 | String [] fullCommand; | |
231 | ||
232 | // Spawn a shell and pass its I/O to the other constructor. | |
233 | if ((System.getProperty("jexer.TTerminal.ptypipe") != null) | |
234 | && (System.getProperty("jexer.TTerminal.ptypipe"). | |
235 | equals("true")) | |
236 | ) { | |
237 | ptypipe = true; | |
238 | fullCommand = new String[command.length + 1]; | |
239 | fullCommand[0] = "ptypipe"; | |
240 | System.arraycopy(command, 0, fullCommand, 1, command.length); | |
241 | } else if (System.getProperty("os.name").startsWith("Windows")) { | |
242 | fullCommand = new String[3]; | |
243 | fullCommand[0] = "cmd"; | |
244 | fullCommand[1] = "/c"; | |
245 | fullCommand[2] = stringArrayToString(command); | |
246 | } else if (System.getProperty("os.name").startsWith("Mac")) { | |
247 | fullCommand = new String[6]; | |
248 | fullCommand[0] = "script"; | |
249 | fullCommand[1] = "-q"; | |
250 | fullCommand[2] = "-F"; | |
251 | fullCommand[3] = "/dev/null"; | |
252 | fullCommand[4] = "-c"; | |
253 | fullCommand[5] = stringArrayToString(command); | |
254 | } else { | |
255 | // Default: behave like Linux | |
e376f42c KL |
256 | if (System.getProperty("jexer.TTerminal.setsid", |
257 | "true").equals("false") | |
258 | ) { | |
259 | fullCommand = new String[5]; | |
260 | fullCommand[0] = "script"; | |
261 | fullCommand[1] = "-fqe"; | |
262 | fullCommand[2] = "/dev/null"; | |
263 | fullCommand[3] = "-c"; | |
264 | fullCommand[4] = stringArrayToString(command); | |
265 | } else { | |
266 | fullCommand = new String[6]; | |
267 | fullCommand[0] = "setsid"; | |
268 | fullCommand[1] = "script"; | |
269 | fullCommand[2] = "-fqe"; | |
270 | fullCommand[3] = "/dev/null"; | |
271 | fullCommand[4] = "-c"; | |
272 | fullCommand[5] = stringArrayToString(command); | |
273 | } | |
4d2c61b4 KL |
274 | } |
275 | spawnShell(fullCommand); | |
276 | } | |
277 | ||
278 | /** | |
279 | * Public constructor spawns a shell. | |
280 | * | |
281 | * @param parent parent widget | |
282 | * @param x column relative to parent | |
283 | * @param y row relative to parent | |
284 | */ | |
285 | public TTerminalWidget(final TWidget parent, final int x, final int y) { | |
2bc32111 KL |
286 | this(parent, x, y, (TAction) null); |
287 | } | |
4d2c61b4 | 288 | |
2bc32111 KL |
289 | /** |
290 | * Public constructor spawns a shell. | |
291 | * | |
292 | * @param parent parent widget | |
293 | * @param x column relative to parent | |
294 | * @param y row relative to parent | |
17b598e9 | 295 | * @param closeAction action to perform when the shell exits |
2bc32111 KL |
296 | */ |
297 | public TTerminalWidget(final TWidget parent, final int x, final int y, | |
298 | final TAction closeAction) { | |
299 | ||
300 | this(parent, x, y, 80, 24, closeAction); | |
301 | } | |
302 | ||
303 | /** | |
304 | * Public constructor spawns a shell. | |
305 | * | |
306 | * @param parent parent widget | |
307 | * @param x column relative to parent | |
308 | * @param y row relative to parent | |
309 | * @param width width of widget | |
310 | * @param height height of widget | |
17b598e9 | 311 | * @param closeAction action to perform when the shell exits |
2bc32111 KL |
312 | */ |
313 | public TTerminalWidget(final TWidget parent, final int x, final int y, | |
314 | final int width, final int height, final TAction closeAction) { | |
315 | ||
316 | super(parent, x, y, width, height); | |
317 | ||
318 | this.closeAction = closeAction; | |
4d2c61b4 KL |
319 | |
320 | if (System.getProperty("jexer.TTerminal.shell") != null) { | |
321 | String shell = System.getProperty("jexer.TTerminal.shell"); | |
322 | if (shell.trim().startsWith("ptypipe")) { | |
323 | ptypipe = true; | |
324 | } | |
325 | spawnShell(shell.split("\\s+")); | |
326 | return; | |
327 | } | |
328 | ||
329 | String cmdShellWindows = "cmd.exe"; | |
330 | ||
331 | // You cannot run a login shell in a bare Process interactively, due | |
332 | // to libc's behavior of buffering when stdin/stdout aren't a tty. | |
333 | // Use 'script' instead to run a shell in a pty. And because BSD and | |
334 | // GNU differ on the '-f' vs '-F' flags, we need two different | |
335 | // commands. Lovely. | |
336 | String cmdShellGNU = "script -fqe /dev/null"; | |
e376f42c | 337 | String cmdShellGNUSetsid = "setsid script -fqe /dev/null"; |
4d2c61b4 KL |
338 | String cmdShellBSD = "script -q -F /dev/null"; |
339 | ||
340 | // ptypipe is another solution that permits dynamic window resizing. | |
341 | String cmdShellPtypipe = "ptypipe /bin/bash --login"; | |
342 | ||
343 | // Spawn a shell and pass its I/O to the other constructor. | |
344 | if ((System.getProperty("jexer.TTerminal.ptypipe") != null) | |
345 | && (System.getProperty("jexer.TTerminal.ptypipe"). | |
346 | equals("true")) | |
347 | ) { | |
348 | ptypipe = true; | |
349 | spawnShell(cmdShellPtypipe.split("\\s+")); | |
350 | } else if (System.getProperty("os.name").startsWith("Windows")) { | |
351 | spawnShell(cmdShellWindows.split("\\s+")); | |
352 | } else if (System.getProperty("os.name").startsWith("Mac")) { | |
353 | spawnShell(cmdShellBSD.split("\\s+")); | |
354 | } else if (System.getProperty("os.name").startsWith("Linux")) { | |
e376f42c KL |
355 | if (System.getProperty("jexer.TTerminal.setsid", |
356 | "true").equals("false") | |
357 | ) { | |
358 | spawnShell(cmdShellGNU.split("\\s+")); | |
359 | } else { | |
360 | spawnShell(cmdShellGNUSetsid.split("\\s+")); | |
361 | } | |
4d2c61b4 KL |
362 | } else { |
363 | // When all else fails, assume GNU. | |
364 | spawnShell(cmdShellGNU.split("\\s+")); | |
365 | } | |
366 | } | |
367 | ||
368 | // ------------------------------------------------------------------------ | |
dbf8e80a | 369 | // Event handlers --------------------------------------------------------- |
4d2c61b4 KL |
370 | // ------------------------------------------------------------------------ |
371 | ||
4d2c61b4 KL |
372 | /** |
373 | * Handle window/screen resize events. | |
374 | * | |
375 | * @param resize resize event | |
376 | */ | |
377 | @Override | |
378 | public void onResize(final TResizeEvent resize) { | |
2bc32111 KL |
379 | // Let TWidget set my size. |
380 | super.onResize(resize); | |
4d2c61b4 | 381 | |
1104f8d7 KL |
382 | if (emulator == null) { |
383 | return; | |
384 | } | |
385 | ||
4d2c61b4 KL |
386 | // Synchronize against the emulator so we don't stomp on its reader |
387 | // thread. | |
388 | synchronized (emulator) { | |
389 | ||
390 | if (resize.getType() == TResizeEvent.Type.WIDGET) { | |
391 | // Resize the scroll bars | |
392 | reflowData(); | |
393 | placeScrollbars(); | |
394 | ||
395 | // Get out of scrollback | |
396 | setVerticalValue(0); | |
397 | ||
398 | if (ptypipe) { | |
399 | emulator.setWidth(getWidth()); | |
400 | emulator.setHeight(getHeight()); | |
401 | ||
402 | emulator.writeRemote("\033[8;" + getHeight() + ";" + | |
403 | getWidth() + "t"); | |
404 | } | |
c7a75ad3 KL |
405 | |
406 | // Pass the correct text cell width/height to the emulator | |
407 | if (getScreen() != null) { | |
408 | emulator.setTextWidth(getScreen().getTextWidth()); | |
409 | emulator.setTextHeight(getScreen().getTextHeight()); | |
410 | } | |
4d2c61b4 KL |
411 | } |
412 | return; | |
413 | ||
414 | } // synchronized (emulator) | |
415 | } | |
416 | ||
4d2c61b4 KL |
417 | /** |
418 | * Handle keystrokes. | |
419 | * | |
420 | * @param keypress keystroke event | |
421 | */ | |
422 | @Override | |
423 | public void onKeypress(final TKeypressEvent keypress) { | |
424 | if (hideMouseWhenTyping) { | |
425 | typingHidMouse = true; | |
426 | } | |
427 | ||
428 | // Scrollback up/down | |
429 | if (keypress.equals(kbShiftPgUp) | |
430 | || keypress.equals(kbCtrlPgUp) | |
431 | || keypress.equals(kbAltPgUp) | |
432 | ) { | |
433 | bigVerticalDecrement(); | |
9917c620 | 434 | dirty = true; |
4d2c61b4 KL |
435 | return; |
436 | } | |
437 | if (keypress.equals(kbShiftPgDn) | |
438 | || keypress.equals(kbCtrlPgDn) | |
439 | || keypress.equals(kbAltPgDn) | |
440 | ) { | |
441 | bigVerticalIncrement(); | |
9917c620 | 442 | dirty = true; |
4d2c61b4 KL |
443 | return; |
444 | } | |
445 | ||
1104f8d7 | 446 | if ((emulator != null) && (emulator.isReading())) { |
4d2c61b4 KL |
447 | // Get out of scrollback |
448 | setVerticalValue(0); | |
449 | emulator.addUserEvent(keypress); | |
450 | ||
451 | // UGLY HACK TIME! cmd.exe needs CRLF, not just CR, so if | |
452 | // this is kBEnter then also send kbCtrlJ. | |
453 | if (keypress.equals(kbEnter)) { | |
454 | if (System.getProperty("os.name").startsWith("Windows") | |
455 | && (System.getProperty("jexer.TTerminal.cmdHack", | |
456 | "true").equals("true")) | |
457 | ) { | |
458 | emulator.addUserEvent(new TKeypressEvent(kbCtrlJ)); | |
459 | } | |
460 | } | |
461 | ||
462 | readEmulatorState(); | |
463 | return; | |
464 | } | |
465 | ||
466 | // Process is closed, honor "normal" TUI keystrokes | |
467 | super.onKeypress(keypress); | |
468 | } | |
469 | ||
470 | /** | |
471 | * Handle mouse press events. | |
472 | * | |
473 | * @param mouse mouse button press event | |
474 | */ | |
475 | @Override | |
476 | public void onMouseDown(final TMouseEvent mouse) { | |
477 | if (hideMouseWhenTyping) { | |
478 | typingHidMouse = false; | |
479 | } | |
480 | ||
1104f8d7 KL |
481 | if (emulator != null) { |
482 | // If the emulator is tracking mouse buttons, it needs to see | |
483 | // wheel events. | |
484 | if (emulator.getMouseProtocol() == ECMA48.MouseProtocol.OFF) { | |
485 | if (mouse.isMouseWheelUp()) { | |
486 | verticalDecrement(); | |
487 | dirty = true; | |
488 | return; | |
489 | } | |
490 | if (mouse.isMouseWheelDown()) { | |
491 | verticalIncrement(); | |
492 | dirty = true; | |
493 | return; | |
494 | } | |
4d2c61b4 | 495 | } |
1104f8d7 KL |
496 | if (mouseOnEmulator(mouse)) { |
497 | emulator.addUserEvent(mouse); | |
498 | readEmulatorState(); | |
4d2c61b4 KL |
499 | return; |
500 | } | |
501 | } | |
4d2c61b4 KL |
502 | |
503 | // Emulator didn't consume it, pass it on | |
504 | super.onMouseDown(mouse); | |
505 | } | |
506 | ||
507 | /** | |
508 | * Handle mouse release events. | |
509 | * | |
510 | * @param mouse mouse button release event | |
511 | */ | |
512 | @Override | |
513 | public void onMouseUp(final TMouseEvent mouse) { | |
514 | if (hideMouseWhenTyping) { | |
515 | typingHidMouse = false; | |
516 | } | |
517 | ||
1104f8d7 | 518 | if ((emulator != null) && (mouseOnEmulator(mouse))) { |
4d2c61b4 KL |
519 | emulator.addUserEvent(mouse); |
520 | readEmulatorState(); | |
521 | return; | |
522 | } | |
523 | ||
524 | // Emulator didn't consume it, pass it on | |
525 | super.onMouseUp(mouse); | |
526 | } | |
527 | ||
528 | /** | |
529 | * Handle mouse motion events. | |
530 | * | |
531 | * @param mouse mouse motion event | |
532 | */ | |
533 | @Override | |
534 | public void onMouseMotion(final TMouseEvent mouse) { | |
535 | if (hideMouseWhenTyping) { | |
536 | typingHidMouse = false; | |
537 | } | |
538 | ||
1104f8d7 | 539 | if ((emulator != null) && (mouseOnEmulator(mouse))) { |
4d2c61b4 KL |
540 | emulator.addUserEvent(mouse); |
541 | readEmulatorState(); | |
542 | return; | |
543 | } | |
544 | ||
545 | // Emulator didn't consume it, pass it on | |
546 | super.onMouseMotion(mouse); | |
547 | } | |
548 | ||
63543c45 KL |
549 | /** |
550 | * Handle posted command events. | |
551 | * | |
552 | * @param command command event | |
553 | */ | |
554 | @Override | |
555 | public void onCommand(final TCommandEvent command) { | |
556 | if (emulator == null) { | |
557 | return; | |
558 | } | |
559 | ||
560 | if (command.equals(cmPaste)) { | |
561 | // Paste text from clipboard. | |
562 | String text = getClipboard().pasteText(); | |
563 | if (text != null) { | |
564 | for (int i = 0; i < text.length(); ) { | |
565 | int ch = text.codePointAt(i); | |
566 | emulator.addUserEvent(new TKeypressEvent(false, 0, ch, | |
567 | false, false, false)); | |
568 | i += Character.charCount(ch); | |
569 | } | |
570 | } | |
571 | return; | |
572 | } | |
573 | } | |
574 | ||
4d2c61b4 | 575 | // ------------------------------------------------------------------------ |
dbf8e80a KL |
576 | // TScrollableWidget ------------------------------------------------------ |
577 | // ------------------------------------------------------------------------ | |
578 | ||
579 | /** | |
580 | * Draw the display buffer. | |
581 | */ | |
582 | @Override | |
583 | public void draw() { | |
1104f8d7 KL |
584 | if (emulator == null) { |
585 | return; | |
586 | } | |
587 | ||
dbf8e80a KL |
588 | int width = getDisplayWidth(); |
589 | ||
590 | boolean syncEmulator = false; | |
83787cfb | 591 | if (System.currentTimeMillis() - lastUpdateTime >= 50) { |
dbf8e80a KL |
592 | // Too much time has passed, draw it all. |
593 | syncEmulator = true; | |
594 | } else if (emulator.isReading() && (dirty == false)) { | |
595 | // Wait until the emulator has brought more data in. | |
596 | syncEmulator = false; | |
597 | } else if (!emulator.isReading() && (dirty == true)) { | |
598 | // The emulator won't receive more data, update the display. | |
599 | syncEmulator = true; | |
600 | } | |
601 | ||
602 | if ((syncEmulator == true) | |
603 | || (display == null) | |
604 | ) { | |
605 | // We want to minimize the amount of time we have the emulator | |
606 | // locked. Grab a copy of its display. | |
607 | synchronized (emulator) { | |
608 | // Update the scroll bars | |
609 | reflowData(); | |
610 | ||
611 | if (!isDrawable()) { | |
612 | // We lost the connection, onShellExit() called an action | |
613 | // that ultimately removed this widget from the UI | |
614 | // hierarchy, so no one cares if we update the display. | |
615 | // Bail out. | |
616 | return; | |
617 | } | |
618 | ||
619 | if ((display == null) || emulator.isReading()) { | |
620 | display = emulator.getVisibleDisplay(getHeight(), | |
621 | -getVerticalValue()); | |
622 | assert (display.size() == getHeight()); | |
623 | } | |
624 | width = emulator.getWidth(); | |
625 | } | |
626 | dirty = false; | |
627 | } | |
628 | ||
629 | // Now draw the emulator screen | |
630 | int row = 0; | |
631 | for (DisplayLine line: display) { | |
632 | int widthMax = width; | |
633 | if (line.isDoubleWidth()) { | |
634 | widthMax /= 2; | |
635 | } | |
636 | if (widthMax > getWidth()) { | |
637 | widthMax = getWidth(); | |
638 | } | |
639 | for (int i = 0; i < widthMax; i++) { | |
640 | Cell ch = line.charAt(i); | |
641 | ||
642 | if (ch.isImage()) { | |
643 | putCharXY(i, row, ch); | |
644 | continue; | |
645 | } | |
646 | ||
647 | Cell newCell = new Cell(ch); | |
648 | boolean reverse = line.isReverseColor() ^ ch.isReverse(); | |
649 | newCell.setReverse(false); | |
650 | if (reverse) { | |
651 | if (ch.getForeColorRGB() < 0) { | |
652 | newCell.setBackColor(ch.getForeColor()); | |
653 | newCell.setBackColorRGB(-1); | |
654 | } else { | |
655 | newCell.setBackColorRGB(ch.getForeColorRGB()); | |
656 | } | |
657 | if (ch.getBackColorRGB() < 0) { | |
658 | newCell.setForeColor(ch.getBackColor()); | |
659 | newCell.setForeColorRGB(-1); | |
660 | } else { | |
661 | newCell.setForeColorRGB(ch.getBackColorRGB()); | |
662 | } | |
663 | } | |
664 | if (line.isDoubleWidth()) { | |
665 | putDoubleWidthCharXY(line, (i * 2), row, newCell); | |
666 | } else { | |
667 | putCharXY(i, row, newCell); | |
668 | } | |
669 | } | |
670 | row++; | |
671 | } | |
672 | } | |
673 | ||
674 | /** | |
675 | * Set current value of the vertical scroll. | |
676 | * | |
677 | * @param value the new scroll value | |
678 | */ | |
679 | @Override | |
680 | public void setVerticalValue(final int value) { | |
681 | super.setVerticalValue(value); | |
682 | dirty = true; | |
683 | } | |
684 | ||
685 | /** | |
686 | * Perform a small step change up. | |
687 | */ | |
688 | @Override | |
689 | public void verticalDecrement() { | |
690 | super.verticalDecrement(); | |
691 | dirty = true; | |
692 | } | |
693 | ||
694 | /** | |
695 | * Perform a small step change down. | |
696 | */ | |
697 | @Override | |
698 | public void verticalIncrement() { | |
699 | super.verticalIncrement(); | |
700 | dirty = true; | |
701 | } | |
702 | ||
703 | /** | |
704 | * Perform a big step change up. | |
705 | */ | |
706 | public void bigVerticalDecrement() { | |
707 | super.bigVerticalDecrement(); | |
708 | dirty = true; | |
709 | } | |
710 | ||
711 | /** | |
712 | * Perform a big step change down. | |
713 | */ | |
714 | public void bigVerticalIncrement() { | |
715 | super.bigVerticalIncrement(); | |
716 | dirty = true; | |
717 | } | |
718 | ||
719 | /** | |
720 | * Go to the top edge of the vertical scroller. | |
721 | */ | |
722 | public void toTop() { | |
723 | super.toTop(); | |
724 | dirty = true; | |
725 | } | |
726 | ||
727 | /** | |
728 | * Go to the bottom edge of the vertical scroller. | |
729 | */ | |
730 | public void toBottom() { | |
731 | super.toBottom(); | |
732 | dirty = true; | |
733 | } | |
734 | ||
735 | /** | |
736 | * Handle widget close. | |
737 | */ | |
738 | @Override | |
739 | public void close() { | |
1104f8d7 KL |
740 | if (emulator != null) { |
741 | emulator.close(); | |
742 | } | |
dbf8e80a KL |
743 | if (shell != null) { |
744 | terminateShellChildProcess(); | |
745 | shell.destroy(); | |
746 | shell = null; | |
747 | } | |
748 | } | |
749 | ||
750 | /** | |
751 | * Resize scrollbars for a new width/height. | |
752 | */ | |
753 | @Override | |
754 | public void reflowData() { | |
1104f8d7 KL |
755 | if (emulator == null) { |
756 | return; | |
757 | } | |
dbf8e80a KL |
758 | |
759 | // Synchronize against the emulator so we don't stomp on its reader | |
760 | // thread. | |
761 | synchronized (emulator) { | |
762 | ||
763 | // Pull cursor information | |
764 | readEmulatorState(); | |
765 | ||
766 | // Vertical scrollbar | |
767 | setTopValue(getHeight() | |
768 | - (emulator.getScrollbackBuffer().size() | |
769 | + emulator.getDisplayBuffer().size())); | |
770 | setVerticalBigChange(getHeight()); | |
771 | ||
772 | } // synchronized (emulator) | |
773 | } | |
774 | ||
775 | // ------------------------------------------------------------------------ | |
4d2c61b4 KL |
776 | // TTerminalWidget -------------------------------------------------------- |
777 | // ------------------------------------------------------------------------ | |
778 | ||
779 | /** | |
780 | * Get the desired window title. | |
781 | * | |
782 | * @return the title | |
783 | */ | |
784 | public String getTitle() { | |
785 | return title; | |
786 | } | |
787 | ||
788 | /** | |
2bc32111 | 789 | * Returns true if this widget does not want the application-wide mouse |
4d2c61b4 KL |
790 | * cursor drawn over it. |
791 | * | |
2bc32111 | 792 | * @return true if this widget does not want the application-wide mouse |
4d2c61b4 KL |
793 | * cursor drawn over it |
794 | */ | |
795 | public boolean hasHiddenMouse() { | |
1104f8d7 KL |
796 | if (emulator == null) { |
797 | return false; | |
798 | } | |
4d2c61b4 KL |
799 | return (emulator.hasHiddenMousePointer() || typingHidMouse); |
800 | } | |
801 | ||
802 | /** | |
803 | * See if the terminal is still running. | |
804 | * | |
805 | * @return if true, we are still connected to / reading from the remote | |
806 | * side | |
807 | */ | |
808 | public boolean isReading() { | |
1104f8d7 KL |
809 | if (emulator == null) { |
810 | return false; | |
811 | } | |
4d2c61b4 KL |
812 | return emulator.isReading(); |
813 | } | |
814 | ||
815 | /** | |
816 | * Convert a string array to a whitespace-separated string. | |
817 | * | |
818 | * @param array the string array | |
819 | * @return a single string | |
820 | */ | |
821 | private String stringArrayToString(final String [] array) { | |
822 | StringBuilder sb = new StringBuilder(array[0].length()); | |
823 | for (int i = 0; i < array.length; i++) { | |
824 | sb.append(array[i]); | |
825 | if (i < array.length - 1) { | |
826 | sb.append(' '); | |
827 | } | |
828 | } | |
829 | return sb.toString(); | |
830 | } | |
831 | ||
832 | /** | |
833 | * Spawn the shell. | |
834 | * | |
835 | * @param command the command line to execute | |
836 | */ | |
837 | private void spawnShell(final String [] command) { | |
838 | ||
839 | /* | |
840 | System.err.printf("spawnShell(): '%s'\n", | |
841 | stringArrayToString(command)); | |
842 | */ | |
843 | ||
844 | // We will have vScroller for its data fields and mouse event | |
845 | // handling, but do not want to draw it. | |
846 | vScroller = new TVScroller(null, getWidth(), 0, getHeight()); | |
847 | vScroller.setVisible(false); | |
848 | setBottomValue(0); | |
849 | ||
850 | title = i18n.getString("windowTitle"); | |
851 | ||
852 | // Assume XTERM | |
853 | ECMA48.DeviceType deviceType = ECMA48.DeviceType.XTERM; | |
854 | ||
855 | try { | |
856 | ProcessBuilder pb = new ProcessBuilder(command); | |
857 | Map<String, String> env = pb.environment(); | |
858 | env.put("TERM", ECMA48.deviceTypeTerm(deviceType)); | |
859 | env.put("LANG", ECMA48.deviceTypeLang(deviceType, "en")); | |
860 | env.put("COLUMNS", "80"); | |
861 | env.put("LINES", "24"); | |
862 | pb.redirectErrorStream(true); | |
863 | shell = pb.start(); | |
864 | emulator = new ECMA48(deviceType, shell.getInputStream(), | |
865 | shell.getOutputStream(), this); | |
866 | } catch (IOException e) { | |
867 | messageBox(i18n.getString("errorLaunchingShellTitle"), | |
868 | MessageFormat.format(i18n.getString("errorLaunchingShellText"), | |
869 | e.getMessage())); | |
870 | } | |
871 | ||
872 | // Setup the scroll bars | |
873 | onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, getWidth(), | |
874 | getHeight())); | |
875 | ||
4d2c61b4 KL |
876 | // Hide mouse when typing option |
877 | if (System.getProperty("jexer.TTerminal.hideMouseWhenTyping", | |
878 | "true").equals("false")) { | |
879 | ||
880 | hideMouseWhenTyping = false; | |
881 | } | |
882 | } | |
883 | ||
884 | /** | |
885 | * Terminate the child of the 'script' process used on POSIX. This may | |
886 | * or may not work. | |
887 | */ | |
888 | private void terminateShellChildProcess() { | |
889 | int pid = -1; | |
890 | if (shell.getClass().getName().equals("java.lang.UNIXProcess")) { | |
891 | /* get the PID on unix/linux systems */ | |
892 | try { | |
893 | Field field = shell.getClass().getDeclaredField("pid"); | |
894 | field.setAccessible(true); | |
895 | pid = field.getInt(shell); | |
896 | } catch (Throwable e) { | |
897 | // SQUASH, this didn't work. Just bail out quietly. | |
898 | return; | |
899 | } | |
900 | } | |
901 | if (pid != -1) { | |
902 | // shell.destroy() works successfully at killing this side of | |
903 | // 'script'. But we need to make sure the other side (child | |
904 | // process) is also killed. | |
905 | String [] cmdKillIt = { | |
906 | "pkill", "-P", Integer.toString(pid) | |
907 | }; | |
908 | try { | |
909 | Runtime.getRuntime().exec(cmdKillIt); | |
910 | } catch (Throwable e) { | |
911 | // SQUASH, this didn't work. Just bail out quietly. | |
912 | return; | |
913 | } | |
914 | } | |
915 | } | |
916 | ||
917 | /** | |
918 | * Hook for subclasses to be notified of the shell termination. | |
919 | */ | |
920 | public void onShellExit() { | |
2bc32111 KL |
921 | TApplication app = getApplication(); |
922 | if (app != null) { | |
1e71bba2 KL |
923 | if (closeAction != null) { |
924 | // We have to put this action inside invokeLater() because it | |
925 | // could be executed during draw() when syncing with ECMA48. | |
926 | app.invokeLater(new Runnable() { | |
927 | public void run() { | |
a524aa2e | 928 | closeAction.DO(TTerminalWidget.this); |
2bc32111 | 929 | } |
1e71bba2 KL |
930 | }); |
931 | } | |
ee831bf6 | 932 | app.doRepaint(); |
4d2c61b4 | 933 | } |
4d2c61b4 KL |
934 | } |
935 | ||
936 | /** | |
937 | * Copy out variables from the emulator that TTerminal has to expose on | |
938 | * screen. | |
939 | */ | |
940 | private void readEmulatorState() { | |
1104f8d7 KL |
941 | if (emulator == null) { |
942 | return; | |
943 | } | |
944 | ||
4d2c61b4 KL |
945 | // Synchronize against the emulator so we don't stomp on its reader |
946 | // thread. | |
947 | synchronized (emulator) { | |
948 | ||
949 | setCursorX(emulator.getCursorX()); | |
950 | setCursorY(emulator.getCursorY() | |
951 | + (getHeight() - emulator.getHeight()) | |
952 | - getVerticalValue()); | |
953 | setCursorVisible(emulator.isCursorVisible()); | |
954 | if (getCursorX() > getWidth()) { | |
955 | setCursorVisible(false); | |
956 | } | |
957 | if ((getCursorY() >= getHeight()) || (getCursorY() < 0)) { | |
958 | setCursorVisible(false); | |
959 | } | |
960 | if (emulator.getScreenTitle().length() > 0) { | |
961 | // Only update the title if the shell is still alive | |
962 | if (shell != null) { | |
963 | title = emulator.getScreenTitle(); | |
964 | } | |
965 | } | |
966 | ||
967 | // Check to see if the shell has died. | |
968 | if (!emulator.isReading() && (shell != null)) { | |
969 | try { | |
970 | int rc = shell.exitValue(); | |
971 | // The emulator exited on its own, all is fine | |
972 | title = MessageFormat.format(i18n. | |
973 | getString("windowTitleCompleted"), title, rc); | |
974 | exitValue = rc; | |
975 | shell = null; | |
976 | emulator.close(); | |
977 | onShellExit(); | |
978 | } catch (IllegalThreadStateException e) { | |
979 | // The emulator thread has exited, but the shell Process | |
980 | // hasn't figured that out yet. Do nothing, we will see | |
981 | // this in a future tick. | |
982 | } | |
983 | } else if (emulator.isReading() && (shell != null)) { | |
984 | // The shell might be dead, let's check | |
985 | try { | |
986 | int rc = shell.exitValue(); | |
987 | // If we got here, the shell died. | |
988 | title = MessageFormat.format(i18n. | |
989 | getString("windowTitleCompleted"), title, rc); | |
990 | exitValue = rc; | |
991 | shell = null; | |
992 | emulator.close(); | |
993 | onShellExit(); | |
994 | } catch (IllegalThreadStateException e) { | |
995 | // The shell is still running, do nothing. | |
996 | } | |
997 | } | |
998 | ||
999 | } // synchronized (emulator) | |
1000 | } | |
1001 | ||
5ca5f8e5 KL |
1002 | /** |
1003 | * Wait for a period of time to get output from the launched process. | |
1004 | * | |
1005 | * @param millis millis to wait for, or 0 to wait forever | |
1006 | * @return true if the launched process has emitted something | |
1007 | */ | |
1008 | public boolean waitForOutput(final int millis) { | |
1009 | if (emulator == null) { | |
1010 | return false; | |
1011 | } | |
1012 | return emulator.waitForOutput(millis); | |
1013 | } | |
1014 | ||
4d2c61b4 KL |
1015 | /** |
1016 | * Check if a mouse press/release/motion event coordinate is over the | |
1017 | * emulator. | |
1018 | * | |
1019 | * @param mouse a mouse-based event | |
1020 | * @return whether or not the mouse is on the emulator | |
1021 | */ | |
1022 | private boolean mouseOnEmulator(final TMouseEvent mouse) { | |
1104f8d7 KL |
1023 | if (emulator == null) { |
1024 | return false; | |
1025 | } | |
4d2c61b4 KL |
1026 | |
1027 | if (!emulator.isReading()) { | |
1028 | return false; | |
1029 | } | |
1030 | ||
1031 | if ((mouse.getX() >= 0) | |
1032 | && (mouse.getX() < getWidth() - 1) | |
1033 | && (mouse.getY() >= 0) | |
1034 | && (mouse.getY() < getHeight()) | |
1035 | ) { | |
1036 | return true; | |
1037 | } | |
1038 | return false; | |
1039 | } | |
1040 | ||
4d2c61b4 KL |
1041 | /** |
1042 | * Draw glyphs for a double-width or double-height VT100 cell to two | |
1043 | * screen cells. | |
1044 | * | |
1045 | * @param line the line this VT100 cell is in | |
1046 | * @param x the X position to draw the left half to | |
1047 | * @param y the Y position to draw to | |
1048 | * @param cell the cell to draw | |
1049 | */ | |
1050 | private void putDoubleWidthCharXY(final DisplayLine line, final int x, | |
1051 | final int y, final Cell cell) { | |
1052 | ||
1053 | int textWidth = getScreen().getTextWidth(); | |
1054 | int textHeight = getScreen().getTextHeight(); | |
1055 | boolean cursorBlinkVisible = true; | |
1056 | ||
1057 | if (getScreen() instanceof SwingTerminal) { | |
1058 | SwingTerminal terminal = (SwingTerminal) getScreen(); | |
1059 | cursorBlinkVisible = terminal.getCursorBlinkVisible(); | |
1060 | } else if (getScreen() instanceof ECMA48Terminal) { | |
1061 | ECMA48Terminal terminal = (ECMA48Terminal) getScreen(); | |
1062 | ||
1063 | if (!terminal.hasSixel()) { | |
1064 | // The backend does not have sixel support, draw this as text | |
1065 | // and bail out. | |
1066 | putCharXY(x, y, cell); | |
1067 | putCharXY(x + 1, y, ' ', cell); | |
1068 | return; | |
1069 | } | |
1070 | cursorBlinkVisible = blinkState; | |
1071 | } else { | |
1072 | // We don't know how to dray glyphs to this screen, draw them as | |
1073 | // text and bail out. | |
1074 | putCharXY(x, y, cell); | |
1075 | putCharXY(x + 1, y, ' ', cell); | |
1076 | return; | |
1077 | } | |
1078 | ||
1079 | if ((textWidth != lastTextWidth) || (textHeight != lastTextHeight)) { | |
1080 | // Screen size has changed, reset the font. | |
1081 | setupFont(textHeight); | |
1082 | lastTextWidth = textWidth; | |
1083 | lastTextHeight = textHeight; | |
1084 | } | |
1085 | assert (doubleFont != null); | |
1086 | ||
1087 | BufferedImage image; | |
1088 | if (line.getDoubleHeight() == 1) { | |
1089 | // Double-height top half: don't draw the underline. | |
1090 | Cell newCell = new Cell(cell); | |
1091 | newCell.setUnderline(false); | |
1092 | image = doubleFont.getImage(newCell, textWidth * 2, textHeight * 2, | |
1093 | cursorBlinkVisible); | |
1094 | } else { | |
1095 | image = doubleFont.getImage(cell, textWidth * 2, textHeight * 2, | |
1096 | cursorBlinkVisible); | |
1097 | } | |
1098 | ||
1099 | // Now that we have the double-wide glyph drawn, copy the right | |
1100 | // pieces of it to the cells. | |
1101 | Cell left = new Cell(cell); | |
1102 | Cell right = new Cell(cell); | |
1103 | right.setChar(' '); | |
1104 | BufferedImage leftImage = null; | |
1105 | BufferedImage rightImage = null; | |
1106 | /* | |
1107 | System.err.println("image " + image + " textWidth " + textWidth + | |
1108 | " textHeight " + textHeight); | |
1109 | */ | |
1110 | ||
1111 | switch (line.getDoubleHeight()) { | |
1112 | case 1: | |
1113 | // Top half double height | |
1114 | leftImage = image.getSubimage(0, 0, textWidth, textHeight); | |
1115 | rightImage = image.getSubimage(textWidth, 0, textWidth, textHeight); | |
1116 | break; | |
1117 | case 2: | |
1118 | // Bottom half double height | |
1119 | leftImage = image.getSubimage(0, textHeight, textWidth, textHeight); | |
1120 | rightImage = image.getSubimage(textWidth, textHeight, | |
1121 | textWidth, textHeight); | |
1122 | break; | |
1123 | default: | |
1124 | // Either single height double-width, or error fallback | |
1125 | BufferedImage wideImage = new BufferedImage(textWidth * 2, | |
1126 | textHeight, BufferedImage.TYPE_INT_ARGB); | |
1127 | Graphics2D grWide = wideImage.createGraphics(); | |
1128 | grWide.drawImage(image, 0, 0, wideImage.getWidth(), | |
1129 | wideImage.getHeight(), null); | |
1130 | grWide.dispose(); | |
1131 | leftImage = wideImage.getSubimage(0, 0, textWidth, textHeight); | |
1132 | rightImage = wideImage.getSubimage(textWidth, 0, textWidth, | |
1133 | textHeight); | |
1134 | break; | |
1135 | } | |
1136 | left.setImage(leftImage); | |
1137 | right.setImage(rightImage); | |
1138 | // Since we have image data, ditch the character here. Otherwise, a | |
1139 | // drawBoxShadow() over the terminal window will show the characters | |
1140 | // which looks wrong. | |
1141 | left.setChar(' '); | |
1142 | right.setChar(' '); | |
1143 | putCharXY(x, y, left); | |
1144 | putCharXY(x + 1, y, right); | |
1145 | } | |
1146 | ||
1147 | /** | |
1148 | * Set up the double-width font. | |
1149 | * | |
1150 | * @param fontSize the size of font to request for the single-width font. | |
1151 | * The double-width font will be 2x this value. | |
1152 | */ | |
1153 | private void setupFont(final int fontSize) { | |
1154 | doubleFont = GlyphMaker.getInstance(fontSize * 2); | |
1155 | ||
1156 | // Special case: the ECMA48 backend needs to have a timer to drive | |
1157 | // its blink state. | |
1158 | if (getScreen() instanceof jexer.backend.ECMA48Terminal) { | |
1159 | if (!haveTimer) { | |
1160 | // Blink every 500 millis. | |
1161 | long millis = 500; | |
1162 | getApplication().addTimer(millis, true, | |
1163 | new TAction() { | |
1164 | public void DO() { | |
1165 | blinkState = !blinkState; | |
1166 | getApplication().doRepaint(); | |
1167 | } | |
1168 | } | |
1169 | ); | |
1170 | haveTimer = true; | |
1171 | } | |
1172 | } | |
1173 | } | |
1174 | ||
1175 | // ------------------------------------------------------------------------ | |
1176 | // DisplayListener -------------------------------------------------------- | |
1177 | // ------------------------------------------------------------------------ | |
1178 | ||
1179 | /** | |
1180 | * Called by emulator when fresh data has come in. | |
1181 | */ | |
1182 | public void displayChanged() { | |
83787cfb KL |
1183 | if (emulator != null) { |
1184 | // Force sync here: EMCA48.run() thread might be setting | |
1185 | // dirty=true while TTerminalWdiget.draw() is setting | |
1186 | // dirty=false. If these writes start interleaving, the display | |
1187 | // stops getting updated. | |
1188 | synchronized (emulator) { | |
1189 | dirty = true; | |
1190 | } | |
1191 | } else { | |
1192 | dirty = true; | |
1193 | } | |
4d2c61b4 KL |
1194 | getApplication().postEvent(new TMenuEvent(TMenu.MID_REPAINT)); |
1195 | } | |
1196 | ||
1197 | /** | |
1198 | * Function to call to obtain the display width. | |
1199 | * | |
1200 | * @return the number of columns in the display | |
1201 | */ | |
1202 | public int getDisplayWidth() { | |
1203 | if (ptypipe) { | |
1204 | return getWidth(); | |
1205 | } | |
1206 | return 80; | |
1207 | } | |
1208 | ||
1209 | /** | |
1210 | * Function to call to obtain the display height. | |
1211 | * | |
1212 | * @return the number of rows in the display | |
1213 | */ | |
1214 | public int getDisplayHeight() { | |
1215 | if (ptypipe) { | |
1216 | return getHeight(); | |
1217 | } | |
1218 | return 24; | |
1219 | } | |
1220 | ||
63543c45 KL |
1221 | // ------------------------------------------------------------------------ |
1222 | // EditMenuUser ----------------------------------------------------------- | |
1223 | // ------------------------------------------------------------------------ | |
1224 | ||
1225 | /** | |
1226 | * Check if the cut menu item should be enabled. | |
1227 | * | |
1228 | * @return true if the cut menu item should be enabled | |
1229 | */ | |
1230 | public boolean isEditMenuCut() { | |
1231 | return false; | |
1232 | } | |
1233 | ||
1234 | /** | |
1235 | * Check if the copy menu item should be enabled. | |
1236 | * | |
1237 | * @return true if the copy menu item should be enabled | |
1238 | */ | |
1239 | public boolean isEditMenuCopy() { | |
1240 | return false; | |
1241 | } | |
1242 | ||
1243 | /** | |
1244 | * Check if the paste menu item should be enabled. | |
1245 | * | |
1246 | * @return true if the paste menu item should be enabled | |
1247 | */ | |
1248 | public boolean isEditMenuPaste() { | |
1249 | return true; | |
1250 | } | |
1251 | ||
1252 | /** | |
1253 | * Check if the clear menu item should be enabled. | |
1254 | * | |
1255 | * @return true if the clear menu item should be enabled | |
1256 | */ | |
1257 | public boolean isEditMenuClear() { | |
1258 | return false; | |
1259 | } | |
1260 | ||
4d2c61b4 | 1261 | } |