Java Code Examples for com.intellij.openapi.editor.Editor#getComponent()

The following examples show how to use com.intellij.openapi.editor.Editor#getComponent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditorFragmentComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static int getAvailableVisualLinesAboveEditor(@Nonnull Editor editor) {
  int availableVisualLines = 2;
  JComponent editorComponent = editor.getComponent();
  Container editorComponentParent = editorComponent.getParent();
  if (editorComponentParent != null) {
    JRootPane rootPane = editorComponent.getRootPane();
    if (rootPane != null) {
      Container contentPane = rootPane.getContentPane();
      if (contentPane != null) {
        int y = SwingUtilities.convertPoint(editorComponentParent, editorComponent.getLocation(), contentPane).y;
        int visualLines = y / editor.getLineHeight();
        availableVisualLines = Math.max(availableVisualLines, visualLines);
      }
    }
  }
  return availableVisualLines;
}
 
Example 2
Source File: CoverageLineMarkerRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected JComponent createActionsToolbar(final Editor editor, final int lineNumber) {

    final JComponent editorComponent = editor.getComponent();

    final DefaultActionGroup group = new DefaultActionGroup();
    final GotoPreviousCoveredLineAction prevAction = new GotoPreviousCoveredLineAction(editor, lineNumber);
    final GotoNextCoveredLineAction nextAction = new GotoNextCoveredLineAction(editor, lineNumber);

    group.add(prevAction);
    group.add(nextAction);

    prevAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.ALT_MASK|InputEvent.SHIFT_MASK)), editorComponent);
    nextAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.ALT_MASK|InputEvent.SHIFT_MASK)), editorComponent);

    final LineData lineData = getLineData(lineNumber);
    if (myCoverageByTestApplicable) {
      group.add(new ShowCoveringTestsAction(myClassName, lineData));
    }
    final AnAction byteCodeViewAction = ActionManager.getInstance().getAction("ByteCodeViewer");
    if (byteCodeViewAction != null) {
      group.add(byteCodeViewAction);
    }
    group.add(new EditCoverageColorsAction(editor, lineNumber));
    group.add(new HideCoverageInfoAction());

    final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.FILEHISTORY_VIEW_TOOLBAR, group, true);
    final JComponent toolbarComponent = toolbar.getComponent();

    final Color background = ((EditorEx)editor).getBackgroundColor();
    final Color foreground = editor.getColorsScheme().getColor(EditorColors.CARET_COLOR);
    toolbarComponent.setBackground(background);
    toolbarComponent.setBorder(new ColoredSideBorder(foreground, foreground, lineData == null || lineData.getStatus() == LineCoverage.NONE || mySubCoverageActive ? foreground : null, foreground, 1));
    toolbar.updateActionsImmediately();
    return toolbarComponent;
  }
 
Example 3
Source File: EditorFragmentComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static int getWidthLimit(@Nonnull Editor editor) {
  Component component = editor.getComponent();
  int screenWidth = ScreenUtil.getScreenRectangle(component).width;
  if (screenWidth > 0) return screenWidth;
  Window window = SwingUtilities.getWindowAncestor(component);
  return window == null ? Integer.MAX_VALUE : window.getWidth();
}
 
Example 4
Source File: LineTooltipRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void correctLocation(Editor editor, JComponent tooltipComponent, Point p, boolean alignToRight, boolean expanded, int currentWidth) {
  final JComponent editorComponent = editor.getComponent();
  final JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();

  int widthLimit = layeredPane.getWidth() - 10;
  int heightLimit = layeredPane.getHeight() - 5;

  Dimension dimension = correctLocation(editor, p, alignToRight, expanded, tooltipComponent, layeredPane, widthLimit, heightLimit, currentWidth);

  // in order to restrict tooltip size
  tooltipComponent.setSize(dimension);
  tooltipComponent.setMaximumSize(dimension);
  tooltipComponent.setMinimumSize(dimension);
  tooltipComponent.setPreferredSize(dimension);
}
 
Example 5
Source File: HintManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static JComponent getExternalComponent(@Nonnull Editor editor) {
  JComponent externalComponent = editor.getComponent();
  JRootPane rootPane = externalComponent.getRootPane();
  if (rootPane == null) return externalComponent;
  JLayeredPane layeredPane = rootPane.getLayeredPane();
  return layeredPane != null ? layeredPane : rootPane;
}
 
