Search in sources :

Example 66 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project cytoscape-impl by cytoscape.

the class ColumnSelector method getTable.

private JTable getTable() {
    if (table == null) {
        final DefaultSelectorTableCellRenderer defRenderer = new DefaultSelectorTableCellRenderer();
        final CheckBoxTableCellRenderer checkBoxRenderer = new CheckBoxTableCellRenderer();
        table = new JTable(new DefaultTableModel(headerNames, 0)) {

            @Override
            public TableCellRenderer getCellRenderer(int row, int column) {
                if (column == SELECTED_COL_IDX)
                    return checkBoxRenderer;
                return defRenderer;
            }
        };
        table.setTableHeader(null);
        table.setShowGrid(false);
        table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    // from changing the selection when multiple table rows are already selected
                    if (table.getSelectedRowCount() > 0)
                        previousSelectedRows = Arrays.stream(table.getSelectedRows()).boxed().collect(Collectors.toList());
                }
            }
        });
        table.addMouseListener(new MouseAdapter() {

            @Override
            public void mousePressed(MouseEvent e) {
                final boolean isMac = LookAndFeelUtil.isMac();
                // COMMAND button down on MacOS (or CONTROL button down on another OS) or SHIFT?
                if ((isMac && e.isMetaDown()) || (!isMac && e.isControlDown()) || e.isShiftDown())
                    // Ignore!
                    return;
                final int col = table.columnAtPoint(e.getPoint());
                if (col == SELECTED_COL_IDX) {
                    final int row = table.rowAtPoint(e.getPoint());
                    // Restore previous multiple-row selection first
                    if (previousSelectedRows != null && previousSelectedRows.contains(row)) {
                        for (int i : previousSelectedRows) table.addRowSelectionInterval(i, i);
                    }
                    toggleSelection(row);
                    updateSelectionButtons();
                }
            }
        });
    }
    return table;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) MouseEvent(java.awt.event.MouseEvent) JTable(javax.swing.JTable) DefaultTableModel(javax.swing.table.DefaultTableModel) ListSelectionEvent(javax.swing.event.ListSelectionEvent) MouseAdapter(java.awt.event.MouseAdapter) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 67 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project cytoscape-impl by cytoscape.

the class DeletionDialog method initComponents.

@SuppressWarnings("serial")
private void initComponents() {
    final JLabel deleteLabel = new JLabel("Select columns to be deleted:");
    final Collator collator = Collator.getInstance(Locale.getDefault());
    final TreeSet<CyColumn> deletableColumns = new TreeSet<>(new Comparator<CyColumn>() {

        @Override
        public int compare(CyColumn c1, CyColumn c2) {
            return collator.compare(c1.getName(), c2.getName());
        }
    });
    for (CyColumn col : table.getColumns()) {
        if (!col.isImmutable())
            deletableColumns.add(col);
    }
    final DefaultListModel<String> listModel = new DefaultListModel<>();
    for (CyColumn col : deletableColumns) listModel.addElement(col.getName());
    columnList = new JList<>(listModel);
    deletionPane = new JScrollPane(columnList);
    deleteButton = new JButton(new AbstractAction("Delete") {

        @Override
        public void actionPerformed(ActionEvent e) {
            deleteButtonActionPerformed(e);
        }
    });
    deleteButton.getAction().setEnabled(false);
    cancelButton = new JButton(new AbstractAction("Cancel") {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    final JPanel buttonPanel = LookAndFeelUtil.createOkCancelPanel(deleteButton, cancelButton);
    columnList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                final int[] selectedIndices = columnList.getSelectedIndices();
                deleteButton.getAction().setEnabled(selectedIndices != null && selectedIndices.length > 0);
            }
        }
    });
    final JPanel contentPane = new JPanel();
    final GroupLayout layout = new GroupLayout(contentPane);
    contentPane.setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(true);
    layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING, true).addComponent(deleteLabel).addComponent(deletionPane, DEFAULT_SIZE, 320, Short.MAX_VALUE).addComponent(buttonPanel));
    layout.setVerticalGroup(layout.createSequentialGroup().addComponent(deleteLabel).addComponent(deletionPane, DEFAULT_SIZE, 240, Short.MAX_VALUE).addComponent(buttonPanel));
    setContentPane(contentPane);
    LookAndFeelUtil.setDefaultOkCancelKeyStrokes(getRootPane(), deleteButton.getAction(), cancelButton.getAction());
    getRootPane().setDefaultButton(deleteButton);
    pack();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) CyColumn(org.cytoscape.model.CyColumn) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JLabel(javax.swing.JLabel) DefaultListModel(javax.swing.DefaultListModel) Collator(java.text.Collator) ListSelectionListener(javax.swing.event.ListSelectionListener) TreeSet(java.util.TreeSet) GroupLayout(javax.swing.GroupLayout) AbstractAction(javax.swing.AbstractAction)

