Java Swing Menu buildManualsMenu(File appDir)

Here you can find the source of buildManualsMenu(File appDir)

Description

build Manuals Menu

License

Open Source License

Declaration

static JMenu buildManualsMenu(File appDir) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JMenu;
import javax.swing.JMenuItem;

public class Main {
    static JMenu buildManualsMenu(File appDir) {
        JMenu manuals = new JMenu("Manuals");

        File manualsDir = new File(appDir.getPath() + File.separatorChar
                + "manual");

        if (manualsDir.exists() && manualsDir.isDirectory()) {
            for (File manualDirContent : manualsDir.listFiles()) {
                if (manualDirContent.isDirectory()) {
                    for (final File manual : manualDirContent.listFiles()) {
                        if (manual.getName().contains(".pdf")) {
                            JMenuItem manualAction = new JMenuItem(
                                    manualDirContent.getName());
                            manualAction
                                    .addActionListener(new ActionListener() {
                                        @Override
                                        public void actionPerformed(
                                                ActionEvent e) {
                                            try {
                                                Desktop.getDesktop().open(
                                                        manual);
                                            } catch (Exception exception) {
                                                exception.printStackTrace();
                                            }
                                        }
                                    });/*from   w  w  w  .  j  a  v  a 2  s  .  c o m*/
                            manuals.add(manualAction);
                        }
                    }
                }
            }
        }
        return manuals;
    }
}

Related

  1. addBooleanActionTo(Container menuOrToolBar, Action action)
  2. addHoverEffect4MenuAbout(final Component component, final Color overbgcolor, final Color overfgcolor, final Color outbgcolor, final Color outfgcolor)
  3. addRCMenuMouseListener(final JTextComponent text)
  4. appendMenuSubElements(MenuElement element, StringBuilder builder, String indent)
  5. applyContextMenuFontRecurse(MenuElement item, Font font)
  6. constructViewMenu(ActionListener act, boolean showUMLOption, boolean showShortenedSourceOption, boolean showJavadocsOption, boolean showSourceOption)
  7. createActionMenu(JTextComponent text, boolean includeModifying)
  8. createMenu(final String label, final String mnemonic, final String accessibleDescription)
  9. createMenu(final String name, final int mnemonic)