Example usage for javax.swing.event MenuListener MenuListener

List of usage examples for javax.swing.event MenuListener MenuListener

Introduction

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

Prototype

MenuListener

Source Link

Usage

From source file:gdt.jgui.entity.fields.JFieldsEditor.java

/**
 * Get the context menu./*from   w  w  w  . j  ava  2 s .c o  m*/
 * @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("FieldsEditor: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()) {
                editCellItem = new JMenuItem("Edit item");
                editCellItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            JTextEditor textEditor = new JTextEditor();
                            String locator$ = textEditor.getLocator();
                            locator$ = Locator.append(locator$, Entigrator.ENTIHOME, entihome$);
                            locator$ = Locator.append(locator$, EntityHandler.ENTITY_KEY, entityKey$);
                            String responseLocator$ = getEditCellLocator();
                            text$ = Locator.getProperty(responseLocator$, JTextEditor.TEXT);
                            locator$ = Locator.append(locator$, JTextEditor.TEXT, text$);
                            //                  System.out.println("FieldsEditor:edit cell:text="+text$);
                            locator$ = Locator.append(locator$, JRequester.REQUESTER_RESPONSE_LOCATOR,
                                    Locator.compressText(responseLocator$));
                            JConsoleHandler.execute(console, locator$);
                        } catch (Exception ee) {
                            LOGGER.severe(ee.toString());
                        }
                    }
                });
                menu.add(editCellItem);
            }
            if (hasSelectedRows()) {
                deleteItemsItem = new JMenuItem("Delete items");
                deleteItemsItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        int response = JOptionPane.showConfirmDialog(JFieldsEditor.this,
                                "Delete selected fields ?", "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) {
                        copy(false);
                    }
                });
                menu.add(copyItem);
                cutItem = new JMenuItem("Cut");
                cutItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        copy(true);
                    }
                });
                menu.add(cutItem);
            }
            if (hasFieldsToPaste()) {
                pasteItem = new JMenuItem("Paste");
                pasteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            String[] sa = console.clipboard.getContent();
                            Properties locator;
                            String type$;
                            String sourceEntityKey$;
                            Sack sourceEntity;
                            String sourceEntihome$;
                            Entigrator sourceEntigrator;
                            for (String aSa : sa) {
                                //System.out.println("FieldsEditor:paste:"+aSa);
                                locator = Locator.toProperties(aSa);
                                type$ = locator.getProperty(Locator.LOCATOR_TYPE);
                                if (LOCATOR_TYPE_FIELD.equals(type$)) {
                                    String action$ = locator.getProperty(JRequester.REQUESTER_ACTION);
                                    String name$ = locator.getProperty(CELL_FIELD_NAME);
                                    String value$ = locator.getProperty(CELL_FIELD_VALUE);
                                    if (name$ != null) {
                                        if (ACTION_COPY_FIELDS.equals(action$))
                                            entity.putElementItem("field", new Core(null, name$, value$));
                                        if (ACTION_CUT_FIELDS.equals(action$)) {
                                            entity.putElementItem("field", new Core(null, name$, value$));
                                            sourceEntihome$ = locator.getProperty(Entigrator.ENTIHOME);
                                            sourceEntigrator = console.getEntigrator(sourceEntihome$);
                                            sourceEntityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
                                            sourceEntity = sourceEntigrator.getEntityAtKey(sourceEntityKey$);
                                            sourceEntity.removeElementItem("field", name$);
                                            sourceEntigrator.save(sourceEntity);
                                        }
                                    }
                                }
                            }
                            entigrator.save(entity);
                            Core[] ca = entity.elementGet("field");
                            replaceTable(ca);
                        } catch (Exception ee) {
                            LOGGER.info(ee.toString());
                        }
                    }
                });
                menu.add(pasteItem);
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });
    doneItem = new JMenuItem("Done");
    doneItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            save();
            if (requesterResponseLocator$ != null) {
                try {
                    byte[] ba = Base64.decodeBase64(requesterResponseLocator$);
                    String responseLocator$ = new String(ba, "UTF-8");
                    responseLocator$ = Locator.append(responseLocator$, Entigrator.ENTIHOME, entihome$);
                    responseLocator$ = Locator.append(responseLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                    //  System.out.println("FieldsEditor:done.response locator="+responseLocator$);
                    JConsoleHandler.execute(console, responseLocator$);
                } catch (Exception ee) {
                    LOGGER.severe(ee.toString());
                }
            } else
                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);
    if (postMenu != null) {
        //System.out.println("JFieldsEditor:postMenu="+postMenu.length);
        for (JMenuItem jmi : postMenu)
            menu.add(jmi);
    }
    //else
    //   System.out.println("JFieldsEditor:postMenu empty");

    return menu;
}

