Example usage for javax.swing JPopupMenu addSeparator

List of usage examples for javax.swing JPopupMenu addSeparator

Introduction

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

Prototype

public void addSeparator() 

Source Link

Document

Appends a new separator at the end of the menu.

Usage

From source file:org.orbisgis.sif.components.fstree.TreeNodeFolder.java

@Override
public void feedPopupMenu(JPopupMenu menu) {
    if (menu.getComponentCount() > 0) {
        menu.addSeparator();
    }// w  w w  .  j  a  va2  s  .c o  m
    // Open the folder
    JMenuItem copyPathMenu = new JMenuItem(I18N.tr("Copy the path"));
    copyPathMenu.setToolTipText(I18N.tr("Copy the folder path in the clipboard"));
    copyPathMenu.setActionCommand("TreeNodeFolder:CopyPath");
    copyPathMenu.addActionListener(EventHandler.create(ActionListener.class, this, "onCopyPath"));
    MenuCommonFunctions.updateOrInsertMenuItem(menu, copyPathMenu);
    // Read the file system to update the tree
    JMenuItem updateMenu = new JMenuItem(I18N.tr("Update"), SifIcon.getIcon("refresh"));
    updateMenu.setToolTipText(I18N.tr("Update the content of this folder from the file system"));
    updateMenu.setActionCommand("Update");
    updateMenu.addActionListener(EventHandler.create(ActionListener.class, this, "updateTree"));
    MenuCommonFunctions.updateOrInsertMenuItem(menu, updateMenu);
    // Add a new Sub Folder
    JMenuItem newSubFolder = new JMenuItem(I18N.tr("New folder"), SifIcon.getIcon("folder_add"));
    newSubFolder.setToolTipText(I18N.tr("Create a sub-folder"));
    newSubFolder.setActionCommand("TreeNodeFolder:newSubFolder");
    newSubFolder.addActionListener(EventHandler.create(ActionListener.class, this, "onNewSubFolder"));
    MenuCommonFunctions.updateOrInsertMenuItem(menu, newSubFolder);
    // Remove the folder
    //The root folder cannot be removed
    if (parent instanceof TreeNodeFolder) {
        JMenuItem folderRemove = new JMenuItem(I18N.tr("Delete"), SifIcon.getIcon("remove"));
        folderRemove.setToolTipText(I18N.tr("Remove permanently the folder"));
        folderRemove.setActionCommand("delete");
        folderRemove.addActionListener(EventHandler.create(ActionListener.class, this, "onDeleteFolder"));
        MenuCommonFunctions.updateOrInsertMenuItem(menu, folderRemove, true);
    }
}

From source file:org.orbisgis.view.components.fstree.TreeNodeFolder.java

@Override
public void feedPopupMenu(JPopupMenu menu) {
    if (menu.getComponentCount() > 0) {
        menu.addSeparator();
    }/*from   w  w w. j ava2 s  .  c o  m*/
    // Open the folder
    JMenuItem copyPathMenu = new JMenuItem(I18N.tr("Copy the path"));
    copyPathMenu.setToolTipText(I18N.tr("Copy the folder path in the clipboard"));
    copyPathMenu.setActionCommand("TreeNodeFolder:CopyPath");
    copyPathMenu.addActionListener(EventHandler.create(ActionListener.class, this, "onCopyPath"));
    MenuCommonFunctions.updateOrInsertMenuItem(menu, copyPathMenu);
    // Read the file system to update the tree
    JMenuItem updateMenu = new JMenuItem(I18N.tr("Update"), OrbisGISIcon.getIcon("arrow_refresh"));
    updateMenu.setToolTipText(I18N.tr("Update the content of this folder from the file system"));
    updateMenu.setActionCommand("Update");
    updateMenu.addActionListener(EventHandler.create(ActionListener.class, this, "updateTree"));
    MenuCommonFunctions.updateOrInsertMenuItem(menu, updateMenu);
    // Add a new Sub Folder
    JMenuItem newSubFolder = new JMenuItem(I18N.tr("New folder"), OrbisGISIcon.getIcon("folder_add"));
    newSubFolder.setToolTipText(I18N.tr("Create a sub-folder"));
    newSubFolder.setActionCommand("TreeNodeFolder:newSubFolder");
    newSubFolder.addActionListener(EventHandler.create(ActionListener.class, this, "onNewSubFolder"));
    MenuCommonFunctions.updateOrInsertMenuItem(menu, newSubFolder);
    // Remove the folder
    //The root folder cannot be removed
    if (parent instanceof TreeNodeFolder) {
        JMenuItem folderRemove = new JMenuItem(I18N.tr("Delete"), OrbisGISIcon.getIcon("remove"));
        folderRemove.setToolTipText(I18N.tr("Remove permanently the folder"));
        folderRemove.setActionCommand("delete");
        folderRemove.addActionListener(EventHandler.create(ActionListener.class, this, "onDeleteFolder"));
        MenuCommonFunctions.updateOrInsertMenuItem(menu, folderRemove, true);
    }
}

