Example usage for javax.swing JMenuBar add

List of usage examples for javax.swing JMenuBar add

Introduction

In this page you can find the example usage for javax.swing JMenuBar add.

Prototype

public JMenu add(JMenu c) 

Source Link

Document

Appends the specified menu to the end of the menu bar.

Usage

From source file:org.omegat.gui.shortcuts.PropertiesShortcutsTest.java

/**
 * Test of bindKeyStrokes method, of class PropertiesShortcuts.
 *///from www. j  av a2 s  .  c o  m
@Test
public void testBindKeyStrokes_JMenuBar() {
    JMenuBar menu = new JMenuBar();
    JMenu parent = new JMenu();
    JMenuItem child1 = new JMenu();
    JMenuItem child2 = new JMenuItem();
    child2.setActionCommand(TEST_DELETE);
    child2.setAccelerator(CTRL_D);
    JMenuItem grandchild1 = new JMenuItem();
    grandchild1.setActionCommand(TEST_USER_1);
    JMenuItem grandchild2 = new JMenuItem();
    grandchild2.setActionCommand(OUT_OF_LIST);
    grandchild2.setAccelerator(CTRL_X);
    menu.add(parent);
    parent.add(child1);
    parent.add(child2);
    child1.add(grandchild1);
    child1.add(grandchild2);

    // bind
    shotcuts.bindKeyStrokes(menu);

    KeyStroke result = parent.getAccelerator();
    assertNull(result);

    result = child1.getAccelerator();
    assertNull(result);

    result = child2.getAccelerator();
    assertNull(result);

    KeyStroke expected = CTRL_P;
    result = grandchild1.getAccelerator();
    assertEquals(expected, result);

    expected = CTRL_X;
    result = grandchild2.getAccelerator();
    assertEquals(expected, result);
}

From source file:org.openconcerto.task.TodoListPanel.java

