2 * Jexer - Java Text User Interface
4 * License: LGPLv3 or later
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
10 * Copyright (C) 2015 Kevin Lamonte
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
33 import jexer
.bits
.MnemonicString
;
36 * TMenu is a top-level collection of TMenuItems.
38 public class TMenu
extends TWindow
{
41 * If true, this is a sub-menu.
43 private boolean isSubMenu
= false;
46 * The shortcut and title.
48 private MnemonicString mnemonic
;
51 * Get the mnemonic string.
53 * @return the full mnemonic string
55 public final MnemonicString
getMnemonic() {
59 // Reserved menu item IDs
60 public static final int MID_UNUSED
= -1;
63 public static final int MID_EXIT
= 1;
64 public static final int MID_QUIT
= MID_EXIT
;
65 public static final int MID_OPEN_FILE
= 2;
66 public static final int MID_SHELL
= 3;
69 public static final int MID_CUT
= 10;
70 public static final int MID_COPY
= 11;
71 public static final int MID_PASTE
= 12;
72 public static final int MID_CLEAR
= 13;
75 public static final int MID_TILE
= 20;
76 public static final int MID_CASCADE
= 21;
77 public static final int MID_CLOSE_ALL
= 22;
78 public static final int MID_WINDOW_MOVE
= 23;
79 public static final int MID_WINDOW_ZOOM
= 24;
80 public static final int MID_WINDOW_NEXT
= 25;
81 public static final int MID_WINDOW_PREVIOUS
= 26;
82 public static final int MID_WINDOW_CLOSE
= 27;
87 * @param parent parent application
88 * @param x column relative to parent
89 * @param y row relative to parent
90 * @param label mnemonic menu title. Label must contain a keyboard
91 * shortcut (mnemonic), denoted by prefixing a letter with "&",
94 public TMenu(final TApplication parent
, final int x
, final int y
,
97 super(parent
, label
, x
, y
, parent
.getScreen().getWidth(),
98 parent
.getScreen().getHeight());
100 // My parent constructor added me as a window, get rid of that
101 parent
.closeWindow(this);
103 // Setup the menu shortcut
104 mnemonic
= new MnemonicString(label
);
105 setTitle(mnemonic
.getRawLabel());
106 assert (mnemonic
.getShortcutIdx() >= 0);
108 // Recompute width and height to reflect an empty menu
109 setWidth(getTitle().length() + 4);