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.tinymediamanager.ui.movies.MoviePanel.java

private void buildMenu() {
    menu.setMnemonic(KeyEvent.VK_M);

    // menu items
    JMenuItem menuItem = menu.add(actionUpdateDataSources2);
    menuItem.setMnemonic(KeyEvent.VK_U);
    menuItem.setAccelerator(//from ww w  . j a  v  a2  s.  c o m
            KeyStroke.getKeyStroke(KeyEvent.VK_U, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    final JMenu menuUpdateDatasources = new JMenu(BUNDLE.getString("update.datasource")); //$NON-NLS-1$
    final JMenu menuFindMissingMovies = new JMenu(BUNDLE.getString("movie.findmissing")); //$NON-NLS-1$
    menuUpdateDatasources.addMenuListener(new MenuListener() {
        @Override
        public void menuCanceled(MenuEvent arg0) {
        }

        @Override
        public void menuDeselected(MenuEvent arg0) {
        }

        @Override
        public void menuSelected(MenuEvent arg0) {
            menuUpdateDatasources.removeAll();
            menuFindMissingMovies.removeAll();
            for (String ds : MovieModuleManager.MOVIE_SETTINGS.getMovieDataSource()) {
                JMenuItem item = new JMenuItem(new MovieUpdateSingleDatasourceAction(ds));
                menuUpdateDatasources.add(item);

                item = new JMenuItem(new MovieFindMissingAction(ds));
                menuFindMissingMovies.add(item);

            }
        }
    });
    menu.add(menuUpdateDatasources);

    menu.add(new MovieFindMissingAction());
    menu.add(menuFindMissingMovies);
    menu.add(new MovieCreateOfflineAction(true));

    menu.addSeparator();

    JMenu menuScrape = new JMenu(BUNDLE.getString("Button.scrape")); //$NON-NLS-1$
    menuScrape.setMnemonic(KeyEvent.VK_S);
    menuItem = menuScrape.add(actionScrape2);
    menuItem.setMnemonic(KeyEvent.VK_S);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menuItem = menuScrape.add(actionScrapeSelected);
    menuItem.setMnemonic(KeyEvent.VK_F);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menuItem = menuScrape.add(actionScrapeUnscraped);
    menuItem.setMnemonic(KeyEvent.VK_U);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_U, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menuItem = menuScrape.add(actionScrapeMetadataSelected);
    menuItem.setMnemonic(KeyEvent.VK_M);
    menuScrape.add(actionAssignMovieSets);
    menu.add(menuScrape);

    JMenu menuEdit = new JMenu(BUNDLE.getString("Button.edit")); //$NON-NLS-1$
    menuEdit.setMnemonic(KeyEvent.VK_E);
    menuItem = menuEdit.add(actionEditMovie2);
    menuItem.setMnemonic(KeyEvent.VK_E);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menuItem = menuEdit.add(actionBatchEdit);
    menuItem.setMnemonic(KeyEvent.VK_B);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menuItem = menuEdit.add(actionSetWatchedFlag);
    menuItem.setMnemonic(KeyEvent.VK_W);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menuItem = menuEdit.add(actionRename2);
    menuItem.setMnemonic(KeyEvent.VK_R);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menuItem = menuEdit.add(actionRenamerPreview);
    menuItem.setMnemonic(KeyEvent.VK_P);
    menu.add(menuEdit);

    menuItem = menu.add(actionRewriteNfo);
    menuItem.setMnemonic(KeyEvent.VK_N);
    menuItem = menu.add(actionTrailerDownload);
    menuItem = menu.add(actionSearchSubtitle);
    menuItem = menu.add(actionDownloadSubtitle);

    menu.addSeparator();
    menuItem = menu.add(actionMediaInformation2);
    menuItem.setMnemonic(KeyEvent.VK_M);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menuItem = menu.add(actionExport);
    menuItem.setMnemonic(KeyEvent.VK_X);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menuItem = menu.add(actionRemove2);
    menuItem.setMnemonic(KeyEvent.VK_R);
    menuItem.setAccelerator(KeyStroke.getKeyStroke((char) KeyEvent.VK_DELETE));
    menuItem = menu.add(actionDelete2);
    menuItem.setMnemonic(KeyEvent.VK_R);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, ActionEvent.SHIFT_MASK));
    menu.addSeparator();
    menuItem = menu.add(actionSyncTrakt);
    menuItem.setMnemonic(KeyEvent.VK_T);
    menuItem = menu.add(actionSyncWatchedTrakt);
    menuItem.setMnemonic(KeyEvent.VK_W);
    menuItem = menu.add(actionSyncSelectedTrakt);

    menu.addSeparator();
    menuItem = menu.add(actionClearImageCache);
    menuItem.setMnemonic(KeyEvent.VK_C);

    // popup menu
    JPopupMenu popupMenu = new JPopupMenu();
    popupMenu.add(actionScrape2);
    popupMenu.add(actionScrapeSelected);
    popupMenu.add(actionScrapeUnscraped);
    popupMenu.add(actionScrapeMetadataSelected);
    popupMenu.add(actionAssignMovieSets);
    popupMenu.addSeparator();
    popupMenu.add(actionEditMovie2);
    popupMenu.add(actionBatchEdit);
    popupMenu.add(actionSetWatchedFlag);
    popupMenu.add(actionRewriteNfo);
    popupMenu.add(actionRename2);
    popupMenu.add(actionRenamerPreview);
    popupMenu.add(actionMediaInformation2);
    popupMenu.add(actionExport);
    popupMenu.add(actionTrailerDownload);
    popupMenu.add(actionSearchSubtitle);
    popupMenu.add(actionDownloadSubtitle);
    popupMenu.addSeparator();
    popupMenu.add(actionSyncTrakt);
    popupMenu.add(actionSyncWatchedTrakt);
    popupMenu.add(actionSyncSelectedTrakt);
    popupMenu.addSeparator();
    popupMenu.add(actionClearImageCache);
    popupMenu.addSeparator();
    popupMenu.add(actionRemove2);
    popupMenu.add(actionDelete2);

    if (Globals.isDebug()) {
        JMenu menuDebug = new JMenu("Debug"); //$NON-NLS-1$
        menuDebug.add(debugDumpMovie);
        menuDebug.addSeparator();
        menuDebug.add(new FakeTmmTaskAction("download", 1, 10));
        menuDebug.add(new FakeTmmTaskAction("download", 10, 10));
        menuDebug.add(new FakeTmmTaskAction("image", 1, 10));
        menuDebug.add(new FakeTmmTaskAction("image", 10, 10));
        menuDebug.add(new FakeTmmTaskAction("unnamed", 1, 10));
        menuDebug.add(new FakeTmmTaskAction("unnamed", 10, 10));
        popupMenu.add(menuDebug);
    }

    MouseListener mouseListener = new MovieTableMouseListener(popupMenu, table);
    table.addMouseListener(mouseListener);
}

