Search in sources :

Example 46 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.

the class UnwrapHandler method showPopup.

private static void showPopup(final List<AnAction> options, Editor editor) {
    final ScopeHighlighter highlighter = new ScopeHighlighter(editor);
    DefaultListModel<String> m = new DefaultListModel<>();
    for (AnAction a : options) {
        m.addElement(((MyUnwrapAction) a).getName());
    }
    final JList list = new JBList(m);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setVisibleRowCount(options.size());
    list.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            int index = list.getSelectedIndex();
            if (index < 0)
                return;
            MyUnwrapAction a = (MyUnwrapAction) options.get(index);
            List<PsiElement> toExtract = new ArrayList<>();
            PsiElement wholeRange = a.collectAffectedElements(toExtract);
            highlighter.highlight(wholeRange, toExtract);
        }
    });
    PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(list);
    builder.setTitle(CodeInsightBundle.message("unwrap.popup.title")).setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> {
        MyUnwrapAction a = (MyUnwrapAction) options.get(list.getSelectedIndex());
        a.actionPerformed(null);
    }).addListener(new JBPopupAdapter() {

        @Override
        public void onClosed(LightweightWindowEvent event) {
            highlighter.dropHighlight();
        }
    });
    JBPopup popup = builder.createPopup();
    popup.showInBestPositionFor(editor);
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) ListSelectionListener(javax.swing.event.ListSelectionListener) JBList(com.intellij.ui.components.JBList) ArrayList(java.util.ArrayList) JBList(com.intellij.ui.components.JBList) List(java.util.List) PsiElement(com.intellij.psi.PsiElement)

Example 47 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.

the class MoveInstanceMethodDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    JPanel mainPanel = new JPanel(new GridBagLayout());
    final TitledSeparator separator = new TitledSeparator();
    mainPanel.add(separator, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.emptyInsets(), 0, 0));
    myList = createTargetVariableChooser();
    myList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            validateTextFields(e.getFirstIndex());
        }
    });
    separator.setText(RefactoringBundle.message("moveInstanceMethod.select.an.instance.parameter"));
    final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myList);
    mainPanel.add(scrollPane, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, JBUI.emptyInsets(), 0, 0));
    myVisibilityPanel = createVisibilityPanel();
    mainPanel.add(myVisibilityPanel, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, JBUI.emptyInsets(), 0, 0));
    final JPanel parametersPanel = createParametersPanel();
    if (parametersPanel != null) {
        mainPanel.add(parametersPanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.emptyInsets(), 0, 0));
    }
    mainPanel.add(initOpenInEditorCb(), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, JBUI.emptyInsets(), 0, 0));
    separator.setLabelFor(myList);
    validateTextFields(myList.getSelectedIndex());
    updateOnChanged(myList);
    return mainPanel;
}
Also used : TitledSeparator(com.intellij.ui.TitledSeparator) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 48 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.

the class FileTypeConfigurable method createComponent.

@Override
public JComponent createComponent() {
    myFileTypePanel = new FileTypePanel();
    myRecognizedFileType = myFileTypePanel.myRecognizedFileType;
    myPatterns = myFileTypePanel.myPatterns;
    myRecognizedFileType.attachActions(this);
    myRecognizedFileType.myFileTypesList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(@Nullable ListSelectionEvent e) {
            updateExtensionList();
        }
    });
    myPatterns.attachActions(this);
    myFileTypePanel.myIgnoreFilesField.setColumns(30);
    return myFileTypePanel.getComponent();
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 49 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.

the class MasterDetailPopupBuilder method setList.

@NotNull
public MasterDetailPopupBuilder setList(@NotNull JBList list) {
    myChooserComponent = list;
    myDetailController.setList(list);
    list.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                removeSelectedItems();
            } else if (e.getModifiersEx() == 0) {
                myDelegate.handleMnemonic(e, myProject, myPopup);
            }
        }
    });
    new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            chooseItems(true);
        }
    }.registerCustomShortcutSet(CommonShortcuts.ENTER, list);
    new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            chooseItems(true);
        }
    }.registerCustomShortcutSet(CommonShortcuts.DOUBLE_CLICK_1, list);
    list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent event) {
            myDetailController.updateDetailView();
        }
    });
    return this;
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) NotNull(org.jetbrains.annotations.NotNull)

Example 50 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project jabref by JabRef.

the class EntryCustomizationDialog method applyChanges.

