Java Code Examples for java.awt.event.InputEvent#getComponent()

The following examples show how to use java.awt.event.InputEvent#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: InsertFigureInteractorInterceptor.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private ProductSceneView getProductSceneView(InputEvent event) {
    ProductSceneView productSceneView = null;
    Component component = event.getComponent();
    while (component != null) {
        if (component instanceof ProductSceneView) {
            productSceneView = (ProductSceneView) component;
            break;
        }
        component = component.getParent();
    }
    return productSceneView;
}
 
Example 2
Source File: GotoDeclarationAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void update(final AnActionEvent event) {
  InputEvent inputEvent = event.getInputEvent();
  if (inputEvent instanceof MouseEvent) {
    Component component = inputEvent.getComponent();
    if (component != null) {
      Point point = ((MouseEvent)inputEvent).getPoint();
      Component componentAt = SwingUtilities.getDeepestComponentAt(component, point.x, point.y);
      if (componentAt instanceof EditorGutterComponentEx) {
        event.getPresentation().setEnabled(false);
        return;
      }
    }
  }

  for (GotoDeclarationHandler handler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {
    try {
      String text = handler.getActionText(event.getDataContext());
      if (text != null) {
        Presentation presentation = event.getPresentation();
        presentation.setText(text);
        break;
      }
    }
    catch (AbstractMethodError e) {
      LOG.error(handler.toString(), e);
    }
  }

  super.update(event);
}
 
Example 3
Source File: OpenInEditorWithMouseAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void update(@Nonnull AnActionEvent e) {
  InputEvent inputEvent = e.getInputEvent();
  if (!(inputEvent instanceof MouseEvent)) {
    e.getPresentation().setEnabledAndVisible(false);
    return;
  }

  if (e.getProject() == null) {
    e.getPresentation().setEnabledAndVisible(false);
    return;
  }

  if (e.getData(OpenInEditorAction.KEY) == null) {
    e.getPresentation().setEnabledAndVisible(false);
    return;
  }

  Component component = inputEvent.getComponent();
  if (component == null) {
    e.getPresentation().setEnabledAndVisible(false);
    return;
  }

  Point point = ((MouseEvent)inputEvent).getPoint();
  Component componentAt = SwingUtilities.getDeepestComponentAt(component, point.x, point.y);
  if (!(componentAt instanceof EditorGutterComponentEx)) {
    e.getPresentation().setEnabledAndVisible(false);
    return;
  }

  Editor editor = getEditor(componentAt);
  if (editor == null) {
    e.getPresentation().setEnabledAndVisible(false);
    return;
  }

  MouseEvent convertedEvent = SwingUtilities.convertMouseEvent(inputEvent.getComponent(), (MouseEvent)inputEvent, componentAt);
  EditorMouseEventArea area = editor.getMouseEventArea(convertedEvent);
  if (area != EditorMouseEventArea.LINE_NUMBERS_AREA) {
    e.getPresentation().setEnabledAndVisible(false);
    return;
  }

  e.getPresentation().setEnabledAndVisible(true);
}