当前位置: 首页>>代码示例>>Java>>正文


Java IdeFocusManager.getGlobalInstance方法代码示例

本文整理汇总了Java中com.intellij.openapi.wm.IdeFocusManager.getGlobalInstance方法的典型用法代码示例。如果您正苦于以下问题:Java IdeFocusManager.getGlobalInstance方法的具体用法?Java IdeFocusManager.getGlobalInstance怎么用?Java IdeFocusManager.getGlobalInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.wm.IdeFocusManager的用法示例。


在下文中一共展示了IdeFocusManager.getGlobalInstance方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findProject

import com.intellij.openapi.wm.IdeFocusManager; //导入方法依赖的package包/类
public static AsyncResult<Project> findProject() {
  final AsyncResult<Project> project = new AsyncResult<Project>();
  final IdeFocusManager fm = IdeFocusManager.getGlobalInstance();
  fm.doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      Component parent = UIUtil.findUltimateParent(fm.getFocusOwner());
      if (parent instanceof IdeFrame) {
        IdeFrame frame = (IdeFrame)parent;
        if (frame.getProject() != null) {
          project.setDone(frame.getProject());
          return;
        }
      }

      project.setRejected();
    }
  });

  return project;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:WindowSystemPlaybackCall.java

示例2: storeLastFocusedComponent

