Example usage for javax.swing JMenuItem JMenuItem

List of usage examples for javax.swing JMenuItem JMenuItem

Introduction

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

Prototype

public JMenuItem(Action a) 

Source Link

Document

Creates a menu item whose properties are taken from the specified Action.

Usage

From source file:eu.europa.ec.markt.dss.applet.view.validationpolicy.EditView.java

private void nodeActionAdd(MouseEvent mouseEvent, final int selectedRow, final TreePath selectedPath,
        final XmlDomAdapterNode clickedItem, final JTree tree) {
    final Element clickedElement = (Element) clickedItem.node;
    // popup menu for list -> add
    final JPopupMenu popup = new JPopupMenu();
    //delete node
    final JMenuItem menuItemToDelete = new JMenuItem(ResourceUtils.getI18n("DELETE"));
    menuItemToDelete.addActionListener(new ActionListener() {
        @Override/* w ww.j a  v  a2 s.  c o m*/
        public void actionPerformed(ActionEvent actionEvent) {
            // find the order# of the child to delete
            final int index = clickedItem.getParent().index(clickedItem);

            Node oldChild = clickedElement.getParentNode().removeChild(clickedElement);
            if (index > -1) {
                validationPolicyTreeModel.fireTreeNodesRemoved(selectedPath.getParentPath(), index, oldChild);
            }
        }
    });
    popup.add(menuItemToDelete);

    //Add node/value
    final Map<XsdNode, Object> xsdTree = validationPolicyTreeModel.getXsdTree();
    final List<XsdNode> children = getChildrenToAdd(clickedElement, xsdTree);
    for (final XsdNode xsdChild : children) {
        final String xmlName = xsdChild.getLastNameOfPath();

        final JMenuItem menuItem = new JMenuItem(ResourceUtils.getI18n("ADD") + " (" + xmlName + " "
                + xsdChild.getType().toString().toLowerCase() + ")");
        popup.add(menuItem);
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                Document document = getModel().getValidationPolicy().getDocument();

                final Node newElement;
                if (xsdChild.getType() == XsdNodeType.TEXT) {
                    // TEXT element always appended (last child)
                    newElement = clickedElement.appendChild(document.createTextNode("VALUE"));
                } else if (xsdChild.getType() == XsdNodeType.ATTRIBUTE) {
                    newElement = document.createAttributeNS(null, xmlName);
                    ((Attr) newElement).setValue("VALUE");
                    clickedElement.setAttributeNode((Attr) newElement);
                } else if (xsdChild.getType() == XsdNodeType.ELEMENT) {
                    final Element childToAdd = document
                            .createElementNS("http://dss.markt.ec.europa.eu/validation/diagnostic", xmlName);
                    // find the correct possition to add the child
                    // Get all allowed children
                    Map<XsdNode, Object> childrenMap = getChild(getXPath(clickedElement), xsdTree);
                    boolean toAddSeen = false;
                    Element elementIsToAddBeforeThisOne = null;
                    for (final XsdNode allowed : childrenMap.keySet()) {
                        if (!toAddSeen && allowed == xsdChild) {
                            toAddSeen = true;
                            continue;
                        }
                        if (toAddSeen) {
                            final NodeList elementsByTagNameNS = clickedElement.getElementsByTagNameNS(
                                    "http://dss.markt.ec.europa.eu/validation/diagnostic",
                                    allowed.getLastNameOfPath());
                            if (elementsByTagNameNS.getLength() > 0) {
                                // we found an element that is supposed to be after the one to add
                                elementIsToAddBeforeThisOne = (Element) elementsByTagNameNS.item(0);
                                break;
                            }
                        }
                    }

                    if (elementIsToAddBeforeThisOne != null) {
                        newElement = clickedElement.insertBefore(childToAdd, elementIsToAddBeforeThisOne);
                    } else {
                        newElement = clickedElement.appendChild(childToAdd);
                    }
                } else {
                    throw new IllegalArgumentException("Unknow XsdNode NodeType " + xsdChild.getType());
                }

                document.normalizeDocument();

                int indexOfAddedItem = 0;
                final int childCount = clickedItem.childCount();
                for (int i = 0; i < childCount; i++) {
                    if (clickedItem.child(i).node == newElement) {
                        indexOfAddedItem = i;
                        break;
                    }
                }

                TreeModelEvent event = new TreeModelEvent(validationPolicyTreeModel, selectedPath,
                        new int[] { indexOfAddedItem }, new Object[] { newElement });
                validationPolicyTreeModel.fireTreeNodesInserted(event);
                tree.expandPath(selectedPath);

                //Update model
                getModel().getValidationPolicy().setXmlDom(new XmlDom(document));
            }
        });

    }
    popup.show(tree, mouseEvent.getX(), mouseEvent.getY());
}

From source file:eu.europa.esig.dss.applet.view.validationpolicy.EditView.java

