Java 类com.intellij.openapi.actionSystem.impl.PresentationFactory 实例源码

项目:tools-idea    文件:DefaultWelcomeScreen.java   
private void appendActionsFromGroup(final ActionGroup group) {
  final AnAction[] actions = group.getChildren(null);
  PresentationFactory factory = new PresentationFactory();
  for (final AnAction action : actions) {
    if (action instanceof ActionGroup) {
      final ActionGroup childGroup = (ActionGroup)action;
      appendActionsFromGroup(childGroup);
    }
    else {
      Presentation presentation = factory.getPresentation(action);
      action.update(new AnActionEvent(null, DataManager.getInstance().getDataContext(myMainPanel),
                                      ActionPlaces.WELCOME_SCREEN, presentation, ActionManager.getInstance(), 0));
      if (presentation.isVisible()) {
        appendButtonForAction(action);
      }
    }
  }
}
项目:tools-idea    文件:DarculaWelcomeScreenForm.java   
private void fillActions(JPanel root, final ActionGroup group, boolean quickStart) {
  final AnAction[] actions = group.getChildren(null);
  PresentationFactory factory = new PresentationFactory();
  for (final AnAction action : actions) {
    if (action instanceof ActionGroup) {
      final ActionGroup childGroup = (ActionGroup)action;
      fillActions(root, childGroup, quickStart);
    }
    else {
      Presentation presentation = factory.getPresentation(action);
      action.update(new AnActionEvent(null, DataManager.getInstance().getDataContext(root),
                                      ActionPlaces.WELCOME_SCREEN, presentation, ActionManager.getInstance(), 0));
      if (presentation.isVisible()) {
        if (quickStart) {
          myQuickStartButtons.add(new DarculaQuickStartButton(action));
        } else {
          myHelpButtons.add(new DarculaHelpButton(action));
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:CardActionsPanel.java   
private List<JComponent> buildComponents(ActionGroup group, String parentId) {
  AnAction[] actions = group.getChildren(null);

  List<JComponent> components = new ArrayList<JComponent>();
  PresentationFactory factory = new PresentationFactory();

  for (AnAction action : actions) {
    Presentation presentation = action.getTemplatePresentation().clone();
    if (!USE_ICONS) {
      presentation.setIcon(null);
    }
    if (action instanceof ActionGroup) {
      ActionGroup childGroup = (ActionGroup)action;
      if (childGroup.isPopup()) {
        final String id = String.valueOf(++nCards);
        createCardForGroup(childGroup, id, parentId);

        components.add(new Button(new ActivateCard(id), presentation));
      }
      else {
        components.addAll(buildComponents(childGroup, parentId));
      }
    }
    else if (action instanceof AbstractActionWithPanel){
      final JPanel panel = ((AbstractActionWithPanel)action).createPanel();
      components.add(panel);
    }
    else {
      action.update(new AnActionEvent(null, DataManager.getInstance().getDataContext(this),
                                      ActionPlaces.WELCOME_SCREEN, presentation, ActionManager.getInstance(), 0));
      if (presentation.isVisible()) {
        components.add(new Button(action, presentation));
      }
    }
  }
  return components;
}
项目:intellij-ce-playground    文件:JBMovePanel.java   
@NotNull
private static ActionButton createButton(@NotNull final AnAction action) {
  PresentationFactory presentationFactory = new PresentationFactory();
  Icon icon = AllIcons.Actions.AllLeft;
  Dimension size = new Dimension(icon.getIconWidth(), icon.getIconHeight());
  return new ActionButton(action, presentationFactory.getPresentation(action), MOVE_PANEL_PLACE, size);
}
项目:intellij-ce-playground    文件:Switcher.java   
private void tryToOpenFileSearch(final InputEvent e, final String fileName) {
  AnAction gotoFile = ActionManager.getInstance().getAction("GotoFile");
  if (gotoFile != null && !StringUtil.isEmpty(fileName)) {
    myPopup.cancel();
    final AnAction action = gotoFile;
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {

        DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer<DataContext>() {
          @Override
          public void consume(@NotNull final DataContext context) {
            final DataContext dataContext = new DataContext() {
              @Nullable
              @Override
              public Object getData(@NonNls String dataId) {
                if (PlatformDataKeys.PREDEFINED_TEXT.is(dataId)) {
                  return fileName;
                }
                return context.getData(dataId);
              }
            };
            final AnActionEvent event =
              new AnActionEvent(e, dataContext, ActionPlaces.EDITOR_POPUP, new PresentationFactory().getPresentation(action),
                                ActionManager.getInstance(), 0);
            action.actionPerformed(event);
          }
        });
      }
    });
  }
}
项目:intellij-ce-playground    文件:UnversionedViewDialog.java   
private void registerShortcuts(@NotNull ActionGroup opActionGroup, @NotNull DataContext dataContext) {
  List<AnAction> opActions = new ArrayList<AnAction>();
  Utils.expandActionGroup(opActionGroup, opActions, new PresentationFactory(), dataContext, "", ActionManager.getInstance());
  for (AnAction action : opActions) {
    action.registerCustomShortcutSet(action.getShortcutSet(), myView);
  }

  // special shortcut for deleting a file
  AnAction deleteAction = ActionManager.getInstance().getAction("ChangesView.DeleteUnversioned.From.Dialog");
  deleteAction.registerCustomShortcutSet(CommonShortcuts.getDelete(), myView);
}
项目:intellij-ce-playground    文件:CtrlMouseHandler.java   
QuickDocInfoPane(@NotNull PsiElement documentationAnchor,
                 @NotNull PsiElement elementUnderMouse,
                 @NotNull JComponent baseDocControl) {
  myBaseDocControl = baseDocControl;

  PresentationFactory presentationFactory = new PresentationFactory();
  for (AbstractDocumentationTooltipAction action : ourTooltipActions) {
    Icon icon = action.getTemplatePresentation().getIcon();
    Dimension minSize = new Dimension(icon.getIconWidth(), icon.getIconHeight());
    myButtons.add(new ActionButton(action, presentationFactory.getPresentation(action), IdeTooltipManager.IDE_TOOLTIP_PLACE, minSize));
    action.setDocInfo(documentationAnchor, elementUnderMouse);
  }
  Collections.reverse(myButtons);

  setPreferredSize(baseDocControl.getPreferredSize());
  setMaximumSize(baseDocControl.getMaximumSize());
  setMinimumSize(baseDocControl.getMinimumSize());
  setBackground(baseDocControl.getBackground());

  add(baseDocControl, Integer.valueOf(0));
  int minWidth = 0;
  int minHeight = 0;
  int buttonWidth = 0;
  for (JComponent button : myButtons) {
    button.setBorder(null);
    button.setBackground(baseDocControl.getBackground());
    add(button, Integer.valueOf(1));
    button.setVisible(false);
    Dimension preferredSize = button.getPreferredSize();
    minWidth += preferredSize.width;
    minHeight = Math.max(minHeight, preferredSize.height);
    buttonWidth = Math.max(buttonWidth, preferredSize.width);
  }
  myButtonWidth = buttonWidth;

  int margin = 2;
  myMinWidth = minWidth + margin * 2 + (myButtons.size() - 1) * BUTTON_HGAP;
  myMinHeight = minHeight + margin * 2;
}
项目:intellij-ce-playground    文件:ExtendedDeviceChooserDialog.java   
private void createUIComponents() {
  myCloudProjectIdLabel = new CloudProjectIdLabel(MATRIX);

  AnAction action = new AnAction() {
    @Override
    public void actionPerformed(AnActionEvent e) {
      if (myCloudConfigurationProvider == null) {
        return;
      }

      String selectedProjectId =
        myCloudConfigurationProvider.openCloudProjectConfigurationDialog(myProject, myCloudProjectIdLabel.getText());

      if (selectedProjectId != null) {
        myCloudProjectIdLabel.updateCloudProjectId(selectedProjectId);
        updateOkButton();
      }
    }

    @Override
    public void update(AnActionEvent event) {
      Presentation presentation = event.getPresentation();
      presentation.setIcon(AllIcons.General.Settings);
    }
  };

  myCloudProjectIdUpdateButton =
    new ActionButton(action, new PresentationFactory().getPresentation(action), "MyPlace", new Dimension(25, 25));

  myCloudConfigurationCombo = new CloudConfigurationComboBox(MATRIX);
  Disposer.register(myDisposable, myCloudConfigurationCombo);
}
项目:intellij-ce-playground    文件:AndroidRunConfigurationEditor.java   
private void createUIComponents() {
  myAvdCombo = new AvdComboBox(myProject, true, false) {
    @Override
    public Module getModule() {
      return getModuleSelector().getModule();
    }
  };
  myAvdCombo.getComboBox().setRenderer(new ListCellRendererWrapper() {
    @Override
    public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
      if (value instanceof IdDisplay) {
        setText(((IdDisplay)value).getDisplay());
      }
      else {
        setText(String.format("<html><font color='red'>Unknown AVD %1$s</font></html>", value == null ? "" : value.toString()));
      }
    }
  });

  myAvdComboComponent = new ComboboxWithBrowseButton(myAvdCombo.getComboBox());

  myCloudMatrixProjectIdLabel = new CloudProjectIdLabel(MATRIX);
  myCloudMatrixConfigurationCombo = new CloudConfigurationComboBox(MATRIX);
  AnAction cloudMatrixProjectAction = new SelectCloudProjectAction(myCloudMatrixProjectIdLabel, myCloudMatrixConfigurationCombo);
  myCloudMatrixProjectIdUpdateButton = new ActionButton(
    cloudMatrixProjectAction, new PresentationFactory().getPresentation(cloudMatrixProjectAction), "MyPlace", new Dimension(25, 25));
  Disposer.register(this, myCloudMatrixConfigurationCombo);

  myCloudDeviceProjectIdLabel = new CloudProjectIdLabel(SINGLE_DEVICE);
  myCloudDeviceConfigurationCombo = new CloudConfigurationComboBox(SINGLE_DEVICE);
  AnAction cloudDeviceProjectAction = new SelectCloudProjectAction(myCloudDeviceProjectIdLabel, myCloudDeviceConfigurationCombo);
  myCloudDeviceProjectIdUpdateButton = new ActionButton(
    cloudDeviceProjectAction, new PresentationFactory().getPresentation(cloudDeviceProjectAction), "MyPlace", new Dimension(25, 25));
  Disposer.register(this, myCloudDeviceConfigurationCombo);
}
项目:intellij-ce-playground    文件:LaunchCloudDeviceDialog.java   
private void createUIComponents() {
  myCloudProjectIdLabel = new CloudProjectIdLabel(SINGLE_DEVICE);

  AnAction action = new AnAction() {
    @Override
    public void actionPerformed(AnActionEvent e) {
      if (myCloudConfigurationProvider == null) {
        return;
      }

      String selectedProjectId =
        myCloudConfigurationProvider.openCloudProjectConfigurationDialog(myProject, myCloudProjectIdLabel.getText());

      if (selectedProjectId != null) {
        myCloudProjectIdLabel.updateCloudProjectId(selectedProjectId);
        updateOkButton();
      }
    }

    @Override
    public void update(AnActionEvent event) {
      Presentation presentation = event.getPresentation();
      presentation.setIcon(AllIcons.General.Settings);
    }
  };

  myCloudProjectIdUpdateButton =
    new ActionButton(action, new PresentationFactory().getPresentation(action), "MyPlace", new Dimension(25, 25));

  myCloudConfigurationCombo = new CloudConfigurationComboBox(SINGLE_DEVICE);
  Disposer.register(myDisposable, myCloudConfigurationCombo);
}
项目:tools-idea    文件:CardActionsPanel.java   
private List<Button> buildButtons(ActionGroup group, String parentId) {
  AnAction[] actions = group.getChildren(null);

  List<Button> buttons = new ArrayList<Button>();
  PresentationFactory factory = new PresentationFactory();

  for (AnAction action : actions) {
    Presentation presentation = action.getTemplatePresentation();
    if (!USE_ICONS) {
      presentation.setIcon(null);
    }
    if (action instanceof ActionGroup) {
      ActionGroup childGroup = (ActionGroup)action;
      if (childGroup.isPopup()) {
        final String id = String.valueOf(++nCards);
        createCardForGroup(childGroup, id, parentId);

        buttons.add(new Button(new ActivateCard(id), presentation));
      }
      else {
        buttons.addAll(buildButtons(childGroup, parentId));
      }
    }
    else {
      action.update(new AnActionEvent(null, DataManager.getInstance().getDataContext(this),
                                      ActionPlaces.WELCOME_SCREEN, presentation, ActionManager.getInstance(), 0));
      if (presentation.isVisible()) {
        buttons.add(new Button(action, presentation));
      }
    }
  }
  return buttons;
}
项目:tools-idea    文件:JBMovePanel.java   
@NotNull
private static ActionButton createButton(@NotNull final AnAction action) {
  PresentationFactory presentationFactory = new PresentationFactory();
  Icon icon = AllIcons.Actions.AllLeft;
  Dimension size = new Dimension(icon.getIconWidth(), icon.getIconHeight());
  return new ActionButton(action, presentationFactory.getPresentation(action), MOVE_PANEL_PLACE, size);
}
项目:tools-idea    文件:UnversionedViewDialog.java   
private void registerShortcuts(@NotNull ActionGroup opActionGroup, @NotNull DataContext dataContext) {
  List<AnAction> opActions = new ArrayList<AnAction>();
  Utils.expandActionGroup(opActionGroup, opActions, new PresentationFactory(), dataContext, "", ActionManager.getInstance());
  for (AnAction action : opActions) {
    action.registerCustomShortcutSet(action.getShortcutSet(), myView);
  }

  // special shortcut for deleting a file
  AnAction deleteAction = ActionManager.getInstance().getAction("ChangesView.DeleteUnversioned.From.Dialog");
  deleteAction.registerCustomShortcutSet(CommonShortcuts.DELETE, myView);
}
项目:tools-idea    文件:CtrlMouseHandler.java   
QuickDocInfoPane(@NotNull PsiElement documentationAnchor,
                 @NotNull PsiElement elementUnderMouse,
                 @NotNull JComponent baseDocControl) {
  myBaseDocControl = baseDocControl;

  PresentationFactory presentationFactory = new PresentationFactory();
  for (AbstractDocumentationTooltipAction action : ourTooltipActions) {
    Icon icon = action.getTemplatePresentation().getIcon();
    Dimension minSize = new Dimension(icon.getIconWidth(), icon.getIconHeight());
    myButtons.add(new ActionButton(action, presentationFactory.getPresentation(action), IdeTooltipManager.IDE_TOOLTIP_PLACE, minSize));
    action.setDocInfo(documentationAnchor, elementUnderMouse);
  }
  Collections.reverse(myButtons);

  setPreferredSize(baseDocControl.getPreferredSize());
  setMaximumSize(baseDocControl.getMaximumSize());
  setMinimumSize(baseDocControl.getMinimumSize());
  setBackground(baseDocControl.getBackground());

  add(baseDocControl, Integer.valueOf(0));
  int minWidth = 0;
  int minHeight = 0;
  int buttonWidth = 0;
  for (JComponent button : myButtons) {
    button.setBorder(null);
    button.setBackground(baseDocControl.getBackground());
    add(button, Integer.valueOf(1));
    button.setVisible(false);
    Dimension preferredSize = button.getPreferredSize();
    minWidth += preferredSize.width;
    minHeight = Math.max(minHeight, preferredSize.height);
    buttonWidth = Math.max(buttonWidth, preferredSize.width);
  }
  myButtonWidth = buttonWidth;

  int margin = 2;
  myMinWidth = minWidth + margin * 2 + (myButtons.size() - 1) * BUTTON_HGAP;
  myMinHeight = minHeight + margin * 2;
}
项目:consulo    文件:JBMovePanel.java   
@Nonnull
private static ActionButton createButton(@Nonnull final AnAction action) {
  PresentationFactory presentationFactory = new PresentationFactory();
  Icon icon = AllIcons.Actions.AllLeft;
  Dimension size = new Dimension(icon.getIconWidth(), icon.getIconHeight());
  return new ActionButton(action, presentationFactory.getPresentation(action), MOVE_PANEL_PLACE, size);
}
项目:consulo    文件:Switcher.java   
private void tryToOpenFileSearch(final InputEvent e, final String fileName) {
  AnAction gotoFile = ActionManager.getInstance().getAction("GotoFile");
  if (gotoFile != null && !StringUtil.isEmpty(fileName)) {
    myPopup.cancel();
    final AnAction action = gotoFile;
    SwingUtilities.invokeLater(() -> DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer<DataContext>() {
      @Override
      public void consume(@Nonnull final DataContext context) {
        final DataContext dataContext = new DataContext() {
          @Nullable
          @Override
          @SuppressWarnings("unchecked")
          public <T> T getData(@Nonnull Key<T> dataId) {
            if (PlatformDataKeys.PREDEFINED_TEXT == dataId) {
              return (T)fileName;
            }
            return context.getData(dataId);
          }
        };
        final AnActionEvent event =
                new AnActionEvent(e, dataContext, ActionPlaces.EDITOR_POPUP, new PresentationFactory().getPresentation(action),
                                  ActionManager.getInstance(), 0);
        action.actionPerformed(event);
      }
    }));
  }
}
项目:consulo    文件:UnversionedViewDialog.java   
@Nonnull
public static List<AnAction> registerUnversionedActionsShortcuts(@Nonnull DataContext dataContext, @Nonnull JComponent component) {
  ActionManager manager = ActionManager.getInstance();
  List<AnAction> actions = ContainerUtil.newArrayList();

  Utils.expandActionGroup(LaterInvocator.isInModalContext(), getUnversionedActionGroup(), actions, new PresentationFactory(), dataContext, "", manager);
  for (AnAction action : actions) {
    action.registerCustomShortcutSet(action.getShortcutSet(), component);
  }

  return actions;
}
项目:consulo    文件:CtrlMouseHandler.java   
QuickDocInfoPane(@Nonnull PsiElement documentationAnchor, @Nonnull PsiElement elementUnderMouse, @Nonnull JComponent baseDocControl) {
  myBaseDocControl = baseDocControl;

  PresentationFactory presentationFactory = new PresentationFactory();
  for (AbstractDocumentationTooltipAction action : ourTooltipActions) {
    Icon icon = action.getTemplatePresentation().getIcon();
    Dimension minSize = new Dimension(icon.getIconWidth(), icon.getIconHeight());
    myButtons.add(new ActionButton(action, presentationFactory.getPresentation(action), IdeTooltipManager.IDE_TOOLTIP_PLACE, minSize));
    action.setDocInfo(documentationAnchor, elementUnderMouse);
  }
  Collections.reverse(myButtons);

  setPreferredSize(baseDocControl.getPreferredSize());
  setMaximumSize(baseDocControl.getMaximumSize());
  setMinimumSize(baseDocControl.getMinimumSize());
  setBackground(baseDocControl.getBackground());

  add(baseDocControl, Integer.valueOf(0));
  int minWidth = 0;
  int minHeight = 0;
  int buttonWidth = 0;
  for (JComponent button : myButtons) {
    button.setBorder(null);
    button.setBackground(baseDocControl.getBackground());
    add(button, Integer.valueOf(1));
    button.setVisible(false);
    Dimension preferredSize = button.getPreferredSize();
    minWidth += preferredSize.width;
    minHeight = Math.max(minHeight, preferredSize.height);
    buttonWidth = Math.max(buttonWidth, preferredSize.width);
  }
  myButtonWidth = buttonWidth;

  int margin = 2;
  myMinWidth = minWidth + margin * 2 + (myButtons.size() - 1) * BUTTON_HGAP;
  myMinHeight = minHeight + margin * 2;
}
项目:tools-idea    文件:Switcher.java   
@Override
protected void processKeyEvent(final KeyEvent e) {
  final int keyCode = e.getKeyCode();
  if (keyCode == VK_LEFT || keyCode == VK_RIGHT) {
    return;
  }
  if (keyCode == VK_ENTER && files.getModel().getSize() + toolWindows.getModel().getSize() == 0) {
    AnAction gotoAction = ActionManager.getInstance().getAction("GotoClass");
    if (gotoAction == null) {
      gotoAction = ActionManager.getInstance().getAction("GotoFile");
    }
    if (gotoAction != null) {
      final String search = mySpeedSearch.getEnteredPrefix();
      myPopup.cancel();
      final AnAction action = gotoAction;
      SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {

          DataManager.getInstance().getDataContextFromFocus().doWhenDone(new AsyncResult.Handler<DataContext>() {
            @Override
            public void run(final DataContext context) {
              final DataContext dataContext = new DataContext() {
                @Nullable
                @Override
                public Object getData(@NonNls String dataId) {
                  if (PlatformDataKeys.PREDEFINED_TEXT.is(dataId)) {
                    return search;
                  }
                  return context.getData(dataId);
                }
              };
              final AnActionEvent event =
                new AnActionEvent(e, dataContext, ActionPlaces.EDITOR_POPUP, new PresentationFactory().getPresentation(action),
                                  ActionManager.getInstance(), 0);
              action.actionPerformed(event);
            }
          });
        }
      });
      return;
    }
  }
  super.processKeyEvent(e);
}