From source file:org.pmedv.blackboard.components.PartView.java

protected void initializeComponents() {

    setLayout(new BorderLayout());

    partPanel = new PartPanel();
    partBusyPanel = new JBusyComponent<PartPanel>(partPanel);

    setSize(new Dimension(900, 650));

    textArea = new RSyntaxTextArea();
    textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
    RTextScrollPane textScrollPane = new RTextScrollPane(textArea);

    CompletionProvider provider = createCompletionProvider();
    AutoCompletion ac = new AutoCompletion(provider);
    ac.install(textArea);//from  www  . j  a  va  2  s.com

    JPopupMenu popup = textArea.getPopupMenu();
    popup.addSeparator();
    popup.add(new JMenuItem(new SaveAction()));

    tabbedPane = new JTabbedPane(JTabbedPane.BOTTOM);
    tabbedPane.addTab("Parts", partBusyPanel);
    tabbedPane.addTab("Part Editor", textScrollPane);
    tabbedPane.setEnabledAt(1, false);
    add(tabbedPane, BorderLayout.CENTER);

    tablePopupMenu = new JPopupMenu();

    // We do the part loading in background and display a busy panel while loading

    SwingWorker<ArrayList<Part>, Void> w = new SwingWorker<ArrayList<Part>, Void>() {

        @Override
        protected ArrayList<Part> doInBackground() {
            partBusyPanel.setBusy(true);
            try {
                return AppContext.getContext().getBean(PartFactory.class).getAvailableParts();
            } catch (Exception e) {
                ErrorUtils.showErrorDialog(e);
                return new ArrayList<Part>();
            }
        }

        @Override
        protected void done() {
            log.info("Done loading parts.");
            try {
                model = new PartTableModel(get());
                partPanel.getPartTable().setModel(model);
            } catch (Exception e) {
                ErrorUtils.showErrorDialog(e);
            }
            partBusyPanel.setBusy(false);
            partPanel.transferFocus();
        }
    };

    partPanel.getPartTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            JXTable table = partPanel.getPartTable();
            int[] rows = table.getSelectedRows();
            if (rows.length == 1) {
                if (model == null)
                    return;
                Part selectedPart = model.getParts().get(table.convertRowIndexToModel(rows[0]));
                currentPart = selectedPart;
                selectedRow = table.convertRowIndexToModel(rows[0]);
                partPanel.getImageLabel().setIcon(new ImageIcon(selectedPart.getImage()));
                partPanel.getImageLabel().setText(null);
                partPanel.getPartNameField().setText(selectedPart.getName());
                partPanel.getDescriptionPane().setText(selectedPart.getDescription());
                partPanel.getPackageTypeField().setText(selectedPart.getPackageType());
                partPanel.getAuthorField().setText(selectedPart.getAuthor());
                partPanel.getLicenseField().setText(selectedPart.getLicense());
                tabbedPane.setEnabledAt(1, true);
                textArea.setText(selectedPart.getXmlContent());
            } else {
                currentPart = null;
                partPanel.getImageLabel().setText(resources.getResourceByKey("PartDialog.selectmsg"));
                partPanel.getImageLabel().setIcon(null);
                tabbedPane.setEnabledAt(1, false);
                textArea.setText("");
            }
        }
    });

    partPanel.getPartTable().addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            handlePopupTrigger(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            handlePopupTrigger(e);
        }
    });

    tablePopupMenu.add(AppContext.getContext().getBean(DeletePartCommand.class));

    // this is the filter configuration for the filter text box on the top
    PartFilter filter = new PartFilter(partPanel.getPartTable());
    BindingGroup filterGroup = new BindingGroup();
    // bind filter JTextBox's text attribute to part tables filterString
    // attribute
    filterGroup.addBinding(Bindings.createAutoBinding(READ, partPanel.getFilterPanel().getFilterTextField(),
            BeanProperty.create("text"), filter, BeanProperty.create("filterString")));
    filterGroup.bind();
    w.execute();

}