From source file:gdt.jgui.entity.procedure.JProcedurePanel.java

/**
 * Get the context menu.// www  .  j av  a2 s  . c o m
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {
    menu = new JMenu("Context");
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            menu.removeAll();
            JMenuItem runItem = new JMenuItem("Run");
            runItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    run();
                }
            });
            menu.add(runItem);
            Entigrator entigrator = console.getEntigrator(entihome$);
            Sack procedure = entigrator.getEntityAtKey(entityKey$);
            if (procedure.getElementItem("parameter", "noreset") == null) {
                JMenuItem resetItem = new JMenuItem("Reset");
                resetItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        int response = JOptionPane.showConfirmDialog(console.getContentPanel(),
                                "Reset source to default ?", "Confirm", JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE);
                        if (response == JOptionPane.YES_OPTION)
                            reset();
                    }
                });
                menu.add(resetItem);
            }
            JMenuItem folderItem = new JMenuItem("Open folder");
            folderItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        File file = new File(entihome$ + "/" + entityKey$);
                        Desktop.getDesktop().open(file);
                    } catch (Exception ee) {
                        Logger.getLogger(getClass().getName()).info(ee.toString());
                    }
                }
            });
            menu.add(folderItem);
            try {
                //Entigrator entigrator=console.getEntigrator(entihome$);
                Sack entity = entigrator.getEntityAtKey(entityKey$);
                String template$ = entity.getAttributeAt("template");
                if (template$ != null) {
                    JMenuItem adaptClone = new JMenuItem("Adapt clone");
                    adaptClone.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            try {
                                adaptClone(console, getLocator());
                            } catch (Exception ee) {
                                Logger.getLogger(getClass().getName()).info(ee.toString());
                            }
                        }
                    });
                    menu.add(adaptClone);
                }
            } catch (Exception ee) {
                Logger.getLogger(getClass().getName()).info(ee.toString());
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

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

From source file:gdt.jgui.entity.contact.JContactEditor.java

@Override
public JMenu getContextMenu() {
    final JMenu menu = new JMenu("Context");
    menu.addMenuListener(new MenuListener() {
        @Override/* ww w  . jav a  2  s  .c o m*/
        public void menuSelected(MenuEvent e) {
            //         System.out.println("EntityEditor:getConextMenu:menu selected");
            menu.removeAll();
            JMenuItem facetsItem = new JMenuItem("Facets");
            facetsItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    save();
                    JEntityFacetPanel erm = new JEntityFacetPanel();
                    String locator$ = erm.getLocator();
                    locator$ = Locator.append(locator$, Entigrator.ENTIHOME, entihome$);
                    locator$ = Locator.append(locator$, EntityHandler.ENTITY_KEY, entityKey$);
                    JConsoleHandler.execute(console, locator$);
                }
            });
            menu.add(facetsItem);

            JMenuItem digestItem = new JMenuItem("Digest");
            digestItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    save();
                    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(digestItem);

            JMenuItem structureItem = new JMenuItem("Structure");
            structureItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    save();
                    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(structureItem);
            menu.addSeparator();
            JMenuItem doneItem = new JMenuItem("Done");
            doneItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {

                    try {
                        Entigrator entigrator = console.getEntigrator(entihome$);
                        Sack contact = entigrator.getEntityAtKey(entityKey$);
                        String entityLabel$ = contact.getProperty("label");
                        String title$ = title.getText();
                        if (!entityLabel$.equals(title$)) {
                            contact = entigrator.ent_assignLabel(contact, title$);
                            contact = entigrator.ent_assignProperty(contact, "contact",
                                    contact.getProperty("label"));
                        }
                        contact = entigrator.ent_assignProperty(contact, "phone", phone.getText());
                        contact = entigrator.ent_assignProperty(contact, "email", email.getText());
                        if (requesterResponseLocator$ != null) {
                            byte[] ba = Base64.decodeBase64(requesterResponseLocator$);
                            String responseLocator$ = new String(ba, "UTF-8");
                            //                     System.out.println("TextEditor:done:response locator="+responseLocator$);
                            JConsoleHandler.execute(console, responseLocator$);
                        } else
                            console.back();
                    } catch (Exception ee) {
                        Logger.getLogger(JContactEditor.class.getName()).severe(ee.toString());
                    }

                }
            });
            menu.add(doneItem);

            JMenuItem cancelItem = new JMenuItem("Cancel");
            cancelItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    console.back();
                }
            });
            menu.add(cancelItem);
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void menuCanceled(MenuEvent e) {
            // TODO Auto-generated method stub

        }

    });
    return menu;
}

