Example usage for javax.swing JPopupMenu JPopupMenu

List of usage examples for javax.swing JPopupMenu JPopupMenu

Introduction

In this page you can find the example usage for javax.swing JPopupMenu JPopupMenu.

Prototype

public JPopupMenu() 

Source Link

Document

Constructs a JPopupMenu without an "invoker".

Usage

From source file:GUI.MainWindow.java

/**
 * @param args the command line arguments
 *///from w  w w.  j  a v a 2s.  co m
public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {

        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    }
    //</editor-fold>

    // Create right click context menu for most Text Components
    final JPopupMenu copypaste = new JPopupMenu();

    JMenuItem cut = new JMenuItem(new DefaultEditorKit.CutAction());
    cut.setText("Cut");
    copypaste.add(cut);

    JMenuItem copy = new JMenuItem(new DefaultEditorKit.CopyAction());
    copy.setText("Copy");
    copypaste.add(copy);

    JMenuItem paste = new JMenuItem(new DefaultEditorKit.PasteAction());
    paste.setText("Paste");
    copypaste.add(paste);

    // Taken from here. It succinctly added a right click context menu to every text component.
    // http://stackoverflow.com/questions/19424574/adding-a-context-menu-to-all-swing-text-components-in-application
    javax.swing.UIManager.addAuxiliaryLookAndFeel(new LookAndFeel() {
        private final UIDefaults defaults = new UIDefaults() {
            public javax.swing.plaf.ComponentUI getUI(JComponent c) {
                if (c instanceof javax.swing.text.JTextComponent) {
                    if (c.getClientProperty(this) == null) {
                        c.setComponentPopupMenu(copypaste);
                        c.putClientProperty(this, Boolean.TRUE);
                    }
                }
                return null;
            }
        };

        @Override
        public UIDefaults getDefaults() {
            return defaults;
        }

        ;

        @Override
        public String getID() {
            return "TextContextMenu";
        }

        @Override
        public String getName() {
            return getID();
        }

        @Override
        public String getDescription() {
            return getID();
        }

        @Override
        public boolean isNativeLookAndFeel() {
            return false;
        }

        @Override
        public boolean isSupportedLookAndFeel() {
            return true;
        }
    });

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new MainWindow().setVisible(true);
        }
    });
}

From source file:base.BasePlayer.Main.java