private void nodeActionAdd(MouseEvent mouseEvent, final int selectedRow, final TreePath selectedPath,
        final XmlDomAdapterNode clickedItem, final JTree tree) {
    final Element clickedElement = (Element) clickedItem.node;
    // popup menu for list -> add
    final JPopupMenu popup = new JPopupMenu();
    //delete node
    final JMenuItem menuItemToDelete = new JMenuItem(ResourceUtils.getI18n("DELETE"));
    menuItemToDelete.addActionListener(new ActionListener() {
        @Override//from   ww w  .j  a v  a 2  s.co m
        public void actionPerformed(ActionEvent actionEvent) {
            // find the order# of the child to delete
            final int index = clickedItem.getParent().index(clickedItem);

            Node oldChild = clickedElement.getParentNode().removeChild(clickedElement);
            if (index > -1) {
                validationPolicyTreeModel.fireTreeNodesRemoved(selectedPath.getParentPath(), index, oldChild);
            }
        }
    });
    popup.add(menuItemToDelete);

    //Add node/value
    final Map<XsdNode, Object> xsdTree = validationPolicyTreeModel.getXsdTree();
    final List<XsdNode> children = getChildrenToAdd(clickedElement, xsdTree);
    for (final XsdNode xsdChild : children) {
        final String xmlName = xsdChild.getLastNameOfPath();

        final JMenuItem menuItem = new JMenuItem(ResourceUtils.getI18n("ADD") + " (" + xmlName + " "
                + xsdChild.getType().toString().toLowerCase() + ")");
        popup.add(menuItem);
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                Document document = getModel().getValidationPolicy().getDocument();

                final Node newElement;
                if (xsdChild.getType() == XsdNodeType.TEXT) {
                    // TEXT element always appended (last child)
                    newElement = clickedElement.appendChild(document.createTextNode("VALUE"));
                } else if (xsdChild.getType() == XsdNodeType.ATTRIBUTE) {
                    newElement = document.createAttributeNS(null, xmlName);
                    ((Attr) newElement).setValue("VALUE");
                    clickedElement.setAttributeNode((Attr) newElement);
                } else if (xsdChild.getType() == XsdNodeType.ELEMENT) {
                    final Element childToAdd = document
                            .createElementNS("http://dss.esig.europa.eu/validation/diagnostic", xmlName);
                    // find the correct possition to add the child
                    // Get all allowed children
                    Map<XsdNode, Object> childrenMap = getChild(getXPath(clickedElement), xsdTree);
                    boolean toAddSeen = false;
                    Element elementIsToAddBeforeThisOne = null;
                    for (final XsdNode allowed : childrenMap.keySet()) {
                        if (!toAddSeen && (allowed == xsdChild)) {
                            toAddSeen = true;
                            continue;
                        }
                        if (toAddSeen) {
                            final NodeList elementsByTagNameNS = clickedElement.getElementsByTagNameNS(
                                    "http://dss.esig.europa.eu/validation/diagnostic",
                                    allowed.getLastNameOfPath());
                            if (elementsByTagNameNS.getLength() > 0) {
                                // we found an element that is supposed to be after the one to add
                                elementIsToAddBeforeThisOne = (Element) elementsByTagNameNS.item(0);
                                break;
                            }
                        }
                    }

                    if (elementIsToAddBeforeThisOne != null) {
                        newElement = clickedElement.insertBefore(childToAdd, elementIsToAddBeforeThisOne);
                    } else {
                        newElement = clickedElement.appendChild(childToAdd);
                    }
                } else {
                    throw new IllegalArgumentException("Unknow XsdNode NodeType " + xsdChild.getType());
                }

                document.normalizeDocument();

                int indexOfAddedItem = 0;
                final int childCount = clickedItem.childCount();
                for (int i = 0; i < childCount; i++) {
                    if (clickedItem.child(i).node == newElement) {
                        indexOfAddedItem = i;
                        break;
                    }
                }

                TreeModelEvent event = new TreeModelEvent(validationPolicyTreeModel, selectedPath,
                        new int[] { indexOfAddedItem }, new Object[] { newElement });
                validationPolicyTreeModel.fireTreeNodesInserted(event);
                tree.expandPath(selectedPath);

                //Update model
                getModel().getValidationPolicy().setXmlDom(new XmlDom(document));
            }
        });

    }
    popup.show(tree, mouseEvent.getX(), mouseEvent.getY());
}

From source file:gdt.jgui.entity.webset.JWeblinksPanel.java

