X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcom%2Fgooglecode%2Flanterna%2Fterminal%2Fswing%2FSwingTerminalImplementation.java;fp=src%2Fcom%2Fgooglecode%2Flanterna%2Fterminal%2Fswing%2FSwingTerminalImplementation.java;h=0000000000000000000000000000000000000000;hb=f06c81000632cfb5f525ca458f719338f55f9f66;hp=06f1fcfe90b7511f07aca3b2cc2ca08ab084438e;hpb=a73a906356c971b080c36368e71a15d87e8b8d31;p=jvcard.git diff --git a/src/com/googlecode/lanterna/terminal/swing/SwingTerminalImplementation.java b/src/com/googlecode/lanterna/terminal/swing/SwingTerminalImplementation.java deleted file mode 100644 index 06f1fcf..0000000 --- a/src/com/googlecode/lanterna/terminal/swing/SwingTerminalImplementation.java +++ /dev/null @@ -1,138 +0,0 @@ -package com.googlecode.lanterna.terminal.swing; - -import com.googlecode.lanterna.TerminalSize; -import com.googlecode.lanterna.TextCharacter; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.HierarchyEvent; -import java.awt.event.HierarchyListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.io.IOException; -import java.util.Collections; - -/** - * Concrete implementation of {@link GraphicalTerminalImplementation} that adapts it to Swing - */ -class SwingTerminalImplementation extends GraphicalTerminalImplementation { - - private final JComponent component; - private final SwingTerminalFontConfiguration fontConfiguration; - - /** - * Creates a new {@code SwingTerminalImplementation} - * @param component JComponent that is the Swing 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 - */ - SwingTerminalImplementation( - JComponent component, - SwingTerminalFontConfiguration 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()); - - //Make sure the component is double-buffered to prevent flickering - component.setDoubleBuffered(true); - - component.addKeyListener(new TerminalInputListener()); - component.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - SwingTerminalImplementation.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 SwingTerminal's current font configuration - */ - public SwingTerminalFontConfiguration 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(SwingUtilities.isEventDispatchThread()) { - component.repaint(); - } - else { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - component.repaint(); - } - }); - } - } - - @Override - public com.googlecode.lanterna.input.KeyStroke readInput() throws IOException { - if(SwingUtilities.isEventDispatchThread()) { - throw new UnsupportedOperationException("Cannot call SwingTerminal.readInput() on the AWT thread"); - } - return super.readInput(); - } -}