Example usage for com.intellij.openapi.wm IdeFocusManager findInstance

List of usage examples for com.intellij.openapi.wm IdeFocusManager findInstance

Introduction

In this page you can find the example usage for com.intellij.openapi.wm IdeFocusManager findInstance.

Prototype

@NotNull
    public static IdeFocusManager findInstance() 

Source Link

Usage

From source file:automation.commands.ParkMouseCommand.java

License:Apache License

@Override
public void process(final Queue<Command> script) throws Exception {

    //Project View item name
    final IdeFrame ideFrame = IdeFocusManager.findInstance().getLastFocusedFrame();
    final RobotControl rc = RobotControlManager.getInstance().getRobotControl();

    switch (myPosition) {
    case CENTER://  w  w w .  j a v  a  2s  .c om
        rc.navigateAndClick(ideFrame.getComponent(), runNext(script));
        break;
    }

}

From source file:com.android.tools.idea.editors.gfxtrace.GfxTraceViewPanel.java

License:Apache License

public void setupViewHierarchy(@NotNull Project project) {
    JPanel rootPanel = getRootComponent();
    rootPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    final ThreeComponentsSplitter threePane = getThreePanes();
    threePane.setDividerWidth(5);/*from  ww w  .j  a  v a2s. c om*/

    // Set some preferences on the scrubber.
    getTopPanel().setBorder(BorderFactory.createLineBorder(JBColor.border()));
    getScrubberScrollPane().setViewportView(getScrubberList());

    // Get rid of the hidden component and remove references to its children, since it's just a placeholder for us to use the UI designer.
    getHiddenComponents().removeAll();
    rootPanel.remove(getHiddenComponents());
    setHiddenComponents(null);

    // Configure the buffer views.
    final JBRunnerTabs bufferTabs = new JBRunnerTabs(project, ActionManager.getInstance(),
            IdeFocusManager.findInstance(), this);
    bufferTabs.setPaintBorder(0, 0, 0, 0).setTabSidePaintBorder(1)
            .setPaintFocus(UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF())
            .setAlwaysPaintSelectedTab(UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF());
    JBPanel[] frameBuffers = new JBPanel[] { myColorBuffer, myWireframeBuffer, myDepthBuffer };
    for (int i = 0; i < frameBuffers.length; ++i) {
        bufferTabs.addTab(
                new TabInfo(frameBuffers[i]).setText(FrameBufferController.BufferType.values()[i].getName()));
    }
    bufferTabs.setBorder(new EmptyBorder(0, 2, 0, 0));
    setBufferTabs(bufferTabs);

    // Put the buffer views in a wrapper so a border can be drawn around it.
    Wrapper bufferWrapper = new Wrapper();
    bufferWrapper.setLayout(new BorderLayout());
    bufferWrapper.setBorder(BorderFactory.createLineBorder(JBColor.border()));
    bufferWrapper.setContent(bufferTabs);

    // Configure the Atom tree container.
    Wrapper atomTreeWrapper = new Wrapper();
    atomTreeWrapper.setBorder(BorderFactory.createLineBorder(JBColor.border()));
    atomTreeWrapper.setContent(myAtomScrollPane);

    // Now add the atom tree and buffer views to the middle pane in the main pane.
    final JBSplitter middleSplitter = new JBSplitter(false);
    middleSplitter.setMinimumSize(new Dimension(100, 10));
    middleSplitter.setFirstComponent(atomTreeWrapper);
    middleSplitter.setSecondComponent(bufferWrapper);
    threePane.setInnerComponent(middleSplitter);

    // Configure the miscellaneous tabs.
    JBRunnerTabs miscTabs = new JBRunnerTabs(project, ActionManager.getInstance(),
            IdeFocusManager.findInstance(), this);
    miscTabs.setPaintBorder(0, 0, 0, 0).setTabSidePaintBorder(1)
            .setPaintFocus(UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF())
            .setAlwaysPaintSelectedTab(UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF());
    miscTabs.addTab(new TabInfo(getMemoryPanel()).setText("Memory"));
    miscTabs.addTab(new TabInfo(getImagePanel()).setText("Image"));
    miscTabs.addTab(new TabInfo(getDocsPanel()).setText("Docs"));
    miscTabs.setBorder(new EmptyBorder(0, 2, 0, 0));

    getDocsScrollPane().setViewportView(getDocsPane());

    // More borders for miscellaneous tabs.
    Wrapper miscWrapper = new Wrapper();
    miscWrapper.setBorder(BorderFactory.createLineBorder(JBColor.border()));
    miscWrapper.setContent(miscTabs);

    // Borders for the state tree as well.
    Wrapper stateWrapper = new Wrapper();
    stateWrapper.setContent(getStateScrollPane());
    stateWrapper.setBorder(BorderFactory.createLineBorder(JBColor.border()));

    // Configure the bottom splitter.
    final JBSplitter bottomSplitter = new JBSplitter(false);
    bottomSplitter.setMinimumSize(new Dimension(100, 10));
    bottomSplitter.setFirstComponent(stateWrapper);
    bottomSplitter.setSecondComponent(miscWrapper);
    threePane.setLastComponent(bottomSplitter);

    // Make sure the bottom splitter honors minimum sizes.
    threePane.setHonorComponentsMinimumSize(true);

    threePane.addHierarchyBoundsListener(new HierarchyBoundsAdapter() {
        @Override
        public void ancestorResized(HierarchyEvent hierarchyEvent) {
            super.ancestorResized(hierarchyEvent);
            resize();
        }
    });
}

