public RendererComponent(
     Project project, @Nullable FileType fileType, boolean inheritFontFromLaF) {
   Pair<EditorTextField, EditorEx> pair = createEditor(project, fileType, inheritFontFromLaF);
   myTextField = pair.first;
   myEditor = pair.second;
   add(myEditor.getContentComponent());
 }
  public void onContentChangedIn(EditorSource source) {
    myDiffUpdater.contentRemoved(source);
    final EditorEx editor = source.getEditor();
    if (myIsHorizontal && source.getSide() == FragmentSide.SIDE1 && editor != null) {
      editor.setVerticalScrollbarOrientation(EditorEx.VERTICAL_SCROLLBAR_LEFT);
    }
    DiffSideView viewSide = getSideView(source.getSide());
    viewSide.setEditorSource(getProject(), source);
    Disposer.dispose(myScrollSupport);
    if (editor == null) {
      if (!myDisposed) {
        rediff();
      }
      return;
    }

    final MouseListener mouseListener =
        PopupHandler.installUnknownPopupHandler(
            editor.getContentComponent(),
            new MergeActionGroup(this, source.getSide()),
            ActionManager.getInstance());
    myDiffUpdater.contentAdded(source);
    editor.getSettings().setLineNumbersShown(true);
    editor.getSettings().setFoldingOutlineShown(false);
    editor.getFoldingModel().setFoldingEnabled(false);
    ((EditorMarkupModel) editor.getMarkupModel()).setErrorStripeVisible(true);

    Editor editor1 = getEditor(FragmentSide.SIDE1);
    Editor editor2 = getEditor(FragmentSide.SIDE2);
    if (editor1 != null && editor2 != null && myIsSyncScroll) {
      myScrollSupport.install(new EditingSides[] {this});
    }

    final VisibleAreaListener visibleAreaListener = mySplitter.getVisibleAreaListener();
    final ScrollingModel scrollingModel = editor.getScrollingModel();
    if (visibleAreaListener != null) {
      scrollingModel.addVisibleAreaListener(visibleAreaListener);
      scrollingModel.addVisibleAreaListener(myVisibleAreaListener);
    }
    myFontSizeSynchronizer.synchronize(editor);
    source.addDisposable(
        new Disposable() {
          public void dispose() {
            myFontSizeSynchronizer.stopSynchronize(editor);
          }
        });
    source.addDisposable(
        new Disposable() {
          public void dispose() {
            if (visibleAreaListener != null) {
              scrollingModel.removeVisibleAreaListener(visibleAreaListener);
              scrollingModel.removeVisibleAreaListener(myVisibleAreaListener);
            }
            editor.getContentComponent().removeMouseListener(mouseListener);
          }
        });
  }
  private static void setupEditorDefault(EditorEx editor) {
    ConsoleViewUtil.setupConsoleEditor(editor, false, false);
    editor.getContentComponent().setFocusCycleRoot(false);
    editor.setHorizontalScrollbarVisible(false);
    editor.setVerticalScrollbarVisible(true);
    editor.setBorder(null);

    final EditorSettings editorSettings = editor.getSettings();
    editorSettings.setAdditionalLinesCount(0);
    editorSettings.setAdditionalColumnsCount(1);
    editorSettings.setRightMarginShown(false);
  }
  private EditorFragmentComponent(
      EditorEx editor, int startLine, int endLine, boolean showFolding, boolean showGutter) {
    Document doc = editor.getDocument();
    final int endOffset =
        endLine < doc.getLineCount() ? doc.getLineEndOffset(endLine) : doc.getTextLength();
    int textWidth =
        Math.min(
            editor.getMaxWidthInRange(doc.getLineStartOffset(startLine), endOffset),
            ScreenUtil.getScreenRectangle(1, 1).width);
    LOG.assertTrue(
        textWidth > 0,
        "TextWidth: " + textWidth + "; startLine:" + startLine + "; endLine:" + endLine + ";");

    FoldingModelEx foldingModel = editor.getFoldingModel();
    boolean isFoldingEnabled = foldingModel.isFoldingEnabled();
    if (!showFolding) {
      foldingModel.setFoldingEnabled(false);
    }

    Point p1 = editor.logicalPositionToXY(new LogicalPosition(startLine, 0));
    Point p2 = editor.logicalPositionToXY(new LogicalPosition(Math.max(endLine, startLine + 1), 0));
    int y1 = p1.y;
    int y2 = p2.y;
    int height = y2 - y1 == 0 ? editor.getLineHeight() : y2 - y1;
    LOG.assertTrue(
        height > 0,
        "Height: "
            + height
            + "; startLine:"
            + startLine
            + "; endLine:"
            + endLine
            + "; p1:"
            + p1
            + "; p2:"
            + p2);

    int savedScrollOffset = editor.getScrollingModel().getHorizontalScrollOffset();
    if (savedScrollOffset > 0) {
      editor.stopOptimizedScrolling();
      editor.getScrollingModel().scrollHorizontally(0);
    }

    final Image textImage = new BufferedImage(textWidth, height, BufferedImage.TYPE_INT_RGB);
    Graphics textGraphics = textImage.getGraphics();

    final JComponent rowHeader;
    final Image markersImage;
    if (showGutter) {
      rowHeader = editor.getGutterComponentEx();
      markersImage =
          new BufferedImage(Math.max(1, rowHeader.getWidth()), height, BufferedImage.TYPE_INT_RGB);
      Graphics markerGraphics = markersImage.getGraphics();

      markerGraphics.translate(0, -y1);
      markerGraphics.setClip(0, y1, rowHeader.getWidth(), height);
      markerGraphics.setColor(getBackgroundColor(editor));
      markerGraphics.fillRect(0, y1, rowHeader.getWidth(), height);
      rowHeader.paint(markerGraphics);
    } else {
      rowHeader = null;
      markersImage = null;
    }

    textGraphics.translate(0, -y1);
    textGraphics.setClip(0, y1, textWidth, height);
    final boolean wasVisible = editor.setCaretVisible(false);
    editor.setPurePaintingMode(true);
    try {
      editor.getContentComponent().paint(textGraphics);
    } finally {
      editor.setPurePaintingMode(false);
    }
    if (wasVisible) {
      editor.setCaretVisible(true);
    }

    if (!showFolding) {
      foldingModel.setFoldingEnabled(isFoldingEnabled);
    }

    if (savedScrollOffset > 0) {
      editor.stopOptimizedScrolling();
      editor.getScrollingModel().scrollHorizontally(savedScrollOffset);
    }

    JComponent component =
        new JComponent() {
          public Dimension getPreferredSize() {
            return new Dimension(
                textImage.getWidth(null) + (markersImage == null ? 0 : markersImage.getWidth(null)),
                textImage.getHeight(null));
          }

          protected void paintComponent(Graphics graphics) {
            if (markersImage != null) {
              graphics.drawImage(markersImage, 0, 0, null);
              graphics.drawImage(textImage, rowHeader.getWidth(), 0, null);
            } else {
              graphics.drawImage(textImage, 0, 0, null);
            }
          }
        };

    setLayout(new BorderLayout());
    add(component);

    final Color borderColor =
        editor.getColorsScheme().getColor(EditorColors.SELECTED_TEARLINE_COLOR);

    Border outsideBorder = BorderFactory.createLineBorder(borderColor, 1);
    Border insideBorder = BorderFactory.createEmptyBorder(2, 2, 2, 2);
    setBorder(BorderFactory.createCompoundBorder(outsideBorder, insideBorder));
  }
  private void setupComponents() {
    setupEditorDefault(myConsoleEditor);
    setupEditorDefault(myHistoryViewer);
    myConsoleEditor.addEditorMouseListener(
        EditorActionUtil.createEditorPopupHandler(IdeActions.GROUP_CONSOLE_EDITOR_POPUP));
    //noinspection PointlessBooleanExpression,ConstantConditions
    if (SEPARATOR_THICKNESS > 0 && myShowSeparatorLine) {
      myHistoryViewer
          .getComponent()
          .setBorder(new SideBorder(JBColor.LIGHT_GRAY, SideBorder.BOTTOM));
    }
    myHistoryViewer.getComponent().setMinimumSize(new Dimension(0, 0));
    myHistoryViewer.getComponent().setPreferredSize(new Dimension(0, 0));
    myConsoleEditor.getSettings().setAdditionalLinesCount(2);
    myConsoleEditor.setHighlighter(
        EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, myVirtualFile));
    myHistoryViewer.setCaretEnabled(false);
    myConsoleEditor.setHorizontalScrollbarVisible(true);
    final VisibleAreaListener areaListener =
        new VisibleAreaListener() {
          public void visibleAreaChanged(VisibleAreaEvent e) {
            final int offset = myConsoleEditor.getScrollingModel().getHorizontalScrollOffset();
            final ScrollingModel model = myHistoryViewer.getScrollingModel();
            final int historyOffset = model.getHorizontalScrollOffset();
            if (historyOffset != offset) {
              try {
                model.disableAnimation();
                model.scrollHorizontally(offset);
              } finally {
                model.enableAnimation();
              }
            }
          }
        };
    myConsoleEditor.getScrollingModel().addVisibleAreaListener(areaListener);
    final DocumentAdapter docListener =
        new DocumentAdapter() {
          @Override
          public void documentChanged(final DocumentEvent e) {
            queueUiUpdate(false);
          }
        };
    myEditorDocument.addDocumentListener(docListener, this);
    myHistoryViewer.getDocument().addDocumentListener(docListener, this);

    myHistoryViewer
        .getContentComponent()
        .addKeyListener(
            new KeyAdapter() {
              public void keyTyped(KeyEvent event) {
                if (isConsoleEditorEnabled() && UIUtil.isReallyTypedEvent(event)) {
                  myConsoleEditor.getContentComponent().requestFocus();
                  myConsoleEditor.processKeyTyped(event);
                }
              }
            });
    for (AnAction action : createActions()) {
      action.registerCustomShortcutSet(action.getShortcutSet(), myConsoleEditor.getComponent());
    }
    EmptyAction.registerActionShortcuts(
        myHistoryViewer.getComponent(), myConsoleEditor.getComponent());
  }
 @Override
 public void dispose() {
   remove(myEditor.getContentComponent());
   myTextField.removeNotify();
 }