Example usage for java.awt.event KeyEvent VK_D

List of usage examples for java.awt.event KeyEvent VK_D

Introduction

In this page you can find the example usage for java.awt.event KeyEvent VK_D.

Prototype

int VK_D

To view the source code for java.awt.event KeyEvent VK_D.

Click Source Link

Document

Constant for the "D" key.

Usage

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

/**
 * This method initializes jButton1   //from   w w  w . ja v a 2 s. c o  m
 *    
 * @return javax.swing.JButton   
 */
private JButton getJButtonDone() {
    if (jButtonDone == null) {
        jButtonDone = new JButton();
        jButtonDone.setText("Done");
        jButtonDone.setMnemonic(KeyEvent.VK_D);
        jButtonDone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
                // Make sure changes in field that was modal before button
                // click are saved to the model.
                if (jTableDeterminations.isEditing()) {
                    jTableDeterminations.getCellEditor().stopCellEditing();
                }
                //
                setVisible(false);
            }
        });
    }
    return jButtonDone;
}

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

private void init() {
    thisDialog = this;
    setBounds(100, 100, 820, 335);/*from   w w  w  .  j  a  v  a 2 s. c  o  m*/
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    JPanel panel = new JPanel();
    panel.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, }));
    {
        JLabel lblAttributeType = new JLabel("Attribute Type");
        panel.add(lblAttributeType, "2, 2, right, default");
    }
    {
        comboBoxType = new JComboBox();
        comboBoxType.setModel(new DefaultComboBoxModel(
                new String[] { "caste", "scientific name", "sex", "life stage", "part association" }));
        comboBoxType.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                String item = comboBoxType.getSelectedItem().toString();
                if (item != null) {
                    comboBoxValue.setEditable(false);
                    if (item.equals("scientific name")) {
                        comboBoxValue.setEditable(true);
                    }
                    if (item.equals("sex")) {
                        comboBoxValue.setModel(new DefaultComboBoxModel(Sex.getSexValues()));
                    }
                    if (item.equals("life stage")) {
                        comboBoxValue.setModel(new DefaultComboBoxModel(LifeStage.getLifeStageValues()));
                    }
                    if (item.equals("caste")) {
                        comboBoxValue.setModel(new DefaultComboBoxModel(Caste.getCasteValues()));
                    }
                    if (item.equals("part association")) {
                        comboBoxValue
                                .setModel(new DefaultComboBoxModel(PartAssociation.getPartAssociationValues()));
                    }
                }
            }

        });
        panel.add(comboBoxType, "4, 2, fill, default");
    }
    {
        JLabel lblValue = new JLabel("Value");
        panel.add(lblValue, "2, 4, right, default");
    }
    {
        comboBoxValue = new JComboBox();
        comboBoxValue.setModel(new DefaultComboBoxModel(Caste.getCasteValues()));

        panel.add(comboBoxValue, "4, 4, fill, default");
    }
    {
        JLabel lblUnits = new JLabel("Units");
        panel.add(lblUnits, "2, 6, right, default");
    }
    {
        textFieldUnits = new JTextField();
        panel.add(textFieldUnits, "4, 6, fill, default");
        textFieldUnits.setColumns(10);
    }
    {
        JLabel lblRemarks = new JLabel("Remarks");
        panel.add(lblRemarks, "2, 8, right, default");
    }
    contentPanel.setLayout(new BorderLayout(0, 0));
    contentPanel.add(panel, BorderLayout.WEST);
    {
        textFieldRemarks = new JTextField();
        panel.add(textFieldRemarks, "4, 8, fill, default");
        textFieldRemarks.setColumns(10);
    }
    {
        JButton btnAdd = new JButton("Add");
        btnAdd.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                SpecimenPartAttribute newAttribs = new SpecimenPartAttribute();
                newAttribs.setAttributeType(comboBoxType.getSelectedItem().toString());
                newAttribs.setAttributeValue(comboBoxValue.getSelectedItem().toString());
                newAttribs.setAttributeUnits(textFieldUnits.getText());
                newAttribs.setAttributeRemark(textFieldRemarks.getText());
                newAttribs.setSpecimenPartId(parentPart);
                newAttribs.setAttributeDeterminer(Singleton.getSingletonInstance().getUserFullName());
                parentPart.getAttributeCollection().add(newAttribs);
                SpecimenPartAttributeLifeCycle sls = new SpecimenPartAttributeLifeCycle();
                try {
                    sls.attachDirty(newAttribs);
                } catch (SaveFailedException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                ((AbstractTableModel) table.getModel()).fireTableDataChanged();
            }
        });
        panel.add(btnAdd, "4, 10");
    }
    try {
        JLabel lblNewLabel = new JLabel(parentPart.getSpecimenId().getBarcode() + ":" + parentPart.getPartName()
                + " " + parentPart.getPreserveMethod() + " (" + parentPart.getLotCount()
                + ")    Right click on table to edit attributes.");
        contentPanel.add(lblNewLabel, BorderLayout.NORTH);
    } catch (Exception e) {
        JLabel lblNewLabel = new JLabel("No Specimen");
        contentPanel.add(lblNewLabel, BorderLayout.NORTH);
    }
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("caste");
    JComboBox comboBox1 = new JComboBox();
    for (int i = 0; i < Caste.getCasteValues().length; i++) {
        comboBox1.addItem(Caste.getCasteValues()[i]);
    }
    JScrollPane scrollPane = new JScrollPane();

    table = new JTable(new SpecimenPartsAttrTableModel(
            (Collection<SpecimenPartAttribute>) parentPart.getAttributeCollection()));

    //table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(comboBox));   

    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                clickedOnRow = ((JTable) e.getComponent()).getSelectedRow();
                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                clickedOnRow = ((JTable) e.getComponent()).getSelectedRow();
                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });

    popupMenu = new JPopupMenu();

    JMenuItem mntmCloneRow = new JMenuItem("Edit Row");
    mntmCloneRow.setMnemonic(KeyEvent.VK_E);
    mntmCloneRow.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                // Launch a dialog to edit the selected row.
                SpecimenPartAttribEditDialog popup = new SpecimenPartAttribEditDialog(
                        ((SpecimenPartsAttrTableModel) table.getModel()).getRowObject(clickedOnRow));
                popup.setVisible(true);
            } catch (Exception ex) {
                log.error(ex.getMessage());
                JOptionPane.showMessageDialog(thisDialog,
                        "Failed to edit a part attribute row. " + ex.getMessage());
            }
        }
    });
    popupMenu.add(mntmCloneRow);

    JMenuItem mntmDeleteRow = new JMenuItem("Delete Row");
    mntmDeleteRow.setMnemonic(KeyEvent.VK_D);
    mntmDeleteRow.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                if (clickedOnRow >= 0) {
                    ((SpecimenPartsAttrTableModel) table.getModel()).deleteRow(clickedOnRow);
                }
            } catch (Exception ex) {
                log.error(ex.getMessage());
                JOptionPane.showMessageDialog(thisDialog,
                        "Failed to delete a part attribute row. " + ex.getMessage());
            }
        }
    });
    popupMenu.add(mntmDeleteRow);

    // TODO: Enable controlled value editing of selected row.

    // table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(comboBox1));

    scrollPane.setViewportView(table);
    contentPanel.add(scrollPane, BorderLayout.EAST);
    {
        JPanel buttonPane = new JPanel();
        buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
        getContentPane().add(buttonPane, BorderLayout.SOUTH);
        {
            okButton = new JButton("OK");
            okButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    okButton.grabFocus();
                    thisDialog.setVisible(false);
                }
            });
            okButton.setActionCommand("OK");
            buttonPane.add(okButton);
            getRootPane().setDefaultButton(okButton);
        }
        {
            JButton cancelButton = new JButton("Cancel");
            cancelButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    thisDialog.setVisible(false);
                }
            });
            cancelButton.setActionCommand("Cancel");
            buttonPane.add(cancelButton);
        }
    }
}