From source file:org.pmedv.blackboard.dialogs.PartDialog.java

@Override
protected void initializeComponents() {

    partPanel = new PartPanel();
    partBusyPanel = new JBusyComponent<PartPanel>(partPanel);

    setSize(new Dimension(900, 750));

    textArea = new RSyntaxTextArea();
    textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
    RTextScrollPane textScrollPane = new RTextScrollPane(textArea);

    CompletionProvider provider = createCompletionProvider();
    AutoCompletion ac = new AutoCompletion(provider);
    ac.install(textArea);//from  w w  w.  j a v a  2  s . co  m

    JPopupMenu popup = textArea.getPopupMenu();
    popup.addSeparator();
    popup.add(new JMenuItem(new SaveAction()));

    tabbedPane = new JTabbedPane(JTabbedPane.BOTTOM);
    tabbedPane.addTab("Parts", partBusyPanel);
    tabbedPane.addTab("Part Editor", textScrollPane);
    tabbedPane.setEnabledAt(1, false);
    getContentPanel().add(tabbedPane);

    tablePopupMenu = new JPopupMenu();

    // We do the part loading in background and display a busy panel while loading

    SwingWorker<ArrayList<Part>, Void> w = new SwingWorker<ArrayList<Part>, Void>() {

        @Override
        protected ArrayList<Part> doInBackground() {
            partBusyPanel.setBusy(true);
            try {
                return AppContext.getContext().getBean(PartFactory.class).getAvailableParts();
            } catch (Exception e) {
                ErrorUtils.showErrorDialog(e);
                return new ArrayList<Part>();
            }
        }

        @Override
        protected void done() {
            log.info("Done loading parts.");
            try {
                model = new PartTableModel(get());
                partPanel.getPartTable().setModel(model);
            } catch (Exception e) {
                ErrorUtils.showErrorDialog(e);
            }
            partBusyPanel.setBusy(false);
            partPanel.transferFocus();
        }
    };

    getOkButton().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JXTable table = partPanel.getPartTable();
            result = OPTION_OK;
            selectedParts = new ArrayList<Part>();
            int rows[] = partPanel.getPartTable().getSelectedRows();
            try {
                for (int i = 0; i < rows.length; i++) {
                    selectedParts.add(AppContext.getContext().getBean(PartFactory.class).createPart(
                            model.getParts().get(table.convertRowIndexToModel(rows[i])).getFilename()));
                }
            } catch (Exception e1) {
                ErrorUtils.showErrorDialog(e1);
            }
            setVisible(false);
        }
    });

    getCancelButton().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            result = OPTION_CANCEL;
            setVisible(false);
        }
    });

    getNewButton().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            AppContext.getContext().getBean(CreatePartCommand.class).execute(e);
        }
    });

    partPanel.getPartTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            JXTable table = partPanel.getPartTable();
            int[] rows = table.getSelectedRows();
            if (rows.length == 1) {
                if (model == null)
                    return;
                Part selectedPart = model.getParts().get(table.convertRowIndexToModel(rows[0]));
                currentPart = selectedPart;
                selectedRow = table.convertRowIndexToModel(rows[0]);
                partPanel.getImageLabel().setIcon(new ImageIcon(selectedPart.getImage()));
                partPanel.getImageLabel().setText(null);
                partPanel.getPartNameField().setText(selectedPart.getName());
                partPanel.getDescriptionPane().setText(selectedPart.getDescription());
                partPanel.getPackageTypeField().setText(selectedPart.getPackageType());
                partPanel.getAuthorField().setText(selectedPart.getAuthor());
                partPanel.getLicenseField().setText(selectedPart.getLicense());
                tabbedPane.setEnabledAt(1, true);
                textArea.setText(selectedPart.getXmlContent());
            } else {
                currentPart = null;
                partPanel.getImageLabel().setText(resources.getResourceByKey("PartDialog.selectmsg"));
                partPanel.getImageLabel().setIcon(null);
                tabbedPane.setEnabledAt(1, false);
                textArea.setText("");
            }
        }
    });

    tabbedPane.addChangeListener(new ChangeListener() {
        // This method is called whenever the selected tab changes
        public void stateChanged(ChangeEvent evt) {
            JTabbedPane pane = (JTabbedPane) evt.getSource();
            int index = pane.getSelectedIndex();
            if (index == 0) {
                getTitleLabel().setText(title);
                getSubTitleLabel().setText(subTitle);
            } else {
                getTitleLabel().setText(editTitle);
                getSubTitleLabel().setText(editSubTitle + " : " + currentPart.getName());
            }
        }
    });

    partPanel.getPartTable().addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            handlePopupTrigger(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            handlePopupTrigger(e);
        }
    });

    tablePopupMenu.add(ctx.getBean(DeletePartCommand.class));

    // this is the filter configuration for the filter text box on the top
    PartFilter filter = new PartFilter(partPanel.getPartTable());
    BindingGroup filterGroup = new BindingGroup();
    // bind filter JTextBox's text attribute to part tables filterString
    // attribute
    filterGroup.addBinding(Bindings.createAutoBinding(READ, partPanel.getFilterPanel().getFilterTextField(),
            BeanProperty.create("text"), filter, BeanProperty.create("filterString")));
    filterGroup.bind();
    w.execute();

}

