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:org.ut.biolab.medsavant.client.view.UpdatesPanel.java

private void showPopup(final int start) {
    popup = new JPopupMenu();
    popup.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));

    if (notifications == null) {
        popup.add(new NotificationIcon(null, null));
    } else {// w  ww. j  a v a2  s.  co  m

        //add notifications
        for (int i = start; i < Math.min(start + 5, notifications.length); i++) {
            popup.add(new NotificationIcon(notifications[i], popup));
            if (i != Math.min(start + 5, notifications.length) - 1) {
                popup.add(createSeparator());
            }
        }

        //add page header
        if (notifications.length > 5) {
            JPanel header = new JPanel();
            header.setMinimumSize(new Dimension(1, 15));
            header.setLayout(new BoxLayout(header, BoxLayout.X_AXIS));
            if (start >= 5) {
                JLabel prevButton = ViewUtil.createLabelButton("  Prev Page  ");
                prevButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        showPopup(start - 5);
                    }
                });
                header.add(prevButton);
            }
            header.add(Box.createHorizontalGlue());
            if (start + 5 < notifications.length) {
                JLabel nextButton = ViewUtil.createLabelButton("  Next Page  ");
                nextButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        showPopup(start + 5);
                    }
                });
                header.add(nextButton);
            }
            popup.add(createSeparator());
            popup.add(header);
        }
    }

    //int offset = -Math.min(5, notifications.length - start) * (MENU_ICON_SIZE.height + 2) -3 - (headerAdded ? 16 : 0);        
    popup.show(this, 0, this.getPreferredSize().height);
}

From source file:org.yccheok.jstock.gui.IndicatorPanel.java

private JPopupMenu getJListPopupMenu() {
    final JPopupMenu popup = new JPopupMenu();
    javax.swing.JMenuItem menuItem = new JMenuItem(GUIBundle.getString("New..."),
            this.getImageIcon("/images/16x16/filenew.png"));
    menuItem.addActionListener(new ActionListener() {
        @Override/*from   w w  w  .  ja  v  a2s.c  o m*/
        public void actionPerformed(ActionEvent evt) {
            New();
        }
    });
    popup.add(menuItem);
    menuItem = new JMenuItem(GUIBundle.getString("Save"), this.getImageIcon("/images/16x16/filesave.png"));
    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            Save(true);
        }
    });
    popup.add(menuItem);
    popup.addSeparator();

    menuItem = new JMenuItem(GUIBundle.getString("Install..."),
            this.getImageIcon("/images/16x16/download.png"));
    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            Install();
        }
    });
    popup.add(menuItem);

    if (isIndicatorDatabaseVisibleAndSelected() || isModuleDatabaseVisibleAndSelected()) {
        menuItem = new JMenuItem(GUIBundle.getString("Export..."),
                this.getImageIcon("/images/16x16/upload.png"));
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                Export();
            }
        });
        popup.add(menuItem);
        popup.addSeparator();
        menuItem = new JMenuItem(GUIBundle.getString("Rename..."), this.getImageIcon("/images/16x16/edit.png"));
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                Rename();
            }
        });
        popup.add(menuItem);
        menuItem = new JMenuItem(GUIBundle.getString("Delete"),
                this.getImageIcon("/images/16x16/editdelete.png"));
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                Delete(true);
            }
        });
        popup.add(menuItem);
    }
    return popup;
}

From source file:org.yccheok.jstock.gui.IndicatorScannerJPanel.java