From source file:eu.apenet.dpt.standalone.gui.DataPreparationToolGUI.java

private void setupTool() {
    LoggerJAXB.outputJaxpImplementationInfo();
    Locale currentLocale = Locale.getDefault();

    labels = new ResourceBundlesWrapper(I18N_BASENAMES, currentLocale);

    retrieveFromDb = new RetrieveFromDb();
    apePanel = new APEPanel(labels, getContentPane(), this, retrieveFromDb);

    Utilities.setXsdList(fillXsdList());

    CheckList checkList = new CheckList();
    langList = checkList.getLangList();//from   ww  w. j  ava 2 s .  c  o  m
    levelList = checkList.getLevelList();

    dateNormalization = new DateNormalization();

    super.setTitle(labels.getString("title"));
    Image topLeftIcon = Utilities.icon.getImage();
    setIconImage(topLeftIcon);

    doChecks();

    if (isFileMissing(Utilities.LOG_DIR)) {
        new File(Utilities.LOG_DIR).mkdir();
    }

    File tempDir = new File(Utilities.TEMP_DIR);
    //In case it didn't deleteOnExit at the previous closing of the program, we clean up.
    if (tempDir.exists()) {
        LOG.warn("Probably a problem when deleting the temp files at closure, so we clean up");
        eraseOldTempFiles(tempDir);
        try {
            FileUtils.deleteDirectory(tempDir);
        } catch (IOException e) {
            LOG.error("Could not delete the temp directory. Attempt to delete the directory once more: "
                    + (tempDir.delete() ? "Successful." : "Unsuccessful."));
        }
    }
    tempDir.mkdir();
    tempDir.deleteOnExit();
    //        ListControlaccessTerms listControlaccessTerms = new ListControlaccessTerms("/Users/yoannmoranville/Documents/Work/APE/data/AD78/");
    //        listControlaccessTerms.countTerms();
    //        listControlaccessTerms.displayLogsResults();
    //        CountCLevels countCLevels = new CountCLevels("/Users/yoannmoranville/Work/APEnet/Projects/data/Ready_APEnet/READY/Finland/HeNAF/FA_EAD/");
    //        CountCLevels countCLevels = new CountCLevels("/Users/yoannmoranville/Work/APEnet/Projects/data/BORA/ALL/");
    //        countCLevels.setCopyInAppropriateDirs(true);
    //        countCLevels.changeMainagencycodeForSweden(false);
    //        countCLevels.countLevels();

    //        SeparateFinnishFiles separateFinnishFiles = new SeparateFinnishFiles(new File("/Users/yoannmoranville/Desktop/files_fi"), TEMP_DIR);
    makeDefaultXsdMenuItems();
    makeDefaultXslMenuItems();

    getContentPane().add(apePanel);

    xmlEadListModel = new ProfileListModel(fileInstances, this);
    xmlEadList = new JList(xmlEadListModel);
    xmlEadList.setCellRenderer(new IconListCellRenderer(fileInstances));
    xmlEadList.setDragEnabled(true);

    xmlEadList.setTransferHandler(new ListTransferHandler());

    xmlEadList.setDropTarget(new DropTarget(xmlEadList, new ListDropTargetListener(xmlEadList, from)));
    xmlEadListModel.setList(xmlEadList);

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);
    menuBar.add(optionMenu);
    menuBar.add(actionMenu);
    menuBar.add(windowMenu);
    menuBar.add(helpMenu);
    fileItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    fileMenu.add(fileItem);

    closeSelectedItem.setEnabled(false);
    //        closeSelectedItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    closeSelectedItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    fileMenu.add(closeSelectedItem);
    saveSelectedItem.setEnabled(false);
    saveSelectedItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    fileMenu.add(saveSelectedItem);
    saveMessageReportItem.setEnabled(false);
    saveMessageReportItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    fileMenu.add(saveMessageReportItem);
    //        sendFilesWebDAV.setEnabled(false);
    //        fileMenu.add(sendFilesWebDAV);
    fileMenu.addSeparator();
    fileMenu.add(quitItem);

    optionMenu.add(countryCodeItem);
    optionMenu.add(repositoryCodeItem);
    optionMenu.add(digitalObjectTypeItem);
    optionMenu.add(edmGeneralOptionsItem);
    optionMenu.add(listDateConversionRulesItem);
    optionMenu.addSeparator();
    optionMenu.add(xsltItem);
    optionMenu.add(xsdItem);
    optionMenu.add(defaultXslSelectionSubmenu);
    optionMenu.add(defaultXsdSelectionSubmenu);
    optionMenu.addSeparator();
    optionMenu.add(checksLoadingFilesItem);
    optionMenu.add(defaultSaveFolderItem);
    optionMenu.add(languageMenu);
    if (Utilities.isDev) {
        optionMenu.addSeparator();
        optionMenu.add(databaseItem);
    }

    validateItem.setEnabled(false);
    validateItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    actionMenu.add(validateItem);
    convertItem.setEnabled(false);
    convertItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_M, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    actionMenu.add(convertItem);

    actionMenu.addSeparator();

    // TODO: Uncomment when edit will be available.
    //        eacCpfItem.add(this.editEacCpfFile);     //add the different EAC-CPF options menu
    eacCpfItem.add(createEacCpf);
    actionMenu.add(eacCpfItem);

    createEag2012Item.add(createEag2012FromExistingEag2012);
    createEag2012Item.add(createEag2012FromScratch);
    actionMenu.add(createEag2012Item);

    summaryWindowItem.setEnabled(true);
    summaryWindowItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_1, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    windowMenu.add(summaryWindowItem);
    validationWindowItem.setEnabled(true);
    validationWindowItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_2, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    windowMenu.add(validationWindowItem);
    conversionWindowItem.setEnabled(true);
    conversionWindowItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_3, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    windowMenu.add(conversionWindowItem);
    edmConversionWindowItem.setEnabled(true);
    edmConversionWindowItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_4, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    windowMenu.add(edmConversionWindowItem);
    editionWindowItem.setEnabled(true);
    editionWindowItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_5, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    windowMenu.add(editionWindowItem);
    helpMenu.add(internetApexItem);
    helpMenu.addSeparator();
    JMenuItem versionItem = new JMenuItem("APE DPT v" + VERSION_NB);
    versionItem.setEnabled(false);
    helpMenu.add(versionItem);
    createLanguageMenu();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fileChooser.setMultiSelectionEnabled(true);

    getContentPane().add(menuBar, BorderLayout.NORTH);

    apePanel.setFilename("");

    createHgListener = new CreateHGListener(retrieveFromDb, labels, getContentPane(), fileInstances, xmlEadList,
            this);
    createHGBtn.addActionListener(createHgListener);
    createHGBtn.setEnabled(false);

    analyzeControlaccessListener = new AnalyzeControlaccessListener(labels, getContentPane(), fileInstances);
    analyzeControlaccessBtn.addActionListener(analyzeControlaccessListener);
    analyzeControlaccessBtn.setEnabled(false);

    validateItem.addActionListener(new ConvertAndValidateActionListener(this, apePanel.getApeTabbedPane(),
            ConvertAndValidateActionListener.VALIDATE));
    convertItem.addActionListener(new ConvertAndValidateActionListener(this, apePanel.getApeTabbedPane(),
            ConvertAndValidateActionListener.CONVERT));

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().add(createWest(), BorderLayout.WEST);

    //        convertAndValidateBtn.addActionListener(new ConvertAndValidateActionListener(this, getContentPane()));
    //        validateSelectionBtn.addActionListener(new ValidateSelectionActionListener(this, getContentPane()));
    //        convertEdmSelectionBtn.addActionListener(new ConvertEdmActionListener(labels, this, apePanel));

    nameComponents();
    wireUp();
    setSize(Toolkit.getDefaultToolkit().getScreenSize());
    setMinimumSize(Toolkit.getDefaultToolkit().getScreenSize());
    setExtendedState(JFrame.MAXIMIZED_BOTH);
}

