Switchable windows
[nikiroo-utils.git] / src / jexer / TMenu.java
1 /**
2 * Jexer - Java Text User Interface
3 *
4 * License: LGPLv3 or later
5 *
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.
9 *
10 * Copyright (C) 2015 Kevin Lamonte
11 *
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.
16 *
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.
21 *
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
26 * 02110-1301 USA
27 *
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
29 * @version 1
30 */
31 package jexer;
32
33 import jexer.bits.MnemonicString;
34
35 /**
36 * TMenu is a top-level collection of TMenuItems.
37 */
38 public class TMenu extends TWindow {
39
40 /**
41 * If true, this is a sub-menu.
42 */
43 private boolean isSubMenu = false;
44
45 /**
46 * The shortcut and title.
47 */
48 private MnemonicString mnemonic;
49
50 /**
51 * Get the mnemonic string.
52 *
53 * @return the full mnemonic string
54 */
55 public final MnemonicString getMnemonic() {
56 return mnemonic;
57 }
58
59 // Reserved menu item IDs
60 public static final int MID_UNUSED = -1;
61
62 // File menu
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;
67
68 // Edit menu
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;
73
74 // Window menu
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;
83
84 /**
85 * Public constructor.
86 *
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 "&",
92 * e.g. "&File"
93 */
94 public TMenu(final TApplication parent, final int x, final int y,
95 final String label) {
96
97 super(parent, label, x, y, parent.getScreen().getWidth(),
98 parent.getScreen().getHeight());
99
100 // My parent constructor added me as a window, get rid of that
101 parent.closeWindow(this);
102
103 // Setup the menu shortcut
104 mnemonic = new MnemonicString(label);
105 setTitle(mnemonic.getRawLabel());
106 assert (mnemonic.getShortcutIdx() >= 0);
107
108 // Recompute width and height to reflect an empty menu
109 setWidth(getTitle().length() + 4);
110 setHeight(2);
111
112 setActive(false);
113 }
114
115 }