Example usage for javax.swing JPopupMenu add

List of usage examples for javax.swing JPopupMenu add

Introduction

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

Prototype

public JMenuItem add(Action a) 

Source Link

Document

Appends a new menu item to the end of the menu which dispatches the specified Action object.

Usage

From source file:org.fhaes.jsea.JSEAFrame.java

/**
 * Setup the GUI components// w  w  w . java  2  s  .  co m
 */
private void setupGui() {

    setTitle("jSEA - Superposed Epoch Analysis");

    getContentPane().setLayout(new MigLayout("", "[1200px,grow,fill]", "[][600px,grow,fill]"));

    initActions();
    setupMenu();
    setupToolbar();

    this.setIconImage(Builder.getApplicationIcon());
    {
        JSplitPane splitPane = new JSplitPane();
        splitPane.setOneTouchExpandable(true);
        getContentPane().add(splitPane, "cell 0 1,alignx left,aligny top");
        splitPane.setLeftComponent(contentPanel);
        contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPanel.setLayout(new MigLayout("", "[grow,fill]", "[78.00][][][grow][]"));
        {
            JPanel panel = new JPanel();
            panel.setBorder(
                    new TitledBorder(null, "Input Files", TitledBorder.LEADING, TitledBorder.TOP, null, null));
            contentPanel.add(panel, "cell 0 0,grow");
            panel.setLayout(new MigLayout("", "[][][grow][]", "[][]"));
            {
                JLabel lblContinuousTimeSeries = new JLabel("Continuous time series file:");
                panel.add(lblContinuousTimeSeries, "cell 0 0,alignx trailing");
            }
            {
                HelpTipButton label = new HelpTipButton(
                        "Continuous time series data files should be two column comma seperated (CSV) text files.  Column one should contains the years (in sequence), and column two should contain the data values.  If there are header lines or comments in the file, these lines should beginning with a *");
                panel.add(label, "cell 1 0,alignx trailing");
            }
            {
                txtTimeSeriesFile = new JTextField();
                txtwrapper = new TextComponentWrapper(txtTimeSeriesFile,
                        PrefKey.JSEA_CONTINUOUS_TIME_SERIES_FILE, "");
                txtTimeSeriesFile.setEditable(true);
                panel.add(txtTimeSeriesFile, "cell 2 0,growx");
                txtTimeSeriesFile.setColumns(10);
            }
            {
                btnTimeSeriesFile = new JButton();
                btnTimeSeriesFile.setIcon(Builder.getImageIcon("fileopen16.png"));
                btnTimeSeriesFile.setActionCommand("TimeSeriesFileBrowse");
                btnTimeSeriesFile.addActionListener(this);
                btnTimeSeriesFile.setPreferredSize(new Dimension(25, 25));
                btnTimeSeriesFile.setMaximumSize(new Dimension(25, 25));
                btnTimeSeriesFile.putClientProperty("JButton.buttonType", "segmentedTextured");
                btnTimeSeriesFile.putClientProperty("JButton.segmentPosition", "middle");

                panel.add(btnTimeSeriesFile, "cell 3 0");
            }
            {
                JLabel lblEventListFile = new JLabel("Event list file:");
                panel.add(lblEventListFile, "cell 0 1,alignx trailing");
            }
            {
                HelpTipButton helpTipButton = new HelpTipButton(
                        "Event data files should be a text file with a single column of integer year values.  If there are any header or comment lines, these should begin with a *");
                panel.add(helpTipButton, "cell 1 1,alignx trailing");
            }
            {
                txtEventListFile = new JTextField();
                new TextComponentWrapper(txtEventListFile, PrefKey.JSEA_EVENT_LIST_FILE, "");
                txtEventListFile.setEditable(false);
                panel.add(txtEventListFile, "cell 2 1,growx");
                txtEventListFile.setColumns(10);
            }
            {
                btnEventListFile = new JButton();
                btnEventListFile.setIcon(Builder.getImageIcon("fileopen16.png"));
                btnEventListFile.setActionCommand("EventListFileBrowse");
                btnEventListFile.addActionListener(this);
                btnEventListFile.setPreferredSize(new Dimension(25, 25));
                btnEventListFile.setMaximumSize(new Dimension(25, 25));
                btnEventListFile.putClientProperty("JButton.buttonType", "segmentedTextured");
                btnEventListFile.putClientProperty("JButton.segmentPosition", "middle");
                panel.add(btnEventListFile, "cell 3 1");
            }
        }
        {
            JPanel panel = new JPanel();
            panel.setBorder(new TitledBorder(null, "Window, Simulation and Statistics", TitledBorder.LEADING,
                    TitledBorder.TOP, null, null));
            contentPanel.add(panel, "cell 0 1,grow");
            panel.setLayout(new MigLayout("", "[right][][fill][10px:10px:10px][right][][90.00,grow,fill]",
                    "[grow][][][]"));
            {
                JLabel lblYears = new JLabel("Years to analyse:");
                panel.add(lblYears, "cell 0 0");
            }
            {
                HelpTipButton helpTipButton = new HelpTipButton(
                        "Specify which years from the dataset to analyse.");
                panel.add(helpTipButton, "cell 1 0");
            }
            {
                JPanel panel_1 = new JPanel();
                panel.add(panel_1, "cell 2 0 5 1,grow");
                panel_1.setLayout(new MigLayout("fill, insets 0", "[80px:80px][][80px:80px,fill][grow]", "[]"));
                {
                    spnFirstYear = new JSpinner();
                    spnFirstYear.setEnabled(false);
                    panel_1.add(spnFirstYear, "cell 0 0,growx");
                    spnFirstYear.setModel(new SpinnerNumberModel(new Integer(0), null, null, new Integer(1)));
                    spnFirstYear.setEditor(new JSpinner.NumberEditor(spnFirstYear, "#"));
                    new SpinnerWrapper(spnFirstYear, PrefKey.JSEA_FIRST_YEAR, 0);
                }
                {
                    JLabel lblTo = new JLabel("-");
                    panel_1.add(lblTo, "cell 1 0");
                }
                {
                    spnLastYear = new JSpinner();
                    spnLastYear.setEnabled(false);
                    panel_1.add(spnLastYear, "cell 2 0");
                    spnLastYear.setModel(new SpinnerNumberModel(new Integer(2020), null, null, new Integer(1)));
                    spnLastYear.setEditor(new JSpinner.NumberEditor(spnLastYear, "#"));
                    new SpinnerWrapper(spnLastYear, PrefKey.JSEA_LAST_YEAR, 2020);
                }
                {
                    chkAllYears = new JCheckBox("all years in series");
                    chkAllYears.setSelected(true);
                    chkAllYears.setActionCommand("AllYearsCheckbox");
                    chkAllYears.addActionListener(this);
                    panel_1.add(chkAllYears, "cell 3 0");
                }
            }
            {
                JLabel lblLagsPriorTo = new JLabel("Lags prior to event:");
                panel.add(lblLagsPriorTo, "cell 0 1");
            }
            {
                HelpTipButton helpTipButton = new HelpTipButton("");
                panel.add(helpTipButton, "cell 1 1");
            }
            {
                spnLagsPrior = new JSpinner();
                new SpinnerWrapper(spnLagsPrior, PrefKey.JSEA_LAGS_PRIOR_TO_EVENT, 6);
                panel.add(spnLagsPrior, "cell 2 1,growx");
                // spnLagsPrior.setModel(new SpinnerNumberModel(6, 1, 100, 1));
                spnLagsPrior.addChangeListener(new ChangeListener() {

                    @Override
                    public void stateChanged(ChangeEvent e) {

                        segmentationPanel.table.tableModel.clearSegments();
                        validateForm();
                    }
                });
            }
            {
                JLabel lblSimulationsToRun = new JLabel("Simulations:");
                panel.add(lblSimulationsToRun, "cell 4 1");
            }
            {
                HelpTipButton helpTipButton = new HelpTipButton(
                        "Number of simulations to run.  Increasing the number of simulations increases the analysis time.");
                panel.add(helpTipButton, "cell 5 1");
            }
            {
                spnSimulationsToRun = new JSpinner();
                new SpinnerWrapper(spnSimulationsToRun, PrefKey.JSEA_SIMULATION_COUNT, 1000);
                panel.add(spnSimulationsToRun, "cell 6 1");
                spnSimulationsToRun.setModel(new SpinnerNumberModel(1000, 1, 10096, 1));
            }
            {
                JLabel lblLagsFollowingThe = new JLabel("Lags following the event:");
                panel.add(lblLagsFollowingThe, "cell 0 2");
            }
            {
                HelpTipButton helpTipButton = new HelpTipButton("");
                panel.add(helpTipButton, "cell 1 2");
            }
            {
                spnLagsAfter = new JSpinner();
                new SpinnerWrapper(spnLagsAfter, PrefKey.JSEA_LAGS_AFTER_EVENT, 4);
                panel.add(spnLagsAfter, "cell 2 2,growx");
                spnLagsAfter.addChangeListener(new ChangeListener() {

                    @Override
                    public void stateChanged(ChangeEvent e) {

                        segmentationPanel.table.tableModel.clearSegments();
                        validateForm();
                    }
                });
            }
            {
                JLabel lblSeedNumber = new JLabel("Seed number:");
                panel.add(lblSeedNumber, "cell 4 2");
            }
            {
                HelpTipButton helpTipButton = new HelpTipButton(
                        "The analysis requires a pseudo-random component which is seeded with the seed number (a large integer value).  Running analyses with the same seed number enables produces the same results.  You can leave the seed as the default number unless you specifically want to generate results from a different randomised pool.");
                panel.add(helpTipButton, "cell 5 2");
            }
            {
                spnSeedNumber = new JSpinner();
                new SpinnerWrapper(spnSeedNumber, PrefKey.JSEA_SEED_NUMBER, 30188);
                panel.add(spnSeedNumber, "cell 6 2");
                spnSeedNumber.setModel(new SpinnerNumberModel(30188, 10000, 1000000, 1));
            }
            {
                JLabel lblIncludeIncompleteWindow = new JLabel("Include incomplete epoch:");
                panel.add(lblIncludeIncompleteWindow, "cell 0 3");
            }
            {
                HelpTipButton helpTipButton = new HelpTipButton("");
                panel.add(helpTipButton, "cell 1 3");
            }
            {
                chkIncludeIncompleteWindow = new JCheckBox("");
                new CheckBoxWrapper(chkIncludeIncompleteWindow, PrefKey.JSEA_INCLUDE_INCOMPLETE_WINDOW, false);

                panel.add(chkIncludeIncompleteWindow, "cell 2 3");
            }
            {
                JLabel lblPvalue = new JLabel("p-value:");
                panel.add(lblPvalue, "cell 4 3");
            }
            {
                HelpTipButton helpTipButton = new HelpTipButton(
                        "The cutoff value to use for statistical significance");
                panel.add(helpTipButton, "cell 5 3,alignx trailing");
            }
            {
                cbxPValue = new JComboBox();
                panel.add(cbxPValue, "cell 6 3");
                cbxPValue.setModel(new DefaultComboBoxModel(new Double[] { 0.05, 0.01, 0.001 }));
            }
        }
        {
            JPanel panel = new JPanel();
            panel.setBorder(new TitledBorder(null, "Chart Options", TitledBorder.LEADING, TitledBorder.TOP,
                    null, null));
            contentPanel.add(panel, "cell 0 2,grow");

            panel.setLayout(new MigLayout("", "[right][][grow]", "[][]"));
            {
                JLabel lblTitleOfChart = new JLabel("Title of chart:");
                panel.add(lblTitleOfChart, "cell 0 0,alignx trailing");
            }
            {
                HelpTipButton helpTipButton = new HelpTipButton(
                        "Title to use on the chart.  The placeholder {segment} is replaced with the years of the segment being plotted.");
                panel.add(helpTipButton, "cell 1 0,alignx trailing");
            }
            {
                txtChartTitle = new JTextField();
                txtChartTitle.setToolTipText("<html>Title to be displayed on the<br/>" + "chart output");
                new TextComponentWrapper(txtChartTitle, PrefKey.JSEA_CHART_TITLE, "Chart title {segment}");
                panel.add(txtChartTitle, "cell 2 0,growx,aligny top");
                txtChartTitle.setColumns(10);
            }
            {
                JLabel lblYaxisLabel = new JLabel("Continuous series (y-axis) label");
                panel.add(lblYaxisLabel, "cell 0 1,alignx trailing");
            }
            {
                txtYAxisLabel = new JTextField();
                txtYAxisLabel
                        .setToolTipText("<html>Label to be displayed on the<br/> " + "continuous series axis");
                new TextComponentWrapper(txtYAxisLabel, PrefKey.JSEA_YAXIS_LABEL, "Y Axis");
                panel.add(txtYAxisLabel, "cell 2 1,growx");
                txtYAxisLabel.setColumns(10);
            }
        }
        {
            // Segmentation implementation used from FHSampleSize
            segmentationPanel = new SegmentationPanel();
            segmentationPanel.chkSegmentation.setText("Process subset or segments of events?");
            segmentationPanel.chkSegmentation.setActionCommand("SegmentationMode");
            segmentationPanel.chkSegmentation.addActionListener(this);
            contentPanel.add(segmentationPanel, "cell 0 3,grow");
        }
        {
            tabbedPane = new JTabbedPane(JTabbedPane.BOTTOM);
            splitPane.setRightComponent(tabbedPane);
            {
                summaryPanel = new JPanel();
                tabbedPane.addTab("Summary ", Builder.getImageIcon("info.png"), summaryPanel, null);
                summaryPanel.setLayout(new BorderLayout(0, 0));
                {
                    scrollPane = new JScrollPane();
                    summaryPanel.add(scrollPane);
                    {
                        txtSummary = new JTextArea();
                        txtSummary.setEditable(false);
                        scrollPane.setViewportView(txtSummary);
                        JMenuItem mntmCopy = new JMenuItem(actionCopy);
                        JPopupMenu popup = new JPopupMenu();
                        addPopup(scrollPane, popup);
                        popup.add(mntmCopy);
                    }
                }
            }
            {
                dataPanel = new JPanel();
                tabbedPane.addTab("Data ", Builder.getImageIcon("table.png"), dataPanel, null);
                dataPanel.setLayout(new MigLayout("", "[grow,fill]", "[grow]"));
                {
                    JSplitPane splitPaneDataTables = new JSplitPane();
                    splitPaneDataTables.setResizeWeight(0.5);
                    splitPaneDataTables.setOneTouchExpandable(true);
                    splitPaneDataTables.setOrientation(JSplitPane.VERTICAL_SPLIT);
                    dataPanel.add(splitPaneDataTables, "cell 0 0,grow");
                    {
                        JPanel panel = new JPanel();
                        splitPaneDataTables.setLeftComponent(panel);
                        panel.setBorder(new TitledBorder(null, "Actual key events", TitledBorder.LEADING,
                                TitledBorder.TOP, null, null));
                        panel.setLayout(new MigLayout("", "[227.00px,grow,fill]", "[68.00px,grow,fill]"));
                        {
                            JScrollPane scrollPane = new JScrollPane();
                            panel.add(scrollPane, "cell 0 0,grow");
                            {
                                tblActual = new JXTable();
                                adapterActualTable = new JTableSpreadsheetByRowAdapter(tblActual);
                                scrollPane.setViewportView(tblActual);
                                tblActual.setSortable(false);
                                JMenuItem mntmCopy = new JMenuItem(actionCopy);
                                JPopupMenu popup = new JPopupMenu();
                                addPopup(tblActual, popup);
                                popup.add(mntmCopy);
                            }
                        }
                    }
                    {
                        JPanel panel = new JPanel();
                        splitPaneDataTables.setRightComponent(panel);
                        panel.setBorder(new TitledBorder(null, "Simulation results", TitledBorder.LEADING,
                                TitledBorder.TOP, null, null));
                        panel.setLayout(new MigLayout("", "[grow,fill]", "[grow,fill]"));
                        {
                            JScrollPane scrollPane = new JScrollPane();
                            panel.add(scrollPane, "cell 0 0,grow");
                            {
                                tblSimulation = new JXTable();
                                adapterSimulationTable = new JTableSpreadsheetByRowAdapter(tblSimulation);
                                scrollPane.setViewportView(tblSimulation);
                                tblSimulation.setSortable(false);
                                JMenuItem mntmCopy = new JMenuItem(actionCopy);
                                JPopupMenu popup = new JPopupMenu();
                                addPopup(tblSimulation, popup);
                                popup.add(mntmCopy);
                            }
                        }
                    }
                    splitPaneDataTables.setDividerLocation(0.5f);
                }
            }
            {
                chartPanel = new JPanel();
                tabbedPane.addTab("Chart ", Builder.getImageIcon("barchart.png"), chartPanel, null);
                chartPanel.setLayout(new MigLayout("", "[][grow]", "[][grow]"));
                {
                    segmentComboBox = new JComboBox();
                    segmentComboBox.addItemListener(new ItemListener() {

                        @Override
                        public void itemStateChanged(ItemEvent arg0) {

                            if (segmentComboBox.getItemCount() > 0) {
                                barChart = new JSEABarChart(
                                        jsea.getChartList().get(segmentComboBox.getSelectedIndex()));
                                barChart.setMaximumDrawHeight(MAX_DRAW_HEIGHT);
                                barChart.setMaximumDrawWidth(MAX_DRAW_WIDTH);
                                chartPanel.removeAll();
                                chartPanel.add(plotSegmentLabel, "cell 0 0,alignx center,aligny center");
                                chartPanel.add(segmentComboBox, "cell 1 0,growx,aligny center");
                                chartPanel.add(barChart, "cell 0 1 2 1,grow");
                                chartPanel.revalidate();
                                chartPanel.repaint();
                            }
                        }
                    });
                    {
                        plotSegmentLabel = new JLabel("Plot Segment: ");
                        chartPanel.add(plotSegmentLabel, "cell 0 0,alignx center,aligny center");
                    }
                    chartPanel.add(segmentComboBox, "cell 1 0,growx,aligny center");
                }
            }
        }
    }

    pack();
    validateForm();
    setAnalysisAvailable(false);
    setExtendedState(this.getExtendedState() | JFrame.MAXIMIZED_BOTH);
}