import com.intellij.openapi.wm.IdeFocusManager; //导入方法依赖的package包/类
private static void storeLastFocusedComponent(WindowEvent we) {
  final Window eventWindow = we.getWindow();

  if (we.getID() == WindowEvent.WINDOW_DEACTIVATED || we.getID() == WindowEvent.WINDOW_LOST_FOCUS) {
    Component frame = UIUtil.findUltimateParent(eventWindow);
    Component focusOwnerInDeactivatedWindow = eventWindow.getMostRecentFocusOwner();
    IdeFrame[] allProjectFrames = WindowManager.getInstance().getAllProjectFrames();

    if (focusOwnerInDeactivatedWindow != null) {
      for (IdeFrame ideFrame : allProjectFrames) {
        JFrame aFrame = WindowManager.getInstance().getFrame(ideFrame.getProject());
        if (aFrame.equals(frame)) {
          IdeFocusManager focusManager = IdeFocusManager.getGlobalInstance();
          if (focusManager instanceof FocusManagerImpl) {
            ((FocusManagerImpl)focusManager).setLastFocusedAtDeactivation(ideFrame, focusOwnerInDeactivatedWindow);
          }
        }
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:IdeEventQueue.java

示例3: focusTable

import com.intellij.openapi.wm.IdeFocusManager; //导入方法依赖的package包/类
public void focusTable() {
  final Project project = myModel.getProject();
  final IdeFocusManager focusManager = project == null || project.isDefault()
                                       ? IdeFocusManager.getGlobalInstance() : IdeFocusManager.getInstance(project);
  focusManager.doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      focusManager.requestFocus(myTable, true);
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:DirDiffPanel.java

示例4: actionPerformed

import com.intellij.openapi.wm.IdeFocusManager; //导入方法依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
  final Project project = e.getData(CommonDataKeys.PROJECT);
  final IdeFocusManager manager = IdeFocusManager.getGlobalInstance();
  if (! (manager instanceof FocusManagerImpl)) return;
  final FocusManagerImpl focusManager = (FocusManagerImpl)manager;

  myActive = !myActive;
  if (myActive) {
    myFocusTracker = new AWTEventListener() {
      @Override
      public void eventDispatched(AWTEvent event) {
        if (event instanceof FocusEvent && event.getID() == FocusEvent.FOCUS_GAINED) {
          focusManager.recordFocusRequest(((FocusEvent)event).getComponent(), false);
        }
      }
    };
    Toolkit.getDefaultToolkit().addAWTEventListener(myFocusTracker, AWTEvent.FOCUS_EVENT_MASK);
  }

  if (!myActive) {
    final List<FocusRequestInfo> requests = focusManager.getRequests();
    new FocusTracesDialog(project, new ArrayList<FocusRequestInfo>(requests)).show();
    Toolkit.getDefaultToolkit().removeAWTEventListener(myFocusTracker);
    myFocusTracker = null;
    requests.clear();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:FocusTracesAction.java

示例5: focus

import com.intellij.openapi.wm.IdeFocusManager; //导入方法依赖的package包/类
public void focus() {
  final Project project = myConfiguration.getModule().getProject();
  final IdeFocusManager focusManager = project.isDefault() ? IdeFocusManager.getGlobalInstance() : IdeFocusManager.getInstance(project);
  focusManager.doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      focusManager.requestFocus(myThemeList, true);
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:ThemeSelectionPanel.java

示例6: _execute

import com.intellij.openapi.wm.IdeFocusManager; //导入方法依赖的package包/类
@Override
protected ActionCallback _execute(PlaybackContext context) {
  String[] args = getText().substring(PREFIX.length()).trim().split(" ");
  String syntaxText = "Syntax error, expected: " + PREFIX + " " + ON + "|" + OFF + " actionName";
  if (args.length != 2) {
    context.error(syntaxText, getLine());
    return ActionCallback.REJECTED;
  }
  
  final boolean on;
  if (ON.equalsIgnoreCase(args[0])) {
    on = true;
  } else if (OFF.equalsIgnoreCase(args[0])) {
    on = false;
  } else {
    context.error(syntaxText, getLine());
    return ActionCallback.REJECTED;
  }
  
  String actionId = args[1];
  final AnAction action = ActionManager.getInstance().getAction(actionId);
  if (action == null) {
    context.error("Unknown action id=" + actionId, getLine());
    return ActionCallback.REJECTED;
  }

  if (!(action instanceof ToggleAction)) {
    context.error("Action is not a toggle action id=" + actionId, getLine());
    return ActionCallback.REJECTED;
  }

  final InputEvent inputEvent = ActionCommand.getInputEvent(actionId);
  final ActionCallback result = new ActionCallback();

  context.getRobot().delay(Registry.intValue("actionSystem.playback.delay"));

  IdeFocusManager fm = IdeFocusManager.getGlobalInstance();
  fm.doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      final Presentation presentation = (Presentation)action.getTemplatePresentation().clone();
      AnActionEvent event =
          new AnActionEvent(inputEvent, DataManager.getInstance()
              .getDataContext(KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()), ActionPlaces.UNKNOWN,
                            presentation, ActionManager.getInstance(), 0);

      ActionUtil.performDumbAwareUpdate(action, event, false);

      Boolean state = (Boolean)event.getPresentation().getClientProperty(ToggleAction.SELECTED_PROPERTY);
      if (state.booleanValue() != on) {
        ActionManager.getInstance().tryToExecute(action, inputEvent, null, ActionPlaces.UNKNOWN, true).doWhenProcessed(result.createSetDoneRunnable());
      }
      else {
        result.setDone();
      }
    }
  });


  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:62,代码来源:ToggleActionCommand.java

示例7: contextMenu

import com.intellij.openapi.wm.IdeFocusManager; //导入方法依赖的package包/类
public static AsyncResult<String> contextMenu(final PlaybackContext context, final String path) {
  final AsyncResult<String> result = new AsyncResult<String>();

  final IdeFocusManager fm = IdeFocusManager.getGlobalInstance();
  fm.doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      Component owner = fm.getFocusOwner();
      if (owner == null) {
        result.setRejected("No component focused");
        return;
      }

      ActionManager am = ActionManager.getInstance();
      AnAction showPopupMenu = am.getAction("ShowPopupMenu");
      if (showPopupMenu == null) {
        result.setRejected("Cannot find action: ShowPopupMenu");
        return;
      }

      am.tryToExecute(showPopupMenu, new MouseEvent(owner, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), 0, 0, 0, 1, true), null,
                      null, false).doWhenDone(
        new Runnable() {
          @Override
          public void run() {
            SwingUtilities.invokeLater(new Runnable() {
              @Override
              public void run() {
                MenuElement[] selectedPath = MenuSelectionManager.defaultManager().getSelectedPath();
                if (selectedPath.length == 0) {
                  result.setRejected("Failed to find active popup menu");
                  return;
                }
                selectNext(context, path.split("\\|"), 0, selectedPath[0].getSubElements(), result);
              }
            });
          }
        }).doWhenRejected(new Runnable() {
        @Override
        public void run() {
          result.setRejected("Cannot invoke popup menu from the ShowPopupMenu action, action call rejected");
        }
      });
    }
  });

  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:49,代码来源:WindowSystemPlaybackCall.java

示例8: getForemostWindow

import com.intellij.openapi.wm.IdeFocusManager; //导入方法依赖的package包/类
private static Window getForemostWindow(final Window window) {
  Window _window = null;
  IdeFocusManager ideFocusManager = IdeFocusManager.getGlobalInstance();

  Component focusOwner = IdeFocusManager.findInstance().getFocusOwner();
  // Let's ask for a focused component first
  if (focusOwner != null) {
    _window = SwingUtilities.getWindowAncestor(focusOwner);
  }

  if (_window == null) {
    // Looks like ide lost focus, let's ask about the last focused component
    focusOwner = ideFocusManager.getLastFocusedFor(ideFocusManager.getLastFocusedFrame());
    if (focusOwner != null) {
      _window = SwingUtilities.getWindowAncestor(focusOwner);
    }
  }

  if (_window == null) {
    _window = WindowManager.getInstance().findVisibleFrame();
  }

  if (_window == null && window != null) {
    // It might be we just has not opened a frame yet.
    // So let's ask AWT
    focusOwner = window.getMostRecentFocusOwner();
    if (focusOwner != null) {
      _window = SwingUtilities.getWindowAncestor(focusOwner);
    }
  }

  if (_window != null) {
    // We have successfully found the window
    // Let's check that we have not missed a blocker
    if (ModalityHelper.isModalBlocked(_window)) {
      _window = ModalityHelper.getModalBlockerFor(_window);
    }
  }

  if (SystemInfo.isAppleJvm && MacUtil.getWindowTitle(_window) == null) {
    // With Apple JDK we cannot find a window if it does not have a title
    // Let's show a dialog instead of the message.
    throw new MessageException("MacMessage parent does not have a title.");
  }
  while (_window != null && MacUtil.getWindowTitle(_window) == null) {
    _window = _window.getOwner();
    //At least our frame should have a title
  }

  while (Registry.is("skip.untitled.windows.for.mac.messages") && _window != null && _window instanceof JDialog && !((JDialog)_window).isModal()) {
    _window = _window.getOwner();
  }

  return _window;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:56,代码来源:JBMacMessages.java


注:本文中的com.intellij.openapi.wm.IdeFocusManager.getGlobalInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。