From source file:org.rdv.datapanel.AbstractDataPanel.java

/**
 * Get a component for displaying the title in top bar. This implementation
 * includes a button to remove a specific channel.
 * //from  ww w.j a  v  a 2  s.com
 * Subclasses should overide this method if they don't want the default
 * implementation.
 * 
 * @return  A component for the top bar
 * @since   1.3
 */
JComponent getTitleComponent() {
    JPanel titleBar = new JPanel();
    titleBar.setOpaque(false);
    titleBar.setLayout(new BorderLayout());

    JPopupMenu popupMenu = new ScrollablePopupMenu();

    final String title;
    if (description != null) {
        title = "Edit description";
    } else {
        title = "Add description";
    }

    JMenuItem addDescriptionMenuItem = new JMenuItem(title);
    addDescriptionMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            String response = (String) JOptionPane.showInputDialog(null, "Enter a description", title,
                    JOptionPane.QUESTION_MESSAGE, null, null, description);
            if (response == null) {
                return;
            } else if (response.length() == 0) {
                setDescription(null);
            } else {
                setDescription(response);
            }
        }
    });
    popupMenu.add(addDescriptionMenuItem);

    if (description != null) {
        JMenuItem removeDescriptionMenuItem = new JMenuItem("Remove description");
        removeDescriptionMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                setDescription(null);
            }
        });
        popupMenu.add(removeDescriptionMenuItem);
    }

    popupMenu.addSeparator();

    final JCheckBoxMenuItem showChannelsInTitleMenuItem = new JCheckBoxMenuItem("Show channels in title",
            showChannelsInTitle);
    showChannelsInTitleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setShowChannelsInTitle(showChannelsInTitleMenuItem.isSelected());
        }
    });
    popupMenu.add(showChannelsInTitleMenuItem);

    if (channels.size() > 0) {
        popupMenu.addSeparator();

        Iterator<String> i = channels.iterator();
        while (i.hasNext()) {
            final String channelName = i.next();

            JMenuItem unsubscribeChannelMenuItem = new JMenuItem("Unsubscribe from " + channelName);
            unsubscribeChannelMenuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    removeChannel(channelName);
                }
            });
            popupMenu.add(unsubscribeChannelMenuItem);
        }
    }

    // set component popup and mouselistener to trigger it
    titleBar.setComponentPopupMenu(popupMenu);
    titleBar.addMouseListener(new MouseInputAdapter() {
    });

    if (description != null) {
        titleBar.add(getDescriptionComponent(), BorderLayout.WEST);
    }

    JComponent titleComponent = getChannelComponent();
    if (titleComponent != null) {
        titleBar.add(titleComponent, BorderLayout.CENTER);
    }

    return titleBar;
}

From source file:org.rdv.datapanel.DigitalTabularDataPanel.java

