コード例 #1
0
  /**
   * 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.<AWTKeyStroke>emptySet());
    //noinspection unchecked
    component.setFocusTraversalKeys(
        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.<AWTKeyStroke>emptySet());

    // Make sure the component is double-buffered to prevent flickering
    component.setDoubleBuffered(true);

    component.addKeyListener(new TerminalInputListener());
    component.addMouseListener(
        new TerminalMouseListener() {
          @Override
          public void mouseClicked(MouseEvent e) {
            super.mouseClicked(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()) {
                onCreated();
              } else {
                onDestroyed();
              }
            }
          }
        });
  }
コード例 #2
0
 @Override
 protected boolean isTextAntiAliased() {
   return fontConfiguration.isAntiAliased();
 }
コード例 #3
0
 @Override
 protected int getFontWidth() {
   return fontConfiguration.getFontWidth();
 }
コード例 #4
0
 @Override
 protected Font getFontForCharacter(TextCharacter character) {
   return fontConfiguration.getFontForCharacter(character);
 }
コード例 #5
0
 @Override
 protected int getFontHeight() {
   return fontConfiguration.getFontHeight();
 }