From source file:com.igormaznitsa.sciareto.ui.MainFrame.java

public MainFrame(@Nonnull @MustNotContainNull final String... args) {
    super();//ww w. j  av a 2  s  .c  o m
    initComponents();

    this.stackPanel = new JPanel();
    this.stackPanel.setFocusable(false);
    this.stackPanel.setOpaque(false);
    this.stackPanel.setBorder(BorderFactory.createEmptyBorder(32, 32, 16, 32));
    this.stackPanel.setLayout(new BoxLayout(this.stackPanel, BoxLayout.Y_AXIS));

    final JPanel glassPanel = (JPanel) this.getGlassPane();
    glassPanel.setOpaque(false);

    this.setGlassPane(glassPanel);

    glassPanel.setLayout(new BorderLayout(8, 8));
    glassPanel.add(Box.createGlue(), BorderLayout.CENTER);

    final JPanel ppanel = new JPanel(new BorderLayout(0, 0));
    ppanel.setFocusable(false);
    ppanel.setOpaque(false);
    ppanel.setCursor(null);
    ppanel.add(this.stackPanel, BorderLayout.SOUTH);

    glassPanel.add(ppanel, BorderLayout.EAST);

    this.stackPanel.add(Box.createGlue());

    glassPanel.setVisible(false);

    this.setTitle("Scia Reto");

    setIconImage(UiUtils.loadImage("logo256x256.png"));

    this.stateless = args.length > 0;

    final MainFrame theInstance = this;

    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(@Nonnull final WindowEvent e) {
            if (doClosing()) {
                dispose();
            }
        }
    });

    this.tabPane = new EditorTabPane(this);

    this.explorerTree = new ExplorerTree(this);

    final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(250);
    splitPane.setResizeWeight(0.0d);
    splitPane.setLeftComponent(this.explorerTree);
    splitPane.setRightComponent(this.tabPane);

    add(splitPane, BorderLayout.CENTER);

    this.menuOpenRecentProject.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            final File[] lastOpenedProjects = FileHistoryManager.getInstance().getLastOpenedProjects();
            if (lastOpenedProjects.length > 0) {
                for (final File folder : lastOpenedProjects) {
                    final JMenuItem item = new JMenuItem(folder.getName());
                    item.setToolTipText(folder.getAbsolutePath());
                    item.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            openProject(folder, false);
                        }
                    });
                    menuOpenRecentProject.add(item);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            menuOpenRecentProject.removeAll();
        }

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

    this.menuOpenRecentFile.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            final File[] lastOpenedFiles = FileHistoryManager.getInstance().getLastOpenedFiles();
            if (lastOpenedFiles.length > 0) {
                for (final File file : lastOpenedFiles) {
                    final JMenuItem item = new JMenuItem(file.getName());
                    item.setToolTipText(file.getAbsolutePath());
                    item.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            openFileAsTab(file);
                        }
                    });
                    menuOpenRecentFile.add(item);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            menuOpenRecentFile.removeAll();
        }

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

    if (!this.stateless) {
        restoreState();
    } else {
        boolean openedProject = false;
        for (final String filePath : args) {
            final File file = new File(filePath);
            if (file.isDirectory()) {
                openedProject = true;
                openProject(file, true);
            } else if (file.isFile()) {
                openFileAsTab(file);
            }
        }
        if (!openedProject) {
            //TODO try to hide project panel!
        }
    }

    final LookAndFeel current = UIManager.getLookAndFeel();
    final ButtonGroup lfGroup = new ButtonGroup();
    final String currentLFClassName = current.getClass().getName();
    for (final UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(info.getName());
        lfGroup.add(menuItem);
        if (currentLFClassName.equals(info.getClassName())) {
            menuItem.setSelected(true);
        }
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(@Nonnull final ActionEvent e) {
                try {
                    UIManager.setLookAndFeel(info.getClassName());
                    SwingUtilities.updateComponentTreeUI(theInstance);
                    PreferencesManager.getInstance().getPreferences().put(Main.PROPERTY_LOOKANDFEEL,
                            info.getClassName());
                    PreferencesManager.getInstance().flush();
                } catch (Exception ex) {
                    LOGGER.error("Can't change LF", ex);
                }
            }
        });
        this.menuLookAndFeel.add(menuItem);
    }
}