/**
 * Get the context menu.//from w  w w . jav  a2 s. c  o  m
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {
    menu = super.getContextMenu();
    int cnt = menu.getItemCount();
    mia = new JMenuItem[cnt];
    for (int i = 0; i < cnt; i++)
        mia[i] = menu.getItem(i);
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            //System.out.println("WeblinkPanel:getConextMenu:menu selected");
            menu.removeAll();
            if (mia != null) {
                for (JMenuItem mi : mia)
                    menu.add(mi);
                menu.addSeparator();
            }
            if (hasSelectedItems()) {
                JMenuItem deleteItem = new JMenuItem("Delete");
                deleteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {

                        int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?",
                                "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                        if (response == JOptionPane.YES_OPTION) {
                            String[] sa = JWeblinksPanel.this.listSelectedItems();
                            if (sa == null)
                                return;
                            String webLinkKey$;
                            Entigrator entigrator = console.getEntigrator(entihome$);
                            Sack entity = entigrator.getEntityAtKey(entityKey$);
                            for (String aSa : sa) {
                                webLinkKey$ = Locator.getProperty(aSa, WEB_LINK_KEY);
                                if (webLinkKey$ == null)
                                    continue;
                                entity.removeElementItem("web", webLinkKey$);
                                entity.removeElementItem("web.login", webLinkKey$);
                                entity.removeElementItem("web.icon", webLinkKey$);
                            }
                            entigrator.save(entity);

                            JConsoleHandler.execute(console, locator$);
                        }
                    }
                });
                menu.add(deleteItem);
                JMenuItem copyItem = new JMenuItem("Copy");
                copyItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        JItemPanel[] ipa = JWeblinksPanel.this.getItems();
                        ArrayList<String> sl = new ArrayList<String>();
                        for (JItemPanel ip : ipa)
                            if (ip.isChecked())
                                sl.add(ip.getLocator());
                        String[] sa = sl.toArray(new String[0]);
                        console.clipboard.clear();
                        for (String aSa : sa)
                            console.clipboard.putString(aSa);
                    }
                });
                menu.add(copyItem);
            }
            JMenuItem newItem = new JMenuItem("New");
            newItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("WeblinksPanel:new:" + locator$);
                    Entigrator entigrator = console.getEntigrator(entihome$);
                    Sack entity = entigrator.getEntityAtKey(entityKey$);
                    if (!entity.existsElement("web"))
                        entity.createElement("web");
                    String webLinkKey$ = Identity.key();
                    entity.putElementItem("web", new Core("Google", webLinkKey$, "http://www.google.com"));
                    if (!entity.existsElement("web.icon"))
                        entity.createElement("web.icon");
                    String icon$ = Support.readHandlerIcon(null, JEntitiesPanel.class, "globe.png");
                    entity.putElementItem("web.icon", new Core(null, webLinkKey$, icon$));
                    entigrator.save(entity);
                    JWeblinkEditor wle = new JWeblinkEditor();
                    String wleLocator$ = wle.getLocator();
                    wleLocator$ = Locator.append(wleLocator$, Entigrator.ENTIHOME, entihome$);
                    wleLocator$ = Locator.append(wleLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                    wleLocator$ = Locator.append(wleLocator$, WEB_LINK_KEY, webLinkKey$);
                    String requesterResponseLocator$ = Locator.compressText(getLocator());
                    wleLocator$ = Locator.append(wleLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR,
                            requesterResponseLocator$);
                    JConsoleHandler.execute(console, wleLocator$);

                }
            });
            menu.add(newItem);
            if (hasItemsToPaste()) {
                JMenuItem pasteItem = new JMenuItem("Paste");
                pasteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        String[] sa = getItemsToPaste();
                        Entigrator entigrator = console.getEntigrator(entihome$);
                        Sack entity = entigrator.getEntityAtKey(entityKey$);
                        if (!entity.existsElement("web"))
                            entity.createElement("web");
                        if (!entity.existsElement("web.icon"))
                            entity.createElement("web.icon");
                        if (!entity.existsElement("web.login"))
                            entity.createElement("web.login");
                        Properties itemLocator;
                        String webLinkKey$;
                        String webLinkUrl$;
                        String webLinkName$;
                        String webLinkIcon$;
                        String webLinkLogin$;
                        String webLinkPassword$;
                        for (String aSa : sa) {
                            itemLocator = Locator.toProperties(aSa);
                            webLinkKey$ = itemLocator.getProperty(WEB_LINK_KEY);
                            webLinkUrl$ = itemLocator.getProperty(WEB_LINK_URL);
                            webLinkName$ = itemLocator.getProperty(WEB_LINK_NAME);
                            webLinkIcon$ = itemLocator.getProperty(Locator.LOCATOR_ICON);
                            webLinkLogin$ = itemLocator.getProperty(WEB_LINK_LOGIN);
                            webLinkPassword$ = itemLocator.getProperty(WEB_LINK_PASSWORD);
                            if (webLinkKey$ == null || webLinkUrl$ == null)
                                continue;
                            entity.putElementItem("web", new Core(webLinkName$, webLinkKey$, webLinkUrl$));
                            if (webLinkLogin$ != null || webLinkPassword$ != null)
                                entity.putElementItem("web.login",
                                        new Core(webLinkLogin$, webLinkKey$, webLinkPassword$));
                            if (webLinkIcon$ != null)
                                entity.putElementItem("web.icon", new Core(null, webLinkKey$, webLinkIcon$));
                        }
                        entigrator.save(entity);
                        JConsoleHandler.execute(console, getLocator());
                    }
                });
                menu.add(pasteItem);
            }
            menu.addSeparator();
            JMenuItem doneItem = new JMenuItem("Done");
            doneItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    if (requesterResponseLocator$ != null) {
                        try {
                            byte[] ba = Base64.decodeBase64(requesterResponseLocator$);
                            String responseLocator$ = new String(ba, "UTF-8");
                            JConsoleHandler.execute(console, responseLocator$);
                        } catch (Exception ee) {
                            Logger.getLogger(JWeblinksPanel.class.getName()).severe(ee.toString());
                        }
                    } else
                        console.back();
                }
            });
            menu.add(doneItem);
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });
    return menu;
}

From source file:com.AandR.beans.plotting.LinePlotPanel.LinePlotPanel.java

private JMenu createLinePropMenu() {
    JMenuItem symMenu = new JMenuItem("Show/Hide Symbols");
    symMenu.setActionCommand(ACTION_SHOW_SYMBOLS);
    symMenu.addActionListener(plotPanelListener);

    JMenuItem lineMenu = new JMenuItem("Show/Hide Lines");
    lineMenu.setActionCommand(ACTION_HIDE_LINES);
    lineMenu.addActionListener(plotPanelListener);

    JMenu menu = new JMenu("Line Properties");
    menu.add(symMenu);/*from w  w w.j  a  va2 s.co  m*/
    menu.add(lineMenu);
    return menu;
}

