Search in sources :

Example 96 with ListSelectionEvent

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

the class MavenRepositoriesConfigurable method configControls.

private void configControls() {
    myServiceList.setModel(myModel);
    myServiceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myAddButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final String value = (String) myServiceList.getSelectedValue();
            final String text = Messages.showInputDialog("Artifactory or Nexus Service URL", "Add Service URL", Messages.getQuestionIcon(), value == null ? "http://" : value, new URLInputVaslidator());
            if (StringUtil.isNotEmpty(text)) {
                myModel.add(text);
                myServiceList.setSelectedValue(text, true);
            }
        }
    });
    myEditButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final int index = myServiceList.getSelectedIndex();
            final String text = Messages.showInputDialog("Artifactory or Nexus Service URL", "Edit Service URL", Messages.getQuestionIcon(), myModel.getElementAt(index), new URLInputVaslidator());
            if (StringUtil.isNotEmpty(text)) {
                myModel.setElementAt(text, index);
            }
        }
    });
    ListUtil.addRemoveListener(myRemoveButton, myServiceList);
    ListUtil.disableWhenNoSelection(myTestButton, myServiceList);
    ListUtil.disableWhenNoSelection(myEditButton, myServiceList);
    myTestButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final String value = (String) myServiceList.getSelectedValue();
            if (value != null) {
                testServiceConnection(value);
            }
        }
    });
    myUpdateButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            doUpdateIndex();
        }
    });
    myIndicesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            updateButtonsState();
        }
    });
    myIndicesTable.addMouseMotionListener(new MouseMotionListener() {

        public void mouseDragged(MouseEvent e) {
        }

        public void mouseMoved(MouseEvent e) {
            int row = myIndicesTable.rowAtPoint(e.getPoint());
            if (row == -1)
                return;
            updateIndexHint(row);
        }
    });
    myIndicesTable.setDefaultRenderer(Object.class, new MyCellRenderer());
    myIndicesTable.setDefaultRenderer(MavenIndicesManager.IndexUpdatingState.class, new MyIconCellRenderer());
    myServiceList.getEmptyText().setText("No services");
    myIndicesTable.getEmptyText().setText("No remote repositories");
    updateButtonsState();
}
Also used : MouseEvent(java.awt.event.MouseEvent) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) MouseMotionListener(java.awt.event.MouseMotionListener) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 97 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project kotlin by JetBrains.

the class KotlinOverridingDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(BorderFactory.createEmptyBorder(8, 0, 4, 0));
    final MyTableModel tableModel = new MyTableModel();
    myTable = new JBTable(tableModel);
    myTable.setShowGrid(false);
    TableColumnModel columnModel = myTable.getColumnModel();
    int checkBoxWidth = new JCheckBox().getPreferredSize().width;
    columnModel.getColumn(CHECK_COLUMN).setCellRenderer(new BooleanTableCellRenderer());
    columnModel.getColumn(CHECK_COLUMN).setMaxWidth(checkBoxWidth);
    columnModel.getColumn(CHECK_COLUMN).setMinWidth(checkBoxWidth);
    // make SPACE check/uncheck selected rows
    InputMap inputMap = myTable.getInputMap();
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "enable_disable");
    ActionMap actionMap = myTable.getActionMap();
    actionMap.put("enable_disable", new AbstractAction() {

        @Override
        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();
            }
        }
    });
    panel.setLayout(new BorderLayout());
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable);
    panel.add(scrollPane, BorderLayout.CENTER);
    ListSelectionListener selectionListener = new ListSelectionListener() {

        @Override
        public void valueChanged(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() {

        @Override
        public void dispose() {
            splitter.dispose();
        }
    });
    if (tableModel.getRowCount() != 0) {
        myTable.getSelectionModel().addSelectionInterval(0, 0);
    }
    return splitter;
}
Also used : Disposable(com.intellij.openapi.Disposable) Splitter(com.intellij.openapi.ui.Splitter) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) TableColumnModel(javax.swing.table.TableColumnModel) JBTable(com.intellij.ui.table.JBTable) ListSelectionListener(javax.swing.event.ListSelectionListener) BooleanTableCellRenderer(com.intellij.ui.BooleanTableCellRenderer) UsageInfo(com.intellij.usageView.UsageInfo)