From source file:org.tinymediamanager.ui.tvshows.TvShowPanel.java

/**
 * Instantiates a new tv show panel./*from w w w .  j  a v a2 s  .  c  o  m*/
 */
public TvShowPanel() {
    super();

    treeModel = new TvShowTreeModel(tvShowList.getTvShows());
    tvShowSeasonSelectionModel = new TvShowSeasonSelectionModel();
    tvShowEpisodeSelectionModel = new TvShowEpisodeSelectionModel();

    // build menu
    menu = new JMenu(BUNDLE.getString("tmm.tvshows")); //$NON-NLS-1$
    JFrame mainFrame = MainWindow.getFrame();
    JMenuBar menuBar = mainFrame.getJMenuBar();
    menuBar.add(menu);

    setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("850px:grow"),
                    FormFactory.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"), }));

    JSplitPane splitPane = new JSplitPane();
    splitPane.setContinuousLayout(true);
    add(splitPane, "2, 2, fill, fill");

    JPanel panelTvShowTree = new JPanel();
    splitPane.setLeftComponent(panelTvShowTree);
    panelTvShowTree.setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                    FormFactory.UNRELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, },
            new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                    RowSpec.decode("3px:grow"), FormFactory.RELATED_GAP_ROWSPEC,
                    FormFactory.DEFAULT_ROWSPEC, }));

    textField = EnhancedTextField.createSearchTextField();
    panelTvShowTree.add(textField, "4, 1, right, bottom");
    textField.setColumns(12);
    textField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void insertUpdate(final DocumentEvent e) {
            applyFilter();
        }

        @Override
        public void removeUpdate(final DocumentEvent e) {
            applyFilter();
        }

        @Override
        public void changedUpdate(final DocumentEvent e) {
            applyFilter();
        }

        public void applyFilter() {
            TvShowTreeModel filteredModel = (TvShowTreeModel) tree.getModel();
            if (StringUtils.isNotBlank(textField.getText())) {
                filteredModel.setFilter(SearchOptions.TEXT, textField.getText());
            } else {
                filteredModel.removeFilter(SearchOptions.TEXT);
            }

            filteredModel.filter(tree);
        }
    });

    final JToggleButton btnFilter = new JToggleButton(IconManager.FILTER);
    btnFilter.setToolTipText(BUNDLE.getString("movieextendedsearch.options")); //$NON-NLS-1$
    panelTvShowTree.add(btnFilter, "6, 1, default, bottom");

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    panelTvShowTree.add(scrollPane, "2, 3, 5, 1, fill, fill");

    JToolBar toolBar = new JToolBar();
    toolBar.setRollover(true);
    toolBar.setFloatable(false);
    toolBar.setOpaque(false);
    panelTvShowTree.add(toolBar, "2, 1");

    // toolBar.add(actionUpdateDatasources);
    final JSplitButton buttonUpdateDatasource = new JSplitButton(IconManager.REFRESH);
    // temp fix for size of the button
    buttonUpdateDatasource.setText("   ");
    buttonUpdateDatasource.setHorizontalAlignment(JButton.LEFT);
    // buttonScrape.setMargin(new Insets(2, 2, 2, 24));
    buttonUpdateDatasource.setSplitWidth(18);
    buttonUpdateDatasource.setToolTipText(BUNDLE.getString("update.datasource")); //$NON-NLS-1$
    buttonUpdateDatasource.addSplitButtonActionListener(new SplitButtonActionListener() {
        public void buttonClicked(ActionEvent e) {
            actionUpdateDatasources.actionPerformed(e);
        }

        public void splitButtonClicked(ActionEvent e) {
            // build the popupmenu on the fly
            buttonUpdateDatasource.getPopupMenu().removeAll();
            buttonUpdateDatasource.getPopupMenu().add(new JMenuItem(actionUpdateDatasources2));
            buttonUpdateDatasource.getPopupMenu().addSeparator();
            for (String ds : TvShowModuleManager.SETTINGS.getTvShowDataSource()) {
                buttonUpdateDatasource.getPopupMenu()
                        .add(new JMenuItem(new TvShowUpdateSingleDatasourceAction(ds)));
            }
            buttonUpdateDatasource.getPopupMenu().addSeparator();
            buttonUpdateDatasource.getPopupMenu().add(new JMenuItem(actionUpdateTvShow));
            buttonUpdateDatasource.getPopupMenu().pack();
        }
    });

    JPopupMenu popup = new JPopupMenu("popup");
    buttonUpdateDatasource.setPopupMenu(popup);
    toolBar.add(buttonUpdateDatasource);

    JSplitButton buttonScrape = new JSplitButton(IconManager.SEARCH);
    // temp fix for size of the button
    buttonScrape.setText("   ");
    buttonScrape.setHorizontalAlignment(JButton.LEFT);
    buttonScrape.setSplitWidth(18);
    buttonScrape.setToolTipText(BUNDLE.getString("tvshow.scrape.selected")); //$NON-NLS-1$

    // register for listener
    buttonScrape.addSplitButtonActionListener(new SplitButtonActionListener() {
        @Override
        public void buttonClicked(ActionEvent e) {
            actionScrape.actionPerformed(e);
        }

        @Override
        public void splitButtonClicked(ActionEvent e) {
        }
    });

    popup = new JPopupMenu("popup");
    JMenuItem item = new JMenuItem(actionScrape2);
    popup.add(item);
    // item = new JMenuItem(actionScrapeUnscraped);
    // popup.add(item);
    item = new JMenuItem(actionScrapeSelected);
    popup.add(item);
    item = new JMenuItem(actionScrapeNewItems);
    popup.add(item);
    buttonScrape.setPopupMenu(popup);
    toolBar.add(buttonScrape);
    toolBar.add(actionEdit);

    JButton btnMediaInformation = new JButton();
    btnMediaInformation.setAction(actionMediaInformation);
    toolBar.add(btnMediaInformation);

    // install drawing of full with
    tree = new ZebraJTree(treeModel) {
        private static final long serialVersionUID = 2422163883324014637L;

        @Override
        public void paintComponent(Graphics g) {
            width = this.getWidth();
            super.paintComponent(g);
        }
    };
    tvShowSelectionModel = new TvShowSelectionModel(tree);

    TreeUI ui = new TreeUI() {
        @Override
        protected void paintRow(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds,
                TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) {
            bounds.width = width - bounds.x;
            super.paintRow(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
        }
    };
    tree.setUI(ui);

    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.setCellRenderer(new TvShowTreeCellRenderer());
    tree.setRowHeight(0);
    scrollPane.setViewportView(tree);

    JPanel panelHeader = new JPanel() {
        private static final long serialVersionUID = -6914183798172482157L;

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            JTattooUtilities.fillHorGradient(g, AbstractLookAndFeel.getTheme().getColHeaderColors(), 0, 0,
                    getWidth(), getHeight());
        }
    };
    scrollPane.setColumnHeaderView(panelHeader);
    panelHeader.setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("center:20px"),
                    ColumnSpec.decode("center:20px"), ColumnSpec.decode("center:20px") },
            new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, }));

    JLabel lblTvShowsColumn = new JLabel(BUNDLE.getString("metatag.tvshow")); //$NON-NLS-1$
    lblTvShowsColumn.setHorizontalAlignment(JLabel.CENTER);
    panelHeader.add(lblTvShowsColumn, "2, 1");

    JLabel lblNfoColumn = new JLabel("");
    lblNfoColumn.setHorizontalAlignment(JLabel.CENTER);
    lblNfoColumn.setIcon(IconManager.INFO);
    lblNfoColumn.setToolTipText(BUNDLE.getString("metatag.nfo"));//$NON-NLS-1$
    panelHeader.add(lblNfoColumn, "4, 1");

    JLabel lblImageColumn = new JLabel("");
    lblImageColumn.setHorizontalAlignment(JLabel.CENTER);
    lblImageColumn.setIcon(IconManager.IMAGE);
    lblImageColumn.setToolTipText(BUNDLE.getString("metatag.images"));//$NON-NLS-1$
    panelHeader.add(lblImageColumn, "5, 1");

    JLabel lblSubtitleColumn = new JLabel("");
    lblSubtitleColumn.setHorizontalAlignment(JLabel.CENTER);
    lblSubtitleColumn.setIcon(IconManager.SUBTITLE);
    lblSubtitleColumn.setToolTipText(BUNDLE.getString("metatag.subtitles"));//$NON-NLS-1$
    panelHeader.add(lblSubtitleColumn, "6, 1");

    JPanel panel = new JPanel();
    panelTvShowTree.add(panel, "2, 5, 3, 1, fill, fill");
    panel.setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
                    FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                    FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                    FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, },
            new RowSpec[] { FormFactory.LINE_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, }));

    JLabel lblTvShowsT = new JLabel(BUNDLE.getString("metatag.tvshows") + ":"); //$NON-NLS-1$
    panel.add(lblTvShowsT, "1, 2, fill, fill");

    lblTvShows = new JLabel("");
    panel.add(lblTvShows, "3, 2");

    JLabel labelSlash = new JLabel("/");
    panel.add(labelSlash, "5, 2");

    JLabel lblEpisodesT = new JLabel(BUNDLE.getString("metatag.episodes") + ":"); //$NON-NLS-1$
    panel.add(lblEpisodesT, "7, 2");

    lblEpisodes = new JLabel("");
    panel.add(lblEpisodes, "9, 2");

    JLayeredPane layeredPaneRight = new JLayeredPane();
    layeredPaneRight.setLayout(
            new FormLayout(new ColumnSpec[] { ColumnSpec.decode("default"), ColumnSpec.decode("default:grow") },
                    new RowSpec[] { RowSpec.decode("default"), RowSpec.decode("default:grow") }));
    panelRight = new JPanel();
    layeredPaneRight.add(panelRight, "1, 1, 2, 2, fill, fill");
    layeredPaneRight.setLayer(panelRight, 0);

    // glass pane
    final TvShowExtendedSearchPanel panelExtendedSearch = new TvShowExtendedSearchPanel(treeModel, tree);
    panelExtendedSearch.setVisible(false);
    // panelMovieList.add(panelExtendedSearch, "2, 5, 2, 1, fill, fill");
    btnFilter.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            if (panelExtendedSearch.isVisible() == true) {
                panelExtendedSearch.setVisible(false);
            } else {
                panelExtendedSearch.setVisible(true);
            }
        }
    });
    // add a propertychangelistener which reacts on setting a filter
    tree.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if ("filterChanged".equals(evt.getPropertyName())) {
                if (Boolean.TRUE.equals(evt.getNewValue())) {
                    btnFilter.setIcon(IconManager.FILTER_ACTIVE);
                    btnFilter.setToolTipText(BUNDLE.getString("movieextendedsearch.options.active")); //$NON-NLS-1$
                } else {
                    btnFilter.setIcon(IconManager.FILTER);
                    btnFilter.setToolTipText(BUNDLE.getString("movieextendedsearch.options")); //$NON-NLS-1$
                }
            }
        }
    });
    layeredPaneRight.add(panelExtendedSearch, "1, 1, fill, fill");
    layeredPaneRight.setLayer(panelExtendedSearch, 1);

    splitPane.setRightComponent(layeredPaneRight);
    panelRight.setLayout(new CardLayout(0, 0));

    JPanel panelTvShow = new TvShowInformationPanel(tvShowSelectionModel);
    panelRight.add(panelTvShow, "tvShow");

    JPanel panelTvShowSeason = new TvShowSeasonInformationPanel(tvShowSeasonSelectionModel);
    panelRight.add(panelTvShowSeason, "tvShowSeason");

    JPanel panelTvShowEpisode = new TvShowEpisodeInformationPanel(tvShowEpisodeSelectionModel);
    panelRight.add(panelTvShowEpisode, "tvShowEpisode");

    tree.addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            if (node != null) {
                // click on a tv show
                if (node.getUserObject() instanceof TvShow) {
                    TvShow tvShow = (TvShow) node.getUserObject();
                    tvShowSelectionModel.setSelectedTvShow(tvShow);
                    CardLayout cl = (CardLayout) (panelRight.getLayout());
                    cl.show(panelRight, "tvShow");
                }

                // click on a season
                if (node.getUserObject() instanceof TvShowSeason) {
                    TvShowSeason tvShowSeason = (TvShowSeason) node.getUserObject();
                    tvShowSeasonSelectionModel.setSelectedTvShowSeason(tvShowSeason);
                    CardLayout cl = (CardLayout) (panelRight.getLayout());
                    cl.show(panelRight, "tvShowSeason");
                }

                // click on an episode
                if (node.getUserObject() instanceof TvShowEpisode) {
                    TvShowEpisode tvShowEpisode = (TvShowEpisode) node.getUserObject();
                    tvShowEpisodeSelectionModel.setSelectedTvShowEpisode(tvShowEpisode);
                    CardLayout cl = (CardLayout) (panelRight.getLayout());
                    cl.show(panelRight, "tvShowEpisode");
                }
            } else {
                // check if there is at least one tv show in the model
                TvShowRootTreeNode root = (TvShowRootTreeNode) tree.getModel().getRoot();
                if (root.getChildCount() == 0) {
                    // sets an inital show
                    tvShowSelectionModel.setSelectedTvShow(null);
                }
            }
        }
    });

    addComponentListener(new ComponentAdapter() {
        @Override
        public void componentHidden(ComponentEvent e) {
            menu.setVisible(false);
            super.componentHidden(e);
        }

        @Override
        public void componentShown(ComponentEvent e) {
            menu.setVisible(true);
            super.componentHidden(e);
        }
    });

    // further initializations
    init();
    initDataBindings();

    // selecting first TV show at startup
    if (tvShowList.getTvShows() != null && tvShowList.getTvShows().size() > 0) {
        DefaultMutableTreeNode firstLeaf = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) tree.getModel()
                .getRoot()).getFirstChild();
        tree.setSelectionPath(new TreePath(((DefaultMutableTreeNode) firstLeaf.getParent()).getPath()));
        tree.setSelectionPath(new TreePath(firstLeaf.getPath()));
    }
}

