Example usage for javax.swing JMenuItem putClientProperty

List of usage examples for javax.swing JMenuItem putClientProperty

Introduction

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

Prototype

public final void putClientProperty(Object key, Object value) 

Source Link

Document

Adds an arbitrary key/value "client property" to this component.

Usage

From source file:biz.wolschon.finance.jgnucash.panels.WritableTransactionsPanel.java

/**
 * @return the context-menu for the transactionTable.
 * @see #getTransactionTable()//from  w w  w . j  ava 2 s.c  om
 */
private Component getTransactionTableContextMenu() {
    if (myContextMenu == null) {
        myContextMenu = new JPopupMenu();

        PluginManager manager = getPluginManager();
        // if we are configured for the plugin-api
        if (manager != null) {
            ExtensionPoint toolExtPoint = manager.getRegistry().getExtensionPoint(getPluginDescriptor().getId(),
                    "TransactionMenuAction");
            for (Iterator<Extension> it = toolExtPoint.getConnectedExtensions().iterator(); it.hasNext();) {
                Extension ext = it.next();
                String pluginName = "unknown";

                try {
                    pluginName = ext.getParameter("name").valueAsString();
                    JMenuItem newMenuItem = new JMenuItem();
                    newMenuItem.putClientProperty("extension", ext);
                    newMenuItem.setText(pluginName);
                    newMenuItem.addActionListener(new TransactionMenuActionMenuAction(ext, pluginName));
                    myContextMenu.add(newMenuItem);
                } catch (Exception e) {
                    LOG.log(Level.SEVERE, "cannot load TransactionMenuAction-Plugin '" + pluginName + "'", e);
                    JOptionPane.showMessageDialog(this, "Error",
                            "Cannot load TransactionMenuAction-Plugin '" + pluginName + "'",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        }

    }
    return myContextMenu;
}

From source file:biz.wolschon.finance.jgnucash.JGnucash.java

/**
 * This method initializes import-menu with
 * plugins.//w  ww.j a  va 2 s .c o  m
 *
 * @return javax.swing.JMenu
 */
@SuppressWarnings("unchecked")
protected JMenu getImportMenu() {
    if (importMenu == null) {
        importMenu = new JMenu();
        importMenu.setText("Import");
        importMenu.setMnemonic('i');
        //importMenu.setEnabled(false);// first we need to load a file

        PluginManager manager = getPluginManager();
        // if we are configured for the plugin-api
        if (manager != null) {
            ExtensionPoint toolExtPoint = manager.getRegistry().getExtensionPoint(getPluginDescriptor().getId(),
                    "Importer");
            for (Iterator<Extension> it = toolExtPoint.getConnectedExtensions().iterator(); it.hasNext();) {
                Extension ext = it.next();
                String pluginName = "unknown";

                try {
                    pluginName = ext.getParameter("name").valueAsString();
                    JMenuItem newMenuItem = new JMenuItem();
                    newMenuItem.putClientProperty("extension", ext);
                    Parameter descrParam = ext.getParameter("description");
                    Parameter iconParam = ext.getParameter("icon");
                    URL iconUrl = null;
                    if (iconParam != null) {
                        try {
                            iconUrl = getPluginManager()
                                    .getPluginClassLoader(ext.getDeclaringPluginDescriptor())
                                    .getResource(iconParam.valueAsString());
                            if (iconUrl != null) {
                                newMenuItem.setIcon(new ImageIcon(iconUrl));
                            }
                        } catch (Exception e) {
                            LOGGER.error("cannot load icon for Importer-Plugin '" + pluginName + "'", e);
                        }
                    }
                    newMenuItem.setText(pluginName);
                    if (descrParam != null) {
                        newMenuItem.setToolTipText(descrParam.valueAsString());
                    }
                    newMenuItem.addActionListener(new ImportPluginMenuAction(this, ext, pluginName));
                    importMenu.add(newMenuItem);
                } catch (Exception e) {
                    LOGGER.error("cannot load Importer-Plugin '" + pluginName + "'", e);
                    JOptionPane.showMessageDialog(this, "Error",
                            "Cannot load Importer-Plugin '" + pluginName + "'", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    }
    return importMenu;
}

From source file:biz.wolschon.finance.jgnucash.JGnucash.java

/**
 * This method initializes import-menu/*from w  w  w . j a  v  a2s. co m*/
 * with plugins.
 *
 * @return javax.swing.JMenu
 */
@SuppressWarnings("unchecked")
protected JMenu getToolMenu() {
    if (toolMenu == null) {
        toolMenu = new JMenu();
        toolMenu.setText("Tools");
        toolMenu.setMnemonic('t');
        //importMenu.setEnabled(false);// first we need to load a file

        PluginManager manager = getPluginManager();
        // if we are configured for the plugin-api
        if (manager != null) {
            ExtensionPoint toolExtPoint = manager.getRegistry().getExtensionPoint(getPluginDescriptor().getId(),
                    "Tool");
            for (Iterator<Extension> it = toolExtPoint.getConnectedExtensions().iterator(); it.hasNext();) {
                Extension ext = it.next();
                String pluginName = "unknown";

                try {
                    pluginName = ext.getParameter("name").valueAsString();
                    JMenuItem newMenuItem = new JMenuItem();
                    newMenuItem.putClientProperty("extension", ext);
                    Parameter descrParam = ext.getParameter("description");
                    Parameter iconParam = ext.getParameter("icon");
                    URL iconUrl = null;
                    if (iconParam != null) {
                        try {
                            iconUrl = getPluginManager()
                                    .getPluginClassLoader(ext.getDeclaringPluginDescriptor())
                                    .getResource(iconParam.valueAsString());
                            if (iconUrl != null) {
                                newMenuItem.setIcon(new ImageIcon(iconUrl));
                            }
                        } catch (Exception e) {
                            LOGGER.error("cannot load icon for Tool-Plugin '" + pluginName + "'", e);
                        }
                    }
                    newMenuItem.setText(pluginName);
                    if (descrParam != null) {
                        newMenuItem.setToolTipText(descrParam.valueAsString());
                    }
                    newMenuItem.addActionListener(new ToolPluginMenuAction(this, ext, pluginName));
                    toolMenu.add(newMenuItem);
                } catch (Exception e) {
                    LOGGER.error("cannot load Tool-Plugin '" + pluginName + "'", e);
                    JOptionPane.showMessageDialog(this, "Error", "Cannot load Tool-Plugin '" + pluginName + "'",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    }
    return toolMenu;
}

From source file:biz.wolschon.finance.jgnucash.JGnucash.java

/**
 * This method initializes FileMenu//from  ww  w. j av  a  2  s .c  o m
 * including all menu-items added by plugins.
 *
 * @return javax.swing.JMenu
 */
@SuppressWarnings("unchecked")
@Override
protected JMenu getFileMenu() {
    if (fileMenu == null) {
        fileMenu = super.getFileMenu();
        fileMenu.setText("File");
        fileMenu.setMnemonic('f');
        int i = 1;
        fileMenu.add(getFileSaveMenuItem(), i++);
        fileMenu.add(getFileSaveAsMenuItem(), i++);

        // allow plugins to supply file-open and file-save -actions
        PluginManager manager = getPluginManager();
        // if we are configured for the plugin-api
        if (manager != null) {
            ExtensionPoint toolExtPoint = manager.getRegistry().getExtensionPoint(getPluginDescriptor().getId(),
                    "DataSource");
            for (Iterator<Extension> it = toolExtPoint.getConnectedExtensions().iterator(); it.hasNext();) {
                Extension ext = it.next();
                String pluginName = "unknown";

                try {
                    pluginName = ext.getParameter("name").valueAsString();

                    LOGGER.debug("adding menu-item for DataSource-plugin " + pluginName
                            + " - support for writeTo=" + ext.getParameter("supportsWritingTo"));
                    JMenuItem newMenuItem = new JMenuItem();
                    newMenuItem.putClientProperty("extension", ext);
                    Parameter descrParam = ext.getParameter("description");
                    Parameter iconParam = ext.getParameter("icon");
                    URL iconUrl = null;
                    if (iconParam != null) {
                        try {
                            iconUrl = getPluginManager()
                                    .getPluginClassLoader(ext.getDeclaringPluginDescriptor())
                                    .getResource(iconParam.valueAsString());
                            if (iconUrl != null) {
                                newMenuItem.setIcon(new ImageIcon(iconUrl));
                            }
                        } catch (Exception e) {
                            LOGGER.error("cannot load icon for Loader-Plugin '" + pluginName + "'", e);
                        }
                    }
                    newMenuItem.setText("open via " + pluginName + "...");
                    if (descrParam != null) {
                        newMenuItem.setToolTipText(descrParam.valueAsString());
                    }
                    newMenuItem.addActionListener(new OpenFilePluginMenuAction(this, ext, pluginName));
                    fileMenu.add(newMenuItem, 1); // Open
                    if (ext.getParameter("supportsWritingTo").valueAsString().equalsIgnoreCase("true")) {
                        LOGGER.debug("Plugin " + pluginName + " also supportes 'write to', adding menu-item");
                        JMenuItem newSaveAsMenuItem = new JMenuItem();
                        newSaveAsMenuItem.putClientProperty("extension", ext);
                        newSaveAsMenuItem.setText("Save to via " + pluginName + "...");
                        if (iconUrl != null) {
                            newMenuItem.setIcon(new ImageIcon(iconUrl));
                        }
                        newSaveAsMenuItem
                                .addActionListener(new SaveAsFilePluginMenuAction(this, ext, pluginName));
                        fileMenu.add(newSaveAsMenuItem, 2); // Open

                    }
                } catch (Exception e) {
                    LOGGER.error("cannot load Loader-Plugin '" + pluginName + "'", e);
                    JOptionPane.showMessageDialog(this, "Error",
                            "Cannot load Loader-Plugin '" + pluginName + "'", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    }
    return fileMenu;
}

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

private void buildFileMenu(JMenu mnuFile) {

    mnuFile.removeAll();//w w  w  .  j  a  v  a 2s  .c  o m

    String[] fileMenuActions = { "newFile", "loadFile", "closeFile", "-", "saveFile", "saveAsFile", "-",
            "importDirectives", "exportDirectives" };

    MenuBuilder.buildMenu(mnuFile, fileMenuActions, _actionMap);

    mnuFile.addSeparator();
    String[] previous = EditorPreferences.getPreviouslyUsedFiles();
    if (previous != null && previous.length > 0) {
        javax.swing.Action a = this._actionMap.get("loadPreviousFile");
        if (a != null) {
            for (int i = 0; i < previous.length; ++i) {
                String filename = previous[i];
                JMenuItem item = new JMenuItem();
                item.setAction(a);
                item.setText(String.format("%d %s", i + 1, filename));
                item.putClientProperty("Filename", filename);
                item.setMnemonic(KeyEvent.VK_1 + i);
                mnuFile.add(item);
            }
        }
    }

    if (!isMac()) {
        mnuFile.addSeparator();
        JMenuItem mnuItFileExit = new JMenuItem();
        mnuItFileExit.setAction(_actionMap.get("exitApplication"));
        mnuFile.add(mnuItFileExit);
    }

}

From source file:blue.automation.AutomationManager.java

public JPopupMenu getAutomationMenu(SoundLayer soundLayer) {
    this.selectedSoundLayer = soundLayer;

    // if (menu == null || dirty) {
    JPopupMenu menu = new JPopupMenu();

    // Build Instrument Menu
    JMenu instrRoot = new JMenu("Instrument");

    Arrangement arrangement = data.getArrangement();

    ParameterIdList paramIdList = soundLayer.getAutomationParameters();

    for (int i = 0; i < arrangement.size(); i++) {
        InstrumentAssignment ia = arrangement.getInstrumentAssignment(i);

        if (ia.enabled && ia.instr instanceof Automatable) {

            ParameterList params = ((Automatable) ia.instr).getParameterList();

            if (params.size() <= 0) {
                continue;
            }/*from  w w w  .j a v a 2s .c  om*/

            JMenu instrMenu = new JMenu();
            instrMenu.setText(ia.arrangementId + ") " + ia.instr.getName());

            for (int j = 0; j < params.size(); j++) {
                Parameter param = params.getParameter(j);
                JMenuItem paramItem = new JMenuItem();
                paramItem.setText(param.getName());
                paramItem.addActionListener(parameterActionListener);

                if (param.isAutomationEnabled()) {
                    if (paramIdList.contains(param.getUniqueId())) {
                        paramItem.setForeground(Color.GREEN);
                    } else {
                        paramItem.setForeground(Color.ORANGE);
                    }

                }

                paramItem.putClientProperty("instr", ia.instr);
                paramItem.putClientProperty("param", param);

                instrMenu.add(paramItem);
            }
            instrRoot.add(instrMenu);
        }
    }

    menu.add(instrRoot);

    // Build Mixer Menu
    Mixer mixer = data.getMixer();

    if (mixer.isEnabled()) {
        JMenu mixerRoot = new JMenu("Mixer");

        // add channels
        ChannelList channels = mixer.getChannels();

        if (channels.size() > 0) {
            JMenu channelsMenu = new JMenu("Channels");

            for (int i = 0; i < channels.size(); i++) {
                channelsMenu.add(buildChannelMenu(channels.getChannel(i), soundLayer));
            }

            mixerRoot.add(channelsMenu);
        }

        // add subchannels
        ChannelList subChannels = mixer.getSubChannels();

        if (subChannels.size() > 0) {
            JMenu subChannelsMenu = new JMenu("Sub-Channels");
            for (int i = 0; i < subChannels.size(); i++) {
                subChannelsMenu.add(buildChannelMenu(subChannels.getChannel(i), soundLayer));
            }

            mixerRoot.add(subChannelsMenu);
        }

        // add master channel
        Channel master = mixer.getMaster();

        mixerRoot.add(buildChannelMenu(master, soundLayer));

        menu.add(mixerRoot);
    }

    menu.addSeparator();

    JMenuItem clearAll = new JMenuItem("Clear All");
    clearAll.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Object retVal = DialogDisplayer.getDefault().notify(new NotifyDescriptor.Confirmation(
                    "Please Confirm Clearing All Parameter Data for this SoundLayer"));

            if (retVal == NotifyDescriptor.YES_OPTION) {

                ParameterIdList idList = selectedSoundLayer.getAutomationParameters();

                Iterator iter = new ArrayList(idList.getParameters()).iterator();

                while (iter.hasNext()) {
                    String paramId = (String) iter.next();
                    Parameter param = getParameter(paramId);

                    param.setAutomationEnabled(false);
                    idList.removeParameterId(paramId);
                }
            }
        }
    });
    menu.add(clearAll);

    clearAll.setEnabled(soundLayer.getAutomationParameters().size() > 0);

    // }

    // System.err.println(parameterMap);

    return menu;
}

From source file:blue.automation.AutomationManager.java

private JMenu buildChannelMenu(Channel channel, SoundLayer soundLayer) {

    JMenu retVal = new JMenu();

    retVal.setText(channel.getName());// w w w  .j av a  2s  .  com

    ParameterIdList paramIdList = soundLayer.getAutomationParameters();

    // pre effects
    EffectsChain preEffects = channel.getPreEffects();

    if (preEffects.size() > 0) {
        JMenu preMenu = new JMenu("Pre-Effects");
        retVal.add(preMenu);

        for (int i = 0; i < preEffects.size(); i++) {
            Automatable automatable = (Automatable) preEffects.getElementAt(i);

            ParameterList params = automatable.getParameterList();

            if (params.size() > 0) {
                JMenu effectMenu = new JMenu();

                if (automatable instanceof Effect) {
                    effectMenu.setText(((Effect) automatable).getName());
                } else if (automatable instanceof Send) {
                    effectMenu.setText("Send: " + ((Send) automatable).getSendChannel());
                } else {
                    effectMenu.setText("ERROR");
                }

                preMenu.add(effectMenu);

                for (int j = 0; j < params.size(); j++) {
                    Parameter param = params.getParameter(j);
                    JMenuItem paramItem = new JMenuItem();
                    paramItem.setText(param.getName());
                    paramItem.addActionListener(parameterActionListener);

                    if (param.isAutomationEnabled()) {
                        if (paramIdList.contains(param.getUniqueId())) {
                            paramItem.setForeground(Color.GREEN);
                        } else {
                            paramItem.setForeground(Color.ORANGE);
                        }

                    }

                    paramItem.putClientProperty("param", param);

                    effectMenu.add(paramItem);
                }
            }
        }
    }

    // volume
    JMenuItem volItem = new JMenuItem("Volume");
    Parameter volParam = channel.getLevelParameter();
    volItem.putClientProperty("param", volParam);
    volItem.addActionListener(parameterActionListener);

    if (volParam.isAutomationEnabled()) {
        if (paramIdList.contains(volParam.getUniqueId())) {
            volItem.setForeground(Color.GREEN);
        } else {
            volItem.setForeground(Color.ORANGE);
        }

    }

    retVal.add(volItem);

    // post effects
    EffectsChain postEffects = channel.getPostEffects();

    if (postEffects.size() > 0) {
        JMenu postMenu = new JMenu("Post-Effects");
        retVal.add(postMenu);

        for (int i = 0; i < postEffects.size(); i++) {
            Automatable automatable = (Automatable) postEffects.getElementAt(i);

            ParameterList params = automatable.getParameterList();

            if (params.size() > 0) {
                JMenu effectMenu = new JMenu();

                if (automatable instanceof Effect) {
                    effectMenu.setText(((Effect) automatable).getName());
                } else if (automatable instanceof Send) {
                    effectMenu.setText("Send: " + ((Send) automatable).getSendChannel());
                } else {
                    effectMenu.setText("ERROR");
                }

                postMenu.add(effectMenu);

                for (int j = 0; j < params.size(); j++) {
                    Parameter param = params.getParameter(j);
                    JMenuItem paramItem = new JMenuItem();
                    paramItem.setText(param.getName());
                    paramItem.addActionListener(parameterActionListener);

                    if (param.isAutomationEnabled()) {
                        if (paramIdList.contains(param.getUniqueId())) {
                            paramItem.setForeground(Color.GREEN);
                        } else {
                            paramItem.setForeground(Color.ORANGE);
                        }

                    }

                    paramItem.putClientProperty("param", param);

                    effectMenu.add(paramItem);
                }
            }
        }
    }

    return retVal;
}

From source file:edu.brown.gui.CatalogViewer.java

/**
 * /*from   w  w  w.ja  va  2s  . c o m*/
 */
protected void viewerInit() {
    // ----------------------------------------------
    // MENU
    // ----------------------------------------------
    JMenu menu;
    JMenuItem menuItem;

    // 
    // File Menu
    //
    menu = new JMenu("File");
    menu.getPopupMenu().setLightWeightPopupEnabled(false);
    menu.setMnemonic(KeyEvent.VK_F);
    menu.getAccessibleContext().setAccessibleDescription("File Menu");
    menuBar.add(menu);

    menuItem = new JMenuItem("Open Catalog From File");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Open Catalog From File");
    menuItem.addActionListener(this.menuHandler);
    menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.CATALOG_OPEN_FILE);
    menu.add(menuItem);

    menuItem = new JMenuItem("Open Catalog From Jar");
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Open Catalog From Project Jar");
    menuItem.addActionListener(this.menuHandler);
    menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.CATALOG_OPEN_JAR);
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem("Quit", KeyEvent.VK_Q);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Quit Program");
    menuItem.addActionListener(this.menuHandler);
    menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.QUIT);
    menu.add(menuItem);

    // ----------------------------------------------
    // CATALOG TREE PANEL
    // ----------------------------------------------
    this.catalogTree = new JTree();
    this.catalogTree.setEditable(false);
    this.catalogTree.setCellRenderer(new CatalogViewer.CatalogTreeRenderer());
    this.catalogTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    this.catalogTree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) CatalogViewer.this.catalogTree
                    .getLastSelectedPathComponent();
            if (node == null)
                return;

            Object user_obj = node.getUserObject();
            String new_text = ""; // <html>";
            boolean text_mode = true;
            if (user_obj instanceof WrapperNode) {
                CatalogType catalog_obj = ((WrapperNode) user_obj).getCatalogType();
                new_text += CatalogViewer.this.getAttributesText(catalog_obj);
            } else if (user_obj instanceof AttributesNode) {
                AttributesNode wrapper = (AttributesNode) user_obj;
                new_text += wrapper.getAttributes();

            } else if (user_obj instanceof PlanTreeCatalogNode) {
                final PlanTreeCatalogNode wrapper = (PlanTreeCatalogNode) user_obj;
                text_mode = false;

                CatalogViewer.this.mainPanel.remove(0);
                CatalogViewer.this.mainPanel.add(wrapper.getPanel(), BorderLayout.CENTER);
                CatalogViewer.this.mainPanel.validate();
                CatalogViewer.this.mainPanel.repaint();

                if (SwingUtilities.isEventDispatchThread() == false) {
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            wrapper.centerOnRoot();
                        }
                    });
                } else {
                    wrapper.centerOnRoot();
                }

            } else {
                new_text += CatalogViewer.this.getSummaryText();
            }

            // Text Mode
            if (text_mode) {
                if (CatalogViewer.this.text_mode == false) {
                    CatalogViewer.this.mainPanel.remove(0);
                    CatalogViewer.this.mainPanel.add(CatalogViewer.this.textInfoPanel);
                }
                CatalogViewer.this.textInfoTextArea.setText(new_text);

                // Scroll to top
                CatalogViewer.this.textInfoTextArea.grabFocus();
            }

            CatalogViewer.this.text_mode = text_mode;
        }
    });
    this.generateCatalogTree(this.catalog, this.catalog_file_path.getName());

    //
    // Text Information Panel
    //
    this.textInfoPanel = new JPanel();
    this.textInfoPanel.setLayout(new BorderLayout());
    this.textInfoTextArea = new JTextArea();
    this.textInfoTextArea.setEditable(false);
    this.textInfoTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
    this.textInfoTextArea.setText(this.getSummaryText());
    this.textInfoTextArea.addFocusListener(new FocusListener() {
        @Override
        public void focusLost(FocusEvent e) {
            // TODO Auto-generated method stub
        }

        @Override
        public void focusGained(FocusEvent e) {
            CatalogViewer.this.scrollTextInfoToTop();
        }
    });
    this.textInfoScroller = new JScrollPane(this.textInfoTextArea);
    this.textInfoPanel.add(this.textInfoScroller, BorderLayout.CENTER);
    this.mainPanel = new JPanel(new BorderLayout());
    this.mainPanel.add(textInfoPanel, BorderLayout.CENTER);

    //
    // Search Toolbar
    //
    JPanel searchPanel = new JPanel();
    searchPanel.setLayout(new BorderLayout());
    JPanel innerSearchPanel = new JPanel();
    innerSearchPanel.setLayout(new BoxLayout(innerSearchPanel, BoxLayout.X_AXIS));
    innerSearchPanel.add(new JLabel("Search: "));
    this.searchField = new JTextField(30);
    innerSearchPanel.add(this.searchField);
    searchPanel.add(innerSearchPanel, BorderLayout.EAST);

    this.searchField.addKeyListener(new KeyListener() {
        private String last = null;

        @Override
        public void keyReleased(KeyEvent e) {
            String value = CatalogViewer.this.searchField.getText().toLowerCase().trim();
            if (!value.isEmpty() && (this.last == null || !this.last.equals(value))) {
                CatalogViewer.this.search(value);
            }
            this.last = value;
        }

        @Override
        public void keyTyped(KeyEvent e) {
            // Do nothing...
        }

        @Override
        public void keyPressed(KeyEvent e) {
            // Do nothing...
        }
    });

    // Putting it all together
    JScrollPane scrollPane = new JScrollPane(this.catalogTree);
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());
    topPanel.add(searchPanel, BorderLayout.NORTH);
    topPanel.add(scrollPane, BorderLayout.CENTER);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, topPanel, this.mainPanel);
    splitPane.setDividerLocation(400);

    this.add(splitPane, BorderLayout.CENTER);
}