From source file:me.mayo.telnetkek.MainPanel.java

public final void setupTablePopup() {
    this.tblPlayers.addMouseListener(new MouseAdapter() {
        @Override//from   w w w .j av a2s.  c o  m
        public void mouseReleased(final MouseEvent mouseEvent) {
            final JTable table = MainPanel.this.tblPlayers;

            final int r = table.rowAtPoint(mouseEvent.getPoint());
            if (r >= 0 && r < table.getRowCount()) {
                table.setRowSelectionInterval(r, r);
            } else {
                table.clearSelection();
            }

            final int rowindex = table.getSelectedRow();
            if (rowindex < 0) {
                return;
            }

            if ((SwingUtilities.isRightMouseButton(mouseEvent) || mouseEvent.isControlDown())
                    && mouseEvent.getComponent() instanceof JTable) {
                final PlayerInfo player = getSelectedPlayer();
                if (player != null) {
                    final JPopupMenu popup = new JPopupMenu(player.getName());

                    final JMenuItem header = new JMenuItem("Apply action to " + player.getName() + ":");
                    header.setEnabled(false);
                    popup.add(header);

                    popup.addSeparator();

                    final ActionListener popupAction = (ActionEvent actionEvent) -> {
                        Object _source = actionEvent.getSource();
                        if (_source instanceof PlayerListPopupItem_Command) {
                            final PlayerListPopupItem_Command source = (PlayerListPopupItem_Command) _source;
                            final String output = source.getCommand().buildOutput(source.getPlayer(), true);
                            MainPanel.this.getConnectionManager().sendDelayedCommand(output, true, 100);
                        } else if (_source instanceof PlayerListPopupItem) {
                            final PlayerListPopupItem source = (PlayerListPopupItem) _source;

                            final PlayerInfo _player = source.getPlayer();

                            switch (actionEvent.getActionCommand()) {
                            case "Copy IP": {
                                copyToClipboard(_player.getIp());
                                MainPanel.this.writeToConsole(
                                        new ConsoleMessage("Copied IP to clipboard: " + _player.getIp()));
                                break;
                            }
                            case "Copy Name": {
                                copyToClipboard(_player.getName());
                                MainPanel.this.writeToConsole(
                                        new ConsoleMessage("Copied name to clipboard: " + _player.getName()));
                                break;
                            }
                            case "Copy UUID": {
                                copyToClipboard(_player.getUuid());
                                MainPanel.this.writeToConsole(
                                        new ConsoleMessage("Copied UUID to clipboard: " + _player.getUuid()));
                                break;
                            }
                            }
                        }
                    };

                    TelnetKek.config.getCommands().stream().map(
                            (command) -> new PlayerListPopupItem_Command(command.getName(), player, command))
                            .map((item) -> {
                                item.addActionListener(popupAction);
                                return item;
                            }).forEach((item) -> {
                                popup.add(item);
                            });

                    popup.addSeparator();

                    JMenuItem item;

                    item = new PlayerListPopupItem("Copy Name", player);
                    item.addActionListener(popupAction);
                    popup.add(item);

                    item = new PlayerListPopupItem("Copy IP", player);
                    item.addActionListener(popupAction);
                    popup.add(item);

                    item = new PlayerListPopupItem("Copy UUID", player);
                    item.addActionListener(popupAction);
                    popup.add(item);

                    popup.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
                }
            }
        }
    });
}