private JPopupMenu getMyJTablePopupMenu() {
    JPopupMenu popup = new JPopupMenu();

    final JStock m = JStock.instance();

    javax.swing.JMenuItem menuItem = new JMenuItem(java.util.ResourceBundle
            .getBundle("org/yccheok/jstock/data/gui").getString("IndicatorScannerJPanel_History..."),
            this.getImageIcon("/images/16x16/strokedocker.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override/*  www .  j ava 2s  . c om*/
        public void actionPerformed(ActionEvent evt) {
            int rows[] = jTable1.getSelectedRows();
            final IndicatorTableModel tableModel = (IndicatorTableModel) jTable1.getModel();

            for (int row : rows) {
                final int modelIndex = jTable1.convertRowIndexToModel(row);
                final Indicator indicator = tableModel.getIndicator(modelIndex);
                if (indicator != null) {
                    m.displayHistoryChart(indicator.getStock());
                }
            }
        }
    });

    popup.add(menuItem);

    menuItem = new JMenuItem(java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/gui")
            .getString("IndicatorScannerJPanel_News..."), this.getImageIcon("/images/16x16/news.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            int rows[] = jTable1.getSelectedRows();
            final IndicatorTableModel tableModel = (IndicatorTableModel) jTable1.getModel();

            for (int row : rows) {
                final int modelIndex = jTable1.convertRowIndexToModel(row);
                final Indicator indicator = tableModel.getIndicator(modelIndex);
                if (indicator != null) {
                    m.displayStockNews(indicator.getStock());
                }
            }
        }
    });

    popup.add(menuItem);

    popup.addSeparator();

    menuItem = new JMenuItem(GUIBundle.getString("IndicatorScannerJPanel_AddToRealTimeInfo"),
            this.getImageIcon("/images/16x16/add.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            int rows[] = jTable1.getSelectedRows();
            final IndicatorTableModel tableModel = (IndicatorTableModel) jTable1.getModel();

            for (int row : rows) {
                final int modelIndex = jTable1.convertRowIndexToModel(row);
                final Indicator indicator = tableModel.getIndicator(modelIndex);
                if (indicator != null) {
                    m.addStockToTable(indicator.getStock());
                }
            }
        }
    });

    popup.add(menuItem);

    if (jTable1.getSelectedRowCount() == 1) {
        popup.addSeparator();

        menuItem = new JMenuItem(GUIBundle.getString("IndicatorScannerJPanel_Buy..."),
                this.getImageIcon("/images/16x16/inbox.png"));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                final int row = jTable1.getSelectedRow();
                final int modelIndex = jTable1.getRowSorter().convertRowIndexToModel(row);
                final IndicatorTableModel tableModel = (IndicatorTableModel) jTable1.getModel();
                final Indicator indicator = tableModel.getIndicator(modelIndex);
                final Stock stock = indicator.getStock();
                JStock.instance().getPortfolioManagementJPanel().showNewBuyTransactionJDialog(stock,
                        stock.getLastPrice(), false);
            }
        });

        popup.add(menuItem);
    }

    return popup;
}

From source file:org.yccheok.jstock.gui.JStock.java

private JPopupMenu getMyJTablePopupMenu() {
    final JPopupMenu popup = new JPopupMenu();
    final TableModel tableModel = jTable1.getModel();

    javax.swing.JMenuItem menuItem = new JMenuItem(
            java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/gui").getString("MainFrame_History..."),
            this.getImageIcon("/images/16x16/strokedocker.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override// w  w  w . j a va2  s.  co  m
        public void actionPerformed(ActionEvent evt) {
            displayHistoryCharts();
        }
    });

    popup.add(menuItem);

    menuItem = new JMenuItem(
            java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/gui").getString("MainFrame_News..."),
            this.getImageIcon("/images/16x16/news.png"));
    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            displayStocksNews();
        }
    });
    popup.add(menuItem);

    popup.addSeparator();

    if (jTable1.getSelectedRowCount() == 1) {
        menuItem = new JMenuItem(
                java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/gui").getString("MainFrame_Buy..."),
                this.getImageIcon("/images/16x16/inbox.png"));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                final int row = jTable1.getSelectedRow();
                final int modelIndex = jTable1.getRowSorter().convertRowIndexToModel(row);
                final Stock stock = ((StockTableModel) tableModel).getStock(modelIndex);

                // We have a real nasty bug here. We retrieve stock information through stock code.
                // When we receive stock information, we update all its particular information, including stock
                // symbol. Here is the catch, the latest updated stock symbol (stock.getSymbol), may not be the
                // same as stock symbol found in stock database. If we pass the stock symbol which is not found
                // in stock database to portfolio, something can go wrong. This is because portfolio rely heavily
                // on symbol <-> code conversion. Hence, instead of using stock.getSymbol, we prefer to get the
                // symbol out from stock database. This marks the close of the following reported bugs :
                //
                // [2800598] buyportfolio.xml file not updated with code symbol
                // [2790218] User unable to add new buy transaction in Spain
                //
                // Say no to : portfolioManagementJPanel.showNewBuyTransactionJDialog(stock.symbol, stock.getLastPrice(), false);
                portfolioManagementJPanel.showNewBuyTransactionJDialog(stock, stock.getLastPrice(), false);
            }
        });

        popup.add(menuItem);

        popup.addSeparator();
    }

    menuItem = new JMenuItem(
            java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/gui").getString("MainFrame_Delete"),
            this.getImageIcon("/images/16x16/editdelete.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            JStock.this.deteleSelectedTableRow();
        }
    });

    popup.add(menuItem);

    return popup;
}

