Search in sources :

Example 71 with JPopupMenu

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

the class SearchPage method recListPopup.

/**
 * ���R�[�h���X�g�p�|�b�v�A�b�v�\��
 * @param e �}�E�X�C�x���g
 */
private void recListPopup(MouseEvent e) {
    JTable tbl = null;
    JScrollPane pane = null;
    try {
        tbl = (JTable) e.getSource();
    } catch (ClassCastException cce) {
        pane = (JScrollPane) e.getSource();
        if (pane.equals(queryDbPane)) {
            tbl = queryDbTable;
        } else if (pane.equals(resultPane)) {
            tbl = resultTable;
        }
        if (pane.equals(queryFilePane)) {
            tbl = queryFileTable;
        }
    }
    int rowCnt = tbl.getSelectedRows().length;
    JMenuItem item1 = new JMenuItem("Show Record");
    item1.addActionListener(new PopupShowRecordListener(tbl));
    JMenuItem item2 = new JMenuItem("Multiple Display");
    item2.addActionListener(new PopupMultipleDisplayListener(tbl));
    // �Ž��ݒ�
    if (tbl.equals(queryFileTable)) {
        item1.setEnabled(false);
        item2.setEnabled(false);
    } else if (rowCnt == 0) {
        item1.setEnabled(false);
        item2.setEnabled(false);
    } else if (rowCnt == 1) {
        item1.setEnabled(true);
        item2.setEnabled(false);
    } else if (rowCnt > 1) {
        item1.setEnabled(false);
        item2.setEnabled(true);
    }
    // �|�b�v�A�b�v���j���[�\��
    JPopupMenu popup = new JPopupMenu();
    popup.add(item1);
    if (tbl.equals(resultTable)) {
        popup.add(item2);
    }
    popup.show(e.getComponent(), e.getX(), e.getY());
}
Also used : JScrollPane(javax.swing.JScrollPane) JTable(javax.swing.JTable) JMenuItem(javax.swing.JMenuItem) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu)

Example 72 with JPopupMenu

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

the class ShowMass method mouseClicked.

/**
 * mouseClicked����
 * @param e mouseClicked�C�x���g
 */