void setMenuBar() {
    //filemenu.addMouseListener(this);

    //toolmenu.addMouseListener(this);
    filemenu = new JMenu("File");
    toolmenu = new JMenu("Tools");
    help = new JMenu("Help");
    about = new JMenu("About");
    menubar = new JMenuBar();
    //help.addMouseListener(this);
    exit = new JMenuItem("Exit");
    manual = new JButton("Online manual");
    manual.addActionListener(new ActionListener() {

        @Override//from ww  w. j  a v  a 2s  .c  o  m
        public void actionPerformed(ActionEvent arg0) {
            Main.gotoURL("https://baseplayer.fi/BPmanual");
        }

    });
    //   opensamples = new JMenuItem("Add samples");
    zoomout = new JButton("Zoom out");
    back = new JButton("<<");
    forward = new JButton(">>");
    manage = new JButton("Variant Manager");
    openvcfs = new JMenuItem("Add VCFs", open);
    openbams = new JMenuItem("Add BAMs", open);
    average = new JMenuItem("Coverage calculator");
    update = new JMenuItem("Update");
    update.setVisible(false);
    errorlog = new JMenuItem("View log");
    //helpLabel = new JLabel("This is pre-release version of BasePlayer\nContact: help@baseplayer.fi\n\nUniversity of Helsinki");

    addURL = new JMenu("Add from URL");
    urlField = new JTextField("Enter URL");
    addtracks = new JMenuItem("Add tracks");
    fromURL = new JMenuItem("Add track from URL");
    addcontrols = new JMenuItem("Add controls");
    pleiadesButton = new JMenuItem("PLEIADES");
    saveProject = new JMenuItem("Save project");
    saveProjectAs = new JMenuItem("Save project as...");
    openProject = new JMenuItem("Open project");
    clear = new JMenuItem("Clear data");
    clearMemory = new JMenuItem("Clean memory");
    //   welcome = new JMenuItem("Welcome screen");
    filemenu.add(openvcfs);
    filemenu.add(openbams);
    variantCaller = new JMenuItem("Variant Caller");
    tbrowser = new JMenuItem("Table Browser");
    bconvert = new JMenuItem("BED converter");
    peakCaller = new JMenuItem("Peak Caller");
    addtracks = new JMenuItem("Add tracks", open);
    filemenu.add(addtracks);
    addcontrols = new JMenuItem("Add controls", open);
    filemenu.add(addcontrols);
    filemenu.add(fromURL);
    if (pleiades) {
        pleiadesButton.setPreferredSize(buttonDimension);
        pleiadesButton.addActionListener(this);

        filemenu.add(pleiadesButton);
    }

    filemenu.add(new JSeparator());
    openProject = new JMenuItem("Open project", open);
    filemenu.add(openProject);
    saveProject = new JMenuItem("Save project", save);
    filemenu.add(saveProject);
    saveProjectAs = new JMenuItem("Save project as...", save);
    filemenu.add(saveProjectAs);
    filemenu.add(new JSeparator());
    filemenu.add(genome);
    filemenu.add(update);
    filemenu.add(clear);
    filemenu.add(new JSeparator());
    filemenu.add(exit);
    exit.addActionListener(this);
    menubar.add(filemenu);
    manage.addActionListener(this);
    manage.addMouseListener(this);
    update.addActionListener(this);
    average.addActionListener(this);
    average.setEnabled(false);
    average.setToolTipText("No bam/cram files opened");
    tbrowser.addActionListener(this);
    bconvert.addActionListener(this);
    toolmenu.add(tbrowser);
    toolmenu.add(average);
    toolmenu.add(variantCaller);
    toolmenu.add(bconvert);
    fromURL.addMouseListener(this);
    fromURL.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {

            final JPopupMenu menu = new JPopupMenu();
            final JTextField area = new JTextField();
            JButton add = new JButton("Fetch");
            JLabel label = new JLabel("Paste track URL below");
            JScrollPane menuscroll = new JScrollPane();
            add.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        String urltext = area.getText().trim();
                        Boolean size = true;
                        if (urltext.contains("pleiades")) {
                            openPleiades(urltext);
                            return;
                        }
                        if (!FileRead.isTrackFile(urltext)) {
                            showError("The file format is not supported.\n"
                                    + "Supported formats: bed, bigwig, bigbed, gff, bedgraph", "Error");
                            return;

                        }
                        if (!urltext.toLowerCase().endsWith(".bw") && !urltext.toLowerCase().endsWith(".bigwig")
                                && !urltext.toLowerCase().endsWith(".bb")
                                && !urltext.toLowerCase().endsWith(".bigbed")) {
                            URL url = null;
                            try {
                                url = new URL(urltext);
                            } catch (Exception ex) {
                                menu.setVisible(false);
                                Main.showError("Please paste whole url (protocol included)", "Error");
                                return;
                            }
                            URL testurl = url;
                            HttpURLConnection huc = (HttpURLConnection) testurl.openConnection();
                            huc.setRequestMethod("HEAD");
                            int responseCode = huc.getResponseCode();

                            if (responseCode != 404) {

                                SeekableStream stream = SeekableStreamFactory.getInstance().getStreamFor(url);
                                TabixReader tabixReader = null;
                                String index = null;

                                try {
                                    if (stream.length() / (double) 1048576 >= Settings.settings
                                            .get("bigFile")) {
                                        size = false;
                                    }
                                    tabixReader = new TabixReader(urltext, urltext + ".tbi", stream);

                                    index = urltext + ".tbi";
                                    testurl = new URL(index);
                                    huc = (HttpURLConnection) testurl.openConnection();
                                    huc.setRequestMethod("HEAD");
                                    responseCode = huc.getResponseCode();

                                    if (responseCode == 404) {
                                        menu.setVisible(false);
                                        Main.showError("Index file (.tbi) not found in the URL.", "Error");

                                        return;
                                    }

                                } catch (Exception ex) {
                                    try {
                                        tabixReader = new TabixReader(urltext,
                                                urltext.substring(0, urltext.indexOf(".gz")) + ".tbi", stream);
                                        index = urltext.substring(0, urltext.indexOf(".gz")) + ".tbi";
                                    } catch (Exception exc) {
                                        menu.setVisible(false);
                                        Main.showError("Could not read tabix file.", "Error");
                                    }
                                }
                                if (tabixReader != null && index != null) {
                                    stream.close();
                                    tabixReader.close();
                                    menu.setVisible(false);
                                    FileRead filereader = new FileRead();
                                    filereader.readBED(urltext, index, size);

                                }

                            } else {
                                menu.setVisible(false);
                                Main.showError("Not a valid URL", "Error");
                            }

                        } else {
                            URL url = null;
                            try {
                                url = new URL(urltext);
                            } catch (Exception ex) {
                                Main.showError("Please paste whole url (protocol included)", "Error");
                                return;
                            }
                            final URL testurl = url;
                            HttpURLConnection huc = (HttpURLConnection) testurl.openConnection();
                            huc.setRequestMethod("HEAD");
                            int responseCode = huc.getResponseCode();

                            if (responseCode != 404) {
                                menu.setVisible(false);
                                FileRead filereader = new FileRead();

                                filereader.readBED(urltext, "nan", true);

                            } else {
                                menu.setVisible(false);
                                Main.showError("Not a valid URL", "Error");
                            }

                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }

                }

            });
            area.setFont(Main.menuFont);
            //area.setText("https://baseplayer.fi/tracks/Mappability_1000Genomes_pilot_mask.bed.gz");
            menu.add(label);
            menu.add(menuscroll);
            menu.add(add);
            area.setPreferredSize(new Dimension(300, Main.defaultFontSize + 8));

            area.setCaretPosition(0);
            area.revalidate();
            menuscroll.getViewport().add(area);
            area.requestFocus();
            menu.pack();

            menu.show(frame, mouseX + 20, fromURL.getY());
        }

    });
    //toolmenu.add(peakCaller);
    variantCaller.setToolTipText("No bam/cram files opened");
    variantCaller.addActionListener(this);
    variantCaller.setEnabled(false);
    peakCaller.setEnabled(true);
    peakCaller.addActionListener(this);
    settings.addActionListener(this);
    clearMemory.addActionListener(this);
    errorlog.addActionListener(this);
    toolmenu.add(clearMemory);
    toolmenu.add(errorlog);
    toolmenu.add(new JSeparator());
    toolmenu.add(settings);
    menubar.add(toolmenu);
    menubar.add(manage);
    area = new JEditorPane();

    String infotext = "<html><h2>BasePlayer</h2>This is a version " + version
            + " of BasePlayer (<a href=https://baseplayer.fi>https://baseplayer.fi</a>)<br/> Author: Riku Katainen <br/> University of Helsinki<br/>"
            + "Tumor Genomics Group (<a href=http://research.med.helsinki.fi/gsb/aaltonen/>http://research.med.helsinki.fi/gsb/aaltonen/</a>) <br/> "
            + "Contact: help@baseplayer.fi <br/> <br/>"

            + "Supported filetype for variants is VCF and VCF.gz (index file will be created if missing)<br/> "
            + "Supported filetypes for reads are BAM and CRAM. Index files required (.bai or .crai). <br/> "
            + "Supported filetypes for additional tracks are BED(.gz), GFF.gz, BedGraph, BigWig, BigBed.<br/> (tabix index required for bgzipped files). <br/><br/> "

            + "For optimal usage, you should have vcf.gz and bam -files for each sample. <br/> "
            + "e.g. in case you have a sample named as sample1, name all files similarly and <br/>"
            + "place in the same folder:<br/>" + "sample1.vcf.gz<br/>" + "sample1.vcf.gz.tbi<br/>"
            + "sample1.bam<br/>" + "sample1.bam.bai<br/><br/>"
            + "When you open sample1.vcf.gz, sample1.bam is recognized and opened<br/>"
            + "on the same track.<br/><br/>"
            + "Instructional videos can be viewed at our <a href=https://www.youtube.com/channel/UCywq-T7W0YPzACyB4LT7Q3g> Youtube channel</a>";
    area = new JEditorPane();
    area.setEditable(false);
    area.setEditorKit(JEditorPane.createEditorKitForContentType("text/html"));
    area.setText(infotext);
    area.setFont(Main.menuFont);
    area.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
            HyperlinkEvent.EventType type = hyperlinkEvent.getEventType();
            final URL url = hyperlinkEvent.getURL();
            if (type == HyperlinkEvent.EventType.ACTIVATED) {
                Main.gotoURL(url.toString());
            }
        }
    });

    about.add(area);
    about.addMouseListener(this);
    help.add(about);
    help.add(manual);
    menubar.add(help);
    JLabel emptylab = new JLabel("  ");
    emptylab.setEnabled(false);
    emptylab.setOpaque(false);
    menubar.add(emptylab);

    chromosomeDropdown.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 1, Color.lightGray));
    chromosomeDropdown.setBorder(BorderFactory.createCompoundBorder(chromosomeDropdown.getBorder(),
            BorderFactory.createEmptyBorder(0, 0, 0, 0)));

    chromlabel.setToolTipText("Current chromosome");
    chromlabel.setFocusable(false);
    chromlabel.addMouseListener(this);
    chromlabel.setBackground(Color.white);
    chromlabel.setEditable(false);
    chromlabel.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 0, Color.lightGray));
    chromlabel.setBorder(BorderFactory.createCompoundBorder(chromlabel.getBorder(),
            BorderFactory.createEmptyBorder(0, 0, 0, 0)));
    menubar.add(chromlabel);
    chromosomeDropdown.setBackground(Color.white);
    chromosomeDropdown.setToolTipText("Current chromosome");
    menubar.add(chromosomeDropdown);
    JLabel empty3 = new JLabel("  ");
    empty3.setEnabled(false);
    empty3.setOpaque(false);
    menubar.add(empty3);
    menubar.add(back);
    menubar.add(searchField);
    searchField.setForeground(Color.gray);
    searchField.setBorder(BorderFactory.createCompoundBorder(searchField.getBorder(),
            BorderFactory.createEmptyBorder(0, 0, 0, 0)));

    searchField.addMouseListener(this);
    menubar.add(back);
    menubar.add(searchField);
    searchField.setForeground(Color.gray);

    back.addMouseListener(this);
    back.setToolTipText("Back");
    forward.addMouseListener(this);
    forward.setToolTipText("Forward");
    back.setEnabled(false);
    forward.setEnabled(false);

    searchField.addMouseListener(this);

    menubar.add(back);
    menubar.add(searchField);
    searchField.setForeground(Color.gray);
    back.addMouseListener(this);
    forward.addMouseListener(this);
    back.setEnabled(false);
    forward.setEnabled(false);
    forward.setMargin(new Insets(0, 2, 0, 2));
    back.setMargin(new Insets(0, 2, 0, 2));
    menubar.add(forward);
    JLabel empty4 = new JLabel("  ");
    empty4.setOpaque(false);
    empty4.setEnabled(false);
    menubar.add(empty4);
    menubar.add(zoomout);
    JLabel empty5 = new JLabel("  ");
    empty5.setEnabled(false);
    empty5.setOpaque(false);
    menubar.add(empty5);
    positionField.setEditable(false);
    positionField.setBackground(new Color(250, 250, 250));

    positionField.setMargin(new Insets(0, 2, 0, 0));
    positionField.setBorder(BorderFactory.createCompoundBorder(widthLabel.getBorder(),
            BorderFactory.createEmptyBorder(0, 0, 0, 0)));
    menubar.add(positionField);
    widthLabel.setEditable(false);
    widthLabel.setBackground(new Color(250, 250, 250));
    widthLabel.setMargin(new Insets(0, 2, 0, 0));
    widthLabel.setBorder(BorderFactory.createCompoundBorder(widthLabel.getBorder(),
            BorderFactory.createEmptyBorder(0, 0, 0, 0)));
    JLabel empty6 = new JLabel("  ");
    empty6.setEnabled(false);
    empty6.setOpaque(false);
    menubar.add(empty6);
    menubar.add(widthLabel);
    JLabel empty7 = new JLabel("  ");
    empty7.setOpaque(false);
    empty7.setEnabled(false);
    menubar.add(empty7);
}

