Java Code Examples for consulo.awt.TargetAWT#from()

The following examples show how to use consulo.awt.TargetAWT#from() . 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: IdeFocusManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
static IdeFocusManager findByComponent(Component c) {
  final Component parent = UIUtil.findUltimateParent(c);
  if (parent instanceof Window) {
    consulo.ui.Window uiWindow = TargetAWT.from((Window)parent);

    IdeFrame ideFrame = uiWindow.getUserData(IdeFrame.KEY);
    if (ideFrame == null) {
      return null;
    }
    return getInstanceSafe(ideFrame.getProject());
  }
  return null;
}
 
Example 2
Source File: PlaybackDebugger.java    From consulo with Apache License 2.0 5 votes vote down vote up
private DesktopIdeFrameImpl getFrame() {
  final Frame[] all = Frame.getFrames();
  for (Frame each : all) {
    Window uiWindow = TargetAWT.from(each);

    IdeFrame ideFrame = uiWindow.getUserData(IdeFrame.KEY);
    if(IdeFrameUtil.isRootFrame(ideFrame)) {
      return (DesktopIdeFrameImpl)ideFrame;
    }
  }

  throw new IllegalStateException("Cannot find IdeFrame to run on");
}
 
Example 3
Source File: ActionPopupMenuImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void show(final Component component, int x, int y) {
  if (!component.isShowing()) {
    //noinspection HardCodedStringLiteral
    throw new IllegalArgumentException("component must be shown on the screen");
  }

  removeAll();

  // Fill menu. Only after filling menu has non zero size.

  int x2 = Math.max(0, Math.min(x, component.getWidth() - 1)); // fit x into [0, width-1]
  int y2 = Math.max(0, Math.min(y, component.getHeight() - 1)); // fit y into [0, height-1]

  myContext = myDataContextProvider != null ? myDataContextProvider.get() : DataManager.getInstance().getDataContext(component, x2, y2);
  Utils.fillMenu(myGroup, this, true, myPresentationFactory, myContext, myPlace, false, false, LaterInvocator.isInModalContext());
  if (getComponentCount() == 0) {
    return;
  }
  if (myApp != null) {
    if (myApp.isActive()) {
      Component frame = UIUtil.findUltimateParent(component);
      if (frame instanceof Window) {
        consulo.ui.Window uiWindow = TargetAWT.from((Window)frame);
        myFrame = uiWindow.getUserData(IdeFrame.KEY);
      }
      myConnection = myApp.getMessageBus().connect();
      myConnection.subscribe(ApplicationActivationListener.TOPIC, ActionPopupMenuImpl.this);
    }
  }

  super.show(component, x, y);
}
 
Example 4
Source File: FrameWrapper.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void dispose() {
  if (isDisposed()) return;

  Window frame = myFrame;
  StatusBar statusBar = myStatusBar;

  myFrame = null;
  myPreferredFocus = null;
  myProject = null;
  myDataMap.clear();
  if (myComponent != null && myFocusWatcher != null) {
    myFocusWatcher.deinstall(myComponent);
  }
  myFocusWatcher = null;
  myFocusedCallback = null;
  myComponent = null;
  myImages = null;
  myDisposed = true;

  if (statusBar != null) {
    Disposer.dispose(statusBar);
  }

  if (frame != null) {
    frame.setVisible(false);

    JRootPane rootPane = ((RootPaneContainer)frame).getRootPane();
    frame.removeAll();
    DialogWrapper.cleanupRootPane(rootPane);

    consulo.ui.Window uiWindow = TargetAWT.from(frame);
    IdeFrame ideFrame = uiWindow.getUserData(IdeFrame.KEY);
    MouseGestureManager.getInstance().remove(ideFrame);

    frame.dispose();

    DialogWrapper.cleanupWindowListeners(frame);
  }
}
 
