Example usage for javax.swing JMenuItem addActionListener

List of usage examples for javax.swing JMenuItem addActionListener

Introduction

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

Prototype

public void addActionListener(ActionListener l) 

Source Link

Document

Adds an ActionListener to the button.

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//from w ww  . j ava2 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:MenuDemo.java

protected JMenuBar createMenuBar() {
    final JMenuBar menuBar = new JMenuBar();

    JMenu menuFile = new JMenu("File");
    menuFile.setMnemonic('f');

    JMenuItem menuItem = new JMenuItem("New");
    menuItem.setIcon(new ImageIcon("file_new.gif"));
    menuItem.setMnemonic('n');
    ActionListener lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("New");
        }// ww  w  . ja v  a2s .  c o  m
    };
    menuItem.addActionListener(lst);
    menuFile.add(menuItem);

    menuItem = new JMenuItem("Open...");
    menuItem.setIcon(new ImageIcon("file_open.gif"));
    menuItem.setMnemonic('o');
    lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            MenuDemo.this.repaint();
            if (fileChooser.showOpenDialog(MenuDemo.this) != JFileChooser.APPROVE_OPTION)
                return;
            System.out.println(fileChooser.getSelectedFile());
        }
    };
    menuItem.addActionListener(lst);
    menuFile.add(menuItem);

    menuItem = new JMenuItem("Save...");
    menuItem.setIcon(new ImageIcon("file_save.gif"));
    menuItem.setMnemonic('s');
    lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Save...");
        }
    };
    menuItem.addActionListener(lst);
    menuFile.add(menuItem);

    menuFile.addSeparator();

    menuItem = new JMenuItem("Exit");
    menuItem.setMnemonic('x');
    lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    };
    menuItem.addActionListener(lst);
    menuFile.add(menuItem);
    menuBar.add(menuFile);

    ActionListener fontListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateMonitor();
        }
    };

    JMenu mFont = new JMenu("Font");
    mFont.setMnemonic('o');

    ButtonGroup group = new ButtonGroup();
    menus = new JMenuItem[FontNames.length];
    for (int i = 0; i < FontNames.length; i++) {
        int m = i + 1;
        menus[i] = new JRadioButtonMenuItem(m + " " + FontNames[i]);
        boolean selected = (i == 0);
        menus[i].setSelected(selected);
        menus[i].setMnemonic('1' + i);
        menus[i].setFont(fontArray[i]);
        menus[i].addActionListener(fontListener);
        group.add(menus[i]);
        mFont.add(menus[i]);
    }

    mFont.addSeparator();

    boldMenuItem = new JCheckBoxMenuItem("Bold");
    boldMenuItem.setMnemonic('b');
    Font fn = fontArray[1].deriveFont(Font.BOLD);
    boldMenuItem.setFont(fn);
    boldMenuItem.setSelected(false);
    boldMenuItem.addActionListener(fontListener);
    mFont.add(boldMenuItem);

    italicMenuItem = new JCheckBoxMenuItem("Italic");
    italicMenuItem.setMnemonic('i');
    fn = fontArray[1].deriveFont(Font.ITALIC);
    italicMenuItem.setFont(fn);
    italicMenuItem.setSelected(false);
    italicMenuItem.addActionListener(fontListener);
    mFont.add(italicMenuItem);

    menuBar.add(mFont);

    return menuBar;
}

From source file:be.fedict.eid.tsl.tool.TslTool.java

private JMenuItem addActionMenuItem(String text, int mnemonic, String actionCommand, JMenu menu,
        boolean enabled) {
    JMenuItem menuItem = new JMenuItem(text);
    menuItem.setMnemonic(mnemonic);/*from  ww w.j a v  a 2 s .c o m*/
    menuItem.setActionCommand(actionCommand);
    menuItem.addActionListener(this);
    menuItem.setEnabled(enabled);
    menu.add(menuItem);
    return menuItem;
}

From source file:edu.harvard.mcz.imagecapture.BulkMediaFrame.java