Example 68 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project cytoscape-impl by cytoscape.

the class ShapeAnnotationPanel method initComponents.

private void initComponents() {
    setBorder(LookAndFeelUtil.createPanelBorder());
    final JLabel nameLabel = new JLabel("Annotation Name:");
    final JLabel label1 = new JLabel("Shape:");
    final JLabel label2 = new JLabel("Fill Color:");
    final JLabel label3 = new JLabel("Fill Opacity:");
    final JLabel label4 = new JLabel("Border Color:");
    final JLabel label5 = new JLabel("Border Opacity:");
    final JLabel label6 = new JLabel("Border Width:");
    nameField = new JTextField(32);
    if (annotation.getName() != null) {
        nameField.setText(annotation.getName());
    }
    nameField.addMouseListener(new TextFieldMouseListener(nameField, preview));
    shapeList = new JList<>();
    shapeList.setModel(new AbstractListModel<String>() {

        List<String> typeList = annotation.getSupportedShapes();

        @Override
        public int getSize() {
            return typeList.size();
        }

        @Override
        public String getElementAt(int i) {
            return typeList.get(i);
        }
    });
    shapeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    shapeList.setSelectedValue(annotation.getShapeType(), true);
    shapeList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent evt) {
            shapeListValueChanged(evt);
        }
    });
    final JScrollPane scrollPane = new JScrollPane(shapeList);
    fillColorCheck = new JCheckBox();
    fillColorCheck.setSelected(annotation.getFillColor() != null);
    fillColorCheck.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            fillColorCheckActionPerformed(evt);
        }
    });
    fillColorButton = new ColorButton((Color) preview.getFillColor());
    fillColorButton.setToolTipText("Select fill color...");
    fillColorButton.setEnabled(fillColorCheck.isSelected());
    fillColorButton.addPropertyChangeListener("color", new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            preview.setFillColor((Color) evt.getNewValue());
            previewPanel.repaint();
        }
    });
    fillOpacitySlider = new JSlider(0, 100);
    fillOpacitySlider.setMajorTickSpacing(100);
    fillOpacitySlider.setMinorTickSpacing(25);
    fillOpacitySlider.setPaintTicks(true);
    fillOpacitySlider.setPaintLabels(true);
    if (annotation.getFillOpacity() != 100.0) {
        fillOpacitySlider.setEnabled(true);
        fillOpacitySlider.setValue((int) annotation.getFillOpacity());
    } else {
        fillOpacitySlider.setValue(100);
        fillOpacitySlider.setEnabled(false);
    }
    fillOpacitySlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent evt) {
            updateFillOpacity(fillOpacitySlider.getValue());
        }
    });
    borderColorCheck = new JCheckBox();
    borderColorCheck.setSelected(annotation.getBorderColor() != null);
    borderColorCheck.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            borderColorCheckActionPerformed(evt);
        }
    });
    borderColorButton = new ColorButton((Color) preview.getBorderColor());
    borderColorButton.setToolTipText("Select border color...");
    borderColorButton.setEnabled(borderColorCheck.isSelected());
    borderColorButton.addPropertyChangeListener("color", new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            preview.setBorderColor((Color) evt.getNewValue());
            previewPanel.repaint();
        }
    });
    borderOpacitySlider = new JSlider(0, 100);
    borderOpacitySlider.setMajorTickSpacing(100);
    borderOpacitySlider.setMinorTickSpacing(25);
    borderOpacitySlider.setPaintTicks(true);
    borderOpacitySlider.setPaintLabels(true);
    if (annotation.getBorderOpacity() != 100.0 || borderColorCheck.isSelected()) {
        borderOpacitySlider.setEnabled(true);
        borderOpacitySlider.setValue((int) annotation.getBorderOpacity());
    } else {
        borderOpacitySlider.setValue(100);
        borderOpacitySlider.setEnabled(false);
    }
    borderOpacitySlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent evt) {
            updateBorderOpacity(borderOpacitySlider.getValue());
        }
    });
    borderWidthCombo = new JComboBox<>();
    borderWidthCombo.setModel(new DefaultComboBoxModel<String>(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" }));
    borderWidthCombo.setSelectedIndex(1);
    for (int i = 0; i < borderWidthCombo.getModel().getSize(); i++) {
        if (((int) annotation.getBorderWidth()) == Integer.parseInt(borderWidthCombo.getModel().getElementAt(i))) {
            borderWidthCombo.setSelectedIndex(i);
            break;
        }
    }
    borderWidthCombo.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            borderWidthActionPerformed(evt);
        }
    });
    final GroupLayout layout = new GroupLayout(this);
    setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(!LookAndFeelUtil.isAquaLAF());
    layout.setHorizontalGroup(layout.createParallelGroup(LEADING, true).addGroup(layout.createSequentialGroup().addComponent(nameLabel).addComponent(nameField)).addComponent(label1).addGroup(layout.createSequentialGroup().addComponent(scrollPane, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addPreferredGap(ComponentPlacement.UNRELATED).addGroup(layout.createParallelGroup(TRAILING, true).addComponent(label2).addComponent(label3).addComponent(label4).addComponent(label5).addComponent(label6)).addPreferredGap(ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(Alignment.LEADING, true).addGroup(layout.createSequentialGroup().addComponent(fillColorCheck).addComponent(fillColorButton)).addComponent(fillOpacitySlider, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addGroup(layout.createSequentialGroup().addComponent(borderColorCheck).addComponent(borderColorButton)).addComponent(borderOpacitySlider, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(borderWidthCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE))));
    layout.setVerticalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(nameLabel).addComponent(nameField)).addComponent(label1).addGroup(layout.createParallelGroup(LEADING, true).addComponent(scrollPane).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(CENTER, false).addComponent(label2).addComponent(fillColorCheck).addComponent(fillColorButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createParallelGroup(LEADING, false).addComponent(label3).addComponent(fillOpacitySlider, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGap(20).addGroup(layout.createParallelGroup(CENTER, false).addComponent(label4).addComponent(borderColorCheck).addComponent(borderColorButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createParallelGroup(LEADING, false).addComponent(label5).addComponent(borderOpacitySlider, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createParallelGroup(CENTER, false).addComponent(label6).addComponent(borderWidthCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)))));
    iModifySAPreview();
}
Also used : PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JTextField(javax.swing.JTextField) ColorButton(org.cytoscape.util.swing.ColorButton) GroupLayout(javax.swing.GroupLayout) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener) JScrollPane(javax.swing.JScrollPane) PropertyChangeEvent(java.beans.PropertyChangeEvent) Color(java.awt.Color) JLabel(javax.swing.JLabel) ListSelectionListener(javax.swing.event.ListSelectionListener) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) ChangeEvent(javax.swing.event.ChangeEvent)

Example 69 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project tetrad by cmu-phil.

the class HpcAccountSettingAction method buildHpcAccountSettingComponent.

private static JComponent buildHpcAccountSettingComponent(final HpcAccountManager manager) {
    // Get ComputingAccount from DB
    final DefaultListModel<HpcAccount> listModel = new DefaultListModel<HpcAccount>();
    for (HpcAccount account : manager.getHpcAccounts()) {
        listModel.addElement(account);
    }
    // JSplitPane
    final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    // Left pane -> JList (parent pane)
    JPanel leftPanel = new JPanel(new BorderLayout());
    // Right pane -> ComputingAccountEditor
    final JPanel accountDetailPanel = new JPanel(new BorderLayout());
    accountDetailPanel.add(new HpcAccountEditor(splitPane, listModel, manager, new HpcAccount()), BorderLayout.CENTER);
    splitPane.setLeftComponent(leftPanel);
    splitPane.setRightComponent(accountDetailPanel);
    // Center Panel
    final JList<HpcAccount> accountList = new JList<>(listModel);
    accountList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    accountList.setLayoutOrientation(JList.VERTICAL);
    accountList.setSelectedIndex(-1);
    accountList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
                return;
            int selectedIndex = ((JList<?>) e.getSource()).getSelectedIndex();
            // Show or remove the detail
            accountDetailPanel.removeAll();
            if (selectedIndex > -1) {
                HpcAccount computingAccount = listModel.get(selectedIndex);
                System.out.println(computingAccount);
                accountDetailPanel.add(new HpcAccountEditor(splitPane, listModel, manager, computingAccount), BorderLayout.CENTER);
            }
            accountDetailPanel.updateUI();
        }
    });
    // Left Panel
    JPanel buttonPanel = new JPanel(new BorderLayout());
    JButton addButton = new JButton("Add");
    addButton.setSize(new Dimension(14, 8));
    addButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // Show the empty ComputingAccountEditor
            accountDetailPanel.removeAll();
            accountDetailPanel.add(new HpcAccountEditor(splitPane, listModel, manager, new HpcAccount()), BorderLayout.CENTER);
            accountDetailPanel.updateUI();
        }
    });
    buttonPanel.add(addButton, BorderLayout.WEST);
    JButton removeButton = new JButton("Remove");
    removeButton.setSize(new Dimension(14, 8));
    removeButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (accountList.isSelectionEmpty())
                return;
            int selectedIndex = accountList.getSelectedIndex();
            if (selectedIndex > -1) {
                HpcAccount computingAccount = listModel.get(selectedIndex);
                // Pop up the confirm dialog
                int option = JOptionPane.showConfirmDialog(accountDetailPanel, "Are you sure that you want to delete " + computingAccount + " ?", "HPC Account Setting", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                // If yes, remove it from DB and listModel
                if (option == JOptionPane.YES_OPTION) {
                    manager.removeAccount(computingAccount);
                    listModel.remove(selectedIndex);
                }
            }
        }
    });
    buttonPanel.add(removeButton, BorderLayout.EAST);
    leftPanel.add(buttonPanel, BorderLayout.NORTH);
    JScrollPane accountListScroller = new JScrollPane(accountList);
    leftPanel.add(accountListScroller, BorderLayout.CENTER);
    int minWidth = 300;
    int minHeight = 200;
    int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
    int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
    int frameWidth = screenWidth / 2;
    int frameHeight = screenHeight / 2;
    frameWidth = minWidth > frameWidth ? minWidth : frameWidth;
    frameHeight = minHeight > frameHeight ? minHeight : frameHeight;
    splitPane.setDividerLocation(frameWidth / 4);
    accountListScroller.setPreferredSize(new Dimension(frameWidth / 4, frameHeight));
    accountDetailPanel.setPreferredSize(new Dimension(frameWidth * 3 / 4, frameHeight));
    return splitPane;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JButton(javax.swing.JButton) DefaultListModel(javax.swing.DefaultListModel) HpcAccountEditor(edu.cmu.tetradapp.app.hpc.editor.HpcAccountEditor) HpcAccount(edu.pitt.dbmi.tetrad.db.entity.HpcAccount) Dimension(java.awt.Dimension) ListSelectionListener(javax.swing.event.ListSelectionListener) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) JSplitPane(javax.swing.JSplitPane) JList(javax.swing.JList)