From source file:org.forester.archaeopteryx.TreePanel.java

final private void makeBranchPopupMenus(final PhylogenyNode node) {
    _node_popup_menu = new JPopupMenu();
    final List<String> clickto_names = _main_panel.getControlPanel().getSingleClickToNames();
    _node_popup_menu_items = new JMenuItem[clickto_names.size()];
    for (int i = 0; i < clickto_names.size(); i++) {
        final String title = clickto_names.get(i);
        _node_popup_menu_items[i] = new JMenuItem(title);
        if (title.equals(Configuration.clickto_options[Configuration.display_branch_data][0])) {

            _node_popup_menu_items[i].addActionListener(this);
            _node_popup_menu.add(_node_popup_menu_items[i]);

        } else if (title.equals(Configuration.clickto_options[Configuration.reroot][0])) {

            _node_popup_menu_items[i].setEnabled(isCanReroot());
            _node_popup_menu_items[i].addActionListener(this);
            _node_popup_menu.add(_node_popup_menu_items[i]);
        }//from www .j a v  a 2s. com

    }
}

From source file:edu.harvard.i2b2.patientSet.ui.PatientSetJPanel.java

private void createPopupMenu() {
    JMenuItem menuItem;/*from ww w.  j  a  v a 2 s  .  co  m*/

    // Create the popup menu.
    JPopupMenu popup = new JPopupMenu();

    menuItem = new JMenuItem("Rename ...");
    // menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
    // java.awt.event.KeyEvent.VK_R,
    // java.awt.event.InputEvent.CTRL_MASK));
    menuItem.addActionListener(this);
    popup.add(menuItem);

    /* popup.add(new javax.swing.JSeparator()); */

    menuItem = new JMenuItem("Delete");
    // menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
    // java.awt.event.KeyEvent.VK_D,
    // java.awt.event.InputEvent.CTRL_MASK));
    menuItem.addActionListener(this);
    popup.add(menuItem);

    popup.add(new javax.swing.JSeparator());

    menuItem = new JMenuItem("Refresh All");
    // menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
    // java.awt.event.KeyEvent.VK_A,
    // java.awt.event.InputEvent.CTRL_MASK));
    menuItem.addActionListener(this);
    popup.add(menuItem);

    menuItem = new JMenuItem("Cancel");
    // menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
    // java.awt.event.KeyEvent.VK_C,
    // java.awt.event.InputEvent.CTRL_MASK));
    menuItem.addActionListener(this);
    popup.add(menuItem);

    // Add listener to the tree
    MouseListener popupListener = new PreviousRunsTreePopupListener(popup);
    jTree1.addMouseListener(popupListener);
    jTree1.addMouseMotionListener(new PreviousRunsTreeMouseMoveListener());
}