From source file:org.yccheok.jstock.gui.MainFrame.java

private JPopupMenu getMyJTablePopupMenu() {
    final JPopupMenu popup = new JPopupMenu();
    final TableModel tableModel = jTable1.getModel();

    javax.swing.JMenuItem menuItem = new JMenuItem(
            java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/gui").getString("MainFrame_History..."),
            this.getImageIcon("/images/16x16/strokedocker.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override//from   w w  w  . java 2s.  c  o m
        public void actionPerformed(ActionEvent evt) {
            int rows[] = jTable1.getSelectedRows();
            final StockTableModel tableModel = (StockTableModel) jTable1.getModel();

            for (int row : rows) {
                final int modelIndex = jTable1.getRowSorter().convertRowIndexToModel(row);
                Stock stock = tableModel.getStock(modelIndex);
                displayHistoryChart(stock);
            }
        }
    });

    popup.add(menuItem);

    popup.addSeparator();

    if (jTable1.getSelectedRowCount() == 1) {
        menuItem = new JMenuItem(
                java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/gui").getString("MainFrame_Buy..."),
                this.getImageIcon("/images/16x16/inbox.png"));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                final int row = jTable1.getSelectedRow();
                final int modelIndex = jTable1.getRowSorter().convertRowIndexToModel(row);
                final Stock stock = ((StockTableModel) tableModel).getStock(modelIndex);

                // We have a real nasty bug here. We retrieve stock information through stock code.
                // When we receive stock information, we update all its particular information, including stock
                // symbol. Here is the catch, the latest updated stock symbol (stock.getSymbol), may not be the
                // same as stock symbol found in stock database. If we pass the stock symbol which is not found
                // in stock database to portfolio, something can go wrong. This is because portfolio rely heavily
                // on symbol <-> code conversion. Hence, instead of using stock.getSymbol, we prefer to get the
                // symbol out from stock database. This marks the close of the following reported bugs :
                //
                // [2800598] buyportfolio.xml file not updated with code symbol
                // [2790218] User unable to add new buy transaction in Spain
                //
                // Say no to : portfolioManagementJPanel.showNewBuyTransactionJDialog(stock.symbol, stock.getLastPrice(), false);
                portfolioManagementJPanel.showNewBuyTransactionJDialog(stock, stock.getLastPrice(), false);
            }
        });

        popup.add(menuItem);

        popup.addSeparator();
    }

    menuItem = new JMenuItem(
            java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/gui").getString("MainFrame_Delete"),
            this.getImageIcon("/images/16x16/editdelete.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            MainFrame.this.deteleSelectedTableRow();
        }
    });

    popup.add(menuItem);

    return popup;
}

From source file:org.yccheok.jstock.gui.portfolio.DividendSummaryJDialog.java

