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;
}
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);
}
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);
}
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;
}
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());
}
}
Aggregations