From source file:edu.harvard.mcz.imagecapture.SpecimenDetailsViewPane.java

/**
 * This method initializes jTableCollectors   
 *    /* w  w w .  j a  v a 2s. c o m*/
 * @return javax.swing.JTable   
 */
private JTable getJTableCollectors() {
    if (jTableCollectors == null) {
        jTableCollectors = new JTable(new CollectorTableModel());

        // Note: When setting the values, the table column editor needs to be reset there, as the model is replaced.

        //JTextField field = new JTextField();
        FilteringAgentJComboBox field = new FilteringAgentJComboBox();
        //field.setInputVerifier(MetadataRetriever.getInputVerifier(Collector.class, "CollectorName", field));
        //jTableCollectors.getColumnModel().getColumn(0).setCellEditor(new PicklistTableCellEditor(field, true));
        jTableCollectors.getColumnModel().getColumn(0).setCellEditor(new ComboBoxCellEditor(field));
        jTableCollectors.setRowHeight(jTableCollectors.getRowHeight() + 4);
        jTableCollectors.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent e) {
                thisPane.setStateToDirty();
            }
        });

        jTableCollectors.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                if (e.isPopupTrigger()) {
                    clickedOnCollsRow = ((JTable) e.getComponent()).getSelectedRow();
                    jPopupCollectors.show(e.getComponent(), e.getX(), e.getY());
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                if (e.isPopupTrigger()) {
                    clickedOnCollsRow = ((JTable) e.getComponent()).getSelectedRow();
                    jPopupCollectors.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        });

        jPopupCollectors = new JPopupMenu();
        JMenuItem mntmDeleteRow = new JMenuItem("Delete Row");
        mntmDeleteRow.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    log.debug(clickedOnCollsRow);
                    if (clickedOnCollsRow >= 0) {
                        int ok = JOptionPane.showConfirmDialog(thisPane, "Delete the selected collector?",
                                "Delete Collector", JOptionPane.OK_CANCEL_OPTION);
                        if (ok == JOptionPane.OK_OPTION) {
                            log.debug("deleting collectors row " + clickedOnCollsRow);
                            ((CollectorTableModel) jTableCollectors.getModel()).deleteRow(clickedOnCollsRow);
                            setStateToDirty();
                        } else {
                            log.debug("collector row delete canceled by user.");
                        }
                    } else {
                        JOptionPane.showMessageDialog(thisPane,
                                "Unable to select row to delete.  Try empting the value and pressing Save.");
                    }
                } catch (Exception ex) {
                    log.error(ex.getMessage());
                    JOptionPane.showMessageDialog(thisPane,
                            "Failed to delete a collector row. " + ex.getMessage());
                }
            }
        });
        jPopupCollectors.add(mntmDeleteRow);
    }
    return jTableCollectors;
}