public void mouseClicked(MouseEvent e) {
    // ���N���b�N�̏ꍇ
    if (SwingUtilities.isLeftMouseButton(e)) {
        // �_�u���N���b�N�̏ꍇ
        if (e.getClickCount() >= 2) {
            // �I�����ꂽ�S�Ă̒l�̃p�X���擾
            TreePath[] paths = BrowsePage.tree.getSelectionPaths();
            if (paths == null || paths.length > 1) {
                return;
            }
            // �I�����ꂽ�X�y�N�g�����̎擾
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) paths[0].getLastPathComponent();
            if (node instanceof LeafNode) {
                LeafNode leaf = (LeafNode) node;
                String accs = (leaf.acc != null) ? leaf.acc : "";
                try {
                    String typeName = MassBankCommon.CGI_TBL[MassBankCommon.CGI_TBL_NUM_TYPE][MassBankCommon.CGI_TBL_TYPE_DISP];
                    String reqStr = BrowsePage.baseUrl + MassBankCommon.DISPATCHER_NAME + "?type=" + typeName + "&id=" + accs;
                    reqStr += "&site=" + BrowsePage.site;
                    URL url = new URL(reqStr);
                    BrowsePage.applet.getAppletContext().showDocument(url, "_blank");
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    // �E�N���b�N�̏ꍇ
    } else if (SwingUtilities.isRightMouseButton(e)) {
        // �I�����ꂽ�S�Ă̒l�̃p�X���擾
        TreePath[] paths = BrowsePage.tree.getSelectionPaths();
        if (paths == null) {
            return;
        }
        // �I�����ꂽ�X�y�N�g�����̎擾
        int l = paths.length;
        ArrayList<String> accs = new ArrayList<String>();
        ArrayList<String> names = new ArrayList<String>();
        int num = 0;
        for (int i = 0; i < l; i++) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) paths[i].getLastPathComponent();
            if (node instanceof LeafNode) {
                LeafNode leaf = (LeafNode) node;
                names.add(leaf.name);
                accs.add(leaf.acc);
                num++;
            }
        }
        // �t�m�[�h��1�‚��I������Ă��Ȃ��ꍇ
        if (num == 0) {
            return;
        }
        // �|�b�v�A�b�v���j���[�쐬
        JPopupMenu popup = new JPopupMenu();
        JMenuItem item1 = new JMenuItem("Show Record");
        JMenuItem item2 = new JMenuItem("Multiple Display");
        popup.add(item1);
        popup.add(item2);
        // �I���s��1�s�̏ꍇ
        if (num == 1) {
            item1.addActionListener(new PopupEntryListener(accs.get(0)));
            item1.setEnabled(true);
            item2.setEnabled(false);
        } else // �I���s�������̏ꍇ
        if (num > 1) {
            item2.addActionListener(new PopupMultipleDisplayListener((String[]) accs.toArray(new String[accs.size()]), (String[]) names.toArray(new String[names.size()])));
            item1.setEnabled(false);
            item2.setEnabled(true);
        }
        // �|�b�v�A�b�v���j���[�\��
        if (num > 0) {
            popup.show(e.getComponent(), e.getX(), e.getY());
        }
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) URL(java.net.URL) JPopupMenu(javax.swing.JPopupMenu) TreePath(javax.swing.tree.TreePath) JMenuItem(javax.swing.JMenuItem)

Example 73 with JPopupMenu

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

the class PlotPane method mouseClicked.

/**
 * �}�E�X�N���b�N�C�x���g
 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
 */
public void mouseClicked(MouseEvent e) {
    if (timer != null && timer.isRunning()) {
        return;
    }
    // ���N���b�N�̏ꍇ
    if (SwingUtilities.isLeftMouseButton(e)) {
        // �N���b�N�Ԋu�Z�o
        long interSec = (e.getWhen() - lastClickedTime);
        lastClickedTime = e.getWhen();
        // �_�u���N���b�N�̏ꍇ�i�N���b�N�Ԋu280�~���b�ȓ��j
        if (interSec <= 280) {
            fromPos = toPos = null;
            initMass();
        } else // �V���O���N���b�N�̏ꍇ
        {
            // �}�E�X�N���b�N�|�C���g
            Point p = e.getPoint();
            ArrayList<Integer> tmpClickPeakList = new ArrayList<Integer>();
            int height = getHeight();
            float yscale = (height - 2.0f * MARGIN) / intensityRange;
            int start, end, its, tmpX, tmpY, tmpWidth, tmpHight;
            double mz;
            start = peaks1.getIndex(massStart);
            end = peaks1.getIndex(massStart + massRange);
            for (int i = start; i < end; i++) {
                mz = peaks1.getMz(i);
                its = peaks1.getIntensity(i);
                tmpX = MARGIN + (int) ((mz - massStart) * xscale) - // Peak�`��n�_�iX���W�j
                (int) Math.floor(xscale / 8);
                // Peak�`��n�_�iY���W�j
                tmpY = height - MARGIN - (int) (its * yscale);
                // �n�_����̕�
                tmpWidth = (int) (xscale / 8);
                // �n�_����̍���
                tmpHight = (int) (its * yscale);
                if (MARGIN > tmpX) {
                    tmpWidth = tmpWidth - (MARGIN - tmpX);
                    tmpX = MARGIN;
                }
                if (tmpWidth < 2) {
                    tmpWidth = 2;
                } else if (tmpWidth < 3) {
                    tmpWidth = 3;
                }
                // �}�E�X�_�E�������ꏊ�iX/Y���W�j��Peak�̕`��G���A�Ɋ܂܂�Ă��邩�𔻒�
                if (tmpX <= p.getX() && p.getX() <= (tmpX + tmpWidth) && tmpY <= p.getY() && p.getY() <= (tmpY + tmpHight)) {
                    tmpClickPeakList.add(i);
                }
            }
            // �}�E�X�N���b�N�Ɠ�����Peak�̐F��ύX����
            if (tmpClickPeakList.size() == 1) {
                int index = tmpClickPeakList.get(0);
                if (!peaks1.isSelectPeakFlag(index)) {
                    if (peaks1.getSelectPeakNum() < MassBankCommon.PEAK_SEARCH_PARAM_NUM) {
                        // �I����Ԃ�ݒ�
                        selectPeakList.add(String.valueOf(peaks1.getMz(index)));
                        peaks1.setSelectPeakFlag(index, true);
                    } else {
                        JOptionPane.showMessageDialog(PlotPane.this, " m/z of " + MassBankCommon.PEAK_SEARCH_PARAM_NUM + " peak or more cannot be selected. ", "Warning", JOptionPane.WARNING_MESSAGE);
                        cursorPoint = new Point();
                    }
                } else if (peaks1.isSelectPeakFlag(index)) {
                    // �I����Ԃ�����
                    selectPeakList.remove(String.valueOf(peaks1.getMz(index)));
                    peaks1.setSelectPeakFlag(index, false);
                }
                PlotPane.this.repaint();
            } else // �}�E�X�N���b�N�Ɠ����Ƀ|�b�v�A�b�v���j���[��\������
            if (tmpClickPeakList.size() >= 2) {
                // �|�b�v�A�b�v���j���[�C���X�^���X����
                selectPopup = new JPopupMenu();
                JMenuItem item = null;
                int index = -1;
                // �|�b�v�A�b�v���j���[�lj�
                for (int i = 0; i < tmpClickPeakList.size(); i++) {
                    index = tmpClickPeakList.get(i);
                    item = new JMenuItem(String.valueOf(peaks1.getMz(index)));
                    selectPopup.add(item);
                    item.addActionListener(new SelectMZPopupListener(index));
                    if (peaks1.getSelectPeakNum() >= MassBankCommon.PEAK_SEARCH_PARAM_NUM && !peaks1.isSelectPeakFlag(index)) {
                        // Peak�I�𐔂�MAX�̏ꍇ�A�I���ς�Peak�ȊO�͑I��s�‚�ݒ�
                        item.setEnabled(false);
                    }
                }
                // �|�b�v�A�b�v���j���[�\��
                selectPopup.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Point(java.awt.Point) JMenuItem(javax.swing.JMenuItem) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu)

Example 74 with JPopupMenu

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

the class DialogComponentDateTimeSelection method setPopupProperty.

private void setPopupProperty(final JDateChooser dateChooser) {
    try {
        // Java will fetch a static field that is public, if you
        // declare it to be non-static or give it the wrong scope, it
        // automatically retrieves the static field from a super
        // class/interface (from which super interface it gets it,
        // depends pretty much on the order after the "extends ..."
        // statement) If this field has the wrong type, a coding
        // problem is reported.
        final Field typeField = JDateChooser.class.getDeclaredField("popup");
        typeField.setAccessible(true);
        ((JPopupMenu) typeField.get(dateChooser)).setFocusable(false);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : JTextField(javax.swing.JTextField) JFormattedTextField(javax.swing.JFormattedTextField) Field(java.lang.reflect.Field) JPopupMenu(javax.swing.JPopupMenu) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NotConfigurableException(org.knime.core.node.NotConfigurableException) DateTimeParseException(java.time.format.DateTimeParseException)

Example 75 with JPopupMenu

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

the class NodeDialogPane method noLightWeight.

/*
     * Converts the specified and all its parent Component object to no-light
     * weight components if they are of type JComboBox, JPopupMenu, or
     * BasicComboPopup.
     */
private static void noLightWeight(final Component c) {
    if (c instanceof Container) {
        if (c instanceof JComboBox) {
            JComboBox cb = (JComboBox) c;
            cb.setLightWeightPopupEnabled(false);
        }
        if (c instanceof JPopupMenu) {
            JPopupMenu pm = (JPopupMenu) c;
            pm.setLightWeightPopupEnabled(false);
        }
        if (c instanceof BasicComboPopup) {
            BasicComboPopup cp = (BasicComboPopup) c;
            cp.setLightWeightPopupEnabled(false);
        }
        Container o = (Container) c;
        for (int cnt = o.getComponentCount(); --cnt >= 0; ) {
            Component newComponent = o.getComponent(cnt);
            noLightWeight(newComponent);
        }
    }
}
Also used : NodeContainer(org.knime.core.node.workflow.NodeContainer) Container(java.awt.Container) JComboBox(javax.swing.JComboBox) Component(java.awt.Component) JComponent(javax.swing.JComponent) BasicComboPopup(javax.swing.plaf.basic.BasicComboPopup) JPopupMenu(javax.swing.JPopupMenu)

Aggregations

JPopupMenu (javax.swing.JPopupMenu)203 JMenuItem (javax.swing.JMenuItem)105 ActionEvent (java.awt.event.ActionEvent)61 ActionListener (java.awt.event.ActionListener)46 JMenu (javax.swing.JMenu)28 Point (java.awt.Point)24 Component (java.awt.Component)20 JLabel (javax.swing.JLabel)20 JSeparator (javax.swing.JSeparator)19 JScrollPane (javax.swing.JScrollPane)18 MouseEvent (java.awt.event.MouseEvent)17 JButton (javax.swing.JButton)16 AbstractAction (javax.swing.AbstractAction)15 BorderLayout (java.awt.BorderLayout)13 JPanel (javax.swing.JPanel)13 JTable (javax.swing.JTable)13 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)12 MouseAdapter (java.awt.event.MouseAdapter)11 ArrayList (java.util.ArrayList)11 Icon (javax.swing.Icon)11