Example 6
Source File: ParameterInfoComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
ParameterInfoComponent(Object[] objects, Editor editor, @Nonnull ParameterInfoHandler handler, boolean requestFocus, boolean allowSwitchLabel) {
  super(new BorderLayout());
  myRequestFocus = requestFocus;

  if (!ApplicationManager.getApplication().isUnitTestMode() && !ApplicationManager.getApplication().isHeadlessEnvironment()) {
    JComponent editorComponent = editor.getComponent();
    JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();
    myWidthLimit = layeredPane.getWidth();
  }

  NORMAL_FONT = editor != null && Registry.is("parameter.info.editor.font") ? editor.getColorsScheme().getFont(EditorFontType.PLAIN) : UIUtil.getLabelFont();
  BOLD_FONT = editor != null && Registry.is("parameter.info.editor.font") ? editor.getColorsScheme().getFont(EditorFontType.BOLD) : NORMAL_FONT.deriveFont(Font.BOLD);

  myObjects = objects;

  setBackground(BACKGROUND);

  myHandler = handler;
  myMainPanel = new JPanel(new GridBagLayout());
  setPanels();

  if (myRequestFocus) {
    AccessibleContextUtil.setName(this, "Parameter Info. Press TAB to navigate through each element. Press ESC to close.");
  }

  final JScrollPane pane = ScrollPaneFactory.createScrollPane(myMainPanel, true);
  add(pane, BorderLayout.CENTER);

  myAllowSwitchLabel = allowSwitchLabel && !(editor instanceof EditorWindow);
  setShortcutLabel();
  myCurrentParameterIndex = -1;
}
 
Example 7
Source File: PropertyEditorPanel.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
PropertyBalloonPositionTrackerScreenshot(Editor editor, Point point) {
  super(editor.getComponent());
  myEditor = editor;
  this.point = point;
}
 
Example 8
Source File: PropertyEditorPanel.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
PropertyBalloonPositionTrackerScreenshot(Editor editor, Point point) {
  super(editor.getComponent());
  myEditor = editor;
  this.point = point;
}
 
Example 9
Source File: MainWindowBase.java    From KodeBeagle with Apache License 2.0 4 votes vote down vote up
@Override
public final void createToolWindowContent(final Project project, final ToolWindow toolWindow) {

    initSystemInfo();
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(PROJECTS);
    JTree jTree = new Tree(root);
    jTree.setRootVisible(false);
    jTree.setAutoscrolls(true);

    if (!propertiesComponent.isValueSet(Identity.BEAGLE_ID)) {
        windowObjects.setBeagleId(UUID.randomUUID().toString());
        propertiesComponent.setValue(Identity.BEAGLE_ID,
                windowObjects.getBeagleId());
    } else {
        windowObjects.setBeagleId(propertiesComponent.getValue(Identity.BEAGLE_ID));
    }

    Document document = new DocumentImpl("", true, false);
    Editor windowEditor =
            EditorFactory.getInstance().createEditor(
                    document, project, FileTypeManager.getInstance()
                            .getFileTypeByExtension(JAVA),
                    false);
    //Dispose the editor once it's no longer needed
    windowEditorOps.releaseEditor(project, windowEditor);
    windowObjects.setTree(jTree);
    windowObjects.setWindowEditor(windowEditor);

    final JComponent toolBar = setUpToolBar();

    JBScrollPane jTreeScrollPane = new JBScrollPane();
    jTreeScrollPane.getViewport().setBackground(JBColor.white);
    jTreeScrollPane.setAutoscrolls(true);
    jTreeScrollPane.setBackground(JBColor.white);
    windowObjects.setJTreeScrollPane(jTreeScrollPane);

    final JSplitPane jSplitPane = new JSplitPane(
            JSplitPane.VERTICAL_SPLIT, jTreeScrollPane, windowEditor.getComponent());
    jSplitPane.setResizeWeight(DIVIDER_LOCATION);

    JPanel editorPanel = new JPanel();
    editorPanel.setOpaque(true);
    editorPanel.setBackground(JBColor.white);
    editorPanel.setLayout(new BoxLayout(editorPanel, BoxLayout.Y_AXIS));

    final JBScrollPane editorScrollPane = new JBScrollPane();
    editorScrollPane.getViewport().setBackground(JBColor.white);
    editorScrollPane.setViewportView(editorPanel);
    editorScrollPane.setPreferredSize(new Dimension(EDITOR_SCROLL_PANE_WIDTH,
            EDITOR_SCROLL_PANE_HEIGHT));
    editorScrollPane.getVerticalScrollBar().setUnitIncrement(UNIT_INCREMENT);
    editorScrollPane.setHorizontalScrollBarPolicy(JBScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

    windowObjects.setPanel(editorPanel);

    final JTabbedPane jTabbedPane = new JBTabbedPane();
    jTabbedPane.add(SPOTLIGHT_TAB, editorScrollPane);
    jTabbedPane.add(ALL_TAB, jSplitPane);
    windowObjects.setjTabbedPane(jTabbedPane);
    final Editor projectEditor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    // Display initial help information here.
    if (projectEditor != null) {
        uiUtils.showHelpInfo(RefreshActionBase.HELP_MESSAGE_NO_SELECTED_CODE);
    } else {
        uiUtils.showHelpInfo(RefreshActionBase.EDITOR_ERROR);
    }
    final JPanel mainPanel = new JPanel();
    mainPanel.setLayout((new BoxLayout(mainPanel, BoxLayout.Y_AXIS)));
    mainPanel.add(toolBar);
    mainPanel.add(jTabbedPane);

    if (!LegalNotice.isLegalNoticeAccepted()) {
        new LegalNotice(project).showLegalNotice();
    }
    toolWindow.getComponent().getParent().add(mainPanel);
}