From source file:gdt.jgui.entity.bonddetail.JBondDetailPanel.java

/**
 * Get the context menu./*from  w w w. j a  v  a  2s . co  m*/
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {

    menu1 = new JMenu("Context");
    menu1.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            //   System.out.println("JBondDetailPanel:getConextMenu:BEGIN");
            menu1.removeAll();
            JMenuItem selectItem = new JMenuItem("Select all");
            selectItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    JItemPanel[] ipa = getItems();
                    if (ipa != null) {
                        for (JItemPanel ip : ipa)
                            ip.setChecked(true);
                    }
                }
            });
            menu1.add(selectItem);
            JMenuItem unselectItem = new JMenuItem("Unselect all");
            unselectItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    JItemPanel[] ipa = getItems();
                    if (ipa != null) {
                        for (JItemPanel ip : ipa)
                            ip.setChecked(false);
                    }
                }
            });
            menu1.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.severe(ee.toString());
                        }
                    } else
                        console.back();

                }

            });
            menu1.add(doneItem);
            menu1.addSeparator();
            addItem = new JMenuItem("Add");
            addItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        Entigrator entigrator = console.getEntigrator(entihome$);

                        JContext adp = (JContext) ExtensionHandler.loadHandlerInstance(entigrator,
                                BondDetailHandler.EXTENSION_KEY, "gdt.jgui.entity.bonddetail.JAddDetailPanel");
                        String adpLocator$ = adp.getLocator();
                        adpLocator$ = Locator.append(adpLocator$, Entigrator.ENTIHOME, entihome$);
                        adpLocator$ = Locator.append(adpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                        JConsoleHandler.execute(console, adpLocator$);

                    } catch (Exception ee) {
                        LOGGER.severe(ee.toString());
                    }
                }
            });
            menu1.add(addItem);
            if (hasToPaste()) {
                JMenuItem pasteItem = new JMenuItem("Paste");
                pasteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        paste();

                    }
                });
                menu1.add(pasteItem);
            }
            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) {

                            delete();
                            JBondDetailPanel bdp = new JBondDetailPanel();
                            String bdpLocator$ = bdp.getLocator();
                            bdpLocator$ = Locator.append(bdpLocator$, Entigrator.ENTIHOME, entihome$);
                            bdpLocator$ = Locator.append(bdpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                            bdpLocator$ = Locator.append(bdpLocator$, JBondsPanel.BOND_KEY, bondKey$);
                            JConsoleHandler.execute(console, bdpLocator$);
                        }
                    }
                });
                menu1.add(deleteItem);
            }

        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

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

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

