Search in sources :

Example 61 with ListSelectionModel

use of javax.swing.ListSelectionModel in project MassBank-web by MassBank.

the class PackageViewPanel method createRecListTable.

/**
 * ���R�[�h���X�g�e�[�u���쐬
 * @return ���R�[�h���X�g�e�[�u��
 */
private JTable createRecListTable() {
    recSorter = new TableSorter(new DefaultTableModel(), specData);
    JTable t = new JTable(recSorter) {

        @Override
        public boolean isCellEditable(int row, int column) {
            super.isCellEditable(row, column);
            // �Z���ҏW��s�‚Ƃ���
            return false;
        }

        @Override
        public void setValueAt(Object value, int row, int col) {
            super.setValueAt(value, row, col);
            // �`�F�b�N�{�b�N�X���ҏW���ꂽ�ꍇ�ɍĕ`����s��
            if (recTable.getColumnName(col).equals(SearchPage.COL_LABEL_DISABLE)) {
                PackageRecData recData = specData.getRecInfo(row);
                recData.setDisable(Boolean.parseBoolean(String.valueOf(recTable.getValueAt(row, col))));
                specData.setMatchPeakInfo(tolVal, tolUnit);
                PackageViewPanel.this.repaint();
                int hitCol = recTable.getColumnModel().getColumnIndex(SearchPage.COL_LABEL_HIT);
                for (int i = 0; i < recTable.getRowCount(); i++) {
                    // �ҏW���ꂽ���R�[�h�ɂ����Hit�J�����̒l���A�b�v�f�[�g����
                    setValueAt(specData.getRecInfo(i).getHitPeakNum(), i, hitCol);
                }
            }
        }

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            Rectangle2D area = new Rectangle2D.Float();
            // �h���b�O���Ƀh���b�O��h��‚Ԃ��\��
            if (!isSortStatus() && dragRowIndex >= 0) {
                g2.setPaint(Color.RED);
                g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
                area.setRect(0, (dragRowIndex * getRowHeight()), getWidth(), getRowHeight());
                g2.fill(area);
            }
            // change color�̏ꍇ�̓I�[�_�[�J�����̍s��h��‚Ԃ��\��
            if (chgColor.isSelected()) {
                for (int i = 0; i < recTable.getRowCount(); i++) {
                    // ��\���̏ꍇ�͐F�Â����Ȃ�
                    if (Boolean.parseBoolean(String.valueOf(getValueAt(i, getColumnModel().getColumnIndex(SearchPage.COL_LABEL_DISABLE))))) {
                        continue;
                    }
                    g2.setPaint(getColor(i));
                    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f));
                    area.setRect(getCellRect(i, getColumnModel().getColumnIndex(SearchPage.COL_LABEL_ORDER), false));
                    g2.fill(area);
                }
            }
        }
    };
    recSorter.setTableHeader(t.getTableHeader());
    t.setMinimumSize(new Dimension(400, 400));
    t.setRowSelectionAllowed(true);
    t.setColumnSelectionAllowed(false);
    t.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    // ���X�i�[�lj�
    t.addMouseListener(new TblMouseListener());
    // ���X�i�[�lj�
    t.addMouseMotionListener(new TblMouseMotionListener());
    // �L�[���X�i�[�lj�
    t.addKeyListener(new TblKeyListener());
    // �I���W�i�������_���[
    t.setDefaultRenderer(Object.class, new TblRenderer());
    ListSelectionModel lm = t.getSelectionModel();
    lm.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    lm.addListSelectionListener(new LmSelectionListener());
    // �J�����Z�b�g
    String[] columnLabel = { SearchPage.COL_LABEL_ORDER, SearchPage.COL_LABEL_TYPE, SearchPage.COL_LABEL_NAME, SearchPage.COL_LABEL_MATCH, SearchPage.COL_LABEL_ID, SearchPage.COL_LABEL_DISABLE, SearchPage.COL_LABEL_CONTRIBUTOR, SearchPage.COL_LABEL_SCORE, SearchPage.COL_LABEL_HIT, SearchPage.COL_LABEL_PEAK, SearchPage.COL_LABEL_PRECURSOR };
    DefaultTableModel model = (DefaultTableModel) recSorter.getTableModel();
    model.setColumnIdentifiers(columnLabel);
    // �񕝃Z�b�g
    t.getColumn(t.getColumnName(0)).setPreferredWidth(36);
    t.getColumn(t.getColumnName(1)).setPreferredWidth(75);
    t.getColumn(t.getColumnName(2)).setPreferredWidth(360);
    t.getColumn(t.getColumnName(3)).setPreferredWidth(36);
    t.getColumn(t.getColumnName(4)).setPreferredWidth(70);
    t.getColumn(t.getColumnName(5)).setPreferredWidth(47);
    t.getColumn(t.getColumnName(6)).setPreferredWidth(70);
    t.getColumn(t.getColumnName(7)).setPreferredWidth(70);
    t.getColumn(t.getColumnName(8)).setPreferredWidth(20);
    t.getColumn(t.getColumnName(9)).setPreferredWidth(36);
    t.getColumn(t.getColumnName(10)).setPreferredWidth(58);
    return t;
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) Rectangle2D(java.awt.geom.Rectangle2D) ListSelectionModel(javax.swing.ListSelectionModel) Dimension(java.awt.Dimension) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D) Graphics(java.awt.Graphics) JTable(javax.swing.JTable)

