Search in sources :

Example 6 with IdeFrame

use of com.intellij.openapi.wm.IdeFrame in project intellij-community by JetBrains.

the class NavBarUpdateQueue method processUserActivity.

private void processUserActivity() {
    if (myPanel == null || !myPanel.isShowing()) {
        return;
    }
    final Project project = myPanel.getProject();
    IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(() -> {
        Window wnd = SwingUtilities.windowForComponent(myPanel);
        if (wnd == null)
            return;
        Component focus = null;
        if (!wnd.isActive()) {
            IdeFrame frame = UIUtil.getParentOfType(IdeFrame.class, myPanel);
            if (frame != null) {
                focus = IdeFocusManager.getInstance(project).getLastFocusedFor(frame);
            }
        } else {
            final Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
            if (window instanceof Dialog) {
                final Dialog dialog = (Dialog) window;
                if (dialog.isModal() && !SwingUtilities.isDescendingFrom(myPanel, dialog)) {
                    return;
                }
            }
        }
        if (focus != null && focus.isShowing()) {
            if (!myPanel.hasFocus() && !myPanel.isNodePopupShowing()) {
                requestModelUpdate(DataManager.getInstance().getDataContext(focus), null, false);
            }
        } else if (wnd.isActive()) {
            requestModelUpdate(null, myPanel.getContextObject(), false);
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) IdeFrame(com.intellij.openapi.wm.IdeFrame)

Example 7 with IdeFrame

use of com.intellij.openapi.wm.IdeFrame in project intellij-community by JetBrains.

the class PlaybackDebugger method startWhenFrameActive.

private void startWhenFrameActive() {
    myLog.setText(null);
    addInfo("Waiting for IDE frame activation", -1, MESSAGE_COLOR, 0);
    myRunner = new PlaybackRunner(myCodeEditor.getText(), this, false, true, false);
    VirtualFile file = pathToFile();
    if (file != null) {
        VirtualFile scriptDir = file.getParent();
        if (scriptDir != null) {
            myRunner.setScriptDir(new File(scriptDir.getPresentableUrl()));
        }
    }
    new Thread("playback debugger") {

        @Override
        public void run() {
            new WaitFor(60000) {

                @Override
                protected boolean condition() {
                    return KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow() instanceof IdeFrame || myRunner == null;
                }
            };
            if (myRunner == null) {
                message(null, "Script stopped", -1, Type.message, true);
                return;
            }
            message(null, "Starting script...", -1, Type.message, true);
            TimeoutUtil.sleep(1000);
            if (myRunner == null) {
                message(null, "Script stopped", -1, Type.message, true);
                return;
            }
            final PlaybackRunner runner = myRunner;
            myRunner.run().doWhenProcessed(() -> {
                if (runner == myRunner) {
                    SwingUtilities.invokeLater(() -> myRunner = null);
                }
            });
        }
    }.start();
}
Also used : PlaybackRunner(com.intellij.openapi.ui.playback.PlaybackRunner) WaitFor(com.intellij.util.WaitFor) File(java.io.File) IdeFrame(com.intellij.openapi.wm.IdeFrame)

Example 8 with IdeFrame

use of com.intellij.openapi.wm.IdeFrame in project intellij-community by JetBrains.

the class DimensionService method keyPair.

/**
   * @return Pair(key, scale) where:
   * key is the HiDPI-aware key,
   * scale is the HiDPI-aware factor to transform size metrics.
   */
@NotNull
private static Pair<String, Float> keyPair(String key, @Nullable Project project) {
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    if (env.isHeadlessInstance()) {
        return new Pair<>(key + ".headless", 1f);
    }
    JFrame frame = null;
    final Component owner = IdeFocusManager.findInstance().getFocusOwner();
    if (owner != null) {
        frame = UIUtil.getParentOfType(JFrame.class, owner);
    }
    if (frame == null) {
        frame = WindowManager.getInstance().findVisibleFrame();
    }
    if (project != null && (frame == null || (frame instanceof IdeFrame && project != ((IdeFrame) frame).getProject()))) {
        frame = WindowManager.getInstance().getFrame(project);
    }
    Rectangle screen = new Rectangle(0, 0, 0, 0);
    GraphicsDevice gd = null;
    if (frame != null) {
        final Point topLeft = frame.getLocation();
        Point2D center = new Point2D.Float(topLeft.x + frame.getWidth() / 2, topLeft.y + frame.getHeight() / 2);
        for (GraphicsDevice device : env.getScreenDevices()) {
            Rectangle bounds = device.getDefaultConfiguration().getBounds();
            if (bounds.contains(center)) {
                screen = bounds;
                gd = device;
                break;
            }
        }
    }
    if (gd == null) {
        gd = env.getDefaultScreenDevice();
        screen = gd.getDefaultConfiguration().getBounds();
    }
    float scale = 1f;
    if (UIUtil.isJreHiDPIEnabled()) {
        scale = JBUI.sysScale(gd.getDefaultConfiguration());
        // normalize screen bounds
        screen.setBounds((int) Math.floor(screen.x * scale), (int) Math.floor(screen.y * scale), (int) Math.ceil(screen.width * scale), (int) Math.ceil(screen.height * scale));
    }
    String realKey = key + '.' + screen.x + '.' + screen.y + '.' + screen.width + '.' + screen.height;
    if (JBUI.isPixHiDPI(gd.getDefaultConfiguration())) {
        int dpi = ((int) (96 * JBUI.pixScale(gd.getDefaultConfiguration())));
        realKey += "@" + dpi + "dpi";
    }
    return new Pair<>(realKey, scale);
}
Also used : IdeFrame(com.intellij.openapi.wm.IdeFrame) Point2D(java.awt.geom.Point2D) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with IdeFrame

use of com.intellij.openapi.wm.IdeFrame in project intellij-community by JetBrains.

the class ActionMenu method showDescriptionInStatusBar.

public static void showDescriptionInStatusBar(boolean isIncluded, Component component, String description) {
    IdeFrame frame = (IdeFrame) (component instanceof IdeFrame ? component : SwingUtilities.getAncestorOfClass(IdeFrame.class, component));
    StatusBar statusBar;
    if (frame != null && (statusBar = frame.getStatusBar()) != null) {
        statusBar.setInfo(isIncluded ? description : null);
    }
}
Also used : IdeFrame(com.intellij.openapi.wm.IdeFrame) StatusBar(com.intellij.openapi.wm.StatusBar)

Example 10 with IdeFrame

use of com.intellij.openapi.wm.IdeFrame in project intellij-community by JetBrains.

the class ActionMenu method fillMenu.

private void fillMenu() {
    DataContext context;
    boolean mayContextBeInvalid;
    if (myContext != null) {
        context = myContext;
        mayContextBeInvalid = false;
    } else {
        @SuppressWarnings("deprecation") DataContext contextFromFocus = DataManager.getInstance().getDataContext();
        context = contextFromFocus;
        if (PlatformDataKeys.CONTEXT_COMPONENT.getData(context) == null) {
            IdeFrame frame = UIUtil.getParentOfType(IdeFrame.class, this);
            context = DataManager.getInstance().getDataContext(IdeFocusManager.getGlobalInstance().getLastFocusedFor(frame));
        }
        mayContextBeInvalid = true;
    }
    Utils.fillMenu(myGroup.getAction(), this, myMnemonicEnabled, myPresentationFactory, context, myPlace, true, mayContextBeInvalid, LaterInvocator.isInModalContext());
}
Also used : IdeFrame(com.intellij.openapi.wm.IdeFrame)

Aggregations

IdeFrame (com.intellij.openapi.wm.IdeFrame)49 Project (com.intellij.openapi.project.Project)13 Nullable (org.jetbrains.annotations.Nullable)7 Balloon (com.intellij.openapi.ui.popup.Balloon)5 IdeFocusManager (com.intellij.openapi.wm.IdeFocusManager)5 NotNull (org.jetbrains.annotations.NotNull)5 ProgressManager (com.intellij.openapi.progress.ProgressManager)4 MessageType (com.intellij.openapi.ui.MessageType)3 StatusBarEx (com.intellij.openapi.wm.ex.StatusBarEx)3 IdeFrameImpl (com.intellij.openapi.wm.impl.IdeFrameImpl)3 RelativePoint (com.intellij.ui.awt.RelativePoint)3 HyperlinkEvent (javax.swing.event.HyperlinkEvent)3 Application (com.intellij.openapi.application.Application)2 ApplicationActivationListener (com.intellij.openapi.application.ApplicationActivationListener)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 ModalityState (com.intellij.openapi.application.ModalityState)2 Extensions (com.intellij.openapi.extensions.Extensions)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Ref (com.intellij.openapi.util.Ref)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2