Example 70 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project GenericKnimeNodes by genericworkflownodes.

the class DialogComponentMultiFileChooser method addListeners.

/**
 * Adds the event listeners to all gui elements.
 */
private void addListeners() {
    addButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent arg0) {
            final int returnVal = chooser.showDialog(getComponentPanel().getParent(), null);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File[] files = chooser.getSelectedFiles();
                ((FileListModel) listbox.getModel()).updateFileList(files);
            }
        }
    });
    removeButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent event) {
            // but we want to be sure
            if (listbox.getSelectedIndex() != -1) {
                int[] selectedIndices = listbox.getSelectedIndices();
                ((FileListModel) listbox.getModel()).remove(selectedIndices);
            }
        }
    });
    clearButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent event) {
            ((FileListModel) listbox.getModel()).clear();
        }
    });
    // make the remove button only available if something is selected
    listbox.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent event) {
            if (!event.getValueIsAdjusting()) {
                removeButton.setEnabled(listbox.getSelectedIndex() != -1);
            }
        }
    });
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener)

Aggregations

ListSelectionListener (javax.swing.event.ListSelectionListener)216 ListSelectionEvent (javax.swing.event.ListSelectionEvent)210 ActionEvent (java.awt.event.ActionEvent)90 ActionListener (java.awt.event.ActionListener)76 JScrollPane (javax.swing.JScrollPane)72 JPanel (javax.swing.JPanel)67 JButton (javax.swing.JButton)61 BorderLayout (java.awt.BorderLayout)53 MouseEvent (java.awt.event.MouseEvent)47 Dimension (java.awt.Dimension)44 JLabel (javax.swing.JLabel)40 MouseAdapter (java.awt.event.MouseAdapter)37 JTable (javax.swing.JTable)36 FlowLayout (java.awt.FlowLayout)28 Insets (java.awt.Insets)28 JList (javax.swing.JList)27 List (java.util.List)24 ArrayList (java.util.ArrayList)22 KeyEvent (java.awt.event.KeyEvent)21 GridBagConstraints (java.awt.GridBagConstraints)20