Example usage for javax.swing JMenuItem addActionListener

List of usage examples for javax.swing JMenuItem addActionListener

Introduction

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

Prototype

public void addActionListener(ActionListener l) 

Source Link

Document

Adds an ActionListener to the button.

Usage

From source file:gtu._work.ui.PropertyEditUI.java

private void initGUI() {
    try {// ww  w . j  a  v  a2s  .  c o  m
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        BorderLayout thisLayout = new BorderLayout();
        this.setTitle("PropertyEditUI");
        getContentPane().setLayout(thisLayout);
        {
            jMenuBar1 = new JMenuBar();
            setJMenuBar(jMenuBar1);
            {
                jMenu1 = new JMenu();
                jMenuBar1.add(jMenu1);
                jMenu1.setText("File");
                {
                    jMenuItem1 = new JMenuItem();
                    jMenu1.add(jMenuItem1);
                    jMenuItem1.setText("open directory");
                    jMenuItem1.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JCommonUtil._jFileChooser_selectDirectoryOnly();
                            loadCurrentFile(file);
                        }
                    });
                }
                {
                    openDirectoryAndChildren = new JMenuItem();
                    jMenu1.add(openDirectoryAndChildren);
                    openDirectoryAndChildren.setText("open directory and children");
                    openDirectoryAndChildren.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            System.out.println("openDirectoryAndChildren.actionPerformed, event=" + evt);
                            File file = JCommonUtil._jFileChooser_selectDirectoryOnly();
                            if (file == null) {
                                // file =
                                // PropertiesUtil.getJarCurrentPath(getClass());//XXX
                                file = new File("D:\\my_tool\\english");
                                JCommonUtil._jOptionPane_showMessageDialog_info("load C:\\L-CONFIG !");
                            }
                            DefaultListModel model = new DefaultListModel();
                            List<File> list = new ArrayList<File>();
                            FileUtil.searchFileMatchs(file, ".*\\.properties", list);
                            for (File f : list) {
                                File_ ff = new File_();
                                ff.file = f;
                                model.addElement(ff);
                            }
                            backupFileList = list;
                            fileList.setModel(model);
                        }
                    });
                }
                {
                    jMenuItem2 = new JMenuItem();
                    jMenu1.add(jMenuItem2);
                    jMenuItem2.setText("save");
                    jMenuItem2.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            System.out.println("jMenu3.actionPerformed, event=" + evt);
                            if (currentFile == null) {
                                return;
                            }
                            if (JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                    "save to " + currentFile.getName(), "SAVE")) {
                                try {
                                    Properties prop = new Properties();
                                    // try {
                                    // prop.load(new
                                    // FileInputStream(currentFile));
                                    // } catch (Exception e) {
                                    // e.printStackTrace();
                                    // JCommonUtil.handleException(e);
                                    // return;
                                    // }
                                    loadModelToProperties(prop);
                                    prop.store(new FileOutputStream(currentFile), getTitle());
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    JCommonUtil.handleException(e);
                                }
                            }
                        }
                    });
                }
                {
                    jMenuItem3 = new JMenuItem();
                    jMenu1.add(jMenuItem3);
                    jMenuItem3.setText("save to target");
                    jMenuItem3.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JFileChooserUtil.newInstance().selectFileOnly().showSaveDialog()
                                    .getApproveSelectedFile();
                            if (file == null) {
                                JCommonUtil._jOptionPane_showMessageDialog_error("file name is not correct!");
                                return;
                            }
                            if (!file.getName().contains(".properties")) {
                                file = new File(file.getParent(), file.getName() + ".properties");
                            }
                            try {
                                Properties prop = new Properties();
                                // try {
                                // prop.load(new
                                // FileInputStream(currentFile));
                                // } catch (Exception e) {
                                // e.printStackTrace();
                                // JCommonUtil.handleException(e);
                                // return;
                                // }
                                loadModelToProperties(prop);
                                prop.store(new FileOutputStream(file), getTitle());
                            } catch (Exception e) {
                                e.printStackTrace();
                                JCommonUtil.handleException(e);
                            }
                        }
                    });
                }
                {
                    jMenuItem4 = new JMenuItem();
                    jMenu1.add(jMenuItem4);
                    jMenuItem4.setText("save file(sorted)");
                    jMenuItem4.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            if (currentFile == null) {
                                return;
                            }
                            try {
                                BufferedReader reader = new BufferedReader(
                                        new InputStreamReader(new FileInputStream(currentFile)));
                                List<String> sortList = new ArrayList<String>();
                                for (String line = null; (line = reader.readLine()) != null;) {
                                    sortList.add(line);
                                }
                                reader.close();
                                Collections.sort(sortList);
                                StringBuilder sb = new StringBuilder();
                                for (String line : sortList) {
                                    sb.append(line + "\n");
                                }
                                FileUtil.saveToFile(currentFile, sb.toString(), "UTF8");
                            } catch (FileNotFoundException e) {
                                e.printStackTrace();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    });
                }
                {
                    jMenuItem5 = new JMenuItem();
                    jMenu1.add(jMenuItem5);
                    jMenuItem5.setText("");
                    jMenuItem5.addActionListener(new ActionListener() {
                        private void setMeaning(String meaning, int rowPos) {
                            propTable.getRowSorter().getModel().setValueAt(meaning, rowPos, 2);
                        }

                        private void setMeaningEn1(String english, int rowPos, List<String> errSb) {
                            EnglishTester_Diectory eng = new EnglishTester_Diectory();
                            try {
                                WordInfo wordInfo = eng.parseToWordInfo(english);
                                String meaning = getChs2Big5(wordInfo.getMeaning());
                                if (hasChinese(meaning)) {
                                    setMeaning(meaning, rowPos);
                                } else {
                                    setMeaningEn2(english, rowPos, errSb);
                                }
                            } catch (Exception e) {
                                errSb.add(english);
                                e.printStackTrace();
                            }
                        }

                        private void setMeaningEn2(String english, int rowPos, List<String> errSb) {
                            EnglishTester_Diectory2 eng2 = new EnglishTester_Diectory2();
                            try {
                                WordInfo2 wordInfo = eng2.parseToWordInfo(english);
                                String meaning = getChs2Big5(StringUtils.join(wordInfo.getMeaningList(), ";"));
                                setMeaning(meaning, rowPos);
                            } catch (Exception e) {
                                errSb.add(english);
                                e.printStackTrace();
                            }
                        }

                        private boolean hasChinese(String val) {
                            return new StringUtil_().getChineseWord(val, true).length() > 0;
                        }

                        private Properties loadFromMemoryBank() {
                            try {
                                Properties prop = new Properties();
                                File f1 = new File(
                                        "D:/gtu001_dropbox/Dropbox/Apps/gtu001_test/etc_config/EnglishSearchUI_MemoryBank.properties");
                                File f2 = new File(
                                        "e:/gtu001_dropbox/Dropbox/Apps/gtu001_test/etc_config/EnglishSearchUI_MemoryBank.properties");
                                for (File f : new File[] { f1, f2 }) {
                                    if (f.exists()) {
                                        HermannEbbinghaus_Memory memory = new HermannEbbinghaus_Memory();
                                        memory.init(f);
                                        List<MemData> memLst = memory.getAllMemData(true);
                                        for (MemData d : memLst) {
                                            prop.setProperty(d.getKey(), getChs2Big5(d.getRemark()));
                                        }
                                        break;
                                    }
                                }
                                return prop;
                            } catch (Exception ex) {
                                throw new RuntimeException(ex);
                            }
                        }

                        public void actionPerformed(ActionEvent evt) {
                            if (currentFile == null) {
                                return;
                            }

                            // Properties memoryProp = loadFromMemoryBank();
                            Properties memoryProp = new Properties();

                            List<String> errSb = new ArrayList<String>();
                            for (int row = 0; row < propTable.getModel().getRowCount(); row++) {
                                int rowPos = propTable.getRowSorter().convertRowIndexToModel(row);
                                String english = StringUtils.trimToEmpty(
                                        (String) propTable.getRowSorter().getModel().getValueAt(rowPos, 1))
                                        .toLowerCase();
                                String desc = (String) propTable.getRowSorter().getModel().getValueAt(rowPos,
                                        2);

                                if (memoryProp.containsKey(english)
                                        && StringUtils.isNotBlank(memoryProp.getProperty(english))) {
                                    setMeaning(memoryProp.getProperty(english), rowPos);
                                } else {
                                    if (StringUtils.isBlank(desc) || !hasChinese(desc)) {
                                        if (!english.contains(" ")) {
                                            setMeaningEn1(english, rowPos, errSb);
                                        } else {
                                            setMeaningEn2(english, rowPos, errSb);
                                        }
                                    }
                                }

                                if (StringUtils.trimToEmpty(desc).contains("?")) {
                                    setMeaning("", rowPos);
                                }
                            }
                            if (!errSb.isEmpty()) {
                                JCommonUtil._jOptionPane_showMessageDialog_error(":\n" + errSb);
                            }
                        }
                    });
                }

                {
                    JMenuItem jMenuItem6 = new JMenuItem();
                    jMenu1.add(jMenuItem6);
                    jMenuItem6.setText("");
                    jMenuItem6.addActionListener(new ActionListener() {
                        private void setMeaning(String meaning, int rowPos) {
                            propTable.getRowSorter().getModel().setValueAt(meaning, rowPos, 2);
                        }

                        public void actionPerformed(ActionEvent evt) {
                            for (int row = 0; row < propTable.getModel().getRowCount(); row++) {
                                int rowPos = propTable.getRowSorter().convertRowIndexToModel(row);
                                String english = StringUtils.trimToEmpty(
                                        (String) propTable.getRowSorter().getModel().getValueAt(rowPos, 1))
                                        .toLowerCase();
                                String desc = (String) propTable.getRowSorter().getModel().getValueAt(rowPos,
                                        2);

                                if (StringUtils.trimToEmpty(desc).contains("?")) {
                                    setMeaning("", rowPos);
                                }
                            }
                        }
                    });
                }
            }
        }
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("editor", null, jPanel2, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel2.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(550, 314));
                    {
                        TableModel propTableModel = new DefaultTableModel(
                                new String[][] { { "", "", "" }, { "", "", "" } },
                                new String[] { "index", "Key", "value" });
                        propTable = new JTable();
                        JTableUtil.defaultSetting_AutoResize(propTable);
                        jScrollPane1.setViewportView(propTable);
                        propTable.setModel(propTableModel);
                        propTable.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                JTableUtil xxxxxx = JTableUtil.newInstance(propTable);
                                int[] rows = xxxxxx.getSelectedRows();
                                for (int ii : rows) {
                                    System.out.println(xxxxxx.getModel().getValueAt(ii, 1));
                                }
                                JPopupMenuUtil.newInstance(propTable).applyEvent(evt)
                                        .addJMenuItem(JTableUtil.newInstance(propTable).getDefaultJMenuItems())
                                        .show();
                            }
                        });
                    }
                }
                {
                    queryText = new JTextField();
                    jPanel2.add(queryText, BorderLayout.NORTH);
                    queryText.getDocument()
                            .addDocumentListener(JCommonUtil.getDocumentListener(new HandleDocumentEvent() {

                                @Override
                                public void process(DocumentEvent event) {
                                    if (currentFile == null) {
                                        return;
                                    }
                                    Properties prop = new Properties();
                                    try {
                                        prop.load(new FileInputStream(currentFile));
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        JCommonUtil.handleException(e);
                                        return;
                                    }
                                    loadPropertiesToModel(prop);
                                    String text = JCommonUtil.getDocumentText(event);
                                    Pattern pattern = null;
                                    try {
                                        pattern = Pattern.compile(text);
                                    } catch (Exception ex) {
                                    }

                                    DefaultTableModel model = JTableUtil.newInstance(propTable).getModel();
                                    for (int ii = 0; ii < model.getRowCount(); ii++) {
                                        String key = (String) model.getValueAt(ii, 1);
                                        String value = (String) model.getValueAt(ii, 2);
                                        if (key.contains(text)) {
                                            continue;
                                        }
                                        if (value.contains(text)) {
                                            continue;
                                        }
                                        if (pattern != null) {
                                            if (pattern.matcher(key).find()) {
                                                continue;
                                            }
                                            if (pattern.matcher(value).find()) {
                                                continue;
                                            }
                                        }
                                        model.removeRow(propTable.convertRowIndexToModel(ii));
                                        ii--;
                                    }
                                }
                            }));
                }
            }
            {
                jPanel3 = new JPanel();
                BorderLayout jPanel3Layout = new BorderLayout();
                jPanel3.setLayout(jPanel3Layout);
                jTabbedPane1.addTab("folder", null, jPanel3, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel3.add(jScrollPane2, BorderLayout.CENTER);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(550, 314));
                    {
                        fileList = new JList();
                        jScrollPane2.setViewportView(fileList);
                        fileList.addKeyListener(new KeyAdapter() {
                            public void keyPressed(KeyEvent evt) {
                                JListUtil.newInstance(fileList).defaultJListKeyPressed(evt);
                            }
                        });
                        fileList.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                final File_ file = JListUtil.getLeadSelectionObject(fileList);

                                if (evt.getButton() == MouseEvent.BUTTON1) {
                                    Properties prop = new Properties();
                                    currentFile = file.file;
                                    setTitle(currentFile.getName());
                                    try {
                                        prop.load(new FileInputStream(file.file));
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                    loadPropertiesToModel(prop);
                                }

                                if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2) {
                                    try {
                                        Runtime.getRuntime().exec(String.format("cmd /c \"%s\"", file.file));
                                    } catch (IOException e1) {
                                        e1.printStackTrace();
                                    }
                                }

                                final File parent = file.file.getParentFile();
                                JMenuItem openTargetDir = new JMenuItem();
                                openTargetDir.setText("open : " + parent);
                                openTargetDir.addActionListener(new ActionListener() {
                                    @Override
                                    public void actionPerformed(ActionEvent e) {
                                        try {
                                            Desktop.getDesktop().open(parent);
                                        } catch (IOException e1) {
                                            JCommonUtil.handleException(e1);
                                        }
                                    }
                                });

                                JPopupMenuUtil.newInstance(fileList).addJMenuItem(openTargetDir).applyEvent(evt)
                                        .show();
                            }
                        });
                    }
                }
                {
                    fileQueryText = new JTextField();
                    jPanel3.add(fileQueryText, BorderLayout.NORTH);
                    fileQueryText.getDocument()
                            .addDocumentListener(JCommonUtil.getDocumentListener(new HandleDocumentEvent() {
                                @Override
                                public void process(DocumentEvent event) {
                                    String text = JCommonUtil.getDocumentText(event);
                                    DefaultListModel model = new DefaultListModel();
                                    for (File f : backupFileList) {
                                        if (f.getName().contains(text)) {
                                            File_ ff = new File_();
                                            ff.file = f;
                                            model.addElement(ff);
                                        }
                                    }
                                    fileList.setModel(model);
                                }
                            }));
                }
                {
                    contentQueryText = new JTextField();
                    jPanel3.add(contentQueryText, BorderLayout.SOUTH);
                    contentQueryText.addActionListener(new ActionListener() {

                        void addModel(File f, DefaultListModel model) {
                            File_ ff = new File_();
                            ff.file = f;
                            model.addElement(ff);
                        }

                        public void actionPerformed(ActionEvent evt) {
                            DefaultListModel model = new DefaultListModel();
                            String text = contentQueryText.getText();
                            if (StringUtils.isEmpty(contentQueryText.getText())) {
                                return;
                            }
                            Pattern pattern = Pattern.compile(text);
                            Properties pp = null;
                            for (File f : backupFileList) {
                                pp = new Properties();
                                try {
                                    pp.load(new FileInputStream(f));
                                    for (String key : pp.stringPropertyNames()) {
                                        if (key.isEmpty()) {
                                            continue;
                                        }
                                        if (pp.getProperty(key) == null || pp.getProperty(key).isEmpty()) {
                                            continue;
                                        }
                                        if (key.contains(text)) {
                                            addModel(f, model);
                                            break;
                                        }
                                        if (pp.getProperty(key).contains(text)) {
                                            addModel(f, model);
                                            break;
                                        }
                                        if (pattern.matcher(key).find()) {
                                            addModel(f, model);
                                            break;
                                        }
                                        if (pattern.matcher(pp.getProperty(key)).find()) {
                                            addModel(f, model);
                                            break;
                                        }
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                            fileList.setModel(model);
                        }
                    });
                }
            }
        }
        JCommonUtil.setJFrameIcon(this, "resource/images/ico/english.ico");
        JCommonUtil.setJFrameCenter(this);
        pack();
        this.setSize(571, 408);

        loadCurrentFile(null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:io.heming.accountbook.ui.MainFrame.java

private void initTablePopupMenu() {
    JPopupMenu popupMenu = new JPopupMenu();

    JMenuItem deleteMenuItem = new JMenuItem("(D)",
            new ImageIcon(getClass().getResource("edit-delete-6.png")));
    deleteMenuItem.setMnemonic('D');
    popupMenu.add(deleteMenuItem);//from   ww  w. j  av  a2  s.c  om
    deleteMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            deleteRecord();
        }
    });

    popupMenu.addSeparator();

    JMenuItem editMenuItem = new JMenuItem("(E)", new ImageIcon(getClass().getResource("edit-4.png")));
    editMenuItem.setMnemonic('E');
    popupMenu.add(editMenuItem);
    editMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Record record = model.getRecord(table.convertRowIndexToModel(table.getSelectedRow()));
            showUpdateRecordDialog(record);
        }
    });

    // ??popup menu
    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (disable)
                return;
            JTable table = (JTable) e.getSource();
            Point point = e.getPoint();
            int row = table.rowAtPoint(point);
            int col = table.columnAtPoint(e.getPoint());
            if (SwingUtilities.isRightMouseButton(e)) {
                if (row >= 0 && col >= 0) {
                    table.setRowSelectionInterval(row, row);
                }
                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            } else if (SwingUtilities.isLeftMouseButton(e)) {
                if (e.getClickCount() == 2) {
                    if (row >= 0 && col >= 0) {
                        //                            Record record = model.getRecord(table.convertRowIndexToModel(row));
                        //                            showUpdateRecordDialog(record);
                    }
                }
            }
        }

    });

    table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter");
    table.getActionMap().put("Enter", new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            if (disable)
                return;
            //do something on JTable enter pressed
            int row = table.getSelectedRow();
            if (row >= 0) {
                Record record = model.getRecord(table.convertRowIndexToModel(row));
                showUpdateRecordDialog(record);
            }
        }
    });

}

