List of usage examples for com.intellij.openapi.ui.popup ListPopup showInFocusCenter
void showInFocusCenter();
From source file:com.intellij.ide.actions.GotoActionAction.java
License:Apache License
public static void performAction(Object element, @Nullable final Component component, @Nullable final AnActionEvent e) { // element could be AnAction (SearchEverywhere) final AnAction action = element instanceof AnAction ? (AnAction) element : ((GotoActionModel.ActionWrapper) element).getAction(); if (action != null) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override/*from w w w. j a va 2s .co m*/ public void run() { if (component == null) return; Presentation presentation = action.getTemplatePresentation().clone(); DataContext context = DataManager.getInstance().getDataContext(component); AnActionEvent event = new AnActionEvent(e == null ? null : e.getInputEvent(), context, ActionPlaces.ACTION_SEARCH, presentation, ActionManager.getInstance(), e == null ? 0 : e.getModifiers()); if (ActionUtil.lastUpdateAndCheckDumb(action, event, false)) { if (action instanceof ActionGroup && ((ActionGroup) action).getChildren(event).length > 0) { ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup( presentation.getText(), (ActionGroup) action, context, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false); if (component.isShowing()) { popup.showInBestPositionFor(context); } else { popup.showInFocusCenter(); } } else { ActionUtil.performActionDumbAware(action, event); } } } }, ModalityState.NON_MODAL); } }
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 www .j a v a 2 s . com } }); } 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"); } }); }