Java JMenu constructRecentlyFilesMenuItems(JMenu recentlyOpenFilesMenuItem, LinkedHashMap filesOpenedLHM)

Here you can find the source of constructRecentlyFilesMenuItems(JMenu recentlyOpenFilesMenuItem, LinkedHashMap filesOpenedLHM)

Description

To use to construct JMenuItens for recently opened files.

License

Open Source License

Parameter

Parameter Description
recentlyOpenFilesMenuItem a parameter

Declaration

public static void constructRecentlyFilesMenuItems(JMenu recentlyOpenFilesMenuItem,
        LinkedHashMap<?, ?> filesOpenedLHM) 

Method Source Code

//package com.java2s;
/*//from www  . java  2 s  .c  om
 * Copyright (c) 2004-2013 Universidade do Porto - Faculdade de Engenharia
 * Laborat?rio de Sistemas e Tecnologia Subaqu?tica (LSTS)
 * All rights reserved.
 * Rua Dr. Roberto Frias s/n, sala I203, 4200-465 Porto, Portugal
 *
 * This file is part of Neptus, Command and Control Framework.
 *
 * Commercial Licence Usage
 * Licencees holding valid commercial Neptus licences may use this file
 * in accordance with the commercial licence agreement provided with the
 * Software or, alternatively, in accordance with the terms contained in a
 * written agreement between you and Universidade do Porto. For licensing
 * terms, conditions, and further information contact lsts@fe.up.pt.
 *
 * European Union Public Licence - EUPL v.1.1 Usage
 * Alternatively, this file may be used under the terms of the EUPL,
 * Version 1.1 only (the "Licence"), appearing in the file LICENCE.md
 * included in the packaging of this file. You may not use this work
 * except in compliance with the Licence. Unless required by applicable
 * law or agreed to in writing, software distributed under the Licence is
 * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF
 * ANY KIND, either express or implied. See the Licence for the specific
 * language governing permissions and limitations at
 * https://www.lsts.pt/neptus/licence.
 *
 * For more information please see <http://lsts.fe.up.pt/neptus>.
 *
 * Author: Paulo Dias
 * 17/Mai/2005
 */

import java.io.File;

import java.util.Iterator;
import java.util.LinkedHashMap;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

public class Main {
    /**
     * To use to construct JMenuItens for recently opened files.
     * 
     * @param recentlyOpenFilesMenuItem
     * @param filesOpenedLHM<JMenuItem,File>
     */
    public static void constructRecentlyFilesMenuItems(JMenu recentlyOpenFilesMenuItem,
            LinkedHashMap<?, ?> filesOpenedLHM) {
        recentlyOpenFilesMenuItem.removeAll();

        if (filesOpenedLHM.size() == 0) {
            recentlyOpenFilesMenuItem.setEnabled(false);
        } else {
            recentlyOpenFilesMenuItem.setEnabled(true);
            Iterator<?> it = filesOpenedLHM.keySet().iterator();
            // int i = 1;
            while (it.hasNext()) {
                JMenuItem nMenuItem = (JMenuItem) it.next();
                // TEST
                File fx = (File) filesOpenedLHM.get(nMenuItem);
                //String ni = Integer.toString(i).length() == 1 ? " " + i : "" + i;
                nMenuItem.setText(
                        fx.getParentFile().getName() + System.getProperty("file.separator") + fx.getName());
                recentlyOpenFilesMenuItem.add(nMenuItem);
                //i++;
            }

        }
    }
}

Related

  1. addSeparator(JMenu menu)
  2. addSeparatorIfNeeded(JMenu menu)
  3. applyDefaultProperties(final JMenu comp)
  4. assignMnemonics(JMenu menu)
  5. changeMenuItemsState(final JMenu menu, final boolean enableState)
  6. containsMenuComponent(JMenu parent, Component comp)
  7. countCheckBoxMenuItem(JMenu menu)
  8. createMenu(String menuText, JMenu menu, ActionListener listener)
  9. createMenuBar(JMenu... menues)