From source file:edu.ku.brc.specify.tasks.QueryTask.java

@Override
public JPopupMenu getPopupMenu() {
    JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem mi = new JMenuItem(UIRegistry.getResourceString("QY_CONFIGURE_CREATORS"));
    popupMenu.add(mi);

    mi.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            configureCreatorQueries();/* w w  w .  j a  v a2 s .  c  o  m*/
        }
    });

    mi = new JMenuItem(UIRegistry.getResourceString("QY_CONFIGURE_QUERIES"));
    popupMenu.add(mi);

    mi.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            configureFavoriteQueries();
        }
    });

    mi = new JMenuItem(UIRegistry.getResourceString("QY_IMPORT_QUERIES"));
    popupMenu.add(mi);

    mi.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            importQueries();
        }
    });

    mi = new JMenuItem(UIRegistry.getResourceString("QY_EXPORT_QUERIES"));
    popupMenu.add(mi);

    mi.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            exportQueries();
        }
    });

    return popupMenu;
}

From source file:com.intuit.tank.proxy.ProxyApp.java

private JPanel getTransactionTable() {
    JPanel frame = new JPanel(new BorderLayout());
    model = new TransactionTableModel();
    final JTable table = new TransactionTable(model);
    final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
    table.setRowSorter(sorter);//from w  w w. j  a  va2  s . co m
    final JPopupMenu pm = new JPopupMenu();
    JMenuItem item = new JMenuItem("Delete Selected");
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            int[] selectedRows = table.getSelectedRows();
            if (selectedRows.length != 0) {
                int response = JOptionPane.showConfirmDialog(ProxyApp.this,
                        "Are you sure you want to delete " + selectedRows.length + " Transactions?",
                        "Confirm Delete", JOptionPane.YES_NO_OPTION);
                if (response == JOptionPane.YES_OPTION) {
                    int[] correctedRows = new int[selectedRows.length];
                    for (int i = selectedRows.length; --i >= 0;) {
                        int row = selectedRows[i];
                        int index = (Integer) table.getValueAt(row, 0) - 1;
                        correctedRows[i] = index;
                    }
                    Arrays.sort(correctedRows);
                    for (int i = correctedRows.length; --i >= 0;) {
                        int row = correctedRows[i];
                        Transaction transaction = model.getTransactionForIndex(row);
                        if (transaction != null) {
                            model.removeTransaction(transaction, row);
                            isDirty = true;
                            saveAction.setEnabled(isDirty && !stopAction.isEnabled());
                        }
                    }
                }
            }
        }
    });
    pm.add(item);
    table.add(pm);

    table.addMouseListener(new MouseAdapter() {
        boolean pressed = false;

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                Point p = e.getPoint();
                int row = table.rowAtPoint(p);
                int index = (Integer) table.getValueAt(row, 0) - 1;
                Transaction transaction = model.getTransactionForIndex(index);
                if (transaction != null) {
                    detailsTF.setText(transaction.toString());
                    detailsTF.setCaretPosition(0);
                    detailsDialog.setVisible(true);
                }
            }
        }

        /**
         * @{inheritDoc
         */
        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                pressed = true;
                int[] selectedRows = table.getSelectedRows();
                if (selectedRows.length != 0) {
                    pm.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }

        /**
         * @{inheritDoc
         */
        @Override
        public void mouseReleased(MouseEvent e) {
            if (!pressed && e.isPopupTrigger()) {
                int[] selectedRows = table.getSelectedRows();
                if (selectedRows.length != 0) {
                    pm.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }

    });

    JScrollPane pane = new JScrollPane(table);
    frame.add(pane, BorderLayout.CENTER);
    JPanel panel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Filter: ");
    panel.add(label, BorderLayout.WEST);
    final JLabel countLabel = new JLabel(" Count: 0 ");
    panel.add(countLabel, BorderLayout.EAST);
    final JTextField filterText = new JTextField("");
    filterText.addKeyListener(new KeyAdapter() {
        public void keyTyped(KeyEvent e) {
            String text = filterText.getText();
            if (text.length() == 0) {
                sorter.setRowFilter(null);
            } else {
                try {
                    sorter.setRowFilter(RowFilter.regexFilter(text));
                    countLabel.setText(" Count: " + sorter.getViewRowCount() + " ");
                } catch (PatternSyntaxException pse) {
                    System.err.println("Bad regex pattern");
                }
            }
        }
    });
    panel.add(filterText, BorderLayout.CENTER);

    frame.add(panel, BorderLayout.NORTH);
    return frame;
}