From source file:gdt.jgui.tool.JEntityEditor.java

/**
 * Get the context menu./*from  w w w.j a  v a2s .  com*/
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {
    menu = new JMenu("Context");
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            //         System.out.println("EntityEditor:getConextMenu:menu selected");

            if (editCellItem != null)
                menu.remove(editCellItem);
            if (deleteItemsItem != null)
                menu.remove(deleteItemsItem);
            if (copyItem != null)
                menu.remove(copyItem);
            if (pasteItem != null)
                menu.remove(pasteItem);
            if (cutItem != null)
                menu.remove(cutItem);
            if (hasEditingCell()) {
                //menu.addSeparator();
                editCellItem = new JMenuItem("Edit item");
                editCellItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        String locator$ = getEditCellLocator();
                        if (locator$ != null)
                            JConsoleHandler.execute(console, locator$);
                    }
                });
                menu.add(editCellItem);
            }
            if (hasSelectedRows()) {
                deleteItemsItem = new JMenuItem("Delete items");
                deleteItemsItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        int response = JOptionPane.showConfirmDialog(JEntityEditor.this,
                                "Delete selected items ?", "Confirm", JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE);
                        if (response == JOptionPane.YES_OPTION) {
                            deleteRows();
                        }
                    }
                });
                menu.add(deleteItemsItem);
                copyItem = new JMenuItem("Copy");
                copyItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        element$ = null;
                        content = getContent(true);
                    }
                });
                menu.add(copyItem);
                cutItem = new JMenuItem("Cut");
                cutItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        int i = tabbedPane.getSelectedIndex();
                        element$ = tabbedPane.getTitleAt(i);
                        content = getContent(true);
                    }
                });
                menu.add(cutItem);
            }
            if (content != null) {
                pasteItem = new JMenuItem("Paste");
                pasteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        pasteTable(content);
                        int j = tabbedPane.getSelectedIndex();
                        if (element$ != null) {
                            int cnt = tabbedPane.getComponentCount();
                            for (int i = 0; i < cnt; i++) {
                                if (element$.equals(tabbedPane.getTitleAt(i))) {
                                    tabbedPane.setSelectedIndex(i);
                                    cutTable(content);
                                    tabbedPane.setSelectedIndex(j);
                                }
                            }
                        }
                    }
                });
                menu.add(pasteItem);
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });

    JMenuItem doneItem = new JMenuItem("Done");
    doneItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            save();
            console.back();

        }
    });
    menu.add(doneItem);
    JMenuItem cancelItem = new JMenuItem("Cancel");
    cancelItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            console.back();
        }
    });
    menu.add(cancelItem);
    menu.addSeparator();
    JMenuItem addItemItem = new JMenuItem("Add item");
    addItemItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            addRow();
        }
    });
    menu.add(addItemItem);
    JMenuItem addElementItem = new JMenuItem("Add element");
    addElementItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String element$ = "new element";
            //addElement(element$);
            String locator$ = getRenameElementLocator(element$);
            JConsoleHandler.execute(console, locator$);
        }
    });
    menu.add(addElementItem);
    JMenuItem deleteElementItem = new JMenuItem("Delete element");
    deleteElementItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int response = JOptionPane.showConfirmDialog(JEntityEditor.this, "Delete element ?", "Confirm",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (response == JOptionPane.YES_OPTION) {
                tabbedPane.remove(tabbedPane.getSelectedComponent());
            }
        }
    });
    menu.add(deleteElementItem);
    JMenuItem renameElementItem = new JMenuItem("Rename element");
    renameElementItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int i = tabbedPane.getSelectedIndex();
            String locator$ = getRenameElementLocator(tabbedPane.getTitleAt(i));
            JConsoleHandler.execute(console, locator$);
        }
    });
    menu.add(renameElementItem);
    menu.addSeparator();
    if (hasEditingCell()) {
        editCellItem = new JMenuItem("Edit item");
        editCellItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String locator$ = getEditCellLocator();
                if (locator$ != null)
                    JConsoleHandler.execute(console, locator$);
            }
        });
        menu.add(editCellItem);
    }
    return menu;
}

From source file:net.sf.xmm.moviemanager.gui.DialogIMDbMultiAdd.java

/**
 * Not yet fully implemented/*from ww w.j  a va 2 s  . c  o m*/
 * @param e
 */
void handleFileLocationPopup(MouseEvent e) {

    if (!GUIUtil.isRightMouseButton(e))
        return;

    JPopupMenu fileLocationPopup = new JPopupMenu();
    JMenuItem fileLocationItem = new JMenuItem("Open content folder");
    fileLocationPopup.add(fileLocationItem);

    fileLocationPopup.show(fileLocation, e.getX(), e.getY());
}