From source file:org.tinymediamanager.ui.tvshows.TvShowPanel.java

/**
 * Builds the menu.//w w  w  .ja va2 s .  co m
 */
private void buildMenu() {
    menu.setMnemonic(KeyEvent.VK_V);

    // menu items
    JMenuItem menuItem = menu.add(actionUpdateDatasources2);
    menuItem.setMnemonic(KeyEvent.VK_U);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_U, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menu.addSeparator();

    JMenu menuScrape = new JMenu(BUNDLE.getString("Button.scrape")); //$NON-NLS-1$
    menuScrape.setMnemonic(KeyEvent.VK_S);
    menuItem = menuScrape.add(actionScrape2);
    menuItem.setMnemonic(KeyEvent.VK_S);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menuItem = menuScrape.add(actionScrapeSelected);
    menuItem.setMnemonic(KeyEvent.VK_F);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menuItem = menuScrape.add(actionScrapeNewItems);
    menuItem.setMnemonic(KeyEvent.VK_N);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menu.add(menuScrape);

    JMenu menuEdit = new JMenu(BUNDLE.getString("Button.edit")); //$NON-NLS-1$
    menuEdit.setMnemonic(KeyEvent.VK_E);
    menuItem = menuEdit.add(actionEdit2);
    menuItem.setMnemonic(KeyEvent.VK_E);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menuItem = menuEdit.add(actionBatchEdit);
    menuItem.setMnemonic(KeyEvent.VK_B);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menuItem = menuEdit.add(actionSetWatchedFlag);
    menuItem.setMnemonic(KeyEvent.VK_W);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menuItem = menuEdit.add(actionChangeSeasonPoster2);
    menuItem.setMnemonic(KeyEvent.VK_S);
    menuEdit.add(actionChangeToDvdOrder);
    menuEdit.add(actionChangeToAiredOrder);

    menu.add(menuEdit);
    menu.add(actionRewriteTvShowNfo);
    menu.add(actionRewriteTvShowEpisodeNfo);

    menuItem = menu.add(actionRename);
    menuItem.setMnemonic(KeyEvent.VK_R);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menuItem = menu.add(actionMediaInformation2);
    menuItem.setMnemonic(KeyEvent.VK_M);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menuItem = menu.add(actionExport);
    menuItem.setMnemonic(KeyEvent.VK_X);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
    menuItem = menu.add(actionClearImageCache);
    menuItem.setMnemonic(KeyEvent.VK_C);

    menu.addSeparator();
    menuItem = menu.add(actionRemove2);
    menuItem.setAccelerator(KeyStroke.getKeyStroke((char) KeyEvent.VK_DELETE));
    menuItem = menu.add(actionDelete2);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, ActionEvent.SHIFT_MASK));

    menu.addSeparator();
    menuItem = menu.add(actionSyncTrakt);
    menuItem.setMnemonic(KeyEvent.VK_T);
    menuItem = menu.add(actionSyncWatchedTrakt);
    menuItem.setMnemonic(KeyEvent.VK_W);
    menuItem = menu.add(actionSyncSelectedTrakt);

    // popup menu
    JPopupMenu popupMenu = new JPopupMenu();
    popupMenu.add(actionScrape2);
    popupMenu.add(actionScrapeSelected);
    popupMenu.add(actionScrapeEpisodes);
    popupMenu.add(actionScrapeEpisodes2);
    popupMenu.add(actionScrapeNewItems);
    // popupMenu.add(actionScrapeMetadataSelected);
    popupMenu.addSeparator();
    popupMenu.add(actionUpdateTvShow);
    popupMenu.addSeparator();
    popupMenu.add(actionEdit2);
    popupMenu.add(actionChangeSeasonPoster2);
    popupMenu.add(actionBatchEdit);
    popupMenu.add(actionSetWatchedFlag);
    popupMenu.add(actionChangeToDvdOrder);
    popupMenu.add(actionChangeToAiredOrder);
    popupMenu.add(actionRewriteTvShowNfo);
    popupMenu.add(actionRewriteTvShowEpisodeNfo);
    // popupMenu.add(actionBatchEdit);
    popupMenu.add(actionRename);
    popupMenu.add(actionMediaInformation2);
    popupMenu.add(actionExport);
    popupMenu.add(actionClearImageCache);
    popupMenu.addSeparator();
    popupMenu.add(actionDownloadSubtitles);
    popupMenu.add(actionSearchAndDownloadSubtitles);
    popupMenu.addSeparator();
    popupMenu.add(actionSyncTrakt);
    popupMenu.add(actionSyncWatchedTrakt);
    popupMenu.add(actionSyncSelectedTrakt);
    popupMenu.addSeparator();
    popupMenu.add(actionRemove2);
    popupMenu.add(actionDelete2);
    popupMenu.addSeparator();
    popupMenu.add(new ExpandAllAction());
    popupMenu.add(new CollapseAllAction());

    if (Globals.isDebug()) {
        JMenu menuDebug = new JMenu("Debug"); //$NON-NLS-1$
        menuDebug.add(debugDumpShow);
        popupMenu.addSeparator();
        popupMenu.add(menuDebug);
    }

    MouseListener popupListener = new TreePopupListener(popupMenu, tree);
    tree.addMouseListener(popupListener);
}

