List of usage examples for com.intellij.openapi.ui.popup JBPopup showUnderneathOf
void showUnderneathOf(@NotNull Component componentUnder);
From source file:com.android.tools.idea.actions.EditMultipleSourcesAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent e) { Project project = e.getData(CommonDataKeys.PROJECT); assert project != null; final Navigatable[] files = e.getData(CommonDataKeys.NAVIGATABLE_ARRAY); assert files != null && files.length > 0; if (files.length > 1) { DefaultListModel listModel = new DefaultListModel(); for (int i = 0; i < files.length; ++i) { assert files[i] instanceof PsiClassNavigation; //noinspection unchecked listModel.add(i, ((PsiClassNavigation) files[i]).getPsiFile()); }//from w ww. j a v a 2 s.co m final JBList list = new JBList(listModel); int width = WindowManager.getInstance().getFrame(project).getSize().width; list.setCellRenderer(new GotoFileCellRenderer(width)); JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Choose Target File") .setItemChoosenCallback(new Runnable() { @Override public void run() { Object selectedValue = list.getSelectedValue(); PsiClassNavigation navigationWrapper = null; for (Navigatable file : files) { if (selectedValue == ((PsiClassNavigation) file).getPsiFile()) { navigationWrapper = (PsiClassNavigation) file; break; } } assert navigationWrapper != null; if (navigationWrapper.canNavigate()) { navigationWrapper.navigate(true); } } }).createPopup(); if (e.getInputEvent().getSource() instanceof ActionButton) { popup.showUnderneathOf((ActionButton) e.getInputEvent().getSource()); } else { popup.showInBestPositionFor(e.getDataContext()); } } else { assert files[0] instanceof PsiClassNavigation; PsiClassNavigation file = (PsiClassNavigation) files[0]; if (file.canNavigate()) { file.navigate(true); } } }
From source file:com.intellij.codeInspection.ui.InspectionResultsView.java
License:Apache License
public static void showPopup(AnActionEvent e, JBPopup popup) { final InputEvent event = e.getInputEvent(); if (event instanceof MouseEvent) { popup.showUnderneathOf(event.getComponent()); } else {/*from w w w . j a va 2s . c om*/ popup.showInBestPositionFor(e.getDataContext()); } }
From source file:com.intellij.execution.ui.CommonProgramParametersPanel.java
License:Apache License
protected void initComponents() { myProgramParametersComponent = LabeledComponent.create(new RawCommandLineEditor(), ExecutionBundle.message("run.configuration.program.parameters")); final JPanel panel = new JPanel(new BorderLayout()); myWorkingDirectoryField = new TextFieldWithBrowseButton(new ActionListener() { @Override//from w ww .jav a 2 s . c o m public void actionPerformed(ActionEvent e) { FileChooserDescriptor fileChooserDescriptor = FileChooserDescriptorFactory .createSingleFolderDescriptor(); fileChooserDescriptor.setTitle(ExecutionBundle.message("select.working.directory.message")); fileChooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, myModuleContext); Project project = myModuleContext != null ? myModuleContext.getProject() : null; VirtualFile file = FileChooser.chooseFile(fileChooserDescriptor, myWorkingDirectoryComponent, project, null); if (file != null) { setWorkingDirectory(file.getPresentableUrl()); } } }) { @Override protected void installPathCompletion(FileChooserDescriptor fileChooserDescriptor) { super.installPathCompletion(FileChooserDescriptorFactory.createSingleFolderDescriptor()); } }; panel.add(myWorkingDirectoryField, BorderLayout.CENTER); final FixedSizeButton button = new FixedSizeButton(myWorkingDirectoryField); button.setIcon(AllIcons.RunConfigurations.Variables); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final List<String> macros = new ArrayList<String>(PathMacros.getInstance().getUserMacroNames()); if (myHaveModuleContext) macros.add("MODULE_DIR"); final JList list = new JBList(ArrayUtil.toStringArray(macros)); final JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list) .setItemChoosenCallback(new Runnable() { @Override public void run() { final Object value = list.getSelectedValue(); if (value instanceof String) { setWorkingDirectory("$" + value + "$"); } } }).setMovable(false).setResizable(false).createPopup(); popup.showUnderneathOf(button); } }); panel.add(button, BorderLayout.EAST); myWorkingDirectoryComponent = LabeledComponent.create(panel, ExecutionBundle.message("run.configuration.working.directory.label")); myEnvVariablesComponent = new EnvironmentVariablesComponent(); myEnvVariablesComponent.setLabelLocation(BorderLayout.WEST); myProgramParametersComponent.setLabelLocation(BorderLayout.WEST); myWorkingDirectoryComponent.setLabelLocation(BorderLayout.WEST); addComponents(); setPreferredSize(new Dimension(10, 10)); setAnchor(myEnvVariablesComponent.getLabel()); }
From source file:com.intellij.ide.ui.search.SearchUtil.java
License:Apache License
public static void showHintPopup(final ConfigurableSearchTextField searchField, final JBPopup[] activePopup, final Alarm showHintAlarm, final Consumer<String> selectConfigurable, final Project project) { for (JBPopup aPopup : activePopup) { if (aPopup != null) { aPopup.cancel();// w w w. ja va 2 s . c o m } } final JBPopup popup = createPopup(searchField, activePopup, showHintAlarm, selectConfigurable, project, 0); //no selection if (popup != null) { popup.showUnderneathOf(searchField); searchField.requestFocusInWindow(); } activePopup[0] = popup; activePopup[1] = null; }
From source file:com.intellij.ide.ui.search.SearchUtil.java
License:Apache License
public static void registerKeyboardNavigation(final ConfigurableSearchTextField searchField, final JBPopup[] activePopup, final Alarm showHintAlarm, final Consumer<String> selectConfigurable, final Project project) { final Consumer<Integer> shower = new Consumer<Integer>() { public void consume(final Integer direction) { if (activePopup[0] != null) { activePopup[0].cancel(); }// w w w .jav a2 s . co m if (activePopup[1] != null && activePopup[1].isVisible()) { return; } final JBPopup popup = createPopup(searchField, activePopup, showHintAlarm, selectConfigurable, project, direction.intValue()); if (popup != null) { popup.showUnderneathOf(searchField); } activePopup[0] = null; activePopup[1] = popup; } }; searchField.registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent e) { shower.consume(1); } }, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); searchField.registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent e) { shower.consume(-1); } }, KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); searchField.addKeyboardListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE && searchField.getText().length() > 0) { e.consume(); if (cancelPopups(activePopup)) return; searchField.setText(""); } else if (e.getKeyCode() == KeyEvent.VK_ENTER) { searchField.addCurrentTextToHistory(); cancelPopups(activePopup); if (e.getModifiers() == 0) { e.consume(); } } } }); }
From source file:com.intellij.vcs.log.ui.GoToRefAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent e) { Project project = e.getProject();/*from w w w . ja va 2 s .c o m*/ final VcsLog log = e.getData(VcsLogDataKeys.VCS_LOG); if (project == null || log == null) { return; } Collection<String> refs = ContainerUtil.map(log.getAllReferences(), new Function<VcsRef, String>() { @Override public String fun(VcsRef ref) { return ref.getName(); } }); final PopupWithTextFieldWithAutoCompletion textField = new PopupWithTextFieldWithAutoCompletion(project, refs); JBPopup popup = textField.createPopup(); popup.addListener(new JBPopupListener.Adapter() { @Override public void onClosed(LightweightWindowEvent event) { if (event.isOk()) { log.jumpToReference(textField.getText().trim()); } } }); popup.showUnderneathOf(log.getToolbar()); }
From source file:krasa.formatter.plugin.ProjectSettingsForm.java
License:Apache License
public ProjectSettingsForm(final Project project) { DONATEButton.setBorder(BorderFactory.createEmptyBorder()); DONATEButton.setContentAreaFilled(false); this.project = project; JToggleButton[] modifiableButtons = new JToggleButton[] { useDefaultFormatter, useEclipseFormatter, optimizeImportsCheckBox, enableJavaFormatting, doNotFormatOtherFilesRadioButton, formatOtherFilesWithExceptionsRadioButton, formatSelectedTextInAllFileTypes, enableJSFormatting, enableCppFormatting, importOrderConfigurationManualRadioButton, importOrderConfigurationFromFileRadioButton, enableGWTNativeMethodsCheckBox }; for (JToggleButton button : modifiableButtons) { button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { updateComponents();//from w w w . ja va 2 s .c o m } }); } JTextField[] modifiableFields = new JTextField[] { pathToEclipsePreferenceFileJava, pathToEclipsePreferenceFileJS, pathToEclipsePreferenceFileCpp, disabledFileTypes, importOrder, pathToImportOrderPreferenceFile }; for (JTextField field : modifiableFields) { field.getDocument().addDocumentListener(new DocumentAdapter() { protected void textChanged(DocumentEvent e) { updateComponents(); } }); } eclipsePreferenceFilePathJavaBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { browseForFile(pathToEclipsePreferenceFileJava); } }); pathToImportOrderPreferenceFileBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { browseForFile(pathToImportOrderPreferenceFile); } }); eclipsePreferenceFilePathJSBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { browseForFile(pathToEclipsePreferenceFileJS); } }); eclipsePreferenceFilePathCppBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { browseForFile(pathToEclipsePreferenceFileCpp); } }); rootComponent.addAncestorListener(new AncestorListener() { public void ancestorAdded(AncestorEvent event) { // Called when component becomes visible, to ensure that the // popups // are visible when the form is shown for the first time. updateComponents(); } public void ancestorRemoved(AncestorEvent event) { } public void ancestorMoved(AncestorEvent event) { } }); pathToEclipsePreferenceFileJava.getDocument().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { setJavaFormatterProfileModel(); } }); pathToEclipsePreferenceFileJS.getDocument().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { setJavaScriptFormatterProfileModel(); } }); pathToEclipsePreferenceFileCpp.getDocument().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { setCppFormatterProfileModel(); } }); newProfile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (isModified(displayedSettings)) { createConfirmation("Profile was modified, save changes to current profile?", "Yes", "No", new Runnable() { @Override public void run() { apply(); createProfile(); } }, new Runnable() { @Override public void run() { importFrom(displayedSettings); createProfile(); } }, 0).showInFocusCenter(); } else { createProfile(); } } private void createProfile() { Settings settings = GlobalSettings.getInstance().newSettings(); refreshProfilesModel(); profiles.setSelectedItem(settings); } }); copyProfile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (isModified(displayedSettings)) { ListPopup confirmation = createConfirmation( "Profile was modified, save changes to current profile?", "Yes", "No", new Runnable() { @Override public void run() { apply(); copyProfile(); } }, new Runnable() { @Override public void run() { importFrom(displayedSettings); copyProfile(); } }, 0); confirmation.showInFocusCenter(); } else { copyProfile(); } } private void copyProfile() { Settings settings = GlobalSettings.getInstance().copySettings(displayedSettings); refreshProfilesModel(); profiles.setSelectedItem(settings); } }); setJavaFormatterProfileModel(); setJavaScriptFormatterProfileModel(); setCppFormatterProfileModel(); profilesModel = createProfilesModel(); profiles.setModel(profilesModel); profiles.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // && isSameId() if (displayedSettings != null && getSelectedItem() != null && isModified(displayedSettings)) { showConfirmationDialogOnProfileChange(); } else if (displayedSettings != null && getSelectedItem() != null) { importFromInternal(getSelectedItem()); } } }); profiles.setRenderer(new ListCellRendererWrapper() { @Override public void customize(JList jList, Object value, int i, boolean b, boolean b1) { if (value != null) { setText(((Settings) value).getName()); } } }); rename.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final JTextField content = new JTextField(); content.setText(displayedSettings.getName()); JBPopup balloon = PopupFactoryImpl.getInstance().createComponentPopupBuilder(content, content) .createPopup(); balloon.setMinimumSize(new Dimension(200, 20)); balloon.addListener(new JBPopupListener() { @Override public void beforeShown(LightweightWindowEvent event) { } @Override public void onClosed(LightweightWindowEvent event) { displayedSettings.setName(content.getText()); } }); balloon.showUnderneathOf(rename); } }); delete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int selectedIndex = profiles.getSelectedIndex(); GlobalSettings.getInstance().delete(getSelectedItem(), getProject()); profiles.setModel(profilesModel = createProfilesModel()); int itemCount = profiles.getItemCount(); if (selectedIndex < itemCount && selectedIndex >= 0) { Object itemAt = profiles.getItemAt(selectedIndex); importFromInternal((Settings) itemAt); profiles.setSelectedIndex(selectedIndex); } if (selectedIndex == itemCount && selectedIndex - 1 >= 0) { Object itemAt = profiles.getItemAt(selectedIndex - 1); importFromInternal((Settings) itemAt); profiles.setSelectedIndex(selectedIndex - 1); } else { Settings defaultSettings = GlobalSettings.getInstance().getDefaultSettings(); importFromInternal(defaultSettings); profiles.setSelectedItem(defaultSettings); } } }); DONATEButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { BareBonesBrowserLaunch.openURL( "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=75YN7U7H7D7XU&lc=CZ&item_name=Eclipse%20code%20formatter%20%2d%20IntelliJ%20plugin%20%2d%20Donation¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest"); } }); helpButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { BareBonesBrowserLaunch .openURL("http://code.google.com/p/eclipse-code-formatter-intellij-plugin/wiki/HowTo"); } }); ; homepage.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { BareBonesBrowserLaunch.openURL("http://plugins.intellij.net/plugin/?idea&id=6546"); } }); }
From source file:org.jetbrains.idea.maven.execution.MavenSelectProjectPopup.java
License:Apache License
public static void attachToButton(@Nonnull final MavenProjectsManager projectsManager, @Nonnull final JButton button, @Nonnull final Consumer<MavenProject> callback) { button.addActionListener(new ActionListener() { @Override/*from w ww. java 2 s . com*/ public void actionPerformed(ActionEvent e) { List<MavenProject> projectList = projectsManager.getProjects(); if (projectList.isEmpty()) { JBPopupFactory.getInstance().createMessage("Maven projects not found").showUnderneathOf(button); return; } DefaultMutableTreeNode root = buildTree(projectList); final Map<MavenProject, String> projectsNameMap = MavenProjectNamer.generateNameMap(projectList); final Tree projectTree = new Tree(root); projectTree.setRootVisible(false); projectTree.setCellRenderer(new NodeRenderer() { @Override public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (value instanceof DefaultMutableTreeNode) { MavenProject mavenProject = (MavenProject) ((DefaultMutableTreeNode) value) .getUserObject(); value = projectsNameMap.get(mavenProject); setIcon(MavenIcons.MavenProject); } super.customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus); } }); new TreeSpeedSearch(projectTree, new Convertor<TreePath, String>() { @Override public String convert(TreePath o) { Object lastPathComponent = o.getLastPathComponent(); if (!(lastPathComponent instanceof DefaultMutableTreeNode)) return null; Object userObject = ((DefaultMutableTreeNode) lastPathComponent).getUserObject(); //noinspection SuspiciousMethodCalls return projectsNameMap.get(userObject); } }); final Ref<JBPopup> popupRef = new Ref<JBPopup>(); Runnable clickCallBack = new Runnable() { @Override public void run() { TreePath path = projectTree.getSelectionPath(); if (path == null) return; Object lastPathComponent = path.getLastPathComponent(); if (!(lastPathComponent instanceof DefaultMutableTreeNode)) return; Object object = ((DefaultMutableTreeNode) lastPathComponent).getUserObject(); if (object == null) return; // may be it's the root callback.consume((MavenProject) object); popupRef.get().closeOk(null); } }; JBPopup popup = new PopupChooserBuilder(projectTree).setTitle("Select maven project") .setResizable(true).setItemChoosenCallback(clickCallBack).setAutoselectOnMouseMove(true) .setCloseOnEnter(false).createPopup(); popupRef.set(popup); popup.showUnderneathOf(button); } private DefaultMutableTreeNode buildTree(List<MavenProject> projectList) { MavenProject[] projects = projectList.toArray(new MavenProject[projectList.size()]); Arrays.sort(projects, new MavenProjectNamer.MavenProjectComparator()); Map<MavenProject, DefaultMutableTreeNode> projectsToNode = new HashMap<MavenProject, DefaultMutableTreeNode>(); for (MavenProject mavenProject : projects) { projectsToNode.put(mavenProject, new DefaultMutableTreeNode(mavenProject)); } DefaultMutableTreeNode root = new DefaultMutableTreeNode(); for (MavenProject mavenProject : projects) { DefaultMutableTreeNode parent; MavenProject aggregator = projectsManager.findAggregator(mavenProject); if (aggregator != null) { parent = projectsToNode.get(aggregator); } else { parent = root; } parent.add(projectsToNode.get(mavenProject)); } return root; } }); }