Search in sources :

Example 56 with ListSelectionEvent

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

the class AbstractActionModelFactory method getDialogMessage.

private JPanel getDialogMessage(JList<String> actions, JComboBox<String> connections) {
    // NOI18N
    JLabel connectionsLabel = new JLabel(Bundle.getMessage("AbstractActionModelFactory.getDialogMessage.connectionsLabel", JLabel.LEADING));
    actions.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> {
        if (!e.getValueIsAdjusting()) {
            connections.removeAllItems();
            connections.setEnabled(false);
            connectionsLabel.setEnabled(false);
            String name = actions.getSelectedValue();
            if (name != null) {
                String className = StartupActionModelUtil.getDefault().getClassName(name);
                if (className != null && StartupActionModelUtil.getDefault().isSystemConnectionAction(className)) {
                    try {
                        Action action = (Action) Class.forName(className).newInstance();
                        if (SystemConnectionAction.class.isAssignableFrom(action.getClass())) {
                            ((SystemConnectionAction) action).getSystemConnectionMemoClasses().stream().forEach((clazz) -> {
                                InstanceManager.getList(SystemConnectionMemo.class).stream().forEach((memo) -> {
                                    if (clazz.isAssignableFrom(memo.getClass())) {
                                        connections.addItem(memo.getUserName());
                                        connections.setEnabled(true);
                                        connectionsLabel.setEnabled(true);
                                    }
                                });
                            });
                        }
                    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
                        log.error("Unable to create Action", ex);
                    }
                }
            }
        }
    });
    connections.setEnabled(false);
    connectionsLabel.setEnabled(false);
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    panel.add(new JLabel(this.getEditModelMessage(), JLabel.LEADING));
    panel.add(new JScrollPane(actions));
    panel.add(connectionsLabel);
    panel.add(connections);
    return panel;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) SystemConnectionAction(jmri.jmrix.swing.SystemConnectionAction) Action(javax.swing.Action) BoxLayout(javax.swing.BoxLayout) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JLabel(javax.swing.JLabel) SystemConnectionAction(jmri.jmrix.swing.SystemConnectionAction)

Example 57 with ListSelectionEvent

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

the class TabbedPreferences method updateJList.

void updateJList() {
    buttonpanel.removeAll();
    if (list.getListSelectionListeners().length > 0) {
        list.removeListSelectionListener(list.getListSelectionListeners()[0]);
    }
    List<String> choices = this.getChoices();
    list = new JList<>(choices.toArray(new String[choices.size()]));
    listScroller = new JScrollPane(list);
    listScroller.setPreferredSize(new Dimension(100, 100));
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    list.setLayoutOrientation(JList.VERTICAL);
    list.addListSelectionListener((ListSelectionEvent e) -> {
        PreferencesCatItems item = preferencesArray.get(list.getSelectedIndex());
        selection(item.getPrefItem());
    });
    buttonpanel.add(listScroller);
    buttonpanel.add(save);
}
Also used : JScrollPane(javax.swing.JScrollPane) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Dimension(java.awt.Dimension)

Example 58 with ListSelectionEvent

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

the class ColumnTreeBuilder method build.

