X-Git-Url: http://git.nikiroo.be/?p=jvcard.git;a=blobdiff_plain;f=src%2Fcom%2Fgooglecode%2Flanterna%2Fterminal%2Fswing%2FAWTTerminalImplementation.java;fp=src%2Fcom%2Fgooglecode%2Flanterna%2Fterminal%2Fswing%2FAWTTerminalImplementation.java;h=0000000000000000000000000000000000000000;hp=7cef34873c814e0c66372942c01ee33c6e9edd23;hb=f06c81000632cfb5f525ca458f719338f55f9f66;hpb=a73a906356c971b080c36368e71a15d87e8b8d31 diff --git a/src/com/googlecode/lanterna/terminal/swing/AWTTerminalImplementation.java b/src/com/googlecode/lanterna/terminal/swing/AWTTerminalImplementation.java deleted file mode 100644 index 7cef348..0000000 --- a/src/com/googlecode/lanterna/terminal/swing/AWTTerminalImplementation.java +++ /dev/null @@ -1,133 +0,0 @@ -package com.googlecode.lanterna.terminal.swing; - -import com.googlecode.lanterna.TerminalSize; -import com.googlecode.lanterna.TextCharacter; -import com.googlecode.lanterna.input.KeyStroke; - -import java.awt.*; -import java.awt.event.*; -import java.io.IOException; -import java.util.Collections; - -/** - * AWT implementation of {@link GraphicalTerminalImplementation} that contains all the overrides for AWT - * Created by martin on 08/02/16. - */ -class AWTTerminalImplementation extends GraphicalTerminalImplementation { - private final Component component; - private final AWTTerminalFontConfiguration fontConfiguration; - - /** - * Creates a new {@code AWTTerminalImplementation} - * @param component Component that is the AWT terminal surface - * @param fontConfiguration Font configuration to use - * @param initialTerminalSize Initial size of the terminal - * @param deviceConfiguration Device configuration - * @param colorConfiguration Color configuration - * @param scrollController Controller to be used when inspecting scroll status - */ - AWTTerminalImplementation( - Component component, - AWTTerminalFontConfiguration fontConfiguration, - TerminalSize initialTerminalSize, - TerminalEmulatorDeviceConfiguration deviceConfiguration, - TerminalEmulatorColorConfiguration colorConfiguration, - TerminalScrollController scrollController) { - - super(initialTerminalSize, deviceConfiguration, colorConfiguration, scrollController); - this.component = component; - this.fontConfiguration = fontConfiguration; - - //Prevent us from shrinking beyond one character - component.setMinimumSize(new Dimension(fontConfiguration.getFontWidth(), fontConfiguration.getFontHeight())); - - //noinspection unchecked - component.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.emptySet()); - //noinspection unchecked - component.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.emptySet()); - - component.addKeyListener(new TerminalInputListener()); - component.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - AWTTerminalImplementation.this.component.requestFocusInWindow(); - } - }); - - component.addHierarchyListener(new HierarchyListener() { - @Override - public void hierarchyChanged(HierarchyEvent e) { - if(e.getChangeFlags() == HierarchyEvent.DISPLAYABILITY_CHANGED) { - if(e.getChanged().isDisplayable()) { - startBlinkTimer(); - } - else { - stopBlinkTimer(); - } - } - } - }); - } - - - /** - * Returns the current font configuration. Note that it is immutable and cannot be changed. - * @return This {@link AWTTerminal}'s current font configuration - */ - public AWTTerminalFontConfiguration getFontConfiguration() { - return fontConfiguration; - } - - @Override - protected int getFontHeight() { - return fontConfiguration.getFontHeight(); - } - - @Override - protected int getFontWidth() { - return fontConfiguration.getFontWidth(); - } - - @Override - protected int getHeight() { - return component.getHeight(); - } - - @Override - protected int getWidth() { - return component.getWidth(); - } - - @Override - protected Font getFontForCharacter(TextCharacter character) { - return fontConfiguration.getFontForCharacter(character); - } - - @Override - protected boolean isTextAntiAliased() { - return fontConfiguration.isAntiAliased(); - } - - @Override - protected void repaint() { - if(EventQueue.isDispatchThread()) { - component.repaint(); - } - else { - EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - component.repaint(); - } - }); - } - } - - @Override - public KeyStroke readInput() throws IOException { - if(EventQueue.isDispatchThread()) { - throw new UnsupportedOperationException("Cannot call SwingTerminal.readInput() on the AWT thread"); - } - return super.readInput(); - } -}