From source file:com.android.tools.idea.gradle.project.GradleProjectImporter.java

License:Apache License

private static void open(@NotNull final Project newProject) {
    ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
    ProjectUtil.updateLastProjectLocation(newProject.getBasePath());
    if (WindowManager.getInstance().isFullScreenSupportedInCurrentOS()) {
        IdeFocusManager instance = IdeFocusManager.findInstance();
        IdeFrame lastFocusedFrame = instance.getLastFocusedFrame();
        if (lastFocusedFrame instanceof IdeFrameEx) {
            boolean fullScreen = ((IdeFrameEx) lastFocusedFrame).isInFullScreen();
            if (fullScreen) {
                newProject.putUserData(IdeFrameImpl.SHOULD_OPEN_IN_FULL_SCREEN, Boolean.TRUE);
            }/*from   w  ww . ja  va 2  s .  c  o  m*/
        }
    }
    projectManager.openProject(newProject);
}

From source file:com.android.tools.idea.tests.gui.framework.fixture.layout.NlPropertyInspectorFixture.java

License:Apache License

@NotNull
public NlPropertyInspectorFixture pressKeyInUnknownProperty(int keyCode, int... modifiers) {
    Component component = FocusManager.getCurrentManager().getFocusOwner();
    assertThat(component).isNotNull();/* w  w  w .  ja v  a  2 s.c o  m*/
    assertThat(SwingUtilities.isDescendingFrom(component, myPanel)).isTrue();
    driver().pressAndReleaseKey(component, keyCode, modifiers);
    IdeFocusManager.findInstance().doWhenFocusSettlesDown(() -> {
    });
    return this;
}

From source file:com.google.idea.blaze.clwb.wizard2.BlazeCProjectCreator.java

License:Open Source License