public JComponent build() {
    // Stash this value since it'll get stomped WideSelectionTreeUI.
    boolean showsRootHandles = myTree.getShowsRootHandles();
    myTree.setUI(new ColumnTreeUI());
    myTree.setShowsRootHandles(showsRootHandles);
    myTree.setCellRenderer(myCellRenderer);
    myTable.getColumnModel().addColumnModelListener(new TableColumnModelListener() {

        @Override
        public void columnAdded(TableColumnModelEvent tableColumnModelEvent) {
        }

        @Override
        public void columnRemoved(TableColumnModelEvent tableColumnModelEvent) {
        }

        @Override
        public void columnMoved(TableColumnModelEvent tableColumnModelEvent) {
        }

        @Override
        public void columnMarginChanged(ChangeEvent changeEvent) {
            myTree.revalidate();
            myTree.repaint();
        }

        @Override
        public void columnSelectionChanged(ListSelectionEvent listSelectionEvent) {
        }
    });
    myTable.setRowSorter(myRowSorter);
    myRowSorter.addRowSorterListener(event -> {
        if (myTreeSorter != null && !myRowSorter.getSortKeys().isEmpty()) {
            RowSorter.SortKey key = myRowSorter.getSortKeys().get(0);
            Comparator<?> comparator = myRowSorter.getComparator(key.getColumn());
            Enumeration<TreePath> expanded = myTree.getExpandedDescendants(new TreePath(myTree.getModel().getRoot()));
            comparator = key.getSortOrder() == SortOrder.ASCENDING ? comparator : Collections.reverseOrder(comparator);
            myTreeSorter.sort(comparator, key.getSortOrder());
            if (expanded != null) {
                while (expanded.hasMoreElements()) {
                    myTree.expandPath(expanded.nextElement());
                }
            }
        }
    });
    myTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
    for (ColumnBuilder column : myColumnBuilders) {
        column.create(myTableModel);
    }
    for (int i = 0; i < myColumnBuilders.size(); i++) {
        ColumnBuilder column = myColumnBuilders.get(i);
        column.configure(i, myTable, myRowSorter, myCellRenderer);
    }
    JPanel panel = new TreeWrapperPanel(myTable, myTree);
    if (myBackground != null) {
        panel.setBackground(myBackground);
    }
    JTableHeader header = myTable.getTableHeader();
    header.setReorderingAllowed(false);
    JViewport viewport = new JViewport();
    viewport.setView(header);
    JBScrollPane scrollPane = new JBScrollPane(panel);
    scrollPane.setColumnHeader(viewport);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    return scrollPane;
}
Also used : TableColumnModelEvent(javax.swing.event.TableColumnModelEvent) TableColumnModelListener(javax.swing.event.TableColumnModelListener) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ChangeEvent(javax.swing.event.ChangeEvent) TreePath(javax.swing.tree.TreePath) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 59 with ListSelectionEvent

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

the class ProjectProfileSelectionDialog method createConflictsPanel.

@NotNull
private JComponent createConflictsPanel() {
    createConflictTree();
    myConflictDetails = new DetailsComponent();
    myConflictDetails.setText("Conflict Detail");
    myConflictDetails.setContent(createTreePanel(myConflictTree));
    removeEmptyBorder(myConflictDetails);
    createConflictsTable();
    myConflictsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            showConflictDetail();
        }
    });
    Splitter splitter = new Splitter(true, .25f);
    splitter.setHonorComponentsMinimumSize(true);
    DetailsComponent details = new DetailsComponent();
    details.setText("Variant Selection Conflicts");
    details.setContent(ScrollPaneFactory.createScrollPane(myConflictsTable));
    removeEmptyBorder(details);
    splitter.setFirstComponent(details.getComponent());
    splitter.setSecondComponent(myConflictDetails.getComponent());
    return splitter;
}
Also used : DetailsComponent(com.intellij.openapi.ui.DetailsComponent) Splitter(com.intellij.openapi.ui.Splitter) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) NotNull(org.jetbrains.annotations.NotNull)

Example 60 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project azure-tools-for-java by Microsoft.

the class WebAppDeployDialog method createUIComponents.

private void createUIComponents() {
    DefaultTableModel tableModel = new DefaultTableModel() {

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    tableModel.addColumn("Name");
    tableModel.addColumn("JDK");
    tableModel.addColumn("Web container");
    tableModel.addColumn("Resource group");
    table = new JBTable(tableModel);
    table.setRowSelectionAllowed(true);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent event) {
            if (event.getValueIsAdjusting())
                return;
            //System.out.println("row : " + table.getValueAt(table.getSelectedRow(), 0).toString());
            fillAppServiceDetails();
        }
    });
    AnActionButton refreshAction = new AnActionButton("Refresh", AllIcons.Actions.Refresh) {

        @Override
        public void actionPerformed(AnActionEvent anActionEvent) {
            refreshAppServices();
        }
    };
    ToolbarDecorator tableToolbarDecorator = ToolbarDecorator.createDecorator(table).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            createAppService();
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            deleteAppService();
        }
    }).setRemoveActionUpdater(new AnActionButtonUpdater() {

        @Override
        public boolean isEnabled(AnActionEvent e) {
            return table.getSelectedRow() != -1;
        }
    }).disableUpDownActions().addExtraActions(refreshAction);
    panelTable = tableToolbarDecorator.createPanel();
}
Also used : AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) AnActionButtonUpdater(com.intellij.ui.AnActionButtonUpdater) DefaultTableModel(javax.swing.table.DefaultTableModel) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) JBTable(com.intellij.ui.table.JBTable) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnActionButton(com.intellij.ui.AnActionButton) 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