From source file:userinterface.properties.GUIGraphHandler.java

private void initComponents() {
    theTabs = new JTabbedPane() {

        @Override/* w w  w.  j  a  v  a2s .c  o m*/
        public String getTitleAt(int index) {
            try {
                TabClosePanel panel = (TabClosePanel) getTabComponentAt(index);
                return panel.getTitle();
            } catch (Exception e) {
                return "";
            }
        }

        @Override
        public String getToolTipTextAt(int index) {
            return ((TabClosePanel) getTabComponentAt(index)).getToolTipText();
        }

        @Override
        public void setTitleAt(int index, String title) {

            if (((TabClosePanel) getTabComponentAt(index)) == null) {
                return;
            }

            ((TabClosePanel) getTabComponentAt(index)).setTitle(title);
        }

        @Override
        public void setIconAt(int index, Icon icon) {
            ((TabClosePanel) getTabComponentAt(index)).setIcon(icon);
        }

        @Override
        public void setToolTipTextAt(int index, String toolTipText) {
            ((TabClosePanel) getTabComponentAt(index)).setToolTip(toolTipText);
        }

    };

    theTabs.addMouseListener(this);
    theTabs.addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getPreciseWheelRotation() > 0.0) {

                if (theTabs.getSelectedIndex() != (theTabs.getTabCount() - 1))
                    theTabs.setSelectedIndex(theTabs.getSelectedIndex() + 1);
            } else {

                if (theTabs.getSelectedIndex() != 0)
                    theTabs.setSelectedIndex(theTabs.getSelectedIndex() - 1);
            }
        }
    });

    setLayout(new BorderLayout());
    add(theTabs, BorderLayout.CENTER);

    graphOptions = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            GraphOptions graphOptions = options.get(theTabs.getSelectedIndex());
            graphOptions.setVisible(true);
        }
    };

    graphOptions.putValue(Action.NAME, "Graph options");
    graphOptions.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_G));
    graphOptions.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallOptions.png"));
    graphOptions.putValue(Action.LONG_DESCRIPTION, "Displays the options dialog for the graph.");

    zoomIn = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JPanel mgm = models.get(theTabs.getSelectedIndex());

            if (mgm instanceof ChartPanel)
                ((ChartPanel) mgm).zoomInBoth(-1, -1);
            else if (mgm instanceof Graph3D) {
                double rho = ((Graph3D) mgm).getChart3DPanel().getViewPoint().getRho();
                ((Graph3D) mgm).getChart3DPanel().getViewPoint().setRho(rho - 5);
                ((Graph3D) mgm).getChart3DPanel().repaint();
            }
        }
    };

    zoomIn.putValue(Action.NAME, "In");
    zoomIn.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_I));
    zoomIn.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallPlayerFwd.png"));
    zoomIn.putValue(Action.LONG_DESCRIPTION, "Zoom in on the graph.");

    zoomOut = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JPanel mgm = models.get(theTabs.getSelectedIndex());

            if (mgm instanceof ChartPanel)
                ((ChartPanel) mgm).zoomOutBoth(-1, -1);
            else if (mgm instanceof Graph3D) {
                double rho = ((Graph3D) mgm).getChart3DPanel().getViewPoint().getRho();
                ((Graph3D) mgm).getChart3DPanel().getViewPoint().setRho(rho + 5);
                ((Graph3D) mgm).getChart3DPanel().repaint();
            }
        }
    };

    zoomOut.putValue(Action.NAME, "Out");
    zoomOut.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_O));
    zoomOut.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallPlayerRew.png"));
    zoomOut.putValue(Action.LONG_DESCRIPTION, "Zoom out of the graph.");

    zoomDefault = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JPanel mgm = models.get(theTabs.getSelectedIndex());

            if (mgm instanceof ChartPanel)
                ((ChartPanel) mgm).restoreAutoBounds();
            else if (mgm instanceof Graph3D) {
                ((Graph3D) mgm).getChart3DPanel().zoomToFit();
                ((Graph3D) mgm).getChart3DPanel().getDrawable()
                        .setViewPoint(new ViewPoint3D(-Math.PI / 2, Math.PI * 1.124, 70.0, 0.0));
                ((Graph3D) mgm).getChart3DPanel().repaint();

            }
        }
    };

    zoomDefault.putValue(Action.NAME, "Default");
    zoomDefault.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_D));
    zoomDefault.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallPlayerStart.png"));
    zoomDefault.putValue(Action.LONG_DESCRIPTION, "Set the default zoom for the graph.");

    importXML = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (plug.showOpenFileDialog(graFilter) != JFileChooser.APPROVE_OPTION)
                return;
            try {
                Graph mgm = Graph.load(plug.getChooserFile());
                addGraph(mgm);
            } catch (GraphException ex) {
                plug.error("Could not import PRISM graph file:\n" + ex.getMessage());
            }
        }
    };
    importXML.putValue(Action.NAME, "PRISM graph (*.gra)");
    importXML.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_I));
    importXML.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFileGraph.png"));
    importXML.putValue(Action.LONG_DESCRIPTION, "Imports a saved PRISM graph from a file.");

    addFunction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {

            plotNewFunction();
        }
    };
    addFunction.putValue(Action.NAME, "Plot function");
    addFunction.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_P));
    addFunction.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFunction.png"));
    addFunction.putValue(Action.LONG_DESCRIPTION, "Plots a new specified function on the current graph");

    exportXML = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (plug.showSaveFileDialog(graFilter) != JFileChooser.APPROVE_OPTION)
                return;
            Graph mgm = (Graph) models.get(theTabs.getSelectedIndex());
            try {
                mgm.save(plug.getChooserFile());
            } catch (PrismException ex) {
                plug.error("Could not export PRISM graph file:\n" + ex.getMessage());
            }
        }
    };
    exportXML.putValue(Action.NAME, "PRISM graph (*.gra)");
    exportXML.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_X));
    exportXML.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFileGraph.png"));
    exportXML.putValue(Action.LONG_DESCRIPTION, "Export graph as a PRISM graph file.");

    exportImageJPG = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JPanel model = getModel(theTabs.getSelectedIndex());

            GUIImageExportDialog imageDialog = new GUIImageExportDialog(plug.getGUI(), model,
                    GUIImageExportDialog.JPEG);
            saveImage(imageDialog);
        }
    };
    exportImageJPG.putValue(Action.NAME, "JPEG Interchange Format (*.jpg, *.jpeg)");
    exportImageJPG.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_J));
    exportImageJPG.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFileImage.png"));
    exportImageJPG.putValue(Action.LONG_DESCRIPTION, "Export graph as a JPEG file.");

    exportImagePNG = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JPanel model = getModel(theTabs.getSelectedIndex());
            GUIImageExportDialog imageDialog = new GUIImageExportDialog(plug.getGUI(), model,
                    GUIImageExportDialog.PNG);
            saveImage(imageDialog);

        }
    };
    exportImagePNG.putValue(Action.NAME, "Portable Network Graphics (*.png)");
    exportImagePNG.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_P));
    exportImagePNG.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFileImage.png"));
    exportImagePNG.putValue(Action.LONG_DESCRIPTION, "Export graph as a Portable Network Graphics file.");

    exportPDF = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (plug.showSaveFileDialog(pdfFilter) != JFileChooser.APPROVE_OPTION)
                return;

            JPanel mgm = models.get(theTabs.getSelectedIndex());

            if (mgm instanceof ChartPanel)
                Graph.exportToPDF(plug.getChooserFile(), ((ChartPanel) mgm).getChart());
            else if (mgm instanceof Graph3D) {

                Graph3D.exportToPDF(plug.getChooserFile(), ((Graph3D) mgm).getChart3DPanel());
            }

        }
    };
    exportPDF.putValue(Action.NAME, "Portable document format (*.pdf)");
    exportPDF.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_P));
    exportPDF.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFilePdf.png"));
    exportPDF.putValue(Action.LONG_DESCRIPTION, "Export the graph as a Portable document format file.");

    exportImageEPS = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JPanel model = getModel(theTabs.getSelectedIndex());

            if (model instanceof ChartPanel) {

                GUIImageExportDialog imageDialog = new GUIImageExportDialog(plug.getGUI(), (ChartPanel) model,
                        GUIImageExportDialog.EPS);

                saveImage(imageDialog);

            }
        }
    };
    exportImageEPS.putValue(Action.NAME, "Encapsulated PostScript (*.eps)");
    exportImageEPS.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_E));
    exportImageEPS.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFilePdf.png"));
    exportImageEPS.putValue(Action.LONG_DESCRIPTION, "Export graph as an Encapsulated PostScript file.");

    exportMatlab = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (plug.showSaveFileDialog(matlabFilter) != JFileChooser.APPROVE_OPTION)
                return;

            JPanel mgm = models.get(theTabs.getSelectedIndex());

            if (mgm instanceof Graph) {

                try {

                    ((Graph) mgm).exportToMatlab(plug.getChooserFile());

                } catch (IOException ex) {
                    plug.error("Could not export Matlab file:\n" + ex.getMessage());
                }

            } else if (mgm instanceof Graph3D) {

                try {

                    ((Graph3D) mgm).exportToMatlab(plug.getChooserFile());

                } catch (IOException e1) {

                    plug.error("Could not export Matlab file:\n" + e1.getMessage());
                    e1.printStackTrace();
                }
            }

        }
    };
    exportMatlab.putValue(Action.NAME, "Matlab file (*.m)");
    exportMatlab.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_M));
    exportMatlab.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFileMatlab.png"));
    exportMatlab.putValue(Action.LONG_DESCRIPTION, "Export graph as a Matlab file.");

    exportGnuplot = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (plug.showSaveFileDialog(gnuplotFilter) != JFileChooser.APPROVE_OPTION)
                return;

            JPanel mgm = models.get(theTabs.getSelectedIndex());

            if (mgm instanceof ChartPanel) {

                try {
                    if (mgm instanceof Graph && !(mgm instanceof ParametricGraph)) {

                        ((Graph) mgm).exportToGnuplot(plug.getChooserFile());
                    } else if (mgm instanceof ParametricGraph) {

                        ((ParametricGraph) mgm).exportToGnuplot(plug.getChooserFile());
                    } else if (mgm instanceof Histogram) {
                        ((Histogram) mgm).exportToGnuplot(plug.getChooserFile());
                    }

                } catch (IOException ex) {
                    plug.error("Could not export Gnuplot file:\n" + ex.getMessage());
                }
            }

            else if (mgm instanceof Graph3D) {

                try {

                    ((Graph3D) mgm).exportToGnuplot(plug.getChooserFile());

                } catch (IOException ex) {

                    plug.error("Could not export Gnuplot file:\n" + ex.getMessage());
                    ex.printStackTrace();
                }
            }

        }
    };

    exportGnuplot.putValue(Action.NAME, "GNU Plot file(*.gnuplot)");
    exportGnuplot.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_G));
    exportGnuplot.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallgnuplot.png"));
    exportGnuplot.putValue(Action.LONG_DESCRIPTION, "Export graph as a GNU plot file.");

    printGraph = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JPanel graph = models.get(theTabs.getSelectedIndex());

            if (graph instanceof ChartPanel) {

                if (graph instanceof Graph) {

                    if (!((Graph) graph).getDisplaySettings().getBackgroundColor().equals(Color.white)) {
                        if (plug.questionYesNo(
                                "Your graph has a coloured background, this background will show up on the \n"
                                        + "printout. Would you like to make the current background colour white?") == 0) {

                            ((Graph) graph).getDisplaySettings().setBackgroundColor(Color.white);
                        }
                    }

                } else if (graph instanceof Histogram) {

                    if (!((Histogram) graph).getDisplaySettings().getBackgroundColor().equals(Color.white)) {
                        if (plug.questionYesNo(
                                "Your graph has a coloured background, this background will show up on the \n"
                                        + "printout. Would you like to make the current background colour white?") == 0) {
                            ((Histogram) graph).getDisplaySettings().setBackgroundColor(Color.white);
                        }
                    }

                }

                ((ChartPanel) graph).createChartPrintJob();
            }

            if (graph instanceof Graph3D) {

                ((Graph3D) graph).createPrintJob();
            }
        }
    };

    printGraph.putValue(Action.NAME, "Print graph");
    printGraph.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_P));
    printGraph.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallPrint.png"));
    printGraph.putValue(Action.LONG_DESCRIPTION, "Print the graph to a printer or file");

    deleteGraph = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JPanel graph = models.get(theTabs.getSelectedIndex());

            models.remove(theTabs.getSelectedIndex());
            options.remove(theTabs.getSelectedIndex());
            theTabs.remove(graph);
        }
    };
    deleteGraph.putValue(Action.NAME, "Delete graph");
    deleteGraph.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_D));
    deleteGraph.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallDelete.png"));
    deleteGraph.putValue(Action.LONG_DESCRIPTION, "Deletes the graph.");

    zoomMenu = new JMenu("Zoom");
    zoomMenu.setMnemonic('Z');
    zoomMenu.setIcon(GUIPrism.getIconFromImage("smallView.png"));
    zoomMenu.add(zoomIn);
    zoomMenu.add(zoomOut);
    zoomMenu.add(zoomDefault);

    exportMenu = new JMenu("Export graph");
    exportMenu.setMnemonic('E');
    exportMenu.setIcon(GUIPrism.getIconFromImage("smallExport.png"));
    exportMenu.add(exportXML);
    exportMenu.add(exportImagePNG);
    exportMenu.add(exportPDF);
    exportMenu.add(exportImageEPS);
    exportMenu.add(exportImageJPG);

    exportMenu.add(exportMatlab);
    exportMenu.add(exportGnuplot);

    importMenu = new JMenu("Import graph");
    importMenu.setMnemonic('I');
    importMenu.setIcon(GUIPrism.getIconFromImage("smallImport.png"));
    importMenu.add(importXML);

    graphMenu.add(graphOptions);
    graphMenu.add(zoomMenu);
    graphMenu.addSeparator();
    graphMenu.add(printGraph);
    graphMenu.add(deleteGraph);
    graphMenu.addSeparator();
    graphMenu.add(exportMenu);
    graphMenu.add(importMenu);
    graphMenu.add(addFunction);

    /* Tab context menu */
    backMenu.add(importXML);
}