private JPopupMenu getMyJTablePopupMenu() {
    final JPopupMenu popup = new JPopupMenu();

    javax.swing.JMenuItem menuItem = new JMenuItem(
            java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/gui").getString("DividendSummary_New"),
            new javax.swing.ImageIcon(getClass().getResource("/images/16x16/filenew.png")));

    menuItem.addActionListener(new ActionListener() {
        @Override//from  ww w. ja va  2  s  . c o m
        public void actionPerformed(ActionEvent e) {
            addNewDividend();
        }
    });

    popup.add(menuItem);

    final Commentable commentable = getSelectedCommentable();
    final String text = this.getSelectedSecondColumnString();
    if (commentable != null && text != null) {
        popup.addSeparator();

        menuItem = new JMenuItem(
                java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/gui")
                        .getString("DividendSummary_Note..."),
                new javax.swing.ImageIcon(getClass().getResource("/images/16x16/sticky.png")));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                showCommentJDialog(commentable, MessageFormat
                        .format(GUIBundle.getString("DividendSummaryJDialog_NoteFor_template"), text));
            }
        });

        popup.add(menuItem);
    }

    if (jTable1.getSelectedRowCount() >= 1) {
        popup.addSeparator();

        menuItem = new JMenuItem(
                java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/gui")
                        .getString("DividendSummaryJDialog_Delete"),
                new javax.swing.ImageIcon(getClass().getResource("/images/16x16/editdelete.png")));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                deleteSelectedDividend();
                jLabel2.setText(getDividendSummaryText());
            }
        });

        popup.add(menuItem);
    }

    return popup;
}

From source file:org.yccheok.jstock.gui.PortfolioManagementJPanel.java

private JPopupMenu getSellTreeTablePopupMenu() {
    final List<Transaction> transactions = getSelectedTransactions(this.sellTreeTable);

    JPopupMenu popup = new JPopupMenu();

    JMenuItem menuItem = null;/*from   ww w .  j  a v a  2 s. c  o m*/

    menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagementJPanel_Cash..."),
            this.getImageIcon("/images/16x16/money.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            showDepositSummaryJDialog();
        }
    });

    popup.add(menuItem);

    menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_Dividend..."),
            this.getImageIcon("/images/16x16/money2.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            showDividendSummaryJDialog();
        }
    });

    popup.add(menuItem);

    popup.addSeparator();

    if (transactions.size() == 1) {
        menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_Edit..."),
                this.getImageIcon("/images/16x16/edit.png"));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                PortfolioManagementJPanel.this.showEditTransactionJDialog(transactions.get(0));
            }
        });

        popup.add(menuItem);
    }

    final Commentable commentable = getSelectedCommentable(this.sellTreeTable);
    final String tmp = getSelectedFirstColumnString(this.sellTreeTable);
    if (commentable != null && tmp != null) {
        menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_Note..."),
                this.getImageIcon("/images/16x16/sticky.png"));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                final String template = GUIBundle.getString("PortfolioManagementJPanel_NoteFor_template");
                final String title = MessageFormat.format(template, tmp);
                PortfolioManagementJPanel.this.showCommentJDialog(commentable, title);
            }
        });

        popup.add(menuItem);

        popup.addSeparator();
    } else if (transactions.size() == 1) {
        popup.addSeparator();
    }

    menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_InvestmentChart..."),
            this.getImageIcon("/images/16x16/graph.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            showChashFlowChartJDialog();
        }
    });

    popup.add(menuItem);

    menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagementJPanel_DividendChart"),
            this.getImageIcon("/images/16x16/chart.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            PortfolioManagementJPanel.this.showDividendSummaryBarChartJDialog();
        }
    });

    popup.add(menuItem);

    menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_Summary..."),
            this.getImageIcon("/images/16x16/pie_chart.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            PortfolioManagementJPanel.this.showSellPortfolioChartJDialog();
        }
    });

    popup.add(menuItem);

    if (isOnlyTreeTableRootBeingSelected(sellTreeTable) == false && (sellTreeTable.getSelectedRow() > 0)) {
        final JStock m = JStock.instance();

        menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_History..."),
                this.getImageIcon("/images/16x16/strokedocker.png"));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                List<Stock> stocks = getSelectedStocks(sellTreeTable);

                for (Stock stock : stocks) {
                    m.displayHistoryChart(stock);
                }
            }
        });

        popup.addSeparator();

        popup.add(menuItem);

        menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_News..."),
                this.getImageIcon("/images/16x16/news.png"));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                List<Stock> stocks = getSelectedStocks(sellTreeTable);

                for (Stock stock : stocks) {
                    m.displayStockNews(stock);
                }
            }
        });

        popup.add(menuItem);

        popup.addSeparator();

        menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_Delete"),
                this.getImageIcon("/images/16x16/editdelete.png"));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                PortfolioManagementJPanel.this.deteleSelectedTreeTableRow();
            }
        });

        popup.add(menuItem);
    }

    return popup;
}