Example 62 with ListSelectionModel

use of javax.swing.ListSelectionModel in project knime-core by knime.

the class TableContentModelTest method testResetHilite.

// testUnHilite()
/**
 * Method being tested: resetHiLite().
 */
public final void testResetHilite() {
    final HiLiteHandler hiliter = new HiLiteHandler();
    final TableContentModel m = new TableContentModel(DATA, hiliter);
    final JTable table = new JTable(m);
    final ListSelectionModel listModel = table.getSelectionModel();
    // make sure, the content model knows about ALL ROWS
    m.getRow(OBJECT_DATA.length - 1);
    assertEquals(table.getRowCount(), OBJECT_DATA.length);
    // first: hilite all;
    listModel.setSelectionInterval(0, OBJECT_DATA.length - 1);
    m.requestHiLite(listModel);
    flushEDTQueue();
    for (int i = 0; i < OBJECT_DATA.length; i++) {
        assertTrue(m.isHiLit(i));
    }
    // reset hilite
    m.requestResetHiLite();
    // hilite happens in EDT thread, this is executed in main - need to wait
    ViewUtils.invokeAndWaitInEDT(new Runnable() {

        @Override
        public void run() {
        // nothing, just run
        }
    });
    for (int i = 0; i < OBJECT_DATA.length; i++) {
        assertFalse(m.isHiLit(i));
    }
    int lucky = (int) (Math.random() * OBJECT_DATA.length);
    listModel.setSelectionInterval(lucky, lucky);
    m.requestHiLite(listModel);
    flushEDTQueue();
    m.setTableContentFilter(TableContentFilter.HiliteOnly);
    // 0 should be ok, it returns the lucky row
    m.getRow(0);
    m.unHiLiteAll(new KeyEvent(this));
    assertEquals(m.getRowCount(), 0);
}
Also used : KeyEvent(org.knime.core.node.property.hilite.KeyEvent) HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) JTable(javax.swing.JTable) ListSelectionModel(javax.swing.ListSelectionModel)

Example 63 with ListSelectionModel

use of javax.swing.ListSelectionModel in project knime-core by knime.

the class TableView method gotoCell.

/**
 * Scrolls to the given coordinate cell. This method is invoked from the navigation menu. If there is no such
 * coordinate it will display an error message.
 *
 * @param row the row to scroll to
 * @param col the col to scroll to (negative for row key)
 */
public void gotoCell(final int row, final int col) {
    final TableContentView cView = getContentTable();
    final ListSelectionModel colSelModel = cView.getColumnModel().getSelectionModel();
    final ListSelectionModel rowSelModel = cView.getSelectionModel();
    if (row >= 0) {
        try {
            cView.getValueAt(row, Math.max(col, 0));
        } catch (IndexOutOfBoundsException ioe) {
            if (cView.getColumnCount() != 0) {
                JOptionPane.showMessageDialog(this, "No such row/col: (" + (row + 1) + ", " + (col + 1) + ")", "Error", JOptionPane.ERROR_MESSAGE);
                return;
            }
        }
        rowSelModel.setSelectionInterval(row, row);
    } else {
        rowSelModel.clearSelection();
    }
    final Rectangle rec = cView.getCellRect(Math.max(row, 0), Math.max(col, 0), false);
    if (col >= 0) {
        colSelModel.setSelectionInterval(col, col);
    } else {
        colSelModel.clearSelection();
    }
    cView.scrollRectToVisible(rec);
}
Also used : Rectangle(java.awt.Rectangle) ListSelectionModel(javax.swing.ListSelectionModel)

Example 64 with ListSelectionModel

use of javax.swing.ListSelectionModel in project knime-core by knime.

the class ColumnSelectionList method setSelectedColumns.

/**
 * Selects all given columns in the list. Non-existing columns are ignored.
 *
 * @param selCols an array with column names. Must not be <code>null</code>.
 */