private void init() {
    thisFrame = this;
    setTitle("BulkMedia Preparation");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 902, 174);/* w ww. j av a  2 s .  c om*/

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu mnFile = new JMenu("File");
    mnFile.setMnemonic(KeyEvent.VK_F);
    menuBar.add(mnFile);

    JMenuItem mntmPrepareDirectory = new JMenuItem("Prepare Directory");
    mntmPrepareDirectory.setMnemonic(KeyEvent.VK_D);
    mntmPrepareDirectory.addActionListener(new PrepareDirectoryAction());
    mnFile.add(mntmPrepareDirectory);

    JMenuItem mntmNewMenuItem = new JMenuItem("Exit");
    mntmNewMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            done();
        }
    });

    JMenuItem mntmNewMenuItem_1 = new JMenuItem("Edit Properties");
    mntmNewMenuItem_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            PropertiesEditor p = new PropertiesEditor();
            p.pack();
            p.setVisible(true);
        }
    });
    mnFile.add(mntmNewMenuItem_1);
    mntmNewMenuItem.setMnemonic(KeyEvent.VK_X);
    mntmNewMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
    mnFile.add(mntmNewMenuItem);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(new BorderLayout(0, 0));

    JPanel panel = new JPanel();
    contentPane.add(panel, BorderLayout.CENTER);
    panel.setLayout(new GridLayout(3, 2, 0, 0));

    JLabel lblBaseUri = new JLabel("Base URI (first part of path to images on the web)");
    lblBaseUri.setHorizontalAlignment(SwingConstants.TRAILING);
    panel.add(lblBaseUri, "2, 2");

    textField = new JTextField();
    textField.setEditable(false);
    textField.setText(Singleton.getSingletonInstance().getProperties().getProperties()
            .getProperty(ImageCaptureProperties.KEY_IMAGEBASEURI));
    panel.add(textField);
    textField.setColumns(10);

    JLabel lblNewLabel = new JLabel("Local Path To Base (local mount path that maps to base URI)");
    lblNewLabel.setHorizontalAlignment(SwingConstants.TRAILING);
    panel.add(lblNewLabel);

    textField_1 = new JTextField();
    textField_1.setEditable(false);
    textField_1.setText(Singleton.getSingletonInstance().getProperties().getProperties()
            .getProperty(ImageCaptureProperties.KEY_IMAGEBASE));
    panel.add(textField_1);
    textField_1.setColumns(10);

    JLabel lblBeforeExitingWait = new JLabel(
            "Before exiting wait for both the Done and Thumbnails Built messages.");
    panel.add(lblBeforeExitingWait);

    JLabel lblThumbnailGenerationIs = new JLabel("Thumbnail generation is not reported on the progress bar.");
    panel.add(lblThumbnailGenerationIs);

    progressBar = new JProgressBar();
    progressBar.setStringPainted(false);
    contentPane.add(progressBar, BorderLayout.NORTH);

    JPanel panel_1 = new JPanel();
    contentPane.add(panel_1, BorderLayout.SOUTH);

    JButton btnPrepareDirectory = new JButton("Run");
    btnPrepareDirectory.setToolTipText("Select a directory and prepare a bulk media file for images therein.");
    panel_1.add(btnPrepareDirectory);
    btnPrepareDirectory.addActionListener(new PrepareDirectoryAction());
    btnPrepareDirectory.setPreferredSize(new Dimension(80, 25));

    JButton btnExit = new JButton("Exit");
    btnExit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            done();
        }
    });
    panel_1.add(btnExit);
}

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  www. j  a  va  2s  .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.JEntityFacetPanel.java

/**
 *Get the context menu.//  w ww  .  j a v a  2s . c  om
 *@return the context menu.
 */