@Nullable
private Project doCreate() throws IOException {
    final ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
    final String projectFilePath = wizardContext.getProjectFileDirectory();

    try {// ww w .jav a  2  s  .  c  o  m
        File projectDir = new File(projectFilePath).getParentFile();
        LOG.assertTrue(projectDir != null,
                "Cannot create project in '" + projectFilePath + "': no parent file exists");
        FileUtil.ensureExists(projectDir);
        if (wizardContext.getProjectStorageFormat() == StorageScheme.DIRECTORY_BASED) {
            final File ideaDir = new File(projectFilePath, Project.DIRECTORY_STORE_FOLDER);
            FileUtil.ensureExists(ideaDir);
        }

        String name = wizardContext.getProjectName();
        Project newProject = projectBuilder.createProject(name, projectFilePath);
        if (newProject == null) {
            return null;
        }

        if (!ApplicationManager.getApplication().isUnitTestMode()) {
            newProject.save();
        }

        if (!projectBuilder.validate(null, newProject)) {
            return null;
        }

        projectBuilder.commit(newProject, null, ModulesProvider.EMPTY_MODULES_PROVIDER);

        StartupManager.getInstance(newProject).registerPostStartupActivity(() -> {
            // ensure the dialog is shown after all startup activities are done
            //noinspection SSBasedInspection
            SwingUtilities.invokeLater(() -> {
                if (newProject.isDisposed() || ApplicationManager.getApplication().isUnitTestMode()) {
                    return;
                }
                ApplicationManager.getApplication().invokeLater(() -> {
                    if (newProject.isDisposed()) {
                        return;
                    }
                    final ToolWindow toolWindow = ToolWindowManager.getInstance(newProject)
                            .getToolWindow(ToolWindowId.PROJECT_VIEW);
                    if (toolWindow != null) {
                        toolWindow.activate(null);
                    }
                }, ModalityState.NON_MODAL);
            });
        });

        ProjectUtil.updateLastProjectLocation(projectFilePath);

        if (WindowManager.getInstance().isFullScreenSupportedInCurrentOS()) {
            IdeFocusManager instance = IdeFocusManager.findInstance();
            IdeFrame lastFocusedFrame = instance.getLastFocusedFrame();
            if (lastFocusedFrame instanceof IdeFrameEx) {
                boolean fullScreen = ((IdeFrameEx) lastFocusedFrame).isInFullScreen();
                if (fullScreen) {
                    newProject.putUserData(IdeFrameImpl.SHOULD_OPEN_IN_FULL_SCREEN, Boolean.TRUE);
                }
            }
        }

        projectManager.openProject(newProject);

        if (!ApplicationManager.getApplication().isUnitTestMode()) {
            newProject.save();
        }
        return newProject;
    } finally {
        projectBuilder.cleanup();
    }
}

From source file:com.intellij.help.impl.IdeaHelpBroker.java

License:Apache License

/**
 * Displays the presentation to the user.
 *///  w ww .j a  v a2s .  co m
public void setDisplayed(boolean visible) {
    createHelpWindow();
    if (myModallyActivated) {
        myDialog.setVisible(visible);
        if (visible) {
            myDialog.setLocationRelativeTo(myDialog.getOwner());
        }
    } else {
        //myFrame.setLocationRelativeTo(null);
        myFrame.setVisible(visible);
        myFrame.setState(JFrame.NORMAL);
        IdeFocusManager focusManager = IdeFocusManager.findInstance();
        JComponent target = focusManager.getFocusTargetFor(myFrame.getRootPane());
        focusManager.requestFocus(target != null ? target : myFrame, true);
    }
}

From source file:com.intellij.ide.actions.SearchEverywhereAction.java

License:Apache License

@Override
public JComponent createCustomComponent(Presentation presentation) {
    JPanel panel = new JPanel(new BorderLayout()) {
        @Override//w ww .j a va2s. c o  m
        protected void paintComponent(Graphics g) {
            if (myBalloon != null && !myBalloon.isDisposed() && myActionEvent != null
                    && myActionEvent.getInputEvent() instanceof MouseEvent) {
                final Gradient gradient = getGradientColors();
                ((Graphics2D) g).setPaint(new GradientPaint(0, 0, gradient.getStartColor(), 0, getHeight(),
                        gradient.getEndColor()));
                g.fillRect(0, 0, getWidth(), getHeight());
            } else {
                super.paintComponent(g);
            }
        }
    };
    panel.setOpaque(false);

    final JLabel label = new JBLabel(AllIcons.Actions.FindPlain) {
        {
            enableEvents(AWTEvent.MOUSE_EVENT_MASK);
            enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
        }
    };
    panel.add(label, BorderLayout.CENTER);
    initTooltip(label);
    label.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            if (myBalloon != null) {
                myBalloon.cancel();
            }
            myFocusOwner = IdeFocusManager.findInstance().getFocusOwner();
            label.setToolTipText(null);
            IdeTooltipManager.getInstance().hideCurrentNow(false);
            label.setIcon(AllIcons.Actions.FindWhite);
            actionPerformed(null, e);
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            if (myBalloon == null || myBalloon.isDisposed()) {
                label.setIcon(AllIcons.Actions.Find);
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
            if (myBalloon == null || myBalloon.isDisposed()) {
                label.setIcon(AllIcons.Actions.FindPlain);
            }
        }
    });

    return panel;
}

From source file:com.intellij.ide.impl.NewProjectUtil.java

License:Apache License