From source file:edu.harvard.mcz.imagecapture.encoder.UnitTrayLabelBrowser.java

/**
 * This method initializes jMenuItem3   
 *    /*from w  w w .  ja  v  a 2s.  c o  m*/
 * @return javax.swing.JMenuItem   
 */
private JMenuItem getJMenuItem3() {
    if (jMenuItem3 == null) {
        jMenuItem3 = new JMenuItem();
        jMenuItem3.setText("Create PDF");
        jMenuItem3.setMnemonic(KeyEvent.VK_D);
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
                makePDF();
            }
        });
    }
    return jMenuItem3;
}

From source file:org.photovault.swingui.PhotoCollectionThumbView.java

void createUI() {
    photoTransferHandler = new PhotoCollectionTransferHandler(this);
    setTransferHandler(photoTransferHandler);

    setAutoscrolls(true);/* www  .  j  av a 2  s  . c  o  m*/

    addMouseListener(this);
    addMouseMotionListener(this);

    // Create the popup menu
    popup = new JPopupMenu();
    ImageIcon propsIcon = getIcon("view_properties.png");
    editSelectionPropsAction = new EditSelectionPropsAction(this, "Properties...", propsIcon,
            "Edit properties of the selected photos", KeyEvent.VK_P);
    JMenuItem propsItem = new JMenuItem(editSelectionPropsAction);
    ImageIcon colorsIcon = getIcon("colors.png");
    editSelectionColorsAction = new EditSelectionColorsAction(this, null, "Adjust colors...", colorsIcon,
            "Adjust colors of the selected photos", KeyEvent.VK_A);
    JMenuItem colorsItem = new JMenuItem(editSelectionColorsAction);
    ImageIcon showIcon = getIcon("show_new_window.png");
    showSelectedPhotoAction = new ShowSelectedPhotoAction(this, "Show image", showIcon,
            "Show the selected phot(s)", KeyEvent.VK_S);
    JMenuItem showItem = new JMenuItem(showSelectedPhotoAction);
    showHistoryAction = new ShowPhotoHistoryAction(this, "Show history", null, "Show history of selected photo",
            KeyEvent.VK_H, null);
    resolveConflictsAction = new ResolvePhotoConflictsAction(this, "Resolve conflicts", null,
            "Resolve synchronization conflicts", KeyEvent.VK_R, null);
    JMenuItem rotateCW = new JMenuItem(ctrl.getActionAdapter("rotate_cw"));
    JMenuItem rotateCCW = new JMenuItem(ctrl.getActionAdapter("rotate_ccw"));
    JMenuItem rotate180deg = new JMenuItem(ctrl.getActionAdapter("rotate_180"));

    JMenuItem addToFolder = new JMenuItem("Add to folder...");
    addToFolder.addActionListener(this);
    addToFolder.setActionCommand(PHOTO_ADD_TO_FOLDER_CMD);
    addToFolder.setIcon(getIcon("empty_icon.png"));
    ImageIcon exportIcon = getIcon("filesave.png");
    exportSelectedAction = new ExportSelectedAction(this, "Export selected...", exportIcon,
            "Export the selected photos to from archive database to image files", KeyEvent.VK_E);
    JMenuItem exportSelected = new JMenuItem(exportSelectedAction);

    ImageIcon deleteSelectedIcon = getIcon("delete_image.png");
    deleteSelectedAction = new DeletePhotoAction(this, "Delete", deleteSelectedIcon,
            "Delete selected photos including all of their instances", KeyEvent.VK_D);
    JMenuItem deleteSelected = new JMenuItem(deleteSelectedAction);

    starIcon = getIcon("star_normal_border.png");
    rejectedIcon = getIcon("quality_unusable.png");

    rawIcon = getIcon("raw_icon.png");

    JMenuItem showHistory = new JMenuItem(showHistoryAction);
    JMenuItem resolveConflicts = new JMenuItem(resolveConflictsAction);
    AddTagAction addTagAction = new AddTagAction(ctrl, "Add tag...", null, "Add tag to image", KeyEvent.VK_T);
    JMenuItem addTag = new JMenuItem(addTagAction);
    popup.add(showItem);
    popup.add(propsItem);
    popup.add(colorsItem);
    popup.add(rotateCW);
    popup.add(rotateCCW);
    popup.add(rotate180deg);
    popup.add(addToFolder);
    popup.add(exportSelected);
    popup.add(deleteSelected);
    popup.add(showHistory);
    popup.add(resolveConflicts);
    popup.add(addTag);
    MouseListener popupListener = new PopupListener();
    addMouseListener(popupListener);

    ImageIcon selectNextIcon = getIcon("next.png");
    selectNextAction = new ChangeSelectionAction(this, ChangeSelectionAction.MOVE_FWD, "Next photo",
            selectNextIcon, "Move to next photo", KeyEvent.VK_N,
            KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    ImageIcon selectPrevIcon = getIcon("previous.png");
    selectPrevAction = new ChangeSelectionAction(this, ChangeSelectionAction.MOVE_BACK, "Previous photo",
            selectPrevIcon, "Move to previous photo", KeyEvent.VK_P,
            KeyStroke.getKeyStroke(KeyEvent.VK_P, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    creatingThumbIcon = getIcon("creating_thumb.png");
}

From source file:com.qspin.qtaste.ui.MainPanel.java

protected void genMenu(final TestCaseTree tct) {
    final JFrame owner = this;
    JMenuBar menuBar = new JMenuBar();
    JMenu tools = new JMenu("Tools");
    tools.setMnemonic(KeyEvent.VK_T);

    // Tools|Config menu item
    JMenuItem config = new JMenuItem("Config", KeyEvent.VK_D);
    config.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            //ATEConfigEditPanel configPanel = new  ATEConfigEditPanel(null);
            //configPanel.setVisible(true);
            MainConfigFrame configFrame = new MainConfigFrame();
            configFrame.launch();// w w  w .  j a v a 2 s .co  m
            configFrame.addWindowListener(new WindowListener() {

                public void windowOpened(WindowEvent e) {
                }

                public void windowClosing(WindowEvent e) {
                }

                public void windowClosed(WindowEvent e) {
                    // refresh the Configuration information display
                    refreshParams();
                }

                public void windowIconified(WindowEvent e) {
                }

                public void windowDeiconified(WindowEvent e) {
                }

                public void windowActivated(WindowEvent e) {
                }

                public void windowDeactivated(WindowEvent e) {
                }
            });

        }
    });
    tools.add(config);

    // Tools|delete results menu item
    JMenuItem deleteResults = new JMenuItem("Delete Results", KeyEvent.VK_D);
    final MainPanel ui = this;
    deleteResults.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String baseDir = TestEngineConfiguration.getInstance().getString("reporting.generated_report_path");
            new File(baseDir, baseDir);
            // TO DO : delete really the files
            JOptionPane.showMessageDialog(ui, "Results have been deleted");

        }
    });
    tools.add(deleteResults);

    JMenu fileMenu = new JMenu("File");
    JMenuItem importTestSuites = new JMenuItem("Import TestSuites");
    importTestSuites.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            //
            mTestCasePanel.importTestSuites();

        }
    });
    fileMenu.add(importTestSuites);

    JMenu help = new JMenu("Help");
    help.setMnemonic(KeyEvent.VK_H);
    JMenuItem about = new JMenuItem("About", KeyEvent.VK_A);
    about.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            new AboutDialog(owner);
        }
    });
    help.add(about);

    JMenuItem ateUserManuel = new JMenuItem("User Manual");
    ateUserManuel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            viewQTasteUserManuel();
        }
    });
    help.add(ateUserManuel);

    //menuBar.add(tools); // not to be used at this time!!!!!!!!!
    //menuBar.add(fileMenu);
    menuBar.add(help);
    setJMenuBar(menuBar);
}