From source file:com.fratello.longevity.smooth.AppGUI.java

private void initialize() {
    LabelMaxSize = 0;/* w  w w .j  ava 2 s. co m*/

    ActiveGUI = true;
    GUI_Start = false;
    GUI_Pause = true;
    GUI_Stop = false;
    ran_at_least_once = false;

    execute();

    initializeFields();

    frmFileSystemSearch = new JFrame();
    frmFileSystemSearch.setTitle("Smooth Longevity Fratello");
    frmFileSystemSearch.setBounds(100, 100, 450, 300);
    frmFileSystemSearch.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frmFileSystemSearch.setResizable(false);

    UIManager.put("PopupMenu.border", BorderFactory.createLineBorder(Color.black, 1));

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

    JMenu mnNewMenu = new JMenu("File");
    menuBar.add(mnNewMenu);

    JMenuItem mntmFirst = new JMenuItem("Open Directory");
    mntmFirst.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            openFileChooserDir(mntmFirst);
        }
    });
    mnNewMenu.add(mntmFirst);

    JMenuItem mntmExit = new JMenuItem("Exit");
    mntmExit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            frmFileSystemSearch.dispose();
        }
    });
    mnNewMenu.add(mntmExit);

    JMenu mnHelp = new JMenu("Help");
    menuBar.add(mnHelp);

    JMenuItem mntmAbout = new JMenuItem("About");
    mnHelp.add(mntmAbout);

    JMenuItem mntmTutorials = new JMenuItem("Tutorials");
    mnHelp.add(mntmTutorials);

    JMenuItem mntmCheckForUpdates = new JMenuItem("Check for Updates");
    mnHelp.add(mntmCheckForUpdates);

    String ppallink = "https://www.paypal.com/cgi-bin/webscr" + "?cmd=" + "_donations" + "&business="
            + "8YUJNSN6KFV54" + "&lc=" + "US" + "&item_name="
            + "Personal%20funds%20for%20programming%20at%20university" + "&currency_code=" + "USD" + "&bn="
            + "PP%2dDonationsBF" + "%3abtn_donateCC_LG%2egif%3aNonHosted";

    JButton btnDonate = new JButton("Donate");
    btnDonate.setToolTipText("<html>Open default Internet browser <br>(Chrome, FireFox, etc.)</html>");
    btnDonate.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            openWebPage(ppallink);
        }
    });
    btnDonate.setBounds(159, 176, 90, 25);
    menuBar.add(btnDonate);

    JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    frmFileSystemSearch.getContentPane().add(tabbedPane, BorderLayout.CENTER);

    // ---------------------------- JPanels ------------------------------
    JPanel panel = new JPanel();
    tabbedPane.addTab("Start Directory", null, panel, null);

    JPanel panel_1 = new JPanel();
    tabbedPane.addTab("Search Setup", null, panel_1, null);
    panel_1.setLayout(null);

    JPanel panel_2 = new JPanel();
    tabbedPane.addTab("Run Program", null, panel_2, null);
    panel_2.setLayout(null);

    JPanel panel_3 = new JPanel();
    tabbedPane.addTab("Information", null, panel_3, null);
    panel_3.setBounds(10, 11, 409, 154);
    GridBagLayout gbl_panel_3 = new GridBagLayout();
    gbl_panel_3.columnWidths = new int[] { 0, 0, 0 };
    gbl_panel_3.rowHeights = new int[] { 0, 0, 0 };
    gbl_panel_3.columnWeights = new double[] { 1.0, 1.0, 1.0 };
    gbl_panel_3.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
    panel_3.setLayout(gbl_panel_3);

    // ------------- Dynamic Update - Swingworker Components -------------
    SentinelProgressBar = new JProgressBar();
    SentinelProgressBar.setMaximumSize(new Dimension(146, 14));
    SentinelProgressBar.setMaximum(1000);
    SentinelProgressBar.setBounds(74, 187, 146, 14);
    panel_2.add(SentinelProgressBar);

    SentinelProgressLabel = new JLabel();
    SentinelProgressLabel.setToolTipText("Time needed to finish the program in progress");
    SentinelProgressLabel.setBounds(333, 181, 86, 20);
    panel_2.add(SentinelProgressLabel);

    // -------------------------------------------------------------------
    // ------------------------ JPanel Components ------------------------
    JLabel lblCurrentDirectory = new JLabel("Current Directory");
    panel.add(lblCurrentDirectory);

    userSelectedDirectories = new JTextField();
    panel.add(userSelectedDirectories);
    userSelectedDirectories.setColumns(35);

    JButton btnBrowse = new JButton("Browse");
    btnBrowse.setToolTipText("Locate directory in system");
    btnBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            openFileChooserDir(btnBrowse);
        }
    });
    panel.add(btnBrowse);

    JButton btnClear = new JButton("Clear");
    btnClear.setToolTipText("Deletes the current directory shown");
    btnClear.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            userSelectedDirectories.setText("");
            clearSourceDirectory();
        }
    });
    panel.add(btnClear);

    // -------------------------------------------------------------------
    // ----------------------- JPanel_1 Components -----------------------

    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // Extension :: [Check Box]
    chckbxExt = new JCheckBox("Extension");
    chckbxExt.setToolTipText("Check to ignore file extensions");
    chckbxExt.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED)
                cf.setUse("Ext", true);
            else if (e.getStateChange() == ItemEvent.DESELECTED)
                cf.setUse("Ext", false);
        }
    });
    chckbxExt.setBounds(8, 15, 97, 23);
    panel_1.add(chckbxExt);

    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // Hash :: [Check Box]
    chckbxHash = new JCheckBox("Hash");
    chckbxHash.setToolTipText("Check to compare by hashing files (FAST)");
    chckbxHash.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED)
                cf.setUse("Hash", true);
            else if (e.getStateChange() == ItemEvent.DESELECTED)
                cf.setUse("Hash", false);
        }
    });
    chckbxHash.setBounds(8, 45, 97, 23);
    panel_1.add(chckbxHash);

    // Hash :: [Combo Box]
    comboBoxHash = new JComboBox<String>();
    comboBoxHash.setToolTipText(
            "<html>Hash algorithm to use in file hashing <br>(note - SHA-512 may not be <br>supported by your computer)</html>");
    comboBoxHash.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            @SuppressWarnings("unchecked")
            JComboBox<String> cb = (JComboBox<String>) e.getSource();
            String UIselect = (String) cb.getSelectedItem();
            cf.setHashString(UIselect);
        }
    });
    comboBoxHash
            .setModel(new DefaultComboBoxModel<String>(new String[] { "MD5", "SHA-1", "SHA-256", "SHA-512" }));
    comboBoxHash.setBounds(150, 44, 75, 25);
    panel_1.add(comboBoxHash);

    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // Name :: [Check Box]
    chckbxName = new JCheckBox("Name");
    chckbxName.setToolTipText("Name tool-tip goes here");
    chckbxName.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED)
                cf.setUse("Name", true);
            else if (e.getStateChange() == ItemEvent.DESELECTED)
                cf.setUse("Name", false);
        }
    });
    chckbxName.setBounds(8, 75, 97, 23);
    panel_1.add(chckbxName);

    // Name :: [Text Field]
    namePercentMatchTextField = new JFormattedTextField(new Double(0.0d));
    namePercentMatchTextField.setFormatterFactory(new DoubleDocListener(namePercentMatchTextField));
    namePercentMatchTextField.getDocument()
            .addDocumentListener(new DoubleDocListener(namePercentMatchTextField));
    namePercentMatchTextField.setToolTipText("Match file names by percentage [00.00-100.00]");
    namePercentMatchTextField.setBounds(150, 74, 110, 25);
    panel_1.add(namePercentMatchTextField);
    namePercentMatchTextField.setColumns(10);

    // Name :: [Combo Box]
    comboBoxNames = new JComboBox<String>();
    comboBoxNames.setToolTipText("Algorithm to compare names");
    comboBoxNames.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            @SuppressWarnings("unchecked")
            JComboBox<String> cb = (JComboBox<String>) e.getSource();
            String UIselect = (String) cb.getSelectedItem();
            cf.setMatchingAlgorithm(UIselect);
        }
    });
    comboBoxNames.setModel(new DefaultComboBoxModel<String>(new String[] { "Bitap", "Cosine",
            "DamerauLevenshtein", "DynamicTimeWarpingStandard1", "DynamicTimeWarpingStandard2", "Hamming",
            "Hirschberg", "JaccardIndex", "JaroWinkler", "Levenshtein", "NeedlemanWunsch", "SmithWaterman",
            "SorensenSimilarityIndex", "WagnerFischer" }));
    comboBoxNames.setBounds(265, 74, 150, 25);
    panel_1.add(comboBoxNames);

    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // Size :: [Check Box]
    chckbxSize = new JCheckBox("Size");
    chckbxSize.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED)
                cf.setUse("Size", true);
            else if (e.getStateChange() == ItemEvent.DESELECTED)
                cf.setUse("Size", false);
        }
    });
    chckbxSize.setBounds(8, 105, 97, 23);
    panel_1.add(chckbxSize);

    // Size :: [Text Field]
    sizePercentMatchTextField = new JFormattedTextField(new Double(0.0d));
    sizePercentMatchTextField.setFormatterFactory(new DoubleDocListener(sizePercentMatchTextField));
    sizePercentMatchTextField.getDocument()
            .addDocumentListener(new DoubleDocListener(sizePercentMatchTextField));
    sizePercentMatchTextField.setToolTipText("Match file sizes by percentage [00.00-100.00]");
    sizePercentMatchTextField.setBounds(150, 104, 110, 25);
    panel_1.add(sizePercentMatchTextField);
    sizePercentMatchTextField.setColumns(10);

    // Size :: [Combo Box]
    comboBoxSize = new JComboBox<String>();
    comboBoxSize.setToolTipText("Specify byte grouping");
    comboBoxSize.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            @SuppressWarnings("unchecked")
            JComboBox<String> cb = (JComboBox<String>) e.getSource();
            String UIselect = (String) cb.getSelectedItem();
            cf.setMetricSize(UIselect);
        }
    });
    comboBoxSize.setModel(
            new DefaultComboBoxModel<String>(new String[] { "BYTE", "KILOBYTE", "MEGABYTE", "GIGABYTE" }));
    comboBoxSize.setBounds(265, 104, 150, 25);
    panel_1.add(comboBoxSize);

    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // Thorough :: [Check Box]
    chckbxThorough = new JCheckBox("Thorough");
    chckbxThorough.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED)
                cf.setUse("Thorough", true);
            else if (e.getStateChange() == ItemEvent.DESELECTED)
                cf.setUse("Thorough", false);
        }
    });
    chckbxThorough.setToolTipText("Check byte by byte");
    chckbxThorough.setBounds(8, 135, 97, 23);
    panel_1.add(chckbxThorough);

    // Thorough :: [Text Field]
    thoroughPercentMatchTextField = new JFormattedTextField(new Double(0.0d));
    thoroughPercentMatchTextField.setFormatterFactory(new DoubleDocListener(thoroughPercentMatchTextField));
    thoroughPercentMatchTextField.getDocument()
            .addDocumentListener(new DoubleDocListener(thoroughPercentMatchTextField));
    thoroughPercentMatchTextField.setToolTipText("Match file sizes by percentage [00.00-100.00]");
    thoroughPercentMatchTextField.setBounds(150, 134, 110, 25);
    panel_1.add(thoroughPercentMatchTextField);
    thoroughPercentMatchTextField.setColumns(10);

    // Thorough :: [Check Box]
    chckbxExitFast = new JCheckBox("Exit Fast");
    chckbxExitFast.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED)
                cf.setThoroughExitFirstByteMisMatch(true);
            else if (e.getStateChange() == ItemEvent.DESELECTED)
                cf.setThoroughExitFirstByteMisMatch(false);
        }
    });
    chckbxExitFast.setToolTipText("<html>When the first byte comparison <br>is a mis-match then stop</html>");
    chckbxExitFast.setBounds(265, 138, 105, 16);
    panel_1.add(chckbxExitFast);

    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    JButton btnSaveSearchSettings = new JButton("Save Search Settings");
    btnSaveSearchSettings.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            pollSearchSettings();
            cf.saveObject();
            // System.out.println(cf.toString()); // debug
        }
    });
    btnSaveSearchSettings.setBounds(292, 181, 140, 25);
    panel_1.add(btnSaveSearchSettings);

    JButton btnLoadSettings = new JButton("Load Settings");
    btnLoadSettings.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (!cf.loadObject())
                cf.setDefaultSettings();
            cacheUpdateGUISettings();
        }
    });
    btnLoadSettings.setBounds(148, 181, 140, 25);
    panel_1.add(btnLoadSettings);

    JButton btnDefaultSettings = new JButton("Use Default Settings");
    btnDefaultSettings.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            cf.setDefaultSettings();
            cacheUpdateGUISettings();
        }
    });
    btnDefaultSettings.setBounds(4, 181, 140, 25);
    panel_1.add(btnDefaultSettings);

    // -------------------------------------------------------------------
    // ----------------------- JPanel_2 Components -----------------------
    JLabel labelStatus = new JLabel("Progress");
    labelStatus.setBounds(10, 187, 54, 14);
    panel_2.add(labelStatus);

    JButton btnStart = new JButton("Start");
    btnStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            pollSearchSettings();
            if (!ran_at_least_once)
                ran_at_least_once = true;
            else {
                SentinelProgressBar.setValue(0);
                SentinelProgressLabel.setText("Waiting...");
            }
            try {
                if (multiSelection == null) {
                    JOptionPane.showMessageDialog(btnStart, "Please enter at least one directory.",
                            "Press OK to continue", JOptionPane.PLAIN_MESSAGE);
                    return;
                }
                setSourceDirectory(multiSelection);
                GUI_Start = true;
            } catch (Exception err) {
                err.printStackTrace();
            }
        }
    });
    btnStart.setBounds(40, 153, 89, 23);
    panel_2.add(btnStart);

    JButton btnStop = new JButton("Stop");
    btnStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            GUI_Stop = true;
        }
    });
    btnStop.setBounds(169, 153, 89, 23);
    panel_2.add(btnStop);

    JButton btnNewButton = new JButton("Pause");
    btnNewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            GUI_Pause = true;
        }
    });
    btnNewButton.setBounds(298, 153, 89, 23);
    panel_2.add(btnNewButton);

    JCheckBox chckbxDeleteDuplicateFiles = new JCheckBox("Delete duplicate files");
    chckbxDeleteDuplicateFiles.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            deleteCopyResults = true;
        }
    });
    chckbxDeleteDuplicateFiles.setBounds(230, 10, 150, 16);
    panel_2.add(chckbxDeleteDuplicateFiles);

    JCheckBox chckbxLogDuplicateFiles = new JCheckBox("Save duplicates to file");
    chckbxLogDuplicateFiles.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            saveCopyResults = true;
        }
    });
    chckbxLogDuplicateFiles.setBounds(230, 36, 150, 16);
    panel_2.add(chckbxLogDuplicateFiles);

    // -------------------------------------------------------------------
    // ----------------------- JPanel_3 Components -----------------------

    JLabel lblAbout = new JLabel("About");
    GridBagConstraints gbc_lblAbout = new GridBagConstraints();
    gbc_lblAbout.insets = new Insets(0, 0, 5, 5);
    gbc_lblAbout.gridx = 0;
    gbc_lblAbout.gridy = 0;
    panel_3.add(lblAbout, gbc_lblAbout);

    JLabel lblTutorials = new JLabel("Tutorials");
    GridBagConstraints gbc_lblTutorials = new GridBagConstraints();
    gbc_lblTutorials.insets = new Insets(0, 0, 5, 5);
    gbc_lblTutorials.gridx = 1;
    gbc_lblTutorials.gridy = 0;
    panel_3.add(lblTutorials, gbc_lblTutorials);

    JLabel lblUpdates = new JLabel("Updates");
    GridBagConstraints gbc_lblUpdates = new GridBagConstraints();
    gbc_lblUpdates.insets = new Insets(0, 0, 5, 0);
    gbc_lblUpdates.gridx = 2;
    gbc_lblUpdates.gridy = 0;
    panel_3.add(lblUpdates, gbc_lblUpdates);

    JButton btnInformation = new JButton("Information");
    btnInformation.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            openWebPage(ppallink);
        }
    });
    GridBagConstraints gbc_btnInformation = new GridBagConstraints();
    gbc_btnInformation.insets = new Insets(0, 0, 0, 5);
    gbc_btnInformation.gridx = 0;
    gbc_btnInformation.gridy = 1;
    panel_3.add(btnInformation, gbc_btnInformation);

    JButton btnExamples = new JButton("Examples");
    btnExamples.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            openWebPage(ppallink);
        }
    });
    GridBagConstraints gbc_btnExamples = new GridBagConstraints();
    gbc_btnExamples.insets = new Insets(0, 0, 0, 5);
    gbc_btnExamples.gridx = 1;
    gbc_btnExamples.gridy = 1;
    panel_3.add(btnExamples, gbc_btnExamples);

    JButton btnCheckNow = new JButton("Check Now");
    btnCheckNow.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            openWebPage(ppallink);
        }
    });
    GridBagConstraints gbc_btnCheckNow = new GridBagConstraints();
    gbc_btnCheckNow.gridx = 2;
    gbc_btnCheckNow.gridy = 1;
    panel_3.add(btnCheckNow, gbc_btnCheckNow);
}