From source file:edu.harvard.mcz.imagecapture.SpecimenDetailsViewPane.java

private JTable getJTableSpecimenParts() {
    if (jTableSpecimenParts == null) {
        try {/*from w  w  w .jav a 2 s .  com*/
            jTableSpecimenParts = new JTable(new SpecimenPartsTableModel(specimen.getSpecimenParts()));
            jTableSpecimenParts.getColumnModel().getColumn(0).setPreferredWidth(90);
        } catch (NullPointerException e) {
            jTableSpecimenParts = new JTable(new SpecimenPartsTableModel());
            jTableSpecimenParts.getColumnModel().getColumn(0).setPreferredWidth(90);
        }
        setSpecimenPartsTableCellEditors();

        log.debug(specimen.getSpecimenParts().size());

        jTableSpecimenParts.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                if (e.isPopupTrigger()) {
                    clickedOnPartsRow = ((JTable) e.getComponent()).getSelectedRow();
                    jPopupSpecimenParts.show(e.getComponent(), e.getX(), e.getY());
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                if (e.isPopupTrigger()) {
                    clickedOnPartsRow = ((JTable) e.getComponent()).getSelectedRow();
                    jPopupSpecimenParts.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        });

        jPopupSpecimenParts = new JPopupMenu();
        JMenuItem mntmDeleteRow = new JMenuItem("Delete Row");
        mntmDeleteRow.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    if (clickedOnPartsRow >= 0) {
                        int ok = JOptionPane.showConfirmDialog(thisPane, "Delete the selected preparation?",
                                "Delete Preparation", JOptionPane.OK_CANCEL_OPTION);
                        if (ok == JOptionPane.OK_OPTION) {
                            log.debug("deleting parts row " + clickedOnPartsRow);
                            ((SpecimenPartsTableModel) jTableSpecimenParts.getModel())
                                    .deleteRow(clickedOnPartsRow);
                            setStateToDirty();
                        } else {
                            log.debug("parts row delete canceled by user.");
                        }
                    } else {
                        JOptionPane.showMessageDialog(thisPane, "Unable to select row to delete.");
                    }
                } catch (Exception ex) {
                    log.error(ex.getMessage());
                    JOptionPane.showMessageDialog(thisPane,
                            "Failed to delete a part attribute row. " + ex.getMessage());
                }
            }
        });
        jPopupSpecimenParts.add(mntmDeleteRow);
    }
    return jTableSpecimenParts;
}

From source file:edu.harvard.i2b2.query.ui.GroupPanel.java