From source file:edu.harvard.mcz.imagecapture.encoder.UnitTrayLabelBrowser.java

private JMenuItem getJMenuItemAddRow() {
    if (jMenuItemAddRow == null) {
        jMenuItemAddRow = new JMenuItem();
        jMenuItemAddRow.setText("Add Blank Row");
        jMenuItemAddRow.setMnemonic(KeyEvent.VK_D);
        jMenuItemAddRow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
                addRow();/*from   ww w. j a va 2s.  co m*/

                //jTable.scrollRectToVisible(jTable.getCellRect(jTable.getRowCount(), 1, false));
                //jTable.editCellAt(jTable.getRowCount(), 1);
                //jScrollPane.getVerticalScrollBar().setValue(jScrollPane.getVerticalScrollBar().getMaximum());
                //jScrollPane.getViewport().invalidate();
                //jScrollPane.getViewport().validate();
                //jScrollPane.getVerticalScrollBar().setValue(jScrollPane.getVerticalScrollBar().getMaximum());

                Rectangle newCell = new Rectangle(1, jTable.getRowHeight() * (jTable.getRowCount()), 10,
                        jTable.getRowHeight());
                //jTable.scrollRectToVisible(newCell);
            }
        });
    }
    return jMenuItemAddRow;
}

From source file:livecanvas.mesheditor.MeshEditor.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu, subMenu;// ww w  . j  a va 2s.c  o m
    JMenuItem menuItem;
    menu = new JMenu("File");
    menu.setMnemonic(KeyEvent.VK_F);
    menu.add(menuItem = Utils.createMenuItem("New", NEW, KeyEvent.VK_N, "ctrl N", this));
    menu.add(menuItem = Utils.createMenuItem("Open...", OPEN, KeyEvent.VK_O, "ctrl O", this));
    menu.add(menuItem = Utils.createMenuItem("Save", SAVE, KeyEvent.VK_S, "ctrl S", this));
    menu.addSeparator();
    menu.add(menuItem = Utils.createMenuItem("Exit", EXIT, KeyEvent.VK_X, "", this));
    menuBar.add(menu);
    menu = new JMenu("Edit");
    menu.setMnemonic(KeyEvent.VK_E);
    menu.add(menuItem = Utils.createMenuItem("Undo", UNDO, KeyEvent.VK_U, "ctrl Z", this));
    menu.add(menuItem = Utils.createMenuItem("Redo", REDO, KeyEvent.VK_R, "ctrl Y", this));
    menu.addSeparator();
    menu.add(menuItem = Utils.createMenuItem("Cut", CUT, KeyEvent.VK_T, "ctrl X", this));
    menu.add(menuItem = Utils.createMenuItem("Copy", COPY, KeyEvent.VK_C, "ctrl C", this));
    menu.add(menuItem = Utils.createMenuItem("Paste", PASTE, KeyEvent.VK_P, "ctrl V", this));
    menu.addSeparator();
    menu.add(menuItem = Utils.createMenuItem("Select All", SELECT_ALL, KeyEvent.VK_A, "ctrl A", this));
    menu.add(menuItem = Utils.createMenuItem("Invert Selection", INVERT_SELECTION, 0, "", this));
    menu.addSeparator();
    menu.add(menuItem = Utils.createMenuItem("Settings...", SETTINGS, KeyEvent.VK_S, "", this));
    menuBar.add(menu);
    menu = new JMenu("Tools");
    menu.setMnemonic(KeyEvent.VK_T);
    menu.add(menuItem = Utils.createMenuItem("Brush", TOOLS_BRUSH, KeyEvent.VK_B, "B", this));
    menu.add(menuItem = Utils.createMenuItem("Pencil", TOOLS_PEN, KeyEvent.VK_N, "N", this));
    menu.add(menuItem = Utils.createMenuItem("Magic Wand", TOOLS_MAGICWAND, KeyEvent.VK_W, "W", this));
    menu.add(menuItem = Utils.createMenuItem("Set Control Points", TOOLS_SETCONTROLPOINTS, KeyEvent.VK_C, "C",
            this));
    menu.add(menuItem = Utils.createMenuItem("Pointer", TOOLS_POINTER, KeyEvent.VK_P, "P", this));
    menu.add(menuItem = Utils.createMenuItem("Pan / Zoom", TOOLS_PANZOOM, KeyEvent.VK_Z, "Z", this));
    menuBar.add(menu);
    menu = new JMenu("Layers");
    menu.setMnemonic(KeyEvent.VK_L);
    menu.add(menuItem = Utils.createMenuItem("Add Layer...", ADD_LAYER, KeyEvent.VK_A, "", this));
    menu.add(menuItem = Utils.createMenuItem("Remove", REMOVE_LAYER, KeyEvent.VK_R, "", this));
    menu.add(menuItem = Utils.createMenuItem("Duplicate", DUPLICATE_LAYER, KeyEvent.VK_C, "", this));
    menu.addSeparator();
    menu.add(menuItem = Utils.createMenuItem("Move Up", MOVEUP_LAYER, KeyEvent.VK_U, "", this));
    menu.add(menuItem = Utils.createMenuItem("Move Down", MOVEDOWN_LAYER, KeyEvent.VK_D, "", this));
    menu.addSeparator();
    menu.add(menuItem = Utils.createMenuItem("Reparent Layer...", REPARENT_LAYER, KeyEvent.VK_R, "", this));
    menu.addSeparator();
    menu.add(menuItem = Utils.createMenuItem("Group Layers", GROUP_LAYERS, KeyEvent.VK_G, "", this));
    menu.add(menuItem = Utils.createMenuItem("Ungroup Layer", UNGROUP_LAYER, KeyEvent.VK_N, "", this));
    menu.addSeparator();
    menu.add(menuItem = Utils.createMenuItem("Join Layers", JOIN_LAYERS, KeyEvent.VK_J, "", this));
    menu.add(menuItem = Utils.createMenuItem("Intersect", INTERSECT_LAYERS, KeyEvent.VK_I, "", this));
    menu.add(menuItem = Utils.createMenuItem("Subtract", SUBTRACT_LAYERS, KeyEvent.VK_S, "", this));
    menu.addSeparator();
    menu.add(menuItem = Utils.createMenuItem("Rename...", RENAME_LAYER, KeyEvent.VK_E, "", this));
    menu.addSeparator();
    subMenu = new JMenu("Background Reference");
    subMenu.add(menuItem = Utils.createMenuItem("Set...", BGREF_SET, KeyEvent.VK_S, "", this));
    subMenu.add(menuItem = Utils.createMenuItem("Remove", BGREF_REMOVE, KeyEvent.VK_R, "", this));
    menu.add(subMenu);
    menuBar.add(menu);
    menu.addSeparator();
    menu.add(menuItem = Utils.createMenuItem("Create Mesh Grid", CREATE_MESHGRID, KeyEvent.VK_M, "", this));
    menu.addSeparator();
    menu.add(menuItem = Utils.createCheckBoxMenuItem("See Through", SEE_THROUGH, KeyEvent.VK_T, "", this));
    menuItem.setSelected(true);
    menu.add(menuItem = Utils.createCheckBoxMenuItem("Show Mesh", SHOW_MESH, KeyEvent.VK_M, "", this));
    menuItem.setSelected(true);
    return menuBar;
}