From source file:org.apache.pdfbox.debugger.PDFDebugger.java

private void addRecentFileItems() {
    Action recentMenuAction = new AbstractAction() {
        @Override//from  w  ww  .  j  a v a  2  s  . co  m
        public void actionPerformed(ActionEvent actionEvent) {
            String filePath = (String) ((JComponent) actionEvent.getSource()).getClientProperty("path");
            try {
                readPDFFile(filePath, "");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    if (!recentFiles.isEmpty()) {
        recentFilesMenu.removeAll();
        List<String> files = recentFiles.getFiles();
        for (int i = files.size() - 1; i >= 0; i--) {
            String path = files.get(i);
            String name = new File(path).getName();
            JMenuItem recentFileMenuItem = new JMenuItem(name);
            recentFileMenuItem.putClientProperty("path", path);
            recentFileMenuItem.addActionListener(recentMenuAction);
            recentFilesMenu.add(recentFileMenuItem);
        }
        recentFilesMenu.setEnabled(true);
    }
}

From source file:org.omegat.gui.scripting.ScriptingWindow.java

protected void buildSetsMenu(JMenuBar mb) {

    m_setsMenu.removeAll();//from w  w  w  .  j a v  a2s  .c  o m

    Mnemonics.setLocalizedText(m_setsMenu, OStrings.getString("SCW_MENU_SETS"));

    JMenuItem item = new JMenuItem();
    Mnemonics.setLocalizedText(item, OStrings.getString("SCW_MENU_SAVE_SET"));
    item.addActionListener(new SaveSetAction());
    m_setsMenu.add(item);
    m_setsMenu.addSeparator();

    if (m_scriptsDirectory == null) {
        return;
    }

    for (File script : m_scriptsDirectory.listFiles(new FileFilter() {

        @Override
        public boolean accept(File script) {
            return script.getName().endsWith(".set");
        }

    })) {

        ScriptSet set = new ScriptSet(script);

        JMenuItem setMenuItem = new JMenuItem();
        setMenuItem.setText(set.getTitle());
        setMenuItem.putClientProperty("set", set);
        setMenuItem.addActionListener(new LoadSetAction());

        m_setsMenu.add(setMenuItem);
    }

    mb.add(m_setsMenu);
    //m_scriptList.setListData(items.toArray(new ScriptItem[items.size()]));
}