From source file:org.yccheok.jstock.gui.PortfolioManagementJPanel.java

private JPopupMenu getBuyTreeTablePopupMenu() {
    JPopupMenu popup = new JPopupMenu();

    JMenuItem menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_Buy..."),
            this.getImageIcon("/images/16x16/inbox.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override//from  w  w  w .  j  av  a  2s . c  om
        public void actionPerformed(ActionEvent evt) {
            List<Stock> stocks = getSelectedStocks();
            if (stocks.size() == 1) {
                PortfolioManagementJPanel.this.showNewBuyTransactionJDialog(stocks.get(0),
                        PortfolioManagementJPanel.this.getStockPrice(stocks.get(0).code), true);
            } else {
                PortfolioManagementJPanel.this.showNewBuyTransactionJDialog(org.yccheok.jstock.engine.Utils
                        .getEmptyStock(Code.newInstance(""), Symbol.newInstance("")), 0.0, true);
            }
        }
    });

    popup.add(menuItem);

    final List<Transaction> transactions = getSelectedTransactions(this.buyTreeTable);
    final List<Stock> stocks = this.getSelectedStocks(this.buyTreeTable);

    if (transactions.size() > 0 && stocks.size() == 1) {
        menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_Sell..."),
                this.getImageIcon("/images/16x16/outbox.png"));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                PortfolioManagementJPanel.this.showNewSellTransactionJDialog(transactions);
            }
        });

        popup.add(menuItem);
    }

    popup.addSeparator();

    menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagementJPanel_Cash..."),
            this.getImageIcon("/images/16x16/money.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            showDepositSummaryJDialog();
        }
    });

    popup.add(menuItem);

    menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_Dividend..."),
            this.getImageIcon("/images/16x16/money2.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            showDividendSummaryJDialog();
        }
    });

    popup.add(menuItem);

    popup.addSeparator();

    boolean needToAddSeperator = false;

    if (transactions.size() == 1) {
        menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_Edit..."),
                this.getImageIcon("/images/16x16/edit.png"));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                PortfolioManagementJPanel.this.showEditTransactionJDialog(transactions.get(0));
            }
        });

        popup.add(menuItem);
        needToAddSeperator = true;
    }

    final Commentable commentable = getSelectedCommentable(this.buyTreeTable);
    final String tmp = getSelectedFirstColumnString(this.buyTreeTable);
    if (commentable != null && tmp != null) {
        menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_Note..."),
                this.getImageIcon("/images/16x16/sticky.png"));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                final String template = GUIBundle.getString("PortfolioManagementJPanel_NoteFor_template");
                final String title = MessageFormat.format(template, tmp);
                PortfolioManagementJPanel.this.showCommentJDialog(commentable, title);
            }
        });

        popup.add(menuItem);
        needToAddSeperator = true;
    }

    // Split or merge only allowed, if there is one and only one stock
    // being selected.
    final List<Stock> selectedStocks = this.getSelectedStocks();
    if (selectedStocks.size() == 1) {
        menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagementJPanel_SplitOrMerge"),
                this.getImageIcon("/images/16x16/merge.png"));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                PortfolioManagementJPanel.this
                        .showSplitOrMergeJDialog(StockInfo.newInstance(selectedStocks.get(0)));
            }
        });

        popup.add(menuItem);
        needToAddSeperator = true;
    }

    if (needToAddSeperator) {
        popup.addSeparator();
    }

    menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_InvestmentChart..."),
            this.getImageIcon("/images/16x16/graph.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            showChashFlowChartJDialog();
        }
    });

    popup.add(menuItem);

    menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagementJPanel_DividendChart"),
            this.getImageIcon("/images/16x16/chart.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            PortfolioManagementJPanel.this.showDividendSummaryBarChartJDialog();
        }
    });

    popup.add(menuItem);

    menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_Summary..."),
            this.getImageIcon("/images/16x16/pie_chart.png"));

    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            PortfolioManagementJPanel.this.showBuyPortfolioChartJDialog();
        }
    });

    popup.add(menuItem);

    if (isOnlyTreeTableRootBeingSelected(buyTreeTable) == false && (buyTreeTable.getSelectedRow() > 0)) {
        final JStock m = JStock.instance();

        menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_History..."),
                this.getImageIcon("/images/16x16/strokedocker.png"));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                List<Stock> stocks = getSelectedStocks(buyTreeTable);

                for (Stock stock : stocks) {
                    m.displayHistoryChart(stock);
                }
            }
        });

        popup.addSeparator();

        popup.add(menuItem);

        menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_News..."),
                this.getImageIcon("/images/16x16/news.png"));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                List<Stock> stocks = getSelectedStocks(buyTreeTable);

                for (Stock stock : stocks) {
                    m.displayStockNews(stock);
                }
            }
        });

        popup.add(menuItem);

        popup.addSeparator();

        menuItem = new JMenuItem(GUIBundle.getString("PortfolioManagement_Delete"),
                this.getImageIcon("/images/16x16/editdelete.png"));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                PortfolioManagementJPanel.this.deteleSelectedTreeTableRow();
            }
        });

        popup.add(menuItem);
    }

    return popup;
}