From source file:au.org.ala.delta.editor.DeltaEditor.java

private void buildWindowMenu(JMenu mnuWindow) {
    mnuWindow.removeAll();/*from   ww  w. ja v  a 2  s.com*/

    JMenuItem mnuItCascade = new JMenuItem();
    mnuItCascade.setAction(_actionMap.get("cascadeFrames"));
    mnuWindow.add(mnuItCascade);

    JMenuItem mnuItTile = new JMenuItem();
    mnuItTile.setAction(_actionMap.get("tileFrames"));
    mnuWindow.add(mnuItTile);

    JMenuItem mnuItTileHorz = new JMenuItem();
    mnuItTileHorz.setAction(_actionMap.get("tileFramesHorizontally"));
    mnuWindow.add(mnuItTileHorz);

    JMenuItem mnuItArrangeIcons = new JMenuItem();
    mnuItArrangeIcons.setAction(_actionMap.get("arrangeIcons"));
    mnuWindow.add(mnuItArrangeIcons);

    JMenuItem mnuItCloseAll = new JMenuItem();
    mnuItCloseAll.setAction(_actionMap.get("closeAllFrames"));
    mnuWindow.add(mnuItCloseAll);

    mnuWindow.addSeparator();

    JMenuItem mnuItChooseFont = new JMenuItem();
    mnuItChooseFont.setAction(_actionMap.get("chooseFont"));
    mnuWindow.add(mnuItChooseFont);

    mnuWindow.addSeparator();

    JMenu mnuLF = new JMenu();
    mnuLF.setName("mnuLF");
    mnuLF.setText(_resourceMap.getString("mnuLF.text"));
    mnuWindow.add(mnuLF);

    JMenuItem mnuItMetalLF = new JMenuItem();
    mnuItMetalLF.setAction(_actionMap.get("metalLookAndFeel"));
    mnuLF.add(mnuItMetalLF);

    JMenuItem mnuItWindowsLF = new JMenuItem();
    mnuItWindowsLF.setAction(_actionMap.get("systemLookAndFeel"));
    mnuLF.add(mnuItWindowsLF);

    try {
        // Nimbus L&F was added in update java 6 update 10.
        Class.forName("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel").newInstance();
        JMenuItem mnuItNimbusLF = new JMenuItem();
        mnuItNimbusLF.setAction(_actionMap.get("nimbusLookAndFeel"));
        mnuLF.add(mnuItNimbusLF);
    } catch (Exception e) {
        // The Nimbus L&F is not available, no matter.
    }
    mnuWindow.addSeparator();

    int i = 1;
    for (final JInternalFrame frame : _frames) {
        JMenuItem windowItem = new JCheckBoxMenuItem();
        if (i < 10) {
            windowItem.setText(String.format("%d %s", i, frame.getTitle()));
            windowItem.setMnemonic(KeyEvent.VK_1 + (i - 1));
        } else {
            windowItem.setText(frame.getTitle());
        }
        windowItem.setSelected(frame.isSelected());
        windowItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    frame.setSelected(true);
                } catch (PropertyVetoException e1) {
                }
            }
        });
        mnuWindow.add(windowItem);
        ++i;
    }

}