public TodoListPanel() {
    this.setOpaque(false);
    this.iconTache = new ImageIcon(TodoListPanel.class.getResource("tache.png"));
    this.iconPriorite = new ImageIcon(TodoListPanel.class.getResource("priorite.png"));
    this.userTableCellRenderer = new UserTableCellRenderer();
    this.timestampTableCellRendererCreated = new TimestampTableCellRenderer();
    this.timestampTableCellRendererDone = new TimestampTableCellRenderer();
    this.timestampTableCellRendererDeadLine = new TimestampTableCellRenderer(true);
    this.timestampTableCellEditorCreated = new TimestampTableCellEditor();
    this.timestampTableCellEditorDone = new TimestampTableCellEditor();
    this.timestampTableCellEditorDeadLine = new TimestampTableCellEditor();
    // Icon renderer
    List<URL> l = new Vector<URL>();
    l.add(TodoListPanel.class.getResource("empty.png"));
    l.add(TodoListPanel.class.getResource("high.png"));
    l.add(TodoListPanel.class.getResource("normal.png"));
    l.add(TodoListPanel.class.getResource("low.png"));
    this.iconEditor = new IconTableCellRenderer(l);
    this.iconRenderer = new IconTableCellRenderer(l);

    final User currentUser = UserManager.getInstance().getCurrentUser();
    this.model = new TodoListModel(currentUser);
    this.sorter = new TableSorter(this.model);
    this.t = new LightEventJTable(this.sorter) {
        public JToolTip createToolTip() {
            return new JMultiLineToolTip();
        }/*from  w w  w.j a v a 2s .  c o m*/

        @Override
        public String getToolTipText(MouseEvent event) {
            String r = null;
            TodoListElement task = getTaskAt(event.getPoint());

            if (task != null && task.getCreatorId() > 1) {
                final String comment = task.getComment();
                if (comment != null) {
                    r = comment;
                    r += "\n\n";
                } else {
                    r = "";
                }
                r += getTM().trM("assignedBy", "user",
                        UserManager.getInstance().getUser(task.getCreatorId()).getFullName(), "date",
                        task.getDate());
            }

            return r;
        }

    };
    this.sorter.setTableHeader(this.t.getTableHeader());

    this.model.setTable(this.t);

    this.comboUser = new JMenu(TM.tr("showTaskAssignedTo"));
    initViewableUsers(currentUser);

    // L'utilisateur courant doit voir ses taches + toutes les taches dont il a les droits
    this.model.addIdListenerSilently(Integer.valueOf(currentUser.getId()));

    final int size = this.users.size();
    for (int i = 0; i < size; i++) {
        Integer id = Integer.valueOf((this.users.get(i)).getId());
        if (this.model.listenToId(id)) {
            ((JCheckBoxMenuItem) this.comboUser.getMenuComponent(i)).setState(true);
        } else {
            ((JCheckBoxMenuItem) this.comboUser.getMenuComponent(i)).setState(false);
        }
    }

    this.addButton = new JButton(TM.tr("addTask"));
    this.removeButton = new JButton();
    this.removeButton.setOpaque(false);
    updateDeleteBtn();
    this.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(2, 2, 1, 2);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 6;
    // SEP
    TitledSeparator sep = new TitledSeparator(
            currentUser.getFirstName() + " " + currentUser.getName().toUpperCase());
    this.add(sep, c);

    c.gridwidth = 1;
    c.gridx = 0;
    c.gridy++;
    c.weightx = 0;
    this.add(this.addButton, c);
    c.gridx++;
    this.add(this.removeButton, c);

    c.anchor = GridBagConstraints.EAST;
    c.gridx++;
    final JMenuBar b = new JMenuBar();
    b.setOpaque(false);
    b.setBorderPainted(false);
    b.add(this.comboUser);
    // Pour que le menu ne disparaisse pas quand on rapetisse trop la fenetre en bas
    b.setMinimumSize(b.getPreferredSize());
    this.add(b, c);

    c.gridx++;
    c.weightx = 1;
    this.detailCheckBox = new JCheckBox(TM.tr("showDetails"));
    this.detailCheckBox.setOpaque(false);
    this.detailCheckBox.setSelected(false);
    this.add(this.detailCheckBox, c);

    //
    c.gridx++;
    this.hideOldCheckBox = new JCheckBox(TM.tr("hideHistory"));
    this.hideOldCheckBox.setOpaque(false);
    this.hideOldCheckBox.setSelected(true);
    this.add(this.hideOldCheckBox, c);

    c.gridx++;

    c.weightx = 0;
    c.anchor = GridBagConstraints.EAST;
    this.reloadPanel.setOpaque(false);
    this.add(this.reloadPanel, c);

    // Table
    c.gridwidth = 6;
    c.gridx = 0;
    c.gridy++;
    c.fill = GridBagConstraints.BOTH;
    c.weighty = 1;
    c.weightx = 1;
    initPopUp();
    initTable(TodoListModel.SIMPLE_MODE);
    this.add(new JScrollPane(this.t), c);

    initListeners();

    this.model.asynchronousFill();
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.view.ImporterUI.java

/**
  * Creates the menu bar.//from   w  w  w  . j a v a  2s. c om
  * 
  * @return The menu bar.
  */
private JMenuBar createMenuBar() {
    TaskBar tb = ImporterAgent.getRegistry().getTaskBar();
    JMenuBar bar = tb.getTaskBarMenuBar();
    if (!model.isMaster())
        return bar;
    JMenu[] existingMenus = new JMenu[bar.getMenuCount()];
    for (int i = 0; i < existingMenus.length; i++) {
        existingMenus[i] = bar.getMenu(i);
    }

    bar.removeAll();
    bar.add(createFileMenu());
    for (int i = 0; i < existingMenus.length; i++) {
        if (i != TaskBar.FILE_MENU)
            bar.add(existingMenus[i]);
    }
    return bar;
}

From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java

/** 
 * Creates the menu bar./*from  w  w w . j ava 2s.c  o  m*/
 * 
 * @param pref The user preferences.
 * @return The menu bar. 
 */
private JMenuBar createMenuBar(ViewerPreferences pref) {
    zoomMenu = new JMenu("Zoom");
    zoomMenu.setMnemonic(KeyEvent.VK_Z);
    zoomingGroup = new ButtonGroup();
    //Create zoom grid menu
    zoomGridMenu = new JMenu("Zoom");
    zoomingGridGroup = new ButtonGroup();

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(createControlsMenu(pref));
    menuBar.add(createViewMenu(pref));
    if (!model.isBigImage())
        menuBar.add(createZoomMenu(pref, true));
    menuBar.add(createShowViewMenu());
    TaskBar tb = ImViewerAgent.getRegistry().getTaskBar();
    //menuBar.add(tb.getWindowsMenu());
    menuBar.add(tb.getMenu(TaskBar.WINDOW_MENU));
    menuBar.add(tb.getMenu(TaskBar.HELP_MENU));
    return menuBar;
}

From source file:org.openmicroscopy.shoola.env.ui.TaskBarView.java

/**
 * Helper method to create the menu bar.
 *
 * @return The menu bar.//from www.ja v a  2 s.c om
 */
private JMenuBar createMenuBar() {
    createMenuItems();
    menus[FILE_MENU] = createFileMenu();
    menus[WINDOW_MENU] = createWindowMenu();
    menus[HELP_MENU] = createHelpMenu();
    JMenuBar bar = new JMenuBar();
    for (int i = 0; i < menus.length; ++i)
        bar.add(menus[i]);
    return bar;
}

From source file:org.openmicroscopy.shoola.env.ui.TaskBarView.java

/**
 * Creates and returns a copy of the original menu bar.
 *
 * @return See above.//from   w  ww.j  a va2 s .c o  m
 */
private JMenuBar copyMenuBar() {
    JMenuBar bar = new JMenuBar();
    JMenu menu, copy;
    for (int i = 0; i < originalBar.getMenuCount(); i++) {
        menu = originalBar.getMenu(i);
        copy = copyItemsFromMenu(menu);
        bar.add(copy);
        if (menu == menus[WINDOW_MENU])
            windowMenus.add(copy);
        else if (menu == menus[HELP_MENU])
            helpMenus.add(copy);
    }
    return bar;
}

From source file:org.openscience.jmol.app.Jmol.java

/**
 * Create the menubar for the app.  By default this pulls the
 * definition of the menu from the associated resource file.
 * @return Menubar//  ww w.  j  a  va2s  .  c  om
 */
protected JMenuBar createMenubar() {
    JMenuBar mb = new JMenuBar();
    addNormalMenuBar(mb);
    // The Macros Menu
    addMacrosMenuBar(mb);
    // The Plugin Menu
    // if (pluginManager != null) {
    //     mb.add(pluginManager.getMenu());
    // }
    // The Help menu, right aligned
    mb.add(Box.createHorizontalGlue());
    addHelpMenuBar(mb);
    return mb;
}

From source file:org.openscience.jmol.app.Jmol.java

protected void addMacrosMenuBar(JMenuBar menuBar) {
    // ok, here needs to be added the funny stuff
    JMenu macroMenu = guimap.newJMenu("macros");
    File macroDir = new File(System.getProperty("user.home") + System.getProperty("file.separator") + ".jmol"
            + System.getProperty("file.separator") + "macros");
    report("User macros dir: " + macroDir);
    report("       exists: " + macroDir.exists());
    report("  isDirectory: " + macroDir.isDirectory());
    if (macroDir.exists() && macroDir.isDirectory()) {
        File[] macros = macroDir.listFiles();
        for (int i = 0; i < macros.length; i++) {
            // loop over these files and load them
            String macroName = macros[i].getName();
            if (macroName.endsWith(".macro")) {
                if (Logger.debugging) {
                    Logger.debug("Possible macro found: " + macroName);
                }/*ww  w .j  a v  a 2s.  c  om*/
                FileInputStream macro = null;
                try {
                    macro = new FileInputStream(macros[i]);
                    Properties macroProps = new Properties();
                    macroProps.load(macro);
                    String macroTitle = macroProps.getProperty("Title");
                    String macroScript = macroProps.getProperty("Script");
                    JMenuItem mi = new JMenuItem(macroTitle);
                    mi.setActionCommand(macroScript);
                    mi.addActionListener(executeScriptAction);
                    macroMenu.add(mi);
                } catch (IOException exception) {
                    System.err.println("Could not load macro file: ");
                    System.err.println(exception);
                } finally {
                    if (macro != null) {
                        try {
                            macro.close();
                        } catch (IOException e) {
                            // Nothing
                        }
                        macro = null;
                    }
                }
            }
        }
    }
    menuBar.add(macroMenu);
}

From source file:org.openscience.jmol.app.Jmol.java

protected void addNormalMenuBar(JMenuBar menuBar) {
    String[] menuKeys = tokenize(JmolResourceHandler.getStringX("menubar"));
    for (int i = 0; i < menuKeys.length; i++) {
        if (menuKeys[i].equals("-")) {
            menuBar.add(Box.createHorizontalGlue());
        } else {// w  w  w  .j a va  2 s .  c  o  m
            JMenu m = createMenu(menuKeys[i]);
            if (m != null)
                menuBar.add(m);
        }
    }
}

From source file:org.openscience.jmol.app.Jmol.java

protected void addHelpMenuBar(JMenuBar menuBar) {
    String menuKey = "help";
    JMenu m = createMenu(menuKey);
    if (m != null) {
        menuBar.add(m);
    }/*from   ww  w  .j  a  va  2 s. com*/
}