use of javax.swing.ListSelectionModel in project mafscaling by vimsh.
the class BilinearInterpolator method addTableHeaderHighlight.
/**
* Method adds selected cell(s) column and row highlighting to the table
* @param table
*/
public static void addTableHeaderHighlight(final JTable table) {
table.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event) {
if (event.getButton() == MouseEvent.BUTTON1) {
JTable eventTable = (JTable) event.getSource();
int colIdx = eventTable.getSelectedColumn();
int rowIdx = eventTable.getSelectedRow();
if (colIdx != -1 && rowIdx != -1) {
Utils.setTableHeaderHighlightColor(eventTable, new int[] { colIdx }, new int[] { rowIdx });
if (eventTable.getColumnCount() - 1 >= colIdx && eventTable.getRowCount() - 1 >= rowIdx) {
eventTable.setColumnSelectionInterval(colIdx, colIdx);
eventTable.setRowSelectionInterval(rowIdx, rowIdx);
}
}
}
}
});
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting())
return;
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
if (!lsm.isSelectionEmpty()) {
Utils.setTableHeaderHighlightColor(table, null, table.getSelectedRows());
}
}
});
table.getColumnModel().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting())
return;
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
if (!lsm.isSelectionEmpty()) {
Utils.setTableHeaderHighlightColor(table, table.getSelectedColumns(), null);
}
}
});
}
use of javax.swing.ListSelectionModel in project mzmine2 by mzmine.
the class PeakListTablePopupMenu method show.
@Override
public void show(final Component invoker, final int x, final int y) {
// Select the row where clicked?
final Point clickedPoint = new Point(x, y);
final int clickedRow = table.rowAtPoint(clickedPoint);
if (table.getSelectedRowCount() < 2) {
ListSelectionModel selectionModel = table.getSelectionModel();
selectionModel.setSelectionInterval(clickedRow, clickedRow);
}
// First, disable all the Show... items
show2DItem.setEnabled(false);
show3DItem.setEnabled(false);
manuallyDefineItem.setEnabled(false);
showMSMSItem.setEnabled(false);
showMSMSMirrorItem.setEnabled(false);
showSpectralDBResults.setEnabled(false);
showAllMSMSItem.setEnabled(false);
showIsotopePatternItem.setEnabled(false);
showPeakRowSummaryItem.setEnabled(false);
exportIsotopesItem.setEnabled(false);
exportMSMSItem.setEnabled(false);
exportMenu.setEnabled(false);
// Enable row items if applicable
final int[] selectedRows = table.getSelectedRows();
final boolean rowsSelected = selectedRows.length > 0;
deleteRowsItem.setEnabled(rowsSelected);
clearIdsItem.setEnabled(rowsSelected);
pasteIdsItem.setEnabled(rowsSelected && copiedId != null);
plotRowsItem.setEnabled(rowsSelected);
showMenu.setEnabled(rowsSelected);
idsMenu.setEnabled(rowsSelected);
exportIsotopesItem.setEnabled(rowsSelected);
exportToSirius.setEnabled(rowsSelected);
exportMSMSLibrary.setEnabled(rowsSelected);
exportMS1Library.setEnabled(rowsSelected);
exportMenu.setEnabled(rowsSelected);
final boolean oneRowSelected = selectedRows.length == 1;
searchMenu.setEnabled(true);
// search methods for single rows
onlineDbSearchItem.setEnabled(oneRowSelected);
nistSearchItem.setEnabled(oneRowSelected);
formulaItem.setEnabled(oneRowSelected);
siriusItem.setEnabled(oneRowSelected);
// search methods for single and multiple rows
spectralDbSearchItem.setEnabled(true);
// Find the row and column where the user clicked
clickedDataFile = null;
final int clickedColumn = columnModel.getColumn(table.columnAtPoint(clickedPoint)).getModelIndex();
if (clickedRow >= 0 && clickedColumn >= 0) {
final int rowIndex = table.convertRowIndexToModel(clickedRow);
clickedPeakListRow = getPeakListRow(rowIndex);
allClickedPeakListRows = new PeakListRow[selectedRows.length];
for (int i = 0; i < selectedRows.length; i++) {
allClickedPeakListRows[i] = getPeakListRow(table.convertRowIndexToModel(selectedRows[i]));
}
// Enable items.
show2DItem.setEnabled(oneRowSelected);
show3DItem.setEnabled(oneRowSelected);
showPeakRowSummaryItem.setEnabled(oneRowSelected);
if (clickedPeakListRow.getBestPeak() != null) {
exportMSMSItem.setEnabled(oneRowSelected && clickedPeakListRow.getBestPeak().getMostIntenseFragmentScanNumber() > 0);
}
// If we clicked on data file columns, check the peak
if (clickedColumn >= CommonColumnType.values().length) {
// Enable manual peak picking
manuallyDefineItem.setEnabled(oneRowSelected);
// Find the actual peak, if we have it.
clickedDataFile = peakList.getRawDataFile((clickedColumn - CommonColumnType.values().length) / DataFileColumnType.values().length);
final Feature clickedPeak = getPeakListRow(table.convertRowIndexToModel(clickedRow)).getPeak(clickedDataFile);
// If we have the peak, enable Show... items
if (clickedPeak != null && oneRowSelected) {
showIsotopePatternItem.setEnabled(clickedPeak.getIsotopePattern() != null);
}
} else {
showIsotopePatternItem.setEnabled(clickedPeakListRow.getBestIsotopePattern() != null && oneRowSelected);
}
long nRowsWithFragmentation = Arrays.stream(allClickedPeakListRows).filter(r -> r.getBestFragmentation() != null).count();
// always show for multi MSMS window
showMSMSItem.setEnabled((oneRowSelected && getSelectedPeakForMSMS() != null && getSelectedPeakForMSMS().getMostIntenseFragmentScanNumber() > 0) || (selectedRows.length > 1 && nRowsWithFragmentation > 1));
// always show if at least one fragmentation is available
showAllMSMSItem.setEnabled(clickedPeakListRow.getBestFragmentation() != null && oneRowSelected);
// only show if selected rows == 2 and both have MS2
boolean bothMS2 = selectedRows.length == 2 && nRowsWithFragmentation == 2;
showMSMSMirrorItem.setEnabled(bothMS2);
// has identity of spectral database match
showSpectralDBResults.setEnabled(hasSpectralDBIdentities(clickedPeakListRow));
// open id url if available
PeakIdentity pi = clickedPeakListRow.getPreferredPeakIdentity();
String url = null;
if (pi != null)
url = pi.getPropertyValue(PeakIdentity.PROPERTY_URL);
openCompoundIdUrl.setEnabled(url != null && !url.isEmpty());
}
copyIdsItem.setEnabled(oneRowSelected && allClickedPeakListRows[0].getPreferredPeakIdentity() != null);
super.show(invoker, x, y);
}
use of javax.swing.ListSelectionModel in project mzmine2 by mzmine.
the class InterpolatingLookupPaintScaleSetupDialog method valueChanged.
public void valueChanged(ListSelectionEvent event) {
if (event.getValueIsAdjusting())
return;
ListSelectionModel lsm = (ListSelectionModel) event.getSource();
int index = lsm.getLeadSelectionIndex();
if (index < 0) {
return;
}
Double value = lookupTable.keySet().toArray(new Double[0])[index];
Color color = lookupTable.get(value);
fieldValue.setValue(value);
buttonColor.setBackground(color);
}
use of javax.swing.ListSelectionModel in project adempiere by adempiere.
the class Info method jbInit.
/**
* Static Init
* @throws Exception
*/
protected void jbInit() throws Exception {
this.getContentPane().add(parameterPanel, BorderLayout.NORTH);
this.getContentPane().add(scrollPane, BorderLayout.CENTER);
this.getContentPane().add(southPanel, BorderLayout.SOUTH);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
//
AppsAction aa = new AppsAction(ConfirmPanel.A_RESET, null, "reset");
bReset = (CButton) aa.getButton();
bReset.setMargin(ConfirmPanel.s_insets);
bReset.setSize(bReset.getHeight(), bReset.getHeight());
Dimension bSize = bReset.getSize();
bSize.height = bReset.getHeight();
bSize.width = bReset.getHeight();
// Make it square
bReset.setMaximumSize(bSize);
bReset.addActionListener(this);
//
buttonPanel = new CPanel(new FlowLayout(FlowLayout.LEFT));
buttonPanel.add(bReset, FlowLayout.LEFT);
//
// p_criteriaGrid is filled by the subordinate class
p_criteriaGrid.setLayout(new ALayout());
//
parameterPanel.setLayout(new BorderLayout());
parameterPanel.add(buttonPanel, BorderLayout.WEST);
parameterPanel.add(p_criteriaGrid, BorderLayout.CENTER);
//
// Setup the detail panel if used
p_detailTaskPane.setVisible(false);
p_detailTaskPane.setCollapsed(true);
p_detailTaskPane.setLayout(new BorderLayout());
p_detailTaskPane.setUI(new AdempiereTaskPaneUI());
p_detailTaskPane.getContentPane().setBackground(new ColorUIResource(251, 248, 241));
p_detailTaskPane.getContentPane().setForeground(new ColorUIResource(251, 0, 0));
addonPanel.setLayout(new BorderLayout());
// Allow auto resizing of the panel
addonPanel.add(p_detailTaskPane, BorderLayout.CENTER);
southPanel.setLayout(southLayout);
southPanel.add(addonPanel, BorderLayout.NORTH);
southPanel.add(confirmPanel, BorderLayout.CENTER);
southPanel.add(statusBar, BorderLayout.SOUTH);
scrollPane.getViewport().add(p_table, null);
//
confirmPanel.addActionListener(this);
confirmPanel.getResetButton().setVisible(hasReset());
confirmPanel.getCustomizeButton().setVisible(hasCustomize());
confirmPanel.getHistoryButton().setVisible(hasHistory());
confirmPanel.getZoomButton().setVisible(hasZoom());
// Only show the OK button if we intend to save
confirmPanel.setOKVisible(p_saveResults);
//
JButton print = ConfirmPanel.createPrintButton(true);
print.addActionListener(this);
confirmPanel.addButton(print);
//
checkAutoQuery.setText(Msg.getMsg(Env.getCtx(), "AutoRefresh"));
checkAutoQuery.setToolTipText(Msg.getMsg(Env.getCtx(), "AutoRefresh"));
checkAutoQuery.setName("AutoQuery");
checkAutoQuery.setSelected(MSysConfig.getValue(SYSCONFIG_INFO_AUTO_QUERY, "Y", Env.getAD_Client_ID(Env.getCtx())).equals("Y"));
checkAutoQuery.addActionListener(this);
// Index 0 is OK-Cancel on the right
CPanel leftButtons = (CPanel) confirmPanel.getComponent(1);
// Add the check box on the very left before the refresh icon
leftButtons.add(checkAutoQuery, 0);
//
popup.add(zoomMenu);
zoomMenu.setText(Msg.getMsg(Env.getCtx(), "Zoom"));
zoomMenu.setIcon(new ImageIcon(org.compiere.Adempiere.class.getResource("images/Zoom16.gif")));
zoomMenu.addActionListener(this);
//
popup.add(calcMenu);
calcMenu.setText(Msg.getMsg(Env.getCtx(), "Calculator"));
calcMenu.setIcon(new ImageIcon(org.compiere.Adempiere.class.getResource("images/Calculator16.gif")));
calcMenu.addActionListener(this);
//
// Table Selection (Invoked before setting column class so that row selection is enabled)
p_table.setKeyColumnIndex(-1);
p_table.setCellSelectionEnabled(false);
p_table.setColumnSelectionAllowed(false);
p_table.setRowSelectionAllowed(true);
// Override the Enter key input and action map
if (p_saveResults) {
p_table.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "doDispose");
} else {
p_table.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "doNothing");
}
p_table.getActionMap().put("doDispose", doDispose);
// To enable buttons
((ListSelectionModel) p_table.getSelectionModel()).addListSelectionListener(this);
p_table.addMouseListener(this);
// Listen to changes in the table
p_table.addPropertyChangeListener("p_table_update", this);
((ListSelectionModel) p_table.getSelectionModel()).addListSelectionListener(this);
//
// Set default location where focus will go. See property change listener.
m_parentPanel = p_criteriaGrid;
//
enableButtons();
}
use of javax.swing.ListSelectionModel in project adempiere by adempiere.
the class MiniTable method toggleRowChecked.
/**
* Toggles the selection checkbox of the given row. Adds or removes the row from
* the selection accordingly.
* @param row - the row in the view to toggle
*/
private void toggleRowChecked(int row) {
// Range check
int rows = this.getRowCount();
if (this.getShowTotals())
rows = rows - 1;
if (row < 0 || row >= rows)
return;
ListSelectionModel rsm = this.getSelectionModel();
// Toggle
setRowChecked(row, !isRowChecked(row));
if (isRowChecked(row)) {
if (isMultiSelection())
rsm.addSelectionInterval(row, row);
else
rsm.setSelectionInterval(row, row);
} else {
rsm.removeSelectionInterval(row, row);
}
}
Aggregations