From source file:es.emergya.ui.gis.FleetControlMapViewer.java

@Override
protected JPopupMenu getContextMenu() {
    JPopupMenu menu = new JPopupMenu();

    menu.setBackground(Color.decode("#E8EDF6"));

    // Ttulo//from w w w .  j ava2 s .c  o m
    final JMenuItem titulo = new JMenuItem(i18n.getString("map.menu.titulo.puntoGenerico"));
    titulo.setFont(LogicConstants.deriveBoldFont(10.0f));
    titulo.setBackground(Color.decode("#A4A4A4"));
    titulo.setFocusable(false);

    menu.add(titulo);

    menu.addSeparator();

    // Actualizar posicin
    final JMenuItem gps = new JMenuItem(i18n.getString("map.menu.gps"), KeyEvent.VK_P);
    gps.setIcon(LogicConstants.getIcon("menucontextual_icon_actualizargps"));
    menu.add(gps);
    gps.addActionListener(this);
    gps.setEnabled(false);

    menu.addSeparator();

    // Mostrar ms cercanos
    final JMenuItem mmc = new JMenuItem(i18n.getString("map.menu.showNearest"), KeyEvent.VK_M);
    mmc.setIcon(LogicConstants.getIcon("menucontextual_icon_mascercano"));
    mmc.addActionListener(this);
    menu.add(mmc);
    // Centrar aqui
    final JMenuItem cent = new JMenuItem(i18n.getString("map.menu.centerHere"), KeyEvent.VK_C);
    cent.setIcon(LogicConstants.getIcon("menucontextual_icon_centrar"));
    cent.addActionListener(this);
    menu.add(cent);
    // Nueva Incidencia
    final JMenuItem newIncidence = new JMenuItem(i18n.getString("map.menu.newIncidence"), KeyEvent.VK_I);
    newIncidence.setIcon(LogicConstants.getIcon("menucontextual_icon_newIncidence"));
    newIncidence.addActionListener(this);
    menu.add(newIncidence);
    // Calcular ruta desde aqui
    final JMenuItem from = new JMenuItem(i18n.getString("map.menu.route.from"), KeyEvent.VK_D);
    from.setIcon(LogicConstants.getIcon("menucontextual_icon_origenruta"));
    from.addActionListener(this);
    menu.add(from);
    // Calcular ruta hasta aqui
    final JMenuItem to = new JMenuItem(i18n.getString("map.menu.route.to"), KeyEvent.VK_H);
    to.setIcon(LogicConstants.getIcon("menucontextual_icon_destinoruta"));
    to.addActionListener(this);
    menu.add(to);

    menu.addSeparator();

    // Ver ficha [recurso / incidencia]
    final JMenuItem summary = new JMenuItem(i18n.getString("map.menu.summary"), KeyEvent.VK_F);
    summary.setIcon(LogicConstants.getIcon("menucontextual_icon_ficha"));
    summary.addActionListener(this);
    menu.add(summary);
    summary.setEnabled(false);

    menu.addPopupMenuListener(new PopupMenuListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            eventOriginal = FleetControlMapViewer.this.mapView.lastMEvent;
            gps.setEnabled(false);
            summary.setEnabled(false);
            titulo.setText(i18n.getString("map.menu.titulo.puntoGenerico"));
            menuObjective = null;
            Point p = new Point(mapView.lastMEvent.getX(), mapView.lastMEvent.getY());
            for (Layer l : mapView.getAllLayers()) { // por cada capa...
                if (l instanceof MarkerLayer) { // ...de marcadores
                    for (Marker marker : ((MarkerLayer) l).data) { // miramos
                        // los
                        // marcadores
                        if ((marker instanceof CustomMarker) && marker.containsPoint(p)) { // y si
                            // estamos
                            // pinchando
                            // en uno
                            CustomMarker m = (CustomMarker) marker;
                            log.trace("Hemos pinchado en " + marker);

                            switch (m.getType()) {
                            case RESOURCE:
                                Recurso r = (Recurso) m.getObject();
                                log.trace("Es un recurso: " + r);
                                if (r != null) {
                                    menuObjective = r;
                                    if (r.getPatrullas() != null) {
                                        titulo.setText(
                                                i18n.getString(Locale.ROOT, "map.menu.titulo.recursoPatrulla",
                                                        r.getIdentificador(), r.getPatrullas()));
                                    } else {
                                        titulo.setText(r.getIdentificador());
                                    }
                                    gps.setEnabled(true);
                                    summary.setEnabled(true);
                                }
                                break;
                            case INCIDENCE:
                                Incidencia i = (Incidencia) m.getObject();
                                log.trace("Es una incidencia: " + i);
                                if (i != null) {
                                    menuObjective = i;
                                    titulo.setText(i.getTitulo());
                                    gps.setEnabled(false);
                                    summary.setEnabled(true);
                                }
                                break;
                            case UNKNOWN:
                                log.trace("Hemos pinchado en un marcador desconocido");
                                break;
                            }

                        }
                    }
                }
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
        }
    });

    return menu;
}