private void addColumn() {
    if (columnGroupCount == MAX_COLUMN_GROUP_COUNT) {
        return;//from  w  w w .j a  v  a  2 s.co m
    }

    if (columnGroupCount != 0) {
        panelBox.add(Box.createHorizontalStrut(7));
    }

    final int tableIndex = columnGroupCount;

    final DataTableModel tableModel = new DataTableModel();
    final JTable table = new JTable(tableModel);

    table.setDragEnabled(true);
    table.setName(DigitalTabularDataPanel.class.getName() + " JTable #" + Integer.toString(columnGroupCount));

    if (showThresholdCheckBoxGroup.isSelected()) {
        tableModel.setThresholdVisible(true);
    }

    if (showMinMaxCheckBoxGroup.isSelected()) {
        tableModel.setMaxMinVisible(true);

        table.getColumn("Min").setCellRenderer(doubleCellRenderer);
        table.getColumn("Max").setCellRenderer(doubleCellRenderer);
    }

    table.getColumn("Value").setCellRenderer(dataCellRenderer);

    tables.add(table);
    tableModels.add(tableModel);

    JScrollPane tableScrollPane = new JScrollPane(table);
    panelBox.add(tableScrollPane);

    // popup menu for panel
    JPopupMenu popupMenu = new JPopupMenu();

    final JMenuItem copyMenuItem = new JMenuItem("Copy");
    copyMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            TransferHandler.getCopyAction().actionPerformed(
                    new ActionEvent(table, ae.getID(), ae.getActionCommand(), ae.getWhen(), ae.getModifiers()));
        }
    });
    popupMenu.add(copyMenuItem);

    popupMenu.addSeparator();

    JMenuItem printMenuItem = new JMenuItem("Print...");
    printMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                table.print(JTable.PrintMode.FIT_WIDTH);
            } catch (PrinterException pe) {
            }
        }
    });
    popupMenu.add(printMenuItem);
    popupMenu.addSeparator();

    final JCheckBoxMenuItem showMaxMinMenuItem = new JCheckBoxMenuItem("Show min/max columns", false);
    showMaxMinMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setMaxMinVisible(showMaxMinMenuItem.isSelected());
        }
    });
    showMinMaxCheckBoxGroup.addCheckBox(showMaxMinMenuItem);
    popupMenu.add(showMaxMinMenuItem);

    final JCheckBoxMenuItem showThresholdMenuItem = new JCheckBoxMenuItem("Show threshold columns", false);
    showThresholdMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setThresholdVisible(showThresholdMenuItem.isSelected());
        }
    });
    showThresholdCheckBoxGroup.addCheckBox(showThresholdMenuItem);
    popupMenu.add(showThresholdMenuItem);

    popupMenu.addSeparator();

    JMenuItem blankRowMenuItem = new JMenuItem("Insert blank row");
    blankRowMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            tableModel.addBlankRow();
        }
    });
    popupMenu.add(blankRowMenuItem);

    final JMenuItem removeSelectedRowsMenuItem = new JMenuItem("Remove selected rows");
    removeSelectedRowsMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            removeSelectedRows(tableIndex);
        }
    });
    popupMenu.add(removeSelectedRowsMenuItem);

    popupMenu.addSeparator();

    JMenu numberOfColumnsMenu = new JMenu("Number of columns");
    numberOfColumnsMenu.addMenuListener(new MenuListener() {
        public void menuSelected(MenuEvent me) {
            JMenu menu = (JMenu) me.getSource();
            for (int j = 0; j < MAX_COLUMN_GROUP_COUNT; j++) {
                JMenuItem menuItem = menu.getItem(j);
                boolean selected = (j == (columnGroupCount - 1));
                menuItem.setSelected(selected);
            }
        }

        public void menuDeselected(MenuEvent me) {
        }

        public void menuCanceled(MenuEvent me) {
        }
    });

    for (int i = 0; i < MAX_COLUMN_GROUP_COUNT; i++) {
        final int number = i + 1;
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(Integer.toString(number));
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                setNumberOfColumns(number);
            }
        });
        numberOfColumnsMenu.add(item);
    }
    popupMenu.add(numberOfColumnsMenu);

    popupMenu.addPopupMenuListener(new PopupMenuListener() {
        public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) {
            boolean anyRowsSelected = table.getSelectedRowCount() > 0;
            copyMenuItem.setEnabled(anyRowsSelected);
            removeSelectedRowsMenuItem.setEnabled(anyRowsSelected);
        }

        public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) {
        }

        public void popupMenuCanceled(PopupMenuEvent arg0) {
        }
    });

    // set component popup and mouselistener to trigger it
    table.setComponentPopupMenu(popupMenu);
    tableScrollPane.setComponentPopupMenu(popupMenu);

    panelBox.revalidate();

    columnGroupCount++;

    properties.setProperty("numberOfColumns", Integer.toString(columnGroupCount));
}