From source file:org.yccheok.jstock.gui.StockDatabaseJDialog.java

private JPopupMenu getMyJTablePopupMenu(boolean newMenuItemOnly) {
    final JPopupMenu popup = new JPopupMenu();

    javax.swing.JMenuItem menuItem = new JMenuItem("New",
            new javax.swing.ImageIcon(getClass().getResource("/images/16x16/filenew.png")));

    menuItem.addActionListener(new ActionListener() {
        @Override/*w w  w .j  av  a 2  s  . co  m*/
        public void actionPerformed(ActionEvent e) {
            addNewStockInfo();
        }
    });

    popup.add(menuItem);

    if (newMenuItemOnly) {
        /* Single menu item only. */
        return popup;
    }

    if (jTable2.getSelectedRowCount() >= 1) {
        popup.addSeparator();

        menuItem = new JMenuItem("Delete",
                new javax.swing.ImageIcon(getClass().getResource("/images/16x16/editdelete.png")));

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                deleteSelectedUserDefinedDatabase();
            }
        });

        popup.add(menuItem);
    }

    return popup;
}

From source file:org.zaproxy.zap.extension.jsonview.HttpPanelJsonView.java

public HttpPanelJsonView(AbstractStringHttpPanelViewModel model) {
    httpPanelJsonArea = new HttpPanelJsonArea();
    RTextScrollPane scrollPane = new RTextScrollPane(httpPanelJsonArea);
    scrollPane.setLineNumbersEnabled(false);
    mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(scrollPane, BorderLayout.CENTER);
    this.model = model;
    model.addHttpPanelViewModelListener(this);

    httpPanelJsonArea.setComponentPopupMenu(new JPopupMenu() {

        private static final long serialVersionUID = 1L;

        @Override//from   w w w .j a v  a 2  s.  c  o  m
        public void show(Component invoker, int x, int y) {
            if (!httpPanelJsonArea.isFocusOwner()) {
                httpPanelJsonArea.requestFocusInWindow();
            }
            View.getSingleton().getPopupMenu().show(httpPanelJsonArea, x, y);
        };
    });
}