From source file:gdt.jgui.entity.edge.JBondsPanel.java

/**
 * Get the context menu.//from   ww  w.j  a  va  2 s. co 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 = JBondsPanel.this.listSelectedItems();
                            if (sa == null)
                                return;
                            for (String s : sa) {
                                //   System.out.println("JBondsPanel:delete:s="+s);
                                if (isGraphEntity())
                                    removeBondEntry(s);
                                else if (isEdgeEntity())
                                    removeBond(console, s);
                                else if (isDetailEntity()) {
                                    System.out.println("JBondsPanel:delete detail:");
                                    Entigrator entigrator = console.getEntigrator(entihome$);
                                    BondDetailHandler.deleteDetail(entigrator, s);
                                }
                            }
                            close();
                            JBondsPanel bp = new JBondsPanel();
                            String bpLocator$ = bp.getLocator();
                            bpLocator$ = Locator.append(bpLocator$, Entigrator.ENTIHOME, entihome$);
                            bpLocator$ = Locator.append(bpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                            JConsoleHandler.execute(console, bpLocator$);
                        }
                    }
                });

                menu.add(deleteItem);
                JMenuItem copyItem = new JMenuItem("Copy");
                copyItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {

                        String[] sa = JBondsPanel.this.listSelectedItems();
                        if (sa == null)
                            return;

                        for (String s : sa) {
                            console.clipboard.putString(s);
                        }
                    }
                });
                menu.add(copyItem);

                menu.addSeparator();
            }
            if (isEdgeEntity()) {
                JMenuItem newItem = new JMenuItem("New");
                newItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        //System.out.println("JBondsPanel:new:"+locator$);

                        Entigrator entigrator = console.getEntigrator(entihome$);
                        Sack entity = entigrator.getEntityAtKey(entityKey$);
                        if (!entity.existsElement("bond"))
                            entity.createElement("bond");
                        String bondKey$ = Identity.key();
                        entity.putElementItem("bond", new Core(null, bondKey$, null));
                        //   String icon$=Support.readHandlerIcon(JEntitiesPanel.class, "globe.png");
                        entigrator.save(entity);
                        // JBondsPanel.this.getPanel().removeAll();
                        close();
                        JBondsPanel bp = new JBondsPanel();
                        String bpLocator$ = bp.getLocator();
                        bpLocator$ = Locator.append(bpLocator$, Entigrator.ENTIHOME, entihome$);
                        bpLocator$ = Locator.append(bpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                        //bpLocator$=Locator.append(bpLocator$, BaseHandler.HANDLER_METHOD,"instantiate");
                        JConsoleHandler.execute(console, bpLocator$);

                    }
                });
                menu.add(newItem);
            }
            if (isGraphEntity()) {
                JMenuItem showItem = new JMenuItem("Show");
                showItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            JGraphRenderer gr = new JGraphRenderer();
                            String grLocator$ = gr.getLocator();
                            grLocator$ = Locator.append(grLocator$, Entigrator.ENTIHOME, entihome$);
                            grLocator$ = Locator.append(grLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                            JConsoleHandler.execute(console, grLocator$);
                        } catch (Exception ee) {
                            Logger.getLogger(JGraphRenderer.class.getName()).info(ee.toString());
                        }
                    }
                });
                menu.add(showItem);

                if (hasBondsToPaste()) {
                    JMenuItem pasteItem = new JMenuItem("Paste");
                    pasteItem.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            pasteBonds();
                            JBondsPanel bp = new JBondsPanel();
                            String bpLocator$ = bp.getLocator();
                            bpLocator$ = Locator.append(bpLocator$, Entigrator.ENTIHOME, entihome$);
                            bpLocator$ = Locator.append(bpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                            JConsoleHandler.execute(console, bpLocator$);
                        }
                    });
                    menu.add(pasteItem);
                }
            }

            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(JBondsPanel.class.getName()).severe(ee.toString());
                        }
                    } else
                        console.back();
                }
            });
            menu.add(doneItem);
            menu.addSeparator();
            JMenuItem sortInNode = new JMenuItem("Sort in node");
            sortInNode.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        selectMode$ = SELECT_MODE_IN;
                        JItemPanel[] ipa = getItems();
                        Entigrator entigrator = console.getEntigrator(entihome$);
                        InNodeComparator inc = new InNodeComparator();
                        inc.entigrator = entigrator;
                        ArrayList<JItemPanel> ipl = new ArrayList<JItemPanel>(Arrays.asList(ipa));

                        Collections.sort(ipl, inc);
                        panel.removeAll();
                        //         System.out.println("JBondsPanel:sort in node:ipl="+ipl.size());
                        if (ipa != null)
                            for (JItemPanel ip : ipl) {
                                panel.add(ip);
                            }
                        revalidate();
                        repaint();
                        Sack entity = entigrator.getEntityAtKey(entityKey$);
                        if (!entity.existsElement("parameter"))
                            entity.createElement("parameter");
                        entity.putElementItem("parameter", new Core(null, SELECT_MODE, selectMode$));
                        entigrator.save(entity);
                    } catch (Exception ee) {
                    }
                }
            });
            menu.add(sortInNode);
            JMenuItem sortOutNode = new JMenuItem("Sort out node");
            sortOutNode.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        selectMode$ = SELECT_MODE_OUT;
                        JItemPanel[] ipa = getItems();
                        ArrayList<JItemPanel> ipl = new ArrayList<JItemPanel>(Arrays.asList(ipa));
                        Collections.sort(ipl, new ItemPanelComparator());
                        panel.removeAll();
                        System.out.println("JBondsPanel:sort out node:ipl=" + ipl.size());
                        if (ipa != null)
                            for (JItemPanel ip : ipl) {
                                panel.add(ip);
                            }
                        revalidate();
                        repaint();
                        Entigrator entigrator = console.getEntigrator(entihome$);
                        Sack entity = entigrator.getEntityAtKey(entityKey$);
                        if (!entity.existsElement("parameter"))
                            entity.createElement("parameter");
                        entity.putElementItem("parameter", new Core(null, SELECT_MODE, selectMode$));
                        entigrator.save(entity);
                    } catch (Exception ee) {
                    }
                }
            });
            menu.add(sortOutNode);
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

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

From source file:net.sf.jabref.gui.openoffice.OpenOfficePanel.java

private void showSettingsPopup() {
    JPopupMenu menu = new JPopupMenu();
    final JCheckBoxMenuItem autoSync = new JCheckBoxMenuItem(
            Localization.lang("Automatically sync bibliography when inserting citations"),
            preferences.syncWhenCiting());
    final JRadioButtonMenuItem useActiveBase = new JRadioButtonMenuItem(
            Localization.lang("Look up BibTeX entries in the active tab only"));
    final JRadioButtonMenuItem useAllBases = new JRadioButtonMenuItem(
            Localization.lang("Look up BibTeX entries in all open databases"));
    final JMenuItem clearConnectionSettings = new JMenuItem(Localization.lang("Clear connection settings"));
    ButtonGroup bg = new ButtonGroup();
    bg.add(useActiveBase);//from  w  ww.java2s. com
    bg.add(useAllBases);
    if (preferences.useAllDatabases()) {
        useAllBases.setSelected(true);
    } else {
        useActiveBase.setSelected(true);
    }

    autoSync.addActionListener(e -> preferences.setSyncWhenCiting(autoSync.isSelected()));

    useAllBases.addActionListener(e -> preferences.setUseAllDatabases(useAllBases.isSelected()));

    useActiveBase.addActionListener(e -> preferences.setUseAllDatabases(!useActiveBase.isSelected()));

    clearConnectionSettings.addActionListener(e -> frame.output(preferences.clearConnectionSettings()));

    menu.add(autoSync);
    menu.addSeparator();
    menu.add(useActiveBase);
    menu.add(useAllBases);
    menu.addSeparator();
    menu.add(clearConnectionSettings);
    menu.show(settingsB, 0, settingsB.getHeight());
}

From source file:com.declarativa.interprolog.gui.ListenerWindow.java

static void addItemToMenu(JMenu menu, String item, ActionListener handler) {
    JMenuItem menuItem = new JMenuItem(item);
    menu.add(menuItem);//from   w ww.ja v a2s.  c  o  m
    menuItem.addActionListener(handler);
}

From source file:edu.ku.brc.specify.tasks.subpane.images.ImagesPane.java

/**
 * Shows the Reset menu.//  www . java2  s  . c om
 * @param e the mouse event
 */