From source file:org.rdv.ui.ChannelListPanel.java

private JPopupMenu getChannelPopup() {
    JPopupMenu popup = new JPopupMenu();
    JMenuItem menuItem;//from  ww  w  . j a  v  a2 s  .co m

    final List<String> channels = getSelectedChannels();
    if (channels.isEmpty()) {
        return null;
    }

    String plural = (channels.size() == 1) ? "" : "s";

    List<Extension> extensions = dataPanelManager.getExtensions(channels);
    if (extensions.size() > 0) {
        for (final Extension extension : extensions) {
            menuItem = new JMenuItem("View channel" + plural + " with " + extension.getName());
            menuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    viewChannels(channels, extension);
                }
            });
            popup.add(menuItem);
        }

        popup.addSeparator();
    }

    if (dataPanelManager.isAnyChannelSubscribed(channels)) {
        menuItem = new JMenuItem("Unsubscribe from channel" + plural);
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                dataPanelManager.unsubscribeChannels(channels);
            }
        });
        popup.add(menuItem);
        popup.addSeparator();
    }

    // menu item to remove local channels
    if (areLocal(channels)) {
        menuItem = new JMenuItem("Remove channel" + plural);
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                LocalChannelManager lcm = LocalChannelManager.getInstance();
                lcm.removeChannels(channels);
            }
        });
        popup.add(menuItem);
        popup.addSeparator();
    }

    String mime = getMime(channels);
    if (mime != null) {
        if (mime.equals("application/octet-stream")) {
            menuItem = new JMenuItem("Export data channel" + plural + "...",
                    DataViewer.getIcon("icons/export.gif"));
            menuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    ActionFactory.getInstance().getDataExportAction().exportData(channels);
                }
            });
            popup.add(menuItem);
        } else if (mime.equals("image/jpeg")) {
            menuItem = new JMenuItem("Export video channel" + plural + "...",
                    DataViewer.getIcon("icons/export.gif"));
            menuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    JFrame frame = RDV.getInstance(RDV.class).getMainFrame();
                    new ExportVideoDialog(frame, rbnb, channels);
                }
            });
            popup.add(menuItem);
        } else {
            popup.remove(popup.getComponentCount() - 1);
        }
    }

    return popup;
}

From source file:org.rdv.viz.image.HighResImageViz.java

