Search in sources :

Example 86 with ListSelectionEvent

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

the class SelectTagDialog method createList.

private void createList(String title, Collection<String> data, String listDescription) {
    setTitle(title);
    final JList list = new JBList();
    myLists.add(list);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (list.getSelectedValue() != null)
                cancelOtherSelections(list);
            setOkEnabled();
        }
    });
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            if (isOKActionEnabled()) {
                doOKAction();
                return true;
            }
            return false;
        }
    }.installOn(list);
    fillList(data, list);
    JPanel panel = new JPanel(new BorderLayout(4, 4));
    panel.add(new JLabel(listDescription, JLabel.LEFT), BorderLayout.NORTH);
    panel.add(ScrollPaneFactory.createScrollPane(list), BorderLayout.CENTER);
    myPanel.add(panel);
}
Also used : MouseEvent(java.awt.event.MouseEvent) DoubleClickListener(com.intellij.ui.DoubleClickListener) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JBList(com.intellij.ui.components.JBList) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 87 with ListSelectionEvent

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

the class HintUpdateSupply method installTableListener.

protected void installTableListener(@NotNull final JTable table) {
    ListSelectionListener listener = new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent e) {
            if (!isHintVisible(HintUpdateSupply.this.myHint) || isSelectedByMouse(table))
                return;
            int selected = ((ListSelectionModel) e.getSource()).getLeadSelectionIndex();
            int rowCount = table.getRowCount();
            if (selected == -1 || rowCount == 0)
                return;
            PsiElement element = getPsiElementForHint(table.getValueAt(Math.min(selected, rowCount - 1), 0));
            if (element != null && element.isValid()) {
                updateHint(element);
            }
        }
    };
    table.getSelectionModel().addListSelectionListener(listener);
    table.getColumnModel().getSelectionModel().addListSelectionListener(listener);
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) PsiElement(com.intellij.psi.PsiElement) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 88 with ListSelectionEvent

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

the class OverridingMethodsDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(BorderFactory.createEmptyBorder(8, 0, 4, 0));
    final MyTableModel tableModel = new MyTableModel();
    myTable = new Table(tableModel);
    myTable.setShowGrid(false);
    TableColumnModel columnModel = myTable.getColumnModel();
    //    columnModel.getColumn(DISPLAY_NAME_COLUMN).setCellRenderer(new MemberSelectionTable.MyTableRenderer());
    TableColumn checkboxColumn = columnModel.getColumn(CHECK_COLUMN);
    TableUtil.setupCheckboxColumn(checkboxColumn);
    checkboxColumn.setCellRenderer(new BooleanTableCellRenderer());
    // make SPACE check/uncheck selected rows
    @NonNls InputMap inputMap = myTable.getInputMap();
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "enable_disable");
    @NonNls final ActionMap actionMap = myTable.getActionMap();
    actionMap.put("enable_disable", new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            if (myTable.isEditing())
                return;
            int[] rows = myTable.getSelectedRows();
            if (rows.length > 0) {
                boolean valueToBeSet = false;
                for (int row : rows) {
                    if (!myChecked[row]) {
                        valueToBeSet = true;
                        break;
                    }
                }
                for (int row : rows) {
                    myChecked[row] = valueToBeSet;
                }
                tableModel.updateData();
            }
        }
    });
    /*Border titledBorder = IdeBorderFactory.createBoldTitledBorder("Select methods");
    Border emptyBorder = BorderFactory.createEmptyBorder(0, 5, 5, 5);
    Border border = BorderFactory.createCompoundBorder(titledBorder, emptyBorder);
    panel.setBorder(border);*/
    panel.setLayout(new BorderLayout());
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable);
    panel.add(scrollPane, BorderLayout.CENTER);
    ListSelectionListener selectionListener = new ListSelectionListener() {

        public void valueChanged(final ListSelectionEvent e) {
            int index = myTable.getSelectionModel().getLeadSelectionIndex();
            if (index != -1) {
                UsageInfo usageInfo = myOverridingMethods.get(index);
                myUsagePreviewPanel.updateLayout(Collections.singletonList(usageInfo));
            } else {
                myUsagePreviewPanel.updateLayout(null);
            }
        }
    };
    myTable.getSelectionModel().addListSelectionListener(selectionListener);
    final Splitter splitter = new Splitter(true, 0.3f);
    splitter.setFirstComponent(panel);
    splitter.setSecondComponent(myUsagePreviewPanel);
    myUsagePreviewPanel.updateLayout(null);
    Disposer.register(myDisposable, new Disposable() {

        public void dispose() {
            splitter.dispose();
        }
    });
    if (tableModel.getRowCount() != 0) {
        myTable.getSelectionModel().addSelectionInterval(0, 0);
    }
    return splitter;
}
Also used : Disposable(com.intellij.openapi.Disposable) NonNls(org.jetbrains.annotations.NonNls) Table(com.intellij.util.ui.Table) Splitter(com.intellij.openapi.ui.Splitter) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn) ListSelectionListener(javax.swing.event.ListSelectionListener) BooleanTableCellRenderer(com.intellij.ui.BooleanTableCellRenderer) UsageInfo(com.intellij.usageView.UsageInfo) SafeDeleteOverridingMethodUsageInfo(com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteOverridingMethodUsageInfo)

Example 89 with ListSelectionEvent

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

the class MoveInstanceMethodDialogBase method createTargetVariableChooser.

protected JList createTargetVariableChooser() {
    final JList list = new JBList(new MyListModel());
    list.setCellRenderer(new MyListCellRenderer());
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);
    list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            updateOnChanged(list);
        }
    });
    return list;
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) JBList(com.intellij.ui.components.JBList) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 90 with ListSelectionEvent

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

the class ImportSourceChooserDialog method initSourceList.

private void initSourceList() {
    mySourceList.setModel(myListModel);
    mySourceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    mySourceList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            int index = mySourceList.getSelectedIndex();
            if (index >= 0) {
                setSelectedSourceName((String) myListModel.getElementAt(index));
            }
        }
    });
    mySourceList.setSelectedIndex(0);
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener)

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