From source file:org.ut.biolab.medsavant.client.cohort.CohortDetailedView.java

public JPopupMenu createHospitalPopup(final String[] hospitalIds) {
    JPopupMenu popupMenu = new JPopupMenu();

    //Filter by patient
    JMenuItem filter1Item = new JMenuItem(String.format("<html>Filter by %s</html>",
            hospitalIds.length == 1 ? "Hospital ID <i>" + hospitalIds[0] + "</i>" : "Selected Hospital IDs"));
    filter1Item.addActionListener(new ActionListener() {
        @Override/*from ww w. j av a 2 s .c o m*/
        public void actionPerformed(ActionEvent e) {
            String cohort = null;
            if (cohorts.length == 1) {
                cohort = cohorts[0].getName();
            }
            QueryUtils.addQueryOnHospitals(hospitalIds, cohort);

            DialogUtils.displayMessage(
                    "Selected Cohort and Hospital IDS have been added to query.  Click 'Variants' to review and execute search.");
        }
    });
    popupMenu.add(filter1Item);

    return popupMenu;
}

From source file:org.ut.biolab.medsavant.client.cohort.CohortDetailedView.java

@Override
public JPopupMenu createPopup() {
    JPopupMenu popupMenu = new JPopupMenu();

    if (ProjectController.getInstance().getCurrentVariantTableSchema() == null) {
        popupMenu.add(new JLabel("(You must choose a variant table before filtering)"));
    } else {/*from w  w w  .  j av a 2s. c  o  m*/

        //Filter by patient
        JMenuItem filter1Item = new JMenuItem(String.format("<html>Filter by %s</html>",
                cohorts.length == 1 ? "Cohort <i>" + cohorts[0] + "</i>" : "Selected Cohorts"));
        filter1Item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                QueryViewController qvc = SearchBar.getInstance().getQueryViewController();
                SearchConditionGroupItem p = qvc.getQueryRootGroup();

                List<SearchConditionItem> sciList = new ArrayList<SearchConditionItem>(cohorts.length);

                List<String> cohortStrings = new ArrayList(cohorts.length);
                for (Cohort cohort : cohorts) {
                    cohortStrings.add(cohort.getName());
                    /*
                     SearchConditionItem cohortItem = new SearchConditionItem("Cohort", SearchConditionGroupItem.QueryRelation.AND, p);
                     cohortItem.setDescription(cohort.toString());
                     cohortItem.setSearchConditionEncoding(StringConditionEncoder.encodeConditions(Arrays.asList(new String[]{cohort.toString()})));
                     sciList.add(cohortItem);
                     * */
                }

                String description = StringConditionEncoder.getDescription(cohortStrings);
                String encodedConditions = StringConditionEncoder.encodeConditions(cohortStrings);

                qvc.replaceFirstLevelItem("Cohort", encodedConditions, description);
                /*
                 if (cohorts.length < 2) {
                        
                 SearchConditionItem sci = sciList.get(0);
                 qvc.generateItemViewAndAddToGroup(sci, p);
                 } else {
                 qvc.replaceFirstLevelGroup("Cohorts", sciList, QueryRelation.AND, true);
                 }*/
                qvc.refreshView();
                DialogUtils.displayMessage(
                        "Selected Cohorts have been added to query.  Click 'Variants' to review and execute search.");

            }
        });
        popupMenu.add(filter1Item);
    }

    return popupMenu;
}