public void setSelectedColumns(final String... selCols) {
    ListSelectionModel selModel = getSelectionModel();
    boolean oldvalue = m_selectionChangeAllowed;
    m_selectionChangeAllowed = true;
    selModel.clearSelection();
    for (int i = 0; i < m_listModel.getSize(); i++) {
        String name = ((DataColumnSpec) m_listModel.get(i)).getName();
        for (int j = 0; j < selCols.length; j++) {
            if (name.equals(selCols[j])) {
                selModel.addSelectionInterval(i, i);
                break;
            }
        }
    }
    m_selectionChangeAllowed = oldvalue;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) ListSelectionModel(javax.swing.ListSelectionModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel)

Example 65 with ListSelectionModel

use of javax.swing.ListSelectionModel in project omegat by omegat-org.

the class FiltersCustomizerController method initGui.

private void initGui() {
    panel = new FiltersCustomizerPanel();
    panel.filtersTable.setDefaultRenderer(String.class, new FilterFormatCellRenderer());
    panel.filtersTable.getSelectionModel().addListSelectionListener(e -> {
        if (e.getValueIsAdjusting()) {
            return;
        }
        ListSelectionModel lsm = (ListSelectionModel) e.getSource();
        if (lsm.isSelectionEmpty()) {
            panel.editButton.setEnabled(false);
            panel.optionsButton.setEnabled(false);
        } else {
            panel.editButton.setEnabled(true);
            Filter currFilter = getFilterAtRow(panel.filtersTable.getSelectedRow());
            IFilter f = FilterMaster.getFilterInstance(currFilter.getClassName());
            panel.optionsButton.setEnabled(f != null && f.hasOptions());
        }
    });
    panel.filtersTable.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent me) {
            if (me.getClickCount() == 2 && me.getButton() == MouseEvent.BUTTON1) {
                doEdit(panel.filtersTable.rowAtPoint(me.getPoint()));
            }
        }
    });
    TableColumnSizer.autoSize(panel.filtersTable, 0, true);
    if (!isProjectSpecific) {
        panel.projectSpecificCB.setVisible(false);
    }
    panel.projectSpecificCB.addActionListener(e -> updateEnabledness());
    panel.cbRemoveTags.addActionListener(e -> editableFilters.setRemoveTags(panel.cbRemoveTags.isSelected()));
    panel.cbRemoveSpacesNonseg.addActionListener(e -> editableFilters.setRemoveSpacesNonseg(panel.cbRemoveSpacesNonseg.isSelected()));
    panel.cbPreserveSpaces.addActionListener(e -> editableFilters.setPreserveSpaces(panel.cbPreserveSpaces.isSelected()));
    panel.cbIgnoreFileContext.addActionListener(e -> editableFilters.setIgnoreFileContext(panel.cbIgnoreFileContext.isSelected()));
    panel.optionsButton.addActionListener(e -> {
        Filter currFilter = getFilterAtRow(panel.filtersTable.getSelectedRow());
        IFilter f = FilterMaster.getFilterInstance(currFilter.getClassName());
        if (f != null) {
            // new options handling
            Map<String, String> newConfig = f.changeOptions(SwingUtilities.windowForComponent(panel), FilterMaster.forFilter(currFilter.getOption()));
            if (newConfig != null) {
                FilterMaster.setOptions(currFilter, newConfig);
            }
        }
    });
    panel.editButton.addActionListener(e -> doEdit(panel.filtersTable.getSelectedRow()));
    if (Core.getProject().isProjectLoaded()) {
        inUseFilters = Core.getProject().getProjectFiles().stream().map(info -> info.filterFileFormatName).collect(Collectors.toSet());
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) Filter(gen.core.filters.Filter) IFilter(org.omegat.filters2.IFilter) IFilter(org.omegat.filters2.IFilter) MouseAdapter(java.awt.event.MouseAdapter) ListSelectionModel(javax.swing.ListSelectionModel)

Aggregations

ListSelectionModel (javax.swing.ListSelectionModel)80 BorderLayout (java.awt.BorderLayout)20 Dimension (java.awt.Dimension)20 JButton (javax.swing.JButton)20 JPanel (javax.swing.JPanel)19 ListSelectionEvent (javax.swing.event.ListSelectionEvent)19 ListSelectionListener (javax.swing.event.ListSelectionListener)19 ActionEvent (java.awt.event.ActionEvent)18 JTable (javax.swing.JTable)18 ActionListener (java.awt.event.ActionListener)17 Point (java.awt.Point)16 JScrollPane (javax.swing.JScrollPane)15 MouseEvent (java.awt.event.MouseEvent)14 MouseAdapter (java.awt.event.MouseAdapter)13 DefaultListSelectionModel (javax.swing.DefaultListSelectionModel)13 TableColumn (javax.swing.table.TableColumn)13 Insets (java.awt.Insets)12 TableModel (javax.swing.table.TableModel)11 TableRowSorter (javax.swing.table.TableRowSorter)10 FlowLayout (java.awt.FlowLayout)9