1 package com
.googlecode
.lanterna
.terminal
.swing
;
3 import com
.googlecode
.lanterna
.TerminalSize
;
4 import com
.googlecode
.lanterna
.TextCharacter
;
5 import com
.googlecode
.lanterna
.input
.KeyStroke
;
8 import java
.awt
.event
.*;
9 import java
.io
.IOException
;
10 import java
.util
.Collections
;
13 * AWT implementation of {@link GraphicalTerminalImplementation} that contains all the overrides for AWT
14 * Created by martin on 08/02/16.
16 class AWTTerminalImplementation
extends GraphicalTerminalImplementation
{
17 private final Component component
;
18 private final AWTTerminalFontConfiguration fontConfiguration
;
21 * Creates a new {@code AWTTerminalImplementation}
22 * @param component Component that is the AWT terminal surface
23 * @param fontConfiguration Font configuration to use
24 * @param initialTerminalSize Initial size of the terminal
25 * @param deviceConfiguration Device configuration
26 * @param colorConfiguration Color configuration
27 * @param scrollController Controller to be used when inspecting scroll status
29 AWTTerminalImplementation(
31 AWTTerminalFontConfiguration fontConfiguration
,
32 TerminalSize initialTerminalSize
,
33 TerminalEmulatorDeviceConfiguration deviceConfiguration
,
34 TerminalEmulatorColorConfiguration colorConfiguration
,
35 TerminalScrollController scrollController
) {
37 super(initialTerminalSize
, deviceConfiguration
, colorConfiguration
, scrollController
);
38 this.component
= component
;
39 this.fontConfiguration
= fontConfiguration
;
41 //Prevent us from shrinking beyond one character
42 component
.setMinimumSize(new Dimension(fontConfiguration
.getFontWidth(), fontConfiguration
.getFontHeight()));
44 //noinspection unchecked
45 component
.setFocusTraversalKeys(KeyboardFocusManager
.FORWARD_TRAVERSAL_KEYS
, Collections
.<AWTKeyStroke
>emptySet());
46 //noinspection unchecked
47 component
.setFocusTraversalKeys(KeyboardFocusManager
.BACKWARD_TRAVERSAL_KEYS
, Collections
.<AWTKeyStroke
>emptySet());
49 component
.addKeyListener(new TerminalInputListener());
50 component
.addMouseListener(new MouseAdapter() {
52 public void mouseClicked(MouseEvent e
) {
53 AWTTerminalImplementation
.this.component
.requestFocusInWindow();
57 component
.addHierarchyListener(new HierarchyListener() {
59 public void hierarchyChanged(HierarchyEvent e
) {
60 if(e
.getChangeFlags() == HierarchyEvent
.DISPLAYABILITY_CHANGED
) {
61 if(e
.getChanged().isDisplayable()) {
74 * Returns the current font configuration. Note that it is immutable and cannot be changed.
75 * @return This {@link AWTTerminal}'s current font configuration
77 public AWTTerminalFontConfiguration
getFontConfiguration() {
78 return fontConfiguration
;
82 protected int getFontHeight() {
83 return fontConfiguration
.getFontHeight();
87 protected int getFontWidth() {
88 return fontConfiguration
.getFontWidth();
92 protected int getHeight() {
93 return component
.getHeight();
97 protected int getWidth() {
98 return component
.getWidth();
102 protected Font
getFontForCharacter(TextCharacter character
) {
103 return fontConfiguration
.getFontForCharacter(character
);
107 protected boolean isTextAntiAliased() {
108 return fontConfiguration
.isAntiAliased();
112 protected void repaint() {
113 if(EventQueue
.isDispatchThread()) {
117 EventQueue
.invokeLater(new Runnable() {
127 public KeyStroke
readInput() throws IOException
{
128 if(EventQueue
.isDispatchThread()) {
129 throw new UnsupportedOperationException("Cannot call SwingTerminal.readInput() on the AWT thread");
131 return super.readInput();