From source file:org.ut.biolab.medsavant.client.query.QueryViewController.java

private List<JComponent> getComponentsFromQueryModel(SearchConditionGroupItem g, int depth) {
    List<JComponent> components = new ArrayList<JComponent>();
    int w = 0;/*from  w w w  .j a va 2 s  . c o m*/
    for (final SearchConditionItem item : g.getItems()) {
        if (item instanceof SearchConditionGroupItem) {
            String addition = "";
            if (item.getParent() != null) {
                addition = item.getRelation() + "";
            }

            final JPanel p = ViewUtil.getClearPanel();
            MigLayout ml = new MigLayout("wrap 1, hidemode 1, insets 2");
            p.setLayout(ml);
            Border border = ViewUtil.getThickLeftLineBorder();
            p.setBorder(border);

            final PillView pv = new PillView(true);
            pv.indent(depth);

            pv.setActivated(true);

            final ActionListener toggleGroupExpand = new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    expandedItemsMap.put((SearchConditionGroupItem) item, !p.isVisible());
                    p.setVisible(!p.isVisible());
                    pv.setText(getGroupTitle((SearchConditionGroupItem) item));
                }
            };

            pv.setExpandListener(toggleGroupExpand);

            pv.setPopupGenerator(new ConditionPopupGenerator() {
                @Override
                public JPopupMenu generatePopup() {
                    final SearchConditionGroupItem groupItem = (SearchConditionGroupItem) item;
                    final JPopupMenu m = new JPopupMenu();

                    if (!item.getParent().isFirstItem(item)) {
                        if (item.getRelation() == QueryRelation.AND) {
                            JMenuItem b = new JMenuItem("Change to \"or\"");
                            b.addActionListener(new ActionListener() {
                                @Override
                                public void actionPerformed(ActionEvent ae) {
                                    item.setRelation(QueryRelation.OR);
                                    pv.setText(getGroupTitle(groupItem));
                                }
                            });
                            m.add(b);
                        } else {
                            JMenuItem b = new JMenuItem("Change to \"and\"");
                            b.addActionListener(new ActionListener() {
                                @Override
                                public void actionPerformed(ActionEvent ae) {
                                    item.setRelation(QueryRelation.AND);
                                    pv.setText(getGroupTitle(groupItem));
                                }
                            });
                            m.add(b);
                        }
                    }

                    JMenuItem delgroup = new JMenuItem("Delete");
                    delgroup.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent ae) {
                            groupItem.getParent().removeItem(groupItem);
                            refreshView();
                            expandedItemsMap.remove((SearchConditionGroupItem) item);
                        }
                    });
                    m.add(delgroup);

                    return m;
                }
            });
            SearchConditionGroupItem g2 = (SearchConditionGroupItem) item;

            pv.setText(getGroupTitle(g2));
            Boolean exp = expandedItemsMap.get((SearchConditionGroupItem) item);

            if (exp == null) {
                p.setVisible(false);
                pv.collapse();
            } else {
                p.setVisible(true);
                pv.expand();
            }

            components.add(pv);
            for (JComponent c : getComponentsFromQueryModel((SearchConditionGroupItem) item, depth + 1)) {
                p.add(c, "left");
            }
            components.add(p);

            w = pv.getMaximumSize().width;
        } else {
            SearchConditionItemView sciv = itemToViewMap.get(item);
            ((PillView) sciv).indent(depth);
            w = sciv.getMaximumSize().width;
            sciv.refresh();
            components.add(sciv);
        }
    }

    if (w == 0) {
        w = BOTTOM_SEARCH_TEXTFIELD_WIDTH;
    }
    JComponent c = getInputFieldForGroup(g, w);
    components.add(c);
    return components;
}

