2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2017 Kevin Lamonte
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
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.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
29 package jexer
.backend
;
31 import java
.awt
.BorderLayout
;
32 import java
.awt
.Color
;
34 import java
.awt
.FontMetrics
;
35 import java
.awt
.Graphics2D
;
36 import java
.awt
.Graphics
;
37 import java
.awt
.Insets
;
38 import java
.awt
.Rectangle
;
39 import java
.awt
.Toolkit
;
40 import java
.awt
.event
.ComponentEvent
;
41 import java
.awt
.event
.ComponentListener
;
42 import java
.awt
.event
.KeyEvent
;
43 import java
.awt
.event
.KeyListener
;
44 import java
.awt
.event
.MouseEvent
;
45 import java
.awt
.event
.MouseListener
;
46 import java
.awt
.event
.MouseMotionListener
;
47 import java
.awt
.event
.MouseWheelEvent
;
48 import java
.awt
.event
.MouseWheelListener
;
49 import java
.awt
.event
.WindowEvent
;
50 import java
.awt
.event
.WindowListener
;
51 import java
.awt
.geom
.Rectangle2D
;
52 import java
.awt
.image
.BufferedImage
;
53 import java
.io
.InputStream
;
54 import java
.util
.HashMap
;
55 import java
.util
.LinkedList
;
56 import java
.util
.List
;
57 import javax
.swing
.JComponent
;
58 import javax
.swing
.JFrame
;
59 import javax
.swing
.SwingUtilities
;
61 import jexer
.TKeypress
;
62 import jexer
.bits
.Cell
;
63 import jexer
.bits
.CellAttributes
;
64 import jexer
.event
.TCommandEvent
;
65 import jexer
.event
.TInputEvent
;
66 import jexer
.event
.TKeypressEvent
;
67 import jexer
.event
.TMouseEvent
;
68 import jexer
.event
.TResizeEvent
;
69 import static jexer
.TCommand
.*;
70 import static jexer
.TKeypress
.*;
73 * This Screen backend reads keystrokes and mouse events and draws to either
74 * a Java Swing JFrame (potentially triple-buffered) or a JComponent.
76 * This class is a bit of an inversion of typical GUI classes. It performs
77 * all of the drawing logic from SwingTerminal (which is not a Swing class),
78 * and uses a SwingComponent wrapper class to call the JFrame or JComponent
81 public final class SwingTerminal
extends LogicalScreen
82 implements TerminalReader
,
83 ComponentListener
, KeyListener
,
84 MouseListener
, MouseMotionListener
,
85 MouseWheelListener
, WindowListener
{
88 * The Swing component or frame to draw to.
90 private SwingComponent swing
;
92 // ------------------------------------------------------------------------
93 // Screen -----------------------------------------------------------------
94 // ------------------------------------------------------------------------
97 * Cursor style to draw.
99 public enum CursorStyle
{
101 * Use an underscore for the cursor.
106 * Use a solid block for the cursor.
111 * Use an outlined block for the cursor.
117 * A cache of previously-rendered glyphs for blinking text, when it is
120 private HashMap
<Cell
, BufferedImage
> glyphCacheBlink
;
123 * A cache of previously-rendered glyphs for non-blinking, or
124 * blinking-and-visible, text.
126 private HashMap
<Cell
, BufferedImage
> glyphCache
;
128 // Colors to map DOS colors to AWT colors.
129 private static Color MYBLACK
;
130 private static Color MYRED
;
131 private static Color MYGREEN
;
132 private static Color MYYELLOW
;
133 private static Color MYBLUE
;
134 private static Color MYMAGENTA
;
135 private static Color MYCYAN
;
136 private static Color MYWHITE
;
137 private static Color MYBOLD_BLACK
;
138 private static Color MYBOLD_RED
;
139 private static Color MYBOLD_GREEN
;
140 private static Color MYBOLD_YELLOW
;
141 private static Color MYBOLD_BLUE
;
142 private static Color MYBOLD_MAGENTA
;
143 private static Color MYBOLD_CYAN
;
144 private static Color MYBOLD_WHITE
;
147 * When true, all the MYBLACK, MYRED, etc. colors are set.
149 private static boolean dosColors
= false;
152 * Setup Swing colors to match DOS color palette.
154 private static void setDOSColors() {
158 MYBLACK
= new Color(0x00, 0x00, 0x00);
159 MYRED
= new Color(0xa8, 0x00, 0x00);
160 MYGREEN
= new Color(0x00, 0xa8, 0x00);
161 MYYELLOW
= new Color(0xa8, 0x54, 0x00);
162 MYBLUE
= new Color(0x00, 0x00, 0xa8);
163 MYMAGENTA
= new Color(0xa8, 0x00, 0xa8);
164 MYCYAN
= new Color(0x00, 0xa8, 0xa8);
165 MYWHITE
= new Color(0xa8, 0xa8, 0xa8);
166 MYBOLD_BLACK
= new Color(0x54, 0x54, 0x54);
167 MYBOLD_RED
= new Color(0xfc, 0x54, 0x54);
168 MYBOLD_GREEN
= new Color(0x54, 0xfc, 0x54);
169 MYBOLD_YELLOW
= new Color(0xfc, 0xfc, 0x54);
170 MYBOLD_BLUE
= new Color(0x54, 0x54, 0xfc);
171 MYBOLD_MAGENTA
= new Color(0xfc, 0x54, 0xfc);
172 MYBOLD_CYAN
= new Color(0x54, 0xfc, 0xfc);
173 MYBOLD_WHITE
= new Color(0xfc, 0xfc, 0xfc);
179 * The terminus font resource filename.
181 private static final String FONTFILE
= "terminus-ttf-4.39/TerminusTTF-Bold-4.39.ttf";
184 * If true, we were successful getting Terminus.
186 private boolean gotTerminus
= false;
189 * If true, we were successful at getting the font dimensions.
191 private boolean gotFontDimensions
= false;
194 * The currently selected font.
196 private Font font
= null;
199 * The currently selected font size in points.
201 private int fontSize
= 16;
204 * Width of a character cell in pixels.
206 private int textWidth
= 1;
209 * Height of a character cell in pixels.
211 private int textHeight
= 1;
214 * Descent of a character cell in pixels.
216 private int maxDescent
= 0;
219 * System-dependent Y adjustment for text in the character cell.
221 private int textAdjustY
= 0;
224 * System-dependent X adjustment for text in the character cell.
226 private int textAdjustX
= 0;
229 * Top pixel absolute location.
231 private int top
= 30;
234 * Left pixel absolute location.
236 private int left
= 30;
239 * The cursor style to draw.
241 private CursorStyle cursorStyle
= CursorStyle
.UNDERLINE
;
244 * The number of millis to wait before switching the blink from visible
245 * to invisible. Set to 0 or negative to disable blinking.
247 private long blinkMillis
= 500;
250 * Get the number of millis to wait before switching the blink from
251 * visible to invisible.
253 * @return the number of milli to wait before switching the blink from
254 * visible to invisible
256 public long getBlinkMillis() {
261 * If true, the cursor should be visible right now based on the blink
264 private boolean cursorBlinkVisible
= true;
267 * The time that the blink last flipped from visible to invisible or
268 * from invisible to visible.
270 private long lastBlinkTime
= 0;
273 * Get the font size in points.
275 * @return font size in points
277 public int getFontSize() {
282 * Set the font size in points.
284 * @param fontSize font size in points
286 public void setFontSize(final int fontSize
) {
287 this.fontSize
= fontSize
;
288 Font newFont
= font
.deriveFont((float) fontSize
);
293 * Set to a new font, and resize the screen to match its dimensions.
295 * @param font the new font
297 public void setFont(final Font font
) {
301 glyphCacheBlink
= new HashMap
<Cell
, BufferedImage
>();
302 glyphCache
= new HashMap
<Cell
, BufferedImage
>();
307 * Set the font to Terminus, the best all-around font for both CP437 and
310 public void getDefaultFont() {
312 ClassLoader loader
= Thread
.currentThread().
313 getContextClassLoader();
314 InputStream in
= loader
.getResourceAsStream(FONTFILE
);
315 Font terminusRoot
= Font
.createFont(Font
.TRUETYPE_FONT
, in
);
316 Font terminus
= terminusRoot
.deriveFont(Font
.PLAIN
, fontSize
);
319 } catch (Exception e
) {
321 font
= new Font(Font
.MONOSPACED
, Font
.PLAIN
, fontSize
);
328 * Convert a CellAttributes foreground color to an Swing Color.
330 * @param attr the text attributes
331 * @return the Swing Color
333 private Color
attrToForegroundColor(final CellAttributes attr
) {
335 if (attr
.getForeColor().equals(jexer
.bits
.Color
.BLACK
)) {
337 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.RED
)) {
339 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.BLUE
)) {
341 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.GREEN
)) {
343 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.YELLOW
)) {
344 return MYBOLD_YELLOW
;
345 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.CYAN
)) {
347 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.MAGENTA
)) {
348 return MYBOLD_MAGENTA
;
349 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.WHITE
)) {
353 if (attr
.getForeColor().equals(jexer
.bits
.Color
.BLACK
)) {
355 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.RED
)) {
357 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.BLUE
)) {
359 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.GREEN
)) {
361 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.YELLOW
)) {
363 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.CYAN
)) {
365 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.MAGENTA
)) {
367 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.WHITE
)) {
371 throw new IllegalArgumentException("Invalid color: " +
372 attr
.getForeColor().getValue());
376 * Convert a CellAttributes background color to an Swing Color.
378 * @param attr the text attributes
379 * @return the Swing Color
381 private Color
attrToBackgroundColor(final CellAttributes attr
) {
382 if (attr
.getBackColor().equals(jexer
.bits
.Color
.BLACK
)) {
384 } else if (attr
.getBackColor().equals(jexer
.bits
.Color
.RED
)) {
386 } else if (attr
.getBackColor().equals(jexer
.bits
.Color
.BLUE
)) {
388 } else if (attr
.getBackColor().equals(jexer
.bits
.Color
.GREEN
)) {
390 } else if (attr
.getBackColor().equals(jexer
.bits
.Color
.YELLOW
)) {
392 } else if (attr
.getBackColor().equals(jexer
.bits
.Color
.CYAN
)) {
394 } else if (attr
.getBackColor().equals(jexer
.bits
.Color
.MAGENTA
)) {
396 } else if (attr
.getBackColor().equals(jexer
.bits
.Color
.WHITE
)) {
399 throw new IllegalArgumentException("Invalid color: " +
400 attr
.getBackColor().getValue());
404 * Figure out what textAdjustX and textAdjustY should be, based on the
405 * location of a vertical bar (to find textAdjustY) and a horizontal bar
406 * (to find textAdjustX).
408 * @return true if textAdjustX and textAdjustY were guessed at correctly
410 private boolean getFontAdjustments() {
411 BufferedImage image
= null;
413 // What SHOULD happen is that the topmost/leftmost white pixel is at
414 // position (gr2x, gr2y). But it might also be off by a pixel in
417 Graphics2D gr2
= null;
420 image
= new BufferedImage(textWidth
* 2, textHeight
* 2,
421 BufferedImage
.TYPE_INT_ARGB
);
423 gr2
= image
.createGraphics();
424 gr2
.setFont(swing
.getFont());
425 gr2
.setColor(java
.awt
.Color
.BLACK
);
426 gr2
.fillRect(0, 0, textWidth
* 2, textHeight
* 2);
427 gr2
.setColor(java
.awt
.Color
.WHITE
);
428 char [] chars
= new char[1];
429 chars
[0] = jexer
.bits
.GraphicsChars
.VERTICAL_BAR
;
430 gr2
.drawChars(chars
, 0, 1, gr2x
, gr2y
+ textHeight
- maxDescent
);
433 for (int x
= 0; x
< textWidth
; x
++) {
434 for (int y
= 0; y
< textHeight
; y
++) {
437 System.err.println("X: " + x + " Y: " + y + " " +
441 if ((image
.getRGB(x
, y
) & 0xFFFFFF) != 0) {
442 textAdjustY
= (gr2y
- y
);
444 // System.err.println("textAdjustY: " + textAdjustY);
451 gr2
= image
.createGraphics();
452 gr2
.setFont(swing
.getFont());
453 gr2
.setColor(java
.awt
.Color
.BLACK
);
454 gr2
.fillRect(0, 0, textWidth
* 2, textHeight
* 2);
455 gr2
.setColor(java
.awt
.Color
.WHITE
);
456 chars
[0] = jexer
.bits
.GraphicsChars
.SINGLE_BAR
;
457 gr2
.drawChars(chars
, 0, 1, gr2x
, gr2y
+ textHeight
- maxDescent
);
460 for (int x
= 0; x
< textWidth
; x
++) {
461 for (int y
= 0; y
< textHeight
; y
++) {
464 System.err.println("X: " + x + " Y: " + y + " " +
468 if ((image
.getRGB(x
, y
) & 0xFFFFFF) != 0) {
469 textAdjustX
= (gr2x
- x
);
471 // System.err.println("textAdjustX: " + textAdjustX);
477 // Something weird happened, don't rely on this function.
478 // System.err.println("getFontAdjustments: false");
483 * Figure out my font dimensions. This code path works OK for the JFrame
484 * case, and can be called immediately after JFrame creation.
486 private void getFontDimensions() {
488 Graphics gr
= swing
.getGraphics();
492 getFontDimensions(gr
);
496 * Figure out my font dimensions. This code path is needed to lazy-load
497 * the information inside paint().
499 * @param gr Graphics object to use
501 private void getFontDimensions(final Graphics gr
) {
503 FontMetrics fm
= gr
.getFontMetrics();
504 maxDescent
= fm
.getMaxDescent();
505 Rectangle2D bounds
= fm
.getMaxCharBounds(gr
);
506 int leading
= fm
.getLeading();
507 textWidth
= (int)Math
.round(bounds
.getWidth());
508 // textHeight = (int)Math.round(bounds.getHeight()) - maxDescent;
510 // This produces the same number, but works better for ugly
512 textHeight
= fm
.getMaxAscent() + maxDescent
- leading
;
514 if (gotTerminus
== true) {
518 if (getFontAdjustments() == false) {
519 // We were unable to programmatically determine textAdjustX and
520 // textAdjustY, so try some guesses based on VM vendor.
521 String runtime
= System
.getProperty("java.runtime.name");
522 if ((runtime
!= null) && (runtime
.contains("Java(TM)"))) {
528 if (sessionInfo
!= null) {
529 sessionInfo
.setTextCellDimensions(textWidth
, textHeight
);
531 gotFontDimensions
= true;
535 * Resize to font dimensions.
537 public void resizeToScreen() {
538 swing
.setDimensions(textWidth
* width
, textHeight
* height
);
542 * Draw one glyph to the screen.
544 * @param gr the Swing Graphics context
545 * @param cell the Cell to draw
546 * @param xPixel the x-coordinate to render to. 0 means the
547 * left-most pixel column.
548 * @param yPixel the y-coordinate to render to. 0 means the top-most
551 private void drawGlyph(final Graphics gr
, final Cell cell
,
552 final int xPixel
, final int yPixel
) {
555 System.err.println("drawGlyph(): " + xPixel + " " + yPixel +
559 BufferedImage image
= null;
560 if (cell
.isBlink() && !cursorBlinkVisible
) {
561 image
= glyphCacheBlink
.get(cell
);
563 image
= glyphCache
.get(cell
);
566 if (swing
.getFrame() != null) {
567 gr
.drawImage(image
, xPixel
, yPixel
, swing
.getFrame());
569 gr
.drawImage(image
, xPixel
, yPixel
, swing
.getComponent());
574 // Generate glyph and draw it.
575 Graphics2D gr2
= null;
578 if ((SwingComponent
.tripleBuffer
) && (swing
.getFrame() != null)) {
579 image
= new BufferedImage(textWidth
, textHeight
,
580 BufferedImage
.TYPE_INT_ARGB
);
581 gr2
= image
.createGraphics();
582 gr2
.setFont(swing
.getFont());
586 gr2
= (Graphics2D
) gr
;
589 Cell cellColor
= new Cell();
590 cellColor
.setTo(cell
);
593 if (cell
.isReverse()) {
594 cellColor
.setForeColor(cell
.getBackColor());
595 cellColor
.setBackColor(cell
.getForeColor());
598 // Draw the background rectangle, then the foreground character.
599 gr2
.setColor(attrToBackgroundColor(cellColor
));
600 gr2
.fillRect(gr2x
, gr2y
, textWidth
, textHeight
);
602 // Handle blink and underline
604 || (cell
.isBlink() && cursorBlinkVisible
)
606 gr2
.setColor(attrToForegroundColor(cellColor
));
607 char [] chars
= new char[1];
608 chars
[0] = cell
.getChar();
609 gr2
.drawChars(chars
, 0, 1, gr2x
+ textAdjustX
,
610 gr2y
+ textHeight
- maxDescent
+ textAdjustY
);
612 if (cell
.isUnderline()) {
613 gr2
.fillRect(gr2x
, gr2y
+ textHeight
- 2, textWidth
, 2);
617 if ((SwingComponent
.tripleBuffer
) && (swing
.getFrame() != null)) {
620 // We need a new key that will not be mutated by
622 Cell key
= new Cell();
624 if (cell
.isBlink() && !cursorBlinkVisible
) {
625 glyphCacheBlink
.put(key
, image
);
627 glyphCache
.put(key
, image
);
630 if (swing
.getFrame() != null) {
631 gr
.drawImage(image
, xPixel
, yPixel
, swing
.getFrame());
633 gr
.drawImage(image
, xPixel
, yPixel
, swing
.getComponent());
640 * Check if the cursor is visible, and if so draw it.
642 * @param gr the Swing Graphics context
644 private void drawCursor(final Graphics gr
) {
649 && (cursorY
<= height
- 1)
650 && (cursorX
<= width
- 1)
651 && cursorBlinkVisible
653 int xPixel
= cursorX
* textWidth
+ left
;
654 int yPixel
= cursorY
* textHeight
+ top
;
655 Cell lCell
= logical
[cursorX
][cursorY
];
656 gr
.setColor(attrToForegroundColor(lCell
));
657 switch (cursorStyle
) {
661 gr
.fillRect(xPixel
, yPixel
+ textHeight
- 2, textWidth
, 2);
664 gr
.fillRect(xPixel
, yPixel
, textWidth
, textHeight
);
667 gr
.drawRect(xPixel
, yPixel
, textWidth
- 1, textHeight
- 1);
674 * Reset the blink timer.
676 private void resetBlinkTimer() {
677 lastBlinkTime
= System
.currentTimeMillis();
678 cursorBlinkVisible
= true;
682 * Paint redraws the whole screen.
684 * @param gr the Swing Graphics context
686 public void paint(final Graphics gr
) {
688 if (gotFontDimensions
== false) {
689 // Lazy-load the text width/height
690 getFontDimensions(gr
);
692 System.err.println("textWidth " + textWidth +
693 " textHeight " + textHeight);
694 System.err.println("FONT: " + swing.getFont() + " font " + font);
699 int xCellMax
= width
;
701 int yCellMax
= height
;
703 Rectangle bounds
= gr
.getClipBounds();
704 if (bounds
!= null) {
705 // Only update what is in the bounds
706 xCellMin
= textColumn(bounds
.x
);
707 xCellMax
= textColumn(bounds
.x
+ bounds
.width
);
708 if (xCellMax
> width
) {
711 if (xCellMin
>= xCellMax
) {
712 xCellMin
= xCellMax
- 2;
717 yCellMin
= textRow(bounds
.y
);
718 yCellMax
= textRow(bounds
.y
+ bounds
.height
);
719 if (yCellMax
> height
) {
722 if (yCellMin
>= yCellMax
) {
723 yCellMin
= yCellMax
- 2;
729 // We need a total repaint
730 reallyCleared
= true;
733 // Prevent updates to the screen's data from the TApplication
735 synchronized (this) {
738 System.err.printf("bounds %s X %d %d Y %d %d\n",
739 bounds, xCellMin, xCellMax, yCellMin, yCellMax);
742 for (int y
= yCellMin
; y
< yCellMax
; y
++) {
743 for (int x
= xCellMin
; x
< xCellMax
; x
++) {
745 int xPixel
= x
* textWidth
+ left
;
746 int yPixel
= y
* textHeight
+ top
;
748 Cell lCell
= logical
[x
][y
];
749 Cell pCell
= physical
[x
][y
];
751 if (!lCell
.equals(pCell
)
754 || (swing
.getFrame() == null)) {
756 drawGlyph(gr
, lCell
, xPixel
, yPixel
);
758 // Physical is always updated
759 physical
[x
][y
].setTo(lCell
);
765 reallyCleared
= false;
766 } // synchronized (this)
770 * Restore terminal to normal state.
772 public void shutdown() {
777 * Push the logical screen to the physical device.
780 public void flushPhysical() {
781 // See if it is time to flip the blink time.
782 long nowTime
= System
.currentTimeMillis();
783 if (nowTime
>= blinkMillis
+ lastBlinkTime
) {
784 lastBlinkTime
= nowTime
;
785 cursorBlinkVisible
= !cursorBlinkVisible
;
786 // System.err.println("New lastBlinkTime: " + lastBlinkTime);
789 if ((swing
.getFrame() != null)
790 && (swing
.getBufferStrategy() != null)
795 } while (swing
.getBufferStrategy().contentsRestored());
797 swing
.getBufferStrategy().show();
798 Toolkit
.getDefaultToolkit().sync();
799 } while (swing
.getBufferStrategy().contentsLost());
802 // Non-triple-buffered, call drawToSwing() once
808 * Push the logical screen to the physical device.
810 private void drawToSwing() {
813 System.err.printf("drawToSwing(): reallyCleared %s dirty %s\n",
814 reallyCleared, dirty);
817 // If reallyCleared is set, we have to draw everything.
818 if ((swing
.getFrame() != null)
819 && (swing
.getBufferStrategy() != null)
820 && (reallyCleared
== true)
822 // Triple-buffering: we have to redraw everything on this thread.
823 Graphics gr
= swing
.getBufferStrategy().getDrawGraphics();
826 swing
.getBufferStrategy().show();
827 Toolkit
.getDefaultToolkit().sync();
829 } else if (((swing
.getFrame() != null)
830 && (swing
.getBufferStrategy() == null))
831 || (reallyCleared
== true)
833 // Repaint everything on the Swing thread.
834 // System.err.println("REPAINT ALL");
839 if ((swing
.getFrame() != null) && (swing
.getBufferStrategy() != null)) {
840 Graphics gr
= swing
.getBufferStrategy().getDrawGraphics();
842 synchronized (this) {
843 for (int y
= 0; y
< height
; y
++) {
844 for (int x
= 0; x
< width
; x
++) {
845 Cell lCell
= logical
[x
][y
];
846 Cell pCell
= physical
[x
][y
];
848 int xPixel
= x
* textWidth
+ left
;
849 int yPixel
= y
* textHeight
+ top
;
851 if (!lCell
.equals(pCell
)
857 drawGlyph(gr
, lCell
, xPixel
, yPixel
);
858 physical
[x
][y
].setTo(lCell
);
863 } // synchronized (this)
866 swing
.getBufferStrategy().show();
867 Toolkit
.getDefaultToolkit().sync();
871 // Swing thread version: request a repaint, but limit it to the area
874 // Find the minimum-size damaged region.
875 int xMin
= swing
.getWidth();
877 int yMin
= swing
.getHeight();
880 synchronized (this) {
881 for (int y
= 0; y
< height
; y
++) {
882 for (int x
= 0; x
< width
; x
++) {
883 Cell lCell
= logical
[x
][y
];
884 Cell pCell
= physical
[x
][y
];
886 int xPixel
= x
* textWidth
+ left
;
887 int yPixel
= y
* textHeight
+ top
;
889 if (!lCell
.equals(pCell
)
898 if (xPixel
+ textWidth
> xMax
) {
899 xMax
= xPixel
+ textWidth
;
904 if (yPixel
+ textHeight
> yMax
) {
905 yMax
= yPixel
+ textHeight
;
911 if (xMin
+ textWidth
>= xMax
) {
914 if (yMin
+ textHeight
>= yMax
) {
918 // Repaint the desired area
920 System.err.printf("REPAINT X %d %d Y %d %d\n", xMin, xMax,
924 if ((swing
.getFrame() != null) && (swing
.getBufferStrategy() != null)) {
925 // This path should never be taken, but is left here for
927 Graphics gr
= swing
.getBufferStrategy().getDrawGraphics();
928 Rectangle bounds
= new Rectangle(xMin
, yMin
, xMax
- xMin
,
933 swing
.getBufferStrategy().show();
934 Toolkit
.getDefaultToolkit().sync();
936 // Repaint on the Swing thread.
937 swing
.repaint(xMin
, yMin
, xMax
- xMin
, yMax
- yMin
);
942 * Convert pixel column position to text cell column position.
944 * @param x pixel column position
945 * @return text cell column position
947 public int textColumn(final int x
) {
948 return ((x
- left
) / textWidth
);
952 * Convert pixel row position to text cell row position.
954 * @param y pixel row position
955 * @return text cell row position
957 public int textRow(final int y
) {
958 return ((y
- top
) / textHeight
);
962 * Set the window title.
964 * @param title the new title
966 public void setTitle(final String title
) {
967 swing
.setTitle(title
);
970 // ------------------------------------------------------------------------
971 // TerminalReader ---------------------------------------------------------
972 // ------------------------------------------------------------------------
975 * The session information.
977 private SwingSessionInfo sessionInfo
;
980 * Getter for sessionInfo.
982 * @return the SessionInfo
984 public SessionInfo
getSessionInfo() {
989 * The listening object that run() wakes up on new input.
991 private Object listener
;
994 * Set listener to a different Object.
996 * @param listener the new listening object that run() wakes up on new
999 public void setListener(final Object listener
) {
1000 this.listener
= listener
;
1004 * The event queue, filled up by a thread reading on input.
1006 private List
<TInputEvent
> eventQueue
;
1009 * The last reported mouse X position.
1011 private int oldMouseX
= -1;
1014 * The last reported mouse Y position.
1016 private int oldMouseY
= -1;
1019 * true if mouse1 was down. Used to report mouse1 on the release event.
1021 private boolean mouse1
= false;
1024 * true if mouse2 was down. Used to report mouse2 on the release event.
1026 private boolean mouse2
= false;
1029 * true if mouse3 was down. Used to report mouse3 on the release event.
1031 private boolean mouse3
= false;
1034 * Public constructor creates a new JFrame to render to.
1036 * @param windowWidth the number of text columns to start with
1037 * @param windowHeight the number of text rows to start with
1038 * @param fontSize the size in points. Good values to pick are: 16, 20,
1040 * @param listener the object this backend needs to wake up when new
1043 public SwingTerminal(final int windowWidth
, final int windowHeight
,
1044 final int fontSize
, final Object listener
) {
1046 this.fontSize
= fontSize
;
1050 // Figure out my cursor style.
1051 String cursorStyleString
= System
.getProperty(
1052 "jexer.Swing.cursorStyle", "underline").toLowerCase();
1053 if (cursorStyleString
.equals("underline")) {
1054 cursorStyle
= CursorStyle
.UNDERLINE
;
1055 } else if (cursorStyleString
.equals("outline")) {
1056 cursorStyle
= CursorStyle
.OUTLINE
;
1057 } else if (cursorStyleString
.equals("block")) {
1058 cursorStyle
= CursorStyle
.BLOCK
;
1061 // Pull the system property for triple buffering.
1062 if (System
.getProperty("jexer.Swing.tripleBuffer") != null) {
1063 if (System
.getProperty("jexer.Swing.tripleBuffer").equals("true")) {
1064 SwingComponent
.tripleBuffer
= true;
1066 SwingComponent
.tripleBuffer
= false;
1071 SwingUtilities
.invokeAndWait(new Runnable() {
1074 JFrame frame
= new JFrame() {
1077 * Serializable version.
1079 private static final long serialVersionUID
= 1;
1082 * The code that performs the actual drawing.
1084 public SwingTerminal screen
= null;
1087 * Anonymous class initializer saves the screen
1088 * reference, so that paint() and the like call out
1092 this.screen
= SwingTerminal
.this;
1096 * Update redraws the whole screen.
1098 * @param gr the Swing Graphics context
1101 public void update(final Graphics gr
) {
1102 // The default update clears the area. Don't do
1103 // that, instead just paint it directly.
1108 * Paint redraws the whole screen.
1110 * @param gr the Swing Graphics context
1113 public void paint(final Graphics gr
) {
1114 if (screen
!= null) {
1120 // Get the Swing component
1121 SwingTerminal
.this.swing
= new SwingComponent(frame
);
1123 // Hang onto top and left for drawing.
1124 Insets insets
= SwingTerminal
.this.swing
.getInsets();
1125 SwingTerminal
.this.left
= insets
.left
;
1126 SwingTerminal
.this.top
= insets
.top
;
1128 // Load the font so that we can set sessionInfo.
1131 // Get the default cols x rows and set component size
1133 SwingTerminal
.this.sessionInfo
=
1134 new SwingSessionInfo(SwingTerminal
.this.swing
,
1135 SwingTerminal
.this.textWidth
,
1136 SwingTerminal
.this.textHeight
,
1137 windowWidth
, windowHeight
);
1139 SwingTerminal
.this.setDimensions(sessionInfo
.getWindowWidth(),
1140 sessionInfo
.getWindowHeight());
1142 SwingTerminal
.this.resizeToScreen();
1143 SwingTerminal
.this.swing
.setVisible(true);
1146 } catch (Exception e
) {
1147 e
.printStackTrace();
1150 this.listener
= listener
;
1154 eventQueue
= new LinkedList
<TInputEvent
>();
1156 // Add listeners to Swing.
1157 swing
.addKeyListener(this);
1158 swing
.addWindowListener(this);
1159 swing
.addComponentListener(this);
1160 swing
.addMouseListener(this);
1161 swing
.addMouseMotionListener(this);
1162 swing
.addMouseWheelListener(this);
1166 * Public constructor renders to an existing JComponent.
1168 * @param component the Swing component to render to
1169 * @param windowWidth the number of text columns to start with
1170 * @param windowHeight the number of text rows to start with
1171 * @param fontSize the size in points. Good values to pick are: 16, 20,
1173 * @param listener the object this backend needs to wake up when new
1176 public SwingTerminal(final JComponent component
, final int windowWidth
,
1177 final int windowHeight
, final int fontSize
, final Object listener
) {
1179 this.fontSize
= fontSize
;
1183 // Figure out my cursor style.
1184 String cursorStyleString
= System
.getProperty(
1185 "jexer.Swing.cursorStyle", "underline").toLowerCase();
1186 if (cursorStyleString
.equals("underline")) {
1187 cursorStyle
= CursorStyle
.UNDERLINE
;
1188 } else if (cursorStyleString
.equals("outline")) {
1189 cursorStyle
= CursorStyle
.OUTLINE
;
1190 } else if (cursorStyleString
.equals("block")) {
1191 cursorStyle
= CursorStyle
.BLOCK
;
1195 SwingUtilities
.invokeAndWait(new Runnable() {
1198 JComponent newComponent
= new JComponent() {
1201 * Serializable version.
1203 private static final long serialVersionUID
= 1;
1206 * The code that performs the actual drawing.
1208 public SwingTerminal screen
= null;
1211 * Anonymous class initializer saves the screen
1212 * reference, so that paint() and the like call out
1216 this.screen
= SwingTerminal
.this;
1220 * Update redraws the whole screen.
1222 * @param gr the Swing Graphics context
1225 public void update(final Graphics gr
) {
1226 // The default update clears the area. Don't do
1227 // that, instead just paint it directly.
1232 * Paint redraws the whole screen.
1234 * @param gr the Swing Graphics context
1237 public void paint(final Graphics gr
) {
1238 if (screen
!= null) {
1243 component
.setLayout(new BorderLayout());
1244 component
.add(newComponent
);
1246 // Allow key events to be received
1247 component
.setFocusable(true);
1249 // Get the Swing component
1250 SwingTerminal
.this.swing
= new SwingComponent(component
);
1252 // Hang onto top and left for drawing.
1253 Insets insets
= SwingTerminal
.this.swing
.getInsets();
1254 SwingTerminal
.this.left
= insets
.left
;
1255 SwingTerminal
.this.top
= insets
.top
;
1257 // Load the font so that we can set sessionInfo.
1260 // Get the default cols x rows and set component size
1262 SwingTerminal
.this.sessionInfo
=
1263 new SwingSessionInfo(SwingTerminal
.this.swing
,
1264 SwingTerminal
.this.textWidth
,
1265 SwingTerminal
.this.textHeight
);
1268 } catch (Exception e
) {
1269 e
.printStackTrace();
1272 this.listener
= listener
;
1276 eventQueue
= new LinkedList
<TInputEvent
>();
1278 // Add listeners to Swing.
1279 swing
.addKeyListener(this);
1280 swing
.addWindowListener(this);
1281 swing
.addComponentListener(this);
1282 swing
.addMouseListener(this);
1283 swing
.addMouseMotionListener(this);
1284 swing
.addMouseWheelListener(this);
1288 * Check if there are events in the queue.
1290 * @return if true, getEvents() has something to return to the backend
1292 public boolean hasEvents() {
1293 synchronized (eventQueue
) {
1294 return (eventQueue
.size() > 0);
1299 * Return any events in the IO queue.
1301 * @param queue list to append new events to
1303 public void getEvents(final List
<TInputEvent
> queue
) {
1304 synchronized (eventQueue
) {
1305 if (eventQueue
.size() > 0) {
1306 synchronized (queue
) {
1307 queue
.addAll(eventQueue
);
1315 * Restore terminal to normal state.
1317 public void closeTerminal() {
1322 * Pass Swing keystrokes into the event queue.
1324 * @param key keystroke received
1326 public void keyReleased(final KeyEvent key
) {
1327 // Ignore release events
1331 * Pass Swing keystrokes into the event queue.
1333 * @param key keystroke received
1335 public void keyTyped(final KeyEvent key
) {
1336 // Ignore typed events
1340 * Pass Swing keystrokes into the event queue.
1342 * @param key keystroke received
1344 public void keyPressed(final KeyEvent key
) {
1345 boolean alt
= false;
1346 boolean shift
= false;
1347 boolean ctrl
= false;
1349 boolean isKey
= false;
1350 if (key
.isActionKey()) {
1353 ch
= key
.getKeyChar();
1355 alt
= key
.isAltDown();
1356 ctrl
= key
.isControlDown();
1357 shift
= key
.isShiftDown();
1360 System.err.printf("Swing Key: %s\n", key);
1361 System.err.printf(" isKey: %s\n", isKey);
1362 System.err.printf(" alt: %s\n", alt);
1363 System.err.printf(" ctrl: %s\n", ctrl);
1364 System.err.printf(" shift: %s\n", shift);
1365 System.err.printf(" ch: %s\n", ch);
1368 // Special case: not return the bare modifier presses
1369 switch (key
.getKeyCode()) {
1370 case KeyEvent
.VK_ALT
:
1372 case KeyEvent
.VK_ALT_GRAPH
:
1374 case KeyEvent
.VK_CONTROL
:
1376 case KeyEvent
.VK_SHIFT
:
1378 case KeyEvent
.VK_META
:
1384 TKeypress keypress
= null;
1386 switch (key
.getKeyCode()) {
1387 case KeyEvent
.VK_F1
:
1388 keypress
= new TKeypress(true, TKeypress
.F1
, ' ',
1391 case KeyEvent
.VK_F2
:
1392 keypress
= new TKeypress(true, TKeypress
.F2
, ' ',
1395 case KeyEvent
.VK_F3
:
1396 keypress
= new TKeypress(true, TKeypress
.F3
, ' ',
1399 case KeyEvent
.VK_F4
:
1400 keypress
= new TKeypress(true, TKeypress
.F4
, ' ',
1403 case KeyEvent
.VK_F5
:
1404 keypress
= new TKeypress(true, TKeypress
.F5
, ' ',
1407 case KeyEvent
.VK_F6
:
1408 keypress
= new TKeypress(true, TKeypress
.F6
, ' ',
1411 case KeyEvent
.VK_F7
:
1412 keypress
= new TKeypress(true, TKeypress
.F7
, ' ',
1415 case KeyEvent
.VK_F8
:
1416 keypress
= new TKeypress(true, TKeypress
.F8
, ' ',
1419 case KeyEvent
.VK_F9
:
1420 keypress
= new TKeypress(true, TKeypress
.F9
, ' ',
1423 case KeyEvent
.VK_F10
:
1424 keypress
= new TKeypress(true, TKeypress
.F10
, ' ',
1427 case KeyEvent
.VK_F11
:
1428 keypress
= new TKeypress(true, TKeypress
.F11
, ' ',
1431 case KeyEvent
.VK_F12
:
1432 keypress
= new TKeypress(true, TKeypress
.F12
, ' ',
1435 case KeyEvent
.VK_HOME
:
1436 keypress
= new TKeypress(true, TKeypress
.HOME
, ' ',
1439 case KeyEvent
.VK_END
:
1440 keypress
= new TKeypress(true, TKeypress
.END
, ' ',
1443 case KeyEvent
.VK_PAGE_UP
:
1444 keypress
= new TKeypress(true, TKeypress
.PGUP
, ' ',
1447 case KeyEvent
.VK_PAGE_DOWN
:
1448 keypress
= new TKeypress(true, TKeypress
.PGDN
, ' ',
1451 case KeyEvent
.VK_INSERT
:
1452 keypress
= new TKeypress(true, TKeypress
.INS
, ' ',
1455 case KeyEvent
.VK_DELETE
:
1456 keypress
= new TKeypress(true, TKeypress
.DEL
, ' ',
1459 case KeyEvent
.VK_RIGHT
:
1460 keypress
= new TKeypress(true, TKeypress
.RIGHT
, ' ',
1463 case KeyEvent
.VK_LEFT
:
1464 keypress
= new TKeypress(true, TKeypress
.LEFT
, ' ',
1467 case KeyEvent
.VK_UP
:
1468 keypress
= new TKeypress(true, TKeypress
.UP
, ' ',
1471 case KeyEvent
.VK_DOWN
:
1472 keypress
= new TKeypress(true, TKeypress
.DOWN
, ' ',
1475 case KeyEvent
.VK_TAB
:
1476 // Special case: distinguish TAB vs BTAB
1478 keypress
= kbShiftTab
;
1483 case KeyEvent
.VK_ENTER
:
1484 keypress
= new TKeypress(true, TKeypress
.ENTER
, ' ',
1487 case KeyEvent
.VK_ESCAPE
:
1488 keypress
= new TKeypress(true, TKeypress
.ESC
, ' ',
1491 case KeyEvent
.VK_BACK_SPACE
:
1492 // Special case: return it as kbBackspace (Ctrl-H)
1493 keypress
= new TKeypress(false, 0, 'H', false, true, false);
1496 // Unsupported, ignore
1501 if (keypress
== null) {
1504 keypress
= kbBackspace
;
1517 keypress
= kbShiftTab
;
1526 if (!alt
&& ctrl
&& !shift
) {
1527 ch
= KeyEvent
.getKeyText(key
.getKeyCode()).charAt(0);
1529 // Not a special key, put it together
1530 keypress
= new TKeypress(false, 0, ch
, alt
, ctrl
, shift
);
1534 // Save it and we are done.
1535 synchronized (eventQueue
) {
1536 eventQueue
.add(new TKeypressEvent(keypress
));
1539 if (listener
!= null) {
1540 synchronized (listener
) {
1541 listener
.notifyAll();
1547 * Pass window events into the event queue.
1549 * @param event window event received
1551 public void windowActivated(final WindowEvent event
) {
1552 // Force a total repaint
1553 synchronized (this) {
1559 * Pass window events into the event queue.
1561 * @param event window event received
1563 public void windowClosed(final WindowEvent event
) {
1568 * Pass window events into the event queue.
1570 * @param event window event received
1572 public void windowClosing(final WindowEvent event
) {
1573 // Drop a cmAbort and walk away
1574 synchronized (eventQueue
) {
1575 eventQueue
.add(new TCommandEvent(cmAbort
));
1578 if (listener
!= null) {
1579 synchronized (listener
) {
1580 listener
.notifyAll();
1586 * Pass window events into the event queue.
1588 * @param event window event received
1590 public void windowDeactivated(final WindowEvent event
) {
1595 * Pass window events into the event queue.
1597 * @param event window event received
1599 public void windowDeiconified(final WindowEvent event
) {
1604 * Pass window events into the event queue.
1606 * @param event window event received
1608 public void windowIconified(final WindowEvent event
) {
1613 * Pass window events into the event queue.
1615 * @param event window event received
1617 public void windowOpened(final WindowEvent event
) {
1622 * Pass component events into the event queue.
1624 * @param event component event received
1626 public void componentHidden(final ComponentEvent event
) {
1631 * Pass component events into the event queue.
1633 * @param event component event received
1635 public void componentShown(final ComponentEvent event
) {
1640 * Pass component events into the event queue.
1642 * @param event component event received
1644 public void componentMoved(final ComponentEvent event
) {
1649 * Pass component events into the event queue.
1651 * @param event component event received
1653 public void componentResized(final ComponentEvent event
) {
1654 if (gotFontDimensions
== false) {
1655 // We are still waiting to get font information. Don't pass a
1657 // System.err.println("size " + swing.getComponent().getSize());
1661 // Drop a new TResizeEvent into the queue
1662 sessionInfo
.queryWindowSize();
1663 synchronized (eventQueue
) {
1664 TResizeEvent windowResize
= new TResizeEvent(TResizeEvent
.Type
.SCREEN
,
1665 sessionInfo
.getWindowWidth(), sessionInfo
.getWindowHeight());
1666 eventQueue
.add(windowResize
);
1669 if (listener
!= null) {
1670 synchronized (listener
) {
1671 listener
.notifyAll();
1677 * Pass mouse events into the event queue.
1679 * @param mouse mouse event received
1681 public void mouseDragged(final MouseEvent mouse
) {
1682 int modifiers
= mouse
.getModifiersEx();
1683 boolean eventMouse1
= false;
1684 boolean eventMouse2
= false;
1685 boolean eventMouse3
= false;
1686 if ((modifiers
& MouseEvent
.BUTTON1_DOWN_MASK
) != 0) {
1689 if ((modifiers
& MouseEvent
.BUTTON2_DOWN_MASK
) != 0) {
1692 if ((modifiers
& MouseEvent
.BUTTON3_DOWN_MASK
) != 0) {
1695 mouse1
= eventMouse1
;
1696 mouse2
= eventMouse2
;
1697 mouse3
= eventMouse3
;
1698 int x
= textColumn(mouse
.getX());
1699 int y
= textRow(mouse
.getY());
1701 TMouseEvent mouseEvent
= new TMouseEvent(TMouseEvent
.Type
.MOUSE_MOTION
,
1702 x
, y
, x
, y
, mouse1
, mouse2
, mouse3
, false, false);
1704 synchronized (eventQueue
) {
1705 eventQueue
.add(mouseEvent
);
1708 if (listener
!= null) {
1709 synchronized (listener
) {
1710 listener
.notifyAll();
1716 * Pass mouse events into the event queue.
1718 * @param mouse mouse event received
1720 public void mouseMoved(final MouseEvent mouse
) {
1721 int x
= textColumn(mouse
.getX());
1722 int y
= textRow(mouse
.getY());
1723 if ((x
== oldMouseX
) && (y
== oldMouseY
)) {
1724 // Bail out, we've moved some pixels but not a whole text cell.
1730 TMouseEvent mouseEvent
= new TMouseEvent(TMouseEvent
.Type
.MOUSE_MOTION
,
1731 x
, y
, x
, y
, mouse1
, mouse2
, mouse3
, false, false);
1733 synchronized (eventQueue
) {
1734 eventQueue
.add(mouseEvent
);
1737 if (listener
!= null) {
1738 synchronized (listener
) {
1739 listener
.notifyAll();
1745 * Pass mouse events into the event queue.
1747 * @param mouse mouse event received
1749 public void mouseClicked(final MouseEvent mouse
) {
1754 * Pass mouse events into the event queue.
1756 * @param mouse mouse event received
1758 public void mouseEntered(final MouseEvent mouse
) {
1763 * Pass mouse events into the event queue.
1765 * @param mouse mouse event received
1767 public void mouseExited(final MouseEvent mouse
) {
1772 * Pass mouse events into the event queue.
1774 * @param mouse mouse event received
1776 public void mousePressed(final MouseEvent mouse
) {
1777 int modifiers
= mouse
.getModifiersEx();
1778 boolean eventMouse1
= false;
1779 boolean eventMouse2
= false;
1780 boolean eventMouse3
= false;
1781 if ((modifiers
& MouseEvent
.BUTTON1_DOWN_MASK
) != 0) {
1784 if ((modifiers
& MouseEvent
.BUTTON2_DOWN_MASK
) != 0) {
1787 if ((modifiers
& MouseEvent
.BUTTON3_DOWN_MASK
) != 0) {
1790 mouse1
= eventMouse1
;
1791 mouse2
= eventMouse2
;
1792 mouse3
= eventMouse3
;
1793 int x
= textColumn(mouse
.getX());
1794 int y
= textRow(mouse
.getY());
1796 TMouseEvent mouseEvent
= new TMouseEvent(TMouseEvent
.Type
.MOUSE_DOWN
,
1797 x
, y
, x
, y
, mouse1
, mouse2
, mouse3
, false, false);
1799 synchronized (eventQueue
) {
1800 eventQueue
.add(mouseEvent
);
1803 if (listener
!= null) {
1804 synchronized (listener
) {
1805 listener
.notifyAll();
1811 * Pass mouse events into the event queue.
1813 * @param mouse mouse event received
1815 public void mouseReleased(final MouseEvent mouse
) {
1816 int modifiers
= mouse
.getModifiersEx();
1817 boolean eventMouse1
= false;
1818 boolean eventMouse2
= false;
1819 boolean eventMouse3
= false;
1820 if ((modifiers
& MouseEvent
.BUTTON1_DOWN_MASK
) != 0) {
1823 if ((modifiers
& MouseEvent
.BUTTON2_DOWN_MASK
) != 0) {
1826 if ((modifiers
& MouseEvent
.BUTTON3_DOWN_MASK
) != 0) {
1841 int x
= textColumn(mouse
.getX());
1842 int y
= textRow(mouse
.getY());
1844 TMouseEvent mouseEvent
= new TMouseEvent(TMouseEvent
.Type
.MOUSE_UP
,
1845 x
, y
, x
, y
, eventMouse1
, eventMouse2
, eventMouse3
, false, false);
1847 synchronized (eventQueue
) {
1848 eventQueue
.add(mouseEvent
);
1851 if (listener
!= null) {
1852 synchronized (listener
) {
1853 listener
.notifyAll();
1859 * Pass mouse events into the event queue.
1861 * @param mouse mouse event received
1863 public void mouseWheelMoved(final MouseWheelEvent mouse
) {
1864 int modifiers
= mouse
.getModifiersEx();
1865 boolean eventMouse1
= false;
1866 boolean eventMouse2
= false;
1867 boolean eventMouse3
= false;
1868 boolean mouseWheelUp
= false;
1869 boolean mouseWheelDown
= false;
1870 if ((modifiers
& MouseEvent
.BUTTON1_DOWN_MASK
) != 0) {
1873 if ((modifiers
& MouseEvent
.BUTTON2_DOWN_MASK
) != 0) {
1876 if ((modifiers
& MouseEvent
.BUTTON3_DOWN_MASK
) != 0) {
1879 mouse1
= eventMouse1
;
1880 mouse2
= eventMouse2
;
1881 mouse3
= eventMouse3
;
1882 int x
= textColumn(mouse
.getX());
1883 int y
= textRow(mouse
.getY());
1884 if (mouse
.getWheelRotation() > 0) {
1885 mouseWheelDown
= true;
1887 if (mouse
.getWheelRotation() < 0) {
1888 mouseWheelUp
= true;
1891 TMouseEvent mouseEvent
= new TMouseEvent(TMouseEvent
.Type
.MOUSE_DOWN
,
1892 x
, y
, x
, y
, mouse1
, mouse2
, mouse3
, mouseWheelUp
, mouseWheelDown
);
1894 synchronized (eventQueue
) {
1895 eventQueue
.add(mouseEvent
);
1898 if (listener
!= null) {
1899 synchronized (listener
) {
1900 listener
.notifyAll();