public void buildPopupMenu(JPopupMenu menu, MouseEvent e) {
    super.buildPopupMenu(menu, e);

    ActionListener setTimerangeAction = new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            double newScale = Double.parseDouble(ae.getActionCommand());
            setLocalTimescale(newScale);
        }// ww  w.j  a  v  a  2  s .c  o m
    };

    // regenerate new menu
    JMenu timeRangeMenu = new JMenu("Set Timerange");
    ButtonGroup timeRangeGroup = new ButtonGroup();
    JRadioButtonMenuItem range = new JRadioButtonMenuItem(TimeScale.TIME_SCALE_UNDEFINED_DESC);
    range.setActionCommand(String.valueOf(TimeScale.TIME_SCALE_UNDEFINED));
    range.addActionListener(setTimerangeAction);
    timeRangeGroup.add(range);
    timeRangeMenu.add(range);
    if (localTimeScale_ == TimeScale.TIME_SCALE_UNDEFINED)
        range.setSelected(true);

    Double timeScales[] = TimeScale.getGlobalTimeScales();
    for (int i = 0; i < timeScales.length; i++) {
        range = new JRadioButtonMenuItem(DataViewer.formatSeconds(timeScales[i]));
        range.setActionCommand(String.valueOf(timeScales[i]));
        range.addActionListener(setTimerangeAction);
        timeRangeGroup.add(range);
        timeRangeMenu.add(range);
        if (localTimeScale_ == timeScales[i])
            range.setSelected(true);
    }

    menu.add(timeRangeMenu);
    menu.addSeparator();

    // create a popup to copy an image to the clipboard
    final JMenuItem copyImageMenuItem = new JMenuItem("Copy");
    copyImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            copyImage();
        }
    });
    menu.add(copyImageMenuItem);
    menu.addSeparator();

    // create a popup to save an image
    final JMenuItem saveImageMenuItem = new JMenuItem("Save as...");
    saveImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            saveImage();
        }
    });
    menu.add(saveImageMenuItem);

    menu.addSeparator();

    // create a popup to copy an image to the clipboard
    final JMenuItem printImageMenuItem = new JMenuItem("Print...");
    printImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            printImage();
        }
    });
    menu.add(printImageMenuItem);

    menu.addSeparator();

    final JMenuItem zoomInMenuItem = new JMenuItem("Zoom in");
    zoomInMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            imagePanel.zoomIn();
        }
    });
    menu.add(zoomInMenuItem);

    final JMenuItem zoomOutMenuItem = new JMenuItem("Zoom out");
    zoomOutMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            imagePanel.zoomOut();
        }
    });
    menu.add(zoomOutMenuItem);

    final JSeparator zoomMenuSeparator = new JPopupMenu.Separator();
    menu.add(zoomMenuSeparator);

    final JCheckBoxMenuItem autoScaleMenuItem = new JCheckBoxMenuItem("Auto scale", imagePanel.isAutoScaling());
    autoScaleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setAutoScale(autoScaleMenuItem.isSelected());
        }
    });
    menu.add(autoScaleMenuItem);

    final JMenuItem resetScaleMenuItem = new JMenuItem("Reset scale");
    resetScaleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            imagePanel.setScale(1);
        }
    });
    menu.add(resetScaleMenuItem);

    final JCheckBoxMenuItem showNavigationImageMenuItem = new JCheckBoxMenuItem("Show navigation image",
            imagePanel.isNavigationImageEnabled());
    showNavigationImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            setShowNavigationImage(showNavigationImageMenuItem.isSelected());
        }
    });
    menu.add(showNavigationImageMenuItem);

    //menu.addSeparator();

    final JCheckBoxMenuItem useThumbnailImageMenuItem = new JCheckBoxMenuItem("Use thumbnail image",
            useThumbnailImage);
    useThumbnailImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setUseThumbnailImage(useThumbnailImageMenuItem.isSelected());
        }
    });
    menu.add(useThumbnailImageMenuItem);

    boolean hasImage = displayedImageData != null;
    saveImageMenuItem.setEnabled(hasImage);
    copyImageMenuItem.setEnabled(hasImage);
    printImageMenuItem.setEnabled(hasImage);

    boolean enableZoom = hasImage;
    zoomInMenuItem.setEnabled(enableZoom);
    zoomInMenuItem.setVisible(true);
    zoomOutMenuItem.setEnabled(enableZoom);
    zoomOutMenuItem.setVisible(true);
    zoomMenuSeparator.setVisible(true);

    autoScaleMenuItem.setVisible(true);
    resetScaleMenuItem.setVisible(true);
    showNavigationImageMenuItem.setVisible(true);

    useThumbnailImageMenuItem.setSelected(useThumbnailImage);
    useThumbnailImageMenuItem.setVisible(imageHasThumbnail());

}

From source file:org.rdv.viz.image.ImageViz.java