private static Project doCreate(final AddModuleWizard dialog, @Nullable Project projectToClose)
        throws IOException {
    final ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
    final String projectFilePath = dialog.getNewProjectFilePath();
    final ProjectBuilder projectBuilder = dialog.getProjectBuilder();

    try {//from   w  w w .ja v  a2s  .  c o m
        File projectDir = new File(projectFilePath).getParentFile();
        LOGGER.assertTrue(projectDir != null,
                "Cannot create project in '" + projectFilePath + "': no parent file exists");
        FileUtil.ensureExists(projectDir);
        final File ideaDir = new File(projectFilePath, Project.DIRECTORY_STORE_FOLDER);
        FileUtil.ensureExists(ideaDir);

        final Project newProject;
        if (projectBuilder == null || !projectBuilder.isUpdate()) {
            String name = dialog.getProjectName();
            newProject = projectBuilder == null ? projectManager.newProject(name, projectFilePath, true, false)
                    : projectBuilder.createProject(name, projectFilePath);
        } else {
            newProject = projectToClose;
        }

        if (newProject == null)
            return projectToClose;

        final String compileOutput = dialog.getNewCompileOutput();
        CommandProcessor.getInstance().executeCommand(newProject, new Runnable() {
            @Override
            public void run() {
                ApplicationManager.getApplication().runWriteAction(new Runnable() {
                    @Override
                    public void run() {
                        String canonicalPath = compileOutput;
                        try {
                            canonicalPath = FileUtil.resolveShortWindowsName(compileOutput);
                        } catch (IOException e) {
                            //file doesn't exist
                        }
                        canonicalPath = FileUtil.toSystemIndependentName(canonicalPath);
                        CompilerConfiguration.getInstance(newProject)
                                .setCompilerOutputUrl(VfsUtilCore.pathToUrl(canonicalPath));
                    }
                });
            }
        }, null, null);

        if (!ApplicationManager.getApplication().isUnitTestMode()) {
            newProject.save();
        }

        if (projectBuilder != null && !projectBuilder.validate(projectToClose, newProject)) {
            return projectToClose;
        }

        if (newProject != projectToClose && !ApplicationManager.getApplication().isUnitTestMode()) {
            closePreviousProject(projectToClose);
        }

        if (projectBuilder != null) {
            projectBuilder.commit(newProject, null, ModulesProvider.EMPTY_MODULES_PROVIDER);
        }

        final boolean need2OpenProjectStructure = projectBuilder == null
                || projectBuilder.isOpenProjectSettingsAfter();
        StartupManager.getInstance(newProject).registerPostStartupActivity(new Runnable() {
            @Override
            public void run() {
                // ensure the dialog is shown after all startup activities are done
                //noinspection SSBasedInspection
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        if (newProject.isDisposed() || ApplicationManager.getApplication().isUnitTestMode())
                            return;
                        if (need2OpenProjectStructure) {
                            ModulesConfigurator.showDialog(newProject, null, null);
                        }
                        ApplicationManager.getApplication().invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                if (newProject.isDisposed())
                                    return;
                                final ToolWindow toolWindow = ToolWindowManager.getInstance(newProject)
                                        .getToolWindow(ToolWindowId.PROJECT_VIEW);
                                if (toolWindow != null) {
                                    toolWindow.activate(null);
                                }
                            }
                        }, ModalityState.NON_MODAL);
                    }
                });
            }
        });

        if (newProject != projectToClose) {
            ProjectUtil.updateLastProjectLocation(projectFilePath);

            if (WindowManager.getInstance().isFullScreenSupportedInCurrentOS()) {
                IdeFocusManager instance = IdeFocusManager.findInstance();
                IdeFrame lastFocusedFrame = instance.getLastFocusedFrame();
                if (lastFocusedFrame instanceof IdeFrameEx) {
                    boolean fullScreen = ((IdeFrameEx) lastFocusedFrame).isInFullScreen();
                    if (fullScreen) {
                        newProject.putUserData(IdeFrameImpl.SHOULD_OPEN_IN_FULL_SCREEN, Boolean.TRUE);
                    }
                }
            }

            projectManager.openProject(newProject);
        }
        if (!ApplicationManager.getApplication().isUnitTestMode()) {
            newProject.save();
        }
        return newProject;
    } finally {
        if (projectBuilder != null) {
            projectBuilder.cleanup();
        }
    }
}