From source file:gui.DownloadPanel.java

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

    openItem = new JMenuItem(bundle.getString("downloadPanel.openItem.name"));
    openItem.addActionListener(this);
    openFolderItem = new JMenuItem(bundle.getString("downloadPanel.openFolderItem.name"));
    openFolderItem.addActionListener(this);

    resumeItem = new JMenuItem(bundle.getString("downloadPanel.resumeItem.name"));
    resumeItem.addActionListener(this);
    pauseItem = new JMenuItem(bundle.getString("downloadPanel.pauseItem.name"));
    pauseItem.addActionListener(this);
    clearItem = new JMenuItem(bundle.getString("downloadPanel.clearItem.name"));
    clearItem.addActionListener(this);

    reJoinItem = new JMenuItem(bundle.getString("downloadPanel.reJoinItem.name"));
    reJoinItem.addActionListener(this);
    reDownloadItem = new JMenuItem(bundle.getString("downloadPanel.reDownloadItem.name"));
    reDownloadItem.addActionListener(this);

    moveToQueueItem = new JMenuItem(bundle.getString("downloadPanel.moveToQueueItem.name"));
    moveToQueueItem.addActionListener(this);
    removeFromQueueItem = new JMenuItem(bundle.getString("downloadPanel.removeFromQueueItem.name"));
    removeFromQueueItem.addActionListener(this);

    propertiesItem = new JMenuItem(bundle.getString("downloadPanel.propertiesItem.name"));
    propertiesItem.addActionListener(this);

    popupMenu.add(openItem);//from  w  w  w. j  a v a  2s. co m
    popupMenu.add(openFolderItem);
    popupMenu.add(new JPopupMenu.Separator());
    popupMenu.add(resumeItem);
    popupMenu.add(pauseItem);
    popupMenu.add(clearItem);
    popupMenu.add(new JPopupMenu.Separator());
    popupMenu.add(reJoinItem);
    popupMenu.add(reDownloadItem);
    popupMenu.add(new JPopupMenu.Separator());
    popupMenu.add(moveToQueueItem);
    popupMenu.add(removeFromQueueItem);
    popupMenu.add(new JPopupMenu.Separator());
    popupMenu.add(propertiesItem);

    setStateOfMenuItems();

    return popupMenu;
}

From source file:br.org.acessobrasil.ases.ferramentas_de_reparo.vista.script.PainelScript.java