@Override
public JMenu getContextMenu() {
    menu = super.getContextMenu();
    menu.addSeparator();
    JMenuItem showStructure = new JMenuItem("Structure");
    showStructure.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String locator$ = getLocator();
            JEntityStructurePanel esp = new JEntityStructurePanel();
            esp.instantiate(console, locator$);
            String espLocator$ = esp.getLocator();
            espLocator$ = Locator.append(espLocator$, Entigrator.ENTIHOME, entihome$);
            espLocator$ = Locator.append(espLocator$, EntityHandler.ENTITY_KEY, entityKey$);
            JConsoleHandler.execute(console, espLocator$);
        }
    });
    menu.add(showStructure);
    JMenuItem showDigest = new JMenuItem("Digest");
    showDigest.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String locator$ = getLocator();
            JEntityDigestDisplay edd = new JEntityDigestDisplay();
            edd.instantiate(console, locator$);
            String eddLocator$ = edd.getLocator();
            eddLocator$ = Locator.append(eddLocator$, Entigrator.ENTIHOME, entihome$);
            eddLocator$ = Locator.append(eddLocator$, EntityHandler.ENTITY_KEY, entityKey$);
            JConsoleHandler.execute(console, eddLocator$);
        }
    });
    menu.add(showDigest);
    menu.addSeparator();
    addFacets = new JMenuItem("Add facets");
    addFacets.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String locator$ = getLocator();
            JEntityAddFacets addFacets = new JEntityAddFacets();
            addFacets.instantiate(console, locator$);
            String facetSelector$ = addFacets.getLocator();
            facetSelector$ = Locator.append(facetSelector$, Entigrator.ENTIHOME, entihome$);
            facetSelector$ = Locator.append(facetSelector$, EntityHandler.ENTITY_KEY, entityKey$);
            JConsoleHandler.execute(console, facetSelector$);
        }
    });
    menu.add(addFacets);
    JMenuItem doneItem = new JMenuItem("Done");
    doneItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String locator$ = getLocator();
            String requesterResponseLocator$ = Locator.getProperty(locator$,
                    JRequester.REQUESTER_RESPONSE_LOCATOR);
            if (requesterResponseLocator$ == null)
                console.back();
            else {
                try {
                    byte[] ba = Base64.decodeBase64(requesterResponseLocator$);
                    String responseLocator$ = new String(ba, "UTF-8");
                    //                         System.out.println("EntityfacetPanel:done:response locator="+responseLocator$);
                    JConsoleHandler.execute(console, responseLocator$);
                } catch (Exception ee) {
                    LOGGER.info(ee.toString());
                }
            }
        }
    });
    menu.add(doneItem);
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            //System.out.println("EntityEditor:getConextMenu:menu selected");
            if (removeFacets != null)
                menu.remove(removeFacets);
            if (copyFacets != null)
                menu.remove(copyFacets);
            if (hasSelectedItems()) {
                copyFacets = new JMenuItem("Copy facets");
                copyFacets.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        copyFacets();
                    }
                });
                menu.add(copyFacets);
            }
            if (hasSelectedRemovableFacets()) {
                removeFacets = new JMenuItem("Remove facets");
                removeFacets.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        removeFacets();
                    }
                });
                menu.add(removeFacets);
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

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

From source file:javazoom.jlgui.player.amp.equalizer.ui.EqualizerUI.java

public void loadUI() {
    log.info("Load EqualizerUI (EDT=" + SwingUtilities.isEventDispatchThread() + ")");
    removeAll();/*from w w  w  .j  a va2s  .  c  o m*/
    // Background
    ImageBorder border = new ImageBorder();
    border.setImage(ui.getEqualizerImage());
    setBorder(border);
    // On/Off
    add(ui.getAcEqOnOff(), ui.getAcEqOnOff().getConstraints());
    ui.getAcEqOnOff().removeActionListener(this);
    ui.getAcEqOnOff().addActionListener(this);
    // Auto
    add(ui.getAcEqAuto(), ui.getAcEqAuto().getConstraints());
    ui.getAcEqAuto().removeActionListener(this);
    ui.getAcEqAuto().addActionListener(this);
    // Sliders
    add(ui.getAcEqPresets(), ui.getAcEqPresets().getConstraints());
    for (int i = 0; i < ui.getAcEqSliders().length; i++) {
        add(ui.getAcEqSliders()[i], ui.getAcEqSliders()[i].getConstraints());
        ui.getAcEqSliders()[i].setValue(maxGain - gainValue[i]);
        ui.getAcEqSliders()[i].removeChangeListener(this);
        ui.getAcEqSliders()[i].addChangeListener(this);
    }
    if (ui.getSpline() != null) {
        ui.getSpline().setValues(gainValue);
        add(ui.getSpline(), ui.getSpline().getConstraints());
    }
    // Popup menu on TitleBar
    mainpopup = new JPopupMenu();
    String[] presets = { "Normal", "Classical", "Club", "Dance", "Full Bass", "Full Bass & Treble",
            "Full Treble", "Laptop", "Live", "Party", "Pop", "Reggae", "Rock", "Techno" };
    JMenuItem mi;
    for (int p = 0; p < presets.length; p++) {
        mi = new JMenuItem(presets[p]);
        mi.removeActionListener(this);
        mi.addActionListener(this);
        mainpopup.add(mi);
    }
    ui.getAcEqPresets().removeActionListener(this);
    ui.getAcEqPresets().addActionListener(this);
    validate();
}

From source file:JXButtonPanel.java