From source file:com.intellij.refactoring.changeSignature.ChangeSignatureDialogBase.java

License:Apache License

private JComponent createSignaturePanel() {
    mySignatureArea = createSignaturePreviewComponent();
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(/*from   w w  w  . ja  v a  2 s .c  o  m*/
            SeparatorFactory.createSeparator(RefactoringBundle.message("signature.preview.border.title"), null),
            BorderLayout.NORTH);
    panel.add(mySignatureArea, BorderLayout.CENTER);
    mySignatureArea.setPreferredSize(new Dimension(-1, 130));
    mySignatureArea.setMinimumSize(new Dimension(-1, 130));
    mySignatureArea.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            Container root = findTraversalRoot(getContentPane());

            if (root != null) {
                Component c = root.getFocusTraversalPolicy().getComponentAfter(root, mySignatureArea);
                if (c != null) {
                    IdeFocusManager.findInstance().requestFocus(c, true);
                }
            }
        }
    });
    updateSignature();
    return panel;
}

From source file:com.intellij.refactoring.introduceParameter.IntroduceParameterHandler.java

License:Apache License

private void chooseMethodToIntroduceParameter(final Editor editor, final List<PsiMethod> validEnclosingMethods,
        final Introducer introducer) {
    final AbstractInplaceIntroducer inplaceIntroducer = AbstractInplaceIntroducer.getActiveIntroducer(editor);
    if (inplaceIntroducer instanceof InplaceIntroduceParameterPopup) {
        final InplaceIntroduceParameterPopup introduceParameterPopup = (InplaceIntroduceParameterPopup) inplaceIntroducer;
        introducer.introduceParameter(introduceParameterPopup.getMethodToIntroduceParameter(),
                introduceParameterPopup.getMethodToSearchFor());
        return;// ww  w .j av a  2 s.  c om
    }
    final JPanel panel = new JPanel(new BorderLayout());
    final JCheckBox superMethod = new JCheckBox("Refactor super method", true);
    superMethod.setMnemonic('U');
    panel.add(superMethod, BorderLayout.SOUTH);
    final JBList list = new JBList(validEnclosingMethods.toArray());
    list.setVisibleRowCount(5);
    list.setCellRenderer(new MethodCellRenderer());
    list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);
    final List<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>();
    final TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme()
            .getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(final ListSelectionEvent e) {
            final PsiMethod selectedMethod = (PsiMethod) list.getSelectedValue();
            if (selectedMethod == null)
                return;
            dropHighlighters(highlighters);
            updateView(selectedMethod, editor, attributes, highlighters, superMethod);
        }
    });
    updateView(validEnclosingMethods.get(0), editor, attributes, highlighters, superMethod);
    final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(list);
    scrollPane.setBorder(null);
    panel.add(scrollPane, BorderLayout.CENTER);

    final List<Pair<ActionListener, KeyStroke>> keyboardActions = Collections
            .singletonList(Pair.<ActionListener, KeyStroke>create(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    final PsiMethod methodToSearchIn = (PsiMethod) list.getSelectedValue();
                    if (myEnclosingMethodsPopup != null && myEnclosingMethodsPopup.isVisible()) {
                        myEnclosingMethodsPopup.cancel();
                    }

                    final PsiMethod methodToSearchFor = superMethod.isEnabled() && superMethod.isSelected()
                            ? methodToSearchIn.findDeepestSuperMethod()
                            : methodToSearchIn;
                    Runnable runnable = new Runnable() {
                        public void run() {
                            introducer.introduceParameter(methodToSearchIn, methodToSearchFor);
                        }
                    };
                    IdeFocusManager.findInstance().doWhenFocusSettlesDown(runnable);
                }
            }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)));
    myEnclosingMethodsPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, list)
            .setTitle("Introduce parameter to method").setMovable(false).setResizable(false)
            .setRequestFocus(true).setKeyboardActions(keyboardActions).addListener(new JBPopupAdapter() {
                @Override
                public void onClosed(LightweightWindowEvent event) {
                    dropHighlighters(highlighters);
                }
            }).createPopup();
    myEnclosingMethodsPopup.showInBestPositionFor(editor);
}