private void applyChanges() {
    valueChanged(new ListSelectionEvent(new JList<>(), 0, 0, false));
    List<String> actuallyChangedTypes = new ArrayList<>();
    // Iterate over our map of required fields, and list those types if necessary:
    List<String> types = typeComp.getFields();
    for (Map.Entry<String, List<String>> stringListEntry : reqLists.entrySet()) {
        if (!types.contains(stringListEntry.getKey())) {
            continue;
        }
        List<String> requiredFieldsList = stringListEntry.getValue();
        List<String> optionalFieldsList = optLists.get(stringListEntry.getKey());
        List<String> secondaryOptionalFieldsLists = opt2Lists.get(stringListEntry.getKey());
        if (secondaryOptionalFieldsLists == null) {
            secondaryOptionalFieldsLists = new ArrayList<>(0);
        }
        // If this type is already existing, check if any changes have
        // been made
        boolean changesMade = true;
        if (defaulted.contains(stringListEntry.getKey())) {
            // This type should be reverted to its default setup.
            EntryTypes.removeType(stringListEntry.getKey(), bibDatabaseMode);
            actuallyChangedTypes.add(stringListEntry.getKey().toLowerCase(Locale.ENGLISH));
            defaulted.remove(stringListEntry.getKey());
            continue;
        }
        Optional<EntryType> oldType = EntryTypes.getType(stringListEntry.getKey(), bibDatabaseMode);
        if (oldType.isPresent()) {
            List<String> oldRequiredFieldsList = oldType.get().getRequiredFieldsFlat();
            List<String> oldOptionalFieldsList = oldType.get().getOptionalFields();
            if (biblatexMode) {
                List<String> oldPrimaryOptionalFieldsLists = oldType.get().getPrimaryOptionalFields();
                List<String> oldSecondaryOptionalFieldsList = oldType.get().getSecondaryOptionalFields();
                if (equalLists(oldRequiredFieldsList, requiredFieldsList) && equalLists(oldPrimaryOptionalFieldsLists, optionalFieldsList) && equalLists(oldSecondaryOptionalFieldsList, secondaryOptionalFieldsLists)) {
                    changesMade = false;
                }
            } else if (equalLists(oldRequiredFieldsList, requiredFieldsList) && equalLists(oldOptionalFieldsList, optionalFieldsList)) {
                changesMade = false;
            }
        }
        if (changesMade) {
            CustomEntryType customType = biblatexMode ? new CustomEntryType(StringUtil.capitalizeFirst(stringListEntry.getKey()), requiredFieldsList, optionalFieldsList, secondaryOptionalFieldsLists) : new CustomEntryType(StringUtil.capitalizeFirst(stringListEntry.getKey()), requiredFieldsList, optionalFieldsList);
            EntryTypes.addOrModifyCustomEntryType(customType, bibDatabaseMode);
            actuallyChangedTypes.add(customType.getName().toLowerCase(Locale.ENGLISH));
        }
    }
    // update all affected entries if something has been changed
    if (!actuallyChangedTypes.isEmpty()) {
        updateEntriesForChangedTypes(actuallyChangedTypes);
    }
    Set<String> typesToRemove = new HashSet<>();
    for (String existingType : EntryTypes.getAllTypes(bibDatabaseMode)) {
        if (!types.contains(existingType)) {
            typesToRemove.add(existingType);
        }
    }
    // Remove those that should be removed:
    if (!typesToRemove.isEmpty()) {
        for (String typeToRemove : typesToRemove) {
            deleteType(typeToRemove);
        }
    }
    updateTables();
    CustomEntryTypesManager.saveCustomEntryTypes(Globals.prefs);
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) ArrayList(java.util.ArrayList) CustomEntryType(org.jabref.model.entry.CustomEntryType) CustomEntryType(org.jabref.model.entry.CustomEntryType) EntryType(org.jabref.model.entry.EntryType) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ActionMap(javax.swing.ActionMap) InputMap(javax.swing.InputMap) JList(javax.swing.JList) HashSet(java.util.HashSet)

Aggregations

ListSelectionEvent (javax.swing.event.ListSelectionEvent)129 ListSelectionListener (javax.swing.event.ListSelectionListener)120 ActionEvent (java.awt.event.ActionEvent)35 JScrollPane (javax.swing.JScrollPane)32 ActionListener (java.awt.event.ActionListener)29 JPanel (javax.swing.JPanel)28 MouseEvent (java.awt.event.MouseEvent)25 BorderLayout (java.awt.BorderLayout)21 JButton (javax.swing.JButton)20 Dimension (java.awt.Dimension)18 JLabel (javax.swing.JLabel)18 JBList (com.intellij.ui.components.JBList)16 MouseAdapter (java.awt.event.MouseAdapter)15 FlowLayout (java.awt.FlowLayout)11 Insets (java.awt.Insets)11 JList (javax.swing.JList)11 NotNull (org.jetbrains.annotations.NotNull)11 KeyAdapter (java.awt.event.KeyAdapter)10 KeyEvent (java.awt.event.KeyEvent)10 ArrayList (java.util.ArrayList)10