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.openmicroscopy.shoola.agents.metadata.editor.ToolBar.java

/** 
 * Creates or recycles the view menu./*w w w.j av a  2s .co m*/
 * 
 * @param source The source of the mouse event.
 * @param p The location of the mouse pressed.
 */
private void showViewMenu(Component source, Point p) {
    JPopupMenu menu = new JPopupMenu();
    IconManager icons = IconManager.getInstance();
    JMenuItem item = new JMenuItem(icons.getIcon(IconManager.VIEWER));
    item.setText("View...");
    item.setActionCommand("" + EditorControl.VIEW_IMAGE);
    item.addActionListener(controller);
    menu.add(item);
    item = new JMenuItem(icons.getIcon(IconManager.VIEWER_IJ));
    item.setText("View in ImageJ...");
    item.setActionCommand("" + EditorControl.VIEW_IMAGE_IN_IJ);
    item.addActionListener(controller);
    menu.add(item);
    menu.show(source, p.x, p.y);
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.ToolBar.java

/** 
 * Builds the menu displaying the available scripts.
 * //  w w  w.jav  a2 s .co m
 * @return See above.
 */
private JPopupMenu getScriptsMenu() {
    JPopupMenu menu = new JPopupMenu();

    Collection<ScriptObject> scripts = model.getScripts();
    //Scripts are sorted.
    if (scripts == null || scripts.size() == 0)
        return menu;
    IconManager icons = IconManager.getInstance();
    JMenuItem refresh = new JMenuItem(icons.getIcon(IconManager.REFRESH));
    refresh.setText("Reload Scripts");
    refresh.setToolTipText("Reloads the existing scripts.");
    refresh.addActionListener(controller);
    refresh.setActionCommand("" + EditorControl.RELOAD_SCRIPT);
    menu.add(refresh);
    menu.add(new JSeparator());

    Iterator<ScriptObject> i = scripts.iterator();
    ScriptObject so;
    Map<String, ScriptSubMenu> menus = new HashMap<String, ScriptSubMenu>();
    String path;
    ScriptSubMenu subMenu;
    List<ScriptSubMenu> others = new ArrayList<ScriptSubMenu>();
    List<String> formattedName = new ArrayList<String>();
    while (i.hasNext()) {
        so = i.next();
        setScriptIcon(so);
        path = so.getPath();
        subMenu = menus.get(path);
        if (subMenu == null) {
            subMenu = new ScriptSubMenu(path, formattedName);
            //formattedName.add(subMenu.getUnformattedText());
            menus.put(path, subMenu);
            if (so.isOfficialScript())
                menu.add(subMenu);
            else
                others.add(subMenu);
        }
        //if (!ScriptMenuItem.isScriptWithUI(so.getScriptLabel()))
        subMenu.addScript(so).addActionListener(controller);
    }
    if (others.size() > 0) {
        menu.add(new JSeparator());
        JMenu uploadedMenu = new JMenu("User Scripts");
        menu.add(uploadedMenu);
        Iterator<ScriptSubMenu> j = others.iterator();
        while (j.hasNext())
            uploadedMenu.add(j.next());
    }
    return menu;
}

From source file:org.orbisgis.core.ui.plugins.views.geocatalog.Catalog.java

public JPopupMenu getPopup() {
    JPopupMenu popup = new JPopupMenu();
    JComponent[] menus = menuTree.getJMenus();
    for (JComponent menu : menus) {
        popup.add(menu);
    }//from  w  w  w  .  ja v  a2 s.c  om

    if (!tagSources.isEmpty() && lstSources.getSelectedIndices().length > 0) {
        JMenu menu = new JMenu(I18N.getString("orbisgis.org.orbisgis.core.ui.plugins.views.geocatalog.tag"));
        Iterator<String> tagsIterator = tagSources.keySet().iterator();
        while (tagsIterator.hasNext()) {
            String tag = tagsIterator.next();
            JCheckBoxMenuItem item;
            if (isSelectionTagged(tag)) {
                item = new JCheckBoxMenuItem(tag, true);
                RemoveTagActionListener removeTagAL = new RemoveTagActionListener(tag);
                item.addActionListener(removeTagAL);
            } else {
                item = new JCheckBoxMenuItem(tag, false);
                AddTagActionListener addTagAL = new AddTagActionListener(tag);
                item.addActionListener(addTagAL);
            }
            menu.add(item);
        }
        popup.addSeparator();
        popup.add(menu);
    }

    return popup;
}

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

/**
 * Fetch all selected items to make a pop-up menu
 * @return /*  w  w  w .  j av a  2  s .c  om*/
 */
private JPopupMenu makePopupMenu() {
    JPopupMenu menu = new JPopupMenu();
    TreePath[] paths = getSelectionPaths();
    if (paths != null) {
        // Generic action on single TreeNode
        if (paths.length == 1) {
            Object component = paths[0].getLastPathComponent();
            if (component instanceof AbstractTreeNode) {
                AbstractTreeNode aTreeNode = (AbstractTreeNode) component;
                if (aTreeNode.isEditable()) {
                    JMenuItem editMenu = new JMenuItem(I18N.tr("Rename"));
                    editMenu.addActionListener(EventHandler.create(ActionListener.class, this, "onRenameItem"));
                    editMenu.setActionCommand("rename");
                    menu.add(editMenu);
                }
            }
        }
        for (TreePath treePath : paths) {
            Object component = treePath.getLastPathComponent();
            // All nodes
            if (component instanceof MutableTreeNode) {
                MutableTreeNode node = (MutableTreeNode) component;
                for (TreeNodeFileFactory fact : getFactories()) {
                    fact.feedTreeNodePopupMenu(node, menu);
                }
            }
            // Specific nodes
            if (component instanceof PopupTreeNode) {
                PopupTreeNode treeNode = (PopupTreeNode) component;
                treeNode.feedPopupMenu(menu);
            }
        }
    }
    return menu;
}

From source file:org.panbox.desktop.common.gui.PanboxClientGUI.java

private void addDeviceContactShareButtonMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_addDeviceContactShareButtonMousePressed
    final JFrame thisFrame = this;

    JPopupMenu menu = new JPopupMenu();
    JMenuItem addDevice = new JMenuItem(bundle.getString("shareUserList.device"));
    addDevice.addActionListener(new ActionListener() {

        @Override//from w ww. ja va2  s .  co  m
        public void actionPerformed(ActionEvent e) {
            try {
                int selected = shareList.getSelectedIndex();
                PanboxShare share = shareModel.getElementAt(selected);

                if (share instanceof DropboxPanboxShare) {
                    DropboxAdapterFactory dbxFac = (DropboxAdapterFactory) CSPAdapterFactory
                            .getInstance(StorageBackendType.DROPBOX);
                    DropboxAPIIntegration api = (DropboxAPIIntegration) dbxFac.getAPIAdapter();
                    DropboxClientIntegration c = (DropboxClientIntegration) dbxFac.getClientAdapter();
                    if (!c.isClientRunning()) {
                        int ret = JOptionPane.showConfirmDialog(client.getMainWindow(),
                                bundle.getString("PanboxClientGUI.dropboxNotRunningError"),
                                bundle.getString("client.warn"), JOptionPane.YES_NO_OPTION);
                        if (ret == JOptionPane.NO_OPTION) {
                            return;
                        }
                    }

                    if (!api.isOnline()) {
                        int ret = JOptionPane.showConfirmDialog(client.getMainWindow(),
                                bundle.getString("PanboxClientGUI.offlineError"),
                                bundle.getString("client.warn"), JOptionPane.YES_NO_OPTION);
                        if (ret == JOptionPane.NO_OPTION) {
                            return;
                        }
                    }
                }

                if (share != null) {
                    AddDeviceToShareDialog dialog = new AddDeviceToShareDialog(thisFrame, deviceModel,
                            share.getDevices());
                    dialog.setVisible(true);
                    List<PanboxDevice> result = dialog.getResult();

                    if (result.isEmpty()) {
                        logger.debug("PanboxClientGUI : addDevice.addActionListener : Operation aborted!");
                        return;
                    }
                    char[] password = PasswordEnterDialog.invoke(PermissionType.DEVICE);
                    PanboxShare sharenew = null;
                    try {
                        client.showTrayMessage(bundle.getString("PleaseWait"),
                                bundle.getString("tray.addDeviceToShare.waitMessage"), MessageType.INFO);
                        client.getShareWatchService().removeShare(share);
                        for (PanboxDevice dev : result) {
                            DeviceShareParticipant dp = new DeviceShareParticipant(dev);
                            sharenew = client.addPermissionToShare(share, dp, password);
                            ((ShareParticipantListModel) usersList.getModel()).addElement(dp);
                        }
                        if (sharenew != null) {
                            shareModel.setElementAt(sharenew, selected);
                        }
                        client.showTrayMessage(bundle.getString("tray.addDeviceToShare.finishTitle"),
                                bundle.getString("tray.addDeviceToShare.finishMessage"), MessageType.INFO);
                    } catch (ShareDoesNotExistException e1) {
                        logger.error("Share not found!", e1);
                        JOptionPane.showMessageDialog(client.getMainWindow(),
                                bundle.getString("PanboxClient.shareNotFound"),
                                bundle.getString("client.error"), JOptionPane.ERROR_MESSAGE);
                    } catch (ShareManagerException e1) {
                        logger.error("Could not add device to share!", e1);
                        JOptionPane.showMessageDialog(client.getMainWindow(),
                                bundle.getString("PanboxClientGUI.errorWhileAddingDeviceToShare"),
                                bundle.getString("client.error"), JOptionPane.ERROR_MESSAGE);
                    } catch (UnrecoverableKeyException e1) {
                        logger.error("Unable to recover key!", e1);
                        JOptionPane.showMessageDialog(client.getMainWindow(),
                                bundle.getString("PanboxClient.unableToRecoverKeys"),
                                bundle.getString("client.error"), JOptionPane.ERROR_MESSAGE);
                    } catch (ShareMetaDataException e1) {
                        logger.error("Error in share metadata", e1);
                        JOptionPane.showMessageDialog(client.getMainWindow(),
                                bundle.getString("PanboxClientGUI.errorWhileAccessingShareMetadata"),
                                bundle.getString("client.error"), JOptionPane.ERROR_MESSAGE);
                    } finally {
                        Utils.eraseChars(password);
                        PanboxShare tmp = (sharenew != null) ? sharenew : share;
                        client.getShareWatchService().registerShare(tmp);
                        // Also update share list for selected device
                        if (device != null) {
                            deviceShareList.setModel(client.getDeviceShares(device));
                        }
                    }
                }
            } catch (OperationAbortedException ex) {
                System.out.println("Operation aborted!");
            }
        }
    });
    JMenuItem addContact = new JMenuItem(bundle.getString("shareUserList.contact"));
    addContact.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // check if user is share owner
            int selected = shareList.getSelectedIndex();
            if ((selected != -1) && shareModel.getElementAt(selected).isOwner()) {
                boolean hasParticipants = (share.getContacts().size() != 0);
                PanboxShare share = shareModel.getElementAt(selected);

                if (share instanceof DropboxPanboxShare) {
                    DropboxAdapterFactory dbxFac = (DropboxAdapterFactory) CSPAdapterFactory
                            .getInstance(StorageBackendType.DROPBOX);
                    DropboxAPIIntegration api = (DropboxAPIIntegration) dbxFac.getAPIAdapter();
                    DropboxClientIntegration c = (DropboxClientIntegration) dbxFac.getClientAdapter();
                    if (!c.isClientRunning()) {
                        int ret = JOptionPane.showConfirmDialog(client.getMainWindow(),
                                bundle.getString("PanboxClientGUI.dropboxNotRunningError"),
                                bundle.getString("client.warn"), JOptionPane.YES_NO_OPTION);
                        if (ret == JOptionPane.NO_OPTION) {
                            return;
                        }
                    }

                    if (!api.isOnline()) {
                        int ret = JOptionPane.showConfirmDialog(client.getMainWindow(),
                                bundle.getString("PanboxClientGUI.offlineError"),
                                bundle.getString("client.warn"), JOptionPane.YES_NO_OPTION);
                        if (ret == JOptionPane.NO_OPTION) {
                            return;
                        }
                    }
                }

                // AddContactToShareWizard contactWizard;
                // try {
                // contactWizard = new AddContactToShareWizard(thisFrame,
                // client, share, contactModel);
                // } catch (Exception e2) {
                // e2.printStackTrace();
                // return;
                // }
                //
                // contactWizard.setVisible(true);

                AddContactToShareDialog dialog = new AddContactToShareDialog(thisFrame, contactModel,
                        share.getContacts());
                dialog.setVisible(true);

                List<PanboxGUIContact> result;
                try {
                    result = dialog.getResult();
                } catch (OperationAbortedException e2) {
                    logger.debug("PanboxClientGUI : addContact.addActionListener : Operation aborted!");
                    return;
                }

                if (result.isEmpty()) {
                    logger.debug("PanboxClientGUI : addContact.addActionListener : Operation aborted!");
                    return;
                }

                char[] password = PasswordEnterDialog.invoke(PermissionType.USER);
                PanboxShare sharenew = null;
                try {
                    client.showTrayMessage(bundle.getString("PleaseWait"),
                            bundle.getString("tray.addContactToShare.waitMessage"), MessageType.INFO);
                    ArrayList<PanboxGUIContact> reallyAdded = new ArrayList<PanboxGUIContact>();
                    client.getShareWatchService().removeShare(share);
                    for (int i = 0; i < result.size(); i++) {
                        // add permission for user
                        ContactShareParticipant cp = new ContactShareParticipant(result.get(i));
                        if (Settings.getInstance().getExpertMode() && !cp.getContact().isVerified()) {
                            int res = JOptionPane.showConfirmDialog(client.getMainWindow(),
                                    MessageFormat.format(bundle.getString(
                                            "PanboxClientGUI.addUnverifiedContactWarning.text"), cp.getName()),
                                    bundle.getString("PanboxClientGUI.addUnverifiedContactWarning.title"),
                                    JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

                            if (res == JOptionPane.YES_OPTION) {
                                sharenew = client.addPermissionToShare(share, cp, password);
                                logger.info("Added unverified contact " + cp.getName() + " to share.");
                                reallyAdded.add(result.get(i));
                                ((ShareParticipantListModel) usersList.getModel()).addElement(cp);
                            } else if (res == JOptionPane.NO_OPTION) {
                                logger.info("Skipped adding unverified contact " + cp.getName() + " to share.");
                                continue;
                            }
                        } else {
                            sharenew = client.addPermissionToShare(share, cp, password);
                            reallyAdded.add(result.get(i));
                            ((ShareParticipantListModel) usersList.getModel()).addElement(cp);
                        }
                    }
                    if (reallyAdded.size() > 0) {
                        shareModel.setElementAt(sharenew, selected);
                        handleCSPShareParticipantConfiguration(sharenew, hasParticipants, reallyAdded);
                    }
                    client.showTrayMessage(bundle.getString("tray.addContactToShare.finishTitle"),
                            bundle.getString("tray.addContactToShare.finishMessage"), MessageType.INFO);
                } catch (ShareDoesNotExistException e1) {
                    logger.error("Share not found!", e1);
                    JOptionPane.showMessageDialog(client.getMainWindow(),
                            bundle.getString("PanboxClient.shareNotFound"), bundle.getString("client.error"),
                            JOptionPane.ERROR_MESSAGE);
                } catch (ShareManagerException e1) {
                    logger.error("Could not add contact to share!", e1);
                    JOptionPane.showMessageDialog(client.getMainWindow(),
                            bundle.getString("PanboxClientGUI.errorWhileAddingContactToShare"),
                            bundle.getString("client.error"), JOptionPane.ERROR_MESSAGE);
                } catch (UnrecoverableKeyException e1) {
                    logger.error("Unable to recover key!", e1);
                    JOptionPane.showMessageDialog(client.getMainWindow(),
                            bundle.getString("PanboxClient.unableToRecoverKeys"),
                            bundle.getString("client.error"), JOptionPane.ERROR_MESSAGE);
                } catch (ShareMetaDataException e1) {
                    logger.error("Error in share metadata", e1);
                    JOptionPane.showMessageDialog(client.getMainWindow(),
                            bundle.getString("PanboxClientGUI.errorWhileAccessingShareMetadata"),
                            bundle.getString("client.error"), JOptionPane.ERROR_MESSAGE);
                } finally {
                    Utils.eraseChars(password);
                    PanboxShare tmp = (sharenew != null) ? sharenew : share;
                    client.getShareWatchService().registerShare(tmp);
                }
            }

        }
    });
    menu.add(addDevice);
    menu.add(addContact);
    menu.show(addDeviceContactShareButton, evt.getX(), evt.getY());
}

From source file:org.panbox.desktop.common.gui.PanboxClientGUI.java

private void addDeviceButtonMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_addDeviceButtonMousePressed
    JPopupMenu menu = new JPopupMenu();
    JMenuItem bluetooth = new JMenuItem(bundle.getString("PanboxClientGui.bluetooth"));
    bluetooth.addActionListener(new AddDeviceBluetoothActionListener(client, this));
    JMenuItem file = new JMenuItem(bundle.getString("PanboxClientGui.File"));
    file.addActionListener(new AddDeviceFileActionListener(client, this));
    JMenuItem lan = new JMenuItem(bundle.getString("PanboxClientGui.lanandwlan"));
    lan.addActionListener(new AddDeviceNetworkActionListener(client, this));
    menu.add(bluetooth);
    menu.add(file);//from ww  w  .  j av  a 2 s. c om
    menu.add(lan);
    menu.show(addDeviceButton, evt.getX(), evt.getY());
}

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

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