Example 98 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project android by JetBrains.

the class ConfigureAvdOptionsStep method bindComponents.

private void bindComponents() {
    myBindings.bindTwoWay(new TextProperty(myAvdDisplayName), getModel().avdDisplayName());
    myBindings.bind(new TextProperty(myAvdId), new StringExpression(getModel().avdDisplayName()) {

        @NotNull
        @Override
        public String get() {
            String displayName = getModel().avdDisplayName().get();
            getModel().avdId().set(StringUtil.isNotEmpty(displayName) ? AvdWizardUtils.cleanAvdName(connection, displayName, !displayName.equals(myOriginalName)) : "");
            return getModel().avdId().get();
        }
    });
    myBindings.bindTwoWay(new TextProperty(mySystemImageName), getModel().systemImageName());
    myBindings.bindTwoWay(new TextProperty(mySystemImageDetails), getModel().systemImageDetails());
    myBindings.bindTwoWay(new SelectedProperty(myQemu2CheckBox), getModel().useQemu2());
    myBindings.bindTwoWay(new SelectedItemProperty<Integer>(myCoreCount), getModel().cpuCoreCount());
    myBindings.bindTwoWay(myRamStorage.storage(), getModel().getAvdDeviceData().ramStorage());
    myBindings.bindTwoWay(myVmHeapStorage.storage(), getModel().vmHeapStorage());
    myBindings.bindTwoWay(myInternalStorage.storage(), getModel().internalStorage());
    myBindings.bindTwoWay(myBuiltInSdCardStorage.storage(), new OptionalToValuePropertyAdapter<Storage>(getModel().sdCardStorage()));
    myBindings.bindTwoWay(new SelectedItemProperty<GpuMode>(myHostGraphics), getModel().hostGpuMode());
    myBindings.bindTwoWay(new SelectedProperty(myDeviceFrameCheckbox), getModel().hasDeviceFrame());
    myBindings.bindTwoWay(new SelectedItemProperty<File>(mySkinComboBox.getComboBox()), getModel().getAvdDeviceData().customSkinFile());
    myOrientationToggle.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            ScreenOrientation orientation = myOrientationToggle.getSelectedElement();
            if (orientation == null) {
                getModel().selectedAvdOrientation().set(ScreenOrientation.PORTRAIT);
            } else {
                getModel().selectedAvdOrientation().set(orientation);
            }
        }
    });
    FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, false) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return super.isFileVisible(file, true);
        }
    };
    fileChooserDescriptor.setHideIgnored(false);
    myExternalSdCard.addBrowseFolderListener("Select SD Card", "Select an existing SD card image", myProject, fileChooserDescriptor);
    myBindings.bindTwoWay(new TextProperty(myExternalSdCard.getTextField()), getModel().externalSdCardLocation());
    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdCamera>(new SelectedItemProperty<AvdCamera>(myFrontCameraCombo)), getModel().selectedFrontCamera());
    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdCamera>(new SelectedItemProperty<AvdCamera>(myBackCameraCombo)), getModel().selectedBackCamera());
    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdNetworkSpeed>(new SelectedItemProperty<AvdNetworkSpeed>(mySpeedCombo)), getModel().selectedNetworkSpeed());
    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdNetworkLatency>(new SelectedItemProperty<AvdNetworkLatency>(myLatencyCombo)), getModel().selectedNetworkLatency());
    myBindings.bindTwoWay(new SelectedProperty(myEnableComputerKeyboard), getModel().enableHardwareKeyboard());
    myBindings.bindTwoWay(new SelectedProperty(myExternalRadioButton), getModel().useExternalSdCard());
    myBindings.bindTwoWay(new SelectedProperty(myBuiltInRadioButton), getModel().useBuiltInSdCard());
    myCheckSdForChanges = true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GpuMode(com.android.sdklib.internal.avd.GpuMode) ListSelectionEvent(javax.swing.event.ListSelectionEvent) NotNull(org.jetbrains.annotations.NotNull) TextProperty(com.android.tools.idea.ui.properties.swing.TextProperty) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ListSelectionListener(javax.swing.event.ListSelectionListener) ScreenOrientation(com.android.resources.ScreenOrientation) SelectedItemProperty(com.android.tools.idea.ui.properties.swing.SelectedItemProperty) StringExpression(com.android.tools.idea.ui.properties.expressions.string.StringExpression) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) SelectedProperty(com.android.tools.idea.ui.properties.swing.SelectedProperty)