private void initPopupMenu() {
    final JPopupMenu popupMenu = new JPopupMenu();

    // create a popup to copy an image to the clipboard
    final JMenuItem copyImageMenuItem = new JMenuItem("Copy");
    copyImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            copyImage();//from w ww . ja  v  a2s.  co m
        }
    });
    popupMenu.add(copyImageMenuItem);

    popupMenu.addSeparator();

    // create a popup to save an image
    final JMenuItem saveImageMenuItem = new JMenuItem("Save as...");
    saveImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            saveImage();
        }
    });
    popupMenu.add(saveImageMenuItem);

    popupMenu.addSeparator();

    // create a popup to copy an image to the clipboard
    final JMenuItem printImageMenuItem = new JMenuItem("Print...");
    printImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            printImage();
        }
    });
    popupMenu.add(printImageMenuItem);

    popupMenu.addSeparator();

    final JMenuItem zoomInMenuItem = new JMenuItem("Zoom in");
    zoomInMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            imagePanel.zoomIn();
        }
    });
    popupMenu.add(zoomInMenuItem);

    final JMenuItem zoomOutMenuItem = new JMenuItem("Zoom out");
    zoomOutMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            imagePanel.zoomOut();
        }
    });
    popupMenu.add(zoomOutMenuItem);

    final JSeparator zoomMenuSeparator = new JPopupMenu.Separator();
    popupMenu.add(zoomMenuSeparator);

    autoScaleMenuItem = new JCheckBoxMenuItem("Auto scale", true);
    autoScaleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setAutoScale(autoScaleMenuItem.isSelected());
        }
    });
    popupMenu.add(autoScaleMenuItem);

    final JMenuItem resetScaleMenuItem = new JMenuItem("Reset scale");
    resetScaleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            imagePanel.setScale(1);
        }
    });
    popupMenu.add(resetScaleMenuItem);

    showNavigationImageMenuItem = new JCheckBoxMenuItem("Show navigation image",
            imagePanel.isNavigationImageEnabled());
    showNavigationImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            setShowNavigationImage(showNavigationImageMenuItem.isSelected());
        }
    });
    popupMenu.add(showNavigationImageMenuItem);

    final JMenu maximumFilmstripImagesMenu = new JMenu("Maximum number of images");
    maximumFilmstripImagesButtonGroup = new ButtonGroup();
    for (final int maximumFilmstripImagesValue : MAXIMUM_FILMSTRIP_IMAGES_VALUES) {
        boolean selected = filmstripPanel.getMaximumImages() == maximumFilmstripImagesValue;
        JMenuItem maximumFilmStripImagesMenuItem = new JRadioButtonMenuItem(
                Integer.toString(maximumFilmstripImagesValue), selected);
        maximumFilmStripImagesMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                filmstripPanel.setMaximumImages(maximumFilmstripImagesValue);
            }
        });
        maximumFilmstripImagesButtonGroup.add(maximumFilmStripImagesMenuItem);
        maximumFilmstripImagesMenu.add(maximumFilmStripImagesMenuItem);
    }
    popupMenu.add(maximumFilmstripImagesMenu);

    popupMenu.addSeparator();

    final JCheckBoxMenuItem showAsFilmstripMenuItem = new JCheckBoxMenuItem("Show as filmstrip", filmstripMode);
    showAsFilmstripMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            boolean filmstripMode = showAsFilmstripMenuItem.isSelected();
            setFilmstripMode(filmstripMode);
        }
    });
    popupMenu.add(showAsFilmstripMenuItem);

    final JCheckBoxMenuItem useThumbnailImageMenuItem = new JCheckBoxMenuItem("Use thumbnail image",
            useThumbnailImage);
    useThumbnailImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setUseThumbnailImage(useThumbnailImageMenuItem.isSelected());
        }
    });
    popupMenu.add(useThumbnailImageMenuItem);

    hideRoboticControlsMenuItem = new JCheckBoxMenuItem("Disable robotic controls", false);
    hideRoboticControlsMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setRoboticControls();
        }
    });
    popupMenu.add(hideRoboticControlsMenuItem);

    // enable the save image popup if an image is being displayed
    popupMenu.addPopupMenuListener(new PopupMenuListener() {
        public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) {
            boolean hasImage = displayedImageData != null;
            saveImageMenuItem.setEnabled(hasImage);
            copyImageMenuItem.setEnabled(hasImage);
            printImageMenuItem.setEnabled(hasImage);

            boolean enableZoom = hasImage && !filmstripMode;
            zoomInMenuItem.setEnabled(enableZoom);
            zoomInMenuItem.setVisible(!filmstripMode);
            zoomOutMenuItem.setEnabled(enableZoom);
            zoomOutMenuItem.setVisible(!filmstripMode);
            zoomMenuSeparator.setVisible(!filmstripMode);

            autoScaleMenuItem.setVisible(!filmstripMode);
            resetScaleMenuItem.setVisible(!filmstripMode);
            showNavigationImageMenuItem.setVisible(!filmstripMode);
            maximumFilmstripImagesMenu.setVisible(filmstripMode);

            showAsFilmstripMenuItem.setSelected(filmstripMode);

            useThumbnailImageMenuItem.setSelected(useThumbnailImage);
            useThumbnailImageMenuItem.setVisible(imageHasThumbnail());

            hideRoboticControlsMenuItem.setVisible(flexTPSStream != null);
        }

        public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) {
        }

        public void popupMenuCanceled(PopupMenuEvent arg0) {
        }
    });

    // set component popup and mouselistener to trigger it
    panel.setComponentPopupMenu(popupMenu);
    imagePanel.setComponentPopupMenu(popupMenu);
    filmstripPanel.setComponentPopupMenu(popupMenu);
    panel.addMouseListener(new MouseInputAdapter() {
    });
}

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   w  ww. j av a  2 s.  c  om*/
            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);
}