private void initComponentsEscalavel(ArrayList<FerramentaDescricaoModel> erros) {
    Ferramenta_Scripts.carregaTexto(TokenLang.LANG);
    JPanel regraFonteBtn = new JPanel();
    regraFonteBtn.setLayout(new BorderLayout());

    textAreaSourceCode = new G_TextAreaSourceCode();
    textAreaSourceCode.setTipoHTML();/*w w  w  . j a va2 s . com*/
    new OnChange(textAreaSourceCode, this);
    tableLinCod = new TabelaDescricao(erros);
    arTextPainelCorrecao = new ArTextPainelCorrecao();
    salvar = new JButton();
    abrir = new JButton();
    cancelar = new JButton();
    strConteudoalt = new String();
    btnSalvar = new JMenuItem("Salvar");
    salvar.setEnabled(false);
    salvaAlteracoes = TxtBuffer.getInstanciaSalvaAlteracoes(textAreaSourceCode.getTextPane(), salvar,
            new JMenuItem(), parentFrame);

    pnRegra = new JPanel();
    lbRegras1 = new JLabel();
    lbRegras2 = new JLabel();
    pnSetaDescricao = new JPanel();
    new JScrollPane();
    tArParticipRotulo = new TArParticipRotulo();
    conteudoDoAlt = new JTextArea();
    pnListaErros = new JPanel();
    scrollPanetabLinCod = new JScrollPane();
    pnBotoes = new JPanel();
    new JButton();
    aplicar = new JButton();
    conteudoParticRotulo = new ArrayList<String>();
    setBackground(CoresDefault.getCorPaineis());
    Container contentPane = this;// ??
    contentPane.setLayout(new GridLayout(2, 1));
    {
        pnRegra.setBorder(criaBorda(Ferramenta_Scripts.TITULO_REGRA));
        pnRegra.setLayout(new GridLayout(2, 1));
        pnRegra.add(lbRegras1);
        lbRegras1.setText(Ferramenta_Scripts.REGRAP1);
        lbRegras2.setText(Ferramenta_Scripts.REGRAP2);
        lbRegras1.setHorizontalAlignment(SwingConstants.CENTER);

        lbRegras2.setHorizontalAlignment(SwingConstants.CENTER);
        pnRegra.add(lbRegras1);
        pnRegra.add(lbRegras2);
        pnRegra.setPreferredSize(new Dimension(700, 60));
    }
    // ---- Salvar ----
    salvar.setText(Ferramenta_Scripts.BTN_SALVAR);
    salvar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            salvarActionPerformed(e);
        }
    });

    salvar.setToolTipText(Ferramenta_Scripts.DICA_SALVAR);
    salvar.getAccessibleContext().setAccessibleDescription(Ferramenta_Scripts.DICA_SALVAR);
    salvar.getAccessibleContext().setAccessibleName(Ferramenta_Scripts.DICA_SALVAR);
    salvar.setBounds(10, 0, 150, 25);

    abrir.setText(Ferramenta_Scripts.BTN_ABRIR);
    abrir.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AbrirActionPerformed(e);
        }
    });

    abrir.setToolTipText(Ferramenta_Scripts.DICA_ABRIR);
    abrir.getAccessibleContext().setAccessibleDescription(Ferramenta_Scripts.DICA_ABRIR_HTML);
    abrir.getAccessibleContext().setAccessibleName(Ferramenta_Scripts.DICA_ABRIR_HTML);
    abrir.setBounds(165, 0, 150, 25);

    cancelar.setText(Ferramenta_Imagens.TELA_ANTERIOR);
    cancelar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            CancelarActionPerformed(e);
        }
    });

    cancelar.setToolTipText(Ferramenta_Imagens.DICA_TELA_ANTERIOR);
    cancelar.getAccessibleContext().setAccessibleDescription(Ferramenta_Imagens.DICA_TELA_ANTERIOR);
    cancelar.getAccessibleContext().setAccessibleName(Ferramenta_Imagens.DICA_TELA_ANTERIOR);
    cancelar.setBounds(320, 0, 150, 25);
    GridBagConstraints cons = new GridBagConstraints();

    cons.fill = GridBagConstraints.BOTH;
    cons.weighty = 1;

    pnSetaDescricao.setLayout(new BorderLayout());
    cons.anchor = GridBagConstraints.WEST;
    cons.insets = new Insets(0, 0, 0, 0);
    JScrollPane sp = new JScrollPane();
    sp.setBorder(criaBorda(Ferramenta_Scripts.CONTEUDO_ALTER));
    sp.setViewportView(conteudoDoAlt);
    sp.setPreferredSize(new Dimension(500, 300));
    pnSetaDescricao.setPreferredSize(new Dimension(400, 60));
    pnListaErros.setBorder(criaBorda(Ferramenta_Scripts.LISTA_ERROS));
    pnListaErros.setLayout(new BorderLayout());
    scrollPanetabLinCod.setViewportView(tableLinCod);
    pnListaErros.add(scrollPanetabLinCod, BorderLayout.CENTER);
    {
        pnBotoes.setLayout(null);
        aplicar.setEnabled(false);
        aplicar.setText(Ferramenta_Scripts.BTN_APLICAR);
        aplicar.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                aplicarRotuloActionPerformed(e);
            }
        });

        aplicar.setToolTipText(Ferramenta_Scripts.DICA_APLICAR);
        aplicar.getAccessibleContext().setAccessibleDescription(Ferramenta_Scripts.DICA_APLICAR);
        aplicar.getAccessibleContext().setAccessibleName(Ferramenta_Scripts.DICA_APLICAR);
        aplicar.setBounds(3, 3, 120, 30);
        pnBotoes.add(aplicar);
    }

    /*
     * Colocar os controles
     */
    pnRegra.setBackground(CoresDefault.getCorPaineis());
    regraFonteBtn.add(pnRegra, BorderLayout.NORTH);
    textAreaSourceCode.setBorder(criaBorda(""));
    textAreaSourceCode.setBackground(CoresDefault.getCorPaineis());

    JSplitPane splitPane = null;

    Dimension minimumSize = new Dimension(0, 0);
    sp.setMinimumSize(minimumSize);
    sp.setPreferredSize(new Dimension(150, 90));
    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sp, textAreaSourceCode);
    splitPane.setOneTouchExpandable(true);
    int w = parentFrame.getWidth();
    int s = w / 4;
    splitPane.setDividerLocation(s);
    regraFonteBtn.add(splitPane, BorderLayout.CENTER);
    pnBotoes.setPreferredSize(new Dimension(600, 35));
    pnBotoes.setBackground(CoresDefault.getCorPaineis());
    regraFonteBtn.setBackground(CoresDefault.getCorPaineis());
    contentPane.add(regraFonteBtn);

    JPanel textoErrosBtn = new JPanel();
    textoErrosBtn.setLayout(new BorderLayout());
    pnSetaDescricao.setBackground(CoresDefault.getCorPaineis());
    pnSetaDescricao.add(pnBotoes, BorderLayout.WEST);
    textoErrosBtn.add(pnSetaDescricao, BorderLayout.NORTH);

    textoErrosBtn.add(pnListaErros, BorderLayout.CENTER);
    JPanel pnSalvarCancelar = new JPanel();
    pnSalvarCancelar.setLayout(null);
    pnSalvarCancelar.setPreferredSize(new Dimension(600, 35));
    pnSalvarCancelar.add(salvar);
    pnSalvarCancelar.add(abrir);
    pnSalvarCancelar.add(cancelar);
    if (!original) {
        reverter = new JButton("Reverter");
        reverter.setText(TradPainelRelatorio.REVERTER);
        reverter.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                setVisible(false);
                TxtBuffer.setContent(TxtBuffer.getContentOriginal());
                parentFrame.showPainelFerramentaScriptPArq(TxtBuffer.getContentOriginal());
                setVisible(true);
            }

        });
        reverter.setToolTipText(TradPainelRelatorio.DICA_REVERTER);
        reverter.getAccessibleContext().setAccessibleDescription(TradPainelRelatorio.DICA_REVERTER);
        reverter.getAccessibleContext().setAccessibleName(TradPainelRelatorio.DICA_REVERTER);
        reverter.setBounds(485, 0, 150, 25);
        pnSalvarCancelar.add(reverter);
    }
    pnSalvarCancelar.setBackground(CoresDefault.getCorPaineis());
    textoErrosBtn.add(pnSalvarCancelar, BorderLayout.SOUTH);
    pnListaErros.setBackground(CoresDefault.getCorPaineis());
    if (tableLinCod.getRowCount() == 0)
        tableLinCod.addLinha(0, 0, GERAL.DOC_SEM_ERROS);
    contentPane.setBackground(CoresDefault.getCorPaineis());
    contentPane.add(textoErrosBtn);
    this.setVisible(true);
}