Example 5
Source File: DesktopWindowManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public IdeFrame findFrameFor(@Nullable final Project project) {
  IdeFrame frame = null;
  if (project != null) {
    frame = project.isDefault() ? WelcomeFrameManager.getInstance().getCurrentFrame() : getIdeFrame(project);
    if (frame == null) {
      frame = myProject2Frame.get(null);
    }
  }
  else {
    Container eachParent = TargetAWT.to(getMostRecentFocusedWindow());
    while (eachParent != null) {
      if (eachParent instanceof Window) {
        consulo.ui.Window uiWIndow = TargetAWT.from((Window)eachParent);
        IdeFrame ideFrame = uiWIndow.getUserData(IdeFrame.KEY);
        if(ideFrame != null) {
          frame = ideFrame;
          break;
        }
      }
      eachParent = eachParent.getParent();
    }

    if (frame == null) {
      frame = tryToFindTheOnlyFrame();
    }
  }

  return frame;
}
 
Example 6
Source File: InfoAndProgressPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static DesktopBalloonLayoutImpl getBalloonLayout(@Nonnull JRootPane pane) {
  Component parent = UIUtil.findUltimateParent(pane);
  if (parent instanceof Window) {
    consulo.ui.Window uiWindow = TargetAWT.from((Window)parent);

    IdeFrame ideFrame = uiWindow.getUserData(IdeFrame.KEY);
    if (ideFrame == null) {
      return null;
    }
    return (DesktopBalloonLayoutImpl)ideFrame.getBalloonLayout();
  }
  return null;
}
 
Example 7
Source File: IdeStatusBarImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public StatusBar findChild(Component c) {
  Component eachParent = c;
  IdeFrame frame = null;
  while (eachParent != null) {
    if (eachParent instanceof Window) {
      consulo.ui.Window uiWindow = TargetAWT.from((Window)eachParent);
      frame = uiWindow.getUserData(IdeFrame.KEY);
    }
    eachParent = eachParent.getParent();
  }

  return frame != null ? frame.getStatusBar() : this;
}
 
Example 8
Source File: DesktopToolWindowManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Rectangle2D getRootBounds(JFrame frame) {
  JRootPane rootPane = frame.getRootPane();
  Rectangle bounds = rootPane.getBounds();
  bounds.setLocation(frame.getX() + rootPane.getX(), frame.getY() + rootPane.getY());
  return TargetAWT.from(bounds);
}
 
Example 9
Source File: DesktopIdeFrameImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Rectangle2D suggestChildFrameBounds() {
  //todo [kirillk] a dummy implementation
  final Rectangle b = myJFrame.getBounds();
  b.x += 100;
  b.width -= 200;
  b.y += 100;
  b.height -= 200;
  return TargetAWT.from(b);
}
 
Example 10
Source File: DesktopLabelImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public Image getImage() {
  return TargetAWT.from(myComponent.getIcon());
}
 
Example 11
Source File: Presentation.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public Image getUIIcon() {
  return TargetAWT.from(myIcon);
}
 
Example 12
Source File: DesktopWindowWatcher.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @param project may be null (for example, if no projects are opened)
 */
@Nullable
public final consulo.ui.Window suggestParentWindow(@Nullable final Project project) {
  synchronized (myLock) {
    Window window = getFocusedWindowForProject(project);
    if (window == null) {
      if (project != null) {
        IdeFrame frameFor = WindowManagerEx.getInstanceEx().findFrameFor(project);
        return frameFor == null ? null : frameFor.getWindow();
      }
      else {
        return null;
      }
    }

    LOG.assertTrue(window.isDisplayable());
    LOG.assertTrue(window.isShowing());

    while (window != null) {
      // skip all windows until found forst dialog or frame
      if (!(window instanceof Dialog) && !(window instanceof Frame)) {
        window = window.getOwner();
        continue;
      }
      // skip not visible and disposed/not shown windows
      if (!window.isDisplayable() || !window.isShowing()) {
        window = window.getOwner();
        continue;
      }
      // skip windows that have not associated WindowInfo
      final WindowInfo info = myWindow2Info.get(TargetAWT.from(window));
      if (info == null) {
        window = window.getOwner();
        continue;
      }
      if (info.mySuggestAsParent) {
        return TargetAWT.from(window);
      }
      else {
        window = window.getOwner();
      }
    }
    return null;
  }
}
 
Example 13
Source File: IdeKeyEventDispatcher.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @return <code>true</code> if and only if the <code>component</code> represents
 * modal context.
 * @throws IllegalArgumentException if <code>component</code> is <code>null</code>.
 */