From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java

private JPopupMenu getColumnMenu() {
    SortableTreeTableModel model = (SortableTreeTableModel) getTreeTableModel();
    JPopupMenu columnMenu = new JPopupMenu();

    for (int i = 0; i < model.getColumnCount(); i++) {
        final String columnName = model.getColumnName(i);
        // Get the column object by name. Using an index may not return the column object if the column is hidden
        TableColumnExt column = getColumnExt(columnName);

        // Create the menu item
        final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(columnName);
        // Show or hide the checkbox
        menuItem.setSelected(column.isVisible());

        menuItem.addActionListener(new ActionListener() {
            @Override/*from  www . ja va 2s.c  om*/
            public void actionPerformed(ActionEvent arg0) {
                TableColumnExt column = getColumnExt(menuItem.getText());
                // Determine whether to show or hide the selected column
                boolean enable = !column.isVisible();
                // Do not hide a column if it is the last remaining visible column              
                if (enable || getColumnCount() > 1) {
                    column.setVisible(enable);

                    Set<String> customHiddenColumns = customHiddenColumnMap.get(channelId);

                    if (customHiddenColumns != null) {
                        if (enable) {
                            customHiddenColumns.remove(columnName);
                        } else {
                            customHiddenColumns.add(columnName);
                        }
                    }
                }
                saveColumnOrder();
            }
        });

        columnMenu.add(menuItem);
    }

    columnMenu.addSeparator();

    JMenuItem menuItem = new JMenuItem("Collapse All");
    menuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            collapseAll();
        }

    });
    columnMenu.add(menuItem);

    menuItem = new JMenuItem("Expand All");
    menuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            expandAll();
        }

    });
    columnMenu.add(menuItem);

    columnMenu.addSeparator();

    menuItem = new JMenuItem("Restore Default");
    menuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            if (metaDataColumns != null) {
                defaultVisibleColumns.addAll(metaDataColumns);
            }
            restoreDefaultColumnPreferences();
        }

    });
    columnMenu.add(menuItem);

    return columnMenu;
}

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

