Search in sources :

Example 81 with ListSelectionEvent

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

the class FinderRecursivePanel method createList.

protected JBList<T> createList() {
    final JBList<T> list = new JBList<>(myListModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setEmptyText(getListEmptyText());
    list.setCellRenderer(createListCellRenderer());
    installListActions(list);
    list.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent event) {
            if (event.getValueIsAdjusting())
                return;
            if (isMergeListItemsRunning())
                return;
            if (myUpdateSelectedPathModeActive.get())
                return;
            updateRightComponent(true);
        }
    });
    ScrollingUtil.installActions(list);
    //    installSpeedSearch(list); // TODO
    installEditOnDoubleClick(list);
    return list;
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) JBList(com.intellij.ui.components.JBList) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 82 with ListSelectionEvent

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

the class AttachToLocalProcessAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = getEventProject(e);
    if (project == null)
        return;
    XLocalAttachDebuggerProvider[] providers = Extensions.getExtensions(XLocalAttachDebuggerProvider.EP);
    new Task.Backgroundable(project, XDebuggerBundle.message("xdebugger.attach.toLocal.action.collectingProcesses"), true, PerformInBackgroundOption.DEAF) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            ProcessInfo[] processList = OSProcessUtil.getProcessList();
            List<AttachItem> items = collectAttachItems(project, processList, indicator, providers);
            ApplicationManager.getApplication().invokeLater(() -> {
                if (project.isDisposed()) {
                    return;
                }
                ProcessListStep step = new ProcessListStep(items, project);
                final ListPopup popup = JBPopupFactory.getInstance().createListPopup(step);
                final JList mainList = ((ListPopupImpl) popup).getList();
                ListSelectionListener listener = event -> {
                    if (event.getValueIsAdjusting())
                        return;
                    Object item = ((JList) event.getSource()).getSelectedValue();
                    if (item == null) {
                        item = mainList.getSelectedValue();
                    }
                    if (item instanceof AttachItem) {
                        String debuggerName = ((AttachItem) item).getSelectedDebugger().getDebuggerDisplayName();
                        debuggerName = StringUtil.shortenTextWithEllipsis(debuggerName, 50, 0);
                        ((ListPopupImpl) popup).setCaption(XDebuggerBundle.message("xdebugger.attach.toLocal.popup.title", debuggerName));
                    }
                };
                popup.addListSelectionListener(listener);
                // force first valueChanged event
                listener.valueChanged(new ListSelectionEvent(mainList, mainList.getMinSelectionIndex(), mainList.getMaxSelectionIndex(), false));
                popup.showCenteredInCurrentWindow(project);
            });
        }
    }.queue();
}
Also used : Task(com.intellij.openapi.progress.Task) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) Project(com.intellij.openapi.project.Project) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) XLocalAttachDebuggerProvider(com.intellij.xdebugger.attach.XLocalAttachDebuggerProvider)

Example 83 with ListSelectionEvent

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

the class RevisionsList method addSelectionListener.

private void addSelectionListener(SelectionListener listener) {
    final SelectionListener l = listener;
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        private int mySelectedRow1 = 0;

        private int mySelectedRow2 = 0;

        private final SelectionListener mySelectionListener = l;

        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
                return;
            ListSelectionModel sm = table.getSelectionModel();
            mySelectedRow1 = sm.getMinSelectionIndex();
            mySelectedRow2 = sm.getMaxSelectionIndex();
            mySelectionListener.revisionsSelected(mySelectedRow1, mySelectedRow2);
        }
    });
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 84 with ListSelectionEvent

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