From source file:cz.muni.fi.javaseminar.kafa.bookregister.gui.MainWindow.java

private void initAuthorsTable() {
    authorsTable.getColumnModel().getColumn(2)
            .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy")));
    authorsTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() {

        @Override/*from   w  w  w .  j a  v a2  s .  co m*/
        public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected,
                boolean hasFocus, int row, int column) {

            if (value instanceof Date) {

                // You could use SimpleDateFormatter instead
                value = new SimpleDateFormat("dd. MM. yyyy").format(value);

            }

            return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column);

        }
    });

    authorsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    ListSelectionModel selectionModel = authorsTable.getSelectionModel();
    selectionModel.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            DefaultListSelectionModel source = (DefaultListSelectionModel) e.getSource();
            if (source.getMinSelectionIndex() >= 0) {
                authorsTableModel.setCurrentSlectedIndex(source.getMinSelectionIndex());
            }

            if (!e.getValueIsAdjusting()) {
                booksTableModel.setAuthorIndex(source.getMinSelectionIndex());
            }

        }
    });

    authorsTable.getColumnModel().getColumn(2)
            .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy")));
    authorsTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected,
                boolean hasFocus, int row, int column) {

            if (value instanceof Date) {

                // You could use SimpleDateFormatter instead
                value = new SimpleDateFormat("dd. MM. yyyy").format(value);

            }

            return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column);

        }
    });

    JPopupMenu authorsPopupMenu = new JPopupMenu();
    JMenuItem deleteItem = new JMenuItem("Delete");

    authorsPopupMenu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    int rowAtPoint = authorsTable.rowAtPoint(
                            SwingUtilities.convertPoint(authorsPopupMenu, new Point(0, 0), authorsTable));
                    if (rowAtPoint > -1) {
                        authorsTable.setRowSelectionInterval(rowAtPoint, rowAtPoint);
                        authorsTableModel.setCurrentSlectedIndex(rowAtPoint);
                    }
                }
            });
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // TODO Auto-generated method stub

        }
    });
    deleteItem.addActionListener(new ActionListener() {
        private Author author;

        @Override
        public void actionPerformed(ActionEvent e) {
            new SwingWorker<Void, Void>() {

                @Override
                protected Void doInBackground() throws Exception {
                    author = authorsTableModel.getAuthors().get(authorsTable.getSelectedRow());
                    log.debug("Deleting author: " + author.getFirstname() + " " + author.getSurname()
                            + " from database.");
                    authorManager.deleteAuthor(author);

                    return null;
                }

                @Override
                protected void done() {
                    try {
                        get();
                    } catch (InterruptedException | ExecutionException e) {
                        if (e.getCause() instanceof DataIntegrityViolationException) {
                            JOptionPane.showMessageDialog(MainWindow.this,
                                    "Couldn't delete author; there are still some books assigned to him.",
                                    "Error", JOptionPane.ERROR_MESSAGE);
                        }
                        log.error("There was an exception thrown during deletion author: "
                                + author.getFirstname() + " " + author.getSurname(), e);

                        return;
                    }

                    updateModel();
                }
            }.execute();
        }
    });
    authorsPopupMenu.add(deleteItem);
    authorsTable.setComponentPopupMenu(authorsPopupMenu);
}