private void createPopupMenu() {
    JMenuItem menuItem;//from w  w  w.  ja  va2  s. c o m

    // Create the popup menu.
    JPopupMenu popup = new JPopupMenu();
    /*
     * menuItem = new JMenuItem("Constrain Item ...");
     * menuItem.setAccelerator
     * (javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C,
     * java.awt.event.InputEvent.CTRL_MASK));
     * menuItem.addActionListener(this); popup.add(menuItem);
     */

    menuItem = new JMenuItem("Delete Item");
    // menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.
    // event.KeyEvent.VK_X,
    // java.awt.event.InputEvent.CTRL_MASK));
    menuItem.addActionListener(this);
    popup.add(menuItem);

    /*
     * popup.add(new javax.swing.JSeparator());
     * 
     * menuItem = new JMenuItem("Exclude All Items");
     * menuItem.setAccelerator
     * (javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A,
     * java.awt.event.InputEvent.CTRL_MASK));
     * menuItem.addActionListener(this); popup.add(menuItem);
     */

    popup.add(new javax.swing.JSeparator());

    menuItem = new JMenuItem("Set Value ...");
    menuItem.setEnabled(false);
    // menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.
    // event.KeyEvent.VK_S,
    // java.awt.event.InputEvent.CTRL_MASK));
    menuItem.addActionListener(this);
    popup.add(menuItem);

    menuItem = new JMenuItem("Set Modifier Value ...");
    menuItem.setEnabled(false);
    // menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.
    // event.KeyEvent.VK_S,
    // java.awt.event.InputEvent.CTRL_MASK));
    menuItem.addActionListener(this);
    popup.add(menuItem);

    // Add listener to the tree
    MouseListener popupListener = new ConceptTreePopupListener(popup);
    jTree1.addMouseListener(popupListener);
}

From source file:edu.harvard.mcz.imagecapture.SpecimenDetailsViewPane.java

/**
 * This method initializes jTable   //from   w  ww  .  j a  va  2 s.c  om
 *    
 * @return javax.swing.JTable   
 */
private JTable getJTable() {
    if (jTableNumbers == null) {
        jTableNumbers = new JTable(new NumberTableModel());
        JComboBox<String> jComboNumberTypes = new JComboBox<String>();
        jComboNumberTypes.setModel(new DefaultComboBoxModel<String>(NumberLifeCycle.getDistinctTypes()));
        jComboNumberTypes.setEditable(true);
        TableColumn typeColumn = jTableNumbers.getColumnModel().getColumn(NumberTableModel.COLUMN_TYPE);
        DefaultCellEditor comboBoxEditor = new DefaultCellEditor(jComboNumberTypes);
        //TODO: enable autocomplete for numbertypes picklist.
        //AutoCompleteDecorator.decorate((JComboBox) comboBoxEditor.getComponent());
        typeColumn.setCellEditor(comboBoxEditor);
        DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
        renderer.setToolTipText("Click for pick list of number types.");
        typeColumn.setCellRenderer(renderer);
        jTableNumbers.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent e) {
                thisPane.setStateToDirty();
            }
        });

        jTableNumbers.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                if (e.isPopupTrigger()) {
                    clickedOnNumsRow = ((JTable) e.getComponent()).getSelectedRow();
                    jPopupNumbers.show(e.getComponent(), e.getX(), e.getY());
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                if (e.isPopupTrigger()) {
                    clickedOnNumsRow = ((JTable) e.getComponent()).getSelectedRow();
                    jPopupNumbers.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        });

        jPopupNumbers = new JPopupMenu();
        JMenuItem mntmDeleteRow = new JMenuItem("Delete Row");
        mntmDeleteRow.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    if (clickedOnNumsRow >= 0) {
                        int ok = JOptionPane.showConfirmDialog(thisPane, "Delete the selected number?",
                                "Delete Number", JOptionPane.OK_CANCEL_OPTION);
                        if (ok == JOptionPane.OK_OPTION) {
                            log.debug("deleting numbers row " + clickedOnNumsRow);
                            ((NumberTableModel) jTableNumbers.getModel()).deleteRow(clickedOnNumsRow);
                            setStateToDirty();
                        } else {
                            log.debug("number row delete canceled by user.");
                        }
                    } else {
                        JOptionPane.showMessageDialog(thisPane,
                                "Unable to select row to delete.  Try empting number and type and pressing Save.");
                    }
                } catch (Exception ex) {
                    log.error(ex.getMessage());
                    JOptionPane.showMessageDialog(thisPane,
                            "Failed to delete a number row. " + ex.getMessage());
                }
            }
        });
        jPopupNumbers.add(mntmDeleteRow);
    }
    return jTableNumbers;
}

From source file:de.main.sessioncreator.DesktopApplication1View.java