private void createPopupMenu() {
    JMenuItem menuItem;//w w w  . j  a v a  2s.  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);

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

From source file:base.BasePlayer.AddGenome.java

public void actionPerformed(ActionEvent event) {
    if (event.getSource() == download) {
        if (!downloading) {
            downloading = true;/* www .j  a v  a2s  .  c  o  m*/
            downloadGenome(genometable.getValueAt(genometable.getSelectedRow(), 0).toString());
            downloading = false;
        }
    } else if (event.getSource() == getLinks) {
        URL[] urls = AddGenome.genomeHash
                .get(genometable.getValueAt(genometable.getSelectedRow(), 0).toString());
        JPopupMenu menu = new JPopupMenu();
        JTextArea area = new JTextArea();
        JScrollPane menuscroll = new JScrollPane();
        area.setFont(Main.menuFont);
        menu.add(menuscroll);
        menu.setPreferredSize(new Dimension(
                menu.getFontMetrics(Main.menuFont).stringWidth(urls[0].toString()) + Main.defaultFontSize * 10,
                (int) menu.getFontMetrics(Main.menuFont).getHeight() * 4));
        //area.setMaximumSize(new Dimension(300, 600));
        area.setLineWrap(true);
        area.setWrapStyleWord(true);
        for (int i = 0; i < urls.length; i++) {
            area.append(urls[i].toString() + "\n");
        }

        area.setCaretPosition(0);
        area.revalidate();
        menuscroll.getViewport().add(area);
        menu.pack();
        menu.show(this, 0, 0);

    } else if (event.getSource() == checkEnsembl) {
        if (ensemblfetch) {
            menu.show(AddGenome.treescroll, 0, 0);
        } else {
            EnsemblFetch fetcher = new EnsemblFetch();
            fetcher.execute();
        }
    } else if (event.getSource() == checkUpdates) {
        URL testfile = null;
        try {
            // kattoo onko paivityksia annotaatioon
            String ref = selectedNode.toString();
            if (AddGenome.genomeHash.get(ref) != null) {
                ArrayList<String> testfiles = new ArrayList<String>();
                if (Main.drawCanvas != null) {
                    for (int i = 0; i < Main.genomehash.get(ref).size(); i++) {
                        testfiles.add(Main.genomehash.get(ref).get(i).getName().replace(".bed.gz", ""));
                    }
                }
                testfile = AddGenome.genomeHash.get(ref)[1];
                String result = Main.checkFile(testfile, testfiles);

                if (result.length() == 0) {
                    Main.showError("You have newest annotation file.", "Note");
                } else {
                    int n = JOptionPane.showConfirmDialog(Main.drawCanvas,
                            "New annotation file found: " + result + "\nDownload it now?", "Note",
                            JOptionPane.YES_NO_OPTION);
                    if (n == JOptionPane.YES_OPTION) {
                        URL fileurl = new URL(testfile.getProtocol() + "://" + testfile.getHost()
                                + testfile.getPath().substring(0, testfile.getPath().lastIndexOf("/") + 1)
                                + result);
                        OutputRunner runner = new OutputRunner(fileurl, ref);
                        runner.downloadAnnotation = true;
                        runner.execute();
                    }
                }
            } else {
                Main.showError("This genome is not from Ensembl list, could not check for updates.", "Note",
                        AddGenome.genometable);
            }
        } catch (Exception e) {
            Main.showError("Cannot connect to " + testfile.getHost() + ".\nTry again later.", "Error");
            e.printStackTrace();
        }
    } else if (event.getSource() == remove) {
        if (!selectedNode.isLeaf()) {
            String removeref = selectedNode.toString();
            //   Boolean same = false;
            try {
                if (Main.drawCanvas != null) {
                    if (removeref.equals(Main.refDropdown.getSelectedItem().toString())) {
                        Main.referenceFile.close();
                        //      same = true;
                        if (ChromDraw.exonReader != null) {
                            ChromDraw.exonReader.close();
                        }
                    }
                }
                if (Main.genomehash.containsKey(removeref)) {
                    for (int i = Main.genomehash.get(removeref).size() - 1; i >= 0; i--) {
                        Main.genomehash.get(removeref).remove(i);
                    }
                    Main.genomehash.remove(removeref);

                }
                if (Main.drawCanvas != null) {
                    Main.refModel.removeElement(removeref);
                    Main.refDropdown.removeItem(removeref);
                    Main.refDropdown.revalidate();
                }

                for (int i = 0; i < Main.genome.getItemCount(); i++) {
                    if (Main.genome.getItem(i).getName() != null) {

                        if (Main.genome.getItem(i).getName().equals(removeref)) {
                            Main.genome.remove(Main.genome.getItem(i));
                            break;
                        }
                    }
                }

                FileUtils.deleteDirectory(new File(Main.genomeDir.getCanonicalPath() + "/" + removeref));
                checkGenomes();
                Main.setAnnotationDrop("");

                if (Main.genomehash.size() == 0) {
                    Main.refDropdown.setSelectedIndex(0);
                    Main.setChromDrop("-1");
                }
            } catch (Exception e) {
                e.printStackTrace();
                try {
                    Main.showError("Could not delete genome folder.\nYou can do it manually by deleting folder "
                            + Main.genomeDir.getCanonicalPath() + "/" + removeref, "Note");
                } catch (IOException e1) {

                    e1.printStackTrace();
                }
            }
        } else {
            try {
                if (Main.drawCanvas != null) {
                    if (ChromDraw.exonReader != null) {
                        ChromDraw.exonReader.close();
                    }
                }

                Main.removeAnnotationFile(selectedNode.getParent().toString(), selectedNode.toString());

                FileUtils.deleteDirectory(new File(Main.genomeDir.getCanonicalPath() + "/"
                        + selectedNode.getParent().toString() + "/annotation/" + selectedNode.toString()));

                //   root.remove(selectedNode.getParent().getIndex(selectedNode));
                //   root.remove
                //   checkGenomes();

            } catch (Exception e) {
                e.printStackTrace();
                try {
                    Main.showError("Could not delete genome folder.\nYou can do it manually by deleting folder "
                            + Main.genomeDir.getCanonicalPath() + "/" + selectedNode.getParent().toString()
                            + "/annotation/" + selectedNode.toString(), "Note");
                } catch (IOException e1) {

                    e1.printStackTrace();
                }
            }
            treemodel.removeNodeFromParent(selectedNode);
        }

    } else if (event.getSource() == add) {

        if (genomeFile == null) {
            if (new File(genomeFileText.getText()).exists()) {
                genomeFile = new File(genomeFileText.getText());

            } else {
                genomeFileText.setText("Select reference genome fasta-file.");
                genomeFileText.setForeground(Color.red);
                return;
            }
        }

        /*if(genomeName.getText().contains("Give name") || genomeName.getText().length() == 0) {
           genomeName.setText("Give name of the genome");
           genomeName.setForeground(Color.red);
           genomeName.revalidate();
                   
        }
        else if(!annotation && new File(Main.userDir +"/genomes/"+genomeName.getText().trim().replace("\\s+", "_")).exists()) {
           genomeName.setText("This genome exists already.");
           genomeName.setForeground(Color.red);
           genomeName.revalidate();
        }
        else */

        if ((genomeFileText.getText().length() == 0
                || genomeFileText.getText().startsWith("Select reference"))) {
            genomeFileText.setText("Select reference genome fasta-file.");
            genomeFileText.setForeground(Color.red);
            genomeFileText.revalidate();
        }

        else {

            OutputRunner runner = new OutputRunner(
                    genomeFile.getName().replace(".fasta", "").replace(".gz", ""), genomeFile, annotationFile);
            runner.execute();
        }

    } else if (event.getSource() == openRef) {
        try {

            JFileChooser chooser = new JFileChooser(Main.downloadDir);
            chooser.setMultiSelectionEnabled(false);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            chooser.setAcceptAllFileFilterUsed(false);
            MyFilterFasta fastaFilter = new MyFilterFasta();

            chooser.addChoosableFileFilter(fastaFilter);
            chooser.setDialogTitle("Select reference fasta-file");
            if (Main.screenSize != null) {
                chooser.setPreferredSize(new Dimension((int) Main.screenSize.getWidth() / 3,
                        (int) Main.screenSize.getHeight() / 3));
            }

            int returnVal = chooser.showOpenDialog((Component) this.getParent());

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                genomeFile = chooser.getSelectedFile();
                Main.downloadDir = genomeFile.getParent();
                Main.writeToConfig("DownloadDir=" + genomeFile.getParent());
                genomeFileText.setText(genomeFile.getName());
                genomeFileText.revalidate();
                frame.pack();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (event.getSource() == openAnno) {
        try {

            JFileChooser chooser = new JFileChooser(Main.downloadDir);
            chooser.setMultiSelectionEnabled(false);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            chooser.setAcceptAllFileFilterUsed(false);
            MyFilterGFF gffFilter = new MyFilterGFF();

            chooser.addChoosableFileFilter(gffFilter);
            chooser.setDialogTitle("Select annotation gff3-file");
            if (Main.screenSize != null) {
                chooser.setPreferredSize(new Dimension((int) Main.screenSize.getWidth() / 3,
                        (int) Main.screenSize.getHeight() / 3));
            }
            int returnVal = chooser.showOpenDialog((Component) this.getParent());

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                if (genomeFile == null) {
                    genomeFile = Main.fastahash.get(Main.hoverGenome);
                }
                annotationFile = chooser.getSelectedFile();
                Main.downloadDir = annotationFile.getParent();
                Main.writeToConfig("DownloadDir=" + annotationFile.getParent());

                OutputRunner runner = new OutputRunner(
                        genomeFile.getName().replace(".fasta", "").replace(".gz", ""), genomeFile,
                        annotationFile);
                runner.execute();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

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

private void createPopupMenu() {
    JMenuItem menuItem;/*  w ww  .j a  v  a 2 s  .  c om*/

    // 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);

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

From source file:com.pironet.tda.TDA.java

/**
 * create a instance of this menu for a category
 *//*from   w  w w. j ava  2  s  .  c om*/
private PopupListener getCatPopupMenu() {
    if (catPopupListener == null) {

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

        JMenuItem menuItem = new JMenuItem("Search...");
        menuItem.addActionListener(this);
        popup.add(menuItem);

        //Add listener to the text area so the popup menu can come up.
        catPopupListener = new PopupListener(popup);
    }

    return (catPopupListener);
}

From source file:blue.automation.AutomationManager.java

public JPopupMenu getAutomationMenu(SoundLayer soundLayer) {
    this.selectedSoundLayer = soundLayer;

    // if (menu == null || dirty) {
    JPopupMenu menu = new JPopupMenu();

    // Build Instrument Menu
    JMenu instrRoot = new JMenu("Instrument");

    Arrangement arrangement = data.getArrangement();

    ParameterIdList paramIdList = soundLayer.getAutomationParameters();

    for (int i = 0; i < arrangement.size(); i++) {
        InstrumentAssignment ia = arrangement.getInstrumentAssignment(i);

        if (ia.enabled && ia.instr instanceof Automatable) {

            ParameterList params = ((Automatable) ia.instr).getParameterList();

            if (params.size() <= 0) {
                continue;
            }/*from w w w .ja  va  2 s.  c o  m*/

            JMenu instrMenu = new JMenu();
            instrMenu.setText(ia.arrangementId + ") " + ia.instr.getName());

            for (int j = 0; j < params.size(); j++) {
                Parameter param = params.getParameter(j);
                JMenuItem paramItem = new JMenuItem();
                paramItem.setText(param.getName());
                paramItem.addActionListener(parameterActionListener);

                if (param.isAutomationEnabled()) {
                    if (paramIdList.contains(param.getUniqueId())) {
                        paramItem.setForeground(Color.GREEN);
                    } else {
                        paramItem.setForeground(Color.ORANGE);
                    }

                }

                paramItem.putClientProperty("instr", ia.instr);
                paramItem.putClientProperty("param", param);

                instrMenu.add(paramItem);
            }
            instrRoot.add(instrMenu);
        }
    }

    menu.add(instrRoot);

    // Build Mixer Menu
    Mixer mixer = data.getMixer();

    if (mixer.isEnabled()) {
        JMenu mixerRoot = new JMenu("Mixer");

        // add channels
        ChannelList channels = mixer.getChannels();

        if (channels.size() > 0) {
            JMenu channelsMenu = new JMenu("Channels");

            for (int i = 0; i < channels.size(); i++) {
                channelsMenu.add(buildChannelMenu(channels.getChannel(i), soundLayer));
            }

            mixerRoot.add(channelsMenu);
        }

        // add subchannels
        ChannelList subChannels = mixer.getSubChannels();

        if (subChannels.size() > 0) {
            JMenu subChannelsMenu = new JMenu("Sub-Channels");
            for (int i = 0; i < subChannels.size(); i++) {
                subChannelsMenu.add(buildChannelMenu(subChannels.getChannel(i), soundLayer));
            }

            mixerRoot.add(subChannelsMenu);
        }

        // add master channel
        Channel master = mixer.getMaster();

        mixerRoot.add(buildChannelMenu(master, soundLayer));

        menu.add(mixerRoot);
    }

    menu.addSeparator();

    JMenuItem clearAll = new JMenuItem("Clear All");
    clearAll.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Object retVal = DialogDisplayer.getDefault().notify(new NotifyDescriptor.Confirmation(
                    "Please Confirm Clearing All Parameter Data for this SoundLayer"));

            if (retVal == NotifyDescriptor.YES_OPTION) {

                ParameterIdList idList = selectedSoundLayer.getAutomationParameters();

                Iterator iter = new ArrayList(idList.getParameters()).iterator();

                while (iter.hasNext()) {
                    String paramId = (String) iter.next();
                    Parameter param = getParameter(paramId);

                    param.setAutomationEnabled(false);
                    idList.removeParameterId(paramId);
                }
            }
        }
    });
    menu.add(clearAll);

    clearAll.setEnabled(soundLayer.getAutomationParameters().size() > 0);

    // }

    // System.err.println(parameterMap);

    return menu;
}

From source file:com.pironet.tda.TDA.java

/**
 * create a instance of this menu for a category
 *///w ww .j a va  2 s.c o  m
private PopupListener getMonitorsPopupMenu() {
    if (monitorsPopupListener == null) {
        final JPopupMenu popup = new JPopupMenu();
        JMenuItem menuItem = new JMenuItem("Search...");
        menuItem.addActionListener(this);
        popup.add(menuItem);
        popup.addSeparator();
        menuItem = new JMenuItem("Expand all nodes");
        menuItem.addActionListener(this);
        popup.add(menuItem);
        menuItem = new JMenuItem("Collapse all nodes");
        menuItem.addActionListener(this);
        popup.add(menuItem);
        popup.addSeparator();
        menuItem = new JMenuItem("Sort by thread count");
        menuItem.addActionListener(this);
        popup.add(menuItem);

        //Add listener to the text area so the popup menu can come up.
        monitorsPopupListener = new PopupListener(popup);
    }

    return (monitorsPopupListener);
}