List of usage examples for com.intellij.openapi.wm IdeFocusManager getGlobalInstance
@NotNull public static IdeFocusManager getGlobalInstance()
From source file:com.android.tools.idea.uibuilder.property.ptable.PTable.java
License:Apache License
private void startEditing(int row) { PTableCellEditor editor = getCellEditor(row, 0); if (editor == null) { return;// www . j a v a 2s.c om } editCellAt(row, 1); JComponent preferredComponent = getComponentToFocus(editor); if (preferredComponent == null) return; IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> { preferredComponent.requestFocusInWindow(); editor.activate(); }); }
From source file:com.codeflections.typengo.GotoActionRunner.java
License:Open Source License
@Override public void runAction(@NotNull Component sourceComponent, @NotNull AnActionEvent originalEvent) { ApplicationManager.getApplication()//from w w w.j a v a 2 s .co m .invokeLater(() -> IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown( () -> GotoActionAction.performAction(action, sourceComponent, originalEvent))); }
From source file:com.intellij.application.options.editor.JavaAutoImportConfigurable.java
License:Apache License
public void addExcludePackage(String packageName) { if (packageName == null) { return;// w w w. ja v a 2 s.c om } int index = -Arrays.binarySearch(myExcludePackagesModel.toArray(), packageName) - 1; if (index < 0) { return; } myExcludePackagesModel.add(index, packageName); myExcludePackagesList.setSelectedValue(packageName, true); ListScrollingUtil.ensureIndexIsVisible(myExcludePackagesList, index, 0); IdeFocusManager.getGlobalInstance().requestFocus(myExcludePackagesList, false); }
From source file:com.intellij.designer.propertyTable.PropertyTable.java
License:Apache License
private void startEditing(int index, boolean startedWithKeyboard) { final PropertyEditor editor = myProperties.get(index).getEditor(); if (editor == null) { return;//from www .j av a2 s .c om } editCellAt(index, convertColumnIndexToView(1)); LOG.assertTrue(editorComp != null); JComponent preferredComponent = editor.getPreferredFocusedComponent(); if (preferredComponent == null) { preferredComponent = IdeFocusTraversalPolicy.getPreferredFocusedComponent((JComponent) editorComp); } if (preferredComponent != null) { preferredComponent.requestFocusInWindow(); } if (startedWithKeyboard) { // waiting for focus is necessary in case, if 'activate' opens dialog. If we don't wait for focus, after the dialog is shown we'll // end up with the table focused instead of the dialog IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(new Runnable() { @Override public void run() { editor.activate(); } }); } }
From source file:com.intellij.ide.actions.AboutDialog.java
License:Apache License
private void init(Window window) { ApplicationInfoEx appInfo = (ApplicationInfoEx) ApplicationInfo.getInstance(); JPanel mainPanel = new JPanel(new BorderLayout()); final JComponent closeListenerOwner; Icon image = IconLoader.getIcon(appInfo.getAboutImageUrl()); final InfoSurface infoSurface = new InfoSurface(image); infoSurface.setPreferredSize(new Dimension(image.getIconWidth(), image.getIconHeight())); mainPanel.add(infoSurface, BorderLayout.NORTH); closeListenerOwner = infoSurface;//from w w w. ja v a2 s.c om setUndecorated(true); setContentPane(mainPanel); final Ref<Long> showTime = Ref.create(System.currentTimeMillis()); addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { int code = e.getKeyCode(); if (code == KeyEvent.VK_ESCAPE && e.getModifiers() == 0) { dispose(); } else if (infoSurface != null) { if (code == KeyEvent.VK_CONTROL || code == KeyEvent.VK_META) { showTime.set(System.currentTimeMillis()); e.consume(); } else if ((code == KeyEvent.VK_C && (e.isControlDown() || e.isMetaDown())) || (!SystemInfo.isMac && code == KeyEvent.VK_INSERT && e.isControlDown())) { copyInfoToClipboard(infoSurface.getText()); showTime.set(System.currentTimeMillis()); e.consume(); } } } }); //final long delta = Patches.APPLE_BUG_ID_3716865 ? 100 : 0; final long delta = 500; //reproducible on Windows too addWindowFocusListener(new WindowFocusListener() { @Override public void windowGainedFocus(WindowEvent e) { } @Override public void windowLostFocus(WindowEvent e) { long eventTime = System.currentTimeMillis(); if (eventTime - showTime.get() > delta && e.getOppositeWindow() != e.getWindow()) { dispose(); } else { IdeFocusManager.getGlobalInstance().requestFocus(AboutDialog.this, true); } } }); new ClickListener() { @Override public boolean onClick(MouseEvent event, int clickCount) { dispose(); return true; } }.installOn(closeListenerOwner); pack(); setLocationRelativeTo(window); }
From source file:com.intellij.ide.actions.MinimizeCurrentWindowAction.java
License:Apache License
@Override public void actionPerformed(final AnActionEvent e) { final Component focusOwner = IdeFocusManager.getGlobalInstance().getFocusOwner(); if (focusOwner != null) { final Window window = focusOwner instanceof JFrame ? (Window) focusOwner : SwingUtilities.getWindowAncestor(focusOwner); if (window instanceof JFrame && !(((JFrame) window).getState() == Frame.ICONIFIED)) { ((JFrame) window).setState(Frame.ICONIFIED); }/*from ww w . j ava 2 s . c om*/ } }
From source file:com.intellij.ide.actions.ToggleFullScreenAction.java
License:Apache License
@Nullable private static IdeFrameEx getFrame() { Component focusOwner = IdeFocusManager.getGlobalInstance().getFocusOwner(); if (focusOwner != null) { Window window = focusOwner instanceof JFrame ? (Window) focusOwner : SwingUtilities.getWindowAncestor(focusOwner); if (window instanceof IdeFrameEx) { return (IdeFrameEx) window; }/* w w w.ja va 2 s . c o m*/ } return null; }
From source file:com.intellij.ide.CommandLineProcessor.java
License:Apache License
@NotNull private static Project findBestProject(VirtualFile virtualFile, Project[] projects) { for (Project aProject : projects) { if (ProjectRootManager.getInstance(aProject).getFileIndex().isInContent(virtualFile)) { return aProject; }//from w w w . jav a2s. c om } IdeFrame frame = IdeFocusManager.getGlobalInstance().getLastFocusedFrame(); Project project = frame == null ? null : frame.getProject(); return project != null ? project : projects[0]; }
From source file:com.intellij.ide.IdeEventQueue.java
License:Apache License
public void fixStickyFocusedComponents(@Nullable AWTEvent e) { if (e != null && !(e instanceof InputEvent)) return; final KeyboardFocusManager mgr = KeyboardFocusManager.getCurrentKeyboardFocusManager(); if (Registry.is("actionSystem.fixStickyFocusedWindows")) { fixStickyWindow(mgr, mgr.getActiveWindow(), "setGlobalActiveWindow"); fixStickyWindow(mgr, mgr.getFocusedWindow(), "setGlobalFocusedWindow"); }/*from ww w .j a va 2 s .c o m*/ if (Registry.is("actionSystem.fixNullFocusedComponent")) { final Component focusOwner = mgr.getFocusOwner(); if (focusOwner == null || !focusOwner.isShowing() || focusOwner instanceof JFrame || focusOwner instanceof JDialog) { final Application app = ApplicationManager.getApplication(); if (app instanceof ApplicationEx && !((ApplicationEx) app).isLoaded()) { return; } boolean mouseEventsAhead = isMouseEventAhead(e); boolean focusTransferredNow = IdeFocusManager.getGlobalInstance().isFocusBeingTransferred(); boolean okToFixFocus = !mouseEventsAhead && !focusTransferredNow; if (okToFixFocus) { Window showingWindow = mgr.getActiveWindow(); if (showingWindow == null) { Method getNativeFocusOwner = ReflectionUtil.getDeclaredMethod(KeyboardFocusManager.class, "getNativeFocusOwner"); if (getNativeFocusOwner != null) { try { Object owner = getNativeFocusOwner.invoke(mgr); if (owner instanceof Component) { showingWindow = UIUtil.getWindow((Component) owner); } } catch (Exception e1) { LOG.debug(e1); } } } if (showingWindow != null) { final IdeFocusManager fm = IdeFocusManager.findInstanceByComponent(showingWindow); ExpirableRunnable maybeRequestDefaultFocus = new ExpirableRunnable() { @Override public void run() { if (getPopupManager().requestDefaultFocus(false)) return; final Application app = ApplicationManager.getApplication(); if (app != null && app.isActive()) { fm.requestDefaultFocus(false); } } @Override public boolean isExpired() { return !UIUtil.isMeaninglessFocusOwner(mgr.getFocusOwner()); } }; fm.revalidateFocus(maybeRequestDefaultFocus); } } } } }
From source file:com.intellij.ide.impl.DataManagerImpl.java
License:Apache License
@Override public AsyncResult<DataContext> getDataContextFromFocus() { final AsyncResult<DataContext> context = new AsyncResult<DataContext>(); IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(new Runnable() { @Override//from w w w. j a v a2s. c o m public void run() { context.setDone(getDataContext()); } }); return context; }