private void btnWizardNext(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnWizardNext
    int selTab = wizardtabp.getSelectedIndex();
    int maxTab = wizardtabp.getTabCount();
    try {/*  www .ja  v  a2 s. c om*/
        wizardbtnBack.setEnabled(true);
        wizardbtntopBack.setEnabled(true);
        wizardtabp.setSelectedIndex(selTab + 1);

        if (wizardtabp.getTitleAt(wizardtabp.getSelectedIndex()).contains("Charter")) {
            wizardChckBxNewCharter.addActionListener(new chckBxNewCharterListener());
            swingHelper.setTab1EnableAt(wizardtabp, 1);
            progressBar.setVisible(true);
            progressBar.setIndeterminate(true);
            wizardbtnBack.setEnabled(false);
            wizardbtntopBack.setEnabled(false);
            wizardbtnNext.setEnabled(false);
            wizardbtntopNext.setEnabled(false);
            mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            wizardCmbxCharter.removeAllItems();
            fileHelper.charterList.clear();
            final File directory = new File(wizardTfPathTodo.getText());
            worker = new SwingWorker<String, Void>() {

                @Override
                protected String doInBackground() {
                    return getCharterBackgroundW(directory);
                }

                @Override
                protected void done() {
                    try {
                        if (!worker.get().contains("no")) {
                            progressBar.setIndeterminate(false);
                            progressBar.setVisible(false);
                            wizardbtnBack.setEnabled(true);
                            wizardbtntopBack.setEnabled(true);
                            wizardbtnNext.setEnabled(true);
                            wizardbtntopNext.setEnabled(true);
                            int no = wizardCmbxCharter.getItemCount();
                            wizardLblChooseCharter.setText("Please select one of " + no + " Charter");
                            mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                        } else {
                            progressBar.setIndeterminate(false);
                            progressBar.setVisible(false);
                            wizardbtnBack.setEnabled(true);
                            wizardbtntopBack.setEnabled(true);
                            wizardbtnNext.setEnabled(false);
                            wizardbtntopNext.setEnabled(false);
                            mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                        }
                    } catch (InterruptedException ex) {
                        Logger.getLogger(DesktopApplication1View.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (ExecutionException ex) {
                        Logger.getLogger(DesktopApplication1View.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            };
            worker.execute();
        }
        if (wizardtabp.getTitleAt(wizardtabp.getSelectedIndex()).contains("Areas")) {
            swingHelper.setTab1EnableAt(wizardtabp, 2);
            progressBar.setVisible(true);
            progressBar.setIndeterminate(true);
            wizardbtnBack.setEnabled(false);
            wizardbtntopBack.setEnabled(false);
            wizardbtnNext.setEnabled(false);
            wizardbtntopNext.setEnabled(false);
            wizardbtnAddAreas.setEnabled(false);
            if (wizardtaChoosenAreas.getDocument().getLength() == 0) {
                wizardbtnRemoveArea.setEnabled(false);
            } else {
                wizardbtnRemoveArea.setEnabled(true);
            }

            wizardtaChoosenAreas.getDocument().addDocumentListener(new choosenAreaListener());
            wizardtabpAreas.removeAll();
            final File coverageini = new File(wizardtfCoverageini.getText());
            getAreasBacgroundW(coverageini);
            wizardbtnBack.setEnabled(true);
            wizardbtntopBack.setEnabled(true);
            wizardbtnNext.setEnabled(true);
            wizardbtntopNext.setEnabled(true);
            if (wizardChckBxNewCharter.isSelected()) {
                wizardbtnSaveTodo.setEnabled(true);
            }
            wizardbtnNext.setText("Create Testsession");
            progressBar.setIndeterminate(false);
            progressBar.setVisible(false);
            if (!wizardChckBxNewCharter.isSelected()) {
                String todo = ChoosenCharter.substring(ChoosenCharter.indexOf("(" + wizardTfPathTodo.getText()))
                        .replace("(", "").replace(")", "");
                final File todocheckliste = new File(todo);
                String msg = "Import all Areas from the Todo-Session?";
                fileHelper.getAreasChecklist(todocheckliste);
                fileHelper.areaChecklist.remove(0);
                if (!fileHelper.areaChecklist.get(0).isEmpty()) {
                    if (JOptionPane.showConfirmDialog(wizardtabpAreas, msg, "Import?",
                            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == 0) {
                        wizardtaChoosenAreas.setText("");
                        for (String s : fileHelper.areaChecklist) {
                            wizardtaChoosenAreas.append(s + "\n");
                        }
                        wizardtaChoosenAreas.setCaretPosition(0);
                    }
                }
            }
        }
        if (wizardtabp.getTitleAt(wizardtabp.getSelectedIndex()).contains("Testsession")) {
            swingHelper.setTab1EnableAt(wizardtabp, 3);
            wizardbtnNext.setVisible(false);
            wizardbtntopNext.setEnabled(false);
            wizardbtnStart.addActionListener(new ButtonListenerStart());
            wizardbtntopStart.addActionListener(new ButtonListenerStart());
            wizardbtnStop.addActionListener(new ButtonListenerStop());
            wizardbtntopStop.addActionListener(new ButtonListenerStop());
            if (wizardChckBxNewCharter.isSelected()) {
                wizardtaCharterdynamic.setText(wizardtaNewCharter.getText().trim());
            } else {
                wizardtaCharterdynamic.setText(
                        ChoosenCharter.substring(0, ChoosenCharter.indexOf("(" + wizardTfPathTodo.getText())));
            }
            statusMessageLabel.setText("");
            wizardbtnStart.setVisible(true);
            wizardbtnStart.setEnabled(true);
            wizardbtntopStart.setEnabled(true);
            wizardbtnStop.setVisible(true);
            wizardbtnStop.setEnabled(false);
            wizardbtntopStop.setEnabled(false);
            final JPopupMenu popupMenu = new JPopupMenu();
            final File coverageini = new File(wizardtfCoverageini.getText());
            swingHelper.getAreastoPopupMenu(popupMenu, coverageini, new alBugsIssue());
            popupListener2 = new PopupListener(popupMenu);
            wizardtaTestsessionAreas.addMouseListener(popupListener2);
            wizardtaTestsessionAreas.setText(wizardtaChoosenAreas.getText());
            wizardtaTestsessionAreas.setCaretPosition(0);
            wizardtaCharterdynamic.setCaretPosition(0);
            if (wizardChckBxSecondTester.isSelected()) {
                TesterRealname = wizardCmbxTester.getSelectedItem().toString();
                wizardtfNameOfTester.setText(TesterRealname.substring(4) + " "
                        + wizardCmbxMoreTester.getSelectedItem().toString().substring(4));
            } else {
                TesterRealname = wizardCmbxTester.getSelectedItem().toString();
                wizardtfNameOfTester.setText(TesterRealname.substring(4));
            }
        }
        if (wizardtabp.getSelectedIndex() == maxTab) {
            wizardbtnNext.setEnabled(false);
            wizardbtntopNext.setEnabled(false);
        }
    } catch (IndexOutOfBoundsException ex) {
        statusMessageLabel.setText(ex.getMessage());
    }
}

From source file:src.gui.ItSIMPLE.java

/**
 * This method initializes treePopupMenu
 *
 * @return javax.swing.JPopupMenu/*from  ww w.ja  v  a2 s  .co  m*/
 */
private JPopupMenu getTreePopupMenu() {

    if (treePopupMenu == null) {
        treePopupMenu = new JPopupMenu();
    } else {
        treePopupMenu.removeAll();
        ItTreeNode selected = (ItTreeNode) projectsTree.getLastSelectedPathComponent();
        if (selected.getData() != null) {

            String projectType = selected.getData().getDocument().getRootElement().getName();

            //Check if this is a UML project
            if (projectType.equals("project")) {
                switch (selected.getLevel()) {
                case 1: {
                    treePopupMenu.add(getNewDiagramMenu());
                    treePopupMenu.add(importModelingPatternAction);
                    treePopupMenu.addSeparator();
                    treePopupMenu.add(closeProjectAction);
                }
                    break;
                case 2: {
                    if (selected.getData().getName().equals("domain")) {
                        // domain menus
                        treePopupMenu.add(getNewDomainMenu());
                        treePopupMenu.add(getOpenAsDomainMenu());
                        treePopupMenu.add(getImportProblemMenu());
                        treePopupMenu.addSeparator();
                        treePopupMenu.add(duplicateAction);
                        treePopupMenu.add(deleteDomainAction);
                    } else if (selected.getData().getName().equals("stateMachineDiagram")) {
                        treePopupMenu.add(openDiagramAction);
                        treePopupMenu.add(getOpenAsPetriNetMenu());
                        treePopupMenu.addSeparator();
                        treePopupMenu.add(deleteDiagramAction);
                    } else {
                        treePopupMenu.add(openDiagramAction);
                        treePopupMenu.addSeparator();
                        treePopupMenu.add(deleteDiagramAction);

                    }
                }
                    break;
                case 3: {
                    if (selected.getData().getName().equals("problem")) {
                        // problem menus
                        treePopupMenu.add(getNewProblemMenu());
                        treePopupMenu.add(getOpenAsProblemMenu());
                        treePopupMenu.addSeparator();
                        treePopupMenu.add(duplicateAction);
                        treePopupMenu.add(deleteProblemAction);
                    } else if (selected.getData().getName().equals("repositoryDiagram")) {
                        // repository diagram
                        treePopupMenu.add(openDiagramAction);
                    }
                }
                    break;
                case 4: {
                    if (selected.getData().getName().equals("objectDiagram")) {
                        treePopupMenu.add(openDiagramAction);
                        treePopupMenu.addSeparator();
                        treePopupMenu.add(deleteDiagramAction);
                    }
                }
                    break;
                default:
                    break;
                }
            }
            //Check if this is a UML project
            else if (projectType.equals("pddlproject")) {
                switch (selected.getLevel()) {
                case 1: {
                    //TODO: getNewMenu (problem)
                    //treePopupMenu.add(getNewDiagramMenu());
                    //treePopupMenu.addSeparator();
                    treePopupMenu.add(closeProjectAction);
                }
                    break;
                case 2: {
                    if (selected.getData().getName().equals("pddldomain")) {
                        // domain menus
                        //treePopupMenu.add(getNewDomainMenu())
                        treePopupMenu.add(openPDDLFile);
                        //treePopupMenu.add(duplicateAction);
                        //treePopupMenu.addSeparator();
                        //treePopupMenu.add(deletePDDLDomainAction);

                    } else {
                        //add new problem instance
                        treePopupMenu.add(newPDDLProblemFileAction);
                    }
                }
                    break;
                case 3: {
                    //will we have anything in this leve;?
                    treePopupMenu.add(openPDDLFile);
                    //treePopupMenu.add(duplicateAction);
                    treePopupMenu.addSeparator();
                    treePopupMenu.add(deletePDDLProblemAction);
                }
                    break;
                default:
                    break;
                }

            }

        }
    }
    return treePopupMenu;
}