From source file:org.ut.biolab.medsavant.client.view.genetics.charts.SummaryChart.java

private JPopupMenu createPopup(final Chart chart) {

    JPopupMenu menu = new JPopupMenu();

    //Filter by selections
    JMenuItem filter1Item = new JMenuItem("Filter by Selection" + (mapGenerator.isNumeric() ? "" : "(s)"));
    filter1Item.addActionListener(new ActionListener() {
        @Override/*ww  w  .j  a va 2s  .co  m*/
        public void actionPerformed(ActionEvent e) {

            ThreadController.getInstance().cancelWorkers(pageName);

            boolean isGender = mapGenerator.getName().equalsIgnoreCase(BasicPatientColumns.GENDER.getAlias());
            try {
                List<String> values = new ArrayList<String>();
                ListSelectionModel selectionModel = chart.getSelectionsForModel(chart.getModel(0));
                QueryViewController qvc = SearchBar.getInstance().getQueryViewController();
                for (int i = selectionModel.getMinSelectionIndex(); i <= selectionModel
                        .getMaxSelectionIndex(); i++) {
                    if (selectionModel.isSelectedIndex(i)) {
                        String v = ((ChartPoint) chart.getModel().getPoint(i)).getHighlight().name();
                        values.add(v);
                        if (mapGenerator.isNumeric() && !isGender) {
                            double low = 0;
                            double high = 0;

                            String[] s = v.split(" - ");
                            if (s.length < 2) {
                                LOG.error("Invalid range detected for numeric condition "
                                        + mapGenerator.getName() + " val=" + v);
                            }
                            NumberFormat format = NumberFormat.getInstance();
                            low = format.parse(s[0]).doubleValue();
                            high = format.parse(s[1]).doubleValue();

                            QueryUtils.addNumericQuery(chartName, low, high, false);
                        }
                    }
                }
                if (values.isEmpty()) {
                    return;
                }

                if (!mapGenerator.isNumeric() || isGender) {
                    QueryUtils.addMultiStringQuery(chartName, values);
                }

            } catch (Exception ex) {
                ClientMiscUtils.reportError("Error filtering by selection: %s", ex);
            }
        }
    });
    menu.add(filter1Item);

    return menu;
}