the class ContentChooser method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    final int selectionMode = myAllowMultipleSelections ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION;
    myList.setSelectionMode(selectionMode);
    if (myUseIdeaEditor) {
        EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
        myList.setFont(scheme.getFont(EditorFontType.PLAIN));
        Color fg = ObjectUtils.chooseNotNull(scheme.getDefaultForeground(), new JBColor(UIUtil::getListForeground));
        Color bg = ObjectUtils.chooseNotNull(scheme.getDefaultBackground(), new JBColor(UIUtil::getListBackground));
        myList.setForeground(fg);
        myList.setBackground(bg);
    }
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            close(OK_EXIT_CODE);
            return true;
        }
    }.installOn(myList);
    MyListCellRenderer renderer = new MyListCellRenderer();
    myList.setCellRenderer(renderer);
    myList.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                int newSelectionIndex = -1;
                for (Object o : myList.getSelectedValuesList()) {
                    int i = ((Item) o).index;
                    removeContentAt(myAllContents.get(i));
                    if (newSelectionIndex < 0) {
                        newSelectionIndex = i;
                    }
                }
                rebuildListContent();
                if (myAllContents.isEmpty()) {
                    close(CANCEL_EXIT_CODE);
                    return;
                }
                newSelectionIndex = Math.min(newSelectionIndex, myAllContents.size() - 1);
                myList.setSelectedIndex(newSelectionIndex);
            } else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                doOKAction();
            } else {
                SpeedSearchSupply supply = SpeedSearchSupply.getSupply(myList);
                if (supply != null && supply.isPopupActive())
                    return;
                char aChar = e.getKeyChar();
                if (aChar >= '0' && aChar <= '9') {
                    int idx = aChar == '0' ? 9 : aChar - '1';
                    if (idx < myAllContents.size()) {
                        myList.setSelectedIndex(idx);
                        e.consume();
                        doOKAction();
                    }
                }
            }
        }
    });
    mySplitter.setFirstComponent(ListWithFilter.wrap(myList, ScrollPaneFactory.createScrollPane(myList), o -> o.getShortText(renderer.previewChars)));
    mySplitter.setSecondComponent(new JPanel());
    mySplitter.getFirstComponent().addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            FontMetrics metrics = myList.getFontMetrics(myList.getFont());
            int charWidth = metrics.charWidth('m');
            renderer.previewChars = myList.getParent().getParent().getWidth() / charWidth + 10;
        }
    });
    rebuildListContent();
    ScrollingUtil.installActions(myList);
    ScrollingUtil.ensureSelectionExists(myList);
    updateViewerForSelection();
    myList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (myUpdateAlarm.isDisposed())
                return;
            myUpdateAlarm.cancelAllRequests();
            myUpdateAlarm.addRequest(() -> updateViewerForSelection(), 100);
        }
    });
    mySplitter.setPreferredSize(JBUI.size(500, 500));
    SplitterProportionsData d = new SplitterProportionsDataImpl();
    d.externalizeToDimensionService(getClass().getName());
    d.restoreSplitterProportions(mySplitter);
    return mySplitter;
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) Arrays(java.util.Arrays) AllIcons(com.intellij.icons.AllIcons) JBIterable(com.intellij.util.containers.JBIterable) Document(com.intellij.openapi.editor.Document) EditorFontType(com.intellij.openapi.editor.colors.EditorFontType) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) ListWithFilter(com.intellij.ui.speedSearch.ListWithFilter) ArrayList(java.util.ArrayList) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) JBUI(com.intellij.util.ui.JBUI) CommonBundle(com.intellij.CommonBundle) Project(com.intellij.openapi.project.Project) SpeedSearchUtil(com.intellij.ui.speedSearch.SpeedSearchUtil) FilteringListModel(com.intellij.ui.speedSearch.FilteringListModel) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JBList(com.intellij.ui.components.JBList) SplitterProportionsDataImpl(com.intellij.ide.ui.SplitterProportionsDataImpl) StringUtil(com.intellij.openapi.util.text.StringUtil) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Editor(com.intellij.openapi.editor.Editor) com.intellij.ui(com.intellij.ui) SpeedSearchSupply(com.intellij.ui.speedSearch.SpeedSearchSupply) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SplitterProportionsData(com.intellij.openapi.ui.SplitterProportionsData) java.awt.event(java.awt.event) EditorFactory(com.intellij.openapi.editor.EditorFactory) ObjectUtils(com.intellij.util.ObjectUtils) NotNull(org.jetbrains.annotations.NotNull) ListSelectionListener(javax.swing.event.ListSelectionListener) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) SplitterProportionsData(com.intellij.openapi.ui.SplitterProportionsData) SplitterProportionsDataImpl(com.intellij.ide.ui.SplitterProportionsDataImpl) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) SpeedSearchSupply(com.intellij.ui.speedSearch.SpeedSearchSupply) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 85 with ListSelectionEvent

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

the class SaveMetaTargetDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    final JPanel panel = new JPanel(new GridBagLayout());
    final JLabel nameLabel = new JLabel(AntBundle.message("save.meta.data.name.label"));
    panel.add(nameLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
    myTfName = new JTextField(myInitialEvent.getPresentableName());
    nameLabel.setLabelFor(myTfName);
    myTfName.selectAll();
    panel.add(myTfName, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, JBUI.insetsTop(4), 0, 0));
    final DefaultListModel dataModel = new DefaultListModel();
    myTargetList = new JBList(dataModel);
    final String[] targetNames = myInitialEvent.getTargetNames();
    for (String name : targetNames) {
        dataModel.addElement(name);
    }
    panel.add(new JLabel(AntBundle.message("save.meta.data.targets.label")), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insetsTop(6), 0, 0));
    panel.add(ScrollPaneFactory.createScrollPane(myTargetList), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 2, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, JBUI.insetsTop(4), 0, 0));
    final JButton upButton = new JButton(AntBundle.message("button.move.up"));
    panel.add(upButton, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, JBUI.insets(6, 6, 0, 0), 0, 0));
    final JButton downButton = new JButton(AntBundle.message("button.move.down"));
    panel.add(downButton, new GridBagConstraints(1, 4, 1, GridBagConstraints.REMAINDER, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, JBUI.insetsLeft(6), 0, 0));
    class UpdateAction implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            upButton.setEnabled(ListUtil.canMoveSelectedItemsUp(myTargetList));
            downButton.setEnabled(ListUtil.canMoveSelectedItemsDown(myTargetList));
        }
    }
    upButton.addActionListener(new UpdateAction() {

        public void actionPerformed(ActionEvent e) {
            ListUtil.moveSelectedItemsUp(myTargetList);
            super.actionPerformed(e);
        }
    });
    downButton.addActionListener(new UpdateAction() {

        public void actionPerformed(ActionEvent e) {
            ListUtil.moveSelectedItemsDown(myTargetList);
            super.actionPerformed(e);
        }
    });
    myTargetList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            upButton.setEnabled(ListUtil.canMoveSelectedItemsUp(myTargetList));
            downButton.setEnabled(ListUtil.canMoveSelectedItemsDown(myTargetList));
        }
    });
    myTargetList.setSelectedIndex(0);
    return panel;
}
Also used : ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) JBList(com.intellij.ui.components.JBList)

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