private void showContextMenu(final MouseEvent e) {
    if (e.isPopupTrigger()) {
        JPopupMenu popup = new JPopupMenu();
        JMenuItem menuItem = new JMenuItem(UIRegistry.getResourceString("ES_TEXT_RESET"));
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ex) {
                searchText.setEnabled(true);
                searchText.setBackground(textBGColor);
                searchText.setText("");
            }
        });
        popup.add(menuItem);
        popup.show(e.getComponent(), e.getX(), e.getY());

    }
}

From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java

/**
 * Creates a popup menu for the panel.//from   w ww . j av  a2  s .  co m
 *
 * @param properties  include a menu item for the chart property editor.
 * @param save  include a menu item for saving the chart.
 * @param print  include a menu item for printing the chart.
 * @param zoom  include menu items for zooming.
 *
 * @return The popup menu.
 */
protected JPopupMenu createPopupMenu(boolean properties, boolean save, boolean print, boolean zoom) {

    JPopupMenu result = new JPopupMenu("Chart:");
    boolean separator = false;

    JMenuItem newClassItem = new JMenuItem(PluginServices.getText(this, "new_class"));
    newClassItem.setActionCommand(NEW_CLASS_COMMAND);
    newClassItem.addActionListener(this);
    result.add(newClassItem);
    separator = true;

    if (properties) {
    }

    if (save) {
        if (separator) {
            result.addSeparator();
            separator = false;
        }
        JMenuItem saveItem = new JMenuItem(localizationResources.getString("Save_as..."));
        saveItem.setActionCommand(SAVE_COMMAND);
        saveItem.addActionListener(this);
        result.add(saveItem);
        separator = true;
    }

    if (print) {
        if (separator) {
            result.addSeparator();
            separator = false;
        }
        JMenuItem printItem = new JMenuItem(localizationResources.getString("Print..."));
        printItem.setActionCommand(PRINT_COMMAND);
        printItem.addActionListener(this);
        result.add(printItem);
        separator = true;
    }

    if (zoom) {
        if (separator) {
            result.addSeparator();
            separator = false;
        }
    }

    return result;

}