From source file:org.ut.biolab.medsavant.client.view.genetics.TablePanel.java

private JPopupMenu createPopupSingle() {

    JPopupMenu menu = new JPopupMenu();

    TableModel model = searchableTablePanel.getTable().getModel();
    int r = TableModelWrapperUtils.getActualRowAt(model, searchableTablePanel.getTable().getSelectedRow());

    final String chrom = (String) model.getValueAt(r, INDEX_OF_CHROM);
    final int startpos = (Integer) model.getValueAt(r, INDEX_OF_START_POSITION);
    final int endpos = (Integer) model.getValueAt(r, INDEX_OF_END_POSITION);
    final String alt = (String) model.getValueAt(r, INDEX_OF_ALT);

    //Filter by position
    JMenuItem posItem = new JMenuItem("Filter by Position");

    posItem.addActionListener(new ActionListener() {
        @Override//from w ww  . ja  v  a 2 s .co m
        public void actionPerformed(ActionEvent ae) {
            //QueryUtils.addQueryOnChromPosition(chrom,pos);

            List<GenomicRegion> gr = new ArrayList<GenomicRegion>(1);
            gr.add(new GenomicRegion(null, chrom, startpos, endpos));

            QueryUtils.addQueryOnRegions(gr, null);
        }
    });

    menu.add(posItem);

    //Filter by position and alt
    JMenuItem posAndAltItem = new JMenuItem("Filter by Position and Alt");
    posAndAltItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            QueryUtils.addQueryOnRegionWithAlt(new GenomicRegion(null, chrom, startpos, endpos), alt);
        }
    });
    menu.add(posAndAltItem);

    return menu;
}

