Search in sources :

Example 36 with ListSelectionModel

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);
            }
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) JTable(javax.swing.JTable) MouseAdapter(java.awt.event.MouseAdapter) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionModel(javax.swing.ListSelectionModel) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 37 with ListSelectionModel

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);
}
Also used : SiriusExportModule(net.sf.mzmine.modules.peaklistmethods.io.siriusexport.SiriusExportModule) Arrays(java.util.Arrays) IntensityPlotModule(net.sf.mzmine.modules.visualization.intensityplot.IntensityPlotModule) URISyntaxException(java.net.URISyntaxException) Point(java.awt.Point) SpectraVisualizerModule(net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraVisualizerModule) DataFileColumnType(net.sf.mzmine.modules.visualization.peaklisttable.table.DataFileColumnType) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) SpectralDBPeakIdentity(net.sf.mzmine.util.spectraldb.entry.SpectralDBPeakIdentity) SiriusProcessingModule(net.sf.mzmine.modules.peaklistmethods.identification.sirius.SiriusProcessingModule) Map(java.util.Map) URI(java.net.URI) PeakListTable(net.sf.mzmine.modules.visualization.peaklisttable.table.PeakListTable) ScanSelection(net.sf.mzmine.parameters.parametertypes.selectors.ScanSelection) Fx3DVisualizerModule(net.sf.mzmine.modules.visualization.fx3d.Fx3DVisualizerModule) SortingProperty(net.sf.mzmine.util.SortingProperty) FormulaPredictionModule(net.sf.mzmine.modules.peaklistmethods.identification.formulaprediction.FormulaPredictionModule) Range(com.google.common.collect.Range) JMenu(javax.swing.JMenu) GUIUtils(net.sf.mzmine.util.GUIUtils) CommonColumnType(net.sf.mzmine.modules.visualization.peaklisttable.table.CommonColumnType) Component(java.awt.Component) Collectors(java.util.stream.Collectors) List(java.util.List) PeakSummaryVisualizerModule(net.sf.mzmine.modules.visualization.peaksummary.PeakSummaryVisualizerModule) MirrorScanWindow(net.sf.mzmine.modules.visualization.spectra.simplespectra.mirrorspectra.MirrorScanWindow) ListSelectionModel(javax.swing.ListSelectionModel) Scan(net.sf.mzmine.datamodel.Scan) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) MZmineCore(net.sf.mzmine.main.MZmineCore) ActionListener(java.awt.event.ActionListener) TICVisualizerModule(net.sf.mzmine.modules.visualization.tic.TICVisualizerModule) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) HashMap(java.util.HashMap) PeakList(net.sf.mzmine.datamodel.PeakList) ArrayList(java.util.ArrayList) MSMSLibrarySubmissionWindow(net.sf.mzmine.modules.peaklistmethods.io.spectraldbsubmit.view.MSMSLibrarySubmissionWindow) SwingUtilities(javax.swing.SwingUtilities) MultiSpectraVisualizerWindow(net.sf.mzmine.modules.visualization.spectra.simplespectra.MultiSpectraVisualizerWindow) Feature(net.sf.mzmine.datamodel.Feature) JMenuItem(javax.swing.JMenuItem) AbstractTableModel(javax.swing.table.AbstractTableModel) XICManualPickerModule(net.sf.mzmine.modules.rawdatamethods.peakpicking.manual.XICManualPickerModule) MSMSExportModule(net.sf.mzmine.modules.visualization.peaklisttable.export.MSMSExportModule) NistMsSearchModule(net.sf.mzmine.modules.peaklistmethods.identification.nist.NistMsSearchModule) ManualPeakPickerModule(net.sf.mzmine.modules.rawdatamethods.peakpicking.manual.ManualPeakPickerModule) PeakListTableColumnModel(net.sf.mzmine.modules.visualization.peaklisttable.table.PeakListTableColumnModel) Desktop(java.awt.Desktop) MultiMSMSWindow(net.sf.mzmine.modules.visualization.spectra.multimsms.MultiMSMSWindow) TICPlotType(net.sf.mzmine.modules.visualization.tic.TICPlotType) JPopupMenu(javax.swing.JPopupMenu) SpectraIdentificationResultsWindow(net.sf.mzmine.modules.visualization.spectra.spectralmatchresults.SpectraIdentificationResultsWindow) TwoDVisualizerModule(net.sf.mzmine.modules.visualization.twod.TwoDVisualizerModule) IOException(java.io.IOException) ActionEvent(java.awt.event.ActionEvent) IsotopePatternExportModule(net.sf.mzmine.modules.visualization.peaklisttable.export.IsotopePatternExportModule) SortingDirection(net.sf.mzmine.util.SortingDirection) OnlineDBSearchModule(net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.OnlineDBSearchModule) LocalSpectralDBSearchModule(net.sf.mzmine.modules.peaklistmethods.identification.spectraldbsearch.LocalSpectralDBSearchModule) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) SpectralDBPeakIdentity(net.sf.mzmine.util.spectraldb.entry.SpectralDBPeakIdentity) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) ListSelectionModel(javax.swing.ListSelectionModel) Point(java.awt.Point) Feature(net.sf.mzmine.datamodel.Feature) Point(java.awt.Point)

Example 38 with ListSelectionModel

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);
}
Also used : Color(java.awt.Color) ListSelectionModel(javax.swing.ListSelectionModel)

Example 39 with ListSelectionModel

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();
}
Also used : AdempiereTaskPaneUI(org.adempiere.plaf.AdempiereTaskPaneUI) ImageIcon(javax.swing.ImageIcon) AppsAction(org.compiere.apps.AppsAction) FlowLayout(java.awt.FlowLayout) BorderLayout(java.awt.BorderLayout) CPanel(org.compiere.swing.CPanel) JButton(javax.swing.JButton) ListSelectionModel(javax.swing.ListSelectionModel) Dimension(java.awt.Dimension) ColorUIResource(javax.swing.plaf.ColorUIResource) ALayout(org.compiere.apps.ALayout)

Example 40 with ListSelectionModel

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);
    }
}
Also used : DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) 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