public static boolean isModalContext(@Nonnull Component component) {
  Window awtWindow = UIUtil.getWindow(component);

  consulo.ui.Window uiWindow = TargetAWT.from(awtWindow);

  IdeFrame ideFrame = uiWindow == null ? null : uiWindow.getUserData(IdeFrame.KEY);
  if (IdeFrameUtil.isRootFrame(ideFrame)) {
    RootPaneContainer rootPaneContainer = (RootPaneContainer)awtWindow;

    Component glassPane = rootPaneContainer.getGlassPane();
    if (glassPane instanceof IdeGlassPaneEx) {
      return ((IdeGlassPaneEx)glassPane).isInModalContext();
    }
  }

  if (awtWindow instanceof JDialog) {
    final JDialog dialog = (JDialog)awtWindow;
    if (!dialog.isModal()) {
      final Window owner = dialog.getOwner();
      return owner != null && isModalContext(owner);
    }
  }

  if (awtWindow instanceof JFrame) {
    return false;
  }

  boolean isFloatingDecorator = awtWindow instanceof ToolWindowFloatingDecorator;

  boolean isPopup = !(component instanceof JFrame) && !(component instanceof JDialog);
  if (isPopup) {
    if (component instanceof JWindow) {
      JBPopup popup = (JBPopup)((JWindow)component).getRootPane().getClientProperty(JBPopup.KEY);
      if (popup != null) {
        return popup.isModalContext();
      }
    }
  }

  return !isFloatingDecorator;
}
 
Example 14
Source File: DesktopUIInternalImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public Window _Window_getActiveWindow() {
  Container window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
  return (Window)TargetAWT.from((java.awt.Window)window);
}
 
Example 15
Source File: DesktopToolWindowManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean dispatchKeyEvent(KeyEvent e) {
  if (e.getKeyCode() != KeyEvent.VK_CONTROL && e.getKeyCode() != KeyEvent.VK_ALT && e.getKeyCode() != KeyEvent.VK_SHIFT && e.getKeyCode() != KeyEvent.VK_META) {
    if (e.getModifiers() == 0) {
      resetHoldState();
    }
    return false;
  }
  if (e.getID() != KeyEvent.KEY_PRESSED && e.getID() != KeyEvent.KEY_RELEASED) return false;

  Component parent = UIUtil.findUltimateParent(e.getComponent());
  if(parent instanceof Window) {
    consulo.ui.Window uiWindow = TargetAWT.from((Window)parent);

    IdeFrame ideFrame = uiWindow.getUserData(IdeFrame.KEY);
    if (ideFrame != null && ideFrame.getProject() != myProject) {
      resetHoldState();
      return false;
    }
  }

  Set<Integer> vks = getActivateToolWindowVKs();

  if (vks.isEmpty()) {
    resetHoldState();
    return false;
  }

  if (vks.contains(e.getKeyCode())) {
    boolean pressed = e.getID() == KeyEvent.KEY_PRESSED;
    int modifiers = e.getModifiers();

    int mouseMask = InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON3_DOWN_MASK;
    if ((e.getModifiersEx() & mouseMask) == 0) {
      if (areAllModifiersPressed(modifiers, vks) || !pressed) {
        processState(pressed);
      }
      else {
        resetHoldState();
      }
    }
  }


  return false;
}
 
Example 16
Source File: DesktopFloatingDecorator.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Rectangle2D getDecoratorBounds() {
  return TargetAWT.from(getBounds());
}
 
Example 17
Source File: WindowOverAWTWindow.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public Window getParent() {
  return TargetAWT.from((java.awt.Window)myWindow.getParent());
}
 
Example 18
Source File: FlatWelcomeFrame.java    From consulo with Apache License 2.0 4 votes vote down vote up
public Rectangle2D suggestChildFrameBounds() {
  return TargetAWT.from(getBounds());
}
 
Example 19
Source File: RunLineMarkerContributor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public Info(@Nonnull final AnAction action) {
  this(TargetAWT.from(action.getTemplatePresentation().getIcon()), element -> getText(action, element), action);
}
 
Example 20
Source File: SwingComponentDelegate.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public Component getParent() {
  return TargetAWT.from(toAWTComponent().getParent());
}