Example 99 with ListSelectionEvent

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

the class CPUSnapshotView method createHotSpotsTreeTable.

private void createHotSpotsTreeTable() {
    myHotSpotsTreeTable = new CallTreeTable(getProject());
    myHotSpotsTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            final Object node = myHotSpotsTreeTable.getSelectedValue();
            if (!(node instanceof MergedCallNode))
                return;
            myAlarm.cancelAllRequests();
            final MergedCallNode mergedCallNode = (MergedCallNode) node;
            myAlarm.addRequest(() -> {
                FrameInfo[] frames = new FrameInfo[] { mergedCallNode.getFrameInfo() };
                final Pair<Map<FrameInfo, Long>, Map<FrameInfo, Long>> countMaps = mergedCallNode.getCallTree().getCalleesTimeMaps(frames);
                final Map<FrameInfo, Long> countMap = countMaps.getFirst();
                final Map<FrameInfo, Long> selfCountMap = countMaps.getSecond();
                DefaultMutableTreeNode tracesRoot = (DefaultMutableTreeNode) myTracesTreeTable.getSortableTreeTableModel().getRoot();
                JTreeUtil.removeChildren(tracesRoot, myTracesTreeTable.getSortableTreeTableModel());
                fillTreeModelRoot(tracesRoot, mergedCallNode.getCallTree(), countMap, selfCountMap, false, frames);
                myTracesTreeTable.reload();
                TreeUtil.expand(myTracesTreeTable.getTree(), 1);
            }, 500);
        }
    });
}
Also used : FrameInfo(com.jetbrains.actionscript.profiler.sampler.FrameInfo) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) MergedCallNode(com.jetbrains.actionscript.profiler.calltreetable.MergedCallNode) ListSelectionEvent(javax.swing.event.ListSelectionEvent) CallTreeTable(com.jetbrains.actionscript.profiler.calltreetable.CallTreeTable) Map(java.util.Map) ListSelectionListener(javax.swing.event.ListSelectionListener) Pair(com.intellij.openapi.util.Pair)

Example 100 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project JMRI by JMRI.

the class RowComboBoxPanel method getTableCellEditorComponent.

/**
     * Create the editor component for the cell and add a listener for changes in the table.
     *
     * @param table parent JTable of NamedBean
     * @param value current value for cell to be rendered.
     * @param isSelected tells if this row is selected in the table.
     * @param row the row in table.
     * @param col the column in table, in this case Value (Aspect or Appearance).
     * @return A JPanel containing a JComboBox with valid options as the CellEditor for the Value.
     */
@Override
public final Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int col) {
    //add a listener to the table
    if (!this.tableListenerAdded) {
        this.tableListenerAdded = true;
        this.table = table;
        this.table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public final void valueChanged(ListSelectionEvent evt) {
                eventTableSelectionChanged();
            }
        });
    }
    this.currentRow = row;
    updateData(row, true, table);
    return getEditorComponent(table, value, isSelected, row, col);
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener)

Aggregations

ListSelectionEvent (javax.swing.event.ListSelectionEvent)110 ListSelectionListener (javax.swing.event.ListSelectionListener)101 ActionEvent (java.awt.event.ActionEvent)29 ActionListener (java.awt.event.ActionListener)23 JPanel (javax.swing.JPanel)22 JScrollPane (javax.swing.JScrollPane)22 MouseEvent (java.awt.event.MouseEvent)21 JButton (javax.swing.JButton)18 JBList (com.intellij.ui.components.JBList)16 BorderLayout (java.awt.BorderLayout)16 JLabel (javax.swing.JLabel)16 MouseAdapter (java.awt.event.MouseAdapter)11 NotNull (org.jetbrains.annotations.NotNull)11 FlowLayout (java.awt.FlowLayout)10 Insets (java.awt.Insets)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Dimension (java.awt.Dimension)8 KeyAdapter (java.awt.event.KeyAdapter)8 KeyEvent (java.awt.event.KeyEvent)8