From source file:org.ut.biolab.medsavant.client.view.genetics.TablePanel.java

private JPopupMenu createPopupMultiple() {
    JPopupMenu menu = new JPopupMenu();

    JMenuItem posItem = new JMenuItem("Filter by Selected Positions");
    posItem.addActionListener(new ActionListener() {
        @Override/*ww  w  .j  a  va 2 s .c o  m*/
        public void actionPerformed(ActionEvent ae) {
            ThreadController.getInstance().cancelWorkers(pageName);

            //QueryViewController qvc = SearchBar.getInstance().getQueryViewController();
            List<GenomicRegion> regions = new ArrayList<GenomicRegion>();
            TableModel model = searchableTablePanel.getTable().getModel();
            int[] selRows = TableModelWrapperUtils.getActualRowsAt(model,
                    searchableTablePanel.getTable().getSelectedRows(), false);
            List<SearchConditionItem> sciList = new ArrayList<SearchConditionItem>(selRows.length);

            for (int r : selRows) {

                String chrom = (String) model.getValueAt(r, INDEX_OF_CHROM);
                int startpos = (Integer) model.getValueAt(r, INDEX_OF_START_POSITION);
                int endpos = (Integer) model.getValueAt(r, INDEX_OF_END_POSITION);
                regions.add(new GenomicRegion(null, chrom, startpos, endpos));

                /*
                 SearchConditionGroupItem posGroup = new SearchConditionGroupItem(SearchConditionGroupItem.QueryRelation.OR, null, null);
                 posGroup.setDescription("Chromosome "+chrom+", Pos. "+pos);
                        
                 SearchConditionItem chromItem = new SearchConditionItem(BasicVariantColumns.CHROM.getAlias(), SearchConditionGroupItem.QueryRelation.AND, posGroup);
                 chromItem.setDescription(chrom);
                 chromItem.setSearchConditionEncoding(StringConditionEncoder.encodeConditions(Arrays.asList(new String[]{chrom})));
                        
                 SearchConditionItem startPosItem = new SearchConditionItem(BasicVariantColumns.POSITION.getAlias(), SearchConditionGroupItem.QueryRelation.AND, posGroup);
                 startPosItem.setDescription(Integer.toString(pos));
                 startPosItem.setSearchConditionEncoding(NumericConditionEncoder.encodeConditions(pos, pos));
                        
                        
                 qvc.generateItemViewAndAddToGroup(chromItem, posGroup);
                 qvc.generateItemViewAndAddToGroup(startPosItem, posGroup);
                        
                 sciList.add(posGroup);                    */
            }
            //qvc.replaceFirstLevelGroup("Selected Position(s)", sciList, QueryRelation.OR, false);
            //qvc.refreshView();
            QueryUtils.addQueryOnRegions(regions, null);

        }
    });
    menu.add(posItem);

    return menu;
}

From source file:org.ut.biolab.medsavant.client.view.genetics.variantinfo.GeneManiaSubInspector.java

private JPopupMenu getRegionSetsMenu(Gene gene) {
    final JPopupMenu regionSets = new JPopupMenu();
    final RegionController regionController = RegionController.getInstance();
    final Gene g = gene;
    try {/*from w  ww. j  a v  a2s .  co m*/
        for (RegionSet s : regionController.getRegionSets()) {
            final RegionSet finalRegionSet = s;
            JMenuItem menuItem = new JMenuItem(s.getName());
            menuItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    try {
                        regionController.addToRegionSet(finalRegionSet, g.getChrom(), g.getStart(), g.getEnd(),
                                g.getName());
                        DialogUtils.displayMessage(String.format("Successfully added %s to %s list",
                                g.getName(), finalRegionSet.getName()));
                    } catch (Exception ex) {
                        ClientMiscUtils.reportError(String.format("Unable to add %s to %s list: %%s",
                                g.getName(), finalRegionSet.getName()), ex);
                    }
                }
            });
            regionSets.add(menuItem);
        }
    } catch (Exception ex) {
        return new JPopupMenu();
    }
    return regionSets;
}