/**
 * Get the context menu.//  w w  w  .jav  a 2 s .c o m
 * @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:gdt.jgui.entity.webset.JWeblinksPanel.java

/**
 * Get the context menu.//from w w w . ja  v  a  2s.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:ca.phon.app.project.ProjectWindow.java

@Override
public void setJMenuBar(JMenuBar menu) {
    super.setJMenuBar(menu);

    JMenu projectMenu = new JMenu("Project");

    int projectMenuIndex = -1;
    // get the edit menu and add view commands
    for (int i = 0; i < menu.getMenuCount(); i++) {
        JMenu currentBar = menu.getMenu(i);

        if (currentBar != null && currentBar.getText() != null && currentBar.getText().equals("Workspace")) {
            projectMenuIndex = i + 1;/*from   w ww.  j  a v a 2  s . c o  m*/
        }
    }

    if (projectMenuIndex > 0) {
        menu.add(projectMenu, projectMenuIndex);
    }

    // refresh lists 
    final RefreshAction refreshItem = new RefreshAction(this);
    projectMenu.add(refreshItem);
    projectMenu.addSeparator();

    // create corpus item
    final NewCorpusAction newCorpusItem = new NewCorpusAction(this);
    projectMenu.add(newCorpusItem);

    //       create corpus item
    final NewSessionAction newSessionItem = new NewSessionAction(this);
    projectMenu.add(newSessionItem);

    projectMenu.addSeparator();

    final AnonymizeAction anonymizeParticipantInfoItem = new AnonymizeAction(this);
    projectMenu.add(anonymizeParticipantInfoItem);

    final CheckTranscriptionsAction repairItem = new CheckTranscriptionsAction(this);
    projectMenu.add(repairItem);

    // merge/split sessions
    final DeriveSessionAction deriveItem = new DeriveSessionAction(this);
    projectMenu.add(deriveItem);

    final JMenu teamMenu = new JMenu("Team");
    teamMenu.addMenuListener(new MenuListener() {

        @Override
        public void menuSelected(MenuEvent e) {
            teamMenu.removeAll();
            if (getProject() != null) {
                final ProjectGitController gitController = new ProjectGitController(getProject());
                if (gitController.hasGitFolder()) {
                    teamMenu.add(new CommitAction(ProjectWindow.this));

                    teamMenu.addSeparator();

                    teamMenu.add(new PullAction(ProjectWindow.this));
                    teamMenu.add(new PushAction(ProjectWindow.this));

                } else {
                    final InitAction initRepoAct = new InitAction(ProjectWindow.this);
                    teamMenu.add(initRepoAct);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {

        }

        @Override
        public void menuCanceled(MenuEvent e) {

        }
    });
    projectMenu.addSeparator();
    projectMenu.add(teamMenu);
}

From source file:KjellDirdalNotepad.java

public WindowMenu(MDIDesktopPane desktop) {
    this.desktop = desktop;
    setText("Window");
    cascade.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            WindowMenu.this.desktop.cascadeFrames();
        }/*from w w w  .  j  a v a  2  s .c o  m*/
    });
    tile.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            WindowMenu.this.desktop.tileFrames();
        }
    });
    addMenuListener(new MenuListener() {
        public void menuCanceled(MenuEvent e) {
        }

        public void menuDeselected(MenuEvent e) {
            removeAll();
        }

        public void menuSelected(MenuEvent e) {
            buildChildMenus();
        }
    });
}

From source file:ca.sqlpower.swingui.object.VariablesPanel.java

@SuppressWarnings("unchecked")
private void showVarsPicker() {
    final MultiValueMap namespaces = this.variableHelper.getNamespaces();

    List<String> sortedNames = new ArrayList<String>(namespaces.keySet().size());
    sortedNames.addAll(namespaces.keySet());
    Collections.sort(sortedNames, new Comparator<String>() {
        public int compare(String o1, String o2) {
            if (o1 == null) {
                return -1;
            }/*from w w  w  .  j a v a  2s .c  o  m*/
            if (o2 == null) {
                return 1;
            }
            return o1.compareTo(o2);
        };
    });

    final JPopupMenu menu = new JPopupMenu();
    for (final String name : sortedNames) {
        final JMenu subMenu = new JMenu(name);
        menu.add(subMenu);
        subMenu.addMenuListener(new MenuListener() {
            private Timer timer;

            public void menuSelected(MenuEvent e) {

                subMenu.removeAll();
                subMenu.add(new PleaseWaitAction());

                ActionListener menuPopulator = new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        if (subMenu.isPopupMenuVisible()) {
                            subMenu.removeAll();
                            for (Object namespaceO : namespaces.getCollection(name)) {
                                String namespace = (String) namespaceO;
                                logger.debug("Resolving variables for namespace ".concat(namespace));
                                int nbItems = 0;
                                for (String key : variableHelper.keySet(namespace)) {
                                    subMenu.add(new InsertVariableAction(SPVariableHelper.getKey((String) key),
                                            (String) key));
                                    nbItems++;
                                }
                                if (nbItems == 0) {
                                    subMenu.add(new DummyAction());
                                    logger.debug("No variables found.");
                                }
                            }
                            subMenu.revalidate();
                            subMenu.getPopupMenu().pack();
                        }
                    }
                };
                timer = new Timer(700, menuPopulator);
                timer.setRepeats(false);
                timer.start();
            }

            public void menuDeselected(MenuEvent e) {
                timer.stop();
            }

            public void menuCanceled(MenuEvent e) {
                timer.stop();
            }
        });
    }

    menu.show(varNameText, 0, varNameText.getHeight());
}