public JXButtonPanelDemo() {
    super("JXButtonPanel demo");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setResizable(false);//from w  w w  .j a  v  a2 s  . c  o  m
    JPanel topPanel = new JPanel(new GridLayout(1, 0));

    final JXButtonPanel radioGroupPanel = createRadioJXButtonPanel();
    topPanel.add(radioGroupPanel);

    final JXButtonPanel checkBoxPanel = createCheckBoxJXButtonPanel();
    topPanel.add(checkBoxPanel);

    add(topPanel);
    add(createButtonJXButtonPanel(), BorderLayout.SOUTH);
    pack();

    JMenuBar bar = new JMenuBar();
    JMenu menu = new JMenu("Options");
    JMenuItem item = new JMenuItem("Unselect radioButtons");
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // hack for 1.5 
            // in 1.6 ButtonGroup.clearSelection added
            JRadioButton b = new JRadioButton();
            radioGroup.add(b);
            b.setSelected(true);
            radioGroup.remove(b);
        }
    });
    menu.add(item);
    bar.add(menu);
    setJMenuBar(bar);

    setSize(300, 300);
    setLocationRelativeTo(null);
}

From source file:de.tud.kom.p2psim.impl.skynet.visualization.SkyNetVisualization.java

private JMenuItem createMenuItem(String text) {
    JMenuItem menuItem = new JMenuItem(text);
    menuItem.addActionListener(this);
    return menuItem;
}

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

/**
 * Get the popup menu for the child node of the facet node 
 * in the digest view./*from   w w  w .  ja  v a  2s  .c  o  m*/
 * @return the popup menu.   
 */
@Override
public JPopupMenu getPopupMenu(final String digestLocator$) {
    JPopupMenu popup = new JPopupMenu();
    JMenuItem openItem = new JMenuItem("Open");
    popup.add(openItem);
    openItem.setHorizontalTextPosition(JMenuItem.RIGHT);
    openItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                //     System.out.println("JWebsetFacetOpenItem:open:digest locator="+digestLocator$); 
                Properties locator = Locator.toProperties(digestLocator$);
                String encodedSelection$ = locator.getProperty(JEntityDigestDisplay.SELECTION);
                byte[] ba = Base64.decodeBase64(encodedSelection$);
                String selection$ = new String(ba, "UTF-8");
                //      System.out.println("JWebsetFacetOpenItem:open:selection="+selection$);
                locator = Locator.toProperties(selection$);
                String entihome$ = locator.getProperty(Entigrator.ENTIHOME);
                String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
                String type$ = locator.getProperty(Locator.LOCATOR_TYPE);
                if (LOCATOR_TYPE_WEB_ADDRESS.equals(type$)) {
                    try {
                        String url$ = locator.getProperty(JWeblinksPanel.WEB_LINK_URL);
                        //                        System.out.println("weblinkEditor:browseUrl:url="+url$);
                        Desktop.getDesktop().browse(new URI(url$));
                    } catch (Exception ee) {
                        Logger.getLogger(JFileOpenItem.class.getName()).info(ee.toString());
                    }
                    return;
                }
                if (JEntityDigestDisplay.LOCATOR_FACET_COMPONENT.equals(type$)) {
                    // String entityKey$=locator.getProperty(EntityHandler.ENTITY_KEY);
                    JWeblinkEditor we = new JWeblinkEditor();
                    String weLocator$ = we.getLocator();
                    weLocator$ = Locator.append(weLocator$, Entigrator.ENTIHOME, entihome$);
                    weLocator$ = Locator.append(weLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                    //JConsoleHandler.execute(console,beLocator$);
                    return;
                }
                String weblinkKey$ = locator.getProperty(JWeblinksPanel.WEB_LINK_KEY);
                JWeblinkEditor we = new JWeblinkEditor();
                String weLocator$ = we.getLocator();
                weLocator$ = Locator.append(weLocator$, Entigrator.ENTIHOME, entihome$);
                weLocator$ = Locator.append(weLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                weLocator$ = Locator.append(weLocator$, JWeblinksPanel.WEB_LINK_KEY, weblinkKey$);
                /*
                Entigrator entigrator=console.getEntigrator(entihome$);
                String componentKey$=locator.getProperty(JEntityDigestDisplay.COMPONENT_KEY);
                Sack entity=entigrator.getEntityAtKey(componentKey$);
                Core weblink=entity.getElementItem("web", weblinkKey$);
                */
                //                  System.out.println("JBookmarkFacetOpenItem:open:selection="+selection$);
                JConsoleHandler.execute(console, weLocator$);
            } catch (Exception ee) {
                Logger.getLogger(JWebsetFacetOpenItem.class.getName()).info(ee.toString());
            }
        }
    });
    return popup;
}