From source file:edu.ku.brc.specify.BackupAndRestoreApp.java

/**
 * Create menus//from   w  w w.j  av a 2 s  . c  o m
 */
public JMenuBar createMenus() {
    JMenuBar mb = new JMenuBar();
    JMenuItem mi;

    //--------------------------------------------------------------------
    //-- File Menu
    //--------------------------------------------------------------------
    JMenu menu = UIHelper.createLocalizedMenu(mb, "Specify.FILE_MENU", "Specify.FILE_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$

    if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) {
        String title = "Specify.EXIT"; //$NON-NLS-1$
        String mnu = "Specify.Exit_MNEU"; //$NON-NLS-1$
        mi = UIHelper.createLocalizedMenuItem(menu, title, mnu, title, true, null);
        mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                doExit(true);
            }
        });
    }

    HelpMgr.setAppDefHelpId("Backup_Restore");

    JMenu helpMenu = UIHelper.createLocalizedMenu(mb, "Specify.HELP_MENU", "Specify.HELP_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$
    HelpMgr.createHelpMenuItem(helpMenu, "Backup and Restore"); //$NON-NLS-1$
    helpMenu.addSeparator();

    if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) {
        String ttle = "Specify.ABOUT";//$NON-NLS-1$ 
        String mneu = "Specify.ABOUTMNEU";//$NON-NLS-1$ 
        String desc = "Specify.ABOUT";//$NON-NLS-1$ 
        mